2 * POWER Data Stream Control Register (DSCR) default test
4 * This test modifies the system wide default DSCR through
5 * it's sysfs interface and then verifies that all threads
6 * see the correct changed DSCR value immediately.
8 * Copyright 2012, Anton Blanchard, IBM Corporation.
9 * Copyright 2015, Anshuman Khandual, IBM Corporation.
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation.
17 static unsigned long dscr; /* System DSCR default */
18 static unsigned long sequence;
19 static unsigned long result[THREADS];
21 static void *do_test(void *in)
23 unsigned long thread = (unsigned long)in;
26 for (i = 0; i < COUNT; i++) {
27 unsigned long d, cur_dscr, cur_dscr_usr;
30 s1 = ACCESS_ONCE(sequence);
36 cur_dscr = get_dscr();
37 cur_dscr_usr = get_dscr_usr();
46 fprintf(stderr, "thread %ld kernel DSCR should be %ld "
47 "but is %ld\n", thread, d, cur_dscr);
49 pthread_exit(&result[thread]);
52 if (cur_dscr_usr != d) {
53 fprintf(stderr, "thread %ld user DSCR should be %ld "
54 "but is %ld\n", thread, d, cur_dscr_usr);
56 pthread_exit(&result[thread]);
60 pthread_exit(&result[thread]);
63 int dscr_default(void)
65 pthread_t threads[THREADS];
66 unsigned long i, *status[THREADS];
67 unsigned long orig_dscr_default;
69 orig_dscr_default = get_default_dscr();
71 /* Initial DSCR default */
73 set_default_dscr(dscr);
75 /* Spawn all testing threads */
76 for (i = 0; i < THREADS; i++) {
77 if (pthread_create(&threads[i], NULL, do_test, (void *)i)) {
78 perror("pthread_create() failed");
85 /* Keep changing the DSCR default */
86 for (i = 0; i < COUNT; i++) {
87 double ret = uniform_deviate(rand());
97 set_default_dscr(dscr);
104 /* Individual testing thread exit status */
105 for (i = 0; i < THREADS; i++) {
106 if (pthread_join(threads[i], (void **)&(status[i]))) {
107 perror("pthread_join() failed");
112 printf("%ldth thread failed to join with %ld status\n",
117 set_default_dscr(orig_dscr_default);
120 set_default_dscr(orig_dscr_default);
124 int main(int argc, char *argv[])
126 return test_harness(dscr_default, "dscr_default_test");