From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: "Michal Koutný" <mkoutny@suse.com>
Subject: [LTP] [PATCH v2 1/2] memcontrol: Add bind_to_current_cpu() helper
Date: Wed, 30 Sep 2026 03:53:14 +0000 [thread overview]
Message-ID: <20260930035332.3360-2-wegao@suse.com> (raw)
In-Reply-To: <20260930035332.3360-1-wegao@suse.com>
Add bind_to_current_cpu() to memcontrol_common.h to allow memcg tests
to bind the test process to a single CPU.
Signed-off-by: Wei Gao <wegao@suse.com>
---
.../controllers/memcg/memcontrol_common.h | 27 +++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/testcases/kernel/controllers/memcg/memcontrol_common.h b/testcases/kernel/controllers/memcg/memcontrol_common.h
index 495f924a0..0f5021c0d 100644
--- a/testcases/kernel/controllers/memcg/memcontrol_common.h
+++ b/testcases/kernel/controllers/memcg/memcontrol_common.h
@@ -52,4 +52,31 @@ static inline void alloc_anon(const size_t size)
free(buf);
}
+static inline void bind_to_current_cpu(void)
+{
+ int cpu = sched_getcpu();
+ size_t mask_size;
+ cpu_set_t *mask;
+
+ if (cpu < 0)
+ tst_brk(TBROK | TERRNO, "sched_getcpu() failed");
+
+ tst_res(TINFO, "Binding test process to CPU %d", cpu);
+
+ mask = CPU_ALLOC(cpu + 1);
+ if (!mask)
+ tst_brk(TBROK | TERRNO, "CPU_ALLOC() failed");
+
+ mask_size = CPU_ALLOC_SIZE(cpu + 1);
+ CPU_ZERO_S(mask_size, mask);
+ CPU_SET_S(cpu, mask_size, mask);
+
+ if (sched_setaffinity(0, mask_size, mask) < 0) {
+ CPU_FREE(mask);
+ tst_brk(TBROK | TERRNO, "sched_setaffinity() failed");
+ }
+
+ CPU_FREE(mask);
+}
+
#endif /* MEMCONTROL_COMMON_H__ */
--
2.55.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-09-30 3:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 2:23 [LTP] [PATCH v1] memcontrol03: Bind to single CPU on systems with 64KB pagesize Wei Gao via ltp
2026-09-29 4:35 ` [LTP] " linuxtestproject.agent
2026-09-29 17:01 ` [LTP] [PATCH v1] " Michal Koutný via ltp
2026-09-30 3:53 ` [LTP] [PATCH v2 0/2] memcontrol03, memcontrol04: Bind test process to a single CPU Wei Gao via ltp
2026-09-30 3:53 ` Wei Gao via ltp [this message]
2026-09-30 8:11 ` [LTP] memcontrol: Add bind_to_current_cpu() helper linuxtestproject.agent
2026-09-30 11:25 ` Wei Gao via ltp
2026-09-30 3:53 ` [LTP] [PATCH v2 2/2] memcontrol03, memcontrol04: Bind test process to a single CPU Wei Gao via ltp
[not found] ` <20260929-second-foyer-87225078267f@there>
2026-09-30 3:55 ` [LTP] [PATCH v1] memcontrol03: Bind to single CPU on systems with 64KB pagesize Wei Gao via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260930035332.3360-2-wegao@suse.com \
--to=ltp@lists.linux.it \
--cc=mkoutny@suse.com \
--cc=wegao@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.