From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=52.35.192.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796336099; b=inEEW1Cl9wlf2Z6rhL6WqtHP1u2N56mUBBwua1cyqhC9VvyXzLZtjevilijN9RBZ92w4 AO0WfRRh5uDwjy8sfEOB9BxhjscfOS8cEZwGwFjcdAkBuhycSSSxRtjzW0LUO5oEG4fHh uZexDULCFr50ogl9sQ321CpiVIT2H084HOSxRC+z23d+tPEQro1476jiWzwXvZDmaic3b +LW09nIOSp+26SgQQgFA6aUjZqxz1K95aaV2Axgvr3wZROxj88QzI8LCcrOy1H4afEGGa 56JYCxc6jtKV/SZ+prFav2Y/FG9R6BsKZuor7zZdWMES76hZFC3ui1l4gwDSmst7rEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796336099; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:Received:Received:X-Farcaster-Flow-ID:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=89GmLsOZUoFMtp3xBAUAi52Hl28RXXe4jD7MILzpHLE=; b=DbnJwyMqwFb8NVxkpuVEj21FOQxouEzzB8K9tFeVw1zTTTe+TC3NVscuCpeQRH1xLjln mbQZW7gKmydFDSz0kn6vwf7d0u4psQiPrsOdUruzzmjZVApGa9AdF6VrxFxruxxPuqX/c kJL5pb7v0E0D4PBrNjlexcfONuL0RqKDJ4s1jfYaOUnZ/R2ctAVG8RG36KhotcXeqdo75 wlJSDFfppNnttbC00tKjrNrLyZPL8lPYbr2si2deySwUpEYTimfhw82Ule4VR07jcLmug ebzjYKTgWFb9cw7LMKZpEd0mEV+gzXnQYD0w+Ou2TYlYARd0tNDyEsUv9/rfMe6xUQA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass header.d=amazon.de header.i=@amazon.de header.a=rsa-sha256 header.s=amazoncorp2 header.b=mMHJ+Rew; arc=none smtp.remote-ip=52.35.192.45 Received: from pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com [52.35.192.45]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23953606A322; Thu, 3 Dec 2026 22:14:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 23953606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=amazon.de header.i=@amazon.de header.a=rsa-sha256 header.s=amazoncorp2 header.b=mMHJ+Rew DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1796336099; x=1827872099; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=89GmLsOZUoFMtp3xBAUAi52Hl28RXXe4jD7MILzpHLE=; b=mMHJ+RewWok0RYFRuexlOTjPuNqp6bqN/rYVt+Vw2uF7SKaCefD1wVog 6VsP9fysISS5+S6jStLejLzkeGX+CzIKfCpP00HrOkTcgtg0Hb/6CuyWR qO5DuT4kC2PoxnaceZDGrfnrnX1kU4/RU75nN6V6K869lPowxtgxHoQE4 y1DKcGr1z99eXFRQaLjIhldWFK0pbuCwcjdL25RCGRnZTE1mSWzJCSvFv OHC/ADkfL3Q6lN8BJOCo62c3qpqyEuz59w9zvHPowQBjFMq0dW15MKRT6 GRcwpWuaoDHW/6/Ale5QG5nXiSKJZWuvKnZ/6N66Zyua69Roc/nGYbUt7 w==; X-CSE-ConnectionGUID: iEvmfNeuTMG1ku6mpj73JQ== X-CSE-MsgGUID: vAM5D1NbRpSM3N9pFjBaLQ== X-IronPort-AV: E=Sophos;i="6.29,77,1794873600"; d="scan'208";a="35587831" Received: from ip-10-5-0-115.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.0.115]) by internal-pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 22:14:49 +0000 Received: from EX19MTAUWC002.ant.amazon.com [205.251.233.111:23782] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.48.218:2525] with esmtp (Farcaster) id e693c0af-c157-40c8-9f17-f04f26abbf7d; Thu, 3 Dec 2026 22:14:48 +0000 (UTC) X-Farcaster-Flow-ID: e693c0af-c157-40c8-9f17-f04f26abbf7d Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Thu, 3 Dec 2026 22:14:48 +0000 Received: from dev-dsk-araoof-1b-23e02486.eu-west-1.amazon.com (10.253.65.187) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Thu, 3 Dec 2026 22:14:45 +0000 From: Ahmed Abdelraoof To: Ingo Molnar , Peter Zijlstra CC: Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , "Mel Gorman" , Valentin Schneider , "K Prateek Nayak" , Jonathan Corbet , Shuah Khan , Randy Dunlap , , , Anselm Busse , Ahmed Abdelraoof Subject: [PATCH 4/4] sched/core: Support L2 cache isolation Date: Thu, 3 Dec 2026 22:13:07 +0000 Message-ID: <20261203221307.86078-5-araoof@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203221307.86078-1-araoof@amazon.de> References: <20261203221307.86078-1-araoof@amazon.de> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D031UWC003.ant.amazon.com (10.13.139.252) To EX19D001UWA001.ant.amazon.com (10.13.138.214) From: Anselm Busse Core scheduling only isolates SMT siblings from each other. Cores that share an L2 cache can observe each other through it much as SMT siblings can through the core, so on processors that pair cores around a shared L2 core scheduling leaves that path open. Add a kernel command-line parameter "sched_core_unit=X", where X can be "smt" (the default) to keep the SMT siblings as the isolation unit, or "cluster" to use the CPUs of a cluster as reported by topology_cluster_cpumask(). On x86 a cluster is the set of CPUs that share an L2 cache. All CPUs of a unit share one rq lock, so a wider unit trades some lock contention for the isolation. If "cluster" is selected but no cluster spans more than one CPU, warn that no clusters were reported and core scheduling is unavailable. Signed-off-by: Anselm Busse Co-developed-by: Ahmed Abdelraoof Signed-off-by: Ahmed Abdelraoof --- .../admin-guide/kernel-parameters.txt | 12 +++++ kernel/sched/core.c | 44 +++++++++++++++++++ kernel/sched/sched.h | 18 ++++++++ 3 files changed, 74 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 176648941aec..faaeb4812b60 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6801,6 +6801,18 @@ Kernel parameters cost of significant additional memory use for tables. + sched_core_unit= + [KNL,EARLY] Select the CPUs that core scheduling treats + as one isolation unit, i.e. that never run tasks with + different core scheduling cookies at the same time. + Format: { smt | cluster } + smt - SMT siblings (default). + cluster - CPUs in the same cluster, as reported by the + CPU topology (on x86, the CPUs that share an L2 + cache); for processors that pair cores around a + shared L2 without SMT. + See Documentation/admin-guide/hw-vuln/core-scheduling.rst. + sched_proxy_exec= [KNL] Enables or disables "proxy execution" style solution to mutex-based priority inversion. diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c69f40e7b93a..6640ea861818 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -429,6 +429,50 @@ static DEFINE_MUTEX(sched_core_mutex); static atomic_t sched_core_count; static struct cpumask sched_core_mask; +enum sched_core_unit_type sched_core_unit __ro_after_init = SCHED_CORE_UNIT_SMT; + +static int __init sched_core_unit_setup(char *str) +{ + /* A bare "sched_core_unit" with no value arrives here as NULL. */ + if (!str) + return 0; + + if (!strcmp(str, "smt")) { + sched_core_unit = SCHED_CORE_UNIT_SMT; + } else if (!strcmp(str, "cluster")) { + sched_core_unit = SCHED_CORE_UNIT_CLUSTER; + } else { + pr_warn("sched_core_unit=%s unrecognised, using smt\n", str); + return 0; + } + + pr_info("core scheduling isolation unit: %s\n", str); + return 0; +} + +/* + * Parsed from start_kernel(), so the value is stable well before the first + * sched_core_cpu_starting() elects any rq->core leader. + */ +early_param("sched_core_unit", sched_core_unit_setup); + +static int __init sched_core_unit_check(void) +{ + int cpu; + + if (sched_core_unit != SCHED_CORE_UNIT_CLUSTER) + return 0; + + for_each_online_cpu(cpu) { + if (cpumask_weight(sched_core_isolation_mask(cpu)) > 1) + return 0; + } + + pr_warn("sched_core: cluster unit spans a single CPU everywhere; no clusters reported, core scheduling unavailable\n"); + return 0; +} +late_initcall(sched_core_unit_check); + /* * The rq locks of a unit share one lockdep class, and a subclass per CPU * would overflow MAX_LOCKDEP_SUBCLASSES on units wider than eight CPUs. So diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 97126c1dcb09..bc7030b4ff75 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1588,13 +1588,31 @@ cfs_prio_less(const struct task_struct *a, const struct task_struct *b, bool fi) extern void task_vruntime_update(struct rq *rq, struct task_struct *p, bool in_fi); +/* + * Which topology level core scheduling treats as its isolation unit. + */ +enum sched_core_unit_type { + SCHED_CORE_UNIT_SMT, + SCHED_CORE_UNIT_CLUSTER, +}; + +extern enum sched_core_unit_type sched_core_unit; + /* * The core scheduling isolation unit: the set of CPUs that share one runqueue * lock and that are constrained to run tasks carrying a single cookie at any * instant. + * + * On x86 topology_cluster_cpumask() is cpu_l2c_shared_mask(), which is built + * from the CPUID leaf 4 L2 descriptor whenever there is more than one core per + * package, independently of CONFIG_SCHED_CLUSTER. So the cluster unit does not + * require a cluster sched domain to exist. */ static inline const struct cpumask *sched_core_isolation_mask(int cpu) { + if (sched_core_unit == SCHED_CORE_UNIT_CLUSTER) + return topology_cluster_cpumask(cpu); + return cpu_smt_mask(cpu); } -- 2.47.3