Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1202073ybc; Tue, 12 Nov 2019 16:23:48 -0800 (PST) X-Google-Smtp-Source: APXvYqxVncuNZxsM9ap/aJysFg2dyDtPI7BVaXh1m6PweGxuciyoAg5ZYd0Y3pASyHmAYQsoKN+x X-Received: by 2002:aa7:c1d4:: with SMTP id d20mr524244edp.273.1573604628339; Tue, 12 Nov 2019 16:23:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573604628; cv=none; d=google.com; s=arc-20160816; b=XMptxJu/1MLTrIoCWXEdSd/OiU62wA36/RvsbK45z88fA7GEjJf0+CDVFUSXZ4QVDt dgr0O3LpDe8AVJYI/mdb9QczSlPWlKnw46et6LNJQkFc2il6C3N06rbzYbDi0vSDi5Xw mKHsElkbsNDeTDmWcHS1jOqxq0Wdabig9GHL0yHKv6uRm/mDCUTf3tJ2LW/zx0y47uFp JIZr/yBr4Yv0yop2DZBYmPwQYa7vUrJg3h8mGGXKQGfd2xQUb0igBOOReRwy8oxg7fiu wAlkar2BrIMevi4wfv1CCyfV64sRhYaXMjflFln+bF/IR2gmx2An5/SyPWvmATvq6eXG cV+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uXrMoLvBg3eSpV7XIHizPFye10GPvnfWWT//Gi0iZh0=; b=mrLR29y+yEYS1018aqJzCkz+AvJhdm854qsN7d1wke3SUhmFI3irmpaaKIRNCNA0S7 OVZvJhlu65IqGjQswRnUkT7yLeN+zaJSXigV8Cf0uaLPhdxSUSF9Ued08jM5jp/KXUBF wA1G+o3cJZLYVfDWpgQTghFywpQjKhozj2Oj7VyMUKDddQ+SDVCyBI15AiipEn19D56n FDRVFbHnWBe064kZlDTe6xqQAYkSfhLPE7AqtDFiVg/vw+z0nroMcRyTtaWDRetwGjMB QU8wGrEadsUdZTiIXp0I5YAlNM8xsCwArXZ6ZwhybjWE8/3rzrCNpcjS/uCsUcAStzku HArw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X60QwV+T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si143766edl.371.2019.11.12.16.23.24; Tue, 12 Nov 2019 16:23:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X60QwV+T; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727004AbfKMAWk (ORCPT + 99 others); Tue, 12 Nov 2019 19:22:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:58420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726910AbfKMAWk (ORCPT ); Tue, 12 Nov 2019 19:22:40 -0500 Received: from localhost (lfbn-ncy-1-150-155.w83-194.abo.wanadoo.fr [83.194.232.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AD8CA206BB; Wed, 13 Nov 2019 00:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573604559; bh=KYsxxVfb9c/zNMVXXf6w4bZXIsHRXJu0HaUT9jvjS00=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X60QwV+TY1luo9vcFS/kOlrxatdJKJF4PDOBVlOrneBwPxse7QBb6ZbrqZqNYAaSJ klLbWbH9v36NACYd+CGLcLlxIw6gkJkEH9QIEMNLiOvNfezKtJ05omywy2QM0i/iWa GFkKAX5BjMUUmQVcipBXgLeYBT2pI3FAfhPUPSXs= Date: Wed, 13 Nov 2019 01:22:36 +0100 From: Frederic Weisbecker To: Leonard Crestez Cc: Peter Zijlstra , Ingo Molnar , LKML , "Paul E . McKenney" , Thomas Gleixner , Viresh Kumar , "linux-pm@vger.kernel.org" , Stephen Rothwell Subject: Re: [PATCH 3/4] irq_work: Slightly simplify IRQ_WORK_PENDING clearing Message-ID: <20191113002235.GA5746@lenoir> References: <20191108160858.31665-1-frederic@kernel.org> <20191108160858.31665-4-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 12, 2019 at 08:27:05PM +0000, Leonard Crestez wrote: > On 08.11.2019 18:09, Frederic Weisbecker wrote: > > Instead of fetching the value of flags and perform an xchg() to clear > > a bit, just use atomic_fetch_andnot() that is more suitable to do that > > job in one operation while keeping the full ordering. > > > > Signed-off-by: Frederic Weisbecker > > Cc: Paul E. McKenney > > Cc: Thomas Gleixner > > Cc: Peter Zijlstra > > Cc: Ingo Molnar > > --- > > kernel/irq_work.c | 7 +++---- > > 1 file changed, 3 insertions(+), 4 deletions(-) > > > > diff --git a/kernel/irq_work.c b/kernel/irq_work.c > > index 255454a48346..49c53f80a13a 100644 > > --- a/kernel/irq_work.c > > +++ b/kernel/irq_work.c > > @@ -34,7 +34,7 @@ static bool irq_work_claim(struct irq_work *work) > > oflags = atomic_fetch_or(IRQ_WORK_CLAIMED, &work->flags); > > /* > > * If the work is already pending, no need to raise the IPI. > > - * The pairing atomic_xchg() in irq_work_run() makes sure > > + * The pairing atomic_fetch_andnot() in irq_work_run() makes sure > > * everything we did before is visible. > > */ > > if (oflags & IRQ_WORK_PENDING) > > @@ -135,7 +135,6 @@ static void irq_work_run_list(struct llist_head *list) > > { > > struct irq_work *work, *tmp; > > struct llist_node *llnode; > > - int flags; > > > > BUG_ON(!irqs_disabled()); > > > > @@ -144,6 +143,7 @@ static void irq_work_run_list(struct llist_head *list) > > > > llnode = llist_del_all(list); > > llist_for_each_entry_safe(work, tmp, llnode, llnode) { > > + int flags; > > /* > > * Clear the PENDING bit, after this point the @work > > * can be re-used. > > @@ -151,8 +151,7 @@ static void irq_work_run_list(struct llist_head *list) > > * to claim that work don't rely on us to handle their data > > * while we are in the middle of the func. > > */ > > - flags = atomic_read(&work->flags) & ~IRQ_WORK_PENDING; > > - atomic_xchg(&work->flags, flags); > > + flags = atomic_fetch_andnot(IRQ_WORK_PENDING, &work->flags); > > > > work->func(work); > > /* > > This breaks switching between cpufreq governors in linux-next on arm64 > and various other stuff. The fix in this email doesn't compile: > > https://lkml.org/lkml/2019/11/12/622 > > I assume you meant "&= ~" instead of "~=", this seems to work: Indeed, duh again! I still think that ~= would be nice to have though... Thanks! > > diff --git a/kernel/irq_work.c b/kernel/irq_work.c > index 49c53f80a13a..828cc30774bc 100644 > --- a/kernel/irq_work.c > +++ b/kernel/irq_work.c > @@ -156,10 +156,11 @@ static void irq_work_run_list(struct llist_head *list) > work->func(work); > /* > * Clear the BUSY bit and return to the free state if > * no-one else claimed it meanwhile. > */ > + flags &= ~IRQ_WORK_PENDING; > (void)atomic_cmpxchg(&work->flags, flags, flags & > ~IRQ_WORK_BUSY); > } > }