From patchwork Wed Mar 4 21:55:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Kacur X-Patchwork-Id: 213187 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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 14BF2C3F2CE for ; Wed, 4 Mar 2020 21:56:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E101F20716 for ; Wed, 4 Mar 2020 21:56:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eN1I7xkX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388422AbgCDV4C (ORCPT ); Wed, 4 Mar 2020 16:56:02 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:43156 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727835AbgCDV4C (ORCPT ); Wed, 4 Mar 2020 16:56:02 -0500 Received: by mail-qt1-f193.google.com with SMTP id v22so2606218qtp.10 for ; Wed, 04 Mar 2020 13:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9b43QogsS9kdbLJ2eqbuzmiK0NZtjtA6Q4q+Rwo4wjk=; b=eN1I7xkXDxR5sBRMfyXOYNN3ksa/K7He5YzRtpRk/vi1w+iPtTvQFEwy76YAR55723 jmIfLkVRVn9iPFS/1FS9wb9mbxKT+X/3XRh49ZJoxPEZ1A12DcSkwTySCeeAXoqqaATX zbYgJxOSmtAaBtIV5O0fjgl/Zk1hYrK50SqOqNEqPxb0DkBDhveajZ+He9g1Suf9SN9l ody4lKthUyzmjHxJnWsU+/+ATBKNYCu/jSiG4HZcVD7Df1nQuIB3OccYuEujTEhl7yYg QddofA7f/Y7+HluWuFol5s8rYIo++moNuyM1CbjD8BUFqx0uxFz6q2IXNyQYdiRSxihd OVcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9b43QogsS9kdbLJ2eqbuzmiK0NZtjtA6Q4q+Rwo4wjk=; b=fyWP5NgMX1SeLFwOgCY2LmvdG0+X+aLKoBiNnGr/rDt8w4Y2ue5TLb/WHmdOrE92EO c8Iw6fn0+7qGlhiHFZyTWFY5WY2bBBZ5+EWVdja+lyKADplQrdveGSdU9jmMRDbyyOl7 l5WkhX2gwSsF9paUAmXVO7JOMJT9DjhtaCd0AeG/56hKdUy7dByElSbxkmRvlcL/Zahe haZegh4lhDzh/L6Srg2IKlTcIzUJwssrvOXiiNDrPcI6IoHqxOsN+fLoBRClfxwHrGKi bry0sq96wvzdfqJpGDka4rlLxry5YTmug4U9gVB3i67tdHkJP2bpgd8xPNEUfdMAj6wq SISw== X-Gm-Message-State: ANhLgQ2MTyoK1QvCDTUkngkiBZ4SEx2f6ja/7iHJ0QLJ4whKu+NdqYPn ZFXkh7clTSALXEzm1UJu4NgQ3XQz2XY= X-Google-Smtp-Source: ADFU+vtPwQ8M2iEpjJIrSuP2V0bPkOOQv2cA5C0QeUZviYuoC2SmpBVtSa52/wqk8o+jzqQc+IyZRA== X-Received: by 2002:ac8:73c7:: with SMTP id v7mr4415631qtp.269.1583358959191; Wed, 04 Mar 2020 13:55:59 -0800 (PST) Received: from planxty.redhat.com (rdwyon0600w-lp130-03-64-231-46-127.dsl.bell.ca. [64.231.46.127]) by smtp.gmail.com with ESMTPSA id f5sm4899164qtq.72.2020.03.04.13.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 13:55:58 -0800 (PST) From: John Kacur To: rt-users Cc: Clark Williams , John Kacur Subject: [PATCH 2/4] rt-tests: cyclictest: Remove support for compiling without NUMA Date: Wed, 4 Mar 2020 16:55:46 -0500 Message-Id: <20200304215548.13079-2-jkacur@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200304215548.13079-1-jkacur@redhat.com> References: <20200304215548.13079-1-jkacur@redhat.com> MIME-Version: 1.0 Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org We announced way back in 2015 that compiling without the NUMA libs was no-longer supported, but we left the bits in there for you to do it anyway. Since this is not supported, and is broken now anyway, let's remove the cruft. Of course running on non-NUMA machines should still work fine. Signed-off-by: John Kacur --- Makefile | 17 +++------- src/cyclictest/rt_numa.h | 67 ---------------------------------------- 2 files changed, 4 insertions(+), 80 deletions(-) diff --git a/Makefile b/Makefile index 186eccb1c882..1475007d7bb4 100644 --- a/Makefile +++ b/Makefile @@ -76,19 +76,10 @@ ostype := $(lastword $(subst -, ,$(dumpmachine))) machinetype := $(shell echo $(dumpmachine)| \ sed -e 's/-.*//' -e 's/i.86/i386/' -e 's/mips.*/mips/' -e 's/ppc.*/powerpc/') -# The default is to assume you have libnuma installed, which is fine to do -# even on non-numa machines. If you don't want to install the numa libs, for -# example, they might not be available in an embedded environment, then -# compile with -# make NUMA=0 -ifneq ($(filter x86_64 i386 ia64 mips powerpc,$(machinetype)),) -NUMA := 1 -endif - -ifeq ($(NUMA),1) - CFLAGS += -DNUMA - NUMA_LIBS = -lnuma -endif +# You have to have libnuma installed, which is fine to do even if you are +# running on non-numa machines +CFLAGS += -DNUMA +NUMA_LIBS = -lnuma include src/arch/android/Makefile diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h index 466f0b68f801..46690941e0a6 100644 --- a/src/cyclictest/rt_numa.h +++ b/src/cyclictest/rt_numa.h @@ -1,8 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * A numa library for cyclictest. - * The functions here are designed to work whether cyclictest has been - * compiled with numa support or not. * * (C) 2010 John Kacur * (C) 2010 Clark Williams @@ -17,7 +15,6 @@ static int numa = 0; -#ifdef NUMA #include static void * @@ -86,70 +83,6 @@ static inline void rt_bitmask_free(struct bitmask *mask) numa_bitmask_free(mask); } - -#else /* ! NUMA */ - -struct bitmask { - unsigned long size; /* number of bits in the map */ - unsigned long *maskp; -}; -#define BITS_PER_LONG (8*sizeof(long)) - -static inline void *threadalloc(size_t size, int n) { return malloc(size); } -static inline void threadfree(void *ptr, size_t s, int n) { free(ptr); } -static inline void rt_numa_set_numa_run_on_node(int n, int c) { } -static inline int rt_numa_numa_node_of_cpu(int cpu) { return -1; } -static void *rt_numa_numa_alloc_onnode(size_t s, int n, int c) { return NULL; } - -/* - * Map legacy CPU affinity behavior onto bit mask infrastructure - */ -static inline unsigned int rt_numa_bitmask_isbitset( const struct bitmask *mask, - unsigned long i) -{ - long bit = mask->maskp[i/BITS_PER_LONG] & (1<<(i % BITS_PER_LONG)); - return (bit != 0); -} - -static inline struct bitmask* rt_numa_parse_cpustring(const char* s, - int max_cpus) -{ - int cpu; - struct bitmask *mask = NULL; - cpu = atoi(s); - if (0 <= cpu && cpu < max_cpus) { - mask = malloc(sizeof(*mask)); - if (mask) { - /* Round up to integral number of longs to contain - * max_cpus bits */ - int nlongs = (max_cpus+BITS_PER_LONG-1)/BITS_PER_LONG; - - mask->maskp = calloc(nlongs, sizeof(unsigned long)); - if (mask->maskp) { - mask->maskp[cpu/BITS_PER_LONG] |= - (1UL << (cpu % BITS_PER_LONG)); - mask->size = max_cpus; - } else { - free(mask); - mask = NULL; - } - } - } - return mask; -} - -static inline void rt_bitmask_free(struct bitmask *mask) -{ - free(mask->maskp); - free(mask); -} - -#endif /* NUMA */ - -/* - * Any behavioral differences above are transparent to these functions - */ - /** Returns number of bits set in mask. */ static inline unsigned int rt_numa_bitmask_count(const struct bitmask *mask) { From patchwork Wed Mar 4 21:55:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Kacur X-Patchwork-Id: 213186 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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 B2600C3F2D8 for ; Wed, 4 Mar 2020 21:56:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8ABAC20716 for ; Wed, 4 Mar 2020 21:56:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UYSPuFbJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388440AbgCDV4E (ORCPT ); Wed, 4 Mar 2020 16:56:04 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:35114 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727835AbgCDV4D (ORCPT ); Wed, 4 Mar 2020 16:56:03 -0500 Received: by mail-qt1-f193.google.com with SMTP id v15so2638873qto.2 for ; Wed, 04 Mar 2020 13:56:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YvNUnxeez6v2XKBQb75FCk1D6hj07Yfy/QQuzuSUQTQ=; b=UYSPuFbJrXX6zPxb8y/0HMq8iTPInMa1Wcv+g7UAPYOyecAMBC8b7Az1gxwxRd5e0E irOKNE+Pptxuk6vX99jkUmT7lEKF1qRA6WGMzs8fAhGDMgnVnF9EPfk3WL39YeVHXOlv woUQJlaBP1cuYYiOYNIMf2Q6HaJrTrKT5Dq6cbtARZ1yRB+4l2iSNHc8jw+MvvgfdFP3 fhYRtMCBxtgdujgVR4hJXPDcYpyK3P3h2A5IESwRXuUQwlsr+oUQGqMa2m4MsrSxb26e sG9xkP5eeaK7ojO1psojG1XasNvG80JzNIf+aoIWdduNucNksIS8XBU1Z0/FavWr3k0u HlCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=YvNUnxeez6v2XKBQb75FCk1D6hj07Yfy/QQuzuSUQTQ=; b=oJ4tC24Jg4VatLwTQ7rNaxJXgN16GOJvHomn1a7WXpE+YZWLmiwUrcg3T2yX+/YiwB kSUr2xG704755kaZLvgNjpz/+rRp7O8gJxoEWauhMeEzl61c66G5eVKMIL8HlZfmpodp 2eaodUN1lLHN30OIf3hAtgxvJJPdJLzcnyslLUWTcafW4sCDQ/LO8KqkmPyvskTVeAKa bF71E700Ke/ibP/8Br4BZq6fSHXstqb0XQ19PgmS79/reyOoQzUPBEM2oCvj9K8U+IHO MepfJ/6/oqWIyvd1CcfEggSpSfB2RQlfWURKv6oi0J2NWA/0R6aevTNnnCJqx460XCHu mPzg== X-Gm-Message-State: ANhLgQ0zjrrKfsSGFl7OhYCWy5qlha7EUsV4cS9Za7JwEJ+m4laBEBTO DzVFRNu3u8ksFwT3TB0japrVky/opgA= X-Google-Smtp-Source: ADFU+vu2v0UL81vf9+X50UqaSNsSIihDY/3QXF/8u9nKQDrhUjaJUZcQQyRJWJQdZHYDGZjZTMfyQQ== X-Received: by 2002:ac8:ac1:: with SMTP id g1mr4418943qti.287.1583358961126; Wed, 04 Mar 2020 13:56:01 -0800 (PST) Received: from planxty.redhat.com (rdwyon0600w-lp130-03-64-231-46-127.dsl.bell.ca. [64.231.46.127]) by smtp.gmail.com with ESMTPSA id f5sm4899164qtq.72.2020.03.04.13.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 13:56:00 -0800 (PST) From: John Kacur To: rt-users Cc: Clark Williams , John Kacur Subject: [PATCH 4/4] rt-tests: cyclictest: Fix -t without a user specified [NUM] Date: Wed, 4 Mar 2020 16:55:48 -0500 Message-Id: <20200304215548.13079-4-jkacur@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200304215548.13079-1-jkacur@redhat.com> References: <20200304215548.13079-1-jkacur@redhat.com> MIME-Version: 1.0 Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org Fix -t without a specified [NUM] to run the same number of threads as available processors. Currently it runs the same number of threads as cpus on a system. However, if cyclictest is contrained to run on a smaller set of cpus either because of a container or a user specified affinity or a combination of the two, then the actual number of available cpus is smaller. -t should reflect that. Signed-off-by: John Kacur --- src/cyclictest/cyclictest.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index f8df4c6954ad..c5f1fd46567a 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1040,6 +1040,35 @@ static unsigned int is_cpumask_zero(const struct bitmask *mask) return (rt_numa_bitmask_count(mask) == 0); } +/* Get available cpus according to getaffinity or according to the + * intersection of getaffinity and the user specified affinity + * in the case of AFFINITY_SPECIFIED, the function has to be called + * after the call to parse_cpumask made in process_options() + */ +static int get_available_cpus(void) +{ + int num_cpus = 0; + int res; + pthread_t thread; + cpu_set_t cpuset; + + + if (affinity_mask != NULL) { + num_cpus = rt_numa_bitmask_count(affinity_mask); + } else { + CPU_ZERO(&cpuset); + thread = pthread_self(); + res = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset); + if (res != 0) { + fatal("pthread_getaffinity_np failed: %s\n", strerror(res)); + } + num_cpus = CPU_COUNT(&cpuset); + } + + return num_cpus; + +} + /* cpu_for_thread AFFINITY_SPECIFIED */ static int cpu_for_thread_sp(int thread_num, int max_cpus) { @@ -1358,7 +1387,7 @@ static void process_options (int argc, char *argv[], int max_cpus) if (numa) fatal("numa and smp options are mutually exclusive\n"); smp = 1; - num_threads = max_cpus; + num_threads = -1; /* update after parsing */ setaffinity = AFFINITY_USEALL; break; case 't': @@ -1372,7 +1401,7 @@ static void process_options (int argc, char *argv[], int max_cpus) else if (optind 99) error = 1; + if (num_threads == -1) + num_threads = get_available_cpus(); + if (priospread && priority == 0) { fprintf(stderr, "defaulting realtime priority to %d\n", num_threads+1);