If you don't want this slack, you can set t.slack = 0 when you are initializing the timer in timer_init. So there you have it, since slack is automatically set to -1, the apply_slack function is changing your expires time to align with, I guess, the timer ticks. The rest really depends on the value of expires, but for sure, it gets changed. ![]() This in turn implies that mask (which is expires ^ expires_limit) is not zero. Therefore, the delta in the function (with your data) is most likely about 4 and delta / 4 is non zero. In that part the difference between expires and jiffies is slightly less than HZ (you just did t.expires = jiffies HZ. If (delta slack >= 0 fails, so the else part is applied. Unsigned long apply_slack(struct timer_list *timer, unsigned long expires) With this knowledge, let's reduce apply_slack and see what remains of it: static inline The init_timer macro eventually calls do_init_timer which sets the slack by default to -1. * 4) use the bitmask to round down the maximum time, so that all lastīefore continuing, let's see what is the timer's slack. * 2) calculate the highest bit where the expires and new max are different * 1) calculate the maximum (absolute) time * Decide where to put the timer while taking the slack into account The mod_timer function calls: expires = apply_slack(timer, expires) Īnd then goes on to actually modify the timer. The add_timer function calls: mod_timer(timer, timer->expires) Printk("Expired timer %lu %lu\n", pre, post) ![]() Static void timer_func(unsigned long data) ![]() Each couple of numbers is the value of the expires field just before and after the call: Init timer 1000 Why is this drift added? Is there a clean way to prevent it? I am not trying to get an accurate millisecond precision, I have a vague understanding of the kernel real-time limitations, but at least to avoid this intentional delay at each call. After some investigations, I found that this is the add_timer() call which adds an offset of 2 to the expires field (~2ms in my case). I am trying to setup a periodic timer triggering a function every seconds, but there is a small drift between each call.
0 Comments
Leave a Reply. |