In the speed test, set the CPU affinity to the expected best core

This commit is contained in:
Andrea Mazzoleni 2026-06-06 17:50:15 +02:00
parent bbd9ad0864
commit 8cd3bc5d0e
3 changed files with 208 additions and 1 deletions

View file

@ -112,10 +112,10 @@ void speed_crc(int nd, void** v, int size, int delta, int period)
} SPEED_STOP
printf("%8" PRIu64, ds / dt);
printf("\n");
}
#endif
printf("\n");
printf("\n");
}
void speed_hash(int nd, void** v, int size, int delta, int period)
@ -1399,6 +1399,29 @@ void speed_rec(int nd, void** v, int size, int delta, int period)
printf("\n");
}
void speed_affinity(void)
{
#if HAVE_LINUX_DEVICE
int num_cpus = sysconf(_SC_NPROCESSORS_CONF);
if (num_cpus <= 0)
return;
printf("Machine has %d cores\n", num_cpus);
int cpu = os_get_optimal_cpu();
if (cpu <= 0)
return;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) == 0) {
printf("Running on core %d\n", cpu);
}
#endif
}
void speed(int period, int nd, int size)
{
int i;
@ -1480,6 +1503,7 @@ void speed(int period, int nd, int size)
#else
printf("CPU of unknown architecture\n");
#endif
speed_affinity();
#if WORDS_BIGENDIAN
printf("Memory is big-endian %d-bit\n", (int)sizeof(void*) * 8);
#else