Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp165612pxb; Wed, 18 Aug 2021 19:01:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfJ1KSEBB0pKu29WMURcAcq6lxoobJU0tepCV9L9SW0rsSqx2pqFOWAfen1fLCYctFqqPI X-Received: by 2002:a17:906:c182:: with SMTP id g2mr12639305ejz.507.1629338506698; Wed, 18 Aug 2021 19:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629338506; cv=none; d=google.com; s=arc-20160816; b=DXDqe97xpvehMWKCP4agnPNQXe3Gh5wMb7kpudMehN/VHN7mH4dRilyTW8jBTZqwJu t6f8U2pN5As4Ot3d4ylSI0lr7KSfPDvqO9849l2kn7/ZSQsXWb43FY8P2p7AHeCQ1E+j pqkdpEklfnqqBJWikeRP9OrABqBPfBx5GgfeVTsahbJhRVJ8YmyMdbohKoDBMEMxAINN dB0R2ENSGOT2YAiC+ZEowDM4kjI1NVlGg7EDdfDY92JENsZUHbCLfVbUxjnMq/WB6iN9 0hSj2FYPfW3ULbe9MxFcbnYHL7YOuYrf6HOoeNAEtA8FoCw34eaJA4BTYiOI0kv4YMCk v8Vw== 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=0NJ+tliVUy5AxPDrrbDAZeL7P5Xe7UPZ+oPMc7Kpyy4=; b=SjAUN9HuvfaoPwRa6Iux2Huz4Ak/bydR43dfnbLTbfiY6FYx+bTTTJUpxd2wFDch28 ZKF6Dr1aE6QU9FwA2rUA9CeAfpG2+T6ZL4XesyMXNuGqg+PN3rwRDkHX1IXmHmQG6jwP OpNZNXwArW3wMmi5CGkdtSFENjwe3ZPNWdnB8B+2uHkugDEeODNLe5UdPizkZ8j7fsak 5IFDZUGfbSCG2ai9ssBaaCWhcxBwS3J9gNyM882QlEKEQO+1Hh6829PrNoH8zjfLfUZG 5O6vASpc/1l7GfAm5fWRIGo1PbLLHrmxI5ZTgcXztHsCHWx7D0oDUILwVhiF00TBjVuJ 9Fgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=juCQN66p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p12si1758734ejj.2.2021.08.18.19.01.22; Wed, 18 Aug 2021 19:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=juCQN66p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235558AbhHSB57 (ORCPT + 99 others); Wed, 18 Aug 2021 21:57:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235384AbhHSB56 (ORCPT ); Wed, 18 Aug 2021 21:57:58 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0AF0C061764; Wed, 18 Aug 2021 18:57:22 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id j18so5574456ioj.8; Wed, 18 Aug 2021 18:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0NJ+tliVUy5AxPDrrbDAZeL7P5Xe7UPZ+oPMc7Kpyy4=; b=juCQN66p/qqGpCSxsDN+mvTpkzCFHBVxWAeJZTcpSMPiOSO8VLnk8T9JicbrjuagS8 3HI38c8+5VtsLyfbiqZwjtZEQDekKLKP463euX9itKEGY649+tk7RL/FKCxSG6haqfHM FG+3vO6S4NPtzfEVeZNygzz3lkYh4X/o2RpJDm40jDoam3uZhfVNwSnHAZsuK7HhwH1i yVbfxsUT5Qkowv3xiOAq4pRuIxaJEgY/P1BBpmh74Cs4mD1OzFl8tHNmqhzJlWRdfm62 YiAoa5G9Iagwy0HIAxdgmIuEKAFX4LSFqHfWiBKN2MIjpK8LT9inAdlJxyUnFqPw57FT Ethw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0NJ+tliVUy5AxPDrrbDAZeL7P5Xe7UPZ+oPMc7Kpyy4=; b=ODmER15TB4W5nzM3GBHS8JWc3C4XrxNRLbdYvUh+TaG8XEsv9tRCB1qBSUGHb2ZVjt jqdinYy+sRow0kfrvT4pRiwCzbOZ0cpIdHs+AvLqdS0rPm71APhI1+2kjQkAhWEFvzjF JqgRaeG411IA4/1A4Qq7CtEWtmlUhvVZUuM12AEu/3P+QYIrJVl5zpiOv/hckd4LM+Iu WIHQn9o7dXL1OhJi9UdNZucqQW0MFeomtYp4pQ/YPa8yEJB17H8k5TPjqMx5BPXfyZr8 meSvIqggfxrbwv27mPa4zqn7hv9jY4i8BCaWdz1xWHoama35hYnZCvNNYuIt+1kPIJSY m8uQ== X-Gm-Message-State: AOAM530ZGwTbHHdwFzPi0wdNzxkLz443KYEpp1gYlIpF1YnqhpFV80R1 IeiZTa+1N8o8/mSiozRRZQg= X-Received: by 2002:a05:6638:265:: with SMTP id x5mr10548593jaq.23.1629338242335; Wed, 18 Aug 2021 18:57:22 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id a17sm884770ios.36.2021.08.18.18.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 18:57:21 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id BE85D27C0054; Wed, 18 Aug 2021 21:57:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 18 Aug 2021 21:57:20 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrleeigdehvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpeevieejtdfhieejfeduheehvdevgedugeethefggfdtvdeutdevgeetvddvfeeg tdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgv rhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfh gvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 18 Aug 2021 21:57:17 -0400 (EDT) Date: Thu, 19 Aug 2021 09:56:45 +0800 From: Boqun Feng To: Changbin Du Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , "Paul E. McKenney" , Josh Triplett , Sergey Senozhatsky , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, Thomas Gleixner , Frederic Weisbecker Subject: Re: [PATCH] preempt: add in_serving_irq() and apply to rcutiny and vsprintf Message-ID: References: <20210814014234.51395-1-changbin.du@gmail.com> <20210818235916.l3zbdt5nli5j65xi@mail.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210818235916.l3zbdt5nli5j65xi@mail.google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [Cc Thomas and Frederic since they contributed the clean-up to these macros recently] Background for discussion: https://lore.kernel.org/lkml/20210814014234.51395-1-changbin.du@gmail.com/ On Thu, Aug 19, 2021 at 07:59:16AM +0800, Changbin Du wrote: > On Tue, Aug 17, 2021 at 12:03:16AM +0800, Boqun Feng wrote: > > On Sat, Aug 14, 2021 at 09:42:34AM +0800, Changbin Du wrote: > > > At some places we need to determine whether we're in nmi, hardirq or > > > softirq context. This adds a macro in_serving_irq() as a shortcut for > > > that. > > > > > > Meanwhile, apply this new macro to existing code in rcutiny and vsprintf. > > > > > > Signed-off-by: Changbin Du > > > --- > > > include/linux/preempt.h | 4 +++- > > > include/linux/rcutiny.h | 3 +-- > > > lib/vsprintf.c | 2 +- > > > 3 files changed, 5 insertions(+), 4 deletions(-) > > > > > > diff --git a/include/linux/preempt.h b/include/linux/preempt.h > > > index 9881eac0698f..9a1c924e2c6c 100644 > > > --- a/include/linux/preempt.h > > > +++ b/include/linux/preempt.h > > > @@ -92,12 +92,14 @@ > > > * in_nmi() - We're in NMI context > > > * in_hardirq() - We're in hard IRQ context > > > * in_serving_softirq() - We're in softirq context > > > + * in_serving_irq() - We're in nmi, hardirq or softirq context > > > * in_task() - We're in task context > > > */ > > > #define in_nmi() (nmi_count()) > > > #define in_hardirq() (hardirq_count()) > > > #define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET) > > > -#define in_task() (!(in_nmi() | in_hardirq() | in_serving_softirq())) > > > +#define in_serving_irq() (in_nmi() | in_hardirq() | in_serving_softirq()) > > > +#define in_task() (!in_serving_irq()) > > > > > > > So in_serving_irq() is !in_task(), right? If so, why not... > > > Adding in_serving_irq() is to reflect the real purpose so improve readability. > And can we preserve that !in_task() means in serving irq context in future? I don't know. > Sure, no one could predict the future. But if a third context (other than thread context and {hard,soft}irq context) comes up, which I think is highly unlikely, we could (and should) audit all callsites of in_task() for necessary adjustment. And introducing in_serving_irq() won't help us in that case, because we will still need to audit usage of in_serving_irq(), for example, let's say rcu_is_idle_cpu() for RCU_TINY is defined as #define rcu_is_idle_cpu(cpu) (is_idle_task(current) && !in_serving_irq()) and we have a new type of context, and we can use in_other() to test whether we are in it. Now even with in_serving_irq() introduced, we still need to make sure the correct version of rcu_is_idle_cpu() is either (is_idle_task(current) && (!in_serving_irq() && !in_other())) or (is_idle_task(current) && !in_serving_irq()) Therefore, I don't see the point of introducing in_serving_irq(). Regards, Boqun > -- > Cheers, > Changbin Du