Commit 068130cf authored by Ingo Molnar's avatar Ingo Molnar

[PATCH] posix-timers-cleanup-2.5.65-A5

This is a pure identity cleanup:

 - coding style fixes (whitespace, code, comment, line length cleanups)
 - remove dead code
 - simplify constructs, make code more readable
parent 187d7824
/* /*
* linux/kernel/posix_timers.c * linux/kernel/posix_timers.c
* *
* *
* 2002-10-15 Posix Clocks & timers by George Anzinger * 2002-10-15 Posix Clocks & timers by George Anzinger
* Copyright (C) 2002 by MontaVista Software. * Copyright (C) 2002 by MontaVista Software.
*/ */
/* These are all the functions necessary to implement /* These are all the functions necessary to implement
* POSIX clocks & timers * POSIX clocks & timers
*/ */
#include <linux/mm.h> #include <linux/mm.h>
...@@ -32,28 +32,28 @@ ...@@ -32,28 +32,28 @@
*remainder = do_div(result,divisor); \ *remainder = do_div(result,divisor); \
result; }) result; })
#endif /* ifndef div_long_long_rem */ #endif
/* /*
* Management arrays for POSIX timers. Timers are kept in slab memory * Management arrays for POSIX timers. Timers are kept in slab memory
* Timer ids are allocated by an external routine that keeps track of the * Timer ids are allocated by an external routine that keeps track of the
* id and the timer. The external interface is: * id and the timer. The external interface is:
* *
*void *idr_find(struct idr *idp, int id); to find timer_id <id> * void *idr_find(struct idr *idp, int id); to find timer_id <id>
*int idr_get_new(struct idr *idp, void *ptr); to get a new id and * int idr_get_new(struct idr *idp, void *ptr); to get a new id and
* related it to <ptr> * related it to <ptr>
*void idr_remove(struct idr *idp, int id); to release <id> * void idr_remove(struct idr *idp, int id); to release <id>
*void idr_init(struct idr *idp); to initialize <idp> * void idr_init(struct idr *idp); to initialize <idp>
* which we supply. * which we supply.
* The idr_get_new *may* call slab for more memory so it must not be * The idr_get_new *may* call slab for more memory so it must not be
* called under a spin lock. Likewise idr_remore may release memory * called under a spin lock. Likewise idr_remore may release memory
* (but it may be ok to do this under a lock...). * (but it may be ok to do this under a lock...).
* idr_find is just a memory look up and is quite fast. A zero return * idr_find is just a memory look up and is quite fast. A zero return
* indicates that the requested id does not exist. * indicates that the requested id does not exist.
*/ */
/* /*
* Lets keep our timers in a slab cache :-) * Lets keep our timers in a slab cache :-)
*/ */
static kmem_cache_t *posix_timers_cache; static kmem_cache_t *posix_timers_cache;
static struct idr posix_timers_id; static struct idr posix_timers_id;
...@@ -65,24 +65,28 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED; ...@@ -65,24 +65,28 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED;
*/ */
#define TIMER_INACTIVE 1 #define TIMER_INACTIVE 1
#define TIMER_RETRY 1 #define TIMER_RETRY 1
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
#define timer_active(tmr) (tmr->it_timer.entry.prev != (void *)TIMER_INACTIVE) # define timer_active(tmr) \
#define set_timer_inactive(tmr) tmr->it_timer.entry.prev = (void *)TIMER_INACTIVE ((tmr)->it_timer.entry.prev != (void *)TIMER_INACTIVE)
# define set_timer_inactive(tmr) \
do { \
(tmr)->it_timer.entry.prev = (void *)TIMER_INACTIVE; \
} while (0)
#else #else
#define timer_active(tmr) BARFY // error to use outside of SMP # define timer_active(tmr) BARFY // error to use outside of SMP
#define set_timer_inactive(tmr) # define set_timer_inactive(tmr) do { } while (0)
#endif #endif
/* /*
* The timer ID is turned into a timer address by idr_find(). * The timer ID is turned into a timer address by idr_find().
* Verifying a valid ID consists of: * Verifying a valid ID consists of:
* *
* a) checking that idr_find() returns other than zero. * a) checking that idr_find() returns other than zero.
* b) checking that the timer id matches the one in the timer itself. * b) checking that the timer id matches the one in the timer itself.
* c) that the timer owner is in the callers thread group. * c) that the timer owner is in the callers thread group.
*/ */
/*
/*
* CLOCKs: The POSIX standard calls for a couple of clocks and allows us * CLOCKs: The POSIX standard calls for a couple of clocks and allows us
* to implement others. This structure defines the various * to implement others. This structure defines the various
* clocks and allows the possibility of adding others. We * clocks and allows the possibility of adding others. We
...@@ -90,7 +94,7 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED; ...@@ -90,7 +94,7 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED;
* the "arch" code to add at least one clock that is high * the "arch" code to add at least one clock that is high
* resolution. Here we define the standard CLOCK_REALTIME as a * resolution. Here we define the standard CLOCK_REALTIME as a
* 1/HZ resolution clock. * 1/HZ resolution clock.
*
* CPUTIME & THREAD_CPUTIME: We are not, at this time, definding these * CPUTIME & THREAD_CPUTIME: We are not, at this time, definding these
* two clocks (and the other process related clocks (Std * two clocks (and the other process related clocks (Std
* 1003.1d-1999). The way these should be supported, we think, * 1003.1d-1999). The way these should be supported, we think,
...@@ -98,7 +102,7 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED; ...@@ -98,7 +102,7 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED;
* pinned to the executing process and to use -pid for clocks * pinned to the executing process and to use -pid for clocks
* pinned to particular pids. Calls which supported these clock * pinned to particular pids. Calls which supported these clock
* ids would split early in the function. * ids would split early in the function.
*
* RESOLUTION: Clock resolution is used to round up timer and interval * RESOLUTION: Clock resolution is used to round up timer and interval
* times, NOT to report clock times, which are reported with as * times, NOT to report clock times, which are reported with as
* much resolution as the system can muster. In some cases this * much resolution as the system can muster. In some cases this
...@@ -106,7 +110,7 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED; ...@@ -106,7 +110,7 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED;
* may not be quantifiable until run time, and only then is the * may not be quantifiable until run time, and only then is the
* necessary code is written. The standard says we should say * necessary code is written. The standard says we should say
* something about this issue in the documentation... * something about this issue in the documentation...
*
* FUNCTIONS: The CLOCKs structure defines possible functions to handle * FUNCTIONS: The CLOCKs structure defines possible functions to handle
* various clock functions. For clocks that use the standard * various clock functions. For clocks that use the standard
* system timer code these entries should be NULL. This will * system timer code these entries should be NULL. This will
...@@ -116,7 +120,7 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED; ...@@ -116,7 +120,7 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED;
* ENOSYS. The standard POSIX timer management code assumes the * ENOSYS. The standard POSIX timer management code assumes the
* following: 1.) The k_itimer struct (sched.h) is used for the * following: 1.) The k_itimer struct (sched.h) is used for the
* timer. 2.) The list, it_lock, it_clock, it_id and it_process * timer. 2.) The list, it_lock, it_clock, it_id and it_process
* fields are not modified by timer code. * fields are not modified by timer code.
* *
* At this time all functions EXCEPT clock_nanosleep can be * At this time all functions EXCEPT clock_nanosleep can be
* redirected by the CLOCKS structure. Clock_nanosleep is in * redirected by the CLOCKS structure. Clock_nanosleep is in
...@@ -132,37 +136,29 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED; ...@@ -132,37 +136,29 @@ static spinlock_t idr_lock = SPIN_LOCK_UNLOCKED;
static struct k_clock posix_clocks[MAX_CLOCKS]; static struct k_clock posix_clocks[MAX_CLOCKS];
#define if_clock_do(clock_fun, alt_fun,parms) (! clock_fun)? alt_fun parms :\ #define if_clock_do(clock_fun,alt_fun,parms) \
clock_fun parms (!clock_fun) ? alt_fun parms : clock_fun parms
#define p_timer_get( clock,a,b) if_clock_do((clock)->timer_get, \ #define p_timer_get(clock,a,b) \
do_timer_gettime, \ if_clock_do((clock)->timer_get,do_timer_gettime, (a,b))
(a,b))
#define p_nsleep( clock,a,b,c) if_clock_do((clock)->nsleep, \ #define p_nsleep(clock,a,b,c) \
do_nsleep, \ if_clock_do((clock)->nsleep, do_nsleep, (a,b,c))
(a,b,c))
#define p_timer_del( clock,a) if_clock_do((clock)->timer_del, \ #define p_timer_del(clock,a) \
do_timer_delete, \ if_clock_do((clock)->timer_del, do_timer_delete, (a))
(a))
void register_posix_clock(int clock_id, struct k_clock *new_clock); void register_posix_clock(int clock_id, struct k_clock *new_clock);
static int do_posix_gettime(struct k_clock *clock, struct timespec *tp); static int do_posix_gettime(struct k_clock *clock, struct timespec *tp);
int do_posix_clock_monotonic_gettime(struct timespec *tp); int do_posix_clock_monotonic_gettime(struct timespec *tp);
int do_posix_clock_monotonic_settime(struct timespec *tp); int do_posix_clock_monotonic_settime(struct timespec *tp);
static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags); static struct k_itimer *lock_timer(timer_t timer_id, unsigned long *flags);
static inline void unlock_timer(struct k_itimer *timr, unsigned long flags); static inline void unlock_timer(struct k_itimer *timr, unsigned long flags);
/* /*
* Initialize everything, well, just everything in Posix clocks/timers ;) * Initialize everything, well, just everything in Posix clocks/timers ;)
*/ */
static __init int init_posix_timers(void)
static __init int
init_posix_timers(void)
{ {
struct k_clock clock_realtime = {.res = NSEC_PER_SEC / HZ }; struct k_clock clock_realtime = {.res = NSEC_PER_SEC / HZ };
struct k_clock clock_monotonic = {.res = NSEC_PER_SEC / HZ, struct k_clock clock_monotonic = {.res = NSEC_PER_SEC / HZ,
...@@ -174,9 +170,9 @@ init_posix_timers(void) ...@@ -174,9 +170,9 @@ init_posix_timers(void)
register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic); register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
posix_timers_cache = kmem_cache_create("posix_timers_cache", posix_timers_cache = kmem_cache_create("posix_timers_cache",
sizeof (struct k_itimer), 0, 0, sizeof (struct k_itimer), 0, 0, 0, 0);
0, 0);
idr_init(&posix_timers_id); idr_init(&posix_timers_id);
return 0; return 0;
} }
...@@ -200,11 +196,11 @@ static void tstojiffie(struct timespec *tp, int res, u64 *jiff) ...@@ -200,11 +196,11 @@ static void tstojiffie(struct timespec *tp, int res, u64 *jiff)
* unsigned int/2). Times beyond this will be truncated back to * unsigned int/2). Times beyond this will be truncated back to
* this value. This is done in the absolute adjustment code, * this value. This is done in the absolute adjustment code,
* below. Here it is enough to just discard the high order * below. Here it is enough to just discard the high order
* bits. * bits.
*/ */
*jiff = (u64)sec * HZ; *jiff = (u64)sec * HZ;
/* /*
* Do the res thing. (Don't forget the add in the declaration of nsec) * Do the res thing. (Don't forget the add in the declaration of nsec)
*/ */
nsec -= nsec % res; nsec -= nsec % res;
/* /*
...@@ -213,8 +209,7 @@ static void tstojiffie(struct timespec *tp, int res, u64 *jiff) ...@@ -213,8 +209,7 @@ static void tstojiffie(struct timespec *tp, int res, u64 *jiff)
*jiff += nsec / (NSEC_PER_SEC / HZ); *jiff += nsec / (NSEC_PER_SEC / HZ);
} }
static void static void tstotimer(struct itimerspec *time, struct k_itimer *timer)
tstotimer(struct itimerspec *time, struct k_itimer *timer)
{ {
u64 result; u64 result;
int res = posix_clocks[timer->it_clock].res; int res = posix_clocks[timer->it_clock].res;
...@@ -225,22 +220,18 @@ tstotimer(struct itimerspec *time, struct k_itimer *timer) ...@@ -225,22 +220,18 @@ tstotimer(struct itimerspec *time, struct k_itimer *timer)
timer->it_incr = (unsigned long)result; timer->it_incr = (unsigned long)result;
} }
static void static void schedule_next_timer(struct k_itimer *timr)
schedule_next_timer(struct k_itimer *timr)
{ {
struct now_struct now; struct now_struct now;
/* Set up the timer for the next interval (if there is one) */ /* Set up the timer for the next interval (if there is one) */
if (timr->it_incr == 0) { if (!timr->it_incr) {
{ set_timer_inactive(timr);
set_timer_inactive(timr); return;
return;
}
} }
posix_get_now(&now); posix_get_now(&now);
while (posix_time_before(&timr->it_timer, &now)) { while (posix_time_before(&timr->it_timer, &now))
posix_bump_timer(timr); posix_bump_timer(timr);
};
timr->it_overrun_last = timr->it_overrun; timr->it_overrun_last = timr->it_overrun;
timr->it_overrun = -1; timr->it_overrun = -1;
timr->it_requeue_pending = 0; timr->it_requeue_pending = 0;
...@@ -248,7 +239,6 @@ schedule_next_timer(struct k_itimer *timr) ...@@ -248,7 +239,6 @@ schedule_next_timer(struct k_itimer *timr)
} }
/* /*
* This function is exported for use by the signal deliver code. It is * This function is exported for use by the signal deliver code. It is
* called just prior to the info block being released and passes that * called just prior to the info block being released and passes that
* block to us. It's function is to update the overrun entry AND to * block to us. It's function is to update the overrun entry AND to
...@@ -258,12 +248,9 @@ schedule_next_timer(struct k_itimer *timr) ...@@ -258,12 +248,9 @@ schedule_next_timer(struct k_itimer *timr)
* *
* To protect aginst the timer going away while the interrupt is queued, * To protect aginst the timer going away while the interrupt is queued,
* we require that the it_requeue_pending flag be set. * we require that the it_requeue_pending flag be set.
*/ */
void void do_schedule_next_timer(struct siginfo *info)
do_schedule_next_timer(struct siginfo *info)
{ {
struct k_itimer *timr; struct k_itimer *timr;
unsigned long flags; unsigned long flags;
...@@ -274,13 +261,12 @@ do_schedule_next_timer(struct siginfo *info) ...@@ -274,13 +261,12 @@ do_schedule_next_timer(struct siginfo *info)
schedule_next_timer(timr); schedule_next_timer(timr);
info->si_overrun = timr->it_overrun_last; info->si_overrun = timr->it_overrun_last;
exit: exit:
if (timr) if (timr)
unlock_timer(timr, flags); unlock_timer(timr, flags);
} }
/* /*
* Notify the task and set up the timer for the next expiration (if * Notify the task and set up the timer for the next expiration (if
* applicable). This function requires that the k_itimer structure * applicable). This function requires that the k_itimer structure
* it_lock is taken. This code will requeue the timer only if we get * it_lock is taken. This code will requeue the timer only if we get
...@@ -288,11 +274,9 @@ do_schedule_next_timer(struct siginfo *info) ...@@ -288,11 +274,9 @@ do_schedule_next_timer(struct siginfo *info)
* indicating that the signal was either not queued or was queued * indicating that the signal was either not queued or was queued
* without an info block. In this case, we will not get a call back to * without an info block. In this case, we will not get a call back to
* do_schedule_next_timer() so we do it here. This should be rare... * do_schedule_next_timer() so we do it here. This should be rare...
*/ */
static void static void timer_notify_task(struct k_itimer *timr)
timer_notify_task(struct k_itimer *timr)
{ {
struct siginfo info; struct siginfo info;
int ret; int ret;
...@@ -305,11 +289,11 @@ timer_notify_task(struct k_itimer *timr) ...@@ -305,11 +289,11 @@ timer_notify_task(struct k_itimer *timr)
info.si_code = SI_TIMER; info.si_code = SI_TIMER;
info.si_tid = timr->it_id; info.si_tid = timr->it_id;
info.si_value = timr->it_sigev_value; info.si_value = timr->it_sigev_value;
if (timr->it_incr == 0) { if (!timr->it_incr)
set_timer_inactive(timr); set_timer_inactive(timr);
} else { else
timr->it_requeue_pending = info.si_sys_private = 1; timr->it_requeue_pending = info.si_sys_private = 1;
}
ret = send_sig_info(info.si_signo, &info, timr->it_process); ret = send_sig_info(info.si_signo, &info, timr->it_process);
switch (ret) { switch (ret) {
...@@ -324,11 +308,11 @@ timer_notify_task(struct k_itimer *timr) ...@@ -324,11 +308,11 @@ timer_notify_task(struct k_itimer *timr)
* signal was not sent because of sig_ignor or, * signal was not sent because of sig_ignor or,
* possibly no queue memory OR will be sent but, * possibly no queue memory OR will be sent but,
* we will not get a call back to restart it AND * we will not get a call back to restart it AND
* it should be restarted. * it should be restarted.
*/ */
schedule_next_timer(timr); schedule_next_timer(timr);
case 0: case 0:
/* /*
* all's well new signal queued * all's well new signal queued
*/ */
break; break;
...@@ -336,14 +320,11 @@ timer_notify_task(struct k_itimer *timr) ...@@ -336,14 +320,11 @@ timer_notify_task(struct k_itimer *timr)
} }
/* /*
* This function gets called when a POSIX.1b interval timer expires. It * This function gets called when a POSIX.1b interval timer expires. It
* is used as a callback from the kernel internal timer. The * is used as a callback from the kernel internal timer. The
* run_timer_list code ALWAYS calls with interrutps on. * run_timer_list code ALWAYS calls with interrutps on.
*/ */
static void static void posix_timer_fn(unsigned long __data)
posix_timer_fn(unsigned long __data)
{ {
struct k_itimer *timr = (struct k_itimer *) __data; struct k_itimer *timr = (struct k_itimer *) __data;
unsigned long flags; unsigned long flags;
...@@ -354,8 +335,8 @@ posix_timer_fn(unsigned long __data) ...@@ -354,8 +335,8 @@ posix_timer_fn(unsigned long __data)
} }
/* /*
* For some reason mips/mips64 define the SIGEV constants plus 128. * For some reason mips/mips64 define the SIGEV constants plus 128.
* Here we define a mask to get rid of the common bits. The * Here we define a mask to get rid of the common bits. The
* optimizer should make this costless to all but mips. * optimizer should make this costless to all but mips.
*/ */
#if (ARCH == mips) || (ARCH == mips64) #if (ARCH == mips) || (ARCH == mips64)
...@@ -367,30 +348,26 @@ posix_timer_fn(unsigned long __data) ...@@ -367,30 +348,26 @@ posix_timer_fn(unsigned long __data)
#define MIPS_SIGEV (int)-1 #define MIPS_SIGEV (int)-1
#endif #endif
static inline struct task_struct * static inline struct task_struct * good_sigevent(sigevent_t * event)
good_sigevent(sigevent_t * event)
{ {
struct task_struct *rtn = current; struct task_struct *rtn = current;
if (event->sigev_notify & SIGEV_THREAD_ID & MIPS_SIGEV) { if ((event->sigev_notify & SIGEV_THREAD_ID & MIPS_SIGEV) &&
if (!(rtn = (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
find_task_by_pid(event->sigev_notify_thread_id)) || rtn->tgid != current->tgid))
rtn->tgid != current->tgid) {
return NULL;
}
}
if (event->sigev_notify & SIGEV_SIGNAL & MIPS_SIGEV) {
if ((unsigned) (event->sigev_signo > SIGRTMAX))
return NULL;
}
if (event->sigev_notify & ~(SIGEV_SIGNAL | SIGEV_THREAD_ID)) {
return NULL; return NULL;
}
if ((event->sigev_notify & SIGEV_SIGNAL & MIPS_SIGEV) &&
((unsigned) (event->sigev_signo > SIGRTMAX)))
return NULL;
if (event->sigev_notify & ~(SIGEV_SIGNAL | SIGEV_THREAD_ID))
return NULL;
return rtn; return rtn;
} }
void void register_posix_clock(int clock_id, struct k_clock *new_clock)
register_posix_clock(int clock_id, struct k_clock *new_clock)
{ {
if ((unsigned) clock_id >= MAX_CLOCKS) { if ((unsigned) clock_id >= MAX_CLOCKS) {
printk("POSIX clock register failed for clock_id %d\n", printk("POSIX clock register failed for clock_id %d\n",
...@@ -400,19 +377,18 @@ register_posix_clock(int clock_id, struct k_clock *new_clock) ...@@ -400,19 +377,18 @@ register_posix_clock(int clock_id, struct k_clock *new_clock)
posix_clocks[clock_id] = *new_clock; posix_clocks[clock_id] = *new_clock;
} }
static struct k_itimer * static struct k_itimer * alloc_posix_timer(void)
alloc_posix_timer(void)
{ {
struct k_itimer *tmr; struct k_itimer *tmr;
tmr = kmem_cache_alloc(posix_timers_cache, GFP_KERNEL); tmr = kmem_cache_alloc(posix_timers_cache, GFP_KERNEL);
memset(tmr, 0, sizeof (struct k_itimer)); memset(tmr, 0, sizeof (struct k_itimer));
return (tmr);
return tmr;
} }
static void static void release_posix_timer(struct k_itimer *tmr)
release_posix_timer(struct k_itimer *tmr)
{ {
if (tmr->it_id != -1){ if (tmr->it_id != -1) {
spin_lock_irq(&idr_lock); spin_lock_irq(&idr_lock);
idr_remove(&posix_timers_id, tmr->it_id); idr_remove(&posix_timers_id, tmr->it_id);
spin_unlock_irq(&idr_lock); spin_unlock_irq(&idr_lock);
...@@ -433,28 +409,29 @@ sys_timer_create(clockid_t which_clock, ...@@ -433,28 +409,29 @@ sys_timer_create(clockid_t which_clock,
sigevent_t event; sigevent_t event;
if ((unsigned) which_clock >= MAX_CLOCKS || if ((unsigned) which_clock >= MAX_CLOCKS ||
!posix_clocks[which_clock].res) return -EINVAL; !posix_clocks[which_clock].res)
return -EINVAL;
new_timer = alloc_posix_timer(); new_timer = alloc_posix_timer();
if (unlikely (new_timer == NULL)) if (unlikely(!new_timer))
return -EAGAIN; return -EAGAIN;
spin_lock_init(&new_timer->it_lock); spin_lock_init(&new_timer->it_lock);
do { do {
if ( unlikely ( !idr_pre_get(&posix_timers_id))){ if (unlikely(!idr_pre_get(&posix_timers_id))) {
error = -EAGAIN; error = -EAGAIN;
new_timer_id = (timer_t)-1; new_timer_id = (timer_t)-1;
goto out; goto out;
} }
spin_lock_irq(&idr_lock); spin_lock_irq(&idr_lock);
new_timer_id = (timer_t) idr_get_new( new_timer_id = (timer_t) idr_get_new(&posix_timers_id,
&posix_timers_id, (void *) new_timer); (void *) new_timer);
spin_unlock_irq(&idr_lock); spin_unlock_irq(&idr_lock);
}while( unlikely (new_timer_id == -1)); } while (unlikely(new_timer_id == -1));
new_timer->it_id = new_timer_id; new_timer->it_id = new_timer_id;
/* /*
* return the timer_id now. The next step is hard to * return the timer_id now. The next step is hard to
* back out if there is an error. * back out if there is an error.
*/ */
if (copy_to_user(created_timer_id, if (copy_to_user(created_timer_id,
...@@ -470,13 +447,12 @@ sys_timer_create(clockid_t which_clock, ...@@ -470,13 +447,12 @@ sys_timer_create(clockid_t which_clock,
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
if ((process = good_sigevent(&event))) { if ((process = good_sigevent(&event))) {
/* /*
* We may be setting up this process for another * We may be setting up this process for another
* thread. It may be exitiing. To catch this * thread. It may be exiting. To catch this
* case the we check the PF_EXITING flag. If * case the we check the PF_EXITING flag. If
* the flag is not set, the task_lock will catch * the flag is not set, the task_lock will catch
* him before it is too late (in exit_itimers). * him before it is too late (in exit_itimers).
*
* The exec case is a bit more invloved but easy * The exec case is a bit more invloved but easy
* to code. If the process is in our thread * to code. If the process is in our thread
* group (and it must be or we would not allow * group (and it must be or we would not allow
...@@ -484,7 +460,6 @@ sys_timer_create(clockid_t which_clock, ...@@ -484,7 +460,6 @@ sys_timer_create(clockid_t which_clock,
* us to be killed. In this case it will wait * us to be killed. In this case it will wait
* for us to die which means we can finish this * for us to die which means we can finish this
* linkage with our last gasp. I.e. no code :) * linkage with our last gasp. I.e. no code :)
*/ */
task_lock(process); task_lock(process);
if (!(process->flags & PF_EXITING)) { if (!(process->flags & PF_EXITING)) {
...@@ -527,11 +502,10 @@ sys_timer_create(clockid_t which_clock, ...@@ -527,11 +502,10 @@ sys_timer_create(clockid_t which_clock,
* Once we set the process, it can be found so do it last... * Once we set the process, it can be found so do it last...
*/ */
new_timer->it_process = process; new_timer->it_process = process;
out:
out: if (error)
if (error) {
release_posix_timer(new_timer); release_posix_timer(new_timer);
}
return error; return error;
} }
...@@ -543,43 +517,36 @@ sys_timer_create(clockid_t which_clock, ...@@ -543,43 +517,36 @@ sys_timer_create(clockid_t which_clock,
* Arguments: * Arguments:
* ts : Pointer to the timespec structure to check * ts : Pointer to the timespec structure to check
* *
* Return value: * Return value:
* If a NULL pointer was passed in, or the tv_nsec field was less than 0 * If a NULL pointer was passed in, or the tv_nsec field was less than 0
* or greater than NSEC_PER_SEC, or the tv_sec field was less than 0, * or greater than NSEC_PER_SEC, or the tv_sec field was less than 0,
* this function returns 0. Otherwise it returns 1. * this function returns 0. Otherwise it returns 1.
*/ */
static int good_timespec(const struct timespec *ts)
static int
good_timespec(const struct timespec *ts)
{ {
if ((ts == NULL) || if ((!ts) || (ts->tv_sec < 0) ||
(ts->tv_sec < 0) || ((unsigned) ts->tv_nsec >= NSEC_PER_SEC))
((unsigned) ts->tv_nsec >= NSEC_PER_SEC)) return 0; return 0;
return 1; return 1;
} }
static inline void static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
unlock_timer(struct k_itimer *timr, unsigned long flags)
{ {
spin_unlock_irqrestore(&timr->it_lock, flags); spin_unlock_irqrestore(&timr->it_lock, flags);
} }
/* /*
* Locking issues: We need to protect the result of the id look up until * Locking issues: We need to protect the result of the id look up until
* we get the timer locked down so it is not deleted under us. The * we get the timer locked down so it is not deleted under us. The
* removal is done under the idr spinlock so we use that here to bridge * removal is done under the idr spinlock so we use that here to bridge
* the find to the timer lock. To avoid a dead lock, the timer id MUST * the find to the timer lock. To avoid a dead lock, the timer id MUST
* be release with out holding the timer lock. * be release with out holding the timer lock.
*/ */
static struct k_itimer * static struct k_itimer * lock_timer(timer_t timer_id, unsigned long *flags)
lock_timer(timer_t timer_id, unsigned long *flags)
{ {
struct k_itimer *timr; struct k_itimer *timr;
/* /*
* Watch out here. We do a irqsave on the idr_lock and pass the * Watch out here. We do a irqsave on the idr_lock and pass the
* flags part over to the timer lock. Must not let interrupts in * flags part over to the timer lock. Must not let interrupts in
* while we are moving the lock. * while we are moving the lock.
*/ */
...@@ -590,35 +557,32 @@ lock_timer(timer_t timer_id, unsigned long *flags) ...@@ -590,35 +557,32 @@ lock_timer(timer_t timer_id, unsigned long *flags)
spin_lock(&timr->it_lock); spin_lock(&timr->it_lock);
spin_unlock(&idr_lock); spin_unlock(&idr_lock);
if ( (timr->it_id != timer_id) || !(timr->it_process) || if ((timr->it_id != timer_id) || !(timr->it_process) ||
timr->it_process->tgid != current->tgid) { timr->it_process->tgid != current->tgid) {
unlock_timer(timr, *flags); unlock_timer(timr, *flags);
timr = NULL; timr = NULL;
} }
} else { } else
spin_unlock_irqrestore(&idr_lock, *flags); spin_unlock_irqrestore(&idr_lock, *flags);
}
return timr; return timr;
} }
/* /*
* Get the time remaining on a POSIX.1b interval timer. This function * Get the time remaining on a POSIX.1b interval timer. This function
* is ALWAYS called with spin_lock_irq on the timer, thus it must not * is ALWAYS called with spin_lock_irq on the timer, thus it must not
* mess with irq. * mess with irq.
*
* We have a couple of messes to clean up here. First there is the case * We have a couple of messes to clean up here. First there is the case
* of a timer that has a requeue pending. These timers should appear to * of a timer that has a requeue pending. These timers should appear to
* be in the timer list with an expiry as if we were to requeue them * be in the timer list with an expiry as if we were to requeue them
* now. * now.
*
* The second issue is the SIGEV_NONE timer which may be active but is * The second issue is the SIGEV_NONE timer which may be active but is
* not really ever put in the timer list (to save system resources). * not really ever put in the timer list (to save system resources).
* This timer may be expired, and if so, we will do it here. Otherwise * This timer may be expired, and if so, we will do it here. Otherwise
* it is the same as a requeue pending timer WRT to what we should * it is the same as a requeue pending timer WRT to what we should
* report. * report.
*/ */
void inline void inline
do_timer_gettime(struct k_itimer *timr, struct itimerspec *cur_setting) do_timer_gettime(struct k_itimer *timr, struct itimerspec *cur_setting)
...@@ -627,31 +591,25 @@ do_timer_gettime(struct k_itimer *timr, struct itimerspec *cur_setting) ...@@ -627,31 +591,25 @@ do_timer_gettime(struct k_itimer *timr, struct itimerspec *cur_setting)
unsigned long expires; unsigned long expires;
struct now_struct now; struct now_struct now;
do { do
expires = timr->it_timer.expires; expires = timr->it_timer.expires;
} while ((volatile long) (timr->it_timer.expires) != expires); while ((volatile long) (timr->it_timer.expires) != expires);
posix_get_now(&now); posix_get_now(&now);
if (expires && (timr->it_sigev_notify & SIGEV_NONE) && !timr->it_incr) { if (expires && (timr->it_sigev_notify & SIGEV_NONE) && !timr->it_incr &&
if (posix_time_before(&timr->it_timer, &now)) { posix_time_before(&timr->it_timer, &now))
timr->it_timer.expires = expires = 0; timr->it_timer.expires = expires = 0;
}
}
if (expires) { if (expires) {
if (timr->it_requeue_pending || if (timr->it_requeue_pending ||
(timr->it_sigev_notify & SIGEV_NONE)) { (timr->it_sigev_notify & SIGEV_NONE))
while (posix_time_before(&timr->it_timer, &now)) { while (posix_time_before(&timr->it_timer, &now))
posix_bump_timer(timr); posix_bump_timer(timr);
}; else
} else { if (!timer_pending(&timr->it_timer))
if (!timer_pending(&timr->it_timer)) {
sub_expires = expires = 0; sub_expires = expires = 0;
} if (expires)
}
if (expires) {
expires -= now.jiffies; expires -= now.jiffies;
}
} }
jiffies_to_timespec(expires, &cur_setting->it_value); jiffies_to_timespec(expires, &cur_setting->it_value);
jiffies_to_timespec(timr->it_incr, &cur_setting->it_interval); jiffies_to_timespec(timr->it_incr, &cur_setting->it_interval);
...@@ -661,6 +619,7 @@ do_timer_gettime(struct k_itimer *timr, struct itimerspec *cur_setting) ...@@ -661,6 +619,7 @@ do_timer_gettime(struct k_itimer *timr, struct itimerspec *cur_setting)
cur_setting->it_value.tv_sec = 0; cur_setting->it_value.tv_sec = 0;
} }
} }
/* Get the time remaining on a POSIX.1b interval timer. */ /* Get the time remaining on a POSIX.1b interval timer. */
asmlinkage long asmlinkage long
sys_timer_gettime(timer_t timer_id, struct itimerspec *setting) sys_timer_gettime(timer_t timer_id, struct itimerspec *setting)
...@@ -683,7 +642,6 @@ sys_timer_gettime(timer_t timer_id, struct itimerspec *setting) ...@@ -683,7 +642,6 @@ sys_timer_gettime(timer_t timer_id, struct itimerspec *setting)
return 0; return 0;
} }
/* /*
* Get the number of overruns of a POSIX.1b interval timer. This is to * Get the number of overruns of a POSIX.1b interval timer. This is to
* be the overrun of the timer last delivered. At the same time we are * be the overrun of the timer last delivered. At the same time we are
* accumulating overruns on the next timer. The overrun is frozen when * accumulating overruns on the next timer. The overrun is frozen when
...@@ -691,7 +649,6 @@ sys_timer_gettime(timer_t timer_id, struct itimerspec *setting) ...@@ -691,7 +649,6 @@ sys_timer_gettime(timer_t timer_id, struct itimerspec *setting)
* is not queued) or at the actual delivery time (as we are informed by * is not queued) or at the actual delivery time (as we are informed by
* the call back to do_schedule_next_timer(). So all we need to do is * the call back to do_schedule_next_timer(). So all we need to do is
* to pick up the frozen overrun. * to pick up the frozen overrun.
*/ */
asmlinkage long asmlinkage long
...@@ -710,8 +667,9 @@ sys_timer_getoverrun(timer_t timer_id) ...@@ -710,8 +667,9 @@ sys_timer_getoverrun(timer_t timer_id)
return overrun; return overrun;
} }
/* Adjust for absolute time */
/* /*
* Adjust for absolute time
*
* If absolute time is given and it is not CLOCK_MONOTONIC, we need to * If absolute time is given and it is not CLOCK_MONOTONIC, we need to
* adjust for the offset between the timer clock (CLOCK_MONOTONIC) and * adjust for the offset between the timer clock (CLOCK_MONOTONIC) and
* what ever clock he is using. * what ever clock he is using.
...@@ -719,26 +677,23 @@ sys_timer_getoverrun(timer_t timer_id) ...@@ -719,26 +677,23 @@ sys_timer_getoverrun(timer_t timer_id)
* If it is relative time, we need to add the current (CLOCK_MONOTONIC) * If it is relative time, we need to add the current (CLOCK_MONOTONIC)
* time to it to get the proper time for the timer. * time to it to get the proper time for the timer.
*/ */
static int static int adjust_abs_time(struct k_clock *clock, struct timespec *tp, int abs)
adjust_abs_time(struct k_clock *clock, struct timespec *tp, int abs)
{ {
struct timespec now; struct timespec now;
struct timespec oc; struct timespec oc;
do_posix_clock_monotonic_gettime(&now); do_posix_clock_monotonic_gettime(&now);
if (abs && if (!abs || (posix_clocks[CLOCK_MONOTONIC].clock_get !=
(posix_clocks[CLOCK_MONOTONIC].clock_get == clock->clock_get)) { clock->clock_get)) {
} else { if (abs)
if (abs) {
do_posix_gettime(clock, &oc); do_posix_gettime(clock, &oc);
} else { else
oc.tv_nsec = oc.tv_sec = 0; oc.tv_nsec = oc.tv_sec = 0;
}
tp->tv_sec += now.tv_sec - oc.tv_sec; tp->tv_sec += now.tv_sec - oc.tv_sec;
tp->tv_nsec += now.tv_nsec - oc.tv_nsec; tp->tv_nsec += now.tv_nsec - oc.tv_nsec;
/* /*
* Normalize... * Normalize...
*/ */
if ((tp->tv_nsec - NSEC_PER_SEC) >= 0) { if ((tp->tv_nsec - NSEC_PER_SEC) >= 0) {
...@@ -761,18 +716,16 @@ adjust_abs_time(struct k_clock *clock, struct timespec *tp, int abs) ...@@ -761,18 +716,16 @@ adjust_abs_time(struct k_clock *clock, struct timespec *tp, int abs)
if ((unsigned) tp->tv_sec < now.tv_sec) { if ((unsigned) tp->tv_sec < now.tv_sec) {
tp->tv_sec = now.tv_sec; tp->tv_sec = now.tv_sec;
tp->tv_nsec = now.tv_nsec; tp->tv_nsec = now.tv_nsec;
} else { } else
// tp->tv_sec = now.tv_sec + (MAX_JIFFY_OFFSET / HZ);
/* /*
* This is a considered response, not exactly in * This is a considered response, not exactly in
* line with the standard (in fact it is silent on * line with the standard (in fact it is silent on
* possible overflows). We assume such a large * possible overflows). We assume such a large
* value is ALMOST always a programming error and * value is ALMOST always a programming error and
* try not to compound it by setting a really dumb * try not to compound it by setting a really dumb
* value. * value.
*/ */
return -EINVAL; return -EINVAL;
}
} }
return 0; return 0;
} }
...@@ -785,28 +738,27 @@ do_timer_settime(struct k_itimer *timr, int flags, ...@@ -785,28 +738,27 @@ do_timer_settime(struct k_itimer *timr, int flags,
{ {
struct k_clock *clock = &posix_clocks[timr->it_clock]; struct k_clock *clock = &posix_clocks[timr->it_clock];
if (old_setting) { if (old_setting)
do_timer_gettime(timr, old_setting); do_timer_gettime(timr, old_setting);
}
/* disable the timer */ /* disable the timer */
timr->it_incr = 0; timr->it_incr = 0;
/* /*
* careful here. If smp we could be in the "fire" routine which will * careful here. If smp we could be in the "fire" routine which will
* be spinning as we hold the lock. But this is ONLY an SMP issue. * be spinning as we hold the lock. But this is ONLY an SMP issue.
*/ */
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
if (timer_active(timr) && !del_timer(&timr->it_timer)) { if (timer_active(timr) && !del_timer(&timr->it_timer))
/* /*
* It can only be active if on an other cpu. Since * It can only be active if on an other cpu. Since
* we have cleared the interval stuff above, it should * we have cleared the interval stuff above, it should
* clear once we release the spin lock. Of course once * clear once we release the spin lock. Of course once
* we do that anything could happen, including the * we do that anything could happen, including the
* complete melt down of the timer. So return with * complete melt down of the timer. So return with
* a "retry" exit status. * a "retry" exit status.
*/ */
return TIMER_RETRY; return TIMER_RETRY;
}
set_timer_inactive(timr); set_timer_inactive(timr);
#else #else
del_timer(&timr->it_timer); del_timer(&timr->it_timer);
...@@ -814,22 +766,21 @@ do_timer_settime(struct k_itimer *timr, int flags, ...@@ -814,22 +766,21 @@ do_timer_settime(struct k_itimer *timr, int flags,
timr->it_requeue_pending = 0; timr->it_requeue_pending = 0;
timr->it_overrun_last = 0; timr->it_overrun_last = 0;
timr->it_overrun = -1; timr->it_overrun = -1;
/* /*
*switch off the timer when it_value is zero *switch off the timer when it_value is zero
*/ */
if ((new_setting->it_value.tv_sec == 0) && if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) {
(new_setting->it_value.tv_nsec == 0)) {
timr->it_timer.expires = 0; timr->it_timer.expires = 0;
return 0; return 0;
} }
if ((flags & TIMER_ABSTIME) && if ((flags & TIMER_ABSTIME) &&
(clock->clock_get != do_posix_clock_monotonic_gettime)) { (clock->clock_get != do_posix_clock_monotonic_gettime))
} // FIXME: what is this?
;
if (adjust_abs_time(clock, if (adjust_abs_time(clock,
&new_setting->it_value, flags & TIMER_ABSTIME)) { &new_setting->it_value, flags & TIMER_ABSTIME))
return -EINVAL; return -EINVAL;
}
tstotimer(new_setting, timr); tstotimer(new_setting, timr);
/* /*
...@@ -838,9 +789,9 @@ do_timer_settime(struct k_itimer *timr, int flags, ...@@ -838,9 +789,9 @@ do_timer_settime(struct k_itimer *timr, int flags,
* We do not even queue SIGEV_NONE timers! * We do not even queue SIGEV_NONE timers!
*/ */
if (!(timr->it_sigev_notify & SIGEV_NONE)) { if (!(timr->it_sigev_notify & SIGEV_NONE)) {
if (timr->it_timer.expires == jiffies) { if (timr->it_timer.expires == jiffies)
timer_notify_task(timr); timer_notify_task(timr);
} else else
add_timer(&timr->it_timer); add_timer(&timr->it_timer);
} }
return 0; return 0;
...@@ -858,62 +809,54 @@ sys_timer_settime(timer_t timer_id, int flags, ...@@ -858,62 +809,54 @@ sys_timer_settime(timer_t timer_id, int flags,
long flag; long flag;
struct itimerspec *rtn = old_setting ? &old_spec : NULL; struct itimerspec *rtn = old_setting ? &old_spec : NULL;
if (new_setting == NULL) { if (!new_setting)
return -EINVAL; return -EINVAL;
}
if (copy_from_user(&new_spec, new_setting, sizeof (new_spec))) { if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
return -EFAULT; return -EFAULT;
}
if ((!good_timespec(&new_spec.it_interval)) || if ((!good_timespec(&new_spec.it_interval)) ||
(!good_timespec(&new_spec.it_value))) { (!good_timespec(&new_spec.it_value)))
return -EINVAL; return -EINVAL;
} retry:
retry:
timr = lock_timer(timer_id, &flag); timr = lock_timer(timer_id, &flag);
if (!timr) if (!timr)
return -EINVAL; return -EINVAL;
if (!posix_clocks[timr->it_clock].timer_set) { if (!posix_clocks[timr->it_clock].timer_set)
error = do_timer_settime(timr, flags, &new_spec, rtn); error = do_timer_settime(timr, flags, &new_spec, rtn);
} else { else
error = posix_clocks[timr->it_clock].timer_set(timr, error = posix_clocks[timr->it_clock].timer_set(timr,
flags, flags,
&new_spec, rtn); &new_spec, rtn);
}
unlock_timer(timr, flag); unlock_timer(timr, flag);
if (error == TIMER_RETRY) { if (error == TIMER_RETRY) {
rtn = NULL; // We already got the old time... rtn = NULL; // We already got the old time...
goto retry; goto retry;
} }
if (old_setting && !error) { if (old_setting && !error && copy_to_user(old_setting,
if (copy_to_user(old_setting, &old_spec, sizeof (old_spec))) { &old_spec, sizeof (old_spec)))
error = -EFAULT; error = -EFAULT;
}
}
return error; return error;
} }
static inline int static inline int do_timer_delete(struct k_itimer *timer)
do_timer_delete(struct k_itimer *timer)
{ {
timer->it_incr = 0; timer->it_incr = 0;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
if (timer_active(timer) && if (timer_active(timer) &&
!del_timer(&timer->it_timer) && !timer->it_requeue_pending) { !del_timer(&timer->it_timer) && !timer->it_requeue_pending)
/* /*
* It can only be active if on an other cpu. Since * It can only be active if on an other cpu. Since
* we have cleared the interval stuff above, it should * we have cleared the interval stuff above, it should
* clear once we release the spin lock. Of course once * clear once we release the spin lock. Of course once
* we do that anything could happen, including the * we do that anything could happen, including the
* complete melt down of the timer. So return with * complete melt down of the timer. So return with
* a "retry" exit status. * a "retry" exit status.
*/ */
return TIMER_RETRY; return TIMER_RETRY;
}
#else #else
del_timer(&timer->it_timer); del_timer(&timer->it_timer);
#endif #endif
...@@ -929,9 +872,8 @@ sys_timer_delete(timer_t timer_id) ...@@ -929,9 +872,8 @@ sys_timer_delete(timer_t timer_id)
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
int error; int error;
retry_delete: retry_delete:
#endif #endif
timer = lock_timer(timer_id, &flags); timer = lock_timer(timer_id, &flags);
if (!timer) if (!timer)
return -EINVAL; return -EINVAL;
...@@ -946,13 +888,9 @@ sys_timer_delete(timer_t timer_id) ...@@ -946,13 +888,9 @@ sys_timer_delete(timer_t timer_id)
#else #else
p_timer_del(&posix_clocks[timer->it_clock], timer); p_timer_del(&posix_clocks[timer->it_clock], timer);
#endif #endif
task_lock(timer->it_process); task_lock(timer->it_process);
list_del(&timer->list); list_del(&timer->list);
task_unlock(timer->it_process); task_unlock(timer->it_process);
/* /*
* This keeps any tasks waiting on the spin lock from thinking * This keeps any tasks waiting on the spin lock from thinking
* they got something (see the lock code above). * they got something (see the lock code above).
...@@ -963,20 +901,17 @@ sys_timer_delete(timer_t timer_id) ...@@ -963,20 +901,17 @@ sys_timer_delete(timer_t timer_id)
return 0; return 0;
} }
/* /*
* return timer owned by the process, used by exit_itimers * return timer owned by the process, used by exit_itimers
*/ */
static inline void static inline void itimer_delete(struct k_itimer *timer)
itimer_delete(struct k_itimer *timer)
{ {
if (sys_timer_delete(timer->it_id)) { if (sys_timer_delete(timer->it_id))
BUG(); BUG();
}
} }
/* /*
* This is exported to exit and exec * This is exported to exit and exec
*/ */
void void exit_itimers(struct task_struct *tsk)
exit_itimers(struct task_struct *tsk)
{ {
struct k_itimer *tmr; struct k_itimer *tmr;
...@@ -992,18 +927,15 @@ exit_itimers(struct task_struct *tsk) ...@@ -992,18 +927,15 @@ exit_itimers(struct task_struct *tsk)
/* /*
* And now for the "clock" calls * And now for the "clock" calls
*
* These functions are called both from timer functions (with the timer * These functions are called both from timer functions (with the timer
* spin_lock_irq() held and from clock calls with no locking. They must * spin_lock_irq() held and from clock calls with no locking. They must
* use the save flags versions of locks. * use the save flags versions of locks.
*/ */
static int static int do_posix_gettime(struct k_clock *clock, struct timespec *tp)
do_posix_gettime(struct k_clock *clock, struct timespec *tp)
{ {
if (clock->clock_get)
if (clock->clock_get) {
return clock->clock_get(tp); return clock->clock_get(tp);
}
do_gettimeofday((struct timeval *) tp); do_gettimeofday((struct timeval *) tp);
tp->tv_nsec *= NSEC_PER_USEC; tp->tv_nsec *= NSEC_PER_USEC;
...@@ -1013,27 +945,24 @@ do_posix_gettime(struct k_clock *clock, struct timespec *tp) ...@@ -1013,27 +945,24 @@ do_posix_gettime(struct k_clock *clock, struct timespec *tp)
/* /*
* We do ticks here to avoid the irq lock ( they take sooo long). * We do ticks here to avoid the irq lock ( they take sooo long).
* The seqlock is great here. Since we a reader, we don't really care * The seqlock is great here. Since we a reader, we don't really care
* if we are interrupted since we don't take lock that will stall us or * if we are interrupted since we don't take lock that will stall us or
* any other cpu. Voila, no irq lock is needed. * any other cpu. Voila, no irq lock is needed.
*
* Note also that the while loop assures that the sub_jiff_offset * Note also that the while loop assures that the sub_jiff_offset
* will be less than a jiffie, thus no need to normalize the result. * will be less than a jiffie, thus no need to normalize the result.
* Well, not really, if called with ints off :( * Well, not really, if called with ints off :(
*
* HELP, this code should make an attempt at resolution beyond the * HELP, this code should make an attempt at resolution beyond the
* jiffie. Trouble is this is "arch" dependent... * jiffie. Trouble is this is "arch" dependent...
*/ */
int int do_posix_clock_monotonic_gettime(struct timespec *tp)
do_posix_clock_monotonic_gettime(struct timespec *tp)
{ {
long sub_sec; long sub_sec;
u64 jiffies_64_f; u64 jiffies_64_f;
#if (BITS_PER_LONG > 32) #if (BITS_PER_LONG > 32)
jiffies_64_f = jiffies_64; jiffies_64_f = jiffies_64;
#else #else
unsigned int seq; unsigned int seq;
...@@ -1041,17 +970,15 @@ do_posix_clock_monotonic_gettime(struct timespec *tp) ...@@ -1041,17 +970,15 @@ do_posix_clock_monotonic_gettime(struct timespec *tp)
seq = read_seqbegin(&xtime_lock); seq = read_seqbegin(&xtime_lock);
jiffies_64_f = jiffies_64; jiffies_64_f = jiffies_64;
}while( read_seqretry(&xtime_lock, seq)); } while (read_seqretry(&xtime_lock, seq));
#endif #endif
tp->tv_sec = div_long_long_rem(jiffies_64_f, HZ, &sub_sec); tp->tv_sec = div_long_long_rem(jiffies_64_f, HZ, &sub_sec);
tp->tv_nsec = sub_sec * (NSEC_PER_SEC / HZ); tp->tv_nsec = sub_sec * (NSEC_PER_SEC / HZ);
return 0; return 0;
} }
int int do_posix_clock_monotonic_settime(struct timespec *tp)
do_posix_clock_monotonic_settime(struct timespec *tp)
{ {
return -EINVAL; return -EINVAL;
} }
...@@ -1062,15 +989,17 @@ sys_clock_settime(clockid_t which_clock, const struct timespec *tp) ...@@ -1062,15 +989,17 @@ sys_clock_settime(clockid_t which_clock, const struct timespec *tp)
struct timespec new_tp; struct timespec new_tp;
if ((unsigned) which_clock >= MAX_CLOCKS || if ((unsigned) which_clock >= MAX_CLOCKS ||
!posix_clocks[which_clock].res) return -EINVAL; !posix_clocks[which_clock].res)
return -EINVAL;
if (copy_from_user(&new_tp, tp, sizeof (*tp))) if (copy_from_user(&new_tp, tp, sizeof (*tp)))
return -EFAULT; return -EFAULT;
if (posix_clocks[which_clock].clock_set) { if (posix_clocks[which_clock].clock_set)
return posix_clocks[which_clock].clock_set(&new_tp); return posix_clocks[which_clock].clock_set(&new_tp);
}
new_tp.tv_nsec /= NSEC_PER_USEC; new_tp.tv_nsec /= NSEC_PER_USEC;
return do_sys_settimeofday((struct timeval *) &new_tp, NULL); return do_sys_settimeofday((struct timeval *) &new_tp, NULL);
} }
asmlinkage long asmlinkage long
sys_clock_gettime(clockid_t which_clock, struct timespec *tp) sys_clock_gettime(clockid_t which_clock, struct timespec *tp)
{ {
...@@ -1078,38 +1007,37 @@ sys_clock_gettime(clockid_t which_clock, struct timespec *tp) ...@@ -1078,38 +1007,37 @@ sys_clock_gettime(clockid_t which_clock, struct timespec *tp)
int error = 0; int error = 0;
if ((unsigned) which_clock >= MAX_CLOCKS || if ((unsigned) which_clock >= MAX_CLOCKS ||
!posix_clocks[which_clock].res) return -EINVAL; !posix_clocks[which_clock].res)
return -EINVAL;
error = do_posix_gettime(&posix_clocks[which_clock], &rtn_tp); error = do_posix_gettime(&posix_clocks[which_clock], &rtn_tp);
if (!error) { if (!error && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
if (copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) { error = -EFAULT;
error = -EFAULT;
}
}
return error; return error;
} }
asmlinkage long asmlinkage long
sys_clock_getres(clockid_t which_clock, struct timespec *tp) sys_clock_getres(clockid_t which_clock, struct timespec *tp)
{ {
struct timespec rtn_tp; struct timespec rtn_tp;
if ((unsigned) which_clock >= MAX_CLOCKS || if ((unsigned) which_clock >= MAX_CLOCKS ||
!posix_clocks[which_clock].res) return -EINVAL; !posix_clocks[which_clock].res)
return -EINVAL;
rtn_tp.tv_sec = 0; rtn_tp.tv_sec = 0;
rtn_tp.tv_nsec = posix_clocks[which_clock].res; rtn_tp.tv_nsec = posix_clocks[which_clock].res;
if (tp) { if (tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp)))
if (copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) { return -EFAULT;
return -EFAULT;
}
}
return 0; return 0;
} }
static void
nanosleep_wake_up(unsigned long __data) static void nanosleep_wake_up(unsigned long __data)
{ {
struct task_struct *p = (struct task_struct *) __data; struct task_struct *p = (struct task_struct *) __data;
...@@ -1119,29 +1047,27 @@ nanosleep_wake_up(unsigned long __data) ...@@ -1119,29 +1047,27 @@ nanosleep_wake_up(unsigned long __data)
/* /*
* The standard says that an absolute nanosleep call MUST wake up at * The standard says that an absolute nanosleep call MUST wake up at
* the requested time in spite of clock settings. Here is what we do: * the requested time in spite of clock settings. Here is what we do:
* For each nanosleep call that needs it (only absolute and not on * For each nanosleep call that needs it (only absolute and not on
* CLOCK_MONOTONIC* (as it can not be set)) we thread a little structure * CLOCK_MONOTONIC* (as it can not be set)) we thread a little structure
* into the "nanosleep_abs_list". All we need is the task_struct pointer. * into the "nanosleep_abs_list". All we need is the task_struct pointer.
* When ever the clock is set we just wake up all those tasks. The rest * When ever the clock is set we just wake up all those tasks. The rest
* is done by the while loop in clock_nanosleep(). * is done by the while loop in clock_nanosleep().
*
* On locking, clock_was_set() is called from update_wall_clock which * On locking, clock_was_set() is called from update_wall_clock which
* holds (or has held for it) a write_lock_irq( xtime_lock) and is * holds (or has held for it) a write_lock_irq( xtime_lock) and is
* called from the timer bh code. Thus we need the irq save locks. * called from the timer bh code. Thus we need the irq save locks.
*/ */
static DECLARE_WAIT_QUEUE_HEAD(nanosleep_abs_wqueue); static DECLARE_WAIT_QUEUE_HEAD(nanosleep_abs_wqueue);
void clock_was_set(void)
void
clock_was_set(void)
{ {
wake_up_all(&nanosleep_abs_wqueue); wake_up_all(&nanosleep_abs_wqueue);
} }
long clock_nanosleep_restart(struct restart_block *restart_block); long clock_nanosleep_restart(struct restart_block *restart_block);
extern long do_clock_nanosleep(clockid_t which_clock, int flags, extern long do_clock_nanosleep(clockid_t which_clock, int flags,
struct timespec *t); struct timespec *t);
#ifdef FOLD_NANO_SLEEP_INTO_CLOCK_NANO_SLEEP #ifdef FOLD_NANO_SLEEP_INTO_CLOCK_NANO_SLEEP
...@@ -1160,9 +1086,9 @@ sys_nanosleep(struct timespec *rqtp, struct timespec *rmtp) ...@@ -1160,9 +1086,9 @@ sys_nanosleep(struct timespec *rqtp, struct timespec *rmtp)
ret = do_clock_nanosleep(CLOCK_REALTIME, 0, &t); ret = do_clock_nanosleep(CLOCK_REALTIME, 0, &t);
if (ret == -ERESTART_RESTARTBLOCK && rmtp && if (ret == -ERESTART_RESTARTBLOCK && rmtp &&
copy_to_user(rmtp, &t, sizeof (t))) copy_to_user(rmtp, &t, sizeof (t)))
return -EFAULT; return -EFAULT;
return ret; return ret;
} }
#endif // ! FOLD_NANO_SLEEP_INTO_CLOCK_NANO_SLEEP #endif // ! FOLD_NANO_SLEEP_INTO_CLOCK_NANO_SLEEP
...@@ -1175,7 +1101,8 @@ sys_clock_nanosleep(clockid_t which_clock, int flags, ...@@ -1175,7 +1101,8 @@ sys_clock_nanosleep(clockid_t which_clock, int flags,
int ret; int ret;
if ((unsigned) which_clock >= MAX_CLOCKS || if ((unsigned) which_clock >= MAX_CLOCKS ||
!posix_clocks[which_clock].res) return -EINVAL; !posix_clocks[which_clock].res)
return -EINVAL;
if (copy_from_user(&t, rqtp, sizeof (struct timespec))) if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
return -EFAULT; return -EFAULT;
...@@ -1185,11 +1112,10 @@ sys_clock_nanosleep(clockid_t which_clock, int flags, ...@@ -1185,11 +1112,10 @@ sys_clock_nanosleep(clockid_t which_clock, int flags,
ret = do_clock_nanosleep(which_clock, flags, &t); ret = do_clock_nanosleep(which_clock, flags, &t);
if ((ret == -ERESTART_RESTARTBLOCK) && rmtp && if ((ret == -ERESTART_RESTARTBLOCK) && rmtp &&
copy_to_user(rmtp, &t, sizeof (t))) copy_to_user(rmtp, &t, sizeof (t)))
return -EFAULT; return -EFAULT;
return ret; return ret;
} }
long long
...@@ -1228,9 +1154,8 @@ do_clock_nanosleep(clockid_t which_clock, int flags, struct timespec *tsave) ...@@ -1228,9 +1154,8 @@ do_clock_nanosleep(clockid_t which_clock, int flags, struct timespec *tsave)
} }
if (abs && (posix_clocks[which_clock].clock_get != if (abs && (posix_clocks[which_clock].clock_get !=
posix_clocks[CLOCK_MONOTONIC].clock_get)) { posix_clocks[CLOCK_MONOTONIC].clock_get))
add_wait_queue(&nanosleep_abs_wqueue, &abs_wqueue); add_wait_queue(&nanosleep_abs_wqueue, &abs_wqueue);
}
do { do {
t = *tsave; t = *tsave;
...@@ -1291,8 +1216,8 @@ clock_nanosleep_restart(struct restart_block *restart_block) ...@@ -1291,8 +1216,8 @@ clock_nanosleep_restart(struct restart_block *restart_block)
struct timespec t; struct timespec t;
int ret = do_clock_nanosleep(restart_block->arg0, 0, &t); int ret = do_clock_nanosleep(restart_block->arg0, 0, &t);
if ((ret == -ERESTART_RESTARTBLOCK) && restart_block->arg1 && if ((ret == -ERESTART_RESTARTBLOCK) && restart_block->arg1 &&
copy_to_user((struct timespec *)(restart_block->arg1), &t, copy_to_user((struct timespec *)(restart_block->arg1), &t,
sizeof (t))) sizeof (t)))
return -EFAULT; return -EFAULT;
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment