* [PATCH resend3 1/2] itimers: merge ITIMER_VIRT and ITIMER_PROF common code
@ 2009-05-18 11:50 Stanislaw Gruszka
2009-05-19 13:52 ` Thomas Gleixner
0 siblings, 1 reply; 3+ messages in thread
From: Stanislaw Gruszka @ 2009-05-18 11:50 UTC (permalink / raw)
To: Thomas Gleixner
Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
Ingo Molnar, Andrew Morton
Both cpu itimers have same data flow in the few places, this patch make
unification of code related with VIRT and PROF itimers.
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
Compared to previous patch bug (using utime instead of sum stime + utime when
setup PROF itimer) is fixed. I also no longer introduce new IT_PROF and IT_VIRT
definitions, only CPUCLOCK_PROF and CPUCLOCK_VIRT are used.
include/linux/sched.h | 8 ++-
kernel/fork.c | 8 +-
kernel/itimer.c | 151 ++++++++++++++++++++++-----------------------
kernel/posix-cpu-timers.c | 86 +++++++++++++-------------
4 files changed, 125 insertions(+), 128 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index b4c38bc..0d8367b 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -454,6 +454,11 @@ struct pacct_struct {
unsigned long ac_minflt, ac_majflt;
};
+struct cpu_itimer {
+ cputime_t expires;
+ cputime_t incr;
+};
+
/**
* struct task_cputime - collected CPU time counts
* @utime: time spent in user mode, in &cputime_t units
@@ -540,8 +545,7 @@ struct signal_struct {
ktime_t it_real_incr;
/* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
- cputime_t it_prof_expires, it_virt_expires;
- cputime_t it_prof_incr, it_virt_incr;
+ struct cpu_itimer it[2];
/*
* Thread group totals for process CPU timers.
diff --git a/kernel/fork.c b/kernel/fork.c
index b9e2edd..fbde8e0 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -790,10 +790,10 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig)
thread_group_cputime_init(sig);
/* Expiration times and increments. */
- sig->it_virt_expires = cputime_zero;
- sig->it_virt_incr = cputime_zero;
- sig->it_prof_expires = cputime_zero;
- sig->it_prof_incr = cputime_zero;
+ sig->it[0].expires = cputime_zero;
+ sig->it[0].incr = cputime_zero;
+ sig->it[1].expires = cputime_zero;
+ sig->it[1].incr = cputime_zero;
/* Cached expiration times. */
sig->cputime_expires.prof_exp = cputime_zero;
diff --git a/kernel/itimer.c b/kernel/itimer.c
index 58762f7..bb8bde6 100644
--- a/kernel/itimer.c
+++ b/kernel/itimer.c
@@ -41,10 +41,48 @@ static struct timeval itimer_get_remtime(struct hrtimer *timer)
return ktime_to_timeval(rem);
}
+static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
+ struct itimerval *value)
+{
+ cputime_t cval, cinterval;
+ struct cpu_itimer *it = &tsk->signal->it[clock_id];
+
+ spin_lock_irq(&tsk->sighand->siglock);
+
+ cval = it->expires;
+ cinterval = it->incr;
+ if (!cputime_eq(cval, cputime_zero)) {
+ struct task_cputime cputime;
+ cputime_t t;
+
+ thread_group_cputimer(tsk, &cputime);
+ switch (clock_id) {
+ default:
+ BUG();
+ case CPUCLOCK_PROF:
+ t = cputime_add(cputime.utime, cputime.stime);
+ break;
+ case CPUCLOCK_VIRT:
+ t = cputime.utime;
+ break;
+ }
+
+ if (cputime_le(cval, t)) { /* about to fire */
+ cval = jiffies_to_cputime(1);
+ } else {
+ cval = cputime_sub(cval, t);
+ }
+ }
+
+ spin_unlock_irq(&tsk->sighand->siglock);
+
+ cputime_to_timeval(cval, &value->it_value);
+ cputime_to_timeval(cinterval, &value->it_interval);
+}
+
int do_getitimer(int which, struct itimerval *value)
{
struct task_struct *tsk = current;
- cputime_t cinterval, cval;
switch (which) {
case ITIMER_REAL:
@@ -55,44 +93,10 @@ int do_getitimer(int which, struct itimerval *value)
spin_unlock_irq(&tsk->sighand->siglock);
break;
case ITIMER_VIRTUAL:
- 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_cputime cputime;
- cputime_t utime;
-
- thread_group_cputimer(tsk, &cputime);
- utime = cputime.utime;
- if (cputime_le(cval, utime)) { /* about to fire */
- cval = jiffies_to_cputime(1);
- } else {
- cval = cputime_sub(cval, utime);
- }
- }
- spin_unlock_irq(&tsk->sighand->siglock);
- cputime_to_timeval(cval, &value->it_value);
- cputime_to_timeval(cinterval, &value->it_interval);
+ get_cpu_itimer(tsk, CPUCLOCK_VIRT, value);
break;
case ITIMER_PROF:
- 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_cputime times;
- cputime_t ptime;
-
- thread_group_cputimer(tsk, ×);
- ptime = cputime_add(times.utime, times.stime);
- if (cputime_le(cval, ptime)) { /* about to fire */
- cval = jiffies_to_cputime(1);
- } else {
- cval = cputime_sub(cval, ptime);
- }
- }
- spin_unlock_irq(&tsk->sighand->siglock);
- cputime_to_timeval(cval, &value->it_value);
- cputime_to_timeval(cinterval, &value->it_interval);
+ get_cpu_itimer(tsk, CPUCLOCK_PROF, value);
break;
default:
return(-EINVAL);
@@ -128,6 +132,36 @@ enum hrtimer_restart it_real_fn(struct hrtimer *timer)
return HRTIMER_NORESTART;
}
+static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
+ struct itimerval *value, struct itimerval *ovalue)
+{
+ cputime_t cval, cinterval, nval, ninterval;
+ struct cpu_itimer *it = &tsk->signal->it[clock_id];
+
+ nval = timeval_to_cputime(&value->it_value);
+ ninterval = timeval_to_cputime(&value->it_interval);
+
+ spin_lock_irq(&tsk->sighand->siglock);
+
+ cval = it->expires;
+ cinterval = it->incr;
+ if (!cputime_eq(cval, cputime_zero) ||
+ !cputime_eq(nval, cputime_zero)) {
+ if (cputime_gt(nval, cputime_zero))
+ nval = cputime_add(nval, jiffies_to_cputime(1));
+ set_process_cpu_timer(tsk, clock_id, &nval, &cval);
+ }
+ it->expires = nval;
+ it->incr = ninterval;
+
+ spin_unlock_irq(&tsk->sighand->siglock);
+
+ if (ovalue) {
+ cputime_to_timeval(cval, &ovalue->it_value);
+ cputime_to_timeval(cinterval, &ovalue->it_interval);
+ }
+}
+
/*
* Returns true if the timeval is in canonical form
*/
@@ -139,7 +173,6 @@ int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue)
struct task_struct *tsk = current;
struct hrtimer *timer;
ktime_t expires;
- cputime_t cval, cinterval, nval, ninterval;
/*
* Validate the timevals in value.
@@ -174,48 +207,10 @@ again:
spin_unlock_irq(&tsk->sighand->siglock);
break;
case ITIMER_VIRTUAL:
- nval = timeval_to_cputime(&value->it_value);
- ninterval = timeval_to_cputime(&value->it_interval);
- spin_lock_irq(&tsk->sighand->siglock);
- cval = tsk->signal->it_virt_expires;
- cinterval = tsk->signal->it_virt_incr;
- if (!cputime_eq(cval, cputime_zero) ||
- !cputime_eq(nval, cputime_zero)) {
- if (cputime_gt(nval, cputime_zero))
- nval = cputime_add(nval,
- jiffies_to_cputime(1));
- set_process_cpu_timer(tsk, CPUCLOCK_VIRT,
- &nval, &cval);
- }
- tsk->signal->it_virt_expires = nval;
- tsk->signal->it_virt_incr = ninterval;
- spin_unlock_irq(&tsk->sighand->siglock);
- if (ovalue) {
- cputime_to_timeval(cval, &ovalue->it_value);
- cputime_to_timeval(cinterval, &ovalue->it_interval);
- }
+ set_cpu_itimer(tsk, CPUCLOCK_VIRT, value, ovalue);
break;
case ITIMER_PROF:
- nval = timeval_to_cputime(&value->it_value);
- ninterval = timeval_to_cputime(&value->it_interval);
- spin_lock_irq(&tsk->sighand->siglock);
- cval = tsk->signal->it_prof_expires;
- cinterval = tsk->signal->it_prof_incr;
- if (!cputime_eq(cval, cputime_zero) ||
- !cputime_eq(nval, cputime_zero)) {
- if (cputime_gt(nval, cputime_zero))
- nval = cputime_add(nval,
- jiffies_to_cputime(1));
- set_process_cpu_timer(tsk, CPUCLOCK_PROF,
- &nval, &cval);
- }
- tsk->signal->it_prof_expires = nval;
- tsk->signal->it_prof_incr = ninterval;
- spin_unlock_irq(&tsk->sighand->siglock);
- if (ovalue) {
- cputime_to_timeval(cval, &ovalue->it_value);
- cputime_to_timeval(cinterval, &ovalue->it_interval);
- }
+ set_cpu_itimer(tsk, CPUCLOCK_PROF, value, ovalue);
break;
default:
return -EINVAL;
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index bece7c0..b6accca 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -14,11 +14,11 @@
*/
void update_rlimit_cpu(unsigned long rlim_new)
{
- cputime_t cputime;
+ cputime_t cputime = secs_to_cputime(rlim_new);
+ struct signal_struct *const sig = current->signal;
- cputime = secs_to_cputime(rlim_new);
- if (cputime_eq(current->signal->it_prof_expires, cputime_zero) ||
- cputime_gt(current->signal->it_prof_expires, cputime)) {
+ if (cputime_eq(sig->it[CPUCLOCK_PROF].expires, cputime_zero) ||
+ cputime_gt(sig->it[CPUCLOCK_PROF].expires, cputime)) {
spin_lock_irq(¤t->sighand->siglock);
set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
spin_unlock_irq(¤t->sighand->siglock);
@@ -613,36 +613,39 @@ static void arm_timer(struct k_itimer *timer, union cpu_time_count now)
break;
}
} else {
+ struct signal_struct *const sig = p->signal;
+
/*
* For a process timer, set the cached expiration time.
*/
+
switch (CPUCLOCK_WHICH(timer->it_clock)) {
default:
BUG();
case CPUCLOCK_VIRT:
- if (!cputime_eq(p->signal->it_virt_expires,
+ if (!cputime_eq(sig->it[CPUCLOCK_VIRT].expires,
cputime_zero) &&
- cputime_lt(p->signal->it_virt_expires,
+ cputime_lt(sig->it[CPUCLOCK_VIRT].expires,
timer->it.cpu.expires.cpu))
break;
p->signal->cputime_expires.virt_exp =
timer->it.cpu.expires.cpu;
break;
case CPUCLOCK_PROF:
- if (!cputime_eq(p->signal->it_prof_expires,
+ if (!cputime_eq(sig->it[CPUCLOCK_PROF].expires,
cputime_zero) &&
- cputime_lt(p->signal->it_prof_expires,
+ cputime_lt(sig->it[CPUCLOCK_PROF].expires,
timer->it.cpu.expires.cpu))
break;
i = p->signal->rlim[RLIMIT_CPU].rlim_cur;
if (i != RLIM_INFINITY &&
i <= cputime_to_secs(timer->it.cpu.expires.cpu))
break;
- p->signal->cputime_expires.prof_exp =
+ sig->cputime_expires.prof_exp =
timer->it.cpu.expires.cpu;
break;
case CPUCLOCK_SCHED:
- p->signal->cputime_expires.sched_exp =
+ sig->cputime_expires.sched_exp =
timer->it.cpu.expires.sched;
break;
}
@@ -1070,6 +1073,28 @@ static void stop_process_timers(struct task_struct *tsk)
spin_unlock_irqrestore(&cputimer->lock, flags);
}
+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);
+ }
+
+ __group_send_sig_info(signo, SEND_SIG_PRIV, tsk);
+ }
+
+ if (!cputime_eq(it->expires, cputime_zero) &&
+ (cputime_eq(*expires, cputime_zero) ||
+ cputime_lt(it->expires, *expires))) {
+ *expires = it->expires;
+ }
+}
+
/*
* Check for any per-thread CPU timers that have fired and move them
* off the tsk->*_timers list onto the firing list. Per-thread timers
@@ -1089,10 +1114,10 @@ static void check_process_timers(struct task_struct *tsk,
* Don't sample the current process CPU clocks if there are no timers.
*/
if (list_empty(&timers[CPUCLOCK_PROF]) &&
- cputime_eq(sig->it_prof_expires, cputime_zero) &&
+ cputime_eq(sig->it[CPUCLOCK_PROF].expires, cputime_zero) &&
sig->rlim[RLIMIT_CPU].rlim_cur == RLIM_INFINITY &&
list_empty(&timers[CPUCLOCK_VIRT]) &&
- cputime_eq(sig->it_virt_expires, cputime_zero) &&
+ cputime_eq(sig->it[CPUCLOCK_VIRT].expires, cputime_zero) &&
list_empty(&timers[CPUCLOCK_SCHED])) {
stop_process_timers(tsk);
return;
@@ -1152,38 +1177,11 @@ static void check_process_timers(struct task_struct *tsk,
/*
* Check for the special case process timers.
*/
- if (!cputime_eq(sig->it_prof_expires, cputime_zero)) {
- if (cputime_ge(ptime, sig->it_prof_expires)) {
- /* ITIMER_PROF fires and reloads. */
- sig->it_prof_expires = sig->it_prof_incr;
- if (!cputime_eq(sig->it_prof_expires, cputime_zero)) {
- sig->it_prof_expires = cputime_add(
- sig->it_prof_expires, ptime);
- }
- __group_send_sig_info(SIGPROF, SEND_SIG_PRIV, tsk);
- }
- if (!cputime_eq(sig->it_prof_expires, cputime_zero) &&
- (cputime_eq(prof_expires, cputime_zero) ||
- cputime_lt(sig->it_prof_expires, prof_expires))) {
- prof_expires = sig->it_prof_expires;
- }
- }
- if (!cputime_eq(sig->it_virt_expires, cputime_zero)) {
- if (cputime_ge(utime, sig->it_virt_expires)) {
- /* ITIMER_VIRTUAL fires and reloads. */
- sig->it_virt_expires = sig->it_virt_incr;
- if (!cputime_eq(sig->it_virt_expires, cputime_zero)) {
- sig->it_virt_expires = cputime_add(
- sig->it_virt_expires, utime);
- }
- __group_send_sig_info(SIGVTALRM, SEND_SIG_PRIV, tsk);
- }
- if (!cputime_eq(sig->it_virt_expires, cputime_zero) &&
- (cputime_eq(virt_expires, cputime_zero) ||
- cputime_lt(sig->it_virt_expires, virt_expires))) {
- virt_expires = sig->it_virt_expires;
- }
- }
+ check_cpu_itimer(tsk, &sig->it[CPUCLOCK_PROF], &prof_expires, ptime,
+ SIGPROF);
+ check_cpu_itimer(tsk, &sig->it[CPUCLOCK_VIRT], &virt_expires, utime,
+ SIGVTALRM);
+
if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) {
unsigned long psecs = cputime_to_secs(ptime);
cputime_t x;
--
1.6.0.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH resend3 1/2] itimers: merge ITIMER_VIRT and ITIMER_PROF common code
2009-05-18 11:50 [PATCH resend3 1/2] itimers: merge ITIMER_VIRT and ITIMER_PROF common code Stanislaw Gruszka
@ 2009-05-19 13:52 ` Thomas Gleixner
2009-05-21 5:53 ` Stanislaw Gruszka
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Gleixner @ 2009-05-19 13:52 UTC (permalink / raw)
To: Stanislaw Gruszka
Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
Ingo Molnar, Andrew Morton
Stanislaw,
On Mon, 18 May 2009, Stanislaw Gruszka wrote:
> Both cpu itimers have same data flow in the few places, this patch make
> unification of code related with VIRT and PROF itimers.
Sorry for late response.
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
> Compared to previous patch bug (using utime instead of sum stime + utime when
> setup PROF itimer) is fixed. I also no longer introduce new IT_PROF and IT_VIRT
> definitions, only CPUCLOCK_PROF and CPUCLOCK_VIRT are used.
>
> include/linux/sched.h | 8 ++-
> kernel/fork.c | 8 +-
> kernel/itimer.c | 151 ++++++++++++++++++++++-----------------------
> kernel/posix-cpu-timers.c | 86 +++++++++++++-------------
> 4 files changed, 125 insertions(+), 128 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index b4c38bc..0d8367b 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -454,6 +454,11 @@ struct pacct_struct {
> unsigned long ac_minflt, ac_majflt;
> };
>
> +struct cpu_itimer {
> + cputime_t expires;
> + cputime_t incr;
> +};
> +
> /**
> * struct task_cputime - collected CPU time counts
> * @utime: time spent in user mode, in &cputime_t units
> @@ -540,8 +545,7 @@ struct signal_struct {
> ktime_t it_real_incr;
>
> /* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
> - cputime_t it_prof_expires, it_virt_expires;
> - cputime_t it_prof_incr, it_virt_incr;
> + struct cpu_itimer it[2];
I like the general idea of the patch, but it's not obvious that
CPUCLOCK_PROF and CPUCLOCK_VIRT happen to be defined as 0 resp 1.
This needs at least a comment.
> +static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
> + struct itimerval *value)
> +{
> + cputime_t cval, cinterval;
> + struct cpu_itimer *it = &tsk->signal->it[clock_id];
> +
> + spin_lock_irq(&tsk->sighand->siglock);
> +
> + cval = it->expires;
> + cinterval = it->incr;
We dereference it-> w/o checking clock_id first ?
> + if (!cputime_eq(cval, cputime_zero)) {
> + struct task_cputime cputime;
> + cputime_t t;
> +
> + thread_group_cputimer(tsk, &cputime);
> + switch (clock_id) {
> + default:
> + BUG();
So the BUG here is correct, but a little late. OTOH we only have local
callers, so that will only catch stupidity of people changing the
calling code. Not sure if it's worth bothering with it at all.
> + case CPUCLOCK_PROF:
> + t = cputime_add(cputime.utime, cputime.stime);
> + break;
> + case CPUCLOCK_VIRT:
> + t = cputime.utime;
> + break;
> + }
> +
> + if (cputime_le(cval, t)) { /* about to fire */
Please avoid end of line comments. The if/else here can do without
braces.
> diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
> index bece7c0..b6accca 100644
> --- a/kernel/posix-cpu-timers.c
> +++ b/kernel/posix-cpu-timers.c
> @@ -14,11 +14,11 @@
> */
> void update_rlimit_cpu(unsigned long rlim_new)
> {
> - cputime_t cputime;
> + cputime_t cputime = secs_to_cputime(rlim_new);
> + struct signal_struct *const sig = current->signal;
>
> - cputime = secs_to_cputime(rlim_new);
> - if (cputime_eq(current->signal->it_prof_expires, cputime_zero) ||
> - cputime_gt(current->signal->it_prof_expires, cputime)) {
> + if (cputime_eq(sig->it[CPUCLOCK_PROF].expires, cputime_zero) ||
> + cputime_gt(sig->it[CPUCLOCK_PROF].expires, cputime)) {
> spin_lock_irq(¤t->sighand->siglock);
> set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
> spin_unlock_irq(¤t->sighand->siglock);
> @@ -613,36 +613,39 @@ static void arm_timer(struct k_itimer *timer, union cpu_time_count now)
> break;
> }
> } else {
> + struct signal_struct *const sig = p->signal;
> +
> /*
> * For a process timer, set the cached expiration time.
> */
> +
Stray newline
> switch (CPUCLOCK_WHICH(timer->it_clock)) {
> default:
> BUG();
> case CPUCLOCK_VIRT:
> - if (!cputime_eq(p->signal->it_virt_expires,
> + if (!cputime_eq(sig->it[CPUCLOCK_VIRT].expires,
> cputime_zero) &&
> - cputime_lt(p->signal->it_virt_expires,
> + cputime_lt(sig->it[CPUCLOCK_VIRT].expires,
> timer->it.cpu.expires.cpu))
> break;
> p->signal->cputime_expires.virt_exp =
> timer->it.cpu.expires.cpu;
Should change to sig->cputime... as well
> break;
> case CPUCLOCK_PROF:
> - if (!cputime_eq(p->signal->it_prof_expires,
> + if (!cputime_eq(sig->it[CPUCLOCK_PROF].expires,
> cputime_zero) &&
> - cputime_lt(p->signal->it_prof_expires,
> + cputime_lt(sig->it[CPUCLOCK_PROF].expires,
> timer->it.cpu.expires.cpu))
> break;
That code could be simplified further by splitting out the
comparisons into a separate function and doing
if (fred(&sig->it[CPUCLOCK_PROF], timer))
break;
> i = p->signal->rlim[RLIMIT_CPU].rlim_cur;
> if (i != RLIM_INFINITY &&
> i <= cputime_to_secs(timer->it.cpu.expires.cpu))
> break;
> - p->signal->cputime_expires.prof_exp =
> + sig->cputime_expires.prof_exp =
> timer->it.cpu.expires.cpu;
Also we reference timer->it.cpu.expires.cpu in all 3 cases several
times, so having an extra pointer to it would make the code more
readable as well.
> break;
> case CPUCLOCK_SCHED:
> - p->signal->cputime_expires.sched_exp =
> + sig->cputime_expires.sched_exp =
> timer->it.cpu.expires.sched;
> break;
> }
> @@ -1070,6 +1073,28 @@ static void stop_process_timers(struct task_struct *tsk)
> spin_unlock_irqrestore(&cputimer->lock, flags);
> }
>
> +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);
> + }
No braces please
> +
> + __group_send_sig_info(signo, SEND_SIG_PRIV, tsk);
> + }
> +
> + if (!cputime_eq(it->expires, cputime_zero) &&
> + (cputime_eq(*expires, cputime_zero) ||
> + cputime_lt(it->expires, *expires))) {
> + *expires = it->expires;
> + }
> +}
> +
Looks fine otherwise. Thanks,
tglx
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH resend3 1/2] itimers: merge ITIMER_VIRT and ITIMER_PROF common code
2009-05-19 13:52 ` Thomas Gleixner
@ 2009-05-21 5:53 ` Stanislaw Gruszka
0 siblings, 0 replies; 3+ messages in thread
From: Stanislaw Gruszka @ 2009-05-21 5:53 UTC (permalink / raw)
To: Thomas Gleixner
Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
Ingo Molnar, Andrew Morton
Hi.
On Tue, 19 May 2009 15:52:06 +0200 (CEST)
Thomas Gleixner <tglx@linutronix.de> wrote:
> > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > index b4c38bc..0d8367b 100644
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -454,6 +454,11 @@ struct pacct_struct {
> > unsigned long ac_minflt, ac_majflt;
> > };
> >
> > +struct cpu_itimer {
> > + cputime_t expires;
> > + cputime_t incr;
> > +};
> > +
> > /**
> > * struct task_cputime - collected CPU time counts
> > * @utime: time spent in user mode, in &cputime_t units
> > @@ -540,8 +545,7 @@ struct signal_struct {
> > ktime_t it_real_incr;
> >
> > /* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
> > - cputime_t it_prof_expires, it_virt_expires;
> > - cputime_t it_prof_incr, it_virt_incr;
> > + struct cpu_itimer it[2];
>
> I like the general idea of the patch, but it's not obvious that
> CPUCLOCK_PROF and CPUCLOCK_VIRT happen to be defined as 0 resp 1.
>
> This needs at least a comment.
Ok. I'll comment that. I though about something better than comment,
but not find nothing appropriate.
> > break;
> > case CPUCLOCK_PROF:
> > - if (!cputime_eq(p->signal->it_prof_expires,
> > + if (!cputime_eq(sig->it[CPUCLOCK_PROF].expires,
> > cputime_zero) &&
> > - cputime_lt(p->signal->it_prof_expires,
> > + cputime_lt(sig->it[CPUCLOCK_PROF].expires,
> > timer->it.cpu.expires.cpu))
> > break;
>
> That code could be simplified further by splitting out the
> comparisons into a separate function and doing
>
> if (fred(&sig->it[CPUCLOCK_PROF], timer))
> break;
I'll create a helper inline function, but I do this in separate patch.
> Looks fine otherwise. Thanks,
>
> tglx
Thanks for review, I'll change both my patches and resend soon.
Stanislaw
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-05-21 5:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-18 11:50 [PATCH resend3 1/2] itimers: merge ITIMER_VIRT and ITIMER_PROF common code Stanislaw Gruszka
2009-05-19 13:52 ` Thomas Gleixner
2009-05-21 5:53 ` Stanislaw Gruszka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox