From: Martin Z. <co...@mz...> - 2010-02-07 14:09:36
|
Hi Michael, you're still a little hesitant (and I can understand that), but I'll get you in the end. :) Thanks -- I have finally understood where all the one-shot timers come from. I never had the time to more than glance at the widget code. But couldn't the "dynamic value update" (which is great and I want to keep as well!) somehow be done during the update callback function? Anyway, yesterday I *did* write some code to sync all timers. What it does is (again) easy but works quite well. When the first timer is started, a global timeval called "timer_sync_base" is set to the current date and time by gettimeofday(). After that, this global value is never touched again. Now, when a new timer is added, my code calculates the number of updates that have happened since "timer_sync_base" and also the time difference that corresponds to this number of updates. This time difference is then added to "timer_sync_base", and finally the timer's "update" value is set to the result. I think, an example is in order (to keep it easy, update interval is one second): 1265490677.167110 first timer is added "timer_sync_base" is set to 1265490677.167110 timer variable "update" is set to 1265490677.167110 1265490678.171091 first timer triggers (initialisation; this is your "old" code) 1265490678.167110 first timer triggers (one second since timer base) 1265490678.671346 second timer is added code calculates that one update has already passed timer variable "update" is set to 1265490678.167110 (one second after "timer_sync_base") 1265490678.698234 second timer triggers (intialisation; this again is your "old" code) 1265490679.167110 first timer triggers (two seconds since timer base) 1265490679.167110 second timer triggers (two seconds since timer base) I have found some easy mathematics to calculate the number of passed updates, so this does not interfere with performance. The code works, but it needs cleaning up and commenting. Right now, I'm probably the only one who'd understand it. ;) > I'm afraid I did miss that patch you are mentioning... wasn't it that "timer_group" stuff? Isn't it necessary to replace > the timer_add() call in the widget code? Yes, that's the one I meant. While you don't exactly need this grouping of timers, it *does* reduce overhead by creating only one timer per group, and this group timer is even continuous. The timer_add() call in the widget code would have to be changed to timer_add_widget(), of course, but the widgets do keep their one-shot timers. So as I said, the widget code wouldn't have to change at all, but we'd get rid of all the one-shot-timer overhead. As a side effect, the groups also ensure that all widgets in a group are updated simultaneously. This effect could also be used for LCDs that only write to a framebuffer and are then updated as a whole, because you could implement a function called update_all() that would be called after all widgets within a group have been updated. This function would have to be in all drivers and would usually be empty. But in drivers that update the whole display, this function would then write the frame buffer to the LCD, getting rid of the timer that is currently needed to regularly copy the frame buffer to the display. You see, I have put some thought into all this, because my LCD is *really* slow when it is updated... :) Given all these advantages, I have finally committed my patch for grouping widgets. I don't know if I've got the copyrights correct -- please feel free to correct them. > but: if there is no more timeshift, how can widgets get unsync? Yes, you're right (if there is no initial delay, but as I say, I'm on my way to fixing this). I think there might be problems with the overhead of creating all those one-shot timers, but I'm in no way able to describe them. Let's say, they are similar to a foreboding... ;) > please, please, don't get me wrong: I in no way dislike your patch. I just want to solve it for *all* timers, not only > widget updates. I didn't get you wrong at all. I know what you're driving at, and I think we're on our way to solve the problem. :) Greetings from snowy Hamburg, Martin -- www.mzuther.de www.radix-musik.de |