aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorStanislaw Gruszka <sgruszka@redhat.com>2009-07-29 06:15:29 -0400
committerIngo Molnar <mingo@elte.hu>2009-08-03 08:48:36 -0400
commita42548a18866e87092db93b771e6c5b060d78401 (patch)
tree897acf5794920ec9c6fd7f87af63908d0c1988f9 /kernel
parentd1e3b6d195770bd422e3229b88edfc154b6a27dd (diff)
cputime: Optimize jiffies_to_cputime(1)
For powerpc with CONFIG_VIRT_CPU_ACCOUNTING jiffies_to_cputime(1) is not compile time constant and run time calculations are quite expensive. To optimize we use precomputed value. For all other architectures is is preprocessor definition. Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Acked-by: Thomas Gleixner <tglx@linutronix.de> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> LKML-Reference: <1248862529-6063-5-git-send-email-sgruszka@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/itimer.c4
-rw-r--r--kernel/posix-cpu-timers.c6
-rw-r--r--kernel/sched.c9
3 files changed, 9 insertions, 10 deletions
diff --git a/kernel/itimer.c b/kernel/itimer.c
index 21adff7b2a17..8078a32d3b10 100644
--- a/kernel/itimer.c
+++ b/kernel/itimer.c
@@ -64,7 +64,7 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
64 64
65 if (cputime_le(cval, t)) 65 if (cputime_le(cval, t))
66 /* about to fire */ 66 /* about to fire */
67 cval = jiffies_to_cputime(1); 67 cval = cputime_one_jiffy;
68 else 68 else
69 cval = cputime_sub(cval, t); 69 cval = cputime_sub(cval, t);
70 } 70 }
@@ -161,7 +161,7 @@ static void set_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
161 if (!cputime_eq(cval, cputime_zero) || 161 if (!cputime_eq(cval, cputime_zero) ||
162 !cputime_eq(nval, cputime_zero)) { 162 !cputime_eq(nval, cputime_zero)) {
163 if (cputime_gt(nval, cputime_zero)) 163 if (cputime_gt(nval, cputime_zero))
164 nval = cputime_add(nval, jiffies_to_cputime(1)); 164 nval = cputime_add(nval, cputime_one_jiffy);
165 set_process_cpu_timer(tsk, clock_id, &nval, &cval); 165 set_process_cpu_timer(tsk, clock_id, &nval, &cval);
166 } 166 }
167 it->expires = nval; 167 it->expires = nval;
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 69c92374355f..18bdde6f676f 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -1086,7 +1086,7 @@ static void check_cpu_itimer(struct task_struct *tsk, struct cpu_itimer *it,
1086 it->error += it->incr_error; 1086 it->error += it->incr_error;
1087 if (it->error >= onecputick) { 1087 if (it->error >= onecputick) {
1088 it->expires = cputime_sub(it->expires, 1088 it->expires = cputime_sub(it->expires,
1089 jiffies_to_cputime(1)); 1089 cputime_one_jiffy);
1090 it->error -= onecputick; 1090 it->error -= onecputick;
1091 } 1091 }
1092 } else 1092 } else
@@ -1461,7 +1461,7 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
1461 if (!cputime_eq(*oldval, cputime_zero)) { 1461 if (!cputime_eq(*oldval, cputime_zero)) {
1462 if (cputime_le(*oldval, now.cpu)) { 1462 if (cputime_le(*oldval, now.cpu)) {
1463 /* Just about to fire. */ 1463 /* Just about to fire. */
1464 *oldval = jiffies_to_cputime(1); 1464 *oldval = cputime_one_jiffy;
1465 } else { 1465 } else {
1466 *oldval = cputime_sub(*oldval, now.cpu); 1466 *oldval = cputime_sub(*oldval, now.cpu);
1467 } 1467 }
@@ -1712,7 +1712,7 @@ static __init int init_posix_cpu_timers(void)
1712 register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process); 1712 register_posix_clock(CLOCK_PROCESS_CPUTIME_ID, &process);
1713 register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread); 1713 register_posix_clock(CLOCK_THREAD_CPUTIME_ID, &thread);
1714 1714
1715 cputime_to_timespec(jiffies_to_cputime(1), &ts); 1715 cputime_to_timespec(cputime_one_jiffy, &ts);
1716 onecputick = ts.tv_nsec; 1716 onecputick = ts.tv_nsec;
1717 WARN_ON(ts.tv_sec != 0); 1717 WARN_ON(ts.tv_sec != 0);
1718 1718
diff --git a/kernel/sched.c b/kernel/sched.c
index 1b59e265273b..8f977d5cc515 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -5031,17 +5031,16 @@ void account_idle_time(cputime_t cputime)
5031 */ 5031 */
5032void account_process_tick(struct task_struct *p, int user_tick) 5032void account_process_tick(struct task_struct *p, int user_tick)
5033{ 5033{
5034 cputime_t one_jiffy = jiffies_to_cputime(1); 5034 cputime_t one_jiffy_scaled = cputime_to_scaled(cputime_one_jiffy);
5035 cputime_t one_jiffy_scaled = cputime_to_scaled(one_jiffy);
5036 struct rq *rq = this_rq(); 5035 struct rq *rq = this_rq();
5037 5036
5038 if (user_tick) 5037 if (user_tick)
5039 account_user_time(p, one_jiffy, one_jiffy_scaled); 5038 account_user_time(p, cputime_one_jiffy, one_jiffy_scaled);
5040 else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET)) 5039 else if ((p != rq->idle) || (irq_count() != HARDIRQ_OFFSET))
5041 account_system_time(p, HARDIRQ_OFFSET, one_jiffy, 5040 account_system_time(p, HARDIRQ_OFFSET, cputime_one_jiffy,
5042 one_jiffy_scaled); 5041 one_jiffy_scaled);
5043 else 5042 else
5044 account_idle_time(one_jiffy); 5043 account_idle_time(cputime_one_jiffy);
5045} 5044}
5046 5045
5047/* 5046/*