1*4882a593Smuzhiyun=================================== 2*4882a593SmuzhiyunDSCR (Data Stream Control Register) 3*4882a593Smuzhiyun=================================== 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunDSCR register in powerpc allows user to have some control of prefetch of data 6*4882a593Smuzhiyunstream in the processor. Please refer to the ISA documents or related manual 7*4882a593Smuzhiyunfor more detailed information regarding how to use this DSCR to attain this 8*4882a593Smuzhiyuncontrol of the prefetches . This document here provides an overview of kernel 9*4882a593Smuzhiyunsupport for DSCR, related kernel objects, it's functionalities and exported 10*4882a593Smuzhiyunuser interface. 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun(A) Data Structures: 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun (1) thread_struct:: 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun dscr /* Thread DSCR value */ 17*4882a593Smuzhiyun dscr_inherit /* Thread has changed default DSCR */ 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun (2) PACA:: 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun dscr_default /* per-CPU DSCR default value */ 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun (3) sysfs.c:: 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun dscr_default /* System DSCR default value */ 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun(B) Scheduler Changes: 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun Scheduler will write the per-CPU DSCR default which is stored in the 30*4882a593Smuzhiyun CPU's PACA value into the register if the thread has dscr_inherit value 31*4882a593Smuzhiyun cleared which means that it has not changed the default DSCR till now. 32*4882a593Smuzhiyun If the dscr_inherit value is set which means that it has changed the 33*4882a593Smuzhiyun default DSCR value, scheduler will write the changed value which will 34*4882a593Smuzhiyun now be contained in thread struct's dscr into the register instead of 35*4882a593Smuzhiyun the per-CPU default PACA based DSCR value. 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun NOTE: Please note here that the system wide global DSCR value never 38*4882a593Smuzhiyun gets used directly in the scheduler process context switch at all. 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun(C) SYSFS Interface: 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun - Global DSCR default: /sys/devices/system/cpu/dscr_default 43*4882a593Smuzhiyun - CPU specific DSCR default: /sys/devices/system/cpu/cpuN/dscr 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun Changing the global DSCR default in the sysfs will change all the CPU 46*4882a593Smuzhiyun specific DSCR defaults immediately in their PACA structures. Again if 47*4882a593Smuzhiyun the current process has the dscr_inherit clear, it also writes the new 48*4882a593Smuzhiyun value into every CPU's DSCR register right away and updates the current 49*4882a593Smuzhiyun thread's DSCR value as well. 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun Changing the CPU specific DSCR default value in the sysfs does exactly 52*4882a593Smuzhiyun the same thing as above but unlike the global one above, it just changes 53*4882a593Smuzhiyun stuff for that particular CPU instead for all the CPUs on the system. 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun(D) User Space Instructions: 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun The DSCR register can be accessed in the user space using any of these 58*4882a593Smuzhiyun two SPR numbers available for that purpose. 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun (1) Problem state SPR: 0x03 (Un-privileged, POWER8 only) 61*4882a593Smuzhiyun (2) Privileged state SPR: 0x11 (Privileged) 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun Accessing DSCR through privileged SPR number (0x11) from user space 64*4882a593Smuzhiyun works, as it is emulated following an illegal instruction exception 65*4882a593Smuzhiyun inside the kernel. Both mfspr and mtspr instructions are emulated. 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun Accessing DSCR through user level SPR (0x03) from user space will first 68*4882a593Smuzhiyun create a facility unavailable exception. Inside this exception handler 69*4882a593Smuzhiyun all mfspr instruction based read attempts will get emulated and returned 70*4882a593Smuzhiyun where as the first mtspr instruction based write attempts will enable 71*4882a593Smuzhiyun the DSCR facility for the next time around (both for read and write) by 72*4882a593Smuzhiyun setting DSCR facility in the FSCR register. 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun(E) Specifics about 'dscr_inherit': 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun The thread struct element 'dscr_inherit' represents whether the thread 77*4882a593Smuzhiyun in question has attempted and changed the DSCR itself using any of the 78*4882a593Smuzhiyun following methods. This element signifies whether the thread wants to 79*4882a593Smuzhiyun use the CPU default DSCR value or its own changed DSCR value in the 80*4882a593Smuzhiyun kernel. 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun (1) mtspr instruction (SPR number 0x03) 83*4882a593Smuzhiyun (2) mtspr instruction (SPR number 0x11) 84*4882a593Smuzhiyun (3) ptrace interface (Explicitly set user DSCR value) 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun Any child of the process created after this event in the process inherits 87*4882a593Smuzhiyun this same behaviour as well. 88