Unix Technical Forum

Modifying time_base_to_time?

This is a discussion on Modifying time_base_to_time? within the AIX Operating System forums, part of the Unix Operating Systems category; --> As many of you will know, reading the realtime clock on AIX is a two-stage process. Read the clock ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2008, 08:48 PM
Andy Platt
 
Posts: n/a
Default Modifying time_base_to_time?

As many of you will know, reading the realtime clock on AIX is a two-stage
process. Read the clock which will perform a processor-dependent register
read (read_real_time) and then convert it to real time which will either be
a no-op or will use the Xint and Xfrac constants (time_base_to_time).

We would like to move the conversion offline for performance reasons.
However, our offline "formatting" can occur on a different machine from the
original one which means Xint and Xfrac may be different. So we can't just
use time_base_to_time directly.

One thought was to call time_base_to_time for a specific time on both
machines and calculate a conversion factor. Unfortunately we lose precision
when we do that, though we haven't really investigated that approach fully.
Another thought was to change the Xint/Xfrac values before making the call
and change them back afterwards but, as expected, they are in read-only
memory.

The ideal would be to have a local version of the time_base_to_time routine
that uses our own values. google shows some discussion on this but the
algorithm suggested doesn't give the same results - and doesn't seem to
match what the time_base_to_time routine does when stepping through it.

Has anyone else tried to do this successfully or have any other ideas?

Andy.

--
I'm not really here - it's just your warped imagination.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-04-2008, 08:48 PM
Andy Platt
 
Posts: n/a
Default Re: Modifying time_base_to_time?

"Andy Platt" <ajp@turnip.his.com> wrote in message
news:3faf8c97$1@news101.his.com...
> As many of you will know, reading the realtime clock on AIX is a two-stage
> process. Read the clock which will perform a processor-dependent register
> read (read_real_time) and then convert it to real time which will either

be
> a no-op or will use the Xint and Xfrac constants (time_base_to_time).
>
> We would like to move the conversion offline for performance reasons.
> However, our offline "formatting" can occur on a different machine from

the
> original one which means Xint and Xfrac may be different. So we can't just
> use time_base_to_time directly.


We figured it out. For posterity, in case anyone else needs this, the
algorithm we used was this:

1. Take the 64 bit value from the timebasestruct_t (e.g. combine tb_high and
tb_low) into an unsigned long long.

2. Divide this by your local Xfrac and keep the quotient and the remainder.

3. Multiply both the quotient and the remainder by your local Xint.

4. Divide the resulting remainder by Xfrac again and add to the new quotient
value. You now have an unsigned long long giving the calculated time in
nanoseconds.

5. Divide by 1000000000 to get seconds, the remainder is the nanoseconds.


Doing the division first and using the remainder was necessary because
multiplying the entire 64 bit value by Xint up-front could overflow.

Andy.

--
I'm not really here - it's just your warped imagination.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:49 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com