From patchwork Mon Aug 5 17:02:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 170603 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4538770ile; Mon, 5 Aug 2019 10:02:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxE4vVqKG8bNbkkEvA4KPP5jQpytlLEWRiY9e+RO2OyUQQXu8k5E7Cedi7DvMNGUqPTeCe8 X-Received: by 2002:a63:c44c:: with SMTP id m12mr97811212pgg.396.1565024552439; Mon, 05 Aug 2019 10:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024552; cv=none; d=google.com; s=arc-20160816; b=MYwACfP8nEaPIR6ToI9FnZPlYb0UfLqAdec+6mMEimQ8FoKK74WaDAfx+ftmzwyqyG PuN7Y+yqzIL78IAgAO5p8ixcqc8ClLRane8joZW3FP64VqN/SnlhZ3z8qF6eFKREwhAt zElfBiENkiico5ZtzGoxERMT/Aj2TzvEIQSN+fwHwIDkxISrdANEUVGS9P3+VYdf+BM3 MkzDsFROBtgjbpgH92Y9CxZrxfYHAZ60h8wsxcgjKQ+MIc+tp7hNj8tbZyfye6YuBP9L IM8Yb5CNq+dBooFscaMYmqjlD6jxBBL4iL9DOGRrYYY1OSA5q1Ef2IqkswOwMnraOjqN JiYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=+IiyIv/QVlUWmx804ezFK4A4Fw8LXcM/x4rGCJj+JDM=; b=H9/FKO1/jkCctoMDXCY2ocz3LTBBcfErxZWX7JTa7DjjweAweIgOSKrj5WHq4Hn0lK xNcEKo78W+dQpWkaZsAz5cXyrSXWXPIJyseP7Gg/0p03VcR4RlknMT5sR3+JxkcG2PCm ZDuWcfwiEFG8T3MlUg2Hn2scc1wvpfiPxYCywa1OAx75OubxVrQgCSX7CX85UxJHITbU Evh/Fg16CbImi1YcHPfAOEW1gLB47nf+kqNnFY0fN9RbMizyYbYRKsgbBSEsfh7xHURa pRbbaVUIO5XMPivZLj3uSMzSUPhIvvDmxPdqmL+y7/tj3dQ8KWaQq/vzWPGHbq9KC4GQ zD+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WVPkyn0n; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 36si44243069pla.80.2019.08.05.10.02.31; Mon, 05 Aug 2019 10:02:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=WVPkyn0n; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1729001AbfHERCb (ORCPT + 11 others); Mon, 5 Aug 2019 13:02:31 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51108 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729780AbfHERCb (ORCPT ); Mon, 5 Aug 2019 13:02:31 -0400 Received: by mail-wm1-f66.google.com with SMTP id v15so75465540wml.0 for ; Mon, 05 Aug 2019 10:02:29 -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; bh=+IiyIv/QVlUWmx804ezFK4A4Fw8LXcM/x4rGCJj+JDM=; b=WVPkyn0n5tb9CV7ZaunY6rCfNEDplgh1SISnuZcsRAd6+CwHMooFSdKdPV4FZWkP5i /bPMWNWAXWvsmwOdsp/ekVvEUO02IPM3PHegVGgzc6xAvr9V0VBnarnVM696ZHF5k095 pO1BzDnCrQHrMtGcJD5M3U8bnaXZAKl/9AxbqnfwVupxSbPqscXt4Qm6Q+vSZLJfN8kB hpAYA6Zripmsc2Q98gFZQ35I6USKZsWvxN5Lz+ggcYuPypXUJl/xEVAOFAlhPCD0q8rh Jey7ftL9jsk2A63nd0drlaZ7mzT003RS2Y3OEN8/tRxfWo2XYC1ombPkQyHL8uFSeFi+ Oz1A== 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; bh=+IiyIv/QVlUWmx804ezFK4A4Fw8LXcM/x4rGCJj+JDM=; b=dfaKU7n7WEGL4gKbP64NB6SHwVBwh3fOXcw1TtlrdxoLgmaWcXfWLwgujAcTFDs7qg DnIAVoxU5XqyHuHMtNjtHtWQEzs8QE3AVFd41xlKz2Lr5HQe3hAhcx8w5444iSJpQQF2 uceSlXAYgBMIOCndEIEHggYYc6f2B6643Xz6BCorj6R4BH6Dp0RC67FN0+CESLO2g1Ga ycOCgQwnuyk2JvxTd3aamumfr2hEhbQraoOrMYlLi1ucvu6S4vib2sMdzAaT+1Dy+AZ+ iIO5uO5Qk+0cgz21FKN2k8G0ZFgnuxeKdNVHKopQEqIqEWEeUhtf0JfgMvWCQ1pC2Mlb qczw== X-Gm-Message-State: APjAAAXj2cwie0qNSEgZLh++ZKeUGZMEwHbXPliiDP9v1PKVKCvaiFvj vdo/FSHqtnrgeLyDD1FqMZJlqQ== X-Received: by 2002:a7b:c106:: with SMTP id w6mr20717489wmi.80.1565024548256; Mon, 05 Aug 2019 10:02:28 -0700 (PDT) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:e5cb:2287:9bbb:b7eb]) by smtp.gmail.com with ESMTPSA id v29sm28893685wrv.74.2019.08.05.10.02.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 10:02:27 -0700 (PDT) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: linux-pm@vger.kernel.org, Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/3] cpuidle: play_idle: Make play_idle more flexible Date: Mon, 5 Aug 2019 19:02:06 +0200 Message-Id: <20190805170208.26873-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The play_idle function has two users, the intel powerclamp and the idle_injection. The idle injection cooling device uses the function via the idle_injection powercap's APIs. Unfortunately, play_idle is currently limited by the idle state depth, by default the deepest idle state is selected. On the ARM[64] platforms, most of the time it is the cluster idle state, the exit latency and the residency can be very high. That reduces the scope of the idle injection usage because the impact on the performances can be very significant and the idle injection would make sense only if the frequency scaling fails to cool down the CPU by dropping the static leakage and force the CPU to regain part of its thermal capacity. If the idle injection cycles are done with a shallow state like a retention state, the cooling effect can give similar results than the cpufreq cooling device. In order to prepare the function to receive an idle state parameter, let's replace the 'use_deepest_state' boolean field with 'use_state' and use this value to enter the specific idle state. The current code keeps the default behavior which is go to the deepest idle state. Signed-off-by: Daniel Lezcano --- drivers/cpuidle/cpuidle.c | 21 +++++++++++---------- include/linux/cpuidle.h | 12 +++++------- kernel/sched/idle.c | 9 ++++----- 3 files changed, 20 insertions(+), 22 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 0895b988fa92..86fcf7278c1a 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -99,31 +99,31 @@ static int find_deepest_state(struct cpuidle_driver *drv, } /** - * cpuidle_use_deepest_state - Set/clear governor override flag. - * @enable: New value of the flag. + * cpuidle_use_state - Force the cpuidle framework to enter an idle state. + * @state: An integer for an idle state * - * Set/unset the current CPU to use the deepest idle state (override governors - * going forward if set). + * Specify an idle state the cpuidle framework must step in and bypass + * the idle state selection process. */ -void cpuidle_use_deepest_state(bool enable) +void cpuidle_use_state(int state) { struct cpuidle_device *dev; preempt_disable(); dev = cpuidle_get_device(); if (dev) - dev->use_deepest_state = enable; + dev->use_state = state; preempt_enable(); } /** * cpuidle_find_deepest_state - Find the deepest available idle state. - * @drv: cpuidle driver for the given CPU. - * @dev: cpuidle device for the given CPU. */ -int cpuidle_find_deepest_state(struct cpuidle_driver *drv, - struct cpuidle_device *dev) +int cpuidle_find_deepest_state(void) { + struct cpuidle_device *dev = cpuidle_get_device(); + struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); + return find_deepest_state(drv, dev, UINT_MAX, 0, false); } @@ -554,6 +554,7 @@ static void __cpuidle_unregister_device(struct cpuidle_device *dev) static void __cpuidle_device_init(struct cpuidle_device *dev) { memset(dev->states_usage, 0, sizeof(dev->states_usage)); + dev->use_state = -1; dev->last_residency = 0; dev->next_hrtimer = 0; } diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 1a9f54eb3aa1..6c58e71a9995 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -80,9 +80,9 @@ struct cpuidle_driver_kobj; struct cpuidle_device { unsigned int registered:1; unsigned int enabled:1; - unsigned int use_deepest_state:1; unsigned int poll_time_limit:1; unsigned int cpu; + unsigned int use_state; ktime_t next_hrtimer; int last_state_idx; @@ -200,19 +200,17 @@ static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; } #endif #ifdef CONFIG_CPU_IDLE -extern int cpuidle_find_deepest_state(struct cpuidle_driver *drv, - struct cpuidle_device *dev); +extern int cpuidle_find_deepest_state(void); extern int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct cpuidle_device *dev); -extern void cpuidle_use_deepest_state(bool enable); +extern void cpuidle_use_state(int state); #else -static inline int cpuidle_find_deepest_state(struct cpuidle_driver *drv, - struct cpuidle_device *dev) +static inline int cpuidle_find_deepest_state(void) {return -ENODEV; } static inline int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct cpuidle_device *dev) {return -ENODEV; } -static inline void cpuidle_use_deepest_state(bool enable) +static inline void cpuidle_use_state(int state) { } #endif diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index b98283fc6914..c102e03dee6e 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -165,7 +165,7 @@ static void cpuidle_idle_call(void) * until a proper wakeup interrupt happens. */ - if (idle_should_enter_s2idle() || dev->use_deepest_state) { + if (idle_should_enter_s2idle() || dev->use_state != -1) { if (idle_should_enter_s2idle()) { rcu_idle_enter(); @@ -181,8 +181,7 @@ static void cpuidle_idle_call(void) tick_nohz_idle_stop_tick(); rcu_idle_enter(); - next_state = cpuidle_find_deepest_state(drv, dev); - call_cpuidle(drv, dev, next_state); + call_cpuidle(drv, dev, dev->use_state); } else { bool stop_tick = true; @@ -328,7 +327,7 @@ void play_idle(unsigned long duration_us) rcu_sleep_check(); preempt_disable(); current->flags |= PF_IDLE; - cpuidle_use_deepest_state(true); + cpuidle_use_state(cpuidle_find_deepest_state()); it.done = 0; hrtimer_init_on_stack(&it.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); @@ -339,7 +338,7 @@ void play_idle(unsigned long duration_us) while (!READ_ONCE(it.done)) do_idle(); - cpuidle_use_deepest_state(false); + cpuidle_use_state(-1); current->flags &= ~PF_IDLE; preempt_fold_need_resched(); From patchwork Mon Aug 5 17:02:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 170608 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4538962ile; Mon, 5 Aug 2019 10:02:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhW2Y7TO1bpcXx+l5L1rSnHcnV3tlWt2DE3J94fwDvUIS6FohkuOEjH+NBgp+50mFV9U6s X-Received: by 2002:a63:c70d:: with SMTP id n13mr135937352pgg.171.1565024562103; Mon, 05 Aug 2019 10:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024562; cv=none; d=google.com; s=arc-20160816; b=F5/agRAA5zFag8vFWJN7nq/eAzk4cetV54o5CKakCo/sC6k7lNOTmbNx2kXGXhcfjA pHqd/R1ELxaZkmWQr8bJfekHY4W8z3+pKumDhC5UbkP/155bSbT3+2Hhl8Tv6qPrNnr6 T1HIyLXvb2YAe52ihMPBTBpUt7rE+zmo8Yjo98m+6AATH5L2aezmmrKpuzXRNZ5QufCA ejWVnAval0vRuAlK5SRBbX4jU3b5fgiKwqLaZCLavVRi7K66RoZPZPnWfcbmOt31r7qh pWqr4rvOFQ8OJsPFQjhsLPnN93I7c1NIGmgCUygjVrEhX31EBrVu+pJsuDsWWFH1DmCZ F/+Q== 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; bh=wTiqcN9ans0X8+b6FfQH+5cUMosgyj2ws3IXTgtGmS8=; b=qQ4NxdnRcEigxdgQUXJiVrqw+gcPphs34WiQkd0QF3EP6dIv3TFG/t8jVSc3+FX+2/ s4tftI8OeRximsND1rLc4IlGeln9NXKCTuSli4NvF/XQj2FZYRuEcKchqz6/F3//kPQE KNSHOsOWAcIDMfjod3uDJZVgMUDxenn1wEuqY/uG/EtQrxhDEzO5n0nfq+2HnSk9WcED y7V/et+29tGgX2H1SiKvhqFrripdjE2xmZTHyzkiRbgEJ7JbMsgBgQC8imWp0F8soDyr gyimEB+FAplA5emoR/oezNq8hSYY119SgRY6ct+GEcLMILGwbNEGrr1iCXbalFAl7d8s 2cXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KQ0cEdMQ; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 l63si46181371pfl.41.2019.08.05.10.02.41; Mon, 05 Aug 2019 10:02:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=KQ0cEdMQ; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1729973AbfHERCl (ORCPT + 11 others); Mon, 5 Aug 2019 13:02:41 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39403 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729914AbfHERCl (ORCPT ); Mon, 5 Aug 2019 13:02:41 -0400 Received: by mail-wm1-f66.google.com with SMTP id u25so63360893wmc.4 for ; Mon, 05 Aug 2019 10:02:39 -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=wTiqcN9ans0X8+b6FfQH+5cUMosgyj2ws3IXTgtGmS8=; b=KQ0cEdMQ7CsmbkTG8v83WQ8idHQcpy1o6EqRpdVIr6T/mKjdwyQyFobXC7ej0BsWmz +4hk4IBZlp0q6fwXr+b2VG5jG7xI0/JO6MYkxepVK2S2dq2oNl7TDkGiCmjj9MgvEC8X gwhZn8+PbYoEeNTEMBT1XyqAx2ikdgyZLf+Vwbu7v8duiat9g1olSU/E5sSpTY+7hbZP wIEd6ysvglzS9f7w5BG4LGuvZRZyIJD8lowKn0tEuhP7xX3s2S885dyADWLPbUCfTGSs 3u66m7CFthV0uuXWVDUCRjvx/9eixE0/bFzMvfTJMJK4iHjFL6zSUEDqeglbj86zW8r7 RhqA== 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=wTiqcN9ans0X8+b6FfQH+5cUMosgyj2ws3IXTgtGmS8=; b=SUjUDm33N+3LNBPP6F3w0iUgyIH/5AZYUI86se8ZLp4kPqVXn8qrktQPQdk1TTyeQS GkAo1i4eogTTCRpHOwk5jpjZeQSoaDUorbHJ3M/o3savP2IgfQBS42vWuRH9DxIZqpve 87Q4gjujYfwOfangQRrbKpTfYqDxdga8q+YRby/VNK7LkXqyJA01NmtB3D/XNYivZyJu ls5gZkCSxY6uxZPZbnFNtDhpFhN/uhqfjj5hlen4elUPn12d9iG1j4Ar0XkSUlNr8K3b xdtITVwcZp5rRbh+YIlYs6pRn7lPfEzrjDW5O390vvkSv2uiGUOx2U+qtivunc6tnO5h yLQw== X-Gm-Message-State: APjAAAX1fPvrsj7QNvjfuq8uVZR999XzKalNgbxiklxB4KiCaiIS9FI6 51Cc6Bmo4f7CunfSDgGbffDAiA== X-Received: by 2002:a05:600c:c4:: with SMTP id u4mr19728181wmm.96.1565024558987; Mon, 05 Aug 2019 10:02:38 -0700 (PDT) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:e5cb:2287:9bbb:b7eb]) by smtp.gmail.com with ESMTPSA id v29sm28893685wrv.74.2019.08.05.10.02.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 10:02:38 -0700 (PDT) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: linux-pm@vger.kernel.org, Zhang Rui , Eduardo Valentin , Ingo Molnar , Peter Zijlstra , Greg Kroah-Hartman , Thomas Gleixner , Luc Van Oostenryck , Finn Thain , Amit Kucheria , Josh Poimboeuf , Nicholas Piggin , Jiri Kosina , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/3] cpuidle: play_idle: Specify play_idle with an idle state Date: Mon, 5 Aug 2019 19:02:07 +0200 Message-Id: <20190805170208.26873-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190805170208.26873-1-daniel.lezcano@linaro.org> References: <20190805170208.26873-1-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently, the play_idle function does not allow to tell which idle state we want to go. Improve this by passing the idle state as parameter to the function. Signed-off-by: Daniel Lezcano --- drivers/powercap/idle_inject.c | 3 ++- drivers/thermal/intel/intel_powerclamp.c | 4 +++- include/linux/cpu.h | 2 +- kernel/sched/idle.c | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c index cd1270614cc6..9b18667b9f26 100644 --- a/drivers/powercap/idle_inject.c +++ b/drivers/powercap/idle_inject.c @@ -138,7 +138,8 @@ static void idle_inject_fn(unsigned int cpu) */ iit->should_run = 0; - play_idle(READ_ONCE(ii_dev->idle_duration_us)); + play_idle(READ_ONCE(ii_dev->idle_duration_us), + cpuidle_find_deepest_state()); } /** diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c index 53216dcbe173..b55786c169ae 100644 --- a/drivers/thermal/intel/intel_powerclamp.c +++ b/drivers/thermal/intel/intel_powerclamp.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -430,7 +431,8 @@ static void clamp_idle_injection_func(struct kthread_work *work) if (should_skip) goto balance; - play_idle(jiffies_to_usecs(w_data->duration_jiffies)); + play_idle(jiffies_to_usecs(w_data->duration_jiffies), + cpuidle_find_deepest_state()); balance: if (clamping && w_data->clamping && cpu_online(w_data->cpu)) diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 88dc0c653925..76e3038b63ce 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -179,7 +179,7 @@ void arch_cpu_idle_dead(void); int cpu_report_state(int cpu); int cpu_check_up_prepare(int cpu); void cpu_set_state_online(int cpu); -void play_idle(unsigned long duration_us); +void play_idle(unsigned long duration_us, int state); #ifdef CONFIG_HOTPLUG_CPU bool cpu_wait_death(unsigned int cpu, int seconds); diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index c102e03dee6e..f9773dd55ab9 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -310,7 +310,7 @@ static enum hrtimer_restart idle_inject_timer_fn(struct hrtimer *timer) return HRTIMER_NORESTART; } -void play_idle(unsigned long duration_us) +void play_idle(unsigned long duration_us, int state) { struct idle_timer it; @@ -327,7 +327,7 @@ void play_idle(unsigned long duration_us) rcu_sleep_check(); preempt_disable(); current->flags |= PF_IDLE; - cpuidle_use_state(cpuidle_find_deepest_state()); + cpuidle_use_state(state); it.done = 0; hrtimer_init_on_stack(&it.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); From patchwork Mon Aug 5 17:02:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 170609 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4539024ile; Mon, 5 Aug 2019 10:02:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLJsZCM01xJva1HFwolDkCB2aRa08iar/QEr7vTRZVkBH3EpOAuoTWq9rDuIV45z2msv1f X-Received: by 2002:a17:902:820c:: with SMTP id x12mr147005986pln.216.1565024566931; Mon, 05 Aug 2019 10:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565024566; cv=none; d=google.com; s=arc-20160816; b=YqVmssedZost86xHGtHJof0c7inmk9w0p38TkfmG/2QLsSOFAeDVpj6ADjrAPLe/WF Q0t4gYS0Rax5YrZ1fT3ex5rEgNTMFwZwT5utD1k8uwFrlkZFx2nQ/y8N49f+mdTcx7EF y/niouMhVsouylHPMmLolGD9px9gBkzvyg5UWFxN/ex1/lTUMzDXhMwhQNHBZyqj3yL0 nWtthq+GFz8Dv95XMyF+Jd7iPtXCkbJL2SH/YlwH0orx1K/kBZhdr10cSY1zPpe3TUeS XJaNminUl0dXVqCFWg+JvXEfBf5AXZmWM4O5hvuBFXxHV/UH/wpdKFwOrP1eJbP6+DJp c1Sg== 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; bh=8seUtniCWRwFTJq4JInJW6atX1NHBdkEw579O8M2U9c=; b=AoKvgIDO19QqRB1KjINErEYR4wWIQEsGXloQ55x4irfb+9eYHiLpwmBPZGRt598ZGA LgDiZQXyIdiRQev8W6GctwxAlMOjKvrsjtFumpB3M2lprJbd3MHjp3o4b4RHCc71it67 V4RS9jmVWUkaznQV7Cpaklq0YTa8q1fNa0npWDu/3uyn5CaLSutaWQcUmjX5fdryzNNM hexE9dgv3tSjJDsJRMgFLehy6jFoyRkDx/krcDVqEXpgF+6AVkiV6KqxHUK8WtxlEhKi e3vR/7hXHkfOhVRpOTB9bCF16ouLyvWfgsIgFGB/uo9hSVXHvThXe12NyedqfskWMSMD BtVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rZuWM93z; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 u128si40093045pgu.389.2019.08.05.10.02.46; Mon, 05 Aug 2019 10:02:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=rZuWM93z; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1730024AbfHERCq (ORCPT + 11 others); Mon, 5 Aug 2019 13:02:46 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52258 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730011AbfHERCq (ORCPT ); Mon, 5 Aug 2019 13:02:46 -0400 Received: by mail-wm1-f68.google.com with SMTP id s3so75435231wms.2 for ; Mon, 05 Aug 2019 10:02:45 -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=8seUtniCWRwFTJq4JInJW6atX1NHBdkEw579O8M2U9c=; b=rZuWM93zis34ydR/ncwm9ywfu2puMq373eHZDdgwqmtjXJXB1PEM9wVVrN1dGDB+Ey VV2wbneQrvNNZxmOELIEn9K+wnBS6lcBwOldd8Ic/DHqfynnRkVfUsKNa4KOKnetFmsS ZFYK5/OmE6emlTxZZ/UJkEjx6X1LwwrAhN+Eoss6ERTPRQ78FTgRpf3jCWG+R7dG2hay CbfdNRQanY9NIos3Zo17BWvTT8pmxSTIK7LMpKEa6FuMbCZtFj7iKiYQ2MoSAx1QM4LH oK1DzgT1Xm1vrsCLu7rfRFb/hZGZeCd+OAZMvD0K+14jUH4vIefXM50yCm35Q2lR92Ok RAeA== 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=8seUtniCWRwFTJq4JInJW6atX1NHBdkEw579O8M2U9c=; b=AH4PGjyygE+bsYtUsOs/250qU/5DbSprJ/BZ7RreMSYSGlLYgru4HYgLWYUl8VgtbC h2VQJ7A1RDlzLPXB+JpKJnrss45Juk/lQ4hpDcR6NE15RVKxkk7c3Zyr7t/aQodZ5m/P slALjoCcpoGtD5vzhVWipJziRo9x4U8dJ8oJ1LDYojW+uPXCwZqWoulO60V6ayyMEu3p dSRiEkAzfOE0N0vNOUoOofjP3QdJglnYMWNpGw85k31n/1UJmPhFgf0DRtsebsLg1VEc 6q22kHS9KUGdc0gyIJ5oZgFqPib2UWQFMapP09AgAfqNz63sXCrbQru/FWvdQg0uxAdE 0m1w== X-Gm-Message-State: APjAAAV2FUbzBV/6UVIP0o8RNG6i0DBmSFDDPOrsbD6INJO1+knjvLZO 2zUnjafvem/zgw8MDNTwnb3xuU489uI= X-Received: by 2002:a1c:a8c9:: with SMTP id r192mr20084425wme.43.1565024564444; Mon, 05 Aug 2019 10:02:44 -0700 (PDT) Received: from localhost.localdomain ([2a01:e34:ed2f:f020:e5cb:2287:9bbb:b7eb]) by smtp.gmail.com with ESMTPSA id v29sm28893685wrv.74.2019.08.05.10.02.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 10:02:44 -0700 (PDT) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org (open list) Subject: [PATCH 3/3] powercap/drivers/idle_inject: Specify the idle state to inject Date: Mon, 5 Aug 2019 19:02:08 +0200 Message-Id: <20190805170208.26873-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190805170208.26873-1-daniel.lezcano@linaro.org> References: <20190805170208.26873-1-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently the idle injection framework only allows to inject the deepest idle state available on the system. Give the opportunity to specify which idle state we want to inject by adding a new function helper to set the state and use it when calling play_idle(). Signed-off-by: Daniel Lezcano --- drivers/powercap/idle_inject.c | 15 ++++++++++++++- include/linux/idle_inject.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/powercap/idle_inject.c b/drivers/powercap/idle_inject.c index 9b18667b9f26..a94ebab9ee21 100644 --- a/drivers/powercap/idle_inject.c +++ b/drivers/powercap/idle_inject.c @@ -38,6 +38,7 @@ #define pr_fmt(fmt) "ii_dev: " fmt #include +#include #include #include #include @@ -65,6 +66,7 @@ struct idle_inject_thread { */ struct idle_inject_device { struct hrtimer timer; + int state; unsigned int idle_duration_us; unsigned int run_duration_us; unsigned long int cpumask[0]; @@ -139,7 +141,7 @@ static void idle_inject_fn(unsigned int cpu) iit->should_run = 0; play_idle(READ_ONCE(ii_dev->idle_duration_us), - cpuidle_find_deepest_state()); + READ_ONCE(ii_dev->state)); } /** @@ -170,6 +172,16 @@ void idle_inject_get_duration(struct idle_inject_device *ii_dev, *idle_duration_us = READ_ONCE(ii_dev->idle_duration_us); } +/** + * idle_inject_set_state - set the idle state to inject + * @state: an integer for the idle state to inject + */ +void idle_inject_set_state(struct idle_inject_device *ii_dev, int state) +{ + if (state >= -1 && state < CPUIDLE_STATE_MAX) + WRITE_ONCE(ii_dev->state, state); +} + /** * idle_inject_start - start idle injections * @ii_dev: idle injection control device structure @@ -298,6 +310,7 @@ struct idle_inject_device *idle_inject_register(struct cpumask *cpumask) cpumask_copy(to_cpumask(ii_dev->cpumask), cpumask); hrtimer_init(&ii_dev->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); ii_dev->timer.function = idle_inject_timer_fn; + ii_dev->state = cpuidle_find_deepest_state(); for_each_cpu(cpu, to_cpumask(ii_dev->cpumask)) { diff --git a/include/linux/idle_inject.h b/include/linux/idle_inject.h index a445cd1a36c5..e2b26b9ccd34 100644 --- a/include/linux/idle_inject.h +++ b/include/linux/idle_inject.h @@ -26,4 +26,7 @@ void idle_inject_set_duration(struct idle_inject_device *ii_dev, void idle_inject_get_duration(struct idle_inject_device *ii_dev, unsigned int *run_duration_us, unsigned int *idle_duration_us); + +void idle_inject_set_state(struct idle_inject_device *ii_dev, int state); + #endif /* __IDLE_INJECT_H__ */