Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp32928pxm; Fri, 25 Feb 2022 03:26:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJzw8i1+kiDSpEVtW3XS+3LPFwfH+HPEZ4yepW9Yju0fqvHr+yL4pbFdVQ+7lzKUP+0NXpve X-Received: by 2002:a17:90a:5b06:b0:1b8:b705:470b with SMTP id o6-20020a17090a5b0600b001b8b705470bmr2714720pji.168.1645788405156; Fri, 25 Feb 2022 03:26:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645788405; cv=none; d=google.com; s=arc-20160816; b=FDCNxMbvYAyiGT2ND7UuT3BRpbyiMUQN+90Q55Hv7vNg+8xBy2AT+yeJdrZXXgxDQe 7msueEwldFbwh8ivxwptkmxp4Sp4wObng2xpd0sNWeQ09N/I/NCRyr3Yq0nhvkB6C0g3 9/EhVMPirYakw8XMLfbNORhi3on8aLuk/crLxF0sf+TbMMv8alS8t5gCY47mTgHlys8Q ENtKoJrX7tVnamNj6vySjlJWR9qJw8yaEKN8QhKnEYXk6QC0+Vo2W+03ei7CTuzEsd5D lWh6Optv4LZ5xu7uuyS/IA7nPmAHXTZvWmqsgdYvLOgdUwkipRnw+hDKQIdW8Q649Pax xRLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=aHhkGLJ9yuf7vcXJSAko13f2p5z/x3RDCJk+eeegtiU=; b=ZRX6P+XWHtUlI9b1LxC8k1XSDpL0/hzimnPooN6OlQ4xtg4Cgd3yYjDyVM9eTRTK1S U8wh4bLosjbyxogzUl6GU/fOLSmAPiifD2D23atJ+Y1b54vXgJ8pJpU90GK+7pIscFo+ vAOx90YDUfkEDLSOoAtwpwLQMEpDPBezCf8dphB/tFO9I7hMMABXrirKUsNLN52KZ1Um jtaNNd+n8sgrygAWpeJAshrpGX0jHU3Yn3ZO4q5tGkJufnadTxhkOaev2Tw+QNF6V0i0 v57lnt/ceqEpPeUol6XqmDBqcxJTQ18LKeDoQL5e/sS16gdTPwfmUpdhtOlJ3RpkoN/O GTUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x10-20020a1709027c0a00b0015008db63e4si1441344pll.303.2022.02.25.03.26.31; Fri, 25 Feb 2022 03:26:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237614AbiBYFuK (ORCPT + 99 others); Fri, 25 Feb 2022 00:50:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbiBYFuJ (ORCPT ); Fri, 25 Feb 2022 00:50:09 -0500 Received: from mx1.molgen.mpg.de (mx3.molgen.mpg.de [141.14.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A06D0B458A; Thu, 24 Feb 2022 21:49:36 -0800 (PST) Received: from [192.168.0.2] (ip5f5aee37.dynamic.kabel-deutschland.de [95.90.238.55]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: pmenzel) by mx.molgen.mpg.de (Postfix) with ESMTPSA id 1675D61EA1939; Fri, 25 Feb 2022 06:49:33 +0100 (CET) Message-ID: Date: Fri, 25 Feb 2022 06:49:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH 2/2] torture: Make thread detection more robust by using lspcu Content-Language: en-US To: "Paul E. McKenney" Cc: Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Shuah Khan , Zhouyi Zhou , rcu@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220222120718.17141-1-pmenzel@molgen.mpg.de> <20220222120718.17141-2-pmenzel@molgen.mpg.de> <20220222174328.GL4285@paulmck-ThinkPad-P17-Gen-1> <1084da08-f67d-b5d7-add4-580e9246b7b7@molgen.mpg.de> <20220224205617.GY4285@paulmck-ThinkPad-P17-Gen-1> From: Paul Menzel In-Reply-To: <20220224205617.GY4285@paulmck-ThinkPad-P17-Gen-1> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dear Paul, Am 24.02.22 um 21:56 schrieb Paul E. McKenney: > On Thu, Feb 24, 2022 at 09:24:11AM +0100, Paul Menzel wrote: >> Am 22.02.22 um 18:43 schrieb Paul E. McKenney: >>> On Tue, Feb 22, 2022 at 01:07:17PM +0100, Paul Menzel wrote: >>>> For consecutive numbers *lscpu* collapses the output and just shows the >>>> range with start and end. The processors are numbered that way on POWER8. >>>> >>>> $ sudo ppc64_cpu --smt=8 >>>> $ lscpu | grep '^NUMA node' >>>> NUMA node(s): 2 >>>> NUMA node0 CPU(s): 0-79 >>>> NUMA node8 CPU(s): 80-159 >>>> >>>> This causes the heuristic to detect the number threads per core, looking >>>> for the number after the first comma, to fail, and QEMU aborts because of >>>> invalid arguments. >>>> >>>> $ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' >>>> $ >>>> >>>> (Before the last patch, the whole line was returned.) >>>> >>>> $ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/' >>>> NUMA node0 CPU(s): 0-79 >>>> >>>> *lscpu* shows the number of threads per core, so use that value directly. >>>> >>>> $ sudo ppc64_cpu --smt=8 >>>> $ lscpu | grep 'Thread(s) per core' >>>> Thread(s) per core: 8 >>>> $ sudo ppc64_cpu --smt=off >>>> $ lscpu | grep 'Thread(s) per core' >>>> Thread(s) per core: 1 >>>> >>>> Note, the replaced heuristic is also incorrect for that case, where the >>>> threads per core are disabled. >>>> >>>> $ lscpu | sed -n -e '/^NUMA node0/s/^[^,]*,\([0-9]*\),.*$/\1/p' >>>> 8 >>>> >>>> Signed-off-by: Paul Menzel >>> >>> Makes sense, and thank you for chasing this down and for the fix! >>> >>> But should this patch and 1/2 be merged? Or am I confused and they >>> are somehow affecting two different lines of scripting? >> >> You are right. I guess with 1/2 I just wanted to document clearly, what I >> learned in #sed@irc.libera.chat, that means, how to avoid using grep, when >> sed is used. > > Nothing wrong with that! > > I have merged the two patches as shown below. Does this work for you? > > Thanx, Paul > > ------------------------------------------------------------------------ > > commit 9f0daba62e958c31326c7a9eae33651e3a3cc6b4 > Author: Paul Menzel > Date: Tue Feb 22 13:07:16 2022 +0100 > > torture: Make thread detection more robust by using lspcu > > For consecutive numbers the lscpu command collapses the output and just > shows the range with start and end. The processors are numbered that > way on POWER8. > > $ sudo ppc64_cpu --smt=8 > $ lscpu | grep '^NUMA node' > NUMA node(s): 2 > NUMA node0 CPU(s): 0-79 > NUMA node8 CPU(s): 80-159 > > This causes the heuristic to detect the number threads per core, looking > for the number after the first comma, to fail, and QEMU aborts because of > invalid arguments. > > $ lscpu | grep '^NUMA node0' | sed -e 's/^[^,-]*(,|\-)\([0-9]*\),.*$/\1/' > NUMA node0 CPU(s): 0-79 > > But the lscpu command shows the number of threads per core: > > $ sudo ppc64_cpu --smt=8 > $ lscpu | grep 'Thread(s) per core' > Thread(s) per core: 8 > $ sudo ppc64_cpu --smt=off > $ lscpu | grep 'Thread(s) per core' > Thread(s) per core: 1 > > This commit therefore directly uses that value. Maybe extend: …, and replaces `grep` by using using sed’s switch `-n` and the command p. > > Signed-off-by: Paul Menzel > Signed-off-by: Paul E. McKenney > > diff --git a/tools/testing/selftests/rcutorture/bin/functions.sh b/tools/testing/selftests/rcutorture/bin/functions.sh > index c35ba24f994c3..66d0414d8e4bc 100644 > --- a/tools/testing/selftests/rcutorture/bin/functions.sh > +++ b/tools/testing/selftests/rcutorture/bin/functions.sh > @@ -301,7 +301,7 @@ specify_qemu_cpus () { > echo $2 -smp $3 > ;; > qemu-system-ppc64) > - nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`" > + nt="`lscpu | sed -n 's/^Thread(s) per core:\s*//p'`" > echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt > ;; > esac Thank you for doing that, and sorry for the extra work. Kind regards, Paul