linux-um.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Anton Ivanov <anton.ivanov@kot-begemot.co.uk>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: Re: [uml-devel] [PATCH v4] um: Switch clocksource to hrtimers
Date: Mon, 02 Nov 2015 22:13:20 +0000	[thread overview]
Message-ID: <5637E000.7020202@kot-begemot.co.uk> (raw)
In-Reply-To: <5637DA94.5000302@nod.at>

On 02/11/15 21:50, Richard Weinberger wrote:
> Am 02.11.2015 um 17:16 schrieb Anton Ivanov:
>> -void idle_sleep(unsigned long long nsecs)
>> +/**
>> + * os_idle_sleep() - sleep for a given time of nsecs
>> + * @nsecs: nanoseconds to sleep
>> + */
>> +void os_idle_sleep(unsigned long long nsecs)
>>  {
>>  	struct timespec ts;
>>  
>> -	/*
>> -	 * nsecs can come in as zero, in which case, this starts a
>> -	 * busy loop.  To prevent this, reset nsecs to the tick
>> -	 * interval if it is zero.
>> -	 */
>> -	if (nsecs == 0)
>> -		nsecs = UM_NSEC_PER_SEC / UM_HZ;
>> +	if (nsecs <= 0) {
>> +		return;
>> +	}
>>  
>> -	nsecs = sleep_time(nsecs);
>> -	ts = ((struct timespec) { .tv_sec	= nsecs / UM_NSEC_PER_SEC,
>> -				  .tv_nsec	= nsecs % UM_NSEC_PER_SEC });
>> +	ts = ((struct timespec) {
>> +			.tv_sec  = nsecs / UM_NSEC_PER_SEC,
>> +			.tv_nsec = nsecs % UM_NSEC_PER_SEC
>> +	});
>>  
>> -	if (nanosleep(&ts, &ts) == 0)
>> +	if (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL)) {
>>  		deliver_alarm();
>> -	after_sleep_interval(&ts);
>> +	}
> Hmm, now this function sleeps at most nsecs. If it is interrupted
> the alarm is delivered.
> Why only upon interruption and not also if clock_nanosleep()
> completes?

It is invoked differently.

We changed process.c too.

The old behaviour used to be to disable the timer, read timer remaining
and program a nanosleep with that. This resulted in the timer actually
firing in idle despite UML using the virtual clock for timers.

With timer moving to MONOTONIC we could do the same, but we do not need
to. Instead of disabling the timer we can leave it running and program a
nanosleep which is long enough in most cases for the timer to fire. This
is what the matching change in process.c does. Together, this results in
saving at least 2 syscalls per each idle invocation.

A.

>
> Thanks,
> //richard
>
> ------------------------------------------------------------------------------
> _______________________________________________
> User-mode-linux-devel mailing list
> User-mode-linux-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
>


------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


  reply	other threads:[~2015-11-02 22:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02 16:16 [uml-devel] [PATCH v4] um: Switch clocksource to hrtimers Anton Ivanov
2015-11-02 21:50 ` Richard Weinberger
2015-11-02 22:13   ` Anton Ivanov [this message]
2015-11-03  7:11     ` Anton Ivanov
2015-11-03  7:58       ` Thomas Meyer
2015-11-06 21:56 ` Richard Weinberger
2015-11-07 10:29   ` Anton Ivanov
2015-11-07 10:32     ` Richard Weinberger
2015-11-18  1:20   ` Lorenzo Colitti
2015-11-18  7:00     ` Anton Ivanov
2015-11-18  7:10       ` Lorenzo Colitti
2015-11-18  8:06         ` Richard Weinberger
2015-11-18 13:32           ` Lorenzo Colitti
2015-11-18 13:40             ` Richard Weinberger

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=5637E000.7020202@kot-begemot.co.uk \
    --to=anton.ivanov@kot-begemot.co.uk \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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).