From patchwork Tue Feb 26 14:54:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 159221 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp3304051jad; Tue, 26 Feb 2019 06:54:42 -0800 (PST) X-Received: by 2002:a2e:965a:: with SMTP id z26mr12065512ljh.59.1551192882417; Tue, 26 Feb 2019 06:54:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551192882; cv=none; d=google.com; s=arc-20160816; b=xDRrF/2mte4hG09YS7cgtNwrwaGd1/+NhZ/U+QSUMpYmq2alXEfMteRizeq1Vjaw1+ HJXa9t3+QejOFKZ3NTEOxr+vOd/VjFmWlX+ENBisrataUmcXdyYcrcnQ+eDY6Vui5OJ0 tthzlaDf7+Bwp1TbG84eCPU7dusn+/LKrH74bM1QqZB5Ndb758cUHlk4tSSdOp60b5dd vBVFXXGJhAcpy1Za9ZIBbKeIfFn9GQCJ9E7UZEMIO/W+wDwaz5TJKVUg2YQdpqmhhOot x8qxh8qyDwPeOINEGWYBEyOw/z5/q2ZnrmNiPjOCA6hd2dzuVb2pTAXhtrzSfWZ4+3zY DPYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AMYIr19DhL7wC893nIVn3Y+H+G175+i8XlmQ/dWB4wQ=; b=Aw2aAYmSNftJN/MT3ULLbZdum1Lilju+1vNmr3eqLVfg5EBSa2ajq/mtAwiGL9jKCl T4sL24HIQJR+NYyChTcU44J5P8GkxfYOd6yDRsEZM7Tk2fD6Dt+Z/FD/ZuwJayrbxd6H /KOjSX9k+VNPCY/0pe75YrEwGzi9SNQ6JLnpMv9VWfsxcofbQnf+0c4BM0SAzfLHPBjt xKbWxGXFSmXxWBLcyAkB37MtiHP8SM6csCN0leksoIUK6fehgwsrevv7c6tt7awF868+ +jzkC4Qp/WHsYMbJ5+gFVBGHHD0h0NxrMklxgFtXqLRK2D395ybwdiRVM0TijqGINhqG un6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WXbnVH1b; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f18sor583397lfc.11.2019.02.26.06.54.42 for (Google Transport Security); Tue, 26 Feb 2019 06:54:42 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WXbnVH1b; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org 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=AMYIr19DhL7wC893nIVn3Y+H+G175+i8XlmQ/dWB4wQ=; b=WXbnVH1bnHlmFW3O8yFUbl6Uw3ZNLM4we+2msBhbMMZoJTPSnF7TyZVvnUuqKPCXpx V1+/lFSM8P0nVXxaNK7jld1v/1f5rPMP1nUihV6qSwvNUskToK5HM7OvZFJZ6QyXD8B/ X3XdzTBVLG+TGrdb9bpWwV6YdS7dUoi9AEZKmGa1m7AOFq+rqYkZMX4erNtlKmkiu4Ld PHX76Ti+FlXmTILcikEJSWJcoTZh/Hu52AVe7t3KkL5eJM1//lF4ZvF0lt+CkXZWNNMO ECX5oXpDzSw7kqPYIDSZH4kzNlYhbt4LafqJAdFzNtkcUXJInTkeNx5CDxOTL8gcOmwk USXQ== 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=AMYIr19DhL7wC893nIVn3Y+H+G175+i8XlmQ/dWB4wQ=; b=gqavUw0BQvkugjNHH1hDGQGC+bJv1pMnnN6PKn7NN/oqmUEZHuGtCQzuUe5TDbBCAI pdbt6SzfXtfvOwFmQB4OgJ1Yj2P1mX39k26H8k6aJsL3QgCUm3g1pe1MqC90NX3fHQsd w/ZuGW5PThCdJJFlb6oQGMtbjQCLSBWH8fu2LCXCGHQrhG30h1MeaLDBVHIiNiZEPPaN XSsO3V3G7IfIhEByVKjgMKnzaDFwR5uK3mjX7n31hW8LqGPgbkRsD5cUOkjDJ4s70H1d hhBbM6ykfmH8qLGlkVLQdrmJFiJ4UXQMOy9D2bBAy9BpVI47taPt+AsGJj67sUuSuSkl zp7w== X-Gm-Message-State: AHQUAuY5Zo/h+HJrkHKqNjG1NOxRGY6A0s8UeGhoPccrI6/nS9UK8jTG uU+zfWQ+kCaKy1RLxspFFi3C+LOS X-Google-Smtp-Source: AHgI3IaNV91xIKeFyKjyyZRkFvds0amqlzky1w/KDmal/FUD1TWohEu1I+qqz3hzqvkCZV5Je/GfQw== X-Received: by 2002:a19:9a47:: with SMTP id c68mr7984024lfe.139.1551192881912; Tue, 26 Feb 2019 06:54:41 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t11sm2206554ljj.92.2019.02.26.06.54.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 06:54:41 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 7/8] cpuidle: Pre-store next timer/tick before selecting an idle state Date: Tue, 26 Feb 2019 15:54:14 +0100 Message-Id: <20190226145415.19411-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190226145415.19411-1-ulf.hansson@linaro.org> References: <20190226145415.19411-1-ulf.hansson@linaro.org> A common piece of data used by cpuidle governors, is the information about when the next timer/tick is going to fire. Rather than having each governor calling tick_nohz_get_next_timer|hrtimer() separately, let's consolidate the code by calling these functions before invoking the ->select() callback of the governor - and store the output data in the struct cpuidle_device. Besides the consolidation benefit, the purpose of this change is also to make the information about the next timer/tick, available outside the cpuidle framework. Following changes that implements a new genpd governor, makes use of this. Signed-off-by: Ulf Hansson --- Changes in v11: - New patch. --- drivers/cpuidle/cpuidle.c | 2 ++ drivers/cpuidle/governors/menu.c | 6 ++---- drivers/cpuidle/governors/teo.c | 6 ++---- include/linux/cpuidle.h | 2 ++ 4 files changed, 8 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 7f108309e871..3b148253036b 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -312,6 +312,8 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, bool *stop_tick) { + dev->next_timer = tick_nohz_get_next_timer(); + dev->next_hrtimer = tick_nohz_get_next_hrtimer(); return cpuidle_curr_governor->select(drv, dev, stop_tick); } diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 95e9122d6047..cdbe434e783d 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -287,8 +287,6 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, unsigned long nr_iowaiters; ktime_t delta_next; ktime_t now = ktime_get(); - ktime_t next_hrtimer = tick_nohz_get_next_hrtimer(); - ktime_t next_timer = tick_nohz_get_next_timer(); if (data->needs_update) { menu_update(drv, dev); @@ -298,14 +296,14 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, /* * Compute the duration before the next timer, whatever the origin */ - delta_next = ktime_sub(next_timer, now); + delta_next = ktime_sub(dev->next_timer, now); data->next_timer_us = ktime_to_us(delta_next); /* * Compute the duration before next hrtimer which is the tick * or an earliest hrtimer */ - delta_next = ktime_sub(next_hrtimer, now); + delta_next = ktime_sub(dev->next_hrtimer, now); nr_iowaiters = nr_iowait_cpu(dev->cpu); data->bucket = which_bucket(data->next_timer_us, nr_iowaiters); diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c index bef1e95c597e..7af9851d9d40 100644 --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -245,8 +245,6 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, int max_early_idx, idx, i; ktime_t delta_tick; ktime_t now = ktime_get(); - ktime_t next_hrtimer = tick_nohz_get_next_hrtimer(); - ktime_t next_timer = tick_nohz_get_next_timer(); if (cpu_data->last_state >= 0) { teo_update(drv, dev); @@ -255,8 +253,8 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, cpu_data->time_span_ns = local_clock(); - cpu_data->sleep_length_ns = ktime_sub(next_timer, now); - delta_tick = ktime_sub(next_hrtimer, now); + cpu_data->sleep_length_ns = ktime_sub(dev->next_timer, now); + delta_tick = ktime_sub(dev->next_hrtimer, now); duration_us = ktime_to_us(cpu_data->sleep_length_ns); count = 0; diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 3b39472324a3..81ec924206f0 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -83,6 +83,8 @@ struct cpuidle_device { unsigned int use_deepest_state:1; unsigned int poll_time_limit:1; unsigned int cpu; + ktime_t next_timer; + ktime_t next_hrtimer; int last_residency; struct cpuidle_state_usage states_usage[CPUIDLE_STATE_MAX];