From 114b4ede4ad8d9cf1825a07ad9e2bb8e10fa1d63 Mon Sep 17 00:00:00 2001 From: Christoph Pohl <christoph.pohl@kit.edu> Date: Wed, 29 Nov 2023 11:31:30 +0100 Subject: [PATCH] Fix CPU pinning in RTUtility and BusIO Adjusted CPU pinning in the RTUtility and BusIO modules to correctly fix the CPU indices. Earlier, the threads were erroneously always pinned to CPU 0. This adjustment facilitates distributing the load among multiple cores, improving overall system performance. The BusIO's requestHandlerLoop thread is now pinned to CPU 1. --- source/armarx/control/ethercat/RTUtility.cpp | 4 ++-- source/armarx/control/ethercat/bus_io/BusIO.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/armarx/control/ethercat/RTUtility.cpp b/source/armarx/control/ethercat/RTUtility.cpp index b839a7fa..1319e97b 100644 --- a/source/armarx/control/ethercat/RTUtility.cpp +++ b/source/armarx/control/ethercat/RTUtility.cpp @@ -63,7 +63,7 @@ namespace armarx::control::ethercat ARMARX_INFO << "Pinning thread #" << pid << " to CPU #" << cpu; cpu_set_t mask; CPU_ZERO(&mask); - CPU_SET(0, &mask); + CPU_SET(cpu, &mask); int retval = sched_setaffinity(static_cast<int>(pid), sizeof(mask), &mask); if (retval != 0) { @@ -72,7 +72,7 @@ namespace armarx::control::ethercat } cpu_set_t mask2; CPU_ZERO(&mask2); - CPU_SET(0, &mask2); + CPU_SET(cpu, &mask2); sched_getaffinity(static_cast<int>(pid), sizeof(mask2), &mask2); bool matches = CPU_EQUAL(&mask, &mask2); if (matches) diff --git a/source/armarx/control/ethercat/bus_io/BusIO.cpp b/source/armarx/control/ethercat/bus_io/BusIO.cpp index 0705b988..9b042e08 100644 --- a/source/armarx/control/ethercat/bus_io/BusIO.cpp +++ b/source/armarx/control/ethercat/bus_io/BusIO.cpp @@ -131,6 +131,7 @@ namespace armarx::control::ethercat BusIO::requestHandlerLoop() { RTUtility::elevateThreadPriority(RTUtility::RT_THREAD_PRIORITY); + RTUtility::pinThreadToCPU(1); while (requestHandlerThreadRunning.load() == true) { -- GitLab