[PATCH] libtracefs utest: Only use online CPUs during tests
Benjamin Drung <[email protected]> Fri, 05 Jun 2026 08:55:43 +0000
| Newsgroups | org.kernel.vger.linux-trace-devel |
|---|---|
| Message-ID | <[email protected]> |
From: Adrien Nader <[email protected]> We cannot do operations over offline cores. Virtual machines can routinely announce the presence of all of the host's cores and only make some of them online. This change assumes that all the online CPUs are continuously numbered and start at 0. While this is not perfect, it is still an improvement and might be enough, especially considering this touches tests only. Signed-off-by: Adrien Nader <[email protected]> --- utest/tracefs-utest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index e3ff215..665c7d9 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -181,7 +181,7 @@ static void save_affinity(void) { int cpus; - cpus = sysconf(_SC_NPROCESSORS_CONF); + cpus = sysconf(_SC_NPROCESSORS_ONLN); cpuset_save = CPU_ALLOC(cpus); cpuset = CPU_ALLOC(cpus); cpu_size = CPU_ALLOC_SIZE(cpus); @@ -216,7 +216,7 @@ static void test_iter_write(struct tracefs_instance *instance) int cpus; int ret; - cpus = sysconf(_SC_NPROCESSORS_CONF); + cpus = sysconf(_SC_NPROCESSORS_ONLN); save_affinity(); path = tracefs_instance_get_file(instance, "trace_marker"); @@ -243,7 +243,7 @@ static void test_iter_write(struct tracefs_instance *instance) static void iter_raw_events_on_cpu(struct tracefs_instance *instance, int cpu, bool snapshot) { - int cpus = sysconf(_SC_NPROCESSORS_CONF); + int cpus = sysconf(_SC_NPROCESSORS_ONLN); cpu_set_t *cpuset = NULL; int cpu_size = 0; int check = 0; @@ -292,7 +292,7 @@ static void iter_raw_events_on_cpu(struct tracefs_instance *instance, int cpu, b static void test_instance_iter_raw_events(struct tracefs_instance *instance) { - int cpus = sysconf(_SC_NPROCESSORS_CONF); + int cpus = sysconf(_SC_NPROCESSORS_ONLN); int ret; int i; @@ -317,7 +317,7 @@ static void test_iter_raw_events(void) static void test_instance_iter_snapshot_events(struct tracefs_instance *instance) { - int cpus = sysconf(_SC_NPROCESSORS_CONF); + int cpus = sysconf(_SC_NPROCESSORS_ONLN); int i; iter_raw_events_on_cpu(instance, -1, true); -- 2.53.0