Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp875135ybt; Tue, 7 Jul 2020 02:23:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNRTnbGi0GKOCSxSQZO2FUMFToPK1S8houMc5PXFXqdOkx96TatLgUyfca475x8Gdy8LgA X-Received: by 2002:a05:6402:2d7:: with SMTP id b23mr48239054edx.145.1594113790625; Tue, 07 Jul 2020 02:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594113790; cv=none; d=google.com; s=arc-20160816; b=PggLWLmfIXZ620dQMgx65cOaBxtWIXEQNMxZK3jvshSTQui28+7ndmxinuuczuYvRN 5ihqO+nbtLhf7+WUncbqXmAioZdTgAeXUIW1wrzFBtRuv1rMQoJ2l/J9QkidiKJHskJg 35O3rQTL/tiCnT4eccHXhRP98wPFwsv1YLmQ+tplMEIc2SJ+xn0MS6c4nKXAr+RSYRcj 8e+8/1/hl3ITg/u8OcRwwy3lB2Wbpc4nqr8LoVUmw30JT+r7EXiK8isQdwPamXXdoQ3d QKYbXJQFvWuhF5vLrC/s5XfcQWApxr1pCmo04f6yCunjye6KdBDtsX0EqkwWYgCoSCOY tM1g== 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; bh=v1Im6DFPTvG6Fla4AWWwCevQlIzX3jyOqLwdX1+9+Xo=; b=t5OamE/1w1qaGCZKTgMsAHzAK7/2w+Lcm6eSSrOfW6G+iMFRM1Mh2BCK75M7PUDwAY He/3wmreAXr7D6R2vJ6snHCL+OYmrCB7/32xE/Gc6SkTqmdF5k589XdzBn0ocQvHgBxh arZHcTZd67f48/+8n3xEsdzrsKE96UGMCL8lO3YgUBpVs3MIxq0simDdsEyepAyCDHik 6xkhA04gbM6ZxzaaWg4fqbdyojWItkKaU1YkQ1XPYYe76OfUUFuaZfb1WinDxaEQOlO0 pXg7cRFXdUWOKXxZEdVnjTA2eb/5lxB3zv5giHWFr+RtsEr03mNME2W+pGv75mStDOwP ZSuQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ci26si13703921ejc.715.2020.07.07.02.22.45; Tue, 07 Jul 2020 02:23:10 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727116AbgGGJUK (ORCPT + 99 others); Tue, 7 Jul 2020 05:20:10 -0400 Received: from foss.arm.com ([217.140.110.172]:33460 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbgGGJUK (ORCPT ); Tue, 7 Jul 2020 05:20:10 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 60775C0A; Tue, 7 Jul 2020 02:20:09 -0700 (PDT) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 45C8E3F68F; Tue, 7 Jul 2020 02:20:08 -0700 (PDT) Date: Tue, 7 Jul 2020 10:20:05 +0100 From: Qais Yousef To: Peter Zijlstra Cc: Dave Jones , Mel Gorman , Linux Kernel , mingo@kernel.org, Linus Torvalds , paul.gortmaker@windriver.com, valentin.schneider@arm.com Subject: Re: weird loadavg on idle machine post 5.7 Message-ID: <20200707092004.jviycpvzb4l5ytiz@e107158-lin.cambridge.arm.com> References: <20200702171548.GA11813@codemonkey.org.uk> <20200702213627.GF3183@techsingularity.net> <20200703090226.GV4800@hirez.programming.kicks-ass.net> <20200703104033.GK117543@hirez.programming.kicks-ass.net> <20200703205153.GA19901@codemonkey.org.uk> <20200706145952.GB597537@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200706145952.GB597537@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/06/20 16:59, Peter Zijlstra wrote: [...] > @@ -4104,12 +4108,19 @@ static void __sched notrace __schedule(bool preempt) > local_irq_disable(); > rcu_note_context_switch(preempt); > > + prev_state = prev->state; > + > /* > - * Make sure that signal_pending_state()->signal_pending() below > - * can't be reordered with __set_current_state(TASK_INTERRUPTIBLE) > - * done by the caller to avoid the race with signal_wake_up(). > + * __set_current_state(@state) > + * schedule() signal_wake_up() > + * prev_state = p->state set_tsk_thread_flag(p, TIF_SIGPENDING) > + * wake_up_state() > + * LOCK rq->lock LOCK p->pi_state > + * smp_mb__after_spinlock() smp_mb__after_spinlock() > + * if (signal_pending_state() if (p->state & @state) > + * > * > - * The membarrier system call requires a full memory barrier > + * Also, the membarrier system call requires a full memory barrier > * after coming from user-space, before storing to rq->curr. > */ > rq_lock(rq, &rf); > @@ -4120,10 +4131,30 @@ static void __sched notrace __schedule(bool preempt) > update_rq_clock(rq); > > switch_count = &prev->nivcsw; > - if (!preempt && prev->state) { > - if (signal_pending_state(prev->state, prev)) { > + /* > + * We must re-load p->state in case ttwu_runnable() changed it > + * before we acquired rq->lock. > + */ > + if (!preempt && prev_state && prev_state == prev->state) { I think the compiler won't optimize `prev_state == prev->state` out because of the smp_mb__after_spinlock() which implies a compiler barrier. Still not sure if it's worth making prev->state accesses a READ_ONCE()? Thanks -- Qais Yousef