From patchwork Wed Jul 10 13:12:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shizhao Chen X-Patchwork-Id: 1958840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=a57NFAvh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WJyvx3pSLz1xqc for ; Wed, 10 Jul 2024 23:13:00 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 989393D3831 for ; Wed, 10 Jul 2024 15:12:57 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5932D3D3818 for ; Wed, 10 Jul 2024 15:12:54 +0200 (CEST) Authentication-Results: in-3.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=shichen@redhat.com; receiver=lists.linux.it) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 8177E1A0114D for ; Wed, 10 Jul 2024 15:12:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720617171; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jvbz8jCu9pW44p5wMBQt9wVd9XdjzW76brou1+pcMtA=; b=a57NFAvhMLv7lQv4mVFThteMY/L2/PBV/qF2jkvSCs5cKJWkub6N+8lVOtG+TFIbwwr9WL UG18YIIFqpUQ+o5SmIMbXwhvTPjOL4ZYQMaGA47Sfd5rIxyXbApjVWEsAbb5JCYdQA6PSk A0E0qtiA5jFjAOOQbpuEOZJFO2EMZOA= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-1gG_3-jwMAeVJQqlHOmPsQ-1; Wed, 10 Jul 2024 09:12:50 -0400 X-MC-Unique: 1gG_3-jwMAeVJQqlHOmPsQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4EABF19560AB for ; Wed, 10 Jul 2024 13:12:49 +0000 (UTC) Received: from loobloo.redhat.com (unknown [10.72.112.170]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F07351955E85; Wed, 10 Jul 2024 13:12:46 +0000 (UTC) From: Shizhao Chen To: ltp@lists.linux.it, Li Wang Date: Wed, 10 Jul 2024 21:12:41 +0800 Message-ID: <20240710131241.193232-1-shichen@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-3.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-3.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2] realtime/prio-preempt: take cpu isolation into consideration X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eder Zulian Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 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 --- .../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 #include #include @@ -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;