Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2109322lqo; Sun, 19 May 2024 14:04:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXIzgzZuYO123QMvCOzC3m4VtK43QICFwszKEVhgsj+K6jw0l/mNYVFQdLSfHyj0UNAUfa+a/7BB8e9gF9ekDwit5Sj71NZK5yScB9MQg== X-Google-Smtp-Source: AGHT+IETneB9ZgiJjK2W3hIzNPp/H6OBSuDnS5LMB3xycGW8iekhplp+Yv1U0Ow7bH0BznXyX3xs X-Received: by 2002:a50:871c:0:b0:572:7c99:a280 with SMTP id 4fb4d7f45d1cf-5764d2165cfmr2363303a12.15.1716152662592; Sun, 19 May 2024 14:04:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716152662; cv=pass; d=google.com; s=arc-20160816; b=mFhoI4iZCgQKJTGKMq8SE5mPjlxzQcgc55ocZJOnv1w/KBFhr8OmgQq00JEJKlccjm 4rvqCbHmgQg9Wvu8O0QZvLJxWHd2tdoNR6ybHoLFg8/HJ0E3G9JPWHAHWRAlbACLqAbX ipwUP+awVBkwfUIKqFbCDGvhncFtgHnPNBvCyLrq6rjQHS0DNoZcfj1PeOahMJ/bQyT/ bkHwSJrfqN8pnN0V5P1OzrZ3OSGJeXDo276emCNLu1DKfQwMfQx1nipuUt5l2PI32d8b PFj8w48yzF1UUFbF01Ilxqu3/VJfbKsgiKJJZNJbfgwBgkSQ1jFOm2ZLerbefn++dQQi vR/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=XlkNr18VWp1TCP0IS/AcaZ56H1iE+w2B5cMNigzCd5E=; fh=lYSj7l1I7tZY20xFjv+kQz9Wz3+VSGrQlN7tiUgMCJM=; b=JtlAi7vQ7sRxQfFzki9LuPQn5Gv8de1IqbuoLFUZxRGJ/Vm/xv5qN1YWfTNsI7JciS 4H3sC9UFHD3lqfiNaS0VtTc9DaOjh7AqW1llsOIZWHqqcotHSI+DaqMWqp3r7IEbvgLN oPVNHU6qkchC/RSxgQXgWnYk23QFZoMocUg87CPS1q/PPR4zJ8lCJRHledqvb36n/eXG c+rN9DjatnLqt1Z8aO3HxQmi/mDNmfRNqu0W4yG7W5P/5oF0vk1npH/ZCqyD2KyrI/vG XKdgeRqSfLVEqoTsX/++GykkXOmr5gEEnsD7QhoUKorp6n2BFTsxhlaiyrhykcuEg8XV fzaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-183268-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183268-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733beacad3si12227082a12.57.2024.05.19.14.04.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 14:04:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183268-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-183268-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183268-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 551671F2157B for ; Sun, 19 May 2024 21:04:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 679166E614; Sun, 19 May 2024 21:04:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E4B026AEC; Sun, 19 May 2024 21:04:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716152652; cv=none; b=u9lp1lx8C5lwTVudZpg9Cdg7jFQV68SNQ+glPQOb/WJTdgm/fv+h9kc1nYvuToJ1ICk0yx05a7fwbcJ+sSl/4mQR6z1JFwFSVuzVrC71iyLjWbtaCBx4CUNKn1qzxHQ/7QTjjSATiT/FLTeIdVm9wxh/GJssCF9EFwpK4sSBT5c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716152652; c=relaxed/simple; bh=d9zC13sd+PcOp2vUU2yC7M1ViEVGOliY1ayJq7D3KmI=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=DGxaBhvH3r1XGjCdT+alrEB02Enyos6yEiqFepoINZwcrOyY4Sv7newVk5P/6vWJE6lsnRB1yK++w6v3a6ITCPljGGFQ1txSdBs/vxReWn3fQWiPY7x3EB+yQjmdn7kjIdYXd1DacNyZJtqFZSn9evFmAgfhLDNaSc4tjPX6oO0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F261F1007; Sun, 19 May 2024 14:04:26 -0700 (PDT) Received: from [10.57.85.2] (unknown [10.57.85.2]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 701D73F762; Sun, 19 May 2024 14:04:01 -0700 (PDT) Message-ID: <0ce2d536-1125-4df8-9a5b-0d5e389cd8af@arm.com> Date: Sun, 19 May 2024 22:03:59 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "linux-kernel@vger.kernel.org" , linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Daniel Lezcano Cc: Qais Yousef , kajetan.puchalski@arm.com, Anna-Maria Behnsen From: Christian Loehle Subject: [PATCH] cpuidle: teo: fix underflow of recent intercepts Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit The recent counter of each cpuidle state bin reflects the number of recent intercepts. It's decremented and incremented accordingly. The decrement was never checked for 0, therefore underflowing into a value teo cannot easily recover from. The underflow lead to deeper idle states being skipped because teo assumed interception was likely and it preferring shallower states. Fixes: 77577558f25d ("cpuidle: teo: Rework most recent idle duration values treatment") Signed-off-by: Christian Loehle --- drivers/cpuidle/governors/teo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c index 7244f71c59c5..42fb2771e35d 100644 --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -290,7 +290,8 @@ static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) if (cpu_data->next_recent_idx >= NR_RECENT) cpu_data->next_recent_idx = 0; - if (cpu_data->recent_idx[i] >= 0) + if (cpu_data->recent_idx[i] >= 0 && + cpu_data->state_bins[cpu_data->recent_idx[i]].recent) cpu_data->state_bins[cpu_data->recent_idx[i]].recent--; /* -- 2.34.1