From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 08BEA156237 for ; Tue, 6 Jan 2026 04:23:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767673433; cv=none; b=HMD1JVqJb37/E4WVR0s9U7/76R6bWHGbrTBigp7oPC2j6yYn06HGTNZG4LY2ZMSbHfw0anl1aH+utKizlSb27qZaTDXvB5DEa1bQUdh2AlN7nSlDh+7Bv4yin4J7wlorzffQb5SNufqyJUOkmjf9WrtMFUYqJx6LS/zTykcqvBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767673433; c=relaxed/simple; bh=dJxlmZ3D2H/fJQZGT7lmrL7jJ1UroG0Aoc5zWD8po/8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Vla/HE7Qc1hykfYvw75WH4ac00TJK7JBeawCSDSHANkUIlMgBjQCuNOBRaVtJrzg3lFFdCetPIiVEQLlFYJJMyTVjOhR4OG3H6toBBnRoJPvvqZ4GLomf6ZTfaLpuJ3oxMf3q5kNhnEoKPFZFyGbGmW8pjPjW2ZMrNakSiRO8M4= 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=S2ARM6fc; arc=none smtp.client-ip=148.163.156.1 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="S2ARM6fc" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 6061r0mh021887; Tue, 6 Jan 2026 04:23:20 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=HsodDP Vf+m/vuyXPDyvVtfIWNmYZkkCDY0N9mrhcsTc=; b=S2ARM6fcnUhwjEfycnTP/b LUjBAigzI7KMkacghcgQ75j/XYe5Ay0jlkh2g+QpwlNHnTAB6HGIWiJp3+YvY1pq rT+aJ5j9ZMWGxxs708LEmvGcG5unQVaIVHy5ZugKoCoqW/6MC7xeeedH3FTrfZ1p 6CXSfBXKqUHwO1Rvylcvnq9BSQIFzu4gbbVnQ+6heipethwvyhY9RmlCpM4j+gol GCmjEfcKvJXbKhfRZQuGI/BPGE9sNMJKyPGiah/xPUoUpa8yoBcfloW7nag874JJ 670S+ZtJlzQ3iD3dK1bsv6HDtDbN41b9x+BtxBbw6B/eUXi1Kzo84s4zPT2NIJIw == Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4betu629fj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Jan 2026 04:23:19 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 6060wSZ0014542; Tue, 6 Jan 2026 04:23:18 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4bfeemsefq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 06 Jan 2026 04:23:18 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6064NGvJ50594134 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 6 Jan 2026 04:23:16 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7511F2004F; Tue, 6 Jan 2026 04:23:16 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 02A6020040; Tue, 6 Jan 2026 04:23:14 +0000 (GMT) Received: from [9.124.214.89] (unknown [9.124.214.89]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 6 Jan 2026 04:23:13 +0000 (GMT) Message-ID: <4f3f52ab-b2d5-4c9e-bf9e-94ea75d3dade@linux.ibm.com> Date: Tue, 6 Jan 2026 09:53:13 +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 v2 2/3] sched/fair: Change likelyhood of nohz.nr_cpus and do stats update if its due To: K Prateek Nayak Cc: linux-kernel@vger.kernel.org, juri.lelli@redhat.com, vschneid@redhat.com, tglx@linutronix.de, dietmar.eggemann@arm.com, anna-maria@linutronix.de, frederic@kernel.org, wangyang.guo@intel.com, mingo@kernel.org, peterz@infradead.org, vincent.guittot@linaro.org References: <20260102124744.360872-1-sshegde@linux.ibm.com> <20260102124744.360872-3-sshegde@linux.ibm.com> <880e3610-dbdb-42a8-9ddb-ab2e7d3cdc1f@linux.ibm.com> <71485a68-c0b0-446a-8326-7c10c583e076@linux.ibm.com> <7050ce6c-64d6-4359-9a4c-9fd4362e5290@amd.com> Content-Language: en-US From: Shrikanth Hegde In-Reply-To: <7050ce6c-64d6-4359-9a4c-9fd4362e5290@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=QbNrf8bv c=1 sm=1 tr=0 ts=695c8e37 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=eJTnxkHzwNBm_rMR:21 a=IkcTkHD0fZMA:10 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=NDKfK31jz_NL8C4weHwA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-ORIG-GUID: _PPtS69p2dtBCi10BQPmftBYJjg4rLj4 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTA2MDAzMyBTYWx0ZWRfX4nk4q3Jf3h3c A0fqkJBTIhKavExiJ4Uhw6In9wuxI6gJsBpIFfUYbgr+MSviggVO94V320tgVhlYGZiGUUcN4y2 iWy8fEXWoMwBamZpZNTFnVJ7ZCHo8BQ4DZs0rze68J4IrC6HBHl3QriM5fnamfW97oCIDinlgHu RogtS1s8pWZqMiUIA0KEBZwLCrYB0af50MsOAaWAjsLrmDWs2Oe4rWMv9vlSuj+GeyiJLbaC5A2 MaqnrFkQsklxdQKPvWe5nrFJw/ZwRIwYzW3KXqjDx0Ckbr3GlmKVIbYzZO8+DRNcj763oWxQCWc SigutV4n6CjDQ5QTVODgeO3oPtWtUcBwnkWIhxlG60RsOfd9rf4EKqZb85wE7dG6G/9f9z4XPPs UiWBLyWdRd7vlishSad+XXCT+nVF2A2re9c5PntyxSOfA5y5U9AfiO7byXeX0BK1KkXvCLIQY2p qhv/2YIbZ7dSJzUONzA== X-Proofpoint-GUID: _PPtS69p2dtBCi10BQPmftBYJjg4rLj4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-05_02,2026-01-05_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 bulkscore=0 suspectscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2512120000 definitions=main-2601060033 On 1/6/26 8:33 AM, K Prateek Nayak wrote: > Hello Shrikanth, > > On 1/5/2026 4:09 PM, Shrikanth Hegde wrote: >>> So cumulatively, including Patch 3, we do: >>> >>>      flags = 0; >>> >>>      if (READ_ONCE(nohz.has_blocked_load) && ...) >>>          flags = NOHZ_STATS_KICK; >>> >>>      if (time_before(now, nohz.next_balance)) >>>          goto out; /* Checks nohz.idle_cpus_mask in find_new_ilb() ... (1) */ >>> >>>      if (unlikely(cpumask_empty(nohz.idle_cpus_mask))) >>>          goto out; /* Still goes to kick_ilb()                     ... (2) */ >>> >>>      ... >>> >>> out: >>>      if (READ_ONCE(nohz.needs_update)) >>>          flags |= NOHZ_NEXT_KICK; >>> >>>      /* assume either NOHZ_STATS_KICK or NOHZ_NEXT_KICK is set */ >>>      kick_ilb() >>>      { >>>           if (flags & NOHZ_BALANCE_KICK) /* Not possible */ >>>               ... >>> >>>           ilb_cpu = find_new_ilb(); /* Find CPU in nohz.idle_cpus_mask */ >>> >>> >>> If we arrive here from (2), we know "nohz.idle_cpus_mask" was empty a >>> while back and we've not updated any global "nohz" state. If we don't >>> find an ilb_cpu, we just do: >>> >>>          if (ilb_cpu < 0) >>>              return; >>> >>> So why not simply return from (2)? >>> >> >> I see, kick_ilb though called will not do a balance since ilb_cpu was not found. >> >> I don't want to have that return in between the two out's. >> >> How about we do below? When there are no idle CPUs left, both has_blocked_load >> and needs_update should be reset. no? >> >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >> index 805b53d9709e..fa0e6065bc9c 100644 >> --- a/kernel/sched/fair.c >> +++ b/kernel/sched/fair.c >> @@ -12377,6 +12377,15 @@ static inline int find_new_ilb(void) >>                         return ilb_cpu; >>         } >> >> +       /* There is no idle CPU left. >> +        * reset has_blocked_load and needs_update, such that unless >> +        * some CPU enters idle state, it will not trigger kick_ilb >> +        */ cpumask_empty check. >> +       if (READ_ONCE(nohz.has_blocked_load)) >> +               WRITE_ONCE(nohz.has_blocked_load, 0); >> +       if (READ_ONCE(nohz.needs_update)) >> +               WRITE_ONCE(nohz.needs_update, 0); >> + > > I'm slightly skeptical - find_new_ilb() will also fail to find any CPU > if idle_cpu() returns false momentarily. > Yes. I even thought to put cpumask_empty check here and then do these updates. But since there might be a window where a remote CPU may be going idle, might race with it and possibly lose a chance for idle balance. Since it is extreme case of 100% busy, all these checks may not be necessary. Will put a return instead :) Thanks for pointing that out. > Those CPUs can again go back to idle without updating > "nohz.has_blocked_load" - tick_nohz_idle_stop_tick() will skip > nohz_balance_enter_idle() if the CPU already had TS_FLAG_STOPPED set. > > For those cases, we'll need to retain the "nohz" state as is until a > suitable ILB CPU can be found - this is the reason why we delay > clearing the "nohz" state until _nohz_idle_balance() and reconstruct it > once the CPU is done with idle balancing. > > There are also nuances like the smp_mb__after_atomic() in That reminds me, need to upgrade this to smp_mb now, given atomic is gone. > nohz_balance_enter_idle() which requires us to check the > "nohz.idle_cpus_mask" after we are done clearing "nohz.needs_update" > and "nohz.has_blocked_load". > >>         return -1; >>  } >> >> >