Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp963348pxb; Thu, 19 Aug 2021 16:05:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr8dpv7ueDmTyvDi83yBt2uVU9sKGDEbMPTYMecxppvPvSFS88PLKAcSRfmXE90VA23iWK X-Received: by 2002:a05:6402:36b:: with SMTP id s11mr19657767edw.235.1629414306691; Thu, 19 Aug 2021 16:05:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629414306; cv=none; d=google.com; s=arc-20160816; b=0tOzFsjK9AgLmxGrAsF2/j9vbqxmKz5XlgjfuedARqJQhuT8BdZjnillP5R2Gt3iVX 61w+ZOrxLsgGR4Whe/dmtpUckJ44nzOvVPXpwPnkgcEcE60rdwqdnJpNIbQjuUZ7K/po EtdYJIVyRJLV6u2AbZA0gRTGNYYPOBfVVo5IsaYrxM0NcsjhwIjgv86aEpLagohld+aB RPswJ6lN2Hnjf4Ic6eHwR/Xf/w3LnbzNkOx+eUjLRK4qrFBlppgpyxZRaFt18yw8rH+G ZD2tSP3fcr+AbmyRXkz3nCtkwgkXtYw6mCDjT/MWFH80El2NCb1Hdlg+eM/YWy0k41WI 2PWA== 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=DIgqo2OBXJoSdsCXTz7ku1pCk/8Xq00XM5YE8fnBA3c=; b=SgiMbwu2sJsTziAYaHXLLT6LnFlToDGGpB99hS1079/mDNixO8BTlG8D6+qUlTOQI7 EFiYCP4VbUW7aVNqWstBvikfvBT53n/X9XT+mkYlIABOouEXIesWUFR/PGYWmlN73Jzo Fn6YJb84tjD5YG65sdNS6K0fgRz/SRvvMH6hrLRmqdb6DGCWsOMqLDkbXdl+s+MALmwu x7zh29oP2Cs9zRppjYmju3kPmVRvEoGLnXUNiDLx6fH0ezyVhcLlPcL3NLA71Ys7c5Vf yD1g7YLclwcEMDFk8zUdlR194Jyeb51MXfFbbu0tJgd/PJ1Hx09SnrPPURF4z3UdTSl4 ElVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="qJmCsZl/"; 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 a16si5568440ejk.489.2021.08.19.16.04.43; Thu, 19 Aug 2021 16:05:06 -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="qJmCsZl/"; 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 S233061AbhHSXBa (ORCPT + 99 others); Thu, 19 Aug 2021 19:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbhHSXB3 (ORCPT ); Thu, 19 Aug 2021 19:01:29 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1125AC061575; Thu, 19 Aug 2021 16:00:53 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id n5so6049631pjt.4; Thu, 19 Aug 2021 16:00:53 -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=DIgqo2OBXJoSdsCXTz7ku1pCk/8Xq00XM5YE8fnBA3c=; b=qJmCsZl/7c7CrNxr5BeAzpbyRaIj4CTi71d4ya0o988dXB/WH3KlfgindcSZnWYyRV Ukc/s/w2eFzKGtXf8WNjDWfz/dvb3KqmYDQ8z2kIEt8MhupcUFcssDbugqSgsfrIJgKJ pPVR3sBsZqs3uqLzKmRp3wPrrFTk8ZZ5IVn2NN9Y+/op0+LrZDnRH02CEZG3nF1qJkrO 948yknzg0cLJ/jSH4wwetmRUUghwCiONq415/IszMmf/IGrXwEROlgrL15ksf9++XEiv Hpal1bys7Wk4DCLQghBkitpSstWPRZt2dAmg9Dxjc//7P/eo4lJ6ht/tbnfQ1i8FJZAg 1ulQ== 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=DIgqo2OBXJoSdsCXTz7ku1pCk/8Xq00XM5YE8fnBA3c=; b=K5eKX2F1oKdI5lnpuSVnvaULPLEikicUuMlaRVwy7iUm8QIegD39rclg+lfWJk7FSr L+kWmhjw8yrRjp3LHKVh9E6uAm6Raei2BqPS6ohvYLtPDz6ZGl9YTTrd/BJ7XD93Zkpe Vfwz6A5i8qReGIBq1u7flFM+I1gtpRYFdEhQwX68lgFLIrgMGqr+TSSbTrxocHFiW3w3 Ixn3qcIyVPc/e/+SlTFUfS3W95czoBafWNUe86dkGV6gerINudPGEONf7uS/E1LwPX/9 BFHS9G4ErEXc8Z4pxaH2ZQSom26IlZmTIZFv5801fBJYsaAhCddWb5ioLwefQ7RxYH0P 2Bkg== X-Gm-Message-State: AOAM532KCQHV9M52M0/Or04hFq8P0fov97hZYCc2qkLp1SXyI2udW5go +iRQuVRnCZVuQx1s+qm/nDA= X-Received: by 2002:a17:90a:9af:: with SMTP id 44mr1238095pjo.62.1629414052470; Thu, 19 Aug 2021 16:00:52 -0700 (PDT) Received: from mail.google.com ([141.164.41.4]) by smtp.gmail.com with ESMTPSA id g26sm5413228pgb.45.2021.08.19.16.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 16:00:52 -0700 (PDT) Date: Fri, 20 Aug 2021 07:00:36 +0800 From: Changbin Du To: Boqun Feng Cc: Changbin Du , 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: <20210819230036.uh2amndgsyza6az7@mail.google.com> 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 19, 2021 at 09:56:45AM +0800, Boqun Feng wrote: > [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(). > ok, as in_serving_irq() is only used in two places, it is not common to judge if it is in serving irq context. So this new macro doesn't help much. > Regards, > Boqun > > > -- > > Cheers, > > Changbin Du -- Cheers, Changbin Du