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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |
| ||||
| "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. |