[LTP] [PATCH v3 3/4] getrusage03: Use tst_bind_to_current_cpu() helper
Wei Gao
wegao@suse.com
Fri Nov 13 05:11:32 CET 2026
Replace the local duplicate pin_to_current_cpu() implementation
with the tst_bind_to_current_cpu() library helper.
Signed-off-by: Wei Gao <wegao@suse.com>
---
.../kernel/syscalls/getrusage/getrusage03.c | 32 +------------------
1 file changed, 1 insertion(+), 31 deletions(-)
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.c b/testcases/kernel/syscalls/getrusage/getrusage03.c
index d4dca8070..090c46dfc 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.c
@@ -18,8 +18,6 @@
#include <stdlib.h>
#include "tst_test.h"
-#include "lapi/cpuset.h"
-#include "lapi/sched.h"
#include "getrusage03.h"
#define TESTBIN "getrusage03_child"
@@ -33,34 +31,6 @@ static const char *const resource[] = {
NULL,
};
-/*
- * Pin the test to the CPU it runs on. Every forked or exec'd child inherits
- * the affinity, so only that CPU can hold RSS counter updates outside the
- * fast percpu_counter read.
- */
-static void pin_to_current_cpu(void)
-{
- unsigned int cpu;
- cpu_set_t *set;
- size_t size;
-
- if (getcpu(&cpu, NULL))
- tst_brk(TBROK | TERRNO, "getcpu() failed");
-
- set = CPU_ALLOC(cpu + 1);
- if (!set)
- tst_brk(TBROK | TERRNO, "CPU_ALLOC() failed");
-
- size = CPU_ALLOC_SIZE(cpu + 1);
- CPU_ZERO_S(size, set);
- CPU_SET_S(cpu, size, set);
- if (sched_setaffinity(0, size, set))
- tst_brk(TBROK | TERRNO, "sched_setaffinity() failed");
-
- CPU_FREE(set);
- tst_res(TINFO, "Pinned to CPU %u", cpu);
-}
-
/*
* The pinned CPU can still hold up to one percpu_counter batch,
* max(32, 2 * online CPUs) pages, outside the fast RSS read.
@@ -80,7 +50,7 @@ static void setup(void)
tst_res(TINFO, "%li online CPUs, lower RSS allowance %li KiB",
online_cpus, lower_allowance);
- pin_to_current_cpu();
+ tst_bind_to_current_cpu();
}
static void check_maxrss(long actual, long expected, const char *name,
--
2.55.0
More information about the ltp
mailing list