diff options
author | Daniil Baturin <daniil@vyos.io> | 2024-12-03 10:39:34 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-03 10:39:34 +0000 |
commit | 03a664a5a1f57ffcb9467434c4939f8be7e1860b (patch) | |
tree | a22ced10bd81e9d5e8ce0da2ef96d038b80b76eb /python | |
parent | a4dfb3d45ed94a67eacf5c62a4901d918c72021d (diff) | |
parent | b4c276fcb8536cf53f414343694f202c75b6eae4 (diff) | |
download | vyos-1x-03a664a5a1f57ffcb9467434c4939f8be7e1860b.tar.gz vyos-1x-03a664a5a1f57ffcb9467434c4939f8be7e1860b.zip |
Merge pull request #4215 from sever-sever/T6917
T6917: fix RPS ethernet settings for CPUs with more than 32 cores
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ifconfig/ethernet.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py index 61da7b74b..50dd0f396 100644 --- a/python/vyos/ifconfig/ethernet.py +++ b/python/vyos/ifconfig/ethernet.py @@ -310,13 +310,15 @@ class EthernetIf(Interface): rps_cpus = 0 queues = len(glob(f'/sys/class/net/{self.ifname}/queues/rx-*')) if state: + cpu_count = os.cpu_count() + # Enable RPS on all available CPUs except CPU0 which we will not # utilize so the system has one spare core when it's under high # preasure to server other means. Linux sysfs excepts a bitmask # representation of the CPUs which should participate on RPS, we # can enable more CPUs that are physically present on the system, # Linux will clip that internally! - rps_cpus = (1 << os.cpu_count()) -1 + rps_cpus = (1 << cpu_count) - 1 # XXX: we should probably reserve one core when the system is under # high preasure so we can still have a core left for housekeeping. @@ -324,8 +326,19 @@ class EthernetIf(Interface): # receive packet steering. rps_cpus &= ~1 - for i in range(0, queues): - self._write_sysfs(f'/sys/class/net/{self.ifname}/queues/rx-{i}/rps_cpus', f'{rps_cpus:x}') + # Convert the bitmask to hexadecimal chunks of 32 bits + # Split the bitmask into chunks of up to 32 bits each + hex_chunks = [] + for i in range(0, cpu_count, 32): + # Extract the next 32-bit chunk + chunk = (rps_cpus >> i) & 0xFFFFFFFF + hex_chunks.append(f"{chunk:08x}") + + # Join the chunks with commas + rps_cpus = ",".join(hex_chunks) + + for i in range(queues): + self._write_sysfs(f'/sys/class/net/{self.ifname}/queues/rx-{i}/rps_cpus', rps_cpus) # send bitmask representation as hex string without leading '0x' return True |