linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>,
	Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux PM <linux-pm@vger.kernel.org>,
	Rafael Wysocki <rafael.j.wysocki@intel.com>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Len Brown <lenb@kernel.org>,
	Eduardo Valentin <edubezval@gmail.com>,
	Zhang Rui <rui.zhang@intel.com>, Petr Mladek <pmladek@suse.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: Re: [PATCH v3 1/3] idle: add support for tasks that inject idle
Date: Thu, 24 Nov 2016 12:04:54 +0100	[thread overview]
Message-ID: <20161124110454.GA22551@gmail.com> (raw)
In-Reply-To: <20161124095016.GD3092@twins.programming.kicks-ass.net>


* Peter Zijlstra <peterz@infradead.org> wrote:

> On Wed, Nov 23, 2016 at 12:13:08PM -0800, Jacob Pan wrote:
> > @@ -280,6 +272,58 @@ bool cpu_in_idle(unsigned long pc)
> >  		pc < (unsigned long)__cpuidle_text_end;
> >  }
> >  
> > +static enum hrtimer_restart idle_inject_timer_fn(struct hrtimer *hrtimer)
> > +{
> > +	set_tsk_need_resched(current);
> > +	return HRTIMER_NORESTART;
> > +}
> > +
> > +void play_idle(unsigned long duration_ms)
> > +{
> > +	struct hrtimer timer;
> > +	unsigned long end_time;
> > +
> > +	/*
> > +	 * Only FIFO tasks can disable the tick since they don't need the forced
> > +	 * preemption.
> > +	 */
> > +	WARN_ON_ONCE(current->policy != SCHED_FIFO);
> > +	WARN_ON_ONCE(current->nr_cpus_allowed != 1);
> > +	WARN_ON_ONCE(!(current->flags & PF_KTHREAD));
> > +	WARN_ON_ONCE(!(current->flags & PF_NO_SETAFFINITY));
> > +
> > +	rcu_sleep_check();
> > +	preempt_disable();
> > +	current->flags |= PF_IDLE;
> > +	cpuidle_use_deepest_state(true);
> > +
> > +	/*
> > +	 * If duration is 0, we will return after a natural wake event occurs. If
> > +	 * duration is none zero, we will go back to sleep if we were woken up earlier.
> > +	 * We also set up a timer to make sure we don't oversleep in deep idle.
> > +	 */
> > +	if (!duration_ms)
> > +		do_idle();
> 
> OK, so that doesn't make any sense, you should not be calling this
> without a timeout.
> 
> > +	else {
> > +		hrtimer_init_on_stack(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
> > +		timer.function = idle_inject_timer_fn;
> > +		hrtimer_start(&timer, ms_to_ktime(duration_ms),
> > +			HRTIMER_MODE_REL_PINNED);
> > +		end_time = jiffies + msecs_to_jiffies(duration_ms);
> > +
> > +		while (time_after(end_time, jiffies))
> > +			do_idle();
> > +	}
> > +	hrtimer_cancel(&timer);
> > +
> > +	cpuidle_use_deepest_state(false);
> > +	current->flags &= ~PF_IDLE;
> > +
> > +	preempt_fold_need_resched();
> > +	preempt_enable();
> > +}
> > +EXPORT_SYMBOL_GPL(play_idle);
> 
> 
> How about something like so... (since I had to edit, I fixed up most
> things Ingo complained about as well).
> 
> Note that it doesn't build because of a distinct lack of
> cpuidle_use_deepest_state() in my kernel tree.

Ok, I really like this one, it so much cleaner!

If the patch builds & works:

  Acked-by: Ingo Molnar <mingo@kernel.org>

Thanks,

	Ingo

  reply	other threads:[~2016-11-24 11:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-23 20:13 [PATCH v3 0/3] Stop sched tick in idle injection task Jacob Pan
2016-11-23 20:13 ` [PATCH v3 1/3] idle: add support for tasks that inject idle Jacob Pan
2016-11-24  4:18   ` Ingo Molnar
2016-11-24  9:50   ` Peter Zijlstra
2016-11-24 11:04     ` Ingo Molnar [this message]
2016-11-24 13:44       ` Rafael J. Wysocki
2016-11-23 20:13 ` [PATCH v3 2/3] cpuidle: allow setting deepest idle Jacob Pan
2016-11-23 20:13 ` [PATCH v3 3/3] thermal/powerclamp: stop sched tick in forced idle Jacob Pan
2016-11-23 21:12 ` [PATCH v3 0/3] Stop sched tick in idle injection task Rafael J. Wysocki
2016-11-23 21:45   ` Peter Zijlstra
2016-11-23 22:38     ` Rafael J. Wysocki
2016-11-24  0:25       ` Jacob Pan
2016-11-24  0:24         ` Rafael J. Wysocki
2016-11-24  4:21   ` Ingo Molnar

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=20161124110454.GA22551@gmail.com \
    --to=mingo@kernel.org \
    --cc=arjan@linux.intel.com \
    --cc=bigeasy@linutronix.de \
    --cc=edubezval@gmail.com \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=lenb@kernel.org \
    --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 \
    /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).