add schedule_timeout_msecs() interface
Subsystems (2)
RFC PATCH 1/1 add schedule_timeout_msecs() interface
Add a new interface, paralleling schedule_timeout(), but accepting instead a relative millisecond value. This is part of my overall effort to incorporate human-time units in the soft-timer subsystem.
Signed-off-by Nishanth Aravamudan <[email protected]>
include/linux/sched.h | 2 + kernel/timer.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
kernel/timer.c +58 -0
@@ -1129,6 +1129,64 @@ fastcall signed long __sched schedule_tiEXPORT_SYMBOL (schedule_timeout); +/** +* schedule_timeout_msecs - sleep until timeout +* @timeout: timeout value in milliseconds +* +* Make the current task sleep until @timeout milliseconds have +* elapsed. The routine will return immediately unless +* the current task state has been set (see set_current_state()). +* +* You can set the task state as follows - +* +* %TASK_UNINTERRUPTIBLE - at least @timeout milliseconds are guaranteed +* to pass before the routine returns. The routine will return 0 +* +* %TASK_INTERRUPTIBLE - the routine may return early if a signal is +* delivered to the current task. In this case the remaining time in +* milliseconds will be returned, or 0 if the timer expired in time +* +* The current task state is guaranteed to be TASK_RUNNING when this +* routine returns. +* +* Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT_MSECS will +* schedule the CPU away without a bound on the timeout. In this case +* the return value will be %MAX_SCHEDULE_TIMEOUT_MSECS. +* +* In all cases the return value is guaranteed to be non-negative. +*/ +fastcall unsigned int __sched schedule_timeout_msecs(unsigned int timeout) +{ +struct timer_list timer; +unsigned long expires; + +if (timeout ==MAX_SCHEDULE_TIMEOUT_MSECS ) { +schedule (); + goto out; + } + + expires = jiffies +msecs_to_jiffies (timeout); + +init_timer (&timer); + timer.expires = expires; + timer.data = (unsigned long )current; + timer.function = process_timeout; + +add_timer (&timer); +schedule (); +del_singleshot_timer_sync (&timer); + +if (jiffies > expires) + timeout =0 ; +else + timeout =jiffies_to_msecs (expires - jiffies); + +out: +return timeout; +} + +EXPORT_SYMBOL_GPL (schedule_timeout_msecs); +/* Thread ID - the internal kernel "pid" */ asmlinkage long sys_gettid (void ) {
include/linux/sched.h +2 -0
@@ -182,7 +182,9 @@ extern void scheduler_tick(void);extern int in_sched_functions (unsigned long addr);#define MAX_SCHEDULE_TIMEOUT LONG_MAX +#define MAX_SCHEDULE_TIMEOUT_MSECS UINT_MAXextern signed long FASTCALL (schedule_timeout (signed long timeout)); +extern unsigned int FASTCALL (schedule_timeout_msecs (unsigned int timeout)); asmlinkage void schedule(void);struct namespace ;
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors