pstop icon indicating copy to clipboard operation
pstop copied to clipboard

CPU Affinity Selection

Open IFD3 opened this issue 2 months ago • 1 comments

I keep it nice and short:

I guess, when pressing a you can select CPUs with numbers 0-9 which I can understand, but having 12 CPUs wich makes in total 24 threads makes it impossible to select even half of it.

IFD3 avatar Sep 09 '26 07:09 IFD3

Hi @IFD3, short and to the point is appreciated, and you're right: with the digit keys as the only way to toggle a CPU, anything past CPU 9 was simply unreachable. On a 12-core / 24-thread box that's more than half the machine.

The fix: f2567ee

The affinity popup (a) is now a proper htop-style selector:

  • All CPUs are shown in a grid that adds columns as needed, so every logical CPU (up to the 64 a Win32 affinity mask can address) is always visible, even on a short terminal.
  • There is a cursor. Move it with the arrow keys or hjkl (Left/Right jump a whole column, Home/End go to the first/last CPU) and press Space to toggle the highlighted CPU.
  • You can also just click a CPU with the mouse to toggle it. The mouse wheel moves the cursor inside the popup instead of silently changing which process is selected underneath.
  • 0-9 still toggle CPUs 0-9 directly like before, a toggles all, and there's a new i to invert the selection (handy for "everything except these").
  • The header shows "N of M selected" so you can see at a glance what you're about to apply. Enter applies, Esc cancels.

Here's what it looks like on a 24-thread machine:

┌──────────────────── CPU Affinity ────────────────────┐
│ CPU Affinity for PID 4242 - game.exe                 │
│                                                      │
│ Allowed CPUs (16 of 24 selected):                    │
│                                                      │
│  [ ] CPU 0   [X] CPU 16                              │
│  [X] CPU 1   [X] CPU 17                              │
│  [X] CPU 2   [ ] CPU 18                              │
│  [ ] CPU 3   [X] CPU 19                              │
│  [X] CPU 4   [X] CPU 20                              │
│  [X] CPU 5   [ ] CPU 21                              │
│  [ ] CPU 6   [X] CPU 22                              │
│  [X] CPU 7   [X] CPU 23                              │
│  [X] CPU 8                                           │
│  [ ] CPU 9                                           │
│  [X] CPU 10                                          │
│  [X] CPU 11                                          │
│  [ ] CPU 12                                          │
│  [X] CPU 13                                          │
│  [X] CPU 14                                          │
│  [ ] CPU 15                                          │
│                                                      │
│ Controls:                                            │
│  Arrows/hjkl  Move cursor         Space  Toggle CPU  │
│  0-9          Toggle CPU 0-9      Click  Toggle CPU  │
│  a            Toggle all          i      Invert      │
│  Home / End   First / last CPU                       │
│  Enter        Apply and close     Esc    Cancel      │
└──────────────────────────────────────────────────────┘

Verification

Three tests cover it: the grid geometry and click-to-CPU mapping for 24 and 64 CPUs, a rendered snapshot of the popup (the one above), and a keyboard walk that steps the cursor through all 24 CPUs toggling each one, then exercises Left/Right/Home/End, digits, i and a.

On master now, shipping with the next release. Thanks for reporting it!

psmux avatar Sep 23 '26 08:09 psmux