From patchwork Fri Dec 18 14:19:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 345802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8D31C2BBD5 for ; Fri, 18 Dec 2020 14:20:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A215E23AAA for ; Fri, 18 Dec 2020 14:20:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727860AbgLROUa (ORCPT ); Fri, 18 Dec 2020 09:20:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:37650 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbgLROU3 (ORCPT ); Fri, 18 Dec 2020 09:20:29 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A0278AF74; Fri, 18 Dec 2020 14:19:47 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests v1 1/6] cyclictest: Always use libnuma Date: Fri, 18 Dec 2020 15:19:30 +0100 Message-Id: <20201218141935.24151-2-dwagner@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201218141935.24151-1-dwagner@suse.de> References: <20201218141935.24151-1-dwagner@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org libnuma is hard dependency for cyclictest. Thus we can always call numa_initialize(). This allows us to remove the global 'numa' variable to track if libnuma has been initialized or not. Signed-off-by: Daniel Wagner --- src/cyclictest/cyclictest.c | 63 +++++++++++++++++-------------------- src/cyclictest/rt_numa.h | 2 -- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index f38c453f1975..514ed7b20fdb 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1018,9 +1018,6 @@ static void process_options(int argc, char *argv[], int max_cpus) /* smp sets AFFINITY_USEALL in OPT_SMP */ if (smp) break; - if (numa_initialize()) - fatal("Couldn't initialize libnuma"); - numa = 1; if (optarg) { parse_cpumask(optarg, max_cpus, &affinity_mask); setaffinity = AFFINITY_SPECIFIED; @@ -1126,8 +1123,6 @@ static void process_options(int argc, char *argv[], int max_cpus) use_system = MODE_SYS_OFFSET; break; case 'S': case OPT_SMP: /* SMP testing */ - if (numa) - fatal("numa and smp options are mutually exclusive\n"); smp = 1; num_threads = -1; /* update after parsing */ setaffinity = AFFINITY_USEALL; @@ -1201,16 +1196,17 @@ static void process_options(int argc, char *argv[], int max_cpus) /* if smp wasn't requested, test for numa automatically */ if (!smp) { - if (numa_initialize()) - fatal("Couldn't initialize libnuma"); - numa = 1; if (setaffinity == AFFINITY_UNSPECIFIED) setaffinity = AFFINITY_USEALL; } - if (option_affinity) { - if (smp) - warn("-a ignored due to smp mode\n"); + if (option_affinity && smp) { + warn("-a ignored due to smp mode\n"); + if (affinity_mask) { + numa_bitmask_free(affinity_mask); + affinity_mask = NULL; + } + setaffinity = AFFINITY_USEALL; } if (smi) { @@ -1744,6 +1740,12 @@ int main(int argc, char **argv) int max_cpus = sysconf(_SC_NPROCESSORS_ONLN); int i, ret = -1; int status; + void *stack; + void *currstk; + size_t stksize; + + if (numa_initialize()) + fatal("Couldn't initialize libnuma"); process_options(argc, argv, max_cpus); @@ -1926,34 +1928,27 @@ int main(int argc, char **argv) default: cpu = -1; } - node = -1; - if (numa) { - void *stack; - void *currstk; - size_t stksize; + /* find the memory node associated with the cpu i */ + node = rt_numa_numa_node_of_cpu(cpu); - /* find the memory node associated with the cpu i */ - node = rt_numa_numa_node_of_cpu(cpu); + /* get the stack size set for this thread */ + if (pthread_attr_getstack(&attr, &currstk, &stksize)) + fatal("failed to get stack size for thread %d\n", i); - /* get the stack size set for this thread */ - if (pthread_attr_getstack(&attr, &currstk, &stksize)) - fatal("failed to get stack size for thread %d\n", i); + /* if the stack size is zero, set a default */ + if (stksize == 0) + stksize = PTHREAD_STACK_MIN * 2; - /* if the stack size is zero, set a default */ - if (stksize == 0) - stksize = PTHREAD_STACK_MIN * 2; + /* allocate memory for a stack on appropriate node */ + stack = rt_numa_numa_alloc_onnode(stksize, node, cpu); - /* allocate memory for a stack on appropriate node */ - stack = rt_numa_numa_alloc_onnode(stksize, node, cpu); + /* touch the stack pages to pre-fault them in */ + memset(stack, 0, stksize); - /* touch the stack pages to pre-fault them in */ - memset(stack, 0, stksize); - - /* set the thread's stack */ - if (pthread_attr_setstack(&attr, stack, stksize)) - fatal("failed to set stack addr for thread %d to 0x%x\n", - i, stack+stksize); - } + /* set the thread's stack */ + if (pthread_attr_setstack(&attr, stack, stksize)) + fatal("failed to set stack addr for thread %d to 0x%x\n", + i, stack+stksize); /* allocate the thread's parameter block */ parameters[i] = par = threadalloc(sizeof(struct thread_param), node); diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h index 46690941e0a6..8d02f419ed6d 100644 --- a/src/cyclictest/rt_numa.h +++ b/src/cyclictest/rt_numa.h @@ -13,8 +13,6 @@ #include "rt-utils.h" #include "error.h" -static int numa = 0; - #include static void * From patchwork Fri Dec 18 14:19:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 345803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18BD7C3526C for ; Fri, 18 Dec 2020 14:20:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E55FE23AC1 for ; Fri, 18 Dec 2020 14:20:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727865AbgLROUb (ORCPT ); Fri, 18 Dec 2020 09:20:31 -0500 Received: from mx2.suse.de ([195.135.220.15]:37686 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727849AbgLROUa (ORCPT ); Fri, 18 Dec 2020 09:20:30 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 88D88B277; Fri, 18 Dec 2020 14:19:48 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests v1 4/6] cyclictest: Mimik --smp behavior with --affinity Date: Fri, 18 Dec 2020 15:19:33 +0100 Message-Id: <20201218141935.24151-5-dwagner@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201218141935.24151-1-dwagner@suse.de> References: <20201218141935.24151-1-dwagner@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Let --affinity without an argument behave in the same way as --smp. Run a thread on each CPU. This makes cyclictest behave as the rest of the rt-tests when --affinity is used. Reviewed-by: Daniel Wagner --- src/cyclictest/cyclictest.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 0e6519125c2f..b9b0eb3575e3 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1024,6 +1024,8 @@ static void process_options(int argc, char *argv[], int max_cpus) argv[optind][0] == '0' || argv[optind][0] == '!')) { parse_cpumask(argv[optind], max_cpus, &affinity_mask); + } else { + num_threads = -1; } if (verbose) From patchwork Fri Dec 18 14:19:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 345801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CABFDC2D0E4 for ; Fri, 18 Dec 2020 14:21:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 895B023AC0 for ; Fri, 18 Dec 2020 14:21:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727890AbgLROVK (ORCPT ); Fri, 18 Dec 2020 09:21:10 -0500 Received: from mx2.suse.de ([195.135.220.15]:37944 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbgLROVJ (ORCPT ); Fri, 18 Dec 2020 09:21:09 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 29536B720; Fri, 18 Dec 2020 14:19:49 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Daniel Wagner Subject: [rt-tests v1 6/6] cyclictest: Move verbose message into main Date: Fri, 18 Dec 2020 15:19:35 +0100 Message-Id: <20201218141935.24151-7-dwagner@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201218141935.24151-1-dwagner@suse.de> References: <20201218141935.24151-1-dwagner@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org By moving the verbose message down we print the message with the final affinity_mask. This also handles the case where the bitmask is not set. Signed-off-by: Daniel Wagner --- src/cyclictest/cyclictest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index a364b4ad203a..5abb69d0b28f 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1020,10 +1020,6 @@ static void process_options(int argc, char *argv[], int max_cpus) argv[optind][0] == '!')) { parse_cpumask(argv[optind], max_cpus, &affinity_mask); } - - if (verbose) - printf("Using %u cpus.\n", - numa_bitmask_weight(affinity_mask)); break; case 'A': case OPT_ALIGNED: @@ -1732,6 +1728,10 @@ int main(int argc, char **argv) res = numa_sched_setaffinity(getpid(), affinity_mask); if (res != 0) warn("Couldn't setaffinity in main thread: %s\n", strerror(errno)); + + if (verbose) + printf("Using %u cpus.\n", + numa_bitmask_weight(affinity_mask)); } if (trigger) {