539.17K
Category: softwaresoftware

Win32 Priority Separation

1.

Win32PrioritySeparation:
What, Why, and How?
Alchemy Tweaks

2.

Agenda:
What is Quantum & Context Switch?
How to change the Win32PrioritySeparation value?
Explaining the Win32PrioritySeparation mechanism
Are there limits to the values I can experiment with?
Latency Results by testing all values of Win32PrioritySeparation
FPS Results by testing all values of Win32PrioritySeparation

3.

Process Scheduling (1/10)
Win32PrioritySeparation
Quantum
- A quantum is the amount of time a thread is permitted to run before Windows
checks to see whether another thread at the same priority is waiting to run. If a
thread completes its quantum and there are no other threads at its priority, Windows
permits the thread to run for another quantum. (Windows Internals 7th Edition
Part 1, page 231)
SCHEDULE
NEW
READY:
P1,P2,P3
RUN CPU
Priority/Time quantum
TERMINAT
E

4.

Process Scheduling (2/10)
Win32PrioritySeparation
Context Switch
- Every time the CPU transitions to a new process, a 'context switch'
occurs.
1) The CPU is executing a task, referred to as process P1.
CPU
2) The CPU receives a signal to interrupt P1 and execute another
task, named process P2.
PROCESS P1
Saves P1 State
3) The CPU saves the state of P1, including the data and
instructions stored in registers and the cache memory.
4) The CPU loads the state of P2, encompassing its data and
instructions.
PROCESS P2
Restore P2 State
PROCESS P2
Saves P2 State
5) The CPU initiates the execution of P2.
6) Once P2 is completed, the CPU saves its state.
7) The CPU loads the saved state of P1.
PROCESS P1
Restore P1 State
8) The CPU resumes the execution of P1 from
the point where it was interrupted.

5.

Process Scheduling (3/10)
Win32PrioritySeparation
Controlling the quantum (How to change the Win32PrioritySeparation Value)
- To change this setting, right-click the This PC icon on the desktop. Alternatively, in Windows Explorer, choose Properties,
click the Advanced System Settings label, click the Advanced tab, click the Settings button in the Performance section,
and click yet another Advanced tab.

6.

Process Scheduling (4/10)
Win32PrioritySeparation
This dialog box contains two key options:
- Programs (Value 26hex-38dec) This setting designates the use of short, variable quantums, which is the default for client versions
of Windows (and other client-like versions, such as mobile, XBOX, HoloLens, and so on). If you install Terminal Services on a server
system and configure the server as an application server, this setting is selected so that the users on the terminal server have the
same quantum settings that would normally be set on a desktop or client system. You might also select this manually if you were
running Windows Server as your desktop OS. (Windows Internals 7th Edition Part 1, page 235)
- Background Services (18hex-24dec) This setting designates the use of long, fixed quantums—the default for server systems. The
only reason you might select this option on a workstation system is if you were using the workstation as a server system. However,
because changes in this option take effect immediately, it might make sense to use it if the machine is about to run a background or
server-style workload. For example, if a long-running computation, encoding, or modeling simulation needs to run overnight, you
could select the Background Services option at night and return the system to Programs mode in the morning. (Windows Internals 7th
Edition Part 1, page 235)

7.

Process Scheduling (5.1/10)
Win32PrioritySeparation
Variable
- quantums:
Table describes the exact quantum value (recall that this is stored in a unit representing one-third of a
clock tick) that will be selected based on the quantum index and which quantum configuration is in use.
(Windows Internals 7th Edition Part 1, page 236)
(Windows Internals 7th Edition Part 1, page
236)
- Thus, when a window is brought into the foreground on a client system, all the threads in the process
containing the thread that owns the foreground window have their quantums tripled. Threads in the
foreground process run with a quantum of six clock ticks, whereas threads in other processes have the
default client quantum of two clock ticks. In this way, when you switch away from a CPU-intensive
process, the new foreground process will get proportionally more of the CPU. This is because when its
threads run, they will have a longer turn than background threads (again, assuming the thread priorities
are the same in both the foreground and background processes). (Windows Internals 7th Edition Part 1,
page 236)

8.

Process Scheduling (5.2/10)
Win32PrioritySeparation
Variable
quantums:
(Windows Internals 7th Edition Part 1, page
236)
Short Quantum
Index:
Used for threads not I/O-bound (don't get stuck waiting for data).
Quantum value depends on the thread's priority level.
Higher priority = larger quantum value = more execution time.
Long Quantum
UsedIndex:
for I/O-bound threads (frequently waiting for data).
Quantum value depends on scheduler configuration (variable or fixed quantum).
Variable: Quantum value increases with I/O activity.
Fixed: Quantum value remains constant.

9.

Process Scheduling (6/10)
Win32PrioritySeparation
Quantum settings registry value:
- The user interface controlling quantum settings, as described earlier, modifies the registry value Win32PrioritySeparation in the key HKLM\SYSTEM\CurrentControlSet\Control\PriorityControl. Besides determining
the relative length of thread quantums (short or long), this registry value also specifies whether variable quantums
should be utilized, along with the priority separation (which, as explained, dictates the quantum index when
variable quantums are enabled). The value consists of 6 bits divided into three 2-bit fields.
Short vs. Long
- Οpting for a short quantum means the CPU allocates a brief period to applications, promoting faster task switching. On the other
hand, choosing a long quantum allows applications to utilize the CPU for extended periods, resulting in fewer interruptions and
smoother processing, which is particularly beneficial for server systems.
Variable vs. Fixed
- Α fixed quantum ensures that time is evenly distributed among applications, whereas a variable quantum allows certain
applications to use the CPU for extended periods when necessary. Opting for a variable quantum can enhance game
performance, potentially leading to better FPS by allocating more CPU time to the game. On the other hand, a fixed quantum is
conducive to improved inputs, as CPU time is equally shared between the game and processes responsible for input devices.
Priority Separation
- This field, stored in the kernel variable PsPrioritySeparation, sets the priority separation, with values ranging up to 2.

10.

Process Scheduling (7/10)
Win32PrioritySeparation
Priority boosts for foreground threads after waits
- As will be described shortly, whenever a thread in the foreground process completes a wait
operation on a kernel object, the kernel boosts its current (not base) priority by the current value of
PsPrioritySeparation. (The windowing system is responsible for determining which process is
considered to be in the foreground.) As described earlier in this chapter in the section “Controlling
the quantum,” PsPrioritySeparation reflects the quantum-table index used to select quantums for
th Edition Part 1, page 243)
(Windows in
Internals
the threads of foreground applications. However,
this 7case,
it is being used as a priority boost
value.
- The reason for this boost is to improve the responsiveness of interactive applications. By giving the
foreground application a small boost when it completes a wait, it has a better chance of running right
(Windows Internals 7th Edition Part 1, page 243)
away, especially when other processes at the same base priority might be
running in the
background.
In simple terms
When a thread in the foreground process finishes waiting for something in the operating system, its
priority gets a temporary boost by a value called PsPrioritySeparation. This boost aims to help
interactive applications run more smoothly, giving them a better chance to run immediately after
waiting, especially if other processes with the same priority are running in the background.

11.

Process Scheduling
Win32PrioritySeparation
(8/10)
Amit’s
table
Hexadecimal:
The hexadecimal value of
PsPriosep
Decimal: The decimal value of PsPriosep
Binary: The binary value of PsPriosep
Interval: The interval that the PsPriosep
value corresponds to
Length: The length of the interval
PsPriosep: The PsPriosep value
ForegroundQU: The CPU time used by
foreground programs
BackgroundQU: The CPU time used by
background programs
TotalQU: The total CPU time used

12.

Process Scheduling (9/10)
Win32PrioritySeparation
Enhancing Focus on Foreground Applications
or Not
PsPrioSep (No foreground boost) – value
0
- The 'no foreground boost' value will allocate time equally (1:1) between foreground
and background processes.
PsPrioSep (Medium foreground boost) –
value 1
- The 'medium foreground boost' value will prioritize real-time applications (like your
game) with a ratio of 2:1
PsPrioSep (High foreground boost) –
value 2
- The 'high foreground boost' value will make the CPU spend three times (3:1) more
time on the foreground application compared to background services.

13.

Process Scheduling (10/10)
Win32PrioritySeparation
Win32PrioritySeparation values
2A Hex = Short, Fixed , High foreground boost.
29 Hex = Short, Fixed , Medium foreground boost.
28 Hex = Short, Fixed , No foreground boost.
26 Hex = Short, Variable , High foreground boost.
25 Hex = Short, Variable , Medium foreground boost.
24 Hex = Short, Variable , No foreground boost.
1A Hex = Long, Fixed, High foreground boost.
19 Hex = Long, Fixed, Medium foreground boost.
18 Hex = Long, Fixed, No foreground boost.
16 Hex = Long, Variable, High foreground boost.
15 Hex = Long, Variable, Medium foreground boost.
14 Hex = Long, Variable, No foreground boost.

14.

Win32PrioritySeparation limitations
values
What values can we use only?
- According to the documentation Windows allows up to 0x3F (63 decimal) because the bitmask is made up of 6-bits,
so why do values above this exist? What happens if we enter a value greater than the (theoretically) maximum
allowed.
- Why can you put values greater than 0x3F (63 in decimal) in the Win32PrioritySeparation registry key when
anything higher is treated the same as values below the maximum limit? The deal here is that the highest value a
REG_DWORD can hold is 0xFFFFFFFF (4294967295 in decimal). Windows doesn't restrict users from entering
illogical values, and when the kernel reads the Win32PrioritySeparation, it has to handle these weird values. So, it
reads only a part of what you entered—specifically, the first 6 bits of the bitmask. This means values over 63
just loop back. (AMIT’s source)
- Suppose a user decides to set the Win32PrioritySeparation registry key value to 80. In binary, the
representation of 80 is 1010000. However, since the system reads only the first 6 bits due to the constraints of a
REG_DWORD, it considers 101000.
- Now, converting this binary representation back to decimal yields 40. Instead of encountering an error or rejecting
the seemingly illogical value of 80, the system adapts by effectively 'looping back' to a value within the acceptable
range. So, despite the user inputting 80, the system interprets and treats it as if it were 40.

15.

Latency Results:
Latency captured & analyzed with Windows
Performance Toolkit

16.

(Fortnite) Avg Duration (Fragmented) (μς) (DPC/ISR) – Lowest better
14
1,191
15
1,204
16
1,193
18
1,417
19
1,436
1A
1,322
24
1,095
25
1,165
26
1,149
28
1,626
29
1,197
2A
1,268
0
0,2
0,4
0,6
2A
0,8
29
28
26
25
1
24
1A
19
1,2
18
16
15
1,4
14
1,6
1,8

17.

(Fortnite) Avg Exclusive Duration (μς) (DPC/ISR) – Lowest better
14
1,193
15
1,204
16
1,253
18
1,624
19
1,439
1A
1,337
24
1,095
25
1,209
26
1,151
28
1,626
29
1,197
2A
1,269
0
0,2
0,4
0,6
2A
0,8
29
28
26
25
1
24
1A
19
1,2
18
16
15
1,4
14
1,6
1,8

18.

(Fortnite) Avg Inclusive Duration (μς) (DPC/ISR) – Lowest better
14
1,205
15
1,215
16
1,266
18
1,658
19
1,446
1A
1,341
24
1,096
25
1,246
26
1,179
28
1,626
29
1,201
2A
1,267
0
0,2
0,4
0,6
2A
0,8
29
28
26
25
1
24
1A
19
1,2
18
16
15
1,4
14
1,6
1,8

19.

(Fortnite) Sum Duration (Fragmented) (μς) (DPC/ISR) – Lowest better
14
454,25
15
494,36
16
467,98
18
321,37
19
336,96
1A
306,22
24
584,92
25
689,49
26
678,79
28
352,89
29
385,81
2A
413,88
0
100
200
300
2A
29
28
400
26
25
24
500
1A
19
18
16
600
15
14
700
800

20.

(Fortnite) Sum Exclusive Duration (μς) (DPC/ISR) – Lowest better
14
454,79
15
494,69
16
491,95
18
244,718
19
337,61
1A
306,54
24
585,17
25
559,045
26
679,61
28
352,89
29
386,1
2A
414,03
0
100
200
300
2A
29
28
400
26
25
24
1A
500
19
18
16
600
15
14
700
800

21.

(Fortnite) Sum Inclusive Duration (μς) (DPC/ISR) – Lowest better
14
459,21
15
498,71
16
496,87
18
251,972
19
339,33
1A
313,52
24
585,45
25
580,145
26
696,55
28
352,89
29
387,22
2A
414,59
0
100
200
300
2A
29
28
400
26
25
24
1A
500
19
18
16
600
15
14
700
800

22.

Conclusion – Highest better
2
18
1
1A
3
24
0
0,5
1
1,5
2
24
1A
18
2,5
3
3,5

23.

FPS Results:
FPS captured & analyzed with CapFrameX

24.

(Fortnite) Average FPS – Highest Better
14
304,3
15
309,6
16
311,8
18
308,8
19
313,9
1A
314,7
24
315,5
25
316,4
26
319,2
28
318,4
29
324,3
2A
326,6
290
295
300
305
2A
29
28
310
26
25
24
1A
315
19
18
16
320
15
14
325
330

25.

(Fortnite) 1% Lows FPS – Highest Better
14
176,3
15
177,9
16
184,4
18
180,7
19
183,9
1A
183,7
24
194,7
25
186,3
26
191,2
28
189,9
29
198
2A
189,64
165
170
175
180
2A
29
28
26
185
25
24
1A
19
18
190
16
15
14
195
200

26.

(Fortnite) 0.1% Lows FPS – Highest Better
14
91
15
89,8
16
100,5
18
93,6
19
98,6
1A
96,6
24
125,4
25
99,3
26
108,5
28
108,6
29
123,8
2A
109,76
0
20
40
60
2A
29
28
26
80
25
24
1A
19
18
100
16
15
14
120
140

27.

(Fortnite) Adaptive STDEV FPS – Lowest Better
14
21,6
15
20,6
16
20,7
18
21,8
19
21,2
1A
21,3
24
22
25
21,4
26
21,6
28
22,4
29
21,7
2A
19,5
22,18
20
20,5
21
2A
29
28
26
21,5
25
24
1A
19
18
22
16
15
14
22,5
23

28.

(Fortnite) Smooth % – Highest Better
14
99,7
15
99,7
16
99,8
18
99,7
19
99,8
1A
99,8
24
99,8
25
99,8
26
99,8
28
99,8
29
99,8
2A
99,8
99,64
99,66
99,68
99,7
2A
99,72
29
28
26
25
99,74
24
1A
19
99,76
18
16
15
14
99,78
99,8
99,82

29.

(Fortnite) Stuttering % – Lowest Better
14
0,2
15
0,2
16
0,1
18
0,2
19
0,2
1A
0,1
24
0,1
25
0,1
26
0,1
28
0,1
29
0,1
2A
0,2
0
0,05
0,1
2A
29
28
0,15
26
25
24
1A
19
18
16
0,2
15
14
0,25

30.

(Fortnite) Frametimes (ms) – Lowest Better
14
9,6
15
9,1
16
8,5
18
8,9
19
8,7
1A
8,6
24
7,6
25
8,4
26
7,9
28
8
29
7,6
2A
7,9
0
2
4
2A
6
29
28
26
25
24
1A
8
19
18
16
15
14
10
12

31.

(Fortnite) Variances < 2ms (%) – Lowest Better
14
99,48
15
99,44
16
99,54
18
99,5
19
99,5
1A
99,47
24
99,57
25
99,5
26
99,5
28
99,58
29
99,56
2A
99,3
99,42
99,35
99,4
2A
29
99,45
28
26
25
24
1A
99,5
19
18
16
15
14
99,55
99,6

32.

(Fortnite) Variances < 4ms (%) – Lowest Better
14
0,33
15
0,37
16
0,3
18
0,32
19
0,33
1A
0,33
24
0,3
25
0,32
26
0,34
28
0,27
29
0,3
2A
0,4
0
0,05
0,1
0,15
2A
29
0,2
28
26
25
0,25
24
1A
19
0,3
18
16
15
14
0,35
0,4
0,45

33.

(Fortnite) Variances < 8ms (%) – Lowest Better
14
0,11
15
0,11
16
0,11
18
0,12
19
0,12
1A
0,13
24
0,1
25
0,12
26
0,11
28
0,11
29
0,1
2A
0,14
0
0,02
0,04
0,06
2A
29
28
0,08
26
25
24
1A
0,1
19
18
16
0,12
15
14
0,14
0,16

34.

(Fortnite) Variances < 12ms (%) – Lowest Better
14
0,04
15
0,02
16
0,02
18
0,02
19
0,02
1A
0,02
24
0,01
25
0,02
26
0,01
28
0,01
29
0,01
2A
0,02
0
0,005
0,01
0,015
2A
29
0,02
28
26
25
0,025
24
1A
19
0,03
18
16
15
14
0,035
0,04
0,045

35.

(Fortnite) Variances > 12ms (%) – Lowest Better
14
0,02
15
0,02
16
0,01
18
0,02
19
0,02
1A
0,02
24
0
25
0,01
26
0,01
28
0,01
29
0,01
2A
0,01
0
0,005
0,01
2A
29
28
0,015
26
25
24
1A
19
18
16
0,02
15
14
0,025

36.

Conclusion – Highest Better
14
1
15
2
18
1
16
2
19
2
1A
1
26
3
28
4
15
1
24
6
29
6
2A
5
0
1
2
3
2A
29
24
15
4
28
26
1A
19
16
5
18
15
14
6
7

37.

Conclusion
Based on results best value is 24hex/36dec

38.

Further Reading
TechPowerUp “Win32PrioritySeparation”
https://www.techpowerup.com/forums/attachments/win32priorityseparation-_microsoft-docs-pdf.163992/
AMIT’S Research “The truth behind ambiguous values”, “No foreground boost
may be superior” https://github.com/amitxv/PCTuning/blob/main/docs/research.md#win32priorityseparation
Windows Internals 7th Edition Part 1 (page 231 – 238)
https://www.amazon.com/Windows-Internals-Part-architecturemanagement/dp/0735684189
Blur Busters https://forums.blurbusters.com/viewtopic.php?t=8535
Win32PrioritySeparation – Understanding How the Values Impact Your
Performance
https://www.xbitlabs.com/win32priorityseparation-performance/
Processor scheduling and quanta in Windows
https://recoverymonkey.org/2007/08/17/processor-scheduling-and-quanta-inwindows-and-a-bit-about-unixlinux/

39.

Thank you!
Alchemy Tweaks
English     Русский Rules