diff options
author | Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> | 2008-01-29 00:27:30 -0500 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2008-02-20 15:55:37 -0500 |
commit | b64f34cdfe5bef9dfed1304c513220b0f2862eca (patch) | |
tree | 04cb9216a9de18afcb27f9bac3fda1f3c7bacbbd /include/asm-ia64 | |
parent | 5d9c4a7de64d398604a978d267a6987f1f4025b7 (diff) |
[IA64] VIRT_CPU_ACCOUNTING (accurate cpu time accounting)
This patch implements VIRT_CPU_ACCOUNTING for ia64,
which enable us to use more accurate cpu time accounting.
The VIRT_CPU_ACCOUNTING is an item of kernel config, which s390
and powerpc arch have. By turning this config on, these archs
change the mechanism of cpu time accounting from tick-sampling
based one to state-transition based one.
The state-transition based accounting is done by checking time
(cycle counter in processor) at every state-transition point,
such as entrance/exit of kernel, interrupt, softirq etc.
The difference between point to point is the actual time consumed
during in the state. There is no doubt about that this value is
more accurate than that of tick-sampling based accounting.
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'include/asm-ia64')
-rw-r--r-- | include/asm-ia64/cputime.h | 104 | ||||
-rw-r--r-- | include/asm-ia64/system.h | 12 | ||||
-rw-r--r-- | include/asm-ia64/thread_info.h | 14 |
3 files changed, 130 insertions, 0 deletions
diff --git a/include/asm-ia64/cputime.h b/include/asm-ia64/cputime.h index 72400a78002a..f9abdec6577a 100644 --- a/include/asm-ia64/cputime.h +++ b/include/asm-ia64/cputime.h | |||
@@ -1,6 +1,110 @@ | |||
1 | /* | ||
2 | * include/asm-ia64/cputime.h: | ||
3 | * Definitions for measuring cputime on ia64 machines. | ||
4 | * | ||
5 | * Based on <asm-powerpc/cputime.h>. | ||
6 | * | ||
7 | * Copyright (C) 2007 FUJITSU LIMITED | ||
8 | * Copyright (C) 2007 Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version | ||
13 | * 2 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * If we have CONFIG_VIRT_CPU_ACCOUNTING, we measure cpu time in nsec. | ||
16 | * Otherwise we measure cpu time in jiffies using the generic definitions. | ||
17 | */ | ||
18 | |||
1 | #ifndef __IA64_CPUTIME_H | 19 | #ifndef __IA64_CPUTIME_H |
2 | #define __IA64_CPUTIME_H | 20 | #define __IA64_CPUTIME_H |
3 | 21 | ||
22 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING | ||
4 | #include <asm-generic/cputime.h> | 23 | #include <asm-generic/cputime.h> |
24 | #else | ||
25 | |||
26 | #include <linux/time.h> | ||
27 | #include <linux/jiffies.h> | ||
28 | #include <asm/processor.h> | ||
29 | |||
30 | typedef u64 cputime_t; | ||
31 | typedef u64 cputime64_t; | ||
32 | |||
33 | #define cputime_zero ((cputime_t)0) | ||
34 | #define cputime_max ((~((cputime_t)0) >> 1) - 1) | ||
35 | #define cputime_add(__a, __b) ((__a) + (__b)) | ||
36 | #define cputime_sub(__a, __b) ((__a) - (__b)) | ||
37 | #define cputime_div(__a, __n) ((__a) / (__n)) | ||
38 | #define cputime_halve(__a) ((__a) >> 1) | ||
39 | #define cputime_eq(__a, __b) ((__a) == (__b)) | ||
40 | #define cputime_gt(__a, __b) ((__a) > (__b)) | ||
41 | #define cputime_ge(__a, __b) ((__a) >= (__b)) | ||
42 | #define cputime_lt(__a, __b) ((__a) < (__b)) | ||
43 | #define cputime_le(__a, __b) ((__a) <= (__b)) | ||
44 | |||
45 | #define cputime64_zero ((cputime64_t)0) | ||
46 | #define cputime64_add(__a, __b) ((__a) + (__b)) | ||
47 | #define cputime64_sub(__a, __b) ((__a) - (__b)) | ||
48 | #define cputime_to_cputime64(__ct) (__ct) | ||
49 | |||
50 | /* | ||
51 | * Convert cputime <-> jiffies (HZ) | ||
52 | */ | ||
53 | #define cputime_to_jiffies(__ct) ((__ct) / (NSEC_PER_SEC / HZ)) | ||
54 | #define jiffies_to_cputime(__jif) ((__jif) * (NSEC_PER_SEC / HZ)) | ||
55 | #define cputime64_to_jiffies64(__ct) ((__ct) / (NSEC_PER_SEC / HZ)) | ||
56 | #define jiffies64_to_cputime64(__jif) ((__jif) * (NSEC_PER_SEC / HZ)) | ||
57 | |||
58 | /* | ||
59 | * Convert cputime <-> milliseconds | ||
60 | */ | ||
61 | #define cputime_to_msecs(__ct) ((__ct) / NSEC_PER_MSEC) | ||
62 | #define msecs_to_cputime(__msecs) ((__msecs) * NSEC_PER_MSEC) | ||
63 | |||
64 | /* | ||
65 | * Convert cputime <-> seconds | ||
66 | */ | ||
67 | #define cputime_to_secs(__ct) ((__ct) / NSEC_PER_SEC) | ||
68 | #define secs_to_cputime(__secs) ((__secs) * NSEC_PER_SEC) | ||
69 | |||
70 | /* | ||
71 | * Convert cputime <-> timespec (nsec) | ||
72 | */ | ||
73 | static inline cputime_t timespec_to_cputime(const struct timespec *val) | ||
74 | { | ||
75 | cputime_t ret = val->tv_sec * NSEC_PER_SEC; | ||
76 | return (ret + val->tv_nsec); | ||
77 | } | ||
78 | static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val) | ||
79 | { | ||
80 | val->tv_sec = ct / NSEC_PER_SEC; | ||
81 | val->tv_nsec = ct % NSEC_PER_SEC; | ||
82 | } | ||
83 | |||
84 | /* | ||
85 | * Convert cputime <-> timeval (msec) | ||
86 | */ | ||
87 | static inline cputime_t timeval_to_cputime(struct timeval *val) | ||
88 | { | ||
89 | cputime_t ret = val->tv_sec * NSEC_PER_SEC; | ||
90 | return (ret + val->tv_usec * NSEC_PER_USEC); | ||
91 | } | ||
92 | static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val) | ||
93 | { | ||
94 | val->tv_sec = ct / NSEC_PER_SEC; | ||
95 | val->tv_usec = (ct % NSEC_PER_SEC) / NSEC_PER_USEC; | ||
96 | } | ||
97 | |||
98 | /* | ||
99 | * Convert cputime <-> clock (USER_HZ) | ||
100 | */ | ||
101 | #define cputime_to_clock_t(__ct) ((__ct) / (NSEC_PER_SEC / USER_HZ)) | ||
102 | #define clock_t_to_cputime(__x) ((__x) * (NSEC_PER_SEC / USER_HZ)) | ||
103 | |||
104 | /* | ||
105 | * Convert cputime64 to clock. | ||
106 | */ | ||
107 | #define cputime64_to_clock_t(__ct) cputime_to_clock_t((cputime_t)__ct) | ||
5 | 108 | ||
109 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING */ | ||
6 | #endif /* __IA64_CPUTIME_H */ | 110 | #endif /* __IA64_CPUTIME_H */ |
diff --git a/include/asm-ia64/system.h b/include/asm-ia64/system.h index 595112bca3cc..dff8128fa58e 100644 --- a/include/asm-ia64/system.h +++ b/include/asm-ia64/system.h | |||
@@ -210,6 +210,13 @@ struct task_struct; | |||
210 | extern void ia64_save_extra (struct task_struct *task); | 210 | extern void ia64_save_extra (struct task_struct *task); |
211 | extern void ia64_load_extra (struct task_struct *task); | 211 | extern void ia64_load_extra (struct task_struct *task); |
212 | 212 | ||
213 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING | ||
214 | extern void ia64_account_on_switch (struct task_struct *prev, struct task_struct *next); | ||
215 | # define IA64_ACCOUNT_ON_SWITCH(p,n) ia64_account_on_switch(p,n) | ||
216 | #else | ||
217 | # define IA64_ACCOUNT_ON_SWITCH(p,n) | ||
218 | #endif | ||
219 | |||
213 | #ifdef CONFIG_PERFMON | 220 | #ifdef CONFIG_PERFMON |
214 | DECLARE_PER_CPU(unsigned long, pfm_syst_info); | 221 | DECLARE_PER_CPU(unsigned long, pfm_syst_info); |
215 | # define PERFMON_IS_SYSWIDE() (__get_cpu_var(pfm_syst_info) & 0x1) | 222 | # define PERFMON_IS_SYSWIDE() (__get_cpu_var(pfm_syst_info) & 0x1) |
@@ -222,6 +229,7 @@ extern void ia64_load_extra (struct task_struct *task); | |||
222 | || IS_IA32_PROCESS(task_pt_regs(t)) || PERFMON_IS_SYSWIDE()) | 229 | || IS_IA32_PROCESS(task_pt_regs(t)) || PERFMON_IS_SYSWIDE()) |
223 | 230 | ||
224 | #define __switch_to(prev,next,last) do { \ | 231 | #define __switch_to(prev,next,last) do { \ |
232 | IA64_ACCOUNT_ON_SWITCH(prev, next); \ | ||
225 | if (IA64_HAS_EXTRA_STATE(prev)) \ | 233 | if (IA64_HAS_EXTRA_STATE(prev)) \ |
226 | ia64_save_extra(prev); \ | 234 | ia64_save_extra(prev); \ |
227 | if (IA64_HAS_EXTRA_STATE(next)) \ | 235 | if (IA64_HAS_EXTRA_STATE(next)) \ |
@@ -266,6 +274,10 @@ void cpu_idle_wait(void); | |||
266 | 274 | ||
267 | void default_idle(void); | 275 | void default_idle(void); |
268 | 276 | ||
277 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING | ||
278 | extern void account_system_vtime(struct task_struct *); | ||
279 | #endif | ||
280 | |||
269 | #endif /* __KERNEL__ */ | 281 | #endif /* __KERNEL__ */ |
270 | 282 | ||
271 | #endif /* __ASSEMBLY__ */ | 283 | #endif /* __ASSEMBLY__ */ |
diff --git a/include/asm-ia64/thread_info.h b/include/asm-ia64/thread_info.h index 93d83cbe0c8c..6da8069a0f77 100644 --- a/include/asm-ia64/thread_info.h +++ b/include/asm-ia64/thread_info.h | |||
@@ -31,6 +31,12 @@ struct thread_info { | |||
31 | mm_segment_t addr_limit; /* user-level address space limit */ | 31 | mm_segment_t addr_limit; /* user-level address space limit */ |
32 | int preempt_count; /* 0=premptable, <0=BUG; will also serve as bh-counter */ | 32 | int preempt_count; /* 0=premptable, <0=BUG; will also serve as bh-counter */ |
33 | struct restart_block restart_block; | 33 | struct restart_block restart_block; |
34 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING | ||
35 | __u64 ac_stamp; | ||
36 | __u64 ac_leave; | ||
37 | __u64 ac_stime; | ||
38 | __u64 ac_utime; | ||
39 | #endif | ||
34 | }; | 40 | }; |
35 | 41 | ||
36 | #define THREAD_SIZE KERNEL_STACK_SIZE | 42 | #define THREAD_SIZE KERNEL_STACK_SIZE |
@@ -62,9 +68,17 @@ struct thread_info { | |||
62 | #define task_stack_page(tsk) ((void *)(tsk)) | 68 | #define task_stack_page(tsk) ((void *)(tsk)) |
63 | 69 | ||
64 | #define __HAVE_THREAD_FUNCTIONS | 70 | #define __HAVE_THREAD_FUNCTIONS |
71 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING | ||
72 | #define setup_thread_stack(p, org) \ | ||
73 | *task_thread_info(p) = *task_thread_info(org); \ | ||
74 | task_thread_info(p)->ac_stime = 0; \ | ||
75 | task_thread_info(p)->ac_utime = 0; \ | ||
76 | task_thread_info(p)->task = (p); | ||
77 | #else | ||
65 | #define setup_thread_stack(p, org) \ | 78 | #define setup_thread_stack(p, org) \ |
66 | *task_thread_info(p) = *task_thread_info(org); \ | 79 | *task_thread_info(p) = *task_thread_info(org); \ |
67 | task_thread_info(p)->task = (p); | 80 | task_thread_info(p)->task = (p); |
81 | #endif | ||
68 | #define end_of_stack(p) (unsigned long *)((void *)(p) + IA64_RBS_OFFSET) | 82 | #define end_of_stack(p) (unsigned long *)((void *)(p) + IA64_RBS_OFFSET) |
69 | 83 | ||
70 | #define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR | 84 | #define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR |