Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 39715
b: refs/heads/master
c: ac08c26
h: refs/heads/master
i:
  39713: b6f25cd
  39711: ae1990a
v: v3
  • Loading branch information
Thomas Gleixner authored and Linus Torvalds committed Oct 17, 2006
1 parent 91ced4d commit cea66c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e24650c2e744f99541125a5b023f0d02cad19d14
refs/heads/master: ac08c26492a0ad4d94a25bd47d5630cd38337069
27 changes: 21 additions & 6 deletions trunk/kernel/posix-cpu-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ static inline union cpu_time_count cpu_time_sub(const clockid_t which_clock,
return a;
}

/*
* Divide and limit the result to res >= 1
*
* This is necessary to prevent signal delivery starvation, when the result of
* the division would be rounded down to 0.
*/
static inline cputime_t cputime_div_non_zero(cputime_t time, unsigned long div)
{
cputime_t res = cputime_div(time, div);

return max_t(cputime_t, res, 1);
}

/*
* Update expiry time from increment, and increase overrun count,
* given the current clock sample.
Expand Down Expand Up @@ -483,8 +496,8 @@ static void process_timer_rebalance(struct task_struct *p,
BUG();
break;
case CPUCLOCK_PROF:
left = cputime_div(cputime_sub(expires.cpu, val.cpu),
nthreads);
left = cputime_div_non_zero(cputime_sub(expires.cpu, val.cpu),
nthreads);
do {
if (likely(!(t->flags & PF_EXITING))) {
ticks = cputime_add(prof_ticks(t), left);
Expand All @@ -498,8 +511,8 @@ static void process_timer_rebalance(struct task_struct *p,
} while (t != p);
break;
case CPUCLOCK_VIRT:
left = cputime_div(cputime_sub(expires.cpu, val.cpu),
nthreads);
left = cputime_div_non_zero(cputime_sub(expires.cpu, val.cpu),
nthreads);
do {
if (likely(!(t->flags & PF_EXITING))) {
ticks = cputime_add(virt_ticks(t), left);
Expand All @@ -515,6 +528,7 @@ static void process_timer_rebalance(struct task_struct *p,
case CPUCLOCK_SCHED:
nsleft = expires.sched - val.sched;
do_div(nsleft, nthreads);
nsleft = max_t(unsigned long long, nsleft, 1);
do {
if (likely(!(t->flags & PF_EXITING))) {
ns = t->sched_time + nsleft;
Expand Down Expand Up @@ -1159,12 +1173,13 @@ static void check_process_timers(struct task_struct *tsk,

prof_left = cputime_sub(prof_expires, utime);
prof_left = cputime_sub(prof_left, stime);
prof_left = cputime_div(prof_left, nthreads);
prof_left = cputime_div_non_zero(prof_left, nthreads);
virt_left = cputime_sub(virt_expires, utime);
virt_left = cputime_div(virt_left, nthreads);
virt_left = cputime_div_non_zero(virt_left, nthreads);
if (sched_expires) {
sched_left = sched_expires - sched_time;
do_div(sched_left, nthreads);
sched_left = max_t(unsigned long long, sched_left, 1);
} else {
sched_left = 0;
}
Expand Down

0 comments on commit cea66c8

Please sign in to comment.