From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35A9B2E06ED for ; Thu, 18 Jun 2026 16:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781799663; cv=none; b=oLt7TIUaRUZFS9wbWwhpclQWtBzBQgDWcqmAy32aHG+/fuPWdZlz/guPnd1wvzR0AnQdeSk+HljfqFSNMan1H1iZCUZn4SLJsZfEWmH9vE8jqxEpz9FqIP0d9lL1exS5n1mmg+yOXG7XvoKzgjFstrH2X5p5GNG+fyZ7jyp35zM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781799663; c=relaxed/simple; bh=GzkStzpMtOUGyqQKHYM+OI+6wYtzdzu1cYYzZi7cUTg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U1sLRlUypmJnW4NrL04QslcL02+g5eCGoecQxXxWHLUhPXnBYvKw7McHFAu985V/BFO6d/1o+M80aGHOVm8Xfr2WBo9oPfHhjJKhb58avCg8XdBSeD7qafPQfgfqzuzrQ04W7Mac13qEUBdI+S7twYmBF34PazXDlqiJRgkYVvM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=pU2im8dC; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="pU2im8dC" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-5176ca6bab1so13042371cf.0 for ; Thu, 18 Jun 2026 09:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1781799660; x=1782404460; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=q0TqgCvzrxOigKV5Uh4y3eBAfwHwTb6Ism6AMx0v3Pc=; b=pU2im8dCOtuMDEmO2pLmKswFie6RDXbM4mc2FmNXPmtgvvZHF56EKZdr/5g6yhuCyD z0Ei1++BNHWH+38rYc4+bXUOd83SFBAhAIy+e+wsP0wbApwbdg0uDHfEUhbZWCFTuVec 46hseImUjkDLyGgpAsqyzvuxGpYIOWaF2wx8frvPmfZDaQKQWZRwcZVLA5RAEanHVW7h c3NP2RfReZPwy40QG5trXBk9+DSXhq6WlV7xQ6JQlWnBm2OzBp5vb+PdpwJ3jDGKBCJb jIsxI1TC08v5cnactldKFLrIrnuOW44cs9PBeTUg+Yso6m1OTKDP4Uj9KSkyUGNv9/NT FCMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781799660; x=1782404460; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q0TqgCvzrxOigKV5Uh4y3eBAfwHwTb6Ism6AMx0v3Pc=; b=WzDL14AcdQ48f3PNc0hz2r5quX3F/lfdBN9MhTk1EtjCR9sulVHN5/43xMpw8zX6oO se9nwOqNcYNVCMFdUW+XdqNwSB0MBnYjdrHXHK/jGulD5EHExctTASechV3dsirj6+IK Cp9eAvOYmREBTviKHd06QHBteVK5pNapo2LLSkwbaBXDbP0CykmYV7YDB5Owl71xryDx w0+rdUHBDHDGadvrmQNirnXJ1JTh+YuNJywbpcvIq0mDhRTAUzWfhT+N9HusT+OwqCvI k+/ZCXf4wst3+G9GQrPsnlZPitV1gH5rq1F2TQ3tvxDwh5HDLplDF4qc/3CfaxQQco5/ aljA== X-Forwarded-Encrypted: i=1; AFNElJ+KSiDfCtQ5AOikDIBTZw4SpwsXbyu/1hP7H7PQSzER3ChgLDGuI3jTP9SKMrGeVW4F/ifHEuf8emZGzEA=@vger.kernel.org X-Gm-Message-State: AOJu0YySwXgknFD566t5wMKXnSogYWm2kpMG1krO1g3nxwqcSCu9Nui6 5OGJTslI4OfzPNVciJVFahLT3zcwEFQ3SMcqG7RKKZj0JQoymBVPAOeWMTqf8D7qE3A= X-Gm-Gg: AfdE7cmkp5r6MZv/457isb/cvJWcWUIxDlALkTuZAGwOu2+Zw/n6zlmbPEEhzozsWTM BxyqQBU+6JPdxwRFvdnpcHzqhP1QdERm0kDak1TrE8OroHSAahd0cU8dUNWpAYCf4tU1kwDw1vj eLW9QjrItEwtFn2GBKCoTpsSE85qKlliJ+s2h8XByHPKgo7Y1PJBtdjQ18UUfYuw+8tzep1faUc oZJVU/A4c7cwfCsHtjZhdXkQ5D8HSx9FuqZ46G+H7vuf44aSzstQlcFFpzTufZBOOoEhung5e4G yaBSPIDnlIkPKUizM2kt9cf4xZ+60h1ErRsuYcAP24K9Le2Ha+ojdcST3yQpKa3yDYF7Hnsmx/X Ng/+0NrJe7clsxjgUUOl9DK2/knmWKYQUrrAT6CuIkMk0rTTfEBkpJdjh45Rf6xUUue5aNd7HWI /tt7/GFSiyEs8= X-Received: by 2002:ac8:5d47:0:b0:517:5f04:f23f with SMTP id d75a77b69052e-519c4bc1118mr52834051cf.4.1781799659683; Thu, 18 Jun 2026 09:20:59 -0700 (PDT) Received: from localhost ([2603:7001:f100:500:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-519e1d06ed6sm2389031cf.14.2026.06.18.09.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2026 09:20:58 -0700 (PDT) Date: Thu, 18 Jun 2026 12:20:55 -0400 From: Johannes Weiner To: Usama Arif Cc: Andrew Morton , david@kernel.org, linux-mm@kvack.org, bsegall@google.com, dietmar.eggemann@arm.com, 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, Chengming Zhou Subject: Re: [PATCH 1/1] sched/psi: skip irqtime accounting when no new irq time has elapsed Message-ID: References: <20260617175219.2494857-1-usama.arif@linux.dev> <20260617175219.2494857-2-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260617175219.2494857-2-usama.arif@linux.dev> On Wed, Jun 17, 2026 at 10:50:06AM -0700, Usama Arif wrote: > psi_account_irqtime() reads irq_time_read() into a per-rq cumulative > counter and only bails out when the delta vs. the previously accounted > amount is negative. A delta of exactly zero is treated as "do the > work": psi_write_begin() is taken, cpu_clock(cpu) is read (which on > x86 ends up in native_sched_clock() / rdtsc) and the cgroup ancestor > chain is walked to add zero to every group's PSI_IRQ_FULL bucket. > > The zero-delta case is common in practice -- it fires every time a > context switch crosses a PSI group boundary on a CPU that hasn't > serviced an interrupt between the two switches. > > Measured on a 176-thread AMD EPYC 9D64 server running a compute > intensive production workload, instrumented with bpftrace over a 30s > window (irq_time_read() read directly from the per-CPU cpu_irqtime so > that delta == 0 and delta < 0 could be separated): > > @total 17,229,311 (100.0%) > @ret_curr_swapper 7,864,195 ( 45.6%) curr->pid == 0 > @ret_samegrp 323,299 ( 1.9%) same cgroup as prev > @reached_delta 9,041,817 ( 52.5%) > @delta_positive 6,358,192 ( 36.9%) real work > @delta_zero 2,683,625 ( 15.6%) work wasted (this patch) > @delta_negative (0) ( 0.0%) monotonic clock > > So 15.6 % of all psi_account_irqtime() calls - and 29.7 % of the > calls that get past the early returns - hit the delta == 0 case; > delta < 0 did not occur once in the 30 s window. Under the current > code each of those ~89 k calls per second performs the full seqcount > write + cpu_clock() read + cgroup-chain walk just to add 0 to every > group's PSI_IRQ_FULL counter. > > Extend the early-return to also cover delta == 0. rq->psi_irq_time > does not need updating in that case (it would store the same value > back) and no PSI bucket would change. The existing behaviour for > delta > 0 is untouched. > > Signed-off-by: Usama Arif Acked-by: Johannes Weiner CCing Chengming as well, quote untrimmed. > --- > kernel/sched/psi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c > index d9c9d9480a45..848955f8893d 100644 > --- a/kernel/sched/psi.c > +++ b/kernel/sched/psi.c > @@ -1023,7 +1023,7 @@ void psi_account_irqtime(struct rq *rq, struct task_struct *curr, struct task_st > > irq = irq_time_read(cpu); > delta = (s64)(irq - rq->psi_irq_time); > - if (delta < 0) > + if (delta <= 0) > return; > rq->psi_irq_time = irq; > > -- > 2.53.0-Meta >