From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C9A8C2D0A3 for ; Mon, 16 Nov 2020 19:32:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0140720825 for ; Mon, 16 Nov 2020 19:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730361AbgKPTbz (ORCPT ); Mon, 16 Nov 2020 14:31:55 -0500 Received: from outbound-smtp45.blacknight.com ([46.22.136.57]:43975 "EHLO outbound-smtp45.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727805AbgKPTby (ORCPT ); Mon, 16 Nov 2020 14:31:54 -0500 Received: from mail.blacknight.com (pemlinmail05.blacknight.ie [81.17.254.26]) by outbound-smtp45.blacknight.com (Postfix) with ESMTPS id A476FFB10C for ; Mon, 16 Nov 2020 19:31:52 +0000 (GMT) Received: (qmail 30325 invoked from network); 16 Nov 2020 19:31:52 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 16 Nov 2020 19:31:51 -0000 Date: Mon, 16 Nov 2020 19:31:49 +0000 From: Mel Gorman To: Peter Zijlstra Cc: Will Deacon , Davidlohr Bueso , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: Loadavg accounting error on arm64 Message-ID: <20201116193149.GW3371@techsingularity.net> References: <20201116091054.GL3371@techsingularity.net> <20201116131102.GA29992@willie-the-truck> <20201116133721.GQ3371@techsingularity.net> <20201116142005.GE3121392@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20201116142005.GE3121392@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 16, 2020 at 03:20:05PM +0100, Peter Zijlstra wrote: > > I think this is at least one possibility. I think at least that one > > should only be explicitly set on WF_MIGRATED and explicitly cleared in > > sched_ttwu_pending. While I haven't audited it fully, it might be enough > > to avoid a double write outside of the rq lock on the bitfield but I > > still need to think more about the ordering of sched_contributes_to_load > > and whether it's ordered by p->on_cpu or not. > > The scenario you're worried about is something like: > > CPU0 CPU1 > > schedule() > prev->sched_contributes_to_load = X; > deactivate_task(prev); > > try_to_wake_up() > if (p->on_rq &&) // false > if (smp_load_acquire(&p->on_cpu) && // true > ttwu_queue_wakelist()) > p->sched_remote_wakeup = Y; > > smp_store_release(prev->on_cpu, 0); > Yes. > And then the stores of X and Y clobber one another.. Hummph, seems > reasonable. One quick thing to test would be something like this: > > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 7abbdd7f3884..9844e541c94c 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -775,7 +775,9 @@ struct task_struct { > unsigned sched_reset_on_fork:1; > unsigned sched_contributes_to_load:1; > unsigned sched_migrated:1; > + unsigned :0; > unsigned sched_remote_wakeup:1; > + unsigned :0; > #ifdef CONFIG_PSI > unsigned sched_psi_wake_requeue:1; > #endif And this works. 986.01 1008.17 1013.15 2/855 1212 362.19 824.70 949.75 1/856 1564 133.19 674.65 890.32 1/864 1958 49.04 551.89 834.61 2/871 2339 18.33 451.54 782.41 1/867 2686 6.77 369.37 733.45 1/866 2929 2.55 302.16 687.55 1/864 2931 0.97 247.18 644.52 1/860 2933 0.48 202.23 604.20 1/849 2935 I should have gone with this after rereading the warning about bit fields having to be protected by the same lock in the "anti-guarantees" section of memory-barriers.txt :( sched_psi_wake_requeue can probably stay with the other three fields given they are under the rq lock but sched_remote_wakeup needs to move out. -- Mel Gorman SUSE Labs From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76575C2D0A3 for ; Mon, 16 Nov 2020 19:33:12 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 19BBF20825 for ; Mon, 16 Nov 2020 19:33:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iWlyormM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19BBF20825 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RYpxoZN6pTVIWaqht9bSFHFbimAGDry3tb9BvR39Alk=; b=iWlyormM1kC0f43DBGXMOM1Oq mRLEQtt57SbD4cxTelN+RtHk3rnQo8xLcyaABvmNMojiJFpwOTtjU6x/fcjWy5T5EFPXe52vIl8/3 gZZZedEyY+kJTa0hCVPbk+8QbFQcrwSBsv11LVa4UTds1trdbq2p+Oq4wYLos1+uhZKaA5fRD+fBc cQro3y/MFX2ojntKrXBMSHwvnRv4WY+Pu8yUXXGyYi2bPAST6w+kSzj2wJNdzvPYD2k7GfN4PCXM7 VwuN/AhIxgJGJYSvot+gLHyVztwQGBhJZJTV1fK0e19NPpnb/pZJL+GrjGqAmDteQeDPe4XkP67KN LQu/utDXg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kekEK-0006sI-Ml; Mon, 16 Nov 2020 19:32:00 +0000 Received: from outbound-smtp24.blacknight.com ([81.17.249.192]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kekEG-0006r2-Qi for linux-arm-kernel@lists.infradead.org; Mon, 16 Nov 2020 19:31:59 +0000 Received: from mail.blacknight.com (pemlinmail05.blacknight.ie [81.17.254.26]) by outbound-smtp24.blacknight.com (Postfix) with ESMTPS id A6E48C0E33 for ; Mon, 16 Nov 2020 19:31:52 +0000 (GMT) Received: (qmail 30325 invoked from network); 16 Nov 2020 19:31:52 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 16 Nov 2020 19:31:51 -0000 Date: Mon, 16 Nov 2020 19:31:49 +0000 From: Mel Gorman To: Peter Zijlstra Subject: Re: Loadavg accounting error on arm64 Message-ID: <20201116193149.GW3371@techsingularity.net> References: <20201116091054.GL3371@techsingularity.net> <20201116131102.GA29992@willie-the-truck> <20201116133721.GQ3371@techsingularity.net> <20201116142005.GE3121392@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201116142005.GE3121392@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201116_143156_971304_5D787C93 X-CRM114-Status: GOOD ( 20.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Davidlohr Bueso , Will Deacon , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Nov 16, 2020 at 03:20:05PM +0100, Peter Zijlstra wrote: > > I think this is at least one possibility. I think at least that one > > should only be explicitly set on WF_MIGRATED and explicitly cleared in > > sched_ttwu_pending. While I haven't audited it fully, it might be enough > > to avoid a double write outside of the rq lock on the bitfield but I > > still need to think more about the ordering of sched_contributes_to_load > > and whether it's ordered by p->on_cpu or not. > > The scenario you're worried about is something like: > > CPU0 CPU1 > > schedule() > prev->sched_contributes_to_load = X; > deactivate_task(prev); > > try_to_wake_up() > if (p->on_rq &&) // false > if (smp_load_acquire(&p->on_cpu) && // true > ttwu_queue_wakelist()) > p->sched_remote_wakeup = Y; > > smp_store_release(prev->on_cpu, 0); > Yes. > And then the stores of X and Y clobber one another.. Hummph, seems > reasonable. One quick thing to test would be something like this: > > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 7abbdd7f3884..9844e541c94c 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -775,7 +775,9 @@ struct task_struct { > unsigned sched_reset_on_fork:1; > unsigned sched_contributes_to_load:1; > unsigned sched_migrated:1; > + unsigned :0; > unsigned sched_remote_wakeup:1; > + unsigned :0; > #ifdef CONFIG_PSI > unsigned sched_psi_wake_requeue:1; > #endif And this works. 986.01 1008.17 1013.15 2/855 1212 362.19 824.70 949.75 1/856 1564 133.19 674.65 890.32 1/864 1958 49.04 551.89 834.61 2/871 2339 18.33 451.54 782.41 1/867 2686 6.77 369.37 733.45 1/866 2929 2.55 302.16 687.55 1/864 2931 0.97 247.18 644.52 1/860 2933 0.48 202.23 604.20 1/849 2935 I should have gone with this after rereading the warning about bit fields having to be protected by the same lock in the "anti-guarantees" section of memory-barriers.txt :( sched_psi_wake_requeue can probably stay with the other three fields given they are under the rq lock but sched_remote_wakeup needs to move out. -- Mel Gorman SUSE Labs _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel