From f804c7f4ff93dcad5dc65ac081ae2f8cff3ad33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Tue, 1 Oct 2024 14:10:19 +0200 Subject: [PATCH] thingies --- .github/workflows/runner.yml | 6 +++--- tests/core/templates/test_rid.h | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.github/workflows/runner.yml b/.github/workflows/runner.yml index 979e20af1bb2..89d1d6c11938 100644 --- a/.github/workflows/runner.yml +++ b/.github/workflows/runner.yml @@ -6,9 +6,9 @@ concurrency: cancel-in-progress: true jobs: - linux-build: - name: 🐧 Linux - uses: ./.github/workflows/linux_builds.yml +# linux-build: +# name: 🐧 Linux +# uses: ./.github/workflows/linux_builds.yml macos-build: name: 🍎 macOS diff --git a/tests/core/templates/test_rid.h b/tests/core/templates/test_rid.h index 82049a72df11..98628597bbca 100644 --- a/tests/core/templates/test_rid.h +++ b/tests/core/templates/test_rid.h @@ -38,6 +38,10 @@ #include "tests/test_macros.h" +#include +#include +#include + namespace TestRID { TEST_CASE("[RID] Default Constructor") { RID rid; @@ -114,6 +118,7 @@ TEST_CASE("[RID_Owner] Thread safety") { struct RID_OwnerTester { RID_Owner rid_owner; TightLocalVector threads; + long cpu_cores = 0; SafeNumeric next_thread_idx; // Using std::atomic directly since SafeNumeric doesn't support relaxed ordering. TightLocalVector> rids; // Atomic here to prevent false data race warnings. @@ -136,7 +141,11 @@ TEST_CASE("[RID_Owner] Thread safety") { explicit RID_OwnerTester(bool p_chunk_for_all, bool p_chunks_preallocated) : rid_owner(sizeof(DataHolder) * (p_chunk_for_all ? OS::get_singleton()->get_processor_count() : 1)) { - threads.resize(OS::get_singleton()->get_processor_count() * 2); + cpu_cores = sysconf(_SC_NPROCESSORS_ONLN); + printf("############################# %ld cores\n", cpu_cores); + + threads.resize(OS::get_singleton()->get_processor_count()); + printf("############################# %u threads\n", threads.size()); rids.resize(threads.size()); if (p_chunks_preallocated) { LocalVector prealloc_rids; @@ -164,6 +173,15 @@ TEST_CASE("[RID_Owner] Thread safety") { // 1. Each thread gets a zero-based index. uint32_t self_th_idx = rot->next_thread_idx.postincrement(); + // Use pthread to set affinity to the core self_th_idx modulo cpu cores. + // This is to avoid threads running on the same core. + thread_port_t mach_thread; + int core = self_th_idx % rot->cpu_cores; + thread_affinity_policy_data_t policy = { core }; + mach_thread = pthread_mach_thread_np(pthread_self()); + thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1); + printf("############################# thread %d - %d\n", self_th_idx, core); + rot->lockstep(0); // 2. Each thread makes a RID holding unique data. @@ -212,7 +230,9 @@ TEST_CASE("[RID_Owner] Thread safety") { SUBCASE("All items in one chunk, pre-allocated") { RID_OwnerTester tester(true, true); - tester.test(); + for (int i = 0; i < 1000; i++) { + tester.test(); + } } #if 0 SUBCASE("All items in one chunk, NOT pre-allocated") {