timer synchronisation across processes

Is there a way to synch timers across processes?
An app consists of a GUI + 4 drivers. Each driver
must talk to its hardware in it’s unique 20ms interval,
over a 80 ms cycle. The drivers are identical
except for a node id.

The following code snippet doesn’t quite work
(using the Pentium’s built-in cycle counter as
a way of determining a unique 20ms slot).
This code is executed by each individual driver
process. The GUI launches the drivers at startup
(up to 4) 200ms apart.

#define MILLISECONDS 999847L
#define DELTA 80
timer.it_value.tv_sec = 0;
timer.it_value.tv_nsec = 0;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_nsec = 0;
timer_settime( timer_id, 0, &timer, NULL );

/*Syncronise to the internal CPU clock, to a 80ms cycle and

  • then to a 20ms cycle in the 80ms based on the node id
  • This is to synchronise multiples
    /
    timer.it_value.tv_sec = 0;
    timer.it_value.tv_nsec = DELTA
    MILLISECONDS;
    timer.it_interval.tv_sec = 0;
    timer.it_interval.tv_nsec = DELTA*MILLISECONDS;
    calibrate_rdtsc();
    time32 = rdtsc32() % cycles_per_100_msec;
    /*Wait for timer under 1 ms in a 100ms cycle first */
    while (time32 > cycles_per_20_msec/20) {
    time32 = rdtsc32() % cycles_per_100_msec;
    }
    /*here if cycle is at the start of a 100 ms cycle */
    /now wait until the multiple of 20ms occurs /
    while ((time32 <= (cycles_per_20_msec
    node_id - cycles_per_20_msec/20))
    ||
    (time32 >= (cycles_per_20_msec
    node_id
  • cycles_per_20_msec/20))) {
    time32 = rdtsc32() % cycles_per_100_msec;
    }
    timer_settime( timer_id, 0, &timer, NULL );

Another approach would be to use a process just to do
the synchronisation and use a Trigger to synch the
other processes. Just wondering if there was a way
to do it by using the timers…

\

Using Opera’s revolutionary e-mail client: http://www.opera.com/m2/

On Wed, 20 Jul 2005 17:09:55 +0400, Alex/Systems 104
<acellarius@yah0o.lsd.com> wrote:

Is there a way to synch timers across processes?
How do you handle the (inevitable) XTALL frequency difference between the

nodes? Even if you could get the proper syncronizm - it WILL drift apart
soon…

Tony.

“Alex/Systems 104” <acellarius@yah0o.lsd.com> wrote in message
news:op.st7qutojbinb6v@alex-pentium-m…

Is there a way to synch timers across processes?
An app consists of a GUI + 4 drivers. Each driver
must talk to its hardware in it’s unique 20ms interval,
over a 80 ms cycle. The drivers are identical
except for a node id.

I`m confuse, you asking “across processes” but then you mention “node id”.
Are processes on the same node or on different nodes.

If they are on the same node you could try using TIMER_ABS (an absolute
time) to get the the first firing to occurs at a specific time (using the
node id to create the time) then the interval would take care of the rest.

If you are on different node, I doubt that`s possible.

The following code snippet doesn’t quite work
(using the Pentium’s built-in cycle counter as
a way of determining a unique 20ms slot).
This code is executed by each individual driver
process. The GUI launches the drivers at startup
(up to 4) 200ms apart.

#define MILLISECONDS 999847L
#define DELTA 80
timer.it_value.tv_sec = 0;
timer.it_value.tv_nsec = 0;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_nsec = 0;
timer_settime( timer_id, 0, &timer, NULL );

/*Syncronise to the internal CPU clock, to a 80ms cycle and

  • then to a 20ms cycle in the 80ms based on the node id
  • This is to synchronise multiples
    /
    timer.it_value.tv_sec = 0;
    timer.it_value.tv_nsec = DELTA
    MILLISECONDS;
    timer.it_interval.tv_sec = 0;
    timer.it_interval.tv_nsec = DELTA*MILLISECONDS;
    calibrate_rdtsc();
    time32 = rdtsc32() % cycles_per_100_msec;
    /*Wait for timer under 1 ms in a 100ms cycle first */
    while (time32 > cycles_per_20_msec/20) {
    time32 = rdtsc32() % cycles_per_100_msec;
    }
    /*here if cycle is at the start of a 100 ms cycle */
    /now wait until the multiple of 20ms occurs /
    while ((time32 <= (cycles_per_20_msec
    node_id - cycles_per_20_msec/20))
    ||
    (time32 >= (cycles_per_20_msec
    node_id +
    cycles_per_20_msec/20))) {
    time32 = rdtsc32() % cycles_per_100_msec;
    }
    timer_settime( timer_id, 0, &timer, NULL );

Another approach would be to use a process just to do
the synchronisation and use a Trigger to synch the
other processes. Just wondering if there was a way
to do it by using the timers…

\

Using Opera’s revolutionary e-mail client: > http://www.opera.com/m2/

On Wed, 20 Jul 2005 15:25:52 +0200, Tony <mts.spb.suxx@mail.ru> wrote:

On Wed, 20 Jul 2005 17:09:55 +0400, Alex/Systems 104
acellarius@yah0o.lsd.com> > wrote:
Is there a way to synch timers across processes?
How do you handle the (inevitable) XTALL frequency difference between
the nodes? Even if you could get the proper syncronizm - it WILL drift
apart soon…

Sorry about the confusing nomenclature.
The application runs on a single x86 processor,
using a customer Arcnet driver. Hence
the node id, but that has nothing to do with
native networking node id’s…

On Wed, 20 Jul 2005 16:05:38 +0200, Mario Charest postmaster@127.0.0.1
wrote:

“Alex/Systems 104” <> acellarius@yah0o.lsd.com> > wrote in message
news:op.st7qutojbinb6v@alex-pentium-m…
Is there a way to synch timers across processes?
An app consists of a GUI + 4 drivers. Each driver
must talk to its hardware in it’s unique 20ms interval,
over a 80 ms cycle. The drivers are identical
except for a node id.

I`m confuse, you asking “across processes” but then you mention “node
id”.
Are processes on the same node or on different nodes.

Sorry about the confusing nomenclature.
See other post for correction.

If they are on the same node you could try using TIMER_ABS (an absolute
time) to get the the first firing to occurs at a specific time (using the
node id to create the time) then the interval would take care of the
rest.

If you are on different node, I doubt that`s possible.

All one node.
Thanks Mario, good idea.
Abs time say at the next second.
1st when the timer occurs, relative timer at
the desired interval, with a unique 20ms multiple
offset…