POSIX clocks & timers take 15 (NOT HIGH RES)
PATCH 1/1 POSIX clocks & timers take 15 (NOT HIGH RES)
Have a nice turkey day :)
This patch has no configure options!
With this version I have changed the signal/ repeating timer model to avoid timer storms from repeating timers. The timer is not inserted back into the timer_list until the signal is dequeued by the receiving task. So, once a timer expires, it will cause NO further system overhead until the task takes the signal, regardless of the repeat interval. The POSIX standard allows this, (actually it seems to encourage it). Each timer has an "overrun" counter that keeps track of the number of times the signal should have been generated but was not because the prior signal was not yet picked up.
The timer_gettime() call returns the time as if the timer were in the timer_list so to the program it looks like it is, but the system overhead is nil.
The really nice thing about this way of limiting timer storms is that a really fast real time program can actually get the high turn over rate while not being impacted by slower, or blocked programs trying to do the same thing. Like wise, if a program loses the cpu, its timers will not impact other tasks. Many thanks to Mark Salisbury <[email protected]> for suggesting this.
The patch stands alone (i.e. does not require any of the following high-res patches).
This, patch implements the POSIX clocks and timers functions. The two standard clocks are defined(CLOCK_REALTIME & CLOCK_MONOTONIC).
Nano_sleep() is rolled into clock_nanosleep(). Also a bug fix in clock_nanosleep().
kernel/timer.c is modified to remove the timer_t typedef which conflicts with the POSIX standard definition for this type.
The patch introduces a new kernel source (posix-timers.c) which contains most of the code.
This implementation has no limits on the number of timers in the system or per process or task, thanks to Jim Houston.
Kernel version 2.5.50
Test programs, man pages and readme files as well as this patch are available on the sourceforge high-res-timers site:
http://sourceforge.net/projects/high-res-timers/
Please apply.
Signature · 5 lines
George Anzinger [email protected] High-res-timers: http://sourceforge.net/projects/high-res-timers/ Preemption patch: http://www.kernel.org/pub/linux/kernel/people/rml
include/linux/posix-timers.h +33 -0
@@ -15,6 +15,38 @@void ( *timer_get)(struct k_itimer *timr,struct itimerspec *cur_setting); }; + +#ifdef CONFIG_HIGH_RES_TIMERS +struct now_struct { +unsigned long jiffies; +long sub_jiffie; +}; +static inline void posix_get_now (struct now_struct *now) +{ + (now)->jiffies = jiffies; + (now)->sub_jiffie =quick_update_jiffies_sub ((now)->jiffies); +while (unlikely (((now)->sub_jiffie - cycles_per_jiffies) >0 )){ + (now)->sub_jiffie = (now)->sub_jiffie - cycles_per_jiffies; + (now)->jiffies++; + } +} + +#define posix_time_before (timer, now) \ + ( {long diff = (long)(timer)->expires - (long)(now)->jiffies; \ + (diff < 0) || \ + ((diff == 0) && ((timer)->sub_expires < (now)->sub_jiffie)); }) + +#define posix_bump_timer (timr) do { \ + (timr)->it_timer.expires += (timr)->it_incr; \ + (timr)->it_timer.sub_expires += (timr)->it_sub_incr; \ + if (((timr)->it_timer.sub_expires - cycles_per_jiffies) >= 0){ \ + (timr)->it_timer.sub_expires -= cycles_per_jiffies; \ + (timr)->it_timer.expires++; \ + } \ + (timr)->it_overrun++; \ + }while (0) + +#else struct now_struct {unsigned long jiffies; };
@@ -26,4 +58,5 @@ (timr)->it_timer.expires += (timr)->it_incr; \ (timr)->it_overrun++; \ }while (0) +#endif // CONFIG_HIGH_RES_TIMERS #endif
include/linux/sched.h +3 -0
@@ -290,6 +290,9 @@int it_sigev_signo;/* signo word of sigevent struct */ sigval_t it_sigev_value;/* value word of sigevent struct */ unsigned long it_incr;/* interval specified in jiffies */ +#ifdef CONFIG_HIGH_RES_TIMERS +int it_sub_incr;/* sub jiffie part of interval */ +#endif struct task_struct *it_process;/* process to send signal to */ struct timer_list it_timer; };
kernel/posix-timers.c +109 -7
260 lines not on this page · raw message
Binary files linux-2.5.50-i386/scripts/lxdialog/lxdialog and linux/scripts/lxdialog/lxdialog differ Binary files linux-2.5.50-i386/usr/gen_init_cpio and linux/usr/gen_init_cpio differ Binary files linux-2.5.50-i386/usr/initramfs_data.cpio.gz and linux/usr/initramfs_data.cpio.gz differ