Loading...
1/*
2 * POWER Data Stream Control Register (DSCR) explicit test
3 *
4 * This test modifies the DSCR value using mtspr instruction and
5 * verifies the change with mfspr instruction. It uses both the
6 * privilege state SPR and the problem state SPR for this purpose.
7 *
8 * When using the privilege state SPR, the instructions such as
9 * mfspr or mtspr are priviledged and the kernel emulates them
10 * for us. Instructions using problem state SPR can be exuecuted
11 * directly without any emulation if the HW supports them. Else
12 * they also get emulated by the kernel.
13 *
14 * Copyright 2012, Anton Blanchard, IBM Corporation.
15 * Copyright 2015, Anshuman Khandual, IBM Corporation.
16 *
17 * This program is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License version 2 as published
19 * by the Free Software Foundation.
20 */
21#include "dscr.h"
22
23int dscr_explicit(void)
24{
25 unsigned long i, dscr = 0;
26
27 srand(getpid());
28 set_dscr(dscr);
29
30 for (i = 0; i < COUNT; i++) {
31 unsigned long cur_dscr, cur_dscr_usr;
32 double ret = uniform_deviate(rand());
33
34 if (ret < 0.001) {
35 dscr++;
36 if (dscr > DSCR_MAX)
37 dscr = 0;
38
39 set_dscr(dscr);
40 }
41
42 cur_dscr = get_dscr();
43 if (cur_dscr != dscr) {
44 fprintf(stderr, "Kernel DSCR should be %ld but "
45 "is %ld\n", dscr, cur_dscr);
46 return 1;
47 }
48
49 ret = uniform_deviate(rand());
50 if (ret < 0.001) {
51 dscr++;
52 if (dscr > DSCR_MAX)
53 dscr = 0;
54
55 set_dscr_usr(dscr);
56 }
57
58 cur_dscr_usr = get_dscr_usr();
59 if (cur_dscr_usr != dscr) {
60 fprintf(stderr, "User DSCR should be %ld but "
61 "is %ld\n", dscr, cur_dscr_usr);
62 return 1;
63 }
64 }
65 return 0;
66}
67
68int main(int argc, char *argv[])
69{
70 return test_harness(dscr_explicit, "dscr_explicit_test");
71}
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * POWER Data Stream Control Register (DSCR) explicit test
4 *
5 * This test modifies the DSCR value using mtspr instruction and
6 * verifies the change with mfspr instruction. It uses both the
7 * privilege state SPR and the problem state SPR for this purpose.
8 *
9 * When using the privilege state SPR, the instructions such as
10 * mfspr or mtspr are priviledged and the kernel emulates them
11 * for us. Instructions using problem state SPR can be exuecuted
12 * directly without any emulation if the HW supports them. Else
13 * they also get emulated by the kernel.
14 *
15 * Copyright 2012, Anton Blanchard, IBM Corporation.
16 * Copyright 2015, Anshuman Khandual, IBM Corporation.
17 */
18#include "dscr.h"
19
20int dscr_explicit(void)
21{
22 unsigned long i, dscr = 0;
23
24 srand(getpid());
25 set_dscr(dscr);
26
27 for (i = 0; i < COUNT; i++) {
28 unsigned long cur_dscr, cur_dscr_usr;
29 double ret = uniform_deviate(rand());
30
31 if (ret < 0.001) {
32 dscr++;
33 if (dscr > DSCR_MAX)
34 dscr = 0;
35
36 set_dscr(dscr);
37 }
38
39 cur_dscr = get_dscr();
40 if (cur_dscr != dscr) {
41 fprintf(stderr, "Kernel DSCR should be %ld but "
42 "is %ld\n", dscr, cur_dscr);
43 return 1;
44 }
45
46 ret = uniform_deviate(rand());
47 if (ret < 0.001) {
48 dscr++;
49 if (dscr > DSCR_MAX)
50 dscr = 0;
51
52 set_dscr_usr(dscr);
53 }
54
55 cur_dscr_usr = get_dscr_usr();
56 if (cur_dscr_usr != dscr) {
57 fprintf(stderr, "User DSCR should be %ld but "
58 "is %ld\n", dscr, cur_dscr_usr);
59 return 1;
60 }
61 }
62 return 0;
63}
64
65int main(int argc, char *argv[])
66{
67 return test_harness(dscr_explicit, "dscr_explicit_test");
68}