Skip to content

Commit

Permalink
FW: Log a failure to set the CPU affinity as a platform problem
Browse files Browse the repository at this point in the history
It's not fatal, but it's bad. I thought about simply refusing to run,
but some tests will deadlock if not all threads get run, in which case
we'd compound the problem.

Removed the perror() calls.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
thiagomacieira committed Mar 21, 2022
1 parent ed05045 commit 5ee9ec0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
16 changes: 14 additions & 2 deletions framework/sandstone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,22 @@ int test_run_wrapper_function(const struct test *test, int thread_number)
static void *thread_runner(void *arg)
{
uintptr_t thread_number = uintptr_t(arg);
thread_num = thread_number;

// convert from internal Sandstone numbering to the system one
pin_to_logical_processor(LogicalProcessor(cpu_info[thread_number].cpu_number), current_test->id);
LogicalProcessor lp{cpu_info[thread_number].cpu_number};
if (!__builtin_expect(pin_to_logical_processor(lp, current_test->id), true)) {
char buf[256] = {};
char *msg = buf;
auto x = strerror_r(errno, buf, sizeof(buf));
if constexpr (std::is_pointer_v<decltype(x)>)
msg = x; // GNU strerror_r doesn't *always* return our buffer
log_platform_message(SANDSTONE_LOG_WARNING "Failed to set affinity to CPU %d "
"(logical CPU %d): %s",
unsigned(thread_number), unsigned(lp), msg);
log_warning("Setting CPU affinity failed, content is likely not running on CPU %d (logical CPU %d)",
unsigned(thread_number), unsigned(lp));
}

struct TestRunWrapper {
struct per_thread_data *this_thread;
Expand All @@ -833,7 +846,6 @@ static void *thread_runner(void *arg)
: this_thread(cpu_data_for_thread(thread_number)),
thread_number(thread_number)
{
thread_num = thread_number;
this_thread->inner_loop_count = 0;
}

Expand Down
6 changes: 1 addition & 5 deletions framework/sysdeps/freebsd/cpu_affinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ bool pin_to_logical_processor(LogicalProcessor n, const char *thread_name)
CPU_ZERO(&cpu_set);
CPU_SET(int(n), &cpu_set);

if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpu_set), &cpu_set)) {
perror("cpuset_setaffinity");
return false;
}
return true;
return cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpu_set), &cpu_set) == 0;
}

6 changes: 1 addition & 5 deletions framework/sysdeps/linux/cpu_affinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ bool pin_to_logical_processor(LogicalProcessor n, const char *thread_name)
CPU_ZERO(&cpu_set);
CPU_SET(int(n), &cpu_set);

if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set)) {
perror("sched_setaffinity");
return false;
}
return true;
return sched_setaffinity(0, sizeof(cpu_set), &cpu_set) == 0;
}

0 comments on commit 5ee9ec0

Please sign in to comment.