From: Shizhao Chen <shichen@redhat.com>
To: ltp@lists.linux.it, Li Wang <liwang@redhat.com>
Cc: Eder Zulian <ezulian@redhat.com>
Subject: [LTP] [PATCH v2] realtime/prio-preempt: take cpu isolation into consideration
Date: Wed, 10 Jul 2024 21:12:41 +0800 [thread overview]
Message-ID: <20240710131241.193232-1-shichen@redhat.com> (raw)
In-Reply-To: <CAEemH2f=PzW68A2NzdfM0BDNKRHX4sfytCkzN4oG-USPHuJk9g@mail.gmail.com>
By default the test starts N-1 busy threads to monopolize N-1 available CPUs,
where N is the number of all available CPUs. However, when CPU isolation is
applied, this will lead to a hang scenario where all housekeeping CPUs are
hogged as isolated CPUs do not share the N-1 busy threads.
Signed-off-by: Shizhao Chen <shichen@redhat.com>
---
.../realtime/func/prio-preempt/prio-preempt.c | 20 ++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/testcases/realtime/func/prio-preempt/prio-preempt.c b/testcases/realtime/func/prio-preempt/prio-preempt.c
index 9bd5e7ad8..16abc1184 100644
--- a/testcases/realtime/func/prio-preempt/prio-preempt.c
+++ b/testcases/realtime/func/prio-preempt/prio-preempt.c
@@ -59,6 +59,7 @@
*
*****************************************************************************/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
@@ -287,6 +288,19 @@ void *master_thread(void *arg)
return NULL;
}
+int get_numcpus(void)
+{
+ long numcpus_conf = sysconf(_SC_NPROCESSORS_CONF);
+ size_t size = CPU_ALLOC_SIZE(numcpus_conf);
+ cpu_set_t *cpuset = CPU_ALLOC(numcpus_conf);
+
+ CPU_ZERO_S(size, cpuset);
+ /* Get the number of cpus accessible to the current process */
+ sched_getaffinity(0, size, cpuset);
+
+ return CPU_COUNT_S(size, cpuset);
+}
+
int main(int argc, char *argv[])
{
int pri_boost, numcpus;
@@ -295,10 +309,10 @@ int main(int argc, char *argv[])
pass_criteria = CHECK_LIMIT;
rt_init("hin:", parse_args, argc, argv);
- numcpus = sysconf(_SC_NPROCESSORS_ONLN);
+ numcpus = get_numcpus();
- /* Max no. of busy threads should always be less than/equal the no. of cpus
- Otherwise, the box will hang */
+ /* Max no. of busy threads should always be less than/equal the no. of
+ housekeeping cpus. Otherwise, the box will hang */
if (rt_threads == -1 || rt_threads > numcpus) {
rt_threads = numcpus;
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-07-10 13:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 3:24 [LTP] [PATCH] realtime/prio-preempt: take cpu isolation into consideration Shizhao Chen
2024-07-10 6:13 ` Li Wang
2024-07-10 6:27 ` Li Wang
2024-07-10 13:12 ` Shizhao Chen [this message]
2024-07-11 6:56 ` [LTP] [PATCH v2] " Li Wang
2024-07-10 13:16 ` [LTP] [PATCH] " Shizhao Chen
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=20240710131241.193232-1-shichen@redhat.com \
--to=shichen@redhat.com \
--cc=ezulian@redhat.com \
--cc=liwang@redhat.com \
--cc=ltp@lists.linux.it \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox