You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See https://github.com/OpenHFT/Java-Thread-Affinity/tree/master/affinity/src/test/java[affinity/src/test/java]
18
18
for working examples of how to use this library.
19
19
20
+
=== Supported operating systems
21
+
22
+
The library detects the running platform in `Affinity.java` and selects an
23
+
implementation for that OS. Features differ between systems:
24
+
25
+
* *Linux* - full affinity control via JNA. The implementation can get and set
26
+
thread affinity, query the current CPU, and obtain process and thread IDs.
27
+
* *Windows* - thread affinity is managed through the kernel API. Process and
28
+
thread IDs are available, while `getCpu()` returns `-1`.
29
+
* *macOS* - provides process and thread IDs but does not modify affinity and
30
+
reports the CPU id as `-1`.
31
+
* *Solaris* - mirrors the macOS implementation: only process and thread IDs are
32
+
returned with no affinity or CPU querying support.
33
+
20
34
=== Changes
21
35
22
36
* V3.2.0 - Add support for text configuration
@@ -47,14 +61,33 @@ for the artifacts `jna` and `jna-platform` in the project's `pom` file.
47
61
48
62
sudo yum install jna
49
63
64
+
=== Installing JNA on Windows
65
+
66
+
choco install jna
67
+
68
+
Or download jna.jar and jna-platform.jar from the JNA project and add them to your classpath.
69
+
50
70
=== How does CPU allocation work?
51
71
The library will read your `/proc/cpuinfo` if you have one or provide one and it will determine your CPU layout. If you don't have one it will assume every CPU is on one CPU socket.
52
72
53
73
The library looks for isolated CPUs determined by looking at the CPUs you are not running on by default.
54
74
i.e. if you have 16 CPUs but 8 of them are not available for general use (as determined by the affinity of the process on startup) it will start assigning to those CPUs.
55
75
56
76
Note: if you have more than one process using this library you need to specify which CPUs the process can use otherwise it will assign the same CPUs to both processes.
57
-
To control which CPUs a process can use, add -Daffinity.reserved={cpu-mask-in-hex} to the command line of the process.
77
+
78
+
To control which CPUs a process can use, add `-Daffinity.reserved={cpu-mask-in-hex}`
79
+
to the command line of the process. The mask is a hexadecimal bit mask without
80
+
the `0x` prefix where bit `0` represents CPU `0`, bit `1` represents CPU `1` and
81
+
so on. Multiple CPUs can be specified by setting more than one bit.
82
+
83
+
For example:
84
+
85
+
* `-Daffinity.reserved=2` reserves only CPU `1`.
86
+
* `-Daffinity.reserved=6` reserves CPUs `1` and `2`.
87
+
* `-Daffinity.reserved=10` reserves CPUs `1` and `3` (hexadecimal `a`).
88
+
89
+
Use an appropriate mask when starting each process to avoid reserving the same
90
+
cores for multiple JVMs.
58
91
59
92
Note: the CPU 0 is reserved for the Operating System, it has to run somewhere.
60
93
@@ -76,6 +109,21 @@ To isolate the 1st and 3rd CPU cores (CPU numbers start from 0) on your system,
76
109
77
110
isolcpus=1,3
78
111
112
+
Using GRUB
113
+
[source]
114
+
----
115
+
sudo sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="isolcpus=1,3 /' /etc/default/grub
116
+
sudo update-grub
117
+
sudo reboot
118
+
----
119
+
120
+
Using systemd-boot
121
+
[source]
122
+
----
123
+
sudo sed -i 's/^options \(.*\)/options \1 isolcpus=1,3/' /boot/loader/entries/*.conf
0 commit comments