Re: [PATCH 1/2] tracing/function-return-tracer: Make the function return tracer lockless



2008/11/13 Ingo Molnar <mingo@xxxxxxx>:
you are right - it needs a bit more logic.

I think the simplest would be something like this:

atomic64_t global_clock = INIT_ATOMIC64(0);

u64 global_time()
{
u64 now, delta, now_global, prev_global;

do {
prev_global = atomic64_read(&global_clock);
now = cpu_clock(raw_smp_processor_id());

if ((s64)(now - prev_global) < 0) {
now = prev_global;
break;
}
} while (atomic64_cmpxchg(&global_clock,
prev_global, now) != prev_global);

return now;
}

This is the simplest way of implementing monotonic time: we only allow
global_clock to go forwards. If all cpu_clock()s are perfectly in
sync, we've got no problem: then "now - prev_global" will never be
negative and we can return the local clock as the latest global time.

But if one of the CPU clocks is "behind", the function returns the
latest global time up until the local clock catches up. Time wont be
allowed to jump around by going back. If the clock is behind for a
long time, then we get a lot of timestamps with the same value -


Ok! I understand now this approach.
So, if global ordering flag is set, we return this kind of protected value,
and on the opposite, we return the normal cpu_clock() local value.

Would that work? [ Would you be interested in sending patches? :-) ]

Yes :-)

that
will be very visible in the trace and we'll then work in improving the
cpu_clock() implementation.

So i think we could start with this simplest approach, and see how
often we get the same timestamp for a long time (indication of the
clocks being not perfectly in sync).


Ok, good idea.
Thanks for the explanations!
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: VolanoMark regression with 2.6.27-rc1
    ... extern void sched_clock_init; ... static inline u64 global_rt_runtime ... * Scheduler clock - returns current time in nanosec units. ... * The dynamic ticks makes the delta jiffies inaccurate. ...
    (Linux-Kernel)
  • Re: Embedded clocks
    ... scheme I know of is just async serial data with a start and a stop bit. ... This is not quite the simplest. ... Transmit has to generate it's own clock. ... I don't see one wire as being any simpler than a UART. ...
    (comp.arch.fpga)
  • [git pull] scheduler fixes for -rc3
    ... cpu hotplug: fix set_cpus_alloweduse in hotplug callbacks ... sched clock: revert various sched_clockchanges ... -static inline u64 sched_clock_cpu ...
    (Linux-Kernel)
  • Re: [PATCH 1/2] tracing/function-return-tracer: Make the function return tracer lockless
    ... without the cmpxchg): ... u64 prev_global_time; ... u64 now, delta, now_global; ... negative and we can return the local clock as the latest global time. ...
    (Linux-Kernel)
  • Re: Whats taters?
    ... >> You realize, Hal, that the number of adapter thingies we have in ... (The simplest way to make an accurate electric or electronic clock ... All those things, plus others, have internal power supplies, in the ...
    (rec.arts.sf.composition)