Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2094627rdb; Thu, 7 Dec 2023 19:28:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+lFXhKeDz1BIp+BJyzLKVoBLgSlWEYRX3o5/GQppoOgIhKLga7UaACpAX8pdonjs8TL5B X-Received: by 2002:a92:d5cd:0:b0:35d:6664:2ae5 with SMTP id d13-20020a92d5cd000000b0035d66642ae5mr3989040ilq.19.1702006121144; Thu, 07 Dec 2023 19:28:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702006121; cv=none; d=google.com; s=arc-20160816; b=007zcS7up5u/S16Yo0IPvS7fAxm+SDYFQ/81YhQefu30nFeoSNwOfKfc++rN7DpEsJ FGOwgC/unwPAIPiyaeNNkeXCS9pdmoDwa96ZRV1x1LIkv/+jF+Vwlr5mhpFglpIm8ooE dkGqhq1sYJh/u0g9aNFBSwr7PJrZ4oCt6dNKQaw+Zd30kh/BY/zCagpMXV6ktl9LiGka f/ngEB7j1Uoz9MBYkqNgkYD7wIx97XagEz6eXurFPQA/3JDo0YO9uFRKg7ahWlTEYG/7 7dqloMOaHbpqFS9d5AvO1NH9polvV0tquGEE+dCbVY2wFpNkU/v5mDN9JTsL5WEPAQju iu0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Fw+TZLy2pjeD88xqozW/G6MQcy71CGObq/BZJWgm1yk=; fh=BDL/a/ouV+t/CAyBcvNlMEmOkYdq8S2Mf5MVqbnjn8c=; b=TDESh17hTFsLgfjmnGTHADDzyfjW6RU845vfdoOG3SaIZ0ytj53vsBMNMltzkDF2+1 qVA9XMBaZQXqKz1CPC3/0Xfgm7ZXWHlOCxw8y1JbHqhp6RPqoWMamxQ9heunHhOd6eL9 nton+GLXQjfH1qTRdH09uJw3iYKhbRgx6+ySrKoDnR59xRUHudvc7l4y8URP0svDSLMw Ld6VxvTjkW++nnG9BcVvWfo9VhA4kktjlh2tdC2DzoJoGAqJLcDTEB50RCYnlxiDp1wq SKJ13ffPQIkI7YN+q2jrgfYIROp5R0Gs2RkW+zD2htNPiMEMP2mMZ9a887srdpZO38gC KIyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RJJP89jB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id 6-20020a630f46000000b00578b487825asi754188pgp.208.2023.12.07.19.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 19:28:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RJJP89jB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CD92080E73C3; Thu, 7 Dec 2023 19:28:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573067AbjLHD2a (ORCPT + 99 others); Thu, 7 Dec 2023 22:28:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235374AbjLHD23 (ORCPT ); Thu, 7 Dec 2023 22:28:29 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E91DE10C2 for ; Thu, 7 Dec 2023 19:28:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702006113; 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: in-reply-to:in-reply-to:references:references; bh=Fw+TZLy2pjeD88xqozW/G6MQcy71CGObq/BZJWgm1yk=; b=RJJP89jBuVhXgoA1fXRTndF3JLGSaKyekPI8iUbkFTUB+tZLefPBY6Ioh0TUcHFayTniiC ti3XnEyn69qOTwBKuI4IowrqEVs/T8aOZQiHndr4YWdJQhE5vo4Nz4T9nr/ziv7Yd63DaQ npfiNx5XXFDLfc72LguVjt+Lc6qQdAg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-YFg4AkRCOuaGFmOGJdqYKw-1; Thu, 07 Dec 2023 22:28:30 -0500 X-MC-Unique: YFg4AkRCOuaGFmOGJdqYKw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id CB88C8371C1; Fri, 8 Dec 2023 03:28:29 +0000 (UTC) Received: from fedora (unknown [10.72.120.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F31D48CD0; Fri, 8 Dec 2023 03:28:25 +0000 (UTC) Date: Fri, 8 Dec 2023 11:28:21 +0800 From: Ming Lei To: Yury Norov Cc: Andrew Morton , Thomas Gleixner , linux-kernel@vger.kernel.org, Andy Shevchenko , Rasmus Villemoes Subject: Re: [PATCH v2 2/6] lib/group_cpus: relax atomicity requirement in grp_spread_init_one() Message-ID: References: <20231207203900.859776-1-yury.norov@gmail.com> <20231207203900.859776-3-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 07 Dec 2023 19:28:39 -0800 (PST) On Thu, Dec 07, 2023 at 06:49:20PM -0800, Yury Norov wrote: > On Fri, Dec 08, 2023 at 09:31:27AM +0800, Ming Lei wrote: > > On Thu, Dec 07, 2023 at 12:38:56PM -0800, Yury Norov wrote: > > > Because nmsk and irqmsk are stable, extra atomicity is not required. > > > > > > Signed-off-by: Yury Norov > > > --- > > > lib/group_cpus.c | 9 ++++----- > > > 1 file changed, 4 insertions(+), 5 deletions(-) > > > > > > diff --git a/lib/group_cpus.c b/lib/group_cpus.c > > > index ee272c4cefcc..8eb18c6bbf3b 100644 > > > --- a/lib/group_cpus.c > > > +++ b/lib/group_cpus.c > > > @@ -24,8 +24,8 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk, > > > if (cpu >= nr_cpu_ids) > > > return; > > > > > > - cpumask_clear_cpu(cpu, nmsk); > > > - cpumask_set_cpu(cpu, irqmsk); > > > + __cpumask_clear_cpu(cpu, nmsk); > > > + __cpumask_set_cpu(cpu, irqmsk); > > > cpus_per_grp--; > > > > > > /* If the cpu has siblings, use them first */ > > > @@ -34,9 +34,8 @@ static void grp_spread_init_one(struct cpumask *irqmsk, struct cpumask *nmsk, > > > sibl = cpumask_next(sibl, siblmsk); > > > if (sibl >= nr_cpu_ids) > > > break; > > > - if (!cpumask_test_and_clear_cpu(sibl, nmsk)) > > > - continue; > > > - cpumask_set_cpu(sibl, irqmsk); > > > + __cpumask_clear_cpu(sibl, nmsk); > > > + __cpumask_set_cpu(sibl, irqmsk); > > > cpus_per_grp--; > > > > Here the change isn't simply to remove atomicity, and the test > > part of cpumask_test_and_clear_cpu() is removed, so logic is changed, > > I feel the correct change should be: > > > > if (cpumask_test_cpu(sibl, nmsk)) { > > __cpumask_clear_cpu(sibl, nmsk); > > __cpumask_set_cpu(sibl, irqmsk); > > cpus_per_grp--; > > } > > Ohh. My mistake is that I put this patch prior to the #3, so people > bisecting the kernel may hit this problem... > > You're right here, but check the following patch: it switches the > for() loop to for_each_cpu_and_from(sibl, siblmsk, nmsk), and it means > that inside the loop sibl indexes set bits in both siblmsk and nmsk. > > Now, because both masks are stable when the grp_spread_init_one() is > called, there's no chance to get nmks.sibl cleared suddenly, and it > means we can just drop the check. > > Does this makes sense to you? > > I can send v3 with a proper order of patches, if needed. v3 is correct, and I'd suggest to either fix v2 or re-order v3, otherwise both patch 2 and 3 are not easy to follow. Thanks, Ming