From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 D9DE03FE373 for ; Mon, 11 May 2026 14:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778510358; cv=none; b=nkAkTQc4seFxuBhb/BvehY8yy+sEHXYqkFkgCwOiCyTfy4ByvBACMrzKZJgtlCGqjUPYa02TBZX8OUUdBo0+xXkYUdBAEwyzUU181IiLms5ATzQXdmcBukdMuqei6VxxpR+HRq6kNUn3QSZnLJsJBbR6dZuQ/tr7dwMHZEtujh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778510358; c=relaxed/simple; bh=L8MnGgVx4ipXRjJiASTpDn37hq1KE4QvKqAM1kqx2AQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=c211+KMi3gjnJa0KVAU23sS1qgbfQwx0rVPlZOWDPLu88AI6fjj3f25fTkI36HnQoPKRbud0S8C8ODggJs2xD/tmhFZ1xgZKI9VRsNMeXO9qwjeCq9VCIVPyAhD+5k8UJ6NCHpPOUdNEuGubewEUCB+R2LtGRAlvy1+6EjGG66s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=PqUcoUOm; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="PqUcoUOm" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64AMnXa2994360; Mon, 11 May 2026 14:37:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=JOi3tT dwcVnRdDTgfNHLLlAxEWJP/WJS2/KvTjoI46Q=; b=PqUcoUOm69Cl09zs7PiPrx p/FctgIKRHCsRLfvMdzY8ebLFhRCPQrTOU1DkBfoGU2ITc7991NEbj3sIAyWV4Qe gLuvbVppBg3jwcP9FnJBEWZ+cxlaPlBbqBSwDiWM/6YUsNnC+uordKIOpNXohdKb vjT7B7Zp53if/Mllw2UyRtfiQyauDWwAp3SzMMhGS1ZzE1vX1+JqIcxLRkuBzAVw KLgi6NeSD/FojLIj7SAfhfosVqu6Zt4cw7SywsE91ZndBlt+SuAelU98nGC+3xAn czC2lWViMheBaQvEonl9haIRr+XwRWXfogDS3ZrQ8ekKw1hEs8Y9lJH73ili56Xg == Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4e1ubdr8wy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2026 14:37:29 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64BEOW0D008812; Mon, 11 May 2026 14:37:29 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4e2f8q5t6n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 May 2026 14:37:28 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64BEbRQb38470092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 May 2026 14:37:27 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57DA020043; Mon, 11 May 2026 14:37:27 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2C76D20040; Mon, 11 May 2026 14:37:24 +0000 (GMT) Received: from [9.124.213.250] (unknown [9.124.213.250]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 11 May 2026 14:37:23 +0000 (GMT) Message-ID: <09edb32d-774a-4780-bb05-cb227f6cddb7@linux.ibm.com> Date: Mon, 11 May 2026 20:07:23 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] sched: Simplify ifdeffery around cpu_smt_mask To: Valentin Schneider Cc: kprateek.nayak@amd.com, juri.lelli@redhat.com, dietmar.eggemann@arm.com, tj@kernel.org, rostedt@goodmis.org, tglx@kernel.org, mgorman@suse.de, bsegall@google.com, arighi@nvidia.com, linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, vincent.guittot@linaro.org References: <20260506110052.9974-1-sshegde@linux.ibm.com> <20260506110052.9974-3-sshegde@linux.ibm.com> From: Shrikanth Hegde Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=BezoFLt2 c=1 sm=1 tr=0 ts=6a01e9aa cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=wJGt2gl0L4RlWVxg5zcA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: 0U18IdCWbf6Mj96fBxSuX8wlFMQV6XeS X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTExMDE2MiBTYWx0ZWRfX2vLcFn+bshiF MB4RoFm/KhvJAKV5CVTmN0o1dzMfvoRTZ42lRvO2jauIxPzwhWBlOm0R+uwtBA07dIUTEPNbZcd BJpez3GFv9H/av3IgHVKT4Gjbxw134KKVpe5RJaFTfVATYrlU7bd8PuoKVmJWS7c1gPmQR5i4lD HGOXQuJdmh4cU6HmqAU3tTSPhXfWpI0g6L1v3y2ug4elaeYMmUDXLiQJ20VlWeuBeinF+HRLbot ikypfJXFVtwLSz6oacOwWM3gKcF1i0x0d3CXnkgZ/Tmwf1TBr+emrNopKage6Eq4wpMwvTrX8+b aHeqDnWxHK5oV/kgTczyqqaYjSkvzPhmROPTn/oV94u4GY3TNpRwPe6LYJa21uNHIdg9gT3JcYe yqalKBgfPZzBSYXUQgw5USa67RBikXqAdOgVYfEvMDPeiM6z0Vv8gkN/H1nlOjnJIpHLgzk7onK 4LWa8BjghOjN+FBlXdg== X-Proofpoint-ORIG-GUID: krK5oB3-157TRY2f7vG0u2L7hoM8auan X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-11_04,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 phishscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605110162 Hi Valentin, Thanks for the reviewing this patchset. On 5/11/26 6:23 PM, Valentin Schneider wrote: > On 06/05/26 16:30, Shrikanth Hegde wrote: >> Now, that cpu_smt_mask is defined as cpumask_of(cpu) for >> CONFIG_SCHED_SMT=n, it is possible to get rid of the ifdeffery. >> >> Effectively, >> - This makes sched_smt_present is defined always >> >> - cpumask_weight(cpumask_of(cpu)) == 1. So sched_smt_present_inc/dec >> will never enable the sched_smt_present. Which is expected. >> >> - Paths that were compile-time eliminated become runtime guarded >> using static keys. >> >> - Defines set_idle_cores, test_idle_cores etc which could likely benefit >> the CONFIG_SCHED_SMT=n systems to use the same optimizations within the >> LLC at wakeups. >> >> - This will expose sched_smt_present,stop_core_cpuslocked symbol for >> CONFIG_SCHED_SMT=n. Likely not a concern. >> >> - There a bloat of code CONFIG_SCHED_SMT=n. (NR_CPUS=2048) >> add/remove: 25/18 grow/shrink: 26/19 up/down: 6696/-3064 (3632) >> Total: Before=30771823, After=30775455, chg +0.01% >> >> - No code bloat for CONFIG_SCHED_SMT=y, which is expected. >> > > Some nitpicks below, otherwise this LGTM except the sched_ext bits which > I'm not familiar enough with. sched_ext just added the ifdefs for the masks i think. It has sched_smt_active() already. > >> @@ -8703,9 +8699,7 @@ int sched_cpu_deactivate(unsigned int cpu) >> */ >> sched_smt_present_dec(cpu); >> >> -#ifdef CONFIG_SCHED_SMT >> sched_core_cpu_deactivate(cpu); >> -#endif > > That ends up grabbing @core_lock, arguably this is during hotplug but still > seems a bit wasteful when, with CONFIG_SCHED_SMT=1, we know the mask weight > will never exceed 1. Probably worth adding a sched_smt_active() check > within the callee. > Ok. Fair enough. Even cpu bringup path too could use the same opt. Something like below? --- diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 084ec3987d7c..add0fcc8ba90 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6494,6 +6494,10 @@ static void sched_core_cpu_starting(unsigned int cpu) struct rq *rq = cpu_rq(cpu), *core_rq = NULL; int t; + /* No point in doing anything further if SMT is not active */ + if (!sched_smt_active()) + return; + guard(core_lock)(&cpu); WARN_ON_ONCE(rq->core != rq); @@ -6533,6 +6537,10 @@ static void sched_core_cpu_deactivate(unsigned int cpu) struct rq *rq = cpu_rq(cpu), *core_rq = NULL; int t; + /* No point in doing anything further if SMT is not active */ + if (!sched_smt_active()) + return; + guard(core_lock)(&cpu); /* if we're the last man standing, nothing to do */ > >> @@ -632,7 +632,6 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus) >> } >> EXPORT_SYMBOL_GPL(stop_machine); >> >> -#ifdef CONFIG_SCHED_SMT >> int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data) > > That seems to be only used by the INTEL_IFS selftest stuff which does some > wait_for_sibling_cpu() loop; at a quick glance it seems to do the right > thing for weight := 1 but IMO worth a proper look. That or have the IFS > code not run that when there is no SMT. > Right. intel_ifs is the only user. INTEL_IFS depends on SMP. SMP select CONFIG_SMT on x86. Symbol: INTEL_IFS [=n] Depends on: X86_PLATFORM_DEVICES [=y] && X86 [=y] && CPU_SUP_INTEL [=y] && 64BIT [=y] && SMP [=y] So, maybe leave this as is, to avoid the code bloat for CONFIG_SCHED_SMT=n as there is no user? Maybe i will add a comment about it. from ./bloat-o-meter. it adds about 260 stop_core_cpuslocked - 260 +260 Does that make sense?