def clear_time_state(self): """ clear_time_state Clears the time state so that the clock can be adjusted manually again. return: None """ adjtimex.adjtimex( adjtimex.Timex(modes=adjtimex.ADJ_STATUS, status=adjtimex.STA_PLL)) adjtimex.adjtimex(adjtimex.Timex(modes=adjtimex.ADJ_STATUS))
def get_speed(self): """ get_speed Gets the current system clock speed. Can be used to provide to set_speed after a reboot. return: Speed of system clock, close to 1.0. """ timeadj = adjtimex.Timex(modes=0) adjtimex.adjtimex(timeadj) speed = float(timeadj.tick) / 10000 + float(timeadj.freq) / SEC_TO_FREQ return speed
def set_offset(self, offset=0.0): """ set_offset Passes the offset to the kernel, making the actual time PLL work. @param offset: Time offset in (actual_time - system_time), as passed to the kernel return: None """ offset_us = int(offset * 1000000) timeadj = adjtimex.Timex(modes=adjtimex.ADJ_OFFSET | adjtimex.ADJ_STATUS | adjtimex.ADJ_MICRO | adjtimex.ADJ_MAXERROR, offset=offset_us, maxerror=abs(offset_us), status=adjtimex.STA_PLL) adjtimex.adjtimex(timeadj)
def set_speed(self, factor=1.0): """ set_speed Sets the system frequency, obtained using get_speed. @param factor : Speed of system clock, should be close to 1.0 return: None """ # Tick is always positive, we can round by adding 0.5 tick = int(factor * 10000 + 0.5) remainder = factor - (tick / 10000.0) freq = int(round(remainder * SEC_TO_FREQ)) timeadj = adjtimex.Timex(modes=adjtimex.ADJ_FREQUENCY | adjtimex.ADJ_TICK | adjtimex.ADJ_STATUS, freq=freq, tick=tick, status=adjtimex.STA_PLL) adjtimex.adjtimex(timeadj)
def timestep(self, seconds=0.0): """ timestep Makes a timestep using the provided seconds. Time will be added to the system time so a positive value will make the clock go forward. @param seconds: Number of seconds to adjust the system clock return: None """ microseconds = int(round(seconds * 1000000)) seconds_int = int(microseconds // 1000000) usec = int(microseconds - (seconds_int * 1000000)) timeval = adjtimex.Timeval(seconds_int, usec) timeadj = adjtimex.Timex(modes=adjtimex.ADJ_SETOFFSET | adjtimex.ADJ_MICRO, time=timeval) adjtimex.adjtimex(timeadj)