From nobody Mon May 25 00:09:40 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 7B6DC3DCD94; Wed, 20 May 2026 08:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266084; cv=none; b=MYeNCwyZj9fXHomRSmXGnjQhhCEI9fc6vVqIbcJmt+bKd9iKHFL8Z5EdXt2rV+4wCshMjh8mMn6hFIsAQVVBKSlFC2zQXotDLo7qh7EYBR3QLtcuF18G1ZeT/YGpyd/82LSn/NEVp6P+RlkEMdMG5+r4RuiHnAPqdkOTd+tnqRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266084; c=relaxed/simple; bh=d75ENGK+orji6kvWnHqgmaRqCUfRJbnPFWiriny6tRQ=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=Ucxv7+elbVnNyR7/ZpQXrx+8SYDI0199xUGYBfeiWlVp2yhIJepA02mYYtNIGTiE+isGq7CuOZy1cFueaDw67gs7EgtoacIOrLysZYr3yGmQxBNen3zDkAwpJpIMlFd3psOQ8ktnZGCjwF2laxBjXhlEO2y7vQ9MUzflXgnGSPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YVP4iN72; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=y+nk86uj; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YVP4iN72"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="y+nk86uj" Date: Wed, 20 May 2026 08:34:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779266081; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2bjQzNRsN0xSOub3fYjEiXrZrN3lAmUVMNAeYX888JQ=; b=YVP4iN72SDChPpYmHUx6IX9qFAKwdwBrERO0TA/cAUsWYPNyU9JiSTAxYW7JP8YUoQ0axu zv0FIHqZUiNiue1U+tu58ttzWV8j2UNyIadd33gC7afGA5c64U3EbSdcyrEJ6vOsZuyWcL MeVxE5dfACPoKDxT8zUg0+yRb3mHlFp4dY0SHQcThCxU4d9OVS19D2IuD5pTt4++WpCH9S pad3wq57b4uPn/7W8PEyf8laVS0W2BXxLPDYLObRO0Sun3r3Xotb8+5Wz4SqNG8aGo+Ta5 CXzHTNZUDd51v1O14XAKdvZpx0G2gfxgnerx8qt+RZsoxxJn+MsuTF1kIOClzA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779266081; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2bjQzNRsN0xSOub3fYjEiXrZrN3lAmUVMNAeYX888JQ=; b=y+nk86ujQWzN2qCdMPY4q2lho7IDYmSHO/U8tjbSlZ2WyT7+5MWUYaf6CSh5GLtvNN9Zfi wctulkAxgSc2HtDw== From: "tip-bot2 for Jianyong Wu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/cache: Allow only 1 thread of the process to calculate the LLC occupancy Cc: Jianyong Wu , Chen Yu , Tim Chen , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3C5672b52e588b855b01e5a1a17822f7c6c7237a3d=2E1778703?= =?utf-8?q?694=2Egit=2Etim=2Ec=2Echen=40linux=2Eintel=2Ecom=3E?= References: =?utf-8?q?=3C5672b52e588b855b01e5a1a17822f7c6c7237a3d=2E17787036?= =?utf-8?q?94=2Egit=2Etim=2Ec=2Echen=40linux=2Eintel=2Ecom=3E?= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177926608045.711.15880687318412001726.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: a2b4cf39d9d333bfeb9262dbaafe3d24d405a5c0 Gitweb: https://git.kernel.org/tip/a2b4cf39d9d333bfeb9262dbaafe3d24d= 405a5c0 Author: Jianyong Wu AuthorDate: Wed, 13 May 2026 13:39:12 -07:00 Committer: Peter Zijlstra CommitterDate: Mon, 18 May 2026 21:33:14 +02:00 sched/cache: Allow only 1 thread of the process to calculate the LLC occupa= ncy Scanning online CPUs to calculate the occupancy might be time-consuming. Only allow 1 thread of the process to scan the CPUs at the same time, which is similar to what NUMA balance does in task_numa_work(). Signed-off-by: Jianyong Wu Signed-off-by: Chen Yu Signed-off-by: Tim Chen Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/5672b52e588b855b01e5a1a17822f7c6c7237a3d.177= 8703694.git.tim.c.chen@linux.intel.com --- include/linux/sched.h | 1 + kernel/sched/fair.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index d201048..6d883f1 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2423,6 +2423,7 @@ struct sched_cache_stat { struct sched_cache_time __percpu *pcpu_sched; raw_spinlock_t lock; unsigned long epoch; + unsigned long next_scan; int cpu; } ____cacheline_aligned_in_smp; =20 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 5f22e5a..a759ea6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1451,6 +1451,7 @@ void mm_init_sched(struct mm_struct *mm, raw_spin_lock_init(&mm->sc_stat.lock); mm->sc_stat.epoch =3D epoch; mm->sc_stat.cpu =3D -1; + mm->sc_stat.next_scan =3D jiffies; =20 /* * The update to mm->sc_stat should not be reordered @@ -1661,6 +1662,7 @@ out: =20 static void task_cache_work(struct callback_head *work) { + unsigned long next_scan, now =3D jiffies; struct task_struct *p =3D current; struct mm_struct *mm =3D p->mm; unsigned long m_a_occ =3D 0; @@ -1675,6 +1677,15 @@ static void task_cache_work(struct callback_head *wo= rk) if (p->flags & PF_EXITING) return; =20 + next_scan =3D READ_ONCE(mm->sc_stat.next_scan); + if (time_before(now, next_scan)) + return; + + /* only 1 thread is allowed to scan */ + if (!try_cmpxchg(&mm->sc_stat.next_scan, &next_scan, + now + EPOCH_PERIOD)) + return; + if (!zalloc_cpumask_var(&cpus, GFP_KERNEL)) return; =20