요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
===================================
DSCR (Data Stream Control Register)
===================================
DSCR register in powerpc allows user to have some control of prefetch of data
stream in the processor. Please refer to the ISA documents or related manual
for more detailed information regarding how to use this DSCR to attain this
control of the prefetches . This document here provides an overview of kernel
support for DSCR, related kernel objects, its functionalities and exported
user interface.
(A) Data Structures:
(1) thread_struct::
dscr /* Thread DSCR value */
dscr_inherit /* Thread has changed default DSCR */
(2) PACA::
dscr_default /* per-CPU DSCR default value */
(3) sysfs.c::
dscr_default /* System DSCR default value */
(B) Scheduler Changes:
Scheduler will write the per-CPU DSCR default which is stored in the
CPU's PACA value into the register if the thread has dscr_inherit value
cleared which means that it has not changed the default DSCR till now.
If the dscr_inherit value is set which means that it has changed the
default DSCR value, scheduler will write the changed value which will
now be contained in thread struct's dscr into the register instead of
the per-CPU default PACA based DSCR value.
NOTE: Please note here that the system wide global DSCR value never
gets used directly in the scheduler process context switch at all.
(C) SYSFS Interface:
- Global DSCR default: /sys/devices/system/cpu/dscr_default
- CPU specific DSCR default: /sys/devices/system/cpu/cpuN/dscr
Changing the global DSCR default in the sysfs will change all the CPU
specific DSCR defaults immediately in their PACA structures. Again if
the current process has the dscr_inherit clear, it also writes the new
value into every CPU's DSCR register right away and updates the current
thread's DSCR value as well.
Changing the CPU specific DSCR default value in the sysfs does exactly
the same thing as above but unlike the global one above, it just changes
stuff for that particular CPU instead for all the CPUs on the system.
(D) User Space Instructions:
The DSCR register can be accessed in the user space using any of these
two SPR numbers available for that purpose.
(1) Problem state SPR: 0x03 (Un-privileged, POWER8 only)
(2) Privileged state SPR: 0x11 (Privileged)
Accessing DSCR through privileged SPR number (0x11) from user space
works, as it is emulated following an illegal instruction exception
inside the kernel. Both mfspr and mtspr instructions are emulated.
Accessing DSCR through user level SPR (0x03) from user space will first
create a facility unavailable exception. Inside this exception handler
all mfspr instruction based read attempts will get emulated and returned
where as the first mtspr instruction based write attempts will enable
the DSCR facility for the next time around (both for read and write) by
setting DSCR facility in the FSCR register.
(E) Specifics about 'dscr_inherit':
The thread struct element 'dscr_inherit' represents whether the thread
in question has attempted and changed the DSCR itself using any of the
following methods. This element signifies whether the thread wants to
use the CPU default DSCR value or its own changed DSCR value in the
kernel.
(1) mtspr instruction (SPR number 0x03)
(2) mtspr instruction (SPR number 0x11)
(3) ptrace interface (Explicitly set user DSCR value)
Any child of the process created after this event in the process inherits
this same behaviour as well.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
DSCR kernel support 개요
1-11PowerPC의 Data Stream Control Register (`DSCR`)는 user가 processor data-stream prefetch를 어느 정도 제어하게 합니다. 구체적인 prefetch tuning은 ISA 문서나 관련 manual을 참조해야 하며, 이 문서는 DSCR의 kernel support, 관련 kernel object, 기능과 userspace interface를 개괄합니다.
DSCR data structure
12-26| 위치 | Field | 의미 |
|---|---|---|
| `thread_struct` | `dscr` | Thread DSCR 값 |
| `thread_struct` | `dscr_inherit` | Thread가 default DSCR을 변경했는지 표시 |
| `PACA` | `dscr_default` | CPU별 DSCR default 값 |
| `sysfs.c` | `dscr_default` | System DSCR default 값 |
Scheduler context-switch 선택
27-39`dscr_inherit`가 clear이면 thread가 아직 default DSCR을 바꾸지 않았다는 뜻이므로 scheduler는 CPU의 PACA에 저장된 per-CPU `dscr_default`를 register에 씁니다.
`dscr_inherit`가 set이면 thread가 default를 변경한 것이므로 scheduler는 PACA default 대신 `thread_struct.dscr`의 변경값을 register에 씁니다.
System-wide global DSCR 값은 scheduler의 process context switch에서 직접 사용되지 않습니다. Global 값은 per-CPU default를 갱신하는 원천입니다.
`dscr_inherit`가 PACA default와 thread-specific 값 사이를 선택합니다.
SYSFS interface
40-54| 범위 | Path |
|---|---|
| Global DSCR default | `/sys/devices/system/cpu/dscr_default` |
| CPU별 DSCR default | `/sys/devices/system/cpu/cpuN/dscr` |
Global DSCR default를 sysfs에서 바꾸면 모든 CPU의 PACA에 있는 per-CPU default가 즉시 변경됩니다. 현재 process의 `dscr_inherit`가 clear이면 모든 CPU의 DSCR register에도 새 값을 바로 쓰고 현재 thread의 DSCR 값도 갱신합니다.
CPU별 DSCR default를 바꾸는 동작은 같지만 system의 모든 CPU가 아니라 지정한 CPU에만 적용됩니다.
Global sysfs write가 per-CPU default와 default를 따르는 current thread에 전파됩니다.
Userspace SPR access
55-73Userspace는 두 SPR 번호 중 하나로 DSCR register에 접근할 수 있습니다.
| SPR | 상태 | Userspace 동작 |
|---|---|---|
| `0x03` | Problem-state, unprivileged, POWER8 only | 첫 access에서 facility-unavailable exception 발생 |
| `0x11` | Privileged | Illegal-instruction exception 뒤 kernel이 emulate |
Privileged SPR `0x11` access는 kernel의 illegal-instruction exception path가 emulate하므로 userspace에서도 동작하며 `mfspr`과 `mtspr` 모두 emulate됩니다.
User-level SPR `0x03` access는 먼저 facility-unavailable exception을 만듭니다. Handler는 `mfspr` read를 emulate해 값을 반환하고, 첫 `mtspr` write에서는 FSCR register의 DSCR facility bit를 set해 이후 read/write에 DSCR facility를 enable합니다.
`dscr_inherit` 설정 조건
74-87`thread_struct.dscr_inherit`는 thread가 다음 방법 중 하나로 직접 DSCR을 바꾸려고 했는지 나타냅니다. 즉 kernel이 CPU default DSCR과 thread-specific DSCR 중 어느 값을 써야 하는지 표시합니다.
| 방법 | 설명 |
|---|---|
| `mtspr` | SPR `0x03`으로 변경 |
| `mtspr` | SPR `0x11`으로 변경 |
| `ptrace` | Userspace DSCR 값을 명시적으로 설정 |
이 event 뒤에 process가 만드는 모든 child도 같은 DSCR behavior를 상속합니다.
요약과 해설
dscr.rst:1-87`dscr_inherit`가 clear이면 scheduler는 PACA default를, set이면 thread-specific DSCR을 사용합니다. Global sysfs 값은 per-CPU default로 전파되지만 context switch에서 직접 읽히지는 않습니다.