CPU POSIX timers livelock
Subsystems (7)
Hello,
there seems to be a possible livelock in the CPU timers (actually, we've experienced it once already). The analysis lead to the conclusion that fixing this properly will be a bit harder.
Problem Statement
1. Any process can set ITIMER_PROF as short as 1 timer tick
2. If the process is CPU-bound (e.g. a number-crunching application), the timer will expire with every timer tick
3. If the process has N threads and each thread runs on its own CPU, the timer will expire N times per timer tick
Now, this can become quite interesting on a larger system. For instance, with 128 CPUs and a (conservative) setting of HZ 300, any process can effectively ask to be sent a SIGPROF every 26 usec (1/300/128 s). Pretty fast, but it can get worse if you consider the pitfalls of a NUMA architecture.
Whenever the timer expires, a new expiration time must be computed for each thread in the thread group. The values are stored in task_struct of each thread, and IIRC those are kept local to the CPU where the thread is running (quite logically). Put in another way, walking all threads means touching remote memory except for the few task_struct which are local to the recomputing CPU. In the 128-CPU example, if each node has 2 CPUs (think Altix), only 2 accesses are to the local node and 126 accesses are to remote memory. These are already quite expensive, but it gets even worse. The timer interrupt is generated locally for each CPU, so if the process is spread over all of them (see above), all CPUs recompute the timer (hint: write access), thus constantly invalidating local caches of the remote memory.
And those computations cannot run in parallel, of course, because everything is serialized on sighand->siglock (see run_posix_cpu_timers). So, each time one CPU finishes walking the threads, there's already a queue of all the other CPUs waiting to do the same again. For this kind of load, those 26 usec (approx. 41600 CPU cycles on a 1.6 GHz CPU) may be well insufficient. Even more so, if somebody else occasionally takes write lock on tasklist_lock. It may so happen that the system spends all CPU cycles re-computing the profiling timers over and over again and never make any progress. Note this is partly caused by the fact that the time needed to handle the profiling timer is itself also counted to the profiling time.
This simply does not scale for large systems (and I was not even considering those really large 1024p ones).
Ideas
Any ideas for improvement? Obviously, storing per-process expiration times in one place instead of dividing the interval by the number of currently running threads would help here. But it would spoil the fast path (when there are no timers at all). Avoiding that multiple threads re-compute the same values might also help (although I've got no idea how to implement this).
Any more comments (before I start hacking something you'll NAK)?
BTW did POSIX really mean to allow an indefinitely small interval for the SIGPROF?
Petr Tesarik
[Added Roland McGrath and Frank Mayhar to Cc:, as this sounds similar enough to what has been discussed here http://lkml.org/lkml/2008/2/6/505]
Quoted 63 lines · Petr Tesarik
Hello,
there seems to be a possible livelock in the CPU timers (actually, we've experienced it once already). The analysis lead to the conclusion that fixing this properly will be a bit harder.
Problem Statement
1. Any process can set
ITIMER_PROFas short as 1 timer tick
2. If the process is CPU-bound (e.g. a number-crunching application), the timer will expire with every timer tick
3. If the process has N threads and each thread runs on its own CPU, the timer will expire N times per timer tickNow, this can become quite interesting on a larger system. For instance, with 128 CPUs and a (conservative) setting of HZ 300, any process can effectively ask to be sent a SIGPROF every 26 usec (1/300/128 s). Pretty fast, but it can get worse if you consider the pitfalls of a NUMA architecture.
Whenever the timer expires, a new expiration time must be computed for each thread in the thread group. The values are stored in
task_structof each thread, and IIRC those are kept local to the CPU where the thread is running (quite logically). Put in another way, walking all threads means touching remote memory except for the fewtask_structwhich are local to the recomputing CPU. In the 128-CPU example, if each node has 2 CPUs (think Altix), only 2 accesses are to the local node and 126 accesses are to remote memory. These are already quite expensive, but it gets even worse. The timer interrupt is generated locally for each CPU, so if the process is spread over all of them (see above), all CPUs recompute the timer (hint: write access), thus constantly invalidating local caches of the remote memory.And those computations cannot run in parallel, of course, because everything is serialized on
sighand->siglock(seerun_posix_cpu_timers). So, each time one CPU finishes walking the threads, there's already a queue of all the other CPUs waiting to do the same again. For this kind of load, those 26 usec (approx. 41600 CPU cycles on a 1.6 GHz CPU) may be well insufficient. Even more so, if somebody else occasionally takes write lock ontasklist_lock. It may so happen that the system spends all CPU cycles re-computing the profiling timers over and over again and never make any progress. Note this is partly caused by the fact that the time needed to handle the profiling timer is itself also counted to the profiling time.This simply does not scale for large systems (and I was not even considering those really large 1024p ones).
Ideas
Any ideas for improvement? Obviously, storing per-process expiration times in one place instead of dividing the interval by the number of currently running threads would help here. But it would spoil the fast path (when there are no timers at all). Avoiding that multiple threads re-compute the same values might also help (although I've got no idea how to implement this).
Any more comments (before I start hacking something you'll NAK)?
BTW did POSIX really mean to allow an indefinitely small interval for the SIGPROF?
Petr Tesarik
Quoted 2 lines · Björn Steinbrink
[Added Roland McGrath and Frank Mayhar to Cc:, as this sounds similar enough to what has been discussed here http://lkml.org/lkml/2008/2/6/505]
Yes, I've just now found the thread too, read it, and I think this is just another case where the current implementation does not scale.
Was there any followup to the patch posted on the 7th of March? The interesting discussion seems to be interrupted there. :(
Petr Tesarik
Quoted 69 lines · Petr Tesarik
Quoted 57 lines
Hello,
there seems to be a possible livelock in the CPU timers (actually, we've experienced it once already). The analysis lead to the conclusion that fixing this properly will be a bit harder.
Problem Statement
1. Any process can set
ITIMER_PROFas short as 1 timer tick
2. If the process is CPU-bound (e.g. a number-crunching application), the timer will expire with every timer tick
3. If the process has N threads and each thread runs on its own CPU, the timer will expire N times per timer tickNow, this can become quite interesting on a larger system. For instance, with 128 CPUs and a (conservative) setting of HZ 300, any process can effectively ask to be sent a SIGPROF every 26 usec (1/300/128 s). Pretty fast, but it can get worse if you consider the pitfalls of a NUMA architecture.
Whenever the timer expires, a new expiration time must be computed for each thread in the thread group. The values are stored in
task_structof each thread, and IIRC those are kept local to the CPU where the thread is running (quite logically). Put in another way, walking all threads means touching remote memory except for the fewtask_structwhich are local to the recomputing CPU. In the 128-CPU example, if each node has 2 CPUs (think Altix), only 2 accesses are to the local node and 126 accesses are to remote memory. These are already quite expensive, but it gets even worse. The timer interrupt is generated locally for each CPU, so if the process is spread over all of them (see above), all CPUs recompute the timer (hint: write access), thus constantly invalidating local caches of the remote memory.And those computations cannot run in parallel, of course, because everything is serialized on
sighand->siglock(seerun_posix_cpu_timers). So, each time one CPU finishes walking the threads, there's already a queue of all the other CPUs waiting to do the same again. For this kind of load, those 26 usec (approx. 41600 CPU cycles on a 1.6 GHz CPU) may be well insufficient. Even more so, if somebody else occasionally takes write lock ontasklist_lock. It may so happen that the system spends all CPU cycles re-computing the profiling timers over and over again and never make any progress. Note this is partly caused by the fact that the time needed to handle the profiling timer is itself also counted to the profiling time.This simply does not scale for large systems (and I was not even considering those really large 1024p ones).
Ideas
Any ideas for improvement? Obviously, storing per-process expiration times in one place instead of dividing the interval by the number of currently running threads would help here. But it would spoil the fast path (when there are no timers at all). Avoiding that multiple threads re-compute the same values might also help (although I've got no idea how to implement this).
Quoted 6 lines
Any more comments (before I start hacking something you'll NAK)?
BTW did POSIX really mean to allow an indefinitely small interval for the SIGPROF?
Petr Tesarik
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 9 lines · Petr Tesarik
Quoted 2 lines · Björn Steinbrink
[Added Roland McGrath and Frank Mayhar to Cc:, as this sounds similar enough to what has been discussed here http://lkml.org/lkml/2008/2/6/505]
Yes, I've just now found the thread too, read it, and I think this is just another case where the current implementation does not scale.
Was there any followup to the patch posted on the 7th of March? The interesting discussion seems to be interrupted there. :(
Hm, I have some message in that thread from April they don't seem to be on lkml.org nor in the bugzilla though. Oh well, I can send you an mbox of that thread in a private mail, just let me know if you want that.
Björn
Quoted 4 lines · Bj?rn Steinbrink
Hm, I have some message in that thread from April they don't seem to be on lkml.org nor in the bugzilla though. Oh well, I can send you an mbox of that thread in a private mail, just let me know if you want that.
Me too please ;)
Please note there is a related problem if we have a single thread but a lot of timers attached to this thread. If the signal is ignored, each timer should be re-armed, this all can consume >= 1/HZ CPU time. We have "maxfire = 20" in check_thread_timers/check_process_timers to prevent this, but it is just a workaround. And it is a bit silly to just waste the CPU if the signal is ignored, arm_timer() is heavy and doesn't scale well.
However, I have already forgot this code, perhaps I missed something, and at least maxfire does help.
Oleg.
Quoted 9 lines · Petr Tesarik
Quoted 2 lines · Björn Steinbrink
[Added Roland McGrath and Frank Mayhar to Cc:, as this sounds similar enough to what has been discussed here http://lkml.org/lkml/2008/2/6/505]
Yes, I've just now found the thread too, read it, and I think this is just another case where the current implementation does not scale.
Was there any followup to the patch posted on the 7th of March? The interesting discussion seems to be interrupted there. :(
Roland and I have continued the conversation but we took it off the LKML since it was really getting into the nitty-gritty details of the implementation and wasn't that interesting to someone not actually directly involved.
The upshot is that I have a proposed patch that I have handed to Roland to review. He's pretty busy, though, so he may not have gotten to it yet. Perhaps this thread will give him further incentive. :-)
Petr's analysis pretty much matches mine, except that he went into a bit more detail in actually computing numbers and whatnot whereas I just reasoned that with a sufficiently large number of threads pretty much any process that uses POSIX timers can cause the system to livelock, simply because repeatedly running the thread group list in run_posix_cpu_timers() will at some point take as long as the timer tick itself.
My proposed patch that Roland is reviewing corrects the implementation of run_posix_cpu_timers() to make it run in constant time for a particular machine by defining a couple of new structures and keeping the thread group timers in one of these. It's way more complex than this and I have a README that goes into detail if anyone is interested.
I've tested the patch with as many as 200,000 threads (all of which are running a prime number sieve and are therefore CPU bound) and it appears to work fine. Before I post it again, though, I want Roland to sign off on it.
Signature · 2 lines
Frank Mayhar <[email protected]> Google, Inc.
Re: CPU POSIX timers livelock (with patch for review)
In reply to Björn SteinbrinkAs I think I promised when this thread was fresh, here is the patch that I've been working up with Roland. It's ready for public review and I'll be formally submitting it soon. Actually I think it's really ready for submission, but I wanted to give it a bit of exposure first.
The README follows. It has gone through two or three revisions; I've vetted it to make sure it matches the actual code but if I've missed anything, please let me know.
----- README -----
This patch reworks the handling of POSIX CPU timers, including the ITIMER_PROF, ITIMER_VIRT timers and rlimit handling. It was put together with the help of Roland McGrath, the owner and original writer of this code.
The problem we ran into, and the reason for this rework, has to do with using a profiling timer in a process with a large number of threads. It appears that the performance of the old implementation of run_posix_cpu_timers() was at least O(n*3) (where "n" is the number of threads in a process) or worse. Everything is fine with an increasing number of threads until the time taken for that routine to run becomes the same as or greater than the tick time, at which point things degrade rather quickly.
This rework corrects the implementation of run_posix_cpu_timers() to make it run in constant time for a particular machine. (Performance may vary between one machine and another depending upon whether the kernel is built as single- or multiprocessor and, in the latter case, depending upon the number of running processors.) To do this, at each tick we now update fields in signal_struct as well as task_struct. The run_posix_cpu_timers() function uses those fields to make its decisions.
We define a new structure, "task_cputime," to contain user, system and scheduler times and use these in appropriate places:
struct task_cputime {
cputime_t utime;
cputime_t stime;
unsigned long long sum_exec_runtime;
};Including in the new structure "thread_group_cputime," which is a new substructure of signal_struct and which varies for uniprocessor versus multiprocessor kernels. For uniprocessor kernels, it uses "task_cputime" as a simple substructure, while for multiprocessor kernels it is a pointer:
struct thread_group_cputime {
struct task_cputime totals;
};struct thread_group_cputime {
struct task_cputime *totals;
};We also add a new task_cputime substructure directly to signal_struct, to cache the earliest expiration of process-wide timers, and task_cputime also replaces the it_*_expires fields of task_struct (used for earliest expiration of thread timers). The "thread_group_cputime" structure contains process-wide timers that are updated via account_user_time() and friends. In the non-SMP case the structure is a simple aggregator; unfortunately in the SMP case that simplicity was not achievable due to cache-line contention between CPUs (in one measured case performance was actually _worse_ on a 16-cpu system than the same test on a 4-cpu system, due to this contention). For SMP, the thread_group_cputime counters are maintained as a per-cpu structure allocated using alloc_percpu(). The timer functions update only the timer field in the structure corresponding to the running CPU, obtained using per_cpu_ptr().
We define a set of inline functions in sched.h that we use to maintain the thread_group_cputime structure and hide the differences between UP and SMP implementations from the rest of the kernel. The thread_group_cputime_init() function initializes the thread_group_cputime structure for the given task. The thread_group_cputime_alloc() is a no-op for UP; for SMP it calls the out-of-line function thread_group_cputime_alloc_smp() to allocate and fill in the per-cpu structures and fields. The thread_group_cputime_free() function, also a no-op for UP, in SMP frees the per-cpu structures. The thread_group_cputime_clone_thread() function (also a UP no-op) for SMP calls thread_group_cputime_alloc() if the per-cpu structures haven't yet been allocated. The thread_group_cputime() function fills the task_cputime structure it is passed with the contents of the thread_group_cputime fields; in UP it's that simple but in SMP it must also safely check that tsk->signal is non-NULL (if it is it just uses the appropriate fields of task_struct) and, if so, sums the per-cpu values for each online CPU. Finally, the three functions account_group_user_time(), account_group_system_time() and account_group_exec_runtime() are used by timer functions to update the respective fields of the thread_group_cputime structure.
Non-SMP operation is trivial and will not be mentioned further.
The per-cpu structure is always allocated when a task creates its first new thread, via a call to thread_group_cputime_clone_thread() from copy_signal(). It is freed at process exit via a call to thread_group_cputime_free() from cleanup_signal().
All functions that formerly summed utime/stime/sum_sched_runtime values from from all threads in the thread group now use thread_group_cputime() to snapshot the values in the thread_group_cputime structure or the values in the task structure itself if the per-cpu structure hasn't been allocated.
Finally, the code in kernel/posix-cpu-timers.c has changed quite a bit. The run_posix_cpu_timers() function has been split into a fast path and a slow path; the former safely checks whether there are any expired thread timers and, if not, just returns, while the slow path does the heavy lifting. With the dedicated thread group fields, timers are no longer "rebalanced" and the process_timer_rebalance() function and related code has gone away. All summing loops are gone and all code that used them now uses the thread_group_cputime() inline. When process-wide timers are set, the new task_cputime structure in signal_struct is used to cache the earliest expiration; this is checked in the fast path.
I have done some limited performance testing; it appears that the performance of the kernel with the fix is at least comparable to the performance without it, with the advantage that profiling processes with many threads will no longer hang the system. On a four-cpu Opteron system without this fix, a sixteen-thread test executed in 3569.991 seconds, of which user was 3568.435s and system was 1.556s. On the same system with the fix, user and elapsed time were about the same, but system time dropped to 0.007 seconds. Performance with eight, four and one thread were comparable. Interestingly, the timer ticks with the fix seemed more accurate: The sixteen-thread test with the fix received 149543 ticks for 0.024 seconds per tick, while the same test without the fix received 58720 for 0.061 seconds per tick. Both cases were configured for an interval of 0.01 seconds. Again, the other tests were comparable. Each thread in this test computed the primes up to 25,000,000
I also did a test with a large number of threads, 100,000 threads, which is impossible without the fix. In this case each thread computed the primes only up to 10,000 (to make the runtime manageable). System time dominated, at 1546.968 seconds out of a total 2176.906 seconds (giving a user time of 629.938s). It received 147651 ticks for 0.015 seconds per tick, still quite accurate. There is obviously no comparable test without the fix.
I hope to provide more statistics soon.
----- README -----
Here's the patch:
------ PATCH ------
fs/binfmt_elf.c | 19 +-- fs/proc/array.c | 8 +- include/linux/posix-timers.h | 2 + include/linux/sched.h | 286 +++++++++++++++++++++++++++-- include/linux/time.h | 3 + kernel/compat.c | 53 ++---- kernel/exit.c | 19 +- kernel/fork.c | 93 +++++----- kernel/itimer.c | 33 +--- kernel/posix-cpu-timers.c | 419 ++++++++++++++++++++---------------------- kernel/sched.c | 53 +++++- kernel/sched_fair.c | 1 + kernel/sched_rt.c | 5 +- kernel/signal.c | 8 +- kernel/sys.c | 75 +++----- security/selinux/hooks.c | 9 +- 16 files changed, 656 insertions(+), 430 deletions(-)
fs/binfmt_elf.c +7 -12
@@ -1313,20 +1313,15 @@ static void fill_prstatus(struct elf_prstatus *prstatus, prstatus->pr_pgrp =task_pgrp_vnr (p); prstatus->pr_sid =task_session_vnr (p);if (thread_group_leader (p)) { +struct task_cputime cputime; +/* -* This is the record for the group leader. Add in the -* cumulative times of previous dead threads. This total -* won't include the time of each live thread whose state -* is included in the core dump. The final total reported -* to our parent process when it calls wait4 will include -* those sums as well as the little bit more time it takes -* this and each other thread to finish dying after the -* core dump synchronization phase. +* This is the record for the group leader. It shows the +* group-wide total, not its individual thread total. */ -cputime_to_timeval (cputime_add (p->utime, p->signal->utime), - &prstatus->pr_utime); -cputime_to_timeval (cputime_add (p->stime, p->signal->stime), - &prstatus->pr_stime); +thread_group_cputime (p, &cputime); +cputime_to_timeval (cputime.utime, &prstatus->pr_utime); +cputime_to_timeval (cputime.stime, &prstatus->pr_stime); }else {cputime_to_timeval (p->utime, &prstatus->pr_utime);cputime_to_timeval (p->stime, &prstatus->pr_stime);
fs/proc/array.c +4 -4
@@ -448,20 +448,20 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,/* add up live thread stats at the group level */ if (whole) { +struct task_cputime cputime;struct task_struct *t = task;do { min_flt += t->min_flt; maj_flt += t->maj_flt; - utime =cputime_add (utime,task_utime (t)); - stime =cputime_add (stime,task_stime (t)); gtime =cputime_add (gtime,task_gtime (t)); t =next_thread (t); }while (t != task); min_flt += sig->min_flt; maj_flt += sig->maj_flt; - utime =cputime_add (utime, sig->utime); - stime =cputime_add (stime, sig->stime); +thread_group_cputime (task, &cputime); + utime = cputime.utime; + stime = cputime.stime; gtime =cputime_add (gtime, sig->gtime); }
include/linux/posix-timers.h +2 -0
@@ -115,4 +115,6 @@ void set_process_cpu_timer(struct task_struct *task, unsigned int clock_idx,long clock_nanosleep_restart (struct restart_block *restart_block); +void update_rlimit_cpu (unsigned long rlim_new); +#endif
include/linux/sched.h +273 -13
334 lines not on this page · raw message
include/linux/time.h +3 -0
@@ -124,6 +124,9 @@ extern int timekeeping_valid_for_hres(void);extern void update_wall_time (void );extern void update_xtime_cache (u64 nsec); +struct tms ; +extern void do_sys_times (struct tms *); +/** * timespec_to_ns - Convert timespec to nanoseconds * @ts: pointer to the timespec variable to be converted
kernel/compat.c +14 -39
69 lines not on this page · raw message
kernel/exit.c +10 -9
@@ -111,8 +111,6 @@ static void __exit_signal(struct task_struct *tsk)* We won't ever get here for the group leader, since it * will have been the last reference on the signal_struct. */ - sig->utime =cputime_add (sig->utime, tsk->utime); - sig->stime =cputime_add (sig->stime, tsk->stime); sig->gtime =cputime_add (sig->gtime, tsk->gtime); sig->min_flt += tsk->min_flt; sig->maj_flt += tsk->maj_flt;
@@ -120,7 +118,6 @@ static void __exit_signal(struct task_struct *tsk) sig->nivcsw += tsk->nivcsw; sig->inblock +=task_io_get_inblock (tsk); sig->oublock +=task_io_get_oublock (tsk); - sig->sum_sched_runtime += tsk->se.sum_exec_runtime; sig =NULL ;/* Marker for below. */ }
@@ -1273,6 +1270,7 @@ static int wait_task_zombie(struct task_struct *p, int noreap,if (likely (!traced)) {struct signal_struct *psig;struct signal_struct *sig; +struct task_cputime cputime;/* * The resource counters for the group leader are in its
@@ -1288,20 +1286,23 @@ static int wait_task_zombie(struct task_struct *p, int noreap,* need to protect the access to p->parent->signal fields, * as other threads in the parent group can be right * here reaping other children at the same time. +* +* We use thread_group_cputime() to get times for the thread +* group, which consolidates times for all threads in the +* group including the group leader. */ spin_lock_irq (&p->parent->sighand->siglock); psig = p->parent->signal; sig = p->signal; +thread_group_cputime (p, &cputime); psig->cutime =cputime_add (psig->cutime, -cputime_add (p->utime, -cputime_add (sig->utime, - sig->cutime))); +cputime_add (cputime.utime, + sig->cutime)); psig->cstime =cputime_add (psig->cstime, -cputime_add (p->stime, -cputime_add (sig->stime, - sig->cstime))); +cputime_add (cputime.stime, + sig->cstime)); psig->cgtime = cputime_add(psig->cgtime, cputime_add(p->gtime,
kernel/fork.c +51 -42
149 lines not on this page · raw message
kernel/itimer.c +10 -23
@@ -55,17 +55,15 @@ int do_getitimer(int which, struct itimerval *value)spin_unlock_irq (&tsk->sighand->siglock);break ;case ITIMER_VIRTUAL : -read_lock (&tasklist_lock);spin_lock_irq (&tsk->sighand->siglock); cval = tsk->signal->it_virt_expires; cinterval = tsk->signal->it_virt_incr;if (!cputime_eq (cval, cputime_zero)) { -struct task_struct *t = tsk; -cputime_t utime = tsk->signal->utime; -do { - utime =cputime_add (utime, t->utime); - t =next_thread (t); - }while (t != tsk); +struct task_cputime cputime; +cputime_t utime; + +thread_group_cputime (tsk, &cputime); + utime = cputime.utime;if (cputime_le (cval, utime)) {/* about to fire */ cval =jiffies_to_cputime (1 ); }else {
@@ -73,25 +71,19 @@ int do_getitimer(int which, struct itimerval *value) } }spin_unlock_irq (&tsk->sighand->siglock); -read_unlock (&tasklist_lock);cputime_to_timeval (cval, &value->it_value);cputime_to_timeval (cinterval, &value->it_interval);break ;case ITIMER_PROF : -read_lock (&tasklist_lock);spin_lock_irq (&tsk->sighand->siglock); cval = tsk->signal->it_prof_expires; cinterval = tsk->signal->it_prof_incr;if (!cputime_eq (cval, cputime_zero)) { -struct task_struct *t = tsk; -cputime_t ptime =cputime_add (tsk->signal->utime, - tsk->signal->stime); -do { - ptime =cputime_add (ptime, -cputime_add (t->utime, - t->stime)); - t =next_thread (t); - }while (t != tsk); +struct task_cputime times; +cputime_t ptime; + +thread_group_cputime (tsk, ×); + ptime =cputime_add (times.utime, times.stime);if (cputime_le (cval, ptime)) {/* about to fire */ cval =jiffies_to_cputime (1 ); }else {
@@ -99,7 +91,6 @@ int do_getitimer(int which, struct itimerval *value) } }spin_unlock_irq (&tsk->sighand->siglock); -read_unlock (&tasklist_lock);cputime_to_timeval (cval, &value->it_value);cputime_to_timeval (cinterval, &value->it_interval);break ;
@@ -185,7 +176,6 @@ again:case ITIMER_VIRTUAL : nval =timeval_to_cputime (&value->it_value); ninterval =timeval_to_cputime (&value->it_interval); -read_lock (&tasklist_lock);spin_lock_irq (&tsk->sighand->siglock); cval = tsk->signal->it_virt_expires; cinterval = tsk->signal->it_virt_incr;
@@ -200,7 +190,6 @@ again: tsk->signal->it_virt_expires = nval; tsk->signal->it_virt_incr = ninterval;spin_unlock_irq (&tsk->sighand->siglock); -read_unlock (&tasklist_lock);if (ovalue) {cputime_to_timeval (cval, &ovalue->it_value);cputime_to_timeval (cinterval, &ovalue->it_interval);
@@ -209,7 +198,6 @@ again:case ITIMER_PROF : nval =timeval_to_cputime (&value->it_value); ninterval =timeval_to_cputime (&value->it_interval); -read_lock (&tasklist_lock);spin_lock_irq (&tsk->sighand->siglock); cval = tsk->signal->it_prof_expires; cinterval = tsk->signal->it_prof_incr;
@@ -224,7 +212,6 @@ again: tsk->signal->it_prof_expires = nval; tsk->signal->it_prof_incr = ninterval;spin_unlock_irq (&tsk->sighand->siglock); -read_unlock (&tasklist_lock);if (ovalue) {cputime_to_timeval (cval, &ovalue->it_value);cputime_to_timeval (cinterval, &ovalue->it_interval);
kernel/posix-cpu-timers.c +199 -219
577 lines not on this page · raw message
kernel/sched.c +45 -8
92 lines not on this page · raw message
kernel/sched_fair.c +1 -0
@@ -481,6 +481,7 @@ static void update_curr(struct cfs_rq *cfs_rq)struct task_struct *curtask =task_of (curr);cpuacct_charge (curtask, delta_exec); +account_group_exec_runtime (curtask, delta_exec); } }
kernel/sched_rt.c +4 -1
@@ -371,6 +371,8 @@ static void update_curr_rt(struct rq *rq)schedstat_set (curr->se.exec_max,max (curr->se.exec_max, delta_exec)); curr->se.sum_exec_runtime += delta_exec; +account_group_exec_runtime (curr, delta_exec); + curr->se.exec_start = rq->clock;cpuacct_charge (curr, delta_exec);
@@ -1273,7 +1275,8 @@ static void watchdog(struct rq *rq, struct task_struct *p) p->rt.timeout++; next =DIV_ROUND_UP (min (soft, hard),USEC_PER_SEC /HZ );if (p->rt.timeout > next) - p->it_sched_expires = p->se.sum_exec_runtime; + p->cputime_expires.sched_exp = + p->se.sum_exec_runtime; } }
kernel/signal.c +4 -4
@@ -1311,6 +1311,7 @@ void do_notify_parent(struct task_struct *tsk, int sig)struct siginfo info;unsigned long flags;struct sighand_struct *psig; +struct task_cputime cputime;BUG_ON (sig ==-1 );
@@ -1341,10 +1342,9 @@ void do_notify_parent(struct task_struct *tsk, int sig) info.si_uid = tsk->uid;/* FIXME: find out whether or not this is supposed to be c*time. */ - info.si_utime =cputime_to_jiffies (cputime_add (tsk->utime, - tsk->signal->utime)); - info.si_stime =cputime_to_jiffies (cputime_add (tsk->stime, - tsk->signal->stime)); +thread_group_cputime (tsk, &cputime); + info.si_utime =cputime_to_jiffies (cputime.utime); + info.si_stime =cputime_to_jiffies (cputime.stime); info.si_status = tsk->exit_code &0x7f ;if (tsk->exit_code &0x80 )
kernel/sys.c +26 -49
127 lines not on this page · raw message
security/selinux/hooks.c +2 -7
@@ -76,6 +76,7 @@#include <linux/string.h> #include <linux/selinux.h> #include <linux/mutex.h> +#include <linux/posix-timers.h> #include "avc.h" #include "objsec.h"
@@ -2262,13 +2263,7 @@ static void selinux_bprm_post_apply_creds(struct linux_binprm *bprm) initrlim = init_task.signal->rlim+i; rlim->rlim_cur =min (rlim->rlim_max, initrlim->rlim_cur); } -if (current->signal->rlim[RLIMIT_CPU ].rlim_cur !=RLIM_INFINITY ) { -/* -* This will cause RLIMIT_CPU calculations -* to be refigured. -*/ - current->it_prof_expires =jiffies_to_cputime (1 ); - } +update_rlimit_cpu (rlim->rlim_cur); }/* Wake up the parent if it is waiting so that it can
------ PATCH ------
Signature · 2 lines
Frank Mayhar <[email protected]> Google, Inc.