From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 A592F25B0B6 for ; Wed, 13 May 2026 20:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778704415; cv=none; b=RbyuV76HA0Pp4brRK2DNoWoXHpU2ScD7aBMla60KJQSou6VNJRYOtPrFF3hctkg6gxVY8RLMqleprjkJnJWd4rCOQoNUPY5/Mvy2e/fcYibDL+7lNp6VFT6ze/vipd0tYKJG1ihHdWj2OP/jObEKldiC6GymRrQQff/4C90HwIc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778704415; c=relaxed/simple; bh=9dRtMFEnE3sO2bgwlBXd25CqjvGaW8hJO8hC9cFO1v4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MCrZToyTXSGdEmzebuGMCckYIADKpUaobeqDJpdjgQX6kZVOQiGLqx4lLVwnaabiZ64XWvj452F1lFA/Z37vAn1lCetCDJYhvUfXJUS+HC2p8Zss4pTBBBS5bLmZFPYD7jWA8GQI59gNi/CtMPVvdm+V3iPV2C6bSqUUB2x9vnY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DTQ7q5O8; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DTQ7q5O8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778704414; x=1810240414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9dRtMFEnE3sO2bgwlBXd25CqjvGaW8hJO8hC9cFO1v4=; b=DTQ7q5O8z9N0MITEoysSiUb75BiQcKrdlno02Xo/kHVdAGdn1TZC1d/t +DkgHJPXgvwtNyfbL/l3M3p48P2fEVnTkt46AmA8gDrOCjQhQB3AW+K0B 2PZ4gLygmoUsdGqQ5uV29EHvGiQCWMTq1/O73GyrBebehnORmF3lEi+Z5 Ot5p9tW2o27avxGsk4W9CAzlkGwloIfu1u44zxutfKeqPlcLrgDP0gYx8 K+3D3syno0dlqMyGoE8TiiY8lPCRgX03kFME22RecO14q6Y+4UZJD5kyX HxH+pXBKVyurxjbGxwx9AeXkS1QWQ+eYXYJVRuF22uOrqHJ+zZWvuoSri w==; X-CSE-ConnectionGUID: /hNjS7tiT8a3DisGQHNXhQ== X-CSE-MsgGUID: I8Drt1ZeSRy5I38KZBdzrw== X-IronPort-AV: E=McAfee;i="6800,10657,11785"; a="79622968" X-IronPort-AV: E=Sophos;i="6.23,233,1770624000"; d="scan'208";a="79622968" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2026 13:33:33 -0700 X-CSE-ConnectionGUID: WFVFDNOkSNC756h9ak1WyA== X-CSE-MsgGUID: vyvJQmtlRcG+Vk5HobAMBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,233,1770624000"; d="scan'208";a="238076313" Received: from b04f130c83f2.jf.intel.com ([10.165.154.98]) by orviesa008.jf.intel.com with ESMTP; 13 May 2026 13:33:32 -0700 From: Tim Chen To: Peter Zijlstra , Ingo Molnar , K Prateek Nayak , Vincent Guittot Cc: Jianyong Wu , 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 , Tim Chen , Aubrey Li , Zhao Liu , Chen Yu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , Josh Don , Gavin Guo , Qais Yousef , Libo Chen , Luo Gengkun , linux-kernel@vger.kernel.org Subject: [Patch v4 01/16] sched/cache: Allow only 1 thread of the process to calculate the LLC occupancy Date: Wed, 13 May 2026 13:39:12 -0700 Message-Id: <5672b52e588b855b01e5a1a17822f7c6c7237a3d.1778703694.git.tim.c.chen@linux.intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jianyong Wu 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 --- 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 d2010483cd77..6d883f109ba3 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; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 5f22e5a097cf..a759ea669d74 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 = epoch; mm->sc_stat.cpu = -1; + mm->sc_stat.next_scan = jiffies; /* * The update to mm->sc_stat should not be reordered @@ -1661,6 +1662,7 @@ static void get_scan_cpumasks(cpumask_var_t cpus, struct task_struct *p) static void task_cache_work(struct callback_head *work) { + unsigned long next_scan, now = jiffies; struct task_struct *p = current; struct mm_struct *mm = p->mm; unsigned long m_a_occ = 0; @@ -1675,6 +1677,15 @@ static void task_cache_work(struct callback_head *work) if (p->flags & PF_EXITING) return; + next_scan = 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; -- 2.32.0