All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>, Avi Kivity <avi@redhat.com>,
	Andi Kleen <ak@linux.intel.com>, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH RFC] sched: add notifier for process migration
Date: Sat, 10 Oct 2009 09:14:23 +0200	[thread overview]
Message-ID: <1255158863.7866.25.camel@twins> (raw)
In-Reply-To: <4ACFBC98.4070701@goop.org>

On Fri, 2009-10-09 at 15:43 -0700, Jeremy Fitzhardinge wrote:

> OK, concretely:
> 
>    1. allocate a page and fixmap it into userspace
>    2. keep an array of structures containing tsc->cycle_t
>       (pvclock_vcpu_time_info) params, indexed by cpu
>    3. register those structures with the hypervisor so it can update
>       them as either the pcpus change freq and/or the vcpus get moved to
>       different pcpus
>    4. associate a "migration_count" with each structure (ie, how many
>       times this cpu has had tasks migrated off it)
> 
> The algorithm is basically:
> 
>     do {
>         cpu = vgetcpu();    	/* get current cpu */
>         ti = &timeinfo[cpu];	/* get scaling+offset for tsc */
> 
>         /* !!! migration race */
> 
>         migration_count = ti->migration_count;
>         version = ti->version;
> 
>         barrier();
> 
>         local_time_info = *ti;
> 
>         tsc = rdtsc();
>         cycles = compute_cycles_from_tsc(tsc, &local_time_info);
> 
>         barrier();
> 
>         cpu1 = vgetcpu();
> 
>     /* loop if anything changed under our feet:
>         - we changed cpus (if we got migrated at "!!! migration race" above
>            then the migration_count test won't pick it up)
>         - the time info changed
>         - we got migrated to a different cpu (we need to check this as well
>            as cpu != cpu1 in case we got migrated from A->B->A)
>      */
> 
>     } while(unlikely(cpu1 != cpu ||
>     		 timeinfo->version != version ||
>     		 timeinfo->migration_count != migration_count));
> 
>     return cycles;
>       
> 
> This is executed in usermode as part of vsyscall gettimeofday via the
> clocksource.vread function.

Why not do something like:

    struct {
	u64 tsc;
	u32 aux;
    } tscp = rdtscp();

    local_time_info = timeinfo[tscp_cpu(tscp)];

    /* yay, consistent tsc and timeinfo !! */

?

  reply	other threads:[~2009-10-10  7:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-09 21:01 [PATCH RFC] sched: add notifier for process migration Jeremy Fitzhardinge
2009-10-09 22:02 ` Peter Zijlstra
2009-10-09 22:43   ` Jeremy Fitzhardinge
2009-10-10  7:14     ` Peter Zijlstra [this message]
2009-10-10  9:05       ` Avi Kivity
2009-10-10  9:24         ` Peter Zijlstra
2009-10-10  9:36           ` Jeremy Fitzhardinge
2009-10-10 10:12             ` Peter Zijlstra
2009-10-13 21:25               ` Jeremy Fitzhardinge
2009-10-14  7:05                 ` Ingo Molnar
2009-10-14  9:26                   ` Peter Zijlstra
2009-10-14 10:37                     ` Avi Kivity
2009-10-14 14:41                     ` Jason Baron
2009-10-14 16:15                   ` Jeremy Fitzhardinge

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=1255158863.7866.25.camel@twins \
    --to=peterz@infradead.org \
    --cc=ak@linux.intel.com \
    --cc=avi@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.