From: Jiri Bohac <jbohac@suse.cz>
To: Andi Kleen <ak@suse.de>
Cc: jbohac@suse.cz, linux-kernel@vger.kernel.org,
Vojtech Pavlik <vojtech@suse.cz>,
ssouhlal@freebsd.org, arjan@infradead.org, tglx@linutronix.de,
johnstul@us.ibm.com, zippel@linux-m68k.org, andrea@suse.de
Subject: Re: [patch 9/9] Make use of the Master Timer
Date: Thu, 1 Feb 2007 15:29:31 +0100 [thread overview]
Message-ID: <20070201142927.GR21755@dwarf.suse.cz> (raw)
In-Reply-To: <200702011236.05429.ak@suse.de>
On Thu, Feb 01, 2007 at 12:36:05PM +0100, Andi Kleen wrote:
> On Thursday 01 February 2007 11:00, jbohac@suse.cz wrote:
>
> > + case VXTIME_TSC:
> > + rdtscll(tsc);
>
> Where is the CPU synchronization?
>
> > + cpu = smp_processor_id();
> > + rdtscll(t);
>
> Also no synchronization. It's slower, but needed.
Hmm, I wasn't sure. Why is it needed? How outdated can the
result of RDTSC / RDTSCP be?
If I do:
rdtscll(a)
...
rdtscll(b)
is it guaranteed that (b > a) ?
>
> > unsigned long long sched_clock(void)
> > {
> > - unsigned long a = 0;
> > -
> > - rdtscll(a);
> > - return cycles_2_ns(a);
> > + return monotonic_clock();
> > }
>
> This is overkill because sched_clock() doesn't need a globally monotonic
> clock, per CPU monotonic is enough. The old version was fine.
OK, thanks for spotting this. I'll change it to use __guess_mt().
(more or less equal to cycles_2_ns(), no need to maintain yet another
tsc->ns ratio just for cycles_2_ns().
> > +static __always_inline void do_vgettimeofday(struct timeval * tv, u64 tsc, int cpu)
> > +{
> > + unsigned int sec;
> > + s64 nsec;
> >
> > - do {
> > - sequence = read_seqbegin(&__xtime_lock);
> > -
> > - sec = __xtime.tv_sec;
> > - usec = __xtime.tv_nsec / 1000;
> > -
> > - usec += ((readl((void __iomem *)
> > - fix_to_virt(VSYSCALL_HPET) + 0xf0) -
> > - __vxtime.last) * __vxtime.quot) >> 32;
> > - } while (read_seqretry(&__xtime_lock, sequence));
> > + sec = __xtime.tv_sec;
> > + nsec = __xtime.tv_nsec;
> > + nsec += max(__do_gettimeoffset(tsc, cpu), __vxtime.drift);
> >
> > - tv->tv_sec = sec + usec / 1000000;
> > - tv->tv_usec = usec % 1000000;
> > + sec += nsec / NSEC_PER_SEC;
> > + nsec %= NSEC_PER_SEC;
>
> Using while() here is probably faster (done in vdso patchkit where
> gtod got mysteriously faster). Modulo and divisions are slow, even
> for constants when they are large.
OK, will do that
>
> > }
> >
> > /* RED-PEN may want to readd seq locking, but then the variable should be write-once. */
> > @@ -107,10 +118,39 @@ static __always_inline long time_syscall
> >
> > int __vsyscall(0) vgettimeofday(struct timeval * tv, struct timezone * tz)
> > {
> > - if (!__sysctl_vsyscall)
> > + int cpu = 0;
> > + u64 tsc;
> > + unsigned long seq;
> > + int do_syscall = !__sysctl_vsyscall;
> > +
> > + if (tv && !do_syscall)
> > + switch (__vxtime.mode) {
> > + case VXTIME_TSC:
> > + case VXTIME_TSCP:
> > + do {
> > + seq = read_seqbegin(&__xtime_lock);
> > +
> > + if (__vxtime.mode == VXTIME_TSC)
> > + rdtscll(tsc);
> > + else {
> > + rdtscpll(tsc, cpu);
> > + cpu &= 0xfff;
> > + }
> > +
> > + if (unlikely(__vxtime.cpu[cpu].tsc_invalid))
> > + do_syscall = 1;
> > + else
> > + do_vgettimeofday(tv, tsc, cpu);
> > +
> > + } while (read_seqretry(&__xtime_lock, seq));
> > + break;
> > + default:
> > + do_syscall = 1;
>
> Why do you not set __sysctl_vsyscall correctly for the mode at initialization?
Because of the __vxtime.cpu[cpu].tsc_invalid flag. We may be
using the vsyscall, but when we get the cpufreq PRE- notification, we
know that TSC cannot be trusted from that point on, until the
frequency stabilises. We set the flag and until TSC becomes
reliable again, vsyscall w/ HW Master Timer read will be used.
So this is something that changes in runtime, and cannot be set
permanently on initialization...
--
Jiri Bohac <jbohac@suse.cz>
SUSE Labs, SUSE CZ
next prev parent reply other threads:[~2007-02-01 14:26 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-01 9:59 [patch 0/9] x86_64: reliable TSC-based gettimeofday jbohac
2007-02-01 9:59 ` [patch 1/9] Fix HPET init race jbohac
2007-02-02 2:34 ` Andrew Morton
2007-02-06 16:44 ` Jiri Bohac
2007-02-07 0:12 ` Andrew Morton
2007-02-10 12:31 ` Andi Kleen
2007-07-26 20:58 ` Robin Holt
2007-02-01 9:59 ` [patch 2/9] Remove the support for the VXTIME_PMTMR timer mode jbohac
2007-02-01 11:13 ` Andi Kleen
2007-02-01 13:13 ` Jiri Bohac
2007-02-01 13:13 ` Andi Kleen
2007-02-01 13:59 ` Jiri Bohac
2007-02-01 14:18 ` Andi Kleen
2007-02-01 9:59 ` [patch 3/9] Remove the support for the VXTIME_HPET " jbohac
2007-02-01 9:59 ` [patch 4/9] Remove the TSC synchronization on SMP machines jbohac
2007-02-01 11:14 ` Andi Kleen
2007-02-01 13:17 ` Jiri Bohac
2007-02-01 15:16 ` Vojtech Pavlik
2007-02-02 7:14 ` Andi Kleen
2007-02-13 0:34 ` Christoph Lameter
2007-02-13 6:40 ` Arjan van de Ven
2007-02-13 8:28 ` Andi Kleen
2007-02-13 8:41 ` Arjan van de Ven
2007-02-13 17:09 ` Christoph Lameter
2007-02-13 17:20 ` Andi Kleen
2007-02-13 22:18 ` Vojtech Pavlik
2007-02-13 22:38 ` Andrea Arcangeli
2007-02-14 6:59 ` Vojtech Pavlik
2007-02-13 23:55 ` Christoph Lameter
2007-02-14 0:18 ` Paul Mackerras
2007-02-14 0:25 ` john stultz
2007-02-02 7:13 ` Andi Kleen
2007-02-01 21:05 ` mbligh
2007-02-03 1:16 ` H. Peter Anvin
2007-02-01 9:59 ` [patch 5/9] Add all the necessary structures to the vsyscall page jbohac
2007-02-01 11:17 ` Andi Kleen
2007-02-01 9:59 ` [patch 6/9] Add the "Master Timer" jbohac
2007-02-01 11:22 ` Andi Kleen
2007-02-01 13:29 ` Jiri Bohac
2007-02-01 9:59 ` [patch 7/9] Adapt the time initialization code jbohac
2007-02-01 11:26 ` Andi Kleen
2007-02-01 13:41 ` Jiri Bohac
2007-02-01 10:00 ` [patch 8/9] Add time_update_mt_guess() jbohac
2007-02-01 11:28 ` Andi Kleen
2007-02-01 13:54 ` Jiri Bohac
2007-02-01 10:00 ` [patch 9/9] Make use of the Master Timer jbohac
2007-02-01 11:36 ` Andi Kleen
2007-02-01 14:29 ` Jiri Bohac [this message]
2007-02-01 15:23 ` Vojtech Pavlik
2007-02-02 7:05 ` Andi Kleen
2007-02-02 7:04 ` Andi Kleen
2007-02-01 11:20 ` [patch 0/9] x86_64: reliable TSC-based gettimeofday Andi Kleen
2007-02-01 11:53 ` Andrea Arcangeli
2007-02-01 12:02 ` Andi Kleen
2007-02-01 12:54 ` Andrea Arcangeli
2007-02-01 12:17 ` Ingo Molnar
2007-02-01 14:52 ` Jiri Bohac
2007-02-01 16:56 ` john stultz
2007-02-01 19:41 ` Vojtech Pavlik
2007-02-01 11:34 ` Ingo Molnar
2007-02-01 11:46 ` [-mm patch] x86_64 GTOD: offer scalable vgettimeofday Ingo Molnar
2007-02-01 12:01 ` Andi Kleen
2007-02-01 12:14 ` Ingo Molnar
2007-02-01 12:17 ` [-mm patch] x86_64 GTOD: offer scalable vgettimeofday II Andi Kleen
2007-02-01 12:24 ` Ingo Molnar
2007-02-01 12:45 ` Andi Kleen
2007-02-02 4:22 ` [patch 0/9] x86_64: reliable TSC-based gettimeofday Andrew Morton
2007-02-02 7:07 ` Andi Kleen
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=20070201142927.GR21755@dwarf.suse.cz \
--to=jbohac@suse.cz \
--cc=ak@suse.de \
--cc=andrea@suse.de \
--cc=arjan@infradead.org \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ssouhlal@freebsd.org \
--cc=tglx@linutronix.de \
--cc=vojtech@suse.cz \
--cc=zippel@linux-m68k.org \
/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
all inboxes | Powered by JetHome®