Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * POWER Data Stream Control Register (DSCR) sysfs thread test
0004  *
0005  * This test updates the system wide DSCR default value through
0006  * sysfs interface which should then update all the CPU specific
0007  * DSCR default values which must also be then visible to threads
0008  * executing on individual CPUs on the system.
0009  *
0010  * Copyright 2015, Anshuman Khandual, IBM Corporation.
0011  */
0012 #define _GNU_SOURCE
0013 #include "dscr.h"
0014 
0015 static int test_thread_dscr(unsigned long val)
0016 {
0017     unsigned long cur_dscr, cur_dscr_usr;
0018 
0019     cur_dscr = get_dscr();
0020     cur_dscr_usr = get_dscr_usr();
0021 
0022     if (val != cur_dscr) {
0023         printf("[cpu %d] Kernel DSCR should be %ld but is %ld\n",
0024                     sched_getcpu(), val, cur_dscr);
0025         return 1;
0026     }
0027 
0028     if (val != cur_dscr_usr) {
0029         printf("[cpu %d] User DSCR should be %ld but is %ld\n",
0030                     sched_getcpu(), val, cur_dscr_usr);
0031         return 1;
0032     }
0033     return 0;
0034 }
0035 
0036 static int check_cpu_dscr_thread(unsigned long val)
0037 {
0038     cpu_set_t mask;
0039     int cpu;
0040 
0041     for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
0042         CPU_ZERO(&mask);
0043         CPU_SET(cpu, &mask);
0044         if (sched_setaffinity(0, sizeof(mask), &mask))
0045             continue;
0046 
0047         if (test_thread_dscr(val))
0048             return 1;
0049     }
0050     return 0;
0051 
0052 }
0053 
0054 int dscr_sysfs_thread(void)
0055 {
0056     unsigned long orig_dscr_default;
0057     int i, j;
0058 
0059     SKIP_IF(!have_hwcap2(PPC_FEATURE2_DSCR));
0060 
0061     orig_dscr_default = get_default_dscr();
0062     for (i = 0; i < COUNT; i++) {
0063         for (j = 0; j < DSCR_MAX; j++) {
0064             set_default_dscr(j);
0065             if (check_cpu_dscr_thread(j))
0066                 goto fail;
0067         }
0068     }
0069     set_default_dscr(orig_dscr_default);
0070     return 0;
0071 fail:
0072     set_default_dscr(orig_dscr_default);
0073     return 1;
0074 }
0075 
0076 int main(int argc, char *argv[])
0077 {
0078     return test_harness(dscr_sysfs_thread, "dscr_sysfs_thread_test");
0079 }