From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 860E932693D for ; Fri, 20 Feb 2026 11:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771585390; cv=none; b=amd5BLvSObDEPtjuQHc4CbaIkPBfbU5YFB1p0TWY7eVOPuvlauG5Xu4LtkczA3/bXfk6mD/TGK+HO8HXMEWCAXG8qAx05i/AjMLF+w1XrO9pfrmyArtrqQQ0eWsCdO6h5ThL2WEHm/EB/ranEVfvPoc3o0CBl/0q1aBCWPKOWSQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771585390; c=relaxed/simple; bh=mG/LThcb/z6/sGG9FW2HxFQlUC0VaaOulgbCTnAJhS0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TgKjgcAtKkARipSSsI6Tuq++0TgFZTm1+H3g3ttQDw6ePEkK6j5t8KiZGxT0yFABlPqEHtHI9KswVgwdsxTHVlQDrZ48RAUt9ZfyGMx5CJXUBYW5vLL0RY8OpmB7KAw/o95zOnoaT+5SXZkCi4ZMSSPzL3+2cTkA6WAlFogrebY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=ip7GUsUe; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ip7GUsUe" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=k/03T7XdYzaqLvmgAwBW6qF7T6IwpVh0vtYIScptqw4=; b=ip7GUsUezXWyMHzdjEzlh0ATyA jhEYXa/ugl+ZvA7f5S6i6e+yZAvwIH1JnHW+95dbtj6luXxJzkFl9KRSkoXyiVBBXh4NCBpxikGoc nkf8jwZXLGueQRs0aywdxwuOWt9s/gbcucRFFXmZMingAMKgXN64PMmFkrhpfQLxj2XRdlojvGbEB apUQr4E6VLXn7skGzFqTQ7oChbWguJCS3B0pThCN89yBBaz7LQQLD3tdIplevJ/El7OLakNxyyHVK 79AZK5WLg4ZkfYXOPsxRQjE0PUXvEuaawNhwjXIS5vnn9Kgq/bbhGNA9pcDN1Jfb7iqKkivTeO+h3 psL4YR+w==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vtOH9-00000002VeD-164V; Fri, 20 Feb 2026 11:02:28 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id A4C96301BD5; Fri, 20 Feb 2026 12:02:22 +0100 (CET) Date: Fri, 20 Feb 2026 12:02:22 +0100 From: Peter Zijlstra To: Tim Chen Cc: Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Madadi Vineeth Reddy , Hillf Danton , Shrikanth Hegde , Jianyong Wu , Yangyu Chen , Tingyin Duan , Vern Hao , Vern Hao , Len Brown , Aubrey Li , Zhao Liu , Chen Yu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , Josh Don , Gavin Guo , Qais Yousef , Libo Chen , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 08/21] sched/cache: Calculate the percpu sd task LLC preference Message-ID: <20260220110222.GP1395266@noisy.programming.kicks-ass.net> References: <41f8e91b70060e7697840163b80c3dc097aabb34.1770760558.git.tim.c.chen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41f8e91b70060e7697840163b80c3dc097aabb34.1770760558.git.tim.c.chen@linux.intel.com> On Tue, Feb 10, 2026 at 02:18:48PM -0800, Tim Chen wrote: > static void account_llc_enqueue(struct rq *rq, struct task_struct *p) > { > + struct sched_domain *sd; > int pref_llc; > > pref_llc = p->preferred_llc; > - if (pref_llc < 0) > + if (!valid_llc_id(pref_llc)) > return; > > rq->nr_llc_running++; > rq->nr_pref_llc_running += (pref_llc == task_llc(p)); > + > + scoped_guard (rcu) { > + sd = rcu_dereference(rq->sd); > + if (valid_llc_buf(sd, pref_llc)) > + sd->pf[pref_llc]++; > + } > } > > static void account_llc_dequeue(struct rq *rq, struct task_struct *p) > { > + struct sched_domain *sd; > int pref_llc; > > pref_llc = p->preferred_llc; > - if (pref_llc < 0) > + if (!valid_llc_id(pref_llc)) > return; > > rq->nr_llc_running--; > rq->nr_pref_llc_running -= (pref_llc == task_llc(p)); > + > + scoped_guard (rcu) { > + sd = rcu_dereference(rq->sd); > + if (valid_llc_buf(sd, pref_llc)) { > + /* > + * There is a race condition between dequeue > + * and CPU hotplug. After a task has been enqueued > + * on CPUx, a CPU hotplug event occurs, and all online > + * CPUs (including CPUx) rebuild their sched_domains > + * and reset statistics to zero (including sd->pf). > + * This can cause temporary undercount and we have to > + * check for such underflow in sd->pf. > + * > + * This undercount is temporary and accurate accounting > + * will resume once the rq has a chance to be idle. > + */ > + if (sd->pf[pref_llc]) > + sd->pf[pref_llc]--; > + } > + } > } FWIW, enqueue/dequeue must be with rq->lock held, and thus preemption disabled and IRQs off. That RCU section is completely pointless.