make ITIMER_PROF, ITIMER_VIRTUAL per-process
Subsystems (3)
PATCH 5/7 make ITIMER_PROF, ITIMER_VIRTUAL per-process
POSIX requires that setitimer, getitimer, and alarm work on a per-process basis. Currently, Linux implements these for individual threads. This patch fixes these semantics for the ITIMER_PROF timer (which generates SIGPROF) and the ITIMER_VIRTUAL timer (which generates SIGVTALRM), making them shared by all threads in a process (thread group).
This patch should be applied after the one that fixes ITIMER_REAL.
The essential machinery for these timers is tied into the new posix-timers code for process CPU clocks and timers. This patch requires the cputimers patch and its dependencies.
Signed-off-by Roland McGrath <[email protected]>
include/linux/posix-timers.h +3 -0
@@ -127,4 +127,7 @@ void run_posix_cpu_timers(struct task_stvoid posix_cpu_timers_exit (struct task_struct *);void posix_cpu_timers_exit_group (struct task_struct *); +void set_process_cpu_timer (struct task_struct *,unsigned int , +unsigned long *,unsigned long *); +#endif
include/linux/sched.h +4 -2
@@ -297,6 +297,10 @@ struct signal_struct {struct timer_list real_timer;unsigned long it_real_value, it_real_incr; +/* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */ +unsigned long it_prof_expires, it_virt_expires; +unsigned long it_prof_incr, it_virt_incr; +/* job control IDs */ pid_t pgrp;pid_t tty_old_pgrp;
@@ -602,8 +606,6 @@ struct task_struct {int __user *clear_child_tid;/* CLONE_CHILD_CLEARTID */ unsigned long rt_priority; -unsigned long it_prof_value, it_virt_value; -unsigned long it_prof_incr, it_virt_incr;unsigned long utime, stime;unsigned long nvcsw, nivcsw;/* context switch counts */ struct timespec start_time;
include/linux/signal.h +1 -0
@@ -212,6 +212,7 @@ static inline void init_sigpending(struc }extern int group_send_sig_info (int sig,struct siginfo *info,struct task_struct *p); +extern int __group_send_sig_info (int ,struct siginfo *,struct task_struct *);extern long do_sigpending (void __user *,unsigned long );extern int sigprocmask (int ,sigset_t *,sigset_t *);
kernel/exit.c +0 -2
@@ -759,8 +759,6 @@ static void exit_notify(struct task_stru* Clear these here so that update_process_times() won't try to deliver * itimer, profile or rlimit signals to this task while it is in late exit. */ - tsk->it_virt_value =0 ; - tsk->it_prof_value =0 ; tsk->it_virt_expires =0 ; tsk->it_prof_expires =0 ; tsk->it_sched_expires =0 ;
kernel/fork.c +6 -4
@@ -743,6 +743,9 @@ static inline int copy_signal(unsigned l sig->real_timer.data = (unsigned long ) tsk;init_timer (&sig->real_timer); + sig->it_virt_expires = sig->it_prof_expires =0 ; + sig->it_virt_incr = sig->it_prof_incr =0 ; + sig->tty = current->signal->tty; sig->pgrp =process_group (current); sig->session = current->signal->session;
@@ -874,9 +877,6 @@ static task_t *copy_process(unsigned lonclear_tsk_thread_flag (p,TIF_SIGPENDING );init_sigpending (&p->pending); - p->it_virt_value = p->it_prof_value =0 ; - p->it_virt_incr = p->it_prof_incr =0 ; - p->utime = p->stime =0 ; p->sched_time =0 ; p->it_virt_expires = p->it_prof_expires =0 ;
@@ -1017,7 +1017,9 @@ static task_t *copy_process(unsigned lonset_tsk_thread_flag (p,TIF_SIGPENDING ); } -if (!list_empty (¤t->signal->cpu_timers[0 ]) || +if (current->signal->it_virt_expires !=0 || + current->signal->it_prof_expires !=0 || + !list_empty (¤t->signal->cpu_timers[0 ]) || !list_empty (¤t->signal->cpu_timers[1 ]) || !list_empty (¤t->signal->cpu_timers[2 ])) {/*
kernel/itimer.c +86 -34
154 lines not on this page · raw message
kernel/posix-cpu-timers.c +135 -26
258 lines not on this page · raw message
kernel/posix-timers.c +2 -2
@@ -1271,7 +1271,7 @@ sys_clock_gettime(clockid_t which_clock,return posix_cpu_clock_gettime (which_clock, tp);if ((unsigned ) which_clock >=MAX_CLOCKS || - !posix_clocks[which_clock].res) + !posix_clocks[which_clock].res)return -EINVAL ; error =do_posix_gettime (&posix_clocks[which_clock], &kernel_tp);
@@ -1398,7 +1398,7 @@ void clock_was_set(void)break ; } timr = list_entry(cws_list.next, struct k_itimer, - it.real.abs_timer_entry); + it.real.abs_timer_entry);list_del_init (&timr->it.real.abs_timer_entry); if (add_clockset_delta(timr, &new_wall_to) &&
kernel/signal.c +16 -16
@@ -550,21 +550,21 @@ int dequeue_signal(struct task_struct *tif (!signr) signr =__dequeue_signal (&tsk->signal->shared_pending, mask, info); -if (signr &&unlikely (sig_kernel_stop (signr))) { -/* -* Set a marker that we have dequeued a stop signal. Our -* caller might release the siglock and then the pending -* stop signal it is about to process is no longer in the -* pending bitmasks, but must still be cleared by a SIGCONT -* (and overruled by a SIGKILL). So those cases clear this -* shared flag after we've set it. Note that this flag may -* remain set after the signal we return is ignored or -* handled. That doesn't matter because its only purpose -* is to alert stop-signal processing code when another -* processor has come along and cleared the flag. -*/ - tsk->signal->flags |=SIGNAL_STOP_DEQUEUED ; - } +if (signr &&unlikely (sig_kernel_stop (signr))) { +/* +* Set a marker that we have dequeued a stop signal. Our +* caller might release the siglock and then the pending +* stop signal it is about to process is no longer in the +* pending bitmasks, but must still be cleared by a SIGCONT +* (and overruled by a SIGKILL). So those cases clear this +* shared flag after we've set it. Note that this flag may +* remain set after the signal we return is ignored or +* handled. That doesn't matter because its only purpose +* is to alert stop-signal processing code when another +* processor has come along and cleared the flag. +*/ + tsk->signal->flags |=SIGNAL_STOP_DEQUEUED ; + }if ( signr && ((info->si_code & __SI_MASK) == __SI_TIMER) && info->si_sys_private){
@@ -1046,7 +1046,7 @@ __group_complete_signal(int sig, structreturn ; } -static int +int __group_send_sig_info (int sig,struct siginfo *info,struct task_struct *p) {int ret =0 ;
kernel/timer.c +0 -29
@@ -818,39 +818,10 @@ static inline void do_process_times(stru } } -static inline void do_it_virt (struct task_struct * p,unsigned long ticks) -{ -unsigned long it_virt = p->it_virt_value; - -if (it_virt) { - it_virt -= ticks; -if (!it_virt) { - it_virt = p->it_virt_incr; -send_sig (SIGVTALRM , p,1 ); - } - p->it_virt_value = it_virt; - } -} - -static inline void do_it_prof (struct task_struct *p) -{ -unsigned long it_prof = p->it_prof_value; - -if (it_prof) { -if (--it_prof ==0 ) { - it_prof = p->it_prof_incr; -send_sig (SIGPROF , p,1 ); - } - p->it_prof_value = it_prof; - } -} -static void update_one_process (struct task_struct *p,unsigned long user,unsigned long system,int cpu) {do_process_times (p, user, system); -do_it_virt (p, user); -do_it_prof (p); }/*