Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * POWER Data Stream Control Register (DSCR) explicit test
0004  *
0005  * This test modifies the DSCR value using mtspr instruction and
0006  * verifies the change with mfspr instruction. It uses both the
0007  * privilege state SPR and the problem state SPR for this purpose.
0008  *
0009  * When using the privilege state SPR, the instructions such as
0010  * mfspr or mtspr are priviledged and the kernel emulates them
0011  * for us. Instructions using problem state SPR can be exuecuted
0012  * directly without any emulation if the HW supports them. Else
0013  * they also get emulated by the kernel.
0014  *
0015  * Copyright 2012, Anton Blanchard, IBM Corporation.
0016  * Copyright 2015, Anshuman Khandual, IBM Corporation.
0017  */
0018 #include "dscr.h"
0019 
0020 int dscr_explicit(void)
0021 {
0022     unsigned long i, dscr = 0;
0023 
0024     SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR));
0025 
0026     srand(getpid());
0027     set_dscr(dscr);
0028 
0029     for (i = 0; i < COUNT; i++) {
0030         unsigned long cur_dscr, cur_dscr_usr;
0031         double ret = uniform_deviate(rand());
0032 
0033         if (ret < 0.001) {
0034             dscr++;
0035             if (dscr > DSCR_MAX)
0036                 dscr = 0;
0037 
0038             set_dscr(dscr);
0039         }
0040 
0041         cur_dscr = get_dscr();
0042         if (cur_dscr != dscr) {
0043             fprintf(stderr, "Kernel DSCR should be %ld but "
0044                     "is %ld\n", dscr, cur_dscr);
0045             return 1;
0046         }
0047 
0048         ret = uniform_deviate(rand());
0049         if (ret < 0.001) {
0050             dscr++;
0051             if (dscr > DSCR_MAX)
0052                 dscr = 0;
0053 
0054             set_dscr_usr(dscr);
0055         }
0056 
0057         cur_dscr_usr = get_dscr_usr();
0058         if (cur_dscr_usr != dscr) {
0059             fprintf(stderr, "User DSCR should be %ld but "
0060                     "is %ld\n", dscr, cur_dscr_usr);
0061             return 1;
0062         }
0063     }
0064     return 0;
0065 }
0066 
0067 int main(int argc, char *argv[])
0068 {
0069     return test_harness(dscr_explicit, "dscr_explicit_test");
0070 }