From patchwork Sun Aug 12 16:09:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 10563681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16A50139A for ; Sun, 12 Aug 2018 16:10:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 048B729466 for ; Sun, 12 Aug 2018 16:10:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED43429469; Sun, 12 Aug 2018 16:10:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A55529466 for ; Sun, 12 Aug 2018 16:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727564AbeHLSse (ORCPT ); Sun, 12 Aug 2018 14:48:34 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36165 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727747AbeHLSsb (ORCPT ); Sun, 12 Aug 2018 14:48:31 -0400 Received: by mail-wr1-f66.google.com with SMTP id h9-v6so12251408wro.3 for ; Sun, 12 Aug 2018 09:10:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V18Yg/vtevZ0nWVd2TxyiDMrqJoQAluOHbayWFvQXps=; b=OSxffkp8NwJyPYpiwF1fIiewerSpTUDVO903chrUq34Ei11KpkKTlPdZubWBo51/Q7 GbrHWJSKaJBzEnXyCV+jI7+Nrezo1178q/h9F6MM14Cop3As8v5NX8aezc3DOGnsm8xo xrYwzUbUVOBGD9k9dvoB0LKsbG5Sxb1gTh22o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V18Yg/vtevZ0nWVd2TxyiDMrqJoQAluOHbayWFvQXps=; b=lfX7t1LYjsWZE9n9daNi9JpmbcLpXff1cHmWABmi3YHPsJnUa61NZF9w2yENbw36rX h2L/kmCzlPKpv5bsVbIM2zwcZ7yNWgciTDDmdxPe3ooHxDo4ZpV0kxz+mXI46Hl0EDWl WcL91a3Fx8LujEH8OaxEmVspZ5QCSnIllsSWhvcqYLeYYbCNERJ7tvNgChW7U6OYcZv3 3fc7kqr7OdGIfvdYGbD/+wBovF8VXDZEcx6062zNWEQCld7ORgc4jPC5Q88Uom3QiOps AJaUTTjD1Gph/USz66ObOgOwICl4ByV9EAKUdNHUwwR8oy1FwB0uVU60rpPeP489nHLG 19QQ== X-Gm-Message-State: AOUpUlHpeTqBwEoVR71ti4Q9CsRJK09dMjVZu44Lby8qkahp8QYt8Byf IBGj5OMo+Xedmi2hHZIJz3u0PA== X-Google-Smtp-Source: AA+uWPzw35FdQt+zWdjk80+9C6z2ADA9CZMw40hg2gNSVOnmMHebG6LDNWqmFukwn27mOuwUBUdfmA== X-Received: by 2002:a5d:458b:: with SMTP id p11-v6mr8555372wrq.122.1534090199872; Sun, 12 Aug 2018 09:09:59 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id t6-v6sm7437369wmf.8.2018.08.12.09.09.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Aug 2018 09:09:58 -0700 (PDT) From: Leo Yan To: "Rafael J. Wysocki" , "Peter Zijlstra (Intel)" , Daniel Lezcano , Vincent Guittot , Ramesh Thomas , linux-kernel@vger.kernel.org, Linux PM Cc: Leo Yan Subject: [PATCH v1 2/5] cpuidle: menu: Record tick delta value in struct menu_device Date: Mon, 13 Aug 2018 00:09:28 +0800 Message-Id: <1534090171-14464-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534090171-14464-1-git-send-email-leo.yan@linaro.org> References: <1534090171-14464-1-git-send-email-leo.yan@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since the tick delta is used in multiple places in menu_select(), it's better to use single one variable to record this value; furthermore, for more readable we can refactor the code to split a separate function to making decision for stopping tick, which also needs to use tick delta value as one metric for consideration. To achieve these purposes, this patch adds a new item 'tick_delta_us' in struct menu_device to record tick delta value. This patch also is a preparation for optimization stopping tick in sequential patches. Signed-off-by: Leo Yan --- drivers/cpuidle/governors/menu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index b972db1..83618ab 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -124,6 +124,7 @@ struct menu_device { int tick_wakeup; unsigned int next_timer_us; + unsigned int tick_delta_us; unsigned int predicted_us; unsigned int bucket; unsigned int correction_factor[BUCKETS]; @@ -305,6 +306,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, /* determine the expected residency time, round up */ data->next_timer_us = ktime_to_us(tick_nohz_get_sleep_length(&delta_next)); + data->tick_delta_us = ktime_to_us(delta_next); get_iowait_load(&nr_iowaiters, &cpu_load); data->bucket = which_bucket(data->next_timer_us, nr_iowaiters); @@ -317,7 +319,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, * timer event for the idle state selection. */ if (tick_nohz_tick_stopped()) { - data->predicted_us = ktime_to_us(delta_next); + data->predicted_us = data->tick_delta_us; goto select; } @@ -400,11 +402,11 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, */ if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || data->predicted_us < TICK_USEC) && !tick_nohz_tick_stopped()) { - unsigned int delta_next_us = ktime_to_us(delta_next); *stop_tick = false; - if (idx > 0 && drv->states[idx].target_residency > delta_next_us) { + if (idx > 0 && + drv->states[idx].target_residency > data->tick_delta_us) { /* * The tick is not going to be stopped and the target * residency of the state to be returned is not within @@ -417,7 +419,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, continue; idx = i; - if (drv->states[i].target_residency <= delta_next_us) + if (drv->states[i].target_residency <= + data->tick_delta_us) break; } }