tueidj wrote:It looks like __libogc_gettod_r() in timesupp.c should be using tick_to_microsecs() instead of tick_microsecs().
The function to be used in __libogc_gettod_r should be tick_microsecs() since tv_usec indicates the number of nanoseconds expired in the current second whilst ticks_to_microsecs() reports the total number of microsecs.
Anyhow there are two considerations:
1) The tick_microsecs() as well tick_nanosecs() macros of libogc are wrong:
In lwp_watchdog.h they are defined as
#define tick_microsecs(ticks) ((((u64)(ticks)*8)%(u64)(TB_TIMER_CLOCK/125)))
#define tick_nanosecs(ticks) ((((u64)(ticks)*8000)%(u64)(TB_TIMER_CLOCK/125)))
TB_TIMER_CLOCK/125 is 486. It means that the gives the rest of 486 that's wrong.
The correct functions should be:
#define tick_microsecs(ticks) ((((u64)(ticks)*8)/(u64)(TB_TIMER_CLOCK/125))%1000000)
#define tick_nanosecs(ticks) ((((u64)(ticks)*8000)/(u64)(TB_TIMER_CLOCK/125))%1000000000)
2) Also the use of tick_nanosecs() is not appropriate for __libogc_gettod_r. Indeed gettimeoftheday() should return the number of seconds since 00:00 hours, Jan 1, 1970 UTC whilst ticks functions represent the time elapsed from the WII switch on.
In timesupp.c there is another bug. The function clock_gettime() define tv_nsec as ticks_to_nanosecs(gettick()).
It would be more appropriate to use:
tp->tv_nsec = tick_nanosecs(gettick());
as in __libogc_gettod_r with the considerations made above for gettimeofday.