On 02/07/2011 08:57 AM, Jan Kiszka wrote:
There should rather be a special vmstate struct for PeriodicTimer, just
like we already have for normal timers.
Agreed.
It's convenient because then if we lose ticks in the PeriodicTimer
layer, the devices have instance access to that info. When you do a
read() from timerfd, it returns the number of coalesced events. That's
the interface I had in my mind.
We could just add a getter for PeriodicTimer and it would serve the same
purpose.
I'm still not sure what the device model is supposed to do with that
information. I think at could remain private to the PeriodicTimer
implementation (unless we want to dump some stats or such).
Yeah, I've been thinking about it too and I think I agree with you.
So here's the new proposal:
typedef struct PeriodicTimer PeriodicTimer;
/**
* @accumulated_ticks: the number of unacknowledged ticks in total
since the creation of the timer
**/
typedef void (PeriodicTimerFunc)(void *opaque);
PeriodicTimer *periodic_timer_new(PeriodicTimerFunc *cb, void *opaque);
void periodic_timer_mod(PeriodicTimer *timer, int64_t interval, TimeUnit
unit);
/**
* @policy: the drift catch-up policy
* DRIFT_COMP_FAST, deliver next tick as soon as any
tick is acknowledged if accumulated_ticks > 1
* DRIFT_COMP_NONE, do not change interval regardless of
accumulated ticks
* DRIFT_COMP_GRADUAL, shorten interval by half until
accumulated_ticks <= 1
*/
void periodic_timer_set_policy(PeriodicTimer *timer,
DriftCompensationPolicy policy);
/**
* @ticks: number of ticks to acknowledge that are currently outstanding.
**/
void periodic_timer_ack(PeriodicTimer *timer, int ticks);
int periodic_timer_get_accumulated_ticks(PeriodicTimer *timer);
Regards,
Anthony Liguori
Jan