~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/tm/tm-syscall.c

Version: ~ [ linux-5.2 ] ~ [ linux-5.1.16 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.57 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.132 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.184 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.184 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.69 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright 2015, Sam Bobroff, IBM Corp.
  3  * Licensed under GPLv2.
  4  *
  5  * Test the kernel's system call code to ensure that a system call
  6  * made from within an active HTM transaction is aborted with the
  7  * correct failure code.
  8  * Conversely, ensure that a system call made from within a
  9  * suspended transaction can succeed.
 10  */
 11 
 12 #include <stdio.h>
 13 #include <unistd.h>
 14 #include <sys/syscall.h>
 15 #include <asm/tm.h>
 16 #include <sys/time.h>
 17 #include <stdlib.h>
 18 
 19 #include "utils.h"
 20 #include "tm.h"
 21 
 22 extern int getppid_tm_active(void);
 23 extern int getppid_tm_suspended(void);
 24 
 25 unsigned retries = 0;
 26 
 27 #define TEST_DURATION 10 /* seconds */
 28 #define TM_RETRIES 100
 29 
 30 pid_t getppid_tm(bool suspend)
 31 {
 32         int i;
 33         pid_t pid;
 34 
 35         for (i = 0; i < TM_RETRIES; i++) {
 36                 if (suspend)
 37                         pid = getppid_tm_suspended();
 38                 else
 39                         pid = getppid_tm_active();
 40 
 41                 if (pid >= 0)
 42                         return pid;
 43 
 44                 if (failure_is_persistent()) {
 45                         if (failure_is_syscall())
 46                                 return -1;
 47 
 48                         printf("Unexpected persistent transaction failure.\n");
 49                         printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
 50                                __builtin_get_texasr(), __builtin_get_tfiar());
 51                         exit(-1);
 52                 }
 53 
 54                 retries++;
 55         }
 56 
 57         printf("Exceeded limit of %d temporary transaction failures.\n", TM_RETRIES);
 58         printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
 59                __builtin_get_texasr(), __builtin_get_tfiar());
 60 
 61         exit(-1);
 62 }
 63 
 64 int tm_syscall(void)
 65 {
 66         unsigned count = 0;
 67         struct timeval end, now;
 68 
 69         SKIP_IF(!have_htm_nosc());
 70 
 71         setbuf(stdout, NULL);
 72 
 73         printf("Testing transactional syscalls for %d seconds...\n", TEST_DURATION);
 74 
 75         gettimeofday(&end, NULL);
 76         now.tv_sec = TEST_DURATION;
 77         now.tv_usec = 0;
 78         timeradd(&end, &now, &end);
 79 
 80         for (count = 0; timercmp(&now, &end, <); count++) {
 81                 /*
 82                  * Test a syscall within a suspended transaction and verify
 83                  * that it succeeds.
 84                  */
 85                 FAIL_IF(getppid_tm(true) == -1); /* Should succeed. */
 86 
 87                 /*
 88                  * Test a syscall within an active transaction and verify that
 89                  * it fails with the correct failure code.
 90                  */
 91                 FAIL_IF(getppid_tm(false) != -1);  /* Should fail... */
 92                 FAIL_IF(!failure_is_persistent()); /* ...persistently... */
 93                 FAIL_IF(!failure_is_syscall());    /* ...with code syscall. */
 94                 gettimeofday(&now, 0);
 95         }
 96 
 97         printf("%d active and suspended transactions behaved correctly.\n", count);
 98         printf("(There were %d transaction retries.)\n", retries);
 99 
100         return 0;
101 }
102 
103 int main(void)
104 {
105         return test_harness(tm_syscall, "tm_syscall");
106 }
107 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp