From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 E66593DD52B for ; Fri, 7 Aug 2026 09:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786096378; cv=none; b=MTbwVt9z1t4zvzGDGPE4czgRQzK7woqRmhnNoWua7JbKb90p1jHf0K7xYYfEpuFjSiWSTbCFyXMySh6hd8YJeg7hQaR0sljXRjk94WaoX8wSkdfZwVUHbb8PsBpwulvmEVGE/h3latK6ntGKR7EY5s/cPruFTAUxKnuDwhEyhco= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786096378; c=relaxed/simple; bh=b7Fn3YXtiycWQhrhKmqwVhyahelDzgkV/45ogfBQGrg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LHRgX+nQUr0658OLiEhjCdHnFQaa3GXlQptfCDx3IWzPTge+DiuEYvTLncYGInJucL2VXkN8Lpqq+ObdPGJewQTYNJz67aWCapz4TuPUi3+IhcHUYCwpM9GYYlc3a3yObuAITDqH3fHOwaj/NTxLNSMHhb4xepPjg5zDsaeY0as= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lui7aXGV; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lui7aXGV" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1786096374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JDwm+bpfV7sp0NsZLwL1fTQ362BSpnSPvzSiZiTS6Fw=; b=lui7aXGVJkSnI0rAHadiry2sYbiWFdwOkuGEJ+3fSB9vF08NjgPVE97bRLmlxldeGB8NRy 5dUBrC3+JrDanqM8ZvKisu4LO+WgpoRcpWT7jN+xNbYbWcDgZMdvn9XlB6GMvxQgCJC4mE 4bPNYwA4ofcXYMgMMS0282FAkY+XR68= From: Usama Arif To: Usama Arif Cc: bsegall@google.com, dietmar.eggemann@arm.com, hannes@cmpxchg.org, juri.lelli@redhat.com, kprateek.nayak@amd.com, linux-kernel@vger.kernel.org, mgorman@suse.de, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, surenb@google.com, vincent.guittot@linaro.org, vschneid@redhat.com, shakeel.butt@linux.dev, riel@surriel.com, kernel-team@meta.com Subject: Re: [PATCH v2] sched/psi: use __ffs() to walk task-count bitmasks in psi_group_change() Date: Fri, 7 Aug 2026 02:52:45 -0700 Message-ID: <20260807095247.1010546-1-usama.arif@linux.dev> In-Reply-To: <20260717105939.203685-1-usama.arif@linux.dev> 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 X-Migadu-Flow: FLOW_OUT On Fri, 17 Jul 2026 03:59:39 -0700 Usama Arif wrote: > psi_group_change() walks the @clear and @set bitmasks to > decrement/increment groupc->tasks[t]. Both masks are at most > NR_PSI_TASK_COUNTS (=4) wide and typically have one or two bits > set. Today's form visits every position up to the highest set bit: > > for (t = 0, m = clear; m; m &= ~(1 << t), t++) { > if (!(m & (1 << t))) > continue; > ... > } > > so a mask with only bit 3 set still spins four times through the > skip path. Switch both walks to __ffs() + m &= m-1 form: > > while (clear) { > t = __ffs(clear); > clear &= clear - 1; > ... > } > > which iterates only over the set bits and terminates naturally on > m == 0. m & (m - 1) clears the lowest set bit. This code is easier > to read as well. > > An in-kernel microbench (noinline, same body, IRQs off, pinned CPU > on Zen4c, min-of-10 cyc/call) over mask distributions produced by > common scheduler PSI paths: > > mask pattern old new delta > empty (clear=0x0, set=0x0) 3.68 3.68 +0% > sleep (clear=0x4, set=0x0) 9.60 3.74 -61% > iowait-sleep (clear=0x4, set=0x1) 12.32 4.45 -63% > memstall-sleep (clear=0xc, set=0x0) 11.87 5.54 -53% > wake (clear=0x0, set=0x4) 7.10 3.70 -47% > iowait-wake (clear=0x1, set=0x4) 10.83 4.48 -58% > > Every non-empty case wins 47-63%: old cost tracks the highest set bit > (linear walk), new cost tracks the count of set bits (skip zeros via > TZCNT). Single-bit patterns run at the empty-case floor. > > The generated psi_group_change() text also shrinks by 67 bytes under > -O2 -march=x86-64 (756 -> 689): no scratch register for a "constant 1" > (only __ffs's operand is needed), simpler bit-clear (LEA+AND vs > SHL+NOT+AND after the test), and no skip-if-unset check per position. > > Acked-by: Johannes Weiner > Signed-off-by: Usama Arif Hello Peter! Just wanted to check if there were any comments or feedback on this patch? I checked sched/core branch and didn't see the patch there. Thanks! Usama