Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4437378pxf; Tue, 30 Mar 2021 07:50:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1MBVZ5knCdOgw4OwaBVOer4J2fJLpQfGFbRhdF6diwzbM2jiFqOwbNLzxxudL6ZXOZeyb X-Received: by 2002:a17:906:a049:: with SMTP id bg9mr33713244ejb.186.1617115857906; Tue, 30 Mar 2021 07:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617115857; cv=none; d=google.com; s=arc-20160816; b=amYLwiRevbgiUCaG5R/vcrL5dg0xXB+5rYTiH+E/3WCShuZ1xUNm8FTBHPBqM7dqd1 IPhlTt4xyIRVJkWkeRBsfSHaiLDfaPpAw2xSOD8Eaaj9z6jEWOmP85WIVkLKYDT3oNbp 5+1s0fvuTT9SFgOt9HjP/lCQHxG75bWks16HjyMYNNTOi8BG0dMspPSJ0ELcE7lDbdeW 7zAmsfP8Z7VoUZGkX1KcMEXNbbIEK9vpUDN9WfL/bL081LtYcI1wlCc0ddu327y3Zkrg AJXEYJi8YG2LsQ3LDHbR8//8o1ochCNPnbFpVgzvnjkIYsotwkqUidocE3izOcrdaNUH F1Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=MQ/R6CX19Up1J/nwzUUDCWCDOqM+HhWlcKjpkwoy/dw=; b=RpnGDyO+6qcSv/sn0+7fZr/H66VLqowozpA4P6wYHIhqDXAuU6XQkmGgq55H/WHkwf 04JxUhD33Kci+MLf/aPr3PNNDD2iZnZHyOvu33Yn8uW4Hv1UzKUUiLDg1/BvmUliLqEc V660WjcOUnqPe7YEcUdMgfH0Uj+L0sqTVWT+qBQKhMeFZpzsg2RQ1gW9h3RjFmP9F6Hx vXfWZo6iiFtdDicJ3RDOwaLbB/RTfU5XoRM0UaIK9Ey4VG46U4BYbP3Di6YLx9qavJFb gwUQZ8WxNObU/UfyinOQ2d11N7A9sjoDAPIAuFn2sBYa2X5dSkCARtmpAZRZ27yJ6Nr4 vfKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h16si15144060ejk.221.2021.03.30.07.50.33; Tue, 30 Mar 2021 07:50:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231998AbhC3Os3 (ORCPT + 99 others); Tue, 30 Mar 2021 10:48:29 -0400 Received: from mail-oi1-f170.google.com ([209.85.167.170]:42931 "EHLO mail-oi1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232279AbhC3OsH (ORCPT ); Tue, 30 Mar 2021 10:48:07 -0400 Received: by mail-oi1-f170.google.com with SMTP id n140so16711216oig.9; Tue, 30 Mar 2021 07:48:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MQ/R6CX19Up1J/nwzUUDCWCDOqM+HhWlcKjpkwoy/dw=; b=mtU6z3upXkBBcGeDOTZoFToB84dfqk5/SNFDioGQtaZuoW1jnbJHjIYaW/8LzHOHzL DDK9RoPg5dOWix7D38RHvTh9DAhA7pCKSChsLOuR5h9af9Opq+3IWTHP8Vl5TSVKVgvf Q4tpqI0hP1SaDruhmc3MBP1PotNsfavOLXpZBG32GwOXEtKLUMimlFIVZZepklK+hX+/ v8a0l5ZBAKYGhC36uo/TB3+L+Q06vDT1waZfjzrH1dBvkBIz/bcWI1vYC7xR3NE3R4GB 5ua1GMsD5E+wPWHYIy9suUhboATia3rAq0siVE47hCzUr0ahU5gr3iZARL9L9VbBLKZP 2ubQ== X-Gm-Message-State: AOAM530ou1oblJZuMA2njTLeh6EC5n1LjtBsN6D7Sl76gvz6Ct0mes4K Job9TVQdMCBBa6jAj7dvsQcrezet34FBE1BLN5Q= X-Received: by 2002:a05:6808:24b:: with SMTP id m11mr3513854oie.157.1617115686845; Tue, 30 Mar 2021 07:48:06 -0700 (PDT) MIME-Version: 1.0 References: <2764850.e9J7NaK4W3@kreacher> <7927358.NyiUUSuA9g@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 30 Mar 2021 16:47:56 +0200 Message-ID: Subject: Re: [PATCH v1 5/5] cpuidle: menu: Take negative "sleep length" values into account To: "Zhou Ti (x2019cwm)" Cc: "Rafael J. Wysocki" , Linux PM , LKML , Frederic Weisbecker , Peter Zijlstra , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 30, 2021 at 4:00 AM Zhou Ti (x2019cwm) wrote: > > On Mon 2021-03-29 14:37 Rafael J. Wysocki wrote: > > Make the menu governor check the tick_nohz_get_next_hrtimer() > > return value so as to avoid dealing with negative "sleep length" > > values and make it use that value directly when the tick is stopped. > > > > While at it, rename local variable delta_next in menu_select() to > > delta_tick which better reflects its purpose. > > > > Signed-off-by: Rafael J. Wysocki > > --- > > drivers/cpuidle/governors/menu.c | 17 +++++++++++------ > > 1 file changed, 11 insertions(+), 6 deletions(-) > > > > Index: linux-pm/drivers/cpuidle/governors/menu.c > > =================================================================== > > --- linux-pm.orig/drivers/cpuidle/governors/menu.c > > +++ linux-pm/drivers/cpuidle/governors/menu.c > > @@ -271,7 +271,7 @@ static int menu_select(struct cpuidle_dr > > u64 predicted_ns; > > u64 interactivity_req; > > unsigned long nr_iowaiters; > > - ktime_t delta_next; > > + ktime_t delta, delta_tick; > > int i, idx; > > > > if (data->needs_update) { > > @@ -280,7 +280,12 @@ static int menu_select(struct cpuidle_dr > > } > > > > /* determine the expected residency time, round up */ > > - data->next_timer_ns = tick_nohz_get_sleep_length(&delta_next); > > + delta = tick_nohz_get_sleep_length(&delta_tick); > > + if (unlikely(delta < 0)) { > > + delta = 0; > > + delta_tick = 0; > > + } > > + data->next_timer_ns = delta; > > > > nr_iowaiters = nr_iowait_cpu(dev->cpu); > > data->bucket = which_bucket(data->next_timer_ns, nr_iowaiters); > > @@ -318,7 +323,7 @@ static int menu_select(struct cpuidle_dr > > * state selection. > > */ > > if (predicted_ns < TICK_NSEC) > > - predicted_ns = delta_next; > > + predicted_ns = data->next_timer_ns; > > } else { > > /* > > * Use the performance multiplier and the user-configurable > > @@ -377,7 +382,7 @@ static int menu_select(struct cpuidle_dr > > * stuck in the shallow one for too long. > > */ > > if (drv->states[idx].target_residency_ns < TICK_NSEC && > > - s->target_residency_ns <= delta_next) > > + s->target_residency_ns <= delta_tick) > > idx = i; > > > > return idx; > > @@ -399,7 +404,7 @@ static int menu_select(struct cpuidle_dr > > predicted_ns < TICK_NSEC) && !tick_nohz_tick_stopped()) { > > *stop_tick = false; > > > > - if (idx > 0 && drv->states[idx].target_residency_ns > delta_next) { > > + if (idx > 0 && drv->states[idx].target_residency_ns > delta_tick) { > > /* > > * The tick is not going to be stopped and the target > > * residency of the state to be returned is not within > > @@ -411,7 +416,7 @@ static int menu_select(struct cpuidle_dr > > continue; > > > > idx = i; > > - if (drv->states[i].target_residency_ns <= delta_next) > > + if (drv->states[i].target_residency_ns <= delta_tick) > > break; > > } > > } > > How about this. > I think it's possible to avoid the new variable delta. > > --- > > --- linux-pm/drivers/cpuidle/governors/menu.c.orig 2021-03-29 22:44:02.316971970 -0300 > +++ linux-pm/drivers/cpuidle/governors/menu.c 2021-03-29 22:51:15.804377168 -0300 > @@ -271,7 +271,7 @@ static int menu_select(struct cpuidle_dr > u64 predicted_ns; > u64 interactivity_req; > unsigned long nr_iowaiters; > - ktime_t delta_next; > + ktime_t delta_tick; > int i, idx; > > if (data->needs_update) { > @@ -280,7 +280,12 @@ static int menu_select(struct cpuidle_dr > } > > /* determine the expected residency time, round up */ > - data->next_timer_ns = tick_nohz_get_sleep_length(&delta_next); > + data->next_timer_ns = tick_nohz_get_sleep_length(&delta_tick); > + > + if (unlikely(data->next_timer_ns >> 63)) { > + data->next_timer_ns = 0; > + delta_tick = 0; > + } Well, not really. Using a new local var is cleaner IMO.