From patchwork Wed Nov 18 19:06:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 327747 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.7 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 129B7C5519F for ; Wed, 18 Nov 2020 19:07:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A690120B1F for ; Wed, 18 Nov 2020 19:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727053AbgKRTG0 (ORCPT ); Wed, 18 Nov 2020 14:06:26 -0500 Received: from mx2.suse.de ([195.135.220.15]:48796 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726614AbgKRTG0 (ORCPT ); Wed, 18 Nov 2020 14:06:26 -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 3797CBACE; Wed, 18 Nov 2020 19:06:24 +0000 (UTC) From: Daniel Wagner To: Clark Williams , John Kacur Cc: linux-rt-users@vger.kernel.org, Sebastian Andrzej Siewior , Daniel Wagner Subject: [rt-tests v2 3/3] signaltest: Set affintiy on default Date: Wed, 18 Nov 2020 20:06:22 +0100 Message-Id: <20201118190622.15885-1-dwagner@suse.de> X-Mailer: git-send-email 2.29.2 Reply-To: 20201115184059.7286-4-dwagner@suse.de MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Make signaltest a bit more userfriendly and move all threads on the same CPU the default behavior. Signed-off-by: Daniel Wagner --- v2: fix compile warnings src/include/rt-numa.h | 1 + src/lib/rt-numa.c | 22 ++++++++++++++++++++++ src/signaltest/signaltest.c | 4 +--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/include/rt-numa.h b/src/include/rt-numa.h index ca86a45dab3a..f52de1ca68d7 100644 --- a/src/include/rt-numa.h +++ b/src/include/rt-numa.h @@ -15,6 +15,7 @@ int numa_initialize(void); int get_available_cpus(struct bitmask *cpumask); int cpu_for_thread_sp(int thread_num, int max_cpus, struct bitmask *cpumask); int cpu_for_thread_ua(int thread_num, int max_cpus); +int cpu_for_thread(int max_cpus); int parse_cpumask(char *str, int max_cpus, struct bitmask **cpumask); diff --git a/src/lib/rt-numa.c b/src/lib/rt-numa.c index 76f8bd2f0ebe..49cebdf9e801 100644 --- a/src/lib/rt-numa.c +++ b/src/lib/rt-numa.c @@ -87,6 +87,28 @@ int cpu_for_thread_ua(int thread_num, int max_cpus) return 0; } +int cpu_for_thread(int max_cpus) +{ + int res, i; + pthread_t thread; + cpu_set_t cpuset; + + thread = pthread_self(); + CPU_ZERO(&cpuset); + + res = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset); + if (res != 0) + fatal("pthread_getaffinity_np failed: %s\n", strerror(res)); + + for (i = 0; i < max_cpus; i++) { + if (CPU_ISSET(i, &cpuset)) + return i; + } + + fprintf(stderr, "Bug in cpu mask handling code.\n"); + return 0; +} + /* * After this function is called, affinity_mask is the intersection of * the user supplied affinity mask and the affinity mask from the run diff --git a/src/signaltest/signaltest.c b/src/signaltest/signaltest.c index e19877a395ba..5aa0003501b3 100644 --- a/src/signaltest/signaltest.c +++ b/src/signaltest/signaltest.c @@ -301,8 +301,6 @@ static void process_options(int argc, char *argv[], unsigned int max_cpus) if (numa_initialize()) fatal("Couldn't initilize libnuma"); numa = 1; - if (setaffinity == AFFINITY_UNSPECIFIED) - setaffinity = AFFINITY_USEALL; } if (option_affinity) { @@ -404,7 +402,7 @@ int main(int argc, char **argv) switch (setaffinity) { case AFFINITY_UNSPECIFIED: - cpu = -1; + cpu = cpu_for_thread(max_cpus); break; case AFFINITY_SPECIFIED: cpu = cpu_for_thread_sp(i, max_cpus, affinity_mask);