From: Jacob Pan <jacob.jun.pan@linux.intel.com>
To: LKML <linux-kernel@vger.kernel.org>,
Linux PM <linux-pm@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>
Cc: Zhang Rui <rui.zhang@intel.com>,
Rafael Wysocki <rafael.j.wysocki@intel.com>,
"Chen, Yu C" <yu.c.chen@intel.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Petr Mladek <pmladek@suse.com>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
Arjan van de Ven <arjan@linux.intel.com>,
Jacob Pan <jacob.jun.pan@linux.intel.com>
Subject: [PATCH 3/3] thermal/powerclamp: use PF_IDLE in injection kthread
Date: Wed, 9 Nov 2016 11:05:12 -0800 [thread overview]
Message-ID: <1478718312-12847-4-git-send-email-jacob.jun.pan@linux.intel.com> (raw)
In-Reply-To: <1478718312-12847-1-git-send-email-jacob.jun.pan@linux.intel.com>
With the introduction of play_idle(), idle injection kthread can
go through the normal idle task processing to get correct accounting
and turn off scheduler tick when possible.
Hrtimer is used to wake up since timeout is most likely to occur
during idle injection.
Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
---
drivers/thermal/intel_powerclamp.c | 58 ++++++++++++++++----------------------
1 file changed, 24 insertions(+), 34 deletions(-)
diff --git a/drivers/thermal/intel_powerclamp.c b/drivers/thermal/intel_powerclamp.c
index 745fcec..c82b41f 100644
--- a/drivers/thermal/intel_powerclamp.c
+++ b/drivers/thermal/intel_powerclamp.c
@@ -51,6 +51,7 @@
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/sched/rt.h>
+#include <linux/cpuidle.h>
#include <asm/nmi.h>
#include <asm/msr.h>
@@ -93,7 +94,7 @@ struct powerclamp_worker_data {
struct kthread_worker *worker;
struct kthread_work balancing_work;
struct kthread_delayed_work idle_injection_work;
- struct timer_list wakeup_timer;
+ struct hrtimer timer;
unsigned int cpu;
unsigned int count;
unsigned int guard;
@@ -278,11 +279,6 @@ static u64 pkg_state_counter(void)
return count;
}
-static void noop_timer(unsigned long foo)
-{
- /* empty... just the fact that we get the interrupt wakes us up */
-}
-
static unsigned int get_compensation(int ratio)
{
unsigned int comp = 0;
@@ -429,14 +425,24 @@ static void clamp_balancing_func(struct kthread_work *work)
sleeptime);
}
+static enum hrtimer_restart idle_inject_timer_fn(struct hrtimer *hrtimer)
+{
+ set_tsk_need_resched(current);
+ return HRTIMER_NORESTART;
+}
+
static void clamp_idle_injection_func(struct kthread_work *work)
{
struct powerclamp_worker_data *w_data;
- unsigned long target_jiffies;
+ unsigned long end_time;
+ unsigned int duration_ms;
w_data = container_of(work, struct powerclamp_worker_data,
idle_injection_work.work);
+ hrtimer_init(&w_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
+ w_data->timer.function = idle_inject_timer_fn;
+
/*
* only elected controlling cpu can collect stats and update
* control parameters.
@@ -453,31 +459,17 @@ static void clamp_idle_injection_func(struct kthread_work *work)
if (should_skip)
goto balance;
- target_jiffies = jiffies + w_data->duration_jiffies;
- mod_timer(&w_data->wakeup_timer, target_jiffies);
- if (unlikely(local_softirq_pending()))
- goto balance;
- /*
- * stop tick sched during idle time, interrupts are still
- * allowed. thus jiffies are updated properly.
- */
- preempt_disable();
- /* mwait until target jiffies is reached */
- while (time_before(jiffies, target_jiffies)) {
- unsigned long ecx = 1;
- unsigned long eax = target_mwait;
-
- /*
- * REVISIT: may call enter_idle() to notify drivers who
- * can save power during cpu idle. same for exit_idle()
- */
- local_touch_nmi();
- stop_critical_timings();
- mwait_idle_with_hints(eax, ecx);
- start_critical_timings();
- atomic_inc(&idle_wakeup_counter);
- }
- preempt_enable();
+ end_time = jiffies + w_data->duration_jiffies;
+ duration_ms = jiffies_to_msecs(w_data->duration_jiffies);
+ hrtimer_start(&w_data->timer, ms_to_ktime(duration_ms),
+ HRTIMER_MODE_REL_PINNED);
+
+ cpuidle_use_deepest_state(true);
+ while (time_after(end_time, jiffies))
+ play_idle();
+ cpuidle_use_deepest_state(false);
+
+ hrtimer_cancel(&w_data->timer);
balance:
if (clamping && w_data->clamping && cpu_online(w_data->cpu))
@@ -540,7 +532,6 @@ static void start_power_clamp_worker(unsigned long cpu)
w_data->cpu = cpu;
w_data->clamping = true;
set_bit(cpu, cpu_clamping_mask);
- setup_timer(&w_data->wakeup_timer, noop_timer, 0);
sched_setscheduler(worker->task, SCHED_FIFO, &sparam);
kthread_init_work(&w_data->balancing_work, clamp_balancing_func);
kthread_init_delayed_work(&w_data->idle_injection_work,
@@ -572,7 +563,6 @@ static void stop_power_clamp_worker(unsigned long cpu)
* a big deal. The balancing work is fast and destroy kthread
* will wait for it.
*/
- del_timer_sync(&w_data->wakeup_timer);
clear_bit(w_data->cpu, cpu_clamping_mask);
kthread_destroy_worker(w_data->worker);
--
1.9.1
next prev parent reply other threads:[~2016-11-09 19:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-09 19:05 [PATCH 0/3] Stop sched tick in idle injection task Jacob Pan
2016-11-09 19:05 ` [PATCH 1/3] idle: add support for tasks that inject idle Jacob Pan
2016-11-14 14:57 ` Peter Zijlstra
2016-11-14 15:01 ` Peter Zijlstra
2016-11-14 15:01 ` Peter Zijlstra
2016-11-14 16:20 ` Jacob Pan
2016-11-14 16:22 ` Peter Zijlstra
2016-11-14 16:29 ` Jacob Pan
2016-11-09 19:05 ` [PATCH 2/3] cpuidle: allow setting deepest idle Jacob Pan
2016-11-14 14:58 ` Peter Zijlstra
2016-11-09 19:05 ` Jacob Pan [this message]
2016-11-14 15:11 ` [PATCH 3/3] thermal/powerclamp: use PF_IDLE in injection kthread Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1478718312-12847-4-git-send-email-jacob.jun.pan@linux.intel.com \
--to=jacob.jun.pan@linux.intel.com \
--cc=arjan@linux.intel.com \
--cc=bigeasy@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rafael.j.wysocki@intel.com \
--cc=rui.zhang@intel.com \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=tglx@linutronix.de \
--cc=yu.c.chen@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).