1 // SPDX-License-Identifier: GPL-2.0-only
3 * POWER Data Stream Control Register (DSCR) default test
5 * This test modifies the system wide default DSCR through
6 * it's sysfs interface and then verifies that all threads
7 * see the correct changed DSCR value immediately.
9 * Copyright 2012, Anton Blanchard, IBM Corporation.
10 * Copyright 2015, Anshuman Khandual, IBM Corporation.
14 static unsigned long dscr
; /* System DSCR default */
15 static unsigned long sequence
;
16 static unsigned long result
[THREADS
];
18 static void *do_test(void *in
)
20 unsigned long thread
= (unsigned long)in
;
23 for (i
= 0; i
< COUNT
; i
++) {
24 unsigned long d
, cur_dscr
, cur_dscr_usr
;
27 s1
= READ_ONCE(sequence
);
33 cur_dscr
= get_dscr();
34 cur_dscr_usr
= get_dscr_usr();
43 fprintf(stderr
, "thread %ld kernel DSCR should be %ld "
44 "but is %ld\n", thread
, d
, cur_dscr
);
46 pthread_exit(&result
[thread
]);
49 if (cur_dscr_usr
!= d
) {
50 fprintf(stderr
, "thread %ld user DSCR should be %ld "
51 "but is %ld\n", thread
, d
, cur_dscr_usr
);
53 pthread_exit(&result
[thread
]);
57 pthread_exit(&result
[thread
]);
60 int dscr_default(void)
62 pthread_t threads
[THREADS
];
63 unsigned long i
, *status
[THREADS
];
64 unsigned long orig_dscr_default
;
66 SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR
));
68 orig_dscr_default
= get_default_dscr();
70 /* Initial DSCR default */
72 set_default_dscr(dscr
);
74 /* Spawn all testing threads */
75 for (i
= 0; i
< THREADS
; i
++) {
76 if (pthread_create(&threads
[i
], NULL
, do_test
, (void *)i
)) {
77 perror("pthread_create() failed");
84 /* Keep changing the DSCR default */
85 for (i
= 0; i
< COUNT
; i
++) {
86 double ret
= uniform_deviate(rand());
96 set_default_dscr(dscr
);
103 /* Individual testing thread exit status */
104 for (i
= 0; i
< THREADS
; i
++) {
105 if (pthread_join(threads
[i
], (void **)&(status
[i
]))) {
106 perror("pthread_join() failed");
111 printf("%ldth thread failed to join with %ld status\n",
116 set_default_dscr(orig_dscr_default
);
119 set_default_dscr(orig_dscr_default
);
123 int main(int argc
, char *argv
[])
125 return test_harness(dscr_default
, "dscr_default_test");