Subject: Re: [linux-audio-dev] MCS: 64 bit timestamps? [simplified]
From: Roger Larsson (roger.larsson_AT_skelleftea.mail.telia.com)
Date: ma loka 11 1999 - 21:19:18 EDT
Hmm...
There are some problems here, I think.
Paul Barton-Davis wrote:
>
> >> another word about timestamps though. you suggested that in order to
> >> call engine->timestamp(), a sensor thread would have to preempt the
> > ^^^^^^^^^^^^^^^^^^^
> >What does this function do, exactly?
>
> msc_time_t
> Engine::timestamp ()
>
> {
> /* greatly un-inlined to make function clear ... */
>
> tsc_t current_cycle_counter;
> tsc_t cycle_diff;
> msc_time_t now;
>
> current_cycle_counter = read_tsc ();
> cycle_diff = current_cycle_counter -
> cycle_counter_at_start_of_control_loop;
What happens when the cycle_diff starts to wrap :-)
Ok, we have 2^64 bits, but wery soon we have 2^32 cycles/s CPUs.
1 GHz next year, and increasing rapidly (typing on a 180 MHz PPro
3 years old, assume 10 GHz in another 3 years, ...)
Why subtract the 'cycle_counter_at_start_of_control_loop' anyway?
> now = (msc_time_t) (samples_per_cycle * (float) cycle_diff));
What 'samples_per_cycle' the requesting plugins, or a master, or ...
Do we really like to have float calculations here? At least we should
make it double to handle the 64 bit cycle_diff.
Suggestion:
Treat the tsc as a sample-driven-unit by itself (started at cycle 0),
but scale it to wrap in a week or so... for debug purposes
SCALE should be a power of 2, 1 is ok!
#define SCALE 1
msc_time_t
Engine::timestamp ()
{
/* greatly un-inlined to make function clear ... */
return read_tsc() / SCALE;
}
msc_time_t
Engine::convert (double secs)
{
return secs * (read_cycles_per_second_tsc() / SCALE);
}
msc_time_t
Plugin::convert (unsigned sample)
{
return Engine::convert( sample / this->samples_per_second ) -
this->start_timestamp;
}
Plugin::init (...)
{
this->start_timestamp = Engine::timestamp();
}
#undef SCALE
Note: this is not SMP safe if people uses processors with
different speeds... some are...
And I think there have been some issues with unsynchronised
cycle counters...
/RogerL
--The Internet interprets Windows as damage, and routes around it.
Roger Larsson Skellefteċ Sweden
This archive was generated by hypermail 2b28 : pe maalis 10 2000 - 07:27:13 EST