Re: [RFC PATCH 1/3] Unified trace buffer
From: Jeremy Fitzhardinge
Date: Thu Sep 25 2008 - 22:07:31 EST
Steven Rostedt wrote:
> OK, let me rephrase my question.
>
> How and where do we record this? Do we keep this information in some
> global variable that we must compare to every time we add a new item in
> the trace?
>
> Do we have the buffer register a call back to record this information?
>
Something like (total pseudocode):
struct tsc_time_parameters {
int version; /* even - values OK; odd - values being updated */
u64 tsc;
u32 tsc_freq;
u64 gtod;
};
DEFINE_PERCPU(struct tsc_time_parameters, tsc_params);
/* To be called after a tsc frequency change, before any new
trace records are being emitted, in a context where we can call get_GTOD() */
void update_tsc_params(void)
{
struct tsc_time_parameters *p = __get_percpu_var(tsc_params);
p->version |= 1;
wmb();
p->tsc = get_tsc();
p->tsc_freq = get_tsc_freq();
p->gtod = get_GTOD();
wmb();
p->version++;
wmb();
}
DEFINE_PERCPU(unsigned, current_tsc_version);
DEFINE_PERCPU(u64, prev_tsc);
/* may be called in any context */
u64 get_trace_timestamp_delta(void)
{
const struct tsc_time_parameters *p = &__get_percpu_var(tsc_params);
unsigned *current_version = &__get_cpu_var(current_tsc_version);
u64 prev = __get_cpu_var(prev_tsc);
u64 now, ret;
/* check the current tsc_params version against the last one we emitted;
if the version is odd, then we interrupted the parameters as they were
being updated, so just emit a new delta with the old parameters */
if (unlikely(*current_version != p->version && !(p->version & 1))) {
/* XXX probably need a loop to deal with p->version changing under our feet */
emit_tsc_freq_record(p);
prev = p->tsc;
__get_cpu_var(current_tsc_version) = p->version;
}
now = read_tsc();
ret = now - prev;
__get_cpu_var(prev_tsc) = now;
return ret;
}
J
--
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/