Skip to content

Commit 455e422

Browse files
Merge pull request #4 from randomizedcoder/2024_06_01
cpu affinity
2 parents 46105dc + b239455 commit 455e422

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ all: hp0 hp3
88
hp0:
99
scp -C ./hp0/* hp0:
1010
scp -C ./modules/* hp0:
11+
scp -C ./scripts/* hp0:
1112
scp -C ./nix_switch.bash hp0:
1213

1314
hp3:
1415
scp -C ./hp3/* hp3:
1516
scp -C ./modules/* hp3:
17+
scp -C ./scripts/* hp3:
1618
scp -C ./nix_switch.bash hp3:
1719

1820
#

hp0/configuration.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
./hosts.nix
2828
./firewall.nix
2929
./il8n.nix
30+
./systemdSystem.nix
3031
./systemPackages.nix
3132
./home-manager.nix
3233
];

hp3/configuration.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
./hosts.nix
2828
./firewall.nix
2929
./il8n.nix
30+
./systemdSystem.nix
3031
./systemPackages.nix
3132
./home-manager.nix
3233
];

modules/systemdSystem.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{ config, pkgs, ... }:
2+
3+
{
4+
# https://github.com/NixOS/nixpkgs/blob/095f1acb70302bd74cd5f3ab02a64bdfac36daa8/nixos/modules/system/boot/systemd.nix#L534
5+
# https://discourse.nixos.org/t/overriding-modifying-systemd-unit-file/45621/7
6+
7+
# https://mynixos.com/nixpkgs/options/systemd
8+
systemd.extraConfig = "CPUAffinity=2-7";
9+
10+
#https://mynixos.com/options/systemd.user
11+
systemd.user.extraConfig = "CPUAffinity=2-7";
12+
# create your own service
13+
# https://discourse.nixos.org/t/how-to-use-toplevel-overrides-for-systemd/12501
14+
}

nix_switch.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
#
33
sudo cp ./*.nix /etc/nixos/
44
sudo nixos-rebuild switch
5+
6+
7+
#sudo ln -s /run/current-system/sw/bin/bash /usr/bin/bash

scripts/pin_nic_irqs.bash

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/bash
2+
#
3+
# This script pins iwlwifi and enp1 to cores 0-1
4+
#
5+
# https://www.kernel.org/doc/Documentation/IRQ-affinity.txt
6+
# https://linux-kernel-labs.github.io/refs/heads/master/lectures/interrupts.html#interrupt-handling-in-linux
7+
# in future consider
8+
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/performance_tuning_guide/network-rps
9+
10+
# [das@hp0:~]$ cat /proc/interrupts | grep wifi
11+
# 86: 0 0 0 4361163 0 0 0 0 IR-PCI-MSIX-0000:03:00.0 0-edge iwlwifi:default_queue
12+
# 87: 527141 0 0 0 0 0 0 0 IR-PCI-MSIX-0000:03:00.0 1-edge iwlwifi:queue_1
13+
# 88: 0 36601 0 0 0 0 0 0 IR-PCI-MSIX-0000:03:00.0 2-edge iwlwifi:queue_2
14+
# 89: 0 0 549109 0 0 0 0 0 IR-PCI-MSIX-0000:03:00.0 3-edge iwlwifi:queue_3
15+
# 90: 0 0 0 393223 0 0 0 0 IR-PCI-MSIX-0000:03:00.0 4-edge iwlwifi:queue_4
16+
# 91: 0 0 0 0 1776763 0 0 0 IR-PCI-MSIX-0000:03:00.0 5-edge iwlwifi:queue_5
17+
# 92: 0 0 0 0 0 159677 0 0 IR-PCI-MSIX-0000:03:00.0 6-edge iwlwifi:queue_6
18+
# 93: 0 0 0 0 0 0 295033 0 IR-PCI-MSIX-0000:03:00.0 7-edge iwlwifi:queue_7
19+
# 94: 0 0 0 0 0 0 0 642178 IR-PCI-MSIX-0000:03:00.0 8-edge iwlwifi:queue_8
20+
# 95: 0 0 0 0 3 0 0 0 IR-PCI-MSIX-0000:03:00.0 9-edge iwlwifi:exception
21+
# grep iwlwifi /proc/interrupts | awk '{ print $1 }' | sed -e 's/://'
22+
23+
echo "starting to pin"
24+
echo "BEFORE"
25+
echo "grep iwlwifi /proc/interrupts"
26+
grep iwlwifi /proc/interrupts
27+
28+
for i in {86..95}
29+
do
30+
echo "Loop:${i}"
31+
echo "echo 0-1 > /proc/irq/${i}/smp_affinity_list"
32+
echo 0-1 > /proc/irq/"${i}"/smp_affinity_list
33+
echo "cat /proc/irq/${i}/smp_affinity_list"
34+
cat /proc/irq/"${i}"/smp_affinity_list
35+
done
36+
37+
echo "AFTER"
38+
echo "grep iwlwifi /proc/interrupts"
39+
grep iwlwifi /proc/interrupts
40+
41+
#[das@hp0:~]$ grep eno /proc/interrupts
42+
# 83: 0 0 0 0 0 0 0 0 IR-PCI-MSIX-0000:05:00.0 0-edge eno1
43+
44+
echo "echo 0-1 > /proc/irq/83/smp_affinity_list"
45+
echo 0-1 > /proc/irq/83/smp_affinity_list

0 commit comments

Comments
 (0)