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: 143995 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2183770ljj; Sun, 12 Aug 2018 09:10:05 -0700 (PDT) X-Google-Smtp-Source: AA+uWPz+mTSUz3c8nCdW6BRFB6AwpVgBb2iTDEDriddj1hmMp9pNbOUcpDTw1rXeJ0bZBuakLKbJ X-Received: by 2002:a17:902:4124:: with SMTP id e33-v6mr13501648pld.48.1534090205329; Sun, 12 Aug 2018 09:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534090205; cv=none; d=google.com; s=arc-20160816; b=aMP2AqmDLCOdu1wzYp7kky9kQTeJuSc2A1iQJK4xuL7wUmVKZ2PgwBO328yOYadV3p CHI3SymUIKk8CQTlQ2nEMISvFNNVCYcvpFz31+9Eyw5AAFSKe5AQXzoeXv8FjM9l+tlg JkbHu0ZklEor526x3m7gzT6x6CLLCOrdI3IOcfyUKibYcGPtY5kZmPuk/REB6YjzDdUL PcLvsXVtMCYz2MBLeBsg1x5mioZRERu5TyXkdzj/8r9cnjLKSgiiuO3th9f9UsRQAtAM rVH71SLPEocMOrgItaMSwniG3iwoQ3yCyCHWS+WW5Vg9fFtHWdNTN2VSLNTl9ViTFEKS E+Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=V18Yg/vtevZ0nWVd2TxyiDMrqJoQAluOHbayWFvQXps=; b=GQ5nAYIF3qJ8cTWRKVsjcUAl2ZXxPjbwz4r7meDZnebeQqwivGn6esCzblhrt4zxOU 9T2Y+Aq5zx55V5acWmsBPYSehKE+lSCob8v7MwB76G5lNfDhd4D1JysSIwZjDOa7usxS gJiTbzh4vWW/3rdkHZ21TqiZXWYj5cXXR/gORTUnfvQxk3FQwflp71rfuQMHwmPjF+Gb WrlHXhKN7RbogL8Z6H5IK4dJZUZPYcYI8eYiqpNE6XR7KodTZjuHxAfZ6wtXBEhSWZbh eL9B9YByPSwMgB26uzJJKo7LJm050W+HuJ1AK9fyPzmM/1usn3PAFAWcrnKpAyQKw4eb NeYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OSxffkp8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x33-v6si12325234plb.160.2018.08.12.09.10.05; Sun, 12 Aug 2018 09:10:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OSxffkp8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728291AbeHLSsb (ORCPT + 31 others); Sun, 12 Aug 2018 14:48:31 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41839 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbeHLSsb (ORCPT ); Sun, 12 Aug 2018 14:48:31 -0400 Received: by mail-wr1-f65.google.com with SMTP id j5-v6so12208866wrr.8 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=DsYrSHTohqjLpdk7NqHoNzKCbf2uf+PDc9QtmLLI/lr/DIZFbSlBblLXojUvDW1LW9 kJ3xanrzLaj/VzlkorqPRChEXb14LMU4Y+rGYwtLLS0BESagB6XBh0GI6Ov6/t8hXczW 3Y7b6VOozS+anF2ANuU1vUwWEqIHCVTgc56XD2UrawZqv2u/lsD+DeRHCxXuv+UdF5Lk 81oYFr4+5Lx6HAKODsiYcpfiXmW0liEIpPfqPPE9HtJdrkK1/FL9wfZNSN97xzM60yez Emp4Va4DhMnteGMVeoD7TJWk7s4bC1vGV0/6Ypne+HhfkfAEMPKEDlPvhuHGTg09iCE6 4gbA== X-Gm-Message-State: AOUpUlEZKQaJ03wPZSwYZKJ2MstjU+lex8HDElVwZXU3L3yIgUdLeIjM jyUnaWB+Mr16VqJuqS+DpbUJWA== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.4 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; } } From patchwork Sun Aug 12 16:09:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 143996 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2183814ljj; Sun, 12 Aug 2018 09:10:08 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwzc9AHU7kwspKeKzSYloIweubsV8gzq3hkegwtzcQAznZed9tSmEqzwHvRM6JAkhmklCG0 X-Received: by 2002:a17:902:50ec:: with SMTP id c41-v6mr13551950plj.269.1534090208220; Sun, 12 Aug 2018 09:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534090208; cv=none; d=google.com; s=arc-20160816; b=GormRva6+grqMo2bObrK49zWENOS7+X/f3Q9ZjkX0SCorpeDrES4y5qzXEvtIThhtK dtfdgTw9lyJP408gq01rAZnmGPOx2xnowdFOaG2BzcTZceZ+F2GMCRaPO1nMYT9vBBYT /gODslxEq2JFRRbCf5I+X0uMAC10kBE3FH2c+GXDvX7vaYxPdD7/p+XkHrcAmC6EyusM xGlSCQckwCTeX/Cme143/nv96Nz8yH1i8fPd1IAkOLaa5Rn+gExsmsZuy4ba8IK74ftP s8xsBjbRB4w9VZ8fsT6oKpL1RkgmisdkZT0NaYYB+KAqLSox7Usi+1FBCKlZZVx21mYF uJCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=v4mRTz9lovuOcDxlp6+85Pwdka+3yYASS/8Q6JA5+Fc=; b=t/vcQckeZNy4GORd9lGWXrSDYhH3iIiI6/tD0qVv1/zMUoJHWqpTJynfWVeueVKZch QPDlrt3vq5UL13IF2vHTJOL7kvuFWd6GITRHPYuDcVvWer0L5DSLb1SEy5aPnSQy2+8B 9gSTd+O6VPX49EUqbA+5zMaOZcRSzjf6Sbirr0y+KJUxgUw7f2gGPWIluA+X+1PWGvIx xWyCf2N9KZZJeiHjiFGdzxNa6KYiQtOFLxz/cJlMnxQOdkuE/VbG08E1XfET0cWWIy4P TpY0wSdcmI/l9M+B6a4lQzNlnGUDjSSG8YDIw669CkN8IGwpqxdvU06vJ+klmVgWjAyo H3xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WqWRK+Eh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i13-v6si15425212pgh.642.2018.08.12.09.10.07; Sun, 12 Aug 2018 09:10:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WqWRK+Eh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728330AbeHLSsf (ORCPT + 31 others); Sun, 12 Aug 2018 14:48:35 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46046 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728294AbeHLSsf (ORCPT ); Sun, 12 Aug 2018 14:48:35 -0400 Received: by mail-wr1-f68.google.com with SMTP id f12-v6so12186691wrv.12 for ; Sun, 12 Aug 2018 09:10:04 -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=v4mRTz9lovuOcDxlp6+85Pwdka+3yYASS/8Q6JA5+Fc=; b=WqWRK+EhooOB8zO22jSGNKLlVuQnJLQ/RdvK4jHkVx663qtYtx2pnnwr0ncjiKn4UT E8tsB8HHZY+h5E/9abCtSeoATObCAafU+7IGV8372NNjcD+zy+GnTZL0StXLKcEofsaQ mSgTXhXyW2pnU+NyrCaJL3n3vMei/pkXGIsmE= 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=v4mRTz9lovuOcDxlp6+85Pwdka+3yYASS/8Q6JA5+Fc=; b=OgvKuHJIZhX2STj13I3BeuoweiopORYk2g+aQhtmz1cx2QNFblkASGDd7Wg3t6dExA Mckv5va0rgRyrs2tZe23zjaq5xdKnr+fZEJ7JbhebTICtmM5W3iHM5gqkGE4ZBGyMMSN qz4MsDgSoepjbQnIenx9qWZ1TPleruwTSoodK9tiTP0QPgTmhWZqRE8ctVdgMmblt1Sj 92gkxVtt+lySmsOfPbif86hrxu1Xjqflm5zwDdwo1UyHKrnOh23upZYvgbFCUo/OdNpf 8QXZ/aKZuX/skKMBhM+YOPvrFV66nIst7Pbc8EZMXj74QXpCeFCMlRsogXCA7NR+Z8WU S40w== X-Gm-Message-State: AOUpUlGCYeKqKu/9AJ6SitdUgo6AbFfVWwyuvnifTnhzDnAQuj/5R6SD RfW+FS778Vh6OgCsHNiITieZ7A== X-Received: by 2002:adf:9261:: with SMTP id 88-v6mr8159181wrj.62.1534090203670; Sun, 12 Aug 2018 09:10:03 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id t6-v6sm7437369wmf.8.2018.08.12.09.10.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Aug 2018 09:10:02 -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 3/5] cpuidle: menu: Provide menu_decide_stopping_tick() Date: Mon, 13 Aug 2018 00:09:29 +0800 Message-Id: <1534090171-14464-4-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch is only for code refactoring and without functional change. It introduces a new function menu_decide_stopping_tick(); we can use this function to focus on making stopping tick decision. With moving out stopping tick decision code, it lets the below piece code is simplized only for the idle state calibration and thus save one indent level in the loop. Signed-off-by: Leo Yan --- drivers/cpuidle/governors/menu.c | 76 ++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 83618ab..4f02207 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -276,6 +276,37 @@ static unsigned int get_typical_interval(struct menu_device *data) } /** + * menu_decide_stopping_tick - decides if need to stopping tick + * @drv: cpuidle driver containing state data + * @data: menu_device structure pointer + * @idx: the candidate idle state index + */ +static bool menu_decide_stopping_tick(struct cpuidle_driver *drv, + struct menu_device *data, int idx) +{ + /* + * If the tick has been stopped yet, force to stop it afterwards and + * don't give chance to set *stop_tick to false. + */ + if (tick_nohz_tick_stopped()) + return true; + + /* Don't stop the tick if the selected state is a polling one */ + if (drv->states[idx].flags & CPUIDLE_FLAG_POLLING) + return false; + + /* + * Don't stop the tick if the prediction is shorter than the + * tick period length. + */ + if (data->predicted_us < TICK_USEC) + return false; + + /* Otherwise, let's stop the tick at this time. */ + return true; +} + +/** * menu_select - selects the next idle state to enter * @drv: cpuidle driver containing state data * @dev: the CPU @@ -396,33 +427,26 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, if (idx == -1) idx = 0; /* No states enabled. Must use 0. */ - /* - * Don't stop the tick if the selected state is a polling one or if the - * expected idle duration is shorter than the tick period length. - */ - if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || - data->predicted_us < TICK_USEC) && !tick_nohz_tick_stopped()) { - - *stop_tick = false; + *stop_tick = menu_decide_stopping_tick(drv, data, idx); - 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 - * the time until the next timer event including the - * tick, so try to correct that. - */ - for (i = idx - 1; i >= 0; i--) { - if (drv->states[i].disabled || - dev->states_usage[i].disable) - continue; - - idx = i; - if (drv->states[i].target_residency <= - data->tick_delta_us) - break; - } + /* Calibrate the idle state according to the tick event. */ + if (!*stop_tick && 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 + * the time until the next timer event including the + * tick, so try to correct that. + */ + for (i = idx - 1; i >= 0; i--) { + if (drv->states[i].disabled || + dev->states_usage[i].disable) + continue; + + idx = i; + if (drv->states[i].target_residency <= + data->tick_delta_us) + break; } } From patchwork Sun Aug 12 16:09:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 143997 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2183871ljj; Sun, 12 Aug 2018 09:10:12 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxBqk0KIUcerSTdQgwUV5mhCJ6zlh8fyC9zoIGxIs6MljcppnVJpeJs3HipX8Sp1NJ3U2KW X-Received: by 2002:a17:902:4124:: with SMTP id e33-v6mr13501944pld.48.1534090212170; Sun, 12 Aug 2018 09:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534090212; cv=none; d=google.com; s=arc-20160816; b=ULzOFdzMMHST5koD1Db14z8gLpGJXAVbdzze/3n865bMUj8q1bK0r259p2Hmf5M1hT 4sYTGaYF9yqCY1scRbUavNtIZIf8BIktM6k9pw4RKfzaqGthK7DIeYotYRemwqpPAYNm Zo2qjTNAwPkzHlzoC/96jfIJXY6F2jH+YXmLiZf1O5AQt1gWrTH7IxqIToUBUZhWRk39 w3KQpjhRTWuP6ClU5gbWyApWyfJN17n/penQckVETA2KDUBd8SoED0A06gYwLRP6Owxc tYQMkzRgp6KiL/bB7reSrV5LPgGIb0n6uVlax3OFffDAF8De3MukHFYm5yZ2qB1Z9f4b nfGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=V/KD4PZAGRjRkYZ8ZQmu8anS2A7JIpWJS7JiZdKweu4=; b=fLbbDgmS1NfAy6bEnXcrqR09KGq1Gh61RKkXZ5eqK3+CpwluYj4UWJhWbh1E/Ov+bU zXCjzLfBHQvIVZzcTONvd90To0Bkxyz3e7JDVuKvfmWhXCQUvXPKtDtihuw7DJAPqju4 +hU6FwhDFehGKUMAiYr1WXwyeIDmmQOz/ZjEzUjL4XQIj50KPMCVloE3VyHn6+GzVwNV MzjfeI1QsBWDBZa75r3zohSFddtTokKrcNIqM/gfdE08GSkcGWQRtzgeb/Jj6nXpgzq0 p/qmFAOfJTJvCOFRCCq2xKmVoWoOnlF9Dk6iYFzPT6vRKr28G+uttver6SVPzZnIlsNP m3lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aAes6E+f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6-v6si14317808pfh.266.2018.08.12.09.10.11; Sun, 12 Aug 2018 09:10:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aAes6E+f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728358AbeHLSsk (ORCPT + 31 others); Sun, 12 Aug 2018 14:48:40 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37636 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbeHLSsj (ORCPT ); Sun, 12 Aug 2018 14:48:39 -0400 Received: by mail-wm0-f65.google.com with SMTP id n11-v6so6448455wmc.2 for ; Sun, 12 Aug 2018 09:10:08 -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=V/KD4PZAGRjRkYZ8ZQmu8anS2A7JIpWJS7JiZdKweu4=; b=aAes6E+f295M09g4lYl2w+zmOWFBPesp3HWKkqOQ5wPP5kvZPb7W5oWINgh1HcevCw oqkiFY51eG1PKuRYLMhZ+6B5AcRNNzTuCtfUB5xloqeK9tSAkUa15MIGFDbIYy9AmU8N AYXGe4AeVpuXtaiZrDMTZjIay1m0kZOJIQcQY= 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=V/KD4PZAGRjRkYZ8ZQmu8anS2A7JIpWJS7JiZdKweu4=; b=L1najRhW8bTOVt9ytHbj5fv9RDbv55qIvZ15fkaXdgX5uJSCkfQN5TVyNWc+nDhRxV rftW/XSAH1CajoKyaxLZA16fENKs2Gl/i0FS2X1gHgveNjVgk//eWYJRC/39UrmP5tBa gVD6+bihaqNwDQnJeeycFKMWspBRrSkoh3+cDIzcs3uaqnSfsaeRZ7I8W/ClcEbtHQI+ WSLr22BJ1UK0aqn62Mw1/gI+XO69Ku314RgtiRjr0WQLcQQwFrWHTgKnQhQt96/kdQco l5Bk6B5Um3HXqyJrwW0VNk/Ej5chzTbl3rwmS4B5j6NRoEcMD+4S7NlrtJwgu2uwbKh6 DijQ== X-Gm-Message-State: AOUpUlEDXu1XJXvafHg/Wiig2zlwvyftDH6xdEUqA8YanwLLETHsczle pocWxOY0F7RjSB5a3TfmfrDnvg== X-Received: by 2002:a1c:4885:: with SMTP id v127-v6mr5928679wma.161.1534090207747; Sun, 12 Aug 2018 09:10:07 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id t6-v6sm7437369wmf.8.2018.08.12.09.10.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Aug 2018 09:10:06 -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 4/5] cpuidle: menu: Don't stay in shallow state for a long time Date: Mon, 13 Aug 2018 00:09:30 +0800 Message-Id: <1534090171-14464-5-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To avoid staying in a shallow state for a long time, the menu governor relies on not stopping tick when detects the prediction is shorter than the tick event. This is just luckily to cover most cases but cannot say it is completely safe. For example, if the prediction is 2000us and the TICK_USEC=1000 so it's impossible to meet the condition 'data->predicted_us < TICK_USEC' and this lead to stop the tick for a shallow state; finally the CPU is possible to stay in this shallow state for very long time. This patch checks the candidate idle state isn't deepest one and find if the timer will come after more than 2 times of the maximum target residency, though the governor selects a shallow state according to prediction, due the timer is most reliable waken up source but it will come very late, so the CPU has chance to stay in the shallow state for a long time; the patch doesn't stop the tick for this case so can avoid powernightmares issue. Signed-off-by: Leo Yan --- drivers/cpuidle/governors/menu.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- 2.7.4 diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 4f02207..566c65c 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -284,6 +284,10 @@ static unsigned int get_typical_interval(struct menu_device *data) static bool menu_decide_stopping_tick(struct cpuidle_driver *drv, struct menu_device *data, int idx) { + int max_target_residency; + + max_target_residency = drv->states[drv->state_count-1].target_residency; + /* * If the tick has been stopped yet, force to stop it afterwards and * don't give chance to set *stop_tick to false. @@ -302,6 +306,23 @@ static bool menu_decide_stopping_tick(struct cpuidle_driver *drv, if (data->predicted_us < TICK_USEC) return false; + /* + * The candidate idle state isn't deepest one, on the other hand + * the most reliable wakeup source is timer (compare against to + * interrupts) says it will come after more than 2 times of maximum + * target residency, this means the CPU has risk to stay in shallow + * state for more than 2 times of maximum target residency. + * + * It's acceptable to stay in the shallow state at this time but we + * need to ensure to wake up the CPU by tick to check if has better + * choice. Finally it can have choice to select deeper state and + * avoid the CPU staying in shallow state for very long time and + * without any wake up event. + */ + if (idx < drv->state_count - 1 && + data->next_timer_us > max_target_residency * 2) + return false; + /* Otherwise, let's stop the tick at this time. */ return true; }