benchmark icon indicating copy to clipboard operation
benchmark copied to clipboard

[BUG] Core Affinity doesn't seem to work (Or Reporter wrong?)

Open FabianSchuetze opened this issue 7 months ago • 5 comments

Describe the bug I would like to run the benchmark on a particular CPU core. The [docs]( says:

2. Set the benchmark program's task affinity to a fixed cpu.  For example:
   ```sh
   taskset -c 0 ./mybenchmark

However, when I run the basic_test app, I see the following:

build git:(main) taskset -c 0 ./test/basic_test
2024-07-11T11:29:31+02:00
Running ./test/basic_test
Run on (24 X 4700 MHz CPU s)
CPU Caches:
  L1 Data 48 KiB (x12)
  L1 Instruction 32 KiB (x12)
  L2 Unified 1280 KiB (x12)
  L3 Unified 25600 KiB (x1)
Load Average: 5.07, 4.92, 2.97
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
-----------------------------------------------------------------------------------------
Benchmark                                               Time             CPU   Iterations
-----------------------------------------------------------------------------------------
BM_empty                                            0.327 ns        0.325 ns   2148747493
BM_empty/threads:24                                 0.296 ns        0.328 ns   2130524928
...

I think it might be reporting here that is wrong. Looking at top, I can verify that only core 0 is used. The code in reporter[https://github.com/google/benchmark/blob/main/src/reporter.cc#L49C29-L49C37) seems to use a static number of cores.

System Which OS, compiler, and compiler version are you using:

  • OS: ubuntu 22.04
  • Compiler and version: gcc 11.4

To reproduce Steps to reproduce the behavior:

  1. sync to commit : ea71a14891474943fc1f34d359f9e0e82476ffe1
  2. cmake: cmake -D BENCHMARK_DOWNLOAD_DEPENDENCIES=1 -S . -B build
  3. make: cmake --build build/ -j20
  4. taskset -c 0 ./build/test/basic_test

Expected behavior I would expect the test to run only on core 0 and the output of the test be: Run on (1 X 4700 MHz CPU s) instead of Run on (24 X 4700 MHz CPU s)

FabianSchuetze avatar Jul 11 '24 09:07 FabianSchuetze