summaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorShuah Khan <shuahkh@osg.samsung.com>2016-09-13 13:13:46 -0400
committerShuah Khan <shuahkh@osg.samsung.com>2016-09-20 11:09:09 -0400
commit92dd8dd4d07f170db0638a20a8db691262da4e5e (patch)
treeef723c0dd5316e51b5e894b9fff7935515f98edd /Documentation
parent10924bc6448760b355492f05ea414a65d924a72c (diff)
selftests: move prctl tests from Documentation/prctl
Move prctl tests from Documentation/prctl to selftests/prctl. Remove prctl from Makefile to move the test. Update prctl Makefile to work under selftests. prctl will not be run as part of selftests suite and will not be included in install targets. They can be built separately for now. Acked-by: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/Makefile2
-rw-r--r--Documentation/prctl/.gitignore3
-rw-r--r--Documentation/prctl/Makefile10
-rw-r--r--Documentation/prctl/disable-tsc-ctxt-sw-stress-test.c97
-rw-r--r--Documentation/prctl/disable-tsc-on-off-stress-test.c96
-rw-r--r--Documentation/prctl/disable-tsc-test.c95
6 files changed, 1 insertions, 302 deletions
diff --git a/Documentation/Makefile b/Documentation/Makefile
index 0473710c09d0..7a28f6c26755 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -1,3 +1,3 @@
1subdir-y := accounting auxdisplay blackfin \ 1subdir-y := accounting auxdisplay blackfin \
2 ia64 laptops mic misc-devices \ 2 ia64 laptops mic misc-devices \
3 networking pcmcia prctl ptp timers vDSO watchdog 3 networking pcmcia ptp timers vDSO watchdog
diff --git a/Documentation/prctl/.gitignore b/Documentation/prctl/.gitignore
deleted file mode 100644
index 0b5c27447bf6..000000000000
--- a/Documentation/prctl/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
1disable-tsc-ctxt-sw-stress-test
2disable-tsc-on-off-stress-test
3disable-tsc-test
diff --git a/Documentation/prctl/Makefile b/Documentation/prctl/Makefile
deleted file mode 100644
index 44de3080c7f2..000000000000
--- a/Documentation/prctl/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
1ifndef CROSS_COMPILE
2# List of programs to build
3hostprogs-$(CONFIG_X86) := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test disable-tsc-test
4# Tell kbuild to always build the programs
5always := $(hostprogs-y)
6
7HOSTCFLAGS_disable-tsc-ctxt-sw-stress-test.o += -I$(objtree)/usr/include
8HOSTCFLAGS_disable-tsc-on-off-stress-test.o += -I$(objtree)/usr/include
9HOSTCFLAGS_disable-tsc-test.o += -I$(objtree)/usr/include
10endif
diff --git a/Documentation/prctl/disable-tsc-ctxt-sw-stress-test.c b/Documentation/prctl/disable-tsc-ctxt-sw-stress-test.c
deleted file mode 100644
index f7499d1c0415..000000000000
--- a/Documentation/prctl/disable-tsc-ctxt-sw-stress-test.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/*
2 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...)
3 *
4 * Tests if the control register is updated correctly
5 * at context switches
6 *
7 * Warning: this test will cause a very high load for a few seconds
8 *
9 */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <signal.h>
15#include <inttypes.h>
16#include <wait.h>
17
18
19#include <sys/prctl.h>
20#include <linux/prctl.h>
21
22/* Get/set the process' ability to use the timestamp counter instruction */
23#ifndef PR_GET_TSC
24#define PR_GET_TSC 25
25#define PR_SET_TSC 26
26# define PR_TSC_ENABLE 1 /* allow the use of the timestamp counter */
27# define PR_TSC_SIGSEGV 2 /* throw a SIGSEGV instead of reading the TSC */
28#endif
29
30static uint64_t rdtsc(void)
31{
32uint32_t lo, hi;
33/* We cannot use "=A", since this would use %rax on x86_64 */
34__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
35return (uint64_t)hi << 32 | lo;
36}
37
38static void sigsegv_expect(int sig)
39{
40 /* */
41}
42
43static void segvtask(void)
44{
45 if (prctl(PR_SET_TSC, PR_TSC_SIGSEGV) < 0)
46 {
47 perror("prctl");
48 exit(0);
49 }
50 signal(SIGSEGV, sigsegv_expect);
51 alarm(10);
52 rdtsc();
53 fprintf(stderr, "FATAL ERROR, rdtsc() succeeded while disabled\n");
54 exit(0);
55}
56
57
58static void sigsegv_fail(int sig)
59{
60 fprintf(stderr, "FATAL ERROR, rdtsc() failed while enabled\n");
61 exit(0);
62}
63
64static void rdtsctask(void)
65{
66 if (prctl(PR_SET_TSC, PR_TSC_ENABLE) < 0)
67 {
68 perror("prctl");
69 exit(0);
70 }
71 signal(SIGSEGV, sigsegv_fail);
72 alarm(10);
73 for(;;) rdtsc();
74}
75
76
77int main(void)
78{
79 int n_tasks = 100, i;
80
81 fprintf(stderr, "[No further output means we're allright]\n");
82
83 for (i=0; i<n_tasks; i++)
84 if (fork() == 0)
85 {
86 if (i & 1)
87 segvtask();
88 else
89 rdtsctask();
90 }
91
92 for (i=0; i<n_tasks; i++)
93 wait(NULL);
94
95 exit(0);
96}
97
diff --git a/Documentation/prctl/disable-tsc-on-off-stress-test.c b/Documentation/prctl/disable-tsc-on-off-stress-test.c
deleted file mode 100644
index a06f027e9d16..000000000000
--- a/Documentation/prctl/disable-tsc-on-off-stress-test.c
+++ /dev/null
@@ -1,96 +0,0 @@
1/*
2 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...)
3 *
4 * Tests if the control register is updated correctly
5 * when set with prctl()
6 *
7 * Warning: this test will cause a very high load for a few seconds
8 *
9 */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <signal.h>
15#include <inttypes.h>
16#include <wait.h>
17
18
19#include <sys/prctl.h>
20#include <linux/prctl.h>
21
22/* Get/set the process' ability to use the timestamp counter instruction */
23#ifndef PR_GET_TSC
24#define PR_GET_TSC 25
25#define PR_SET_TSC 26
26# define PR_TSC_ENABLE 1 /* allow the use of the timestamp counter */
27# define PR_TSC_SIGSEGV 2 /* throw a SIGSEGV instead of reading the TSC */
28#endif
29
30/* snippet from wikipedia :-) */
31
32static uint64_t rdtsc(void)
33{
34uint32_t lo, hi;
35/* We cannot use "=A", since this would use %rax on x86_64 */
36__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
37return (uint64_t)hi << 32 | lo;
38}
39
40int should_segv = 0;
41
42static void sigsegv_cb(int sig)
43{
44 if (!should_segv)
45 {
46 fprintf(stderr, "FATAL ERROR, rdtsc() failed while enabled\n");
47 exit(0);
48 }
49 if (prctl(PR_SET_TSC, PR_TSC_ENABLE) < 0)
50 {
51 perror("prctl");
52 exit(0);
53 }
54 should_segv = 0;
55
56 rdtsc();
57}
58
59static void task(void)
60{
61 signal(SIGSEGV, sigsegv_cb);
62 alarm(10);
63 for(;;)
64 {
65 rdtsc();
66 if (should_segv)
67 {
68 fprintf(stderr, "FATAL ERROR, rdtsc() succeeded while disabled\n");
69 exit(0);
70 }
71 if (prctl(PR_SET_TSC, PR_TSC_SIGSEGV) < 0)
72 {
73 perror("prctl");
74 exit(0);
75 }
76 should_segv = 1;
77 }
78}
79
80
81int main(void)
82{
83 int n_tasks = 100, i;
84
85 fprintf(stderr, "[No further output means we're allright]\n");
86
87 for (i=0; i<n_tasks; i++)
88 if (fork() == 0)
89 task();
90
91 for (i=0; i<n_tasks; i++)
92 wait(NULL);
93
94 exit(0);
95}
96
diff --git a/Documentation/prctl/disable-tsc-test.c b/Documentation/prctl/disable-tsc-test.c
deleted file mode 100644
index 8d494f7bebdb..000000000000
--- a/Documentation/prctl/disable-tsc-test.c
+++ /dev/null
@@ -1,95 +0,0 @@
1/*
2 * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...)
3 *
4 * Basic test to test behaviour of PR_GET_TSC and PR_SET_TSC
5 */
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <unistd.h>
10#include <signal.h>
11#include <inttypes.h>
12
13
14#include <sys/prctl.h>
15#include <linux/prctl.h>
16
17/* Get/set the process' ability to use the timestamp counter instruction */
18#ifndef PR_GET_TSC
19#define PR_GET_TSC 25
20#define PR_SET_TSC 26
21# define PR_TSC_ENABLE 1 /* allow the use of the timestamp counter */
22# define PR_TSC_SIGSEGV 2 /* throw a SIGSEGV instead of reading the TSC */
23#endif
24
25const char *tsc_names[] =
26{
27 [0] = "[not set]",
28 [PR_TSC_ENABLE] = "PR_TSC_ENABLE",
29 [PR_TSC_SIGSEGV] = "PR_TSC_SIGSEGV",
30};
31
32static uint64_t rdtsc(void)
33{
34uint32_t lo, hi;
35/* We cannot use "=A", since this would use %rax on x86_64 */
36__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
37return (uint64_t)hi << 32 | lo;
38}
39
40static void sigsegv_cb(int sig)
41{
42 int tsc_val = 0;
43
44 printf("[ SIG_SEGV ]\n");
45 printf("prctl(PR_GET_TSC, &tsc_val); ");
46 fflush(stdout);
47
48 if ( prctl(PR_GET_TSC, &tsc_val) == -1)
49 perror("prctl");
50
51 printf("tsc_val == %s\n", tsc_names[tsc_val]);
52 printf("prctl(PR_SET_TSC, PR_TSC_ENABLE)\n");
53 fflush(stdout);
54 if ( prctl(PR_SET_TSC, PR_TSC_ENABLE) == -1)
55 perror("prctl");
56
57 printf("rdtsc() == ");
58}
59
60int main(void)
61{
62 int tsc_val = 0;
63
64 signal(SIGSEGV, sigsegv_cb);
65
66 printf("rdtsc() == %llu\n", (unsigned long long)rdtsc());
67 printf("prctl(PR_GET_TSC, &tsc_val); ");
68 fflush(stdout);
69
70 if ( prctl(PR_GET_TSC, &tsc_val) == -1)
71 perror("prctl");
72
73 printf("tsc_val == %s\n", tsc_names[tsc_val]);
74 printf("rdtsc() == %llu\n", (unsigned long long)rdtsc());
75 printf("prctl(PR_SET_TSC, PR_TSC_ENABLE)\n");
76 fflush(stdout);
77
78 if ( prctl(PR_SET_TSC, PR_TSC_ENABLE) == -1)
79 perror("prctl");
80
81 printf("rdtsc() == %llu\n", (unsigned long long)rdtsc());
82 printf("prctl(PR_SET_TSC, PR_TSC_SIGSEGV)\n");
83 fflush(stdout);
84
85 if ( prctl(PR_SET_TSC, PR_TSC_SIGSEGV) == -1)
86 perror("prctl");
87
88 printf("rdtsc() == ");
89 fflush(stdout);
90 printf("%llu\n", (unsigned long long)rdtsc());
91 fflush(stdout);
92
93 exit(EXIT_SUCCESS);
94}
95