Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 165323
b: refs/heads/master
c: 8356b5f
h: refs/heads/master
i:
  165321: 150ac24
  165319: ae9f915
v: v3
  • Loading branch information
Stanislaw Gruszka authored and Ingo Molnar committed Aug 3, 2009
1 parent bf1297a commit 802231e
Show file tree
Hide file tree
Showing 4 changed files with 41 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: 42c4ab41a176ee784c0f28c0b29025a8fc34f05a
refs/heads/master: 8356b5f9c424e5831715abbce747197c30d1fd71
2 changes: 2 additions & 0 deletions trunk/include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ struct pacct_struct {
struct cpu_itimer {
cputime_t expires;
cputime_t incr;
u32 error;
u32 incr_error;
};

/**
Expand Down
24 changes: 21 additions & 3 deletions trunk/kernel/itimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static struct timeval itimer_get_remtime(struct hrtimer *timer)
}

static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
struct itimerval *value)
struct itimerval *const value)
{
cputime_t cval, cinterval;
struct cpu_itimer *it = &tsk->signal->it[clock_id];
Expand Down Expand Up @@ -127,14 +127,32 @@ enum hrtimer_restart it_real_fn(struct hrtimer *timer)
return HRTIMER_NORESTART;
}

static inline u32 cputime_sub_ns(cputime_t ct, s64 real_ns)
{
struct timespec ts;
s64 cpu_ns;

cputime_to_timespec(ct, &ts);
cpu_ns = timespec_to_ns(&ts);

return (cpu_ns <= real_ns) ? 0 : cpu_ns - real_ns;
}

static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
struct itimerval *value, struct itimerval *ovalue)
const struct itimerval *const value,
struct itimerval *const ovalue)
{
cputime_t cval, cinterval, nval, ninterval;
cputime_t cval, nval, cinterval, ninterval;
s64 ns_ninterval, ns_nval;
struct cpu_itimer *it = &tsk->signal->it[clock_id];

nval = timeval_to_cputime(&value->it_value);
ns_nval = timeval_to_ns(&value->it_value);
ninterval = timeval_to_cputime(&value->it_interval);
ns_ninterval = timeval_to_ns(&value->it_interval);

it->incr_error = cputime_sub_ns(ninterval, ns_ninterval);
it->error = cputime_sub_ns(nval, ns_nval);

spin_lock_irq(&tsk->sighand->siglock);

Expand Down
20 changes: 17 additions & 3 deletions trunk/kernel/posix-cpu-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,16 +1070,25 @@ static void stop_process_timers(struct task_struct *tsk)
spin_unlock_irqrestore(&cputimer->lock, flags);
}

static u32 onecputick;

static void check_cpu_itimer(struct task_struct *tsk, struct cpu_itimer *it,
cputime_t *expires, cputime_t cur_time, int signo)
{
if (cputime_eq(it->expires, cputime_zero))
return;

if (cputime_ge(cur_time, it->expires)) {
it->expires = it->incr;
if (!cputime_eq(it->expires, cputime_zero))
it->expires = cputime_add(it->expires, cur_time);
if (!cputime_eq(it->incr, cputime_zero)) {
it->expires = cputime_add(it->expires, it->incr);
it->error += it->incr_error;
if (it->error >= onecputick) {
it->expires = cputime_sub(it->expires,
jiffies_to_cputime(1));
it->error -= onecputick;
}
} else
it->expires = cputime_zero;

__group_send_sig_info(signo, SEND_SIG_PRIV, tsk);
}
Expand Down Expand Up @@ -1696,10 +1705,15 @@ static __init int init_posix_cpu_timers(void)
.nsleep = thread_cpu_nsleep,
.nsleep_restart = thread_cpu_nsleep_restart,
};
struct timespec ts;

register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread);

cputime_to_timespec(jiffies_to_cputime(1), &ts);
onecputick = ts.tv_nsec;
WARN_ON(ts.tv_sec != 0);

return 0;
}
__initcall(init_posix_cpu_timers);

0 comments on commit 802231e

Please sign in to comment.