From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 9E2093ED109 for ; Fri, 17 Jul 2026 10:29:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784284144; cv=none; b=bSXl9U1bQjN+2QPXktLRauYyIVHxvGSCYTe0Z4FzZ4QTVEz4zKZchVGNVmCTk3ToV95oCyJmV++CwlJUHBlvpQT/dHLVvZ2++kPdpBkgArRgqCYTCIdn39gIsU1XpPbf/Gg6SYPRzRr61u2pdyKUAJL7pYkK6RZdFw8N3dfbGUo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784284144; c=relaxed/simple; bh=//C6IhK0SNDYLpEVmZHRpvwKY3/Y2RPsgQlJ5rfKZMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZsUMLT3f8JGAl3vYYakjlgzUXHoRPdUCDyeK8++IhxM8FeAIx4VlymEx/9ucuDxKIjh2RC+dGRoQU+VZBROjznqjwKbj7AZVARgtmNZOtJCo+wvXdVaZJapv4ROuTVwlSB+zxzOZ7IBnubgNnaGPkfm9sy5U+Mpiu+4TpIYEha4= 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=QYFSlPts; arc=none smtp.client-ip=95.215.58.170 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="QYFSlPts" 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=1784284140; 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=ds0jVVzqCKUivTbkQiB+AgVCmfAzBGwQv2Ev0dgsqiI=; b=QYFSlPtsrIPAjYyK7fw4uIpdx7iR7IW/rPIWJJkqP4r8hqAO3h1Ve1FtBiuU6EqrcIgWS5 bX6aj5AtameUZBp+mY9lM8fIAy4ziSmYmmeNOw+6MRcD+wA9POS7psQ8vl/1aqLnEtJCIM 50j3tWH99CyqzpUJY6Tgfx6bcGYEP8c= From: Guopeng Zhang To: Johannes Weiner , Suren Baghdasaryan , Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] sched/psi: Fix long-window growth interpolation Date: Fri, 17 Jul 2026 18:28:23 +0800 Message-ID: <20260717102824.985950-2-guopeng.zhang@linux.dev> In-Reply-To: <20260717102824.985950-1-guopeng.zhang@linux.dev> References: <20260717102824.985950-1-guopeng.zhang@linux.dev> 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 From: Guopeng Zhang PSI trigger windows are stored in nanoseconds and can be up to 10 seconds, but window_update() stores the remaining interval in a u32. For example, after 2 seconds have elapsed in a 10-second window, the remaining 8,000,000,000 ns is truncated to 3,705,032,704 ns. Making remaining a u64 avoids the truncation, but the multiplication can still overflow before the division. Both win->prev_growth and remaining can be close to 10,000,000,000, so their product can exceed U64_MAX. Store the remaining interval in a u64 and use mul_u64_u64_div_u64() to calculate the interpolation without overflowing the intermediate product. Fixes: 0e94682b73bf ("psi: introduce psi monitor") Signed-off-by: Guopeng Zhang --- kernel/sched/psi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 4e152410653d..8e4df8b17c25 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -137,6 +137,7 @@ * sampling of the aggregate task states would be. */ #include +#include #include #include #include "sched.h" @@ -451,10 +452,11 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value) if (elapsed > win->size) window_reset(win, now, value, growth); else { - u32 remaining; + u64 remaining; remaining = win->size - elapsed; - growth += div64_u64(win->prev_growth * remaining, win->size); + growth += mul_u64_u64_div_u64(win->prev_growth, remaining, + win->size); } return growth; -- 2.43.0