0

I'm trying to query the process available CPUs (on which CPUs he can run) using cpuset_getaffinity.

cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, getpid(),
                             sizeof(*cpuset), cpuset);

The cpu set returned by the query has all the system CPUs. I was wondering why and in which cases not all CPUs are available for a process?

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
Brave
  • 159
  • 11
  • 1
    Generally, a process can be run on any general CPU in a given system. The default cpuset mask is all ones for the CPUs in the system (e.g. on a 4 cpu system, the mask is 0x0F). To restrict, one uses `cpuset_setaffinity` with some of the bits cleared. – Craig Estey Nov 14 '22 at 19:51
  • So if I want my process to run on some specific group of CPUs because they are connected to some underlined peripheral I should cpuset_setaffinity? For example limit it to group of CPUs that are part of the same socket. Can it do more harm than good? – Brave Nov 15 '22 at 05:52

1 Answers1

1

You can define witch CPUs are dedicated for lets say some processes you wanna highlight. I use 2 out of 8 CPUs for DPKD.

[root@myserver] cat /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0,115200 console=tty0 isolcpus=2,3 default_hugepagesz=2M hugepagesz=2M hugepages=1024"

You see that isolcpus=2,3 are dedicated for DPKD and they are 100% used.

%Cpu0 : 0.7 us, 0.7 sy, 0.0 ni, 98.7 id,
%Cpu1 : 12.5 us, 2.6 sy, 0.0 ni, 84.9 id,

%Cpu2 :100.0 us, 0.0 sy, 0.0 ni, 0.0 id,
%Cpu3 :100.0 us, 0.0 sy, 0.0 ni, 0.0 id,

%Cpu4 : 1.3 us, 2.0 sy, 0.0 ni, 92.6 id,
%Cpu5 : 0.3 us, 0.3 sy, 0.0 ni, 99.3 id,
%Cpu6 : 0.3 us, 0.3 sy, 0.0 ni, 99.3 id,
%Cpu7 : 0.3 us, 1.0 sy, 0.0 ni, 98.7 id,

So in this case, if this was your question, you see that not all CPUs are available to handle incoming processes.

hippietech
  • 11
  • 1