public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrea Arcangeli <andrea@suse.de>
To: dean gaudet <dean@arctic.org>
Cc: john stultz <johnstul@us.ibm.com>,
	ak@suse.de, linux-kernel@vger.kernel.org, tglx@linutronix.de,
	mingo@elte.hu, Suleiman Souhlal <ssouhlal@FreeBSD.org>
Subject: Re: rdtscp vgettimeofday
Date: Tue, 12 Dec 2006 00:38:00 +0100	[thread overview]
Message-ID: <20061211233800.GP5363@opteron.random> (raw)
In-Reply-To: <Pine.LNX.4.64.0612111503560.21063@twinlark.arctic.org>

On Mon, Dec 11, 2006 at 03:15:44PM -0800, dean gaudet wrote:
> rdtscp gets you 2 of the 5 values you need to compute the time.  anything 
> can happen between when you do the rdtscp and do the other 3 reads:  the 
> computation is (((tsc-A)*B)>>N)+C where N is a constant, and A, B, C are 
> per-cpu data.
> A/B/C change a few times a second (to avoid 32-bit rollover in (tsc-A)), 
> every time there's a halt, and every P-state transition.

This is wrong. There's the D variable too, the seq lock.

The thing I've in mind is something like:

    rdstcp (get tsc and cpu atomic) this is fundamental without tsc
    and cpu read atomically nothing of the below is possible

    read D from cpu we got from rdtscp (seqlock)
    smb_rmb()
    check that D isn't during the race condition (last LSB clear
    or similar) or restart
    rdstcp again (tsc and cpu atomic)
    check that cpu is still the same or restart
    index the per-cpu array and get the safe A B C
    smp_rmb()
    read per-cpu D again and check that it didn't change or restart

Then you have tsc, A, B and C all atomic. N is a constant. rdtsc again
is fundamental in getting this info all atomic w/o accessing the
southbridge and without expensive asm instruction.

> if you lose your tick in the middle of those reads any number of things 
> can happen to screw the computation... including being scheduled on 
> another core and mixing values from two cores.

Being scheduled in another core is normal. continuing gettimeofday
from another core after you have the tsc value is just fine.

If something the problem is to generate A B C in per-cpu data with a
per-cpu seqlock around it. That's the job for the per-cpu kernel
thread.

The only real trouble I see is the offset from the last irq. It's
possible to make this to work we need to rotate the timer irq across
all cpus at regular intervals (before the tsc2usec measurement error
showup).

> oh i think there are several solutions which will work... and i also think 
> rdtscp wasn't a necessary addition to the ISA :)

Please don't suggest me the userland rsp manual unwinding, that's
orders of magnitude more fragile and it sounds much more complex too ;).

  reply	other threads:[~2006-12-11 23:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-29  3:00 [PATCH 0/5][time][x86_64] GENERIC_TIME patchset for x86_64 john stultz
2006-11-29  3:00 ` [PATCH 1/5][time][Generic] vsyscall-gtod support for GENERIC_TIME john stultz
2006-11-29  3:00 ` [PATCH 2/5][time][x86_64] hpet_address cleanup john stultz
2006-11-29  3:00 ` [PATCH 3/5][time][x86_64] Split x86_64/kernel/time.c up john stultz
2006-11-29  3:00 ` [PATCH 4/5][time][x86_64] Convert x86_64 to use GENERIC_TIME john stultz
2006-12-11  0:39   ` rdtscp vgettimeofday Andrea Arcangeli
2006-12-11 21:17     ` dean gaudet
2006-12-11 21:32       ` Andrea Arcangeli
2006-12-11 23:15         ` dean gaudet
2006-12-11 23:38           ` Andrea Arcangeli [this message]
2006-11-29  3:00 ` [PATCH 5/5][time][x86_64] Re-enable vsyscall support for x86_64 john stultz

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=20061211233800.GP5363@opteron.random \
    --to=andrea@suse.de \
    --cc=ak@suse.de \
    --cc=dean@arctic.org \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=ssouhlal@FreeBSD.org \
    --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