diff options
author | Paul Mackerras <paulus@samba.org> | 2006-02-23 18:06:59 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2006-02-23 22:05:56 -0500 |
commit | c6622f63db86fcbd41bf6fe05ddf2e00c1e51ced (patch) | |
tree | 102f3ea0a891212603a3722fece337d6a74d450c /include/asm-powerpc/ppc_asm.h | |
parent | a00428f5b149e36b8225b2a0812742a6dfb07b8c (diff) |
powerpc: Implement accurate task and CPU time accounting
This implements accurate task and cpu time accounting for 64-bit
powerpc kernels. Instead of accounting a whole jiffy of time to a
task on a timer interrupt because that task happened to be running at
the time, we now account time in units of timebase ticks according to
the actual time spent by the task in user mode and kernel mode. We
also count the time spent processing hardware and software interrupts
accurately. This is conditional on CONFIG_VIRT_CPU_ACCOUNTING. If
that is not set, we do tick-based approximate accounting as before.
To get this accurate information, we read either the PURR (processor
utilization of resources register) on POWER5 machines, or the timebase
on other machines on
* each entry to the kernel from usermode
* each exit to usermode
* transitions between process context, hard irq context and soft irq
context in kernel mode
* context switches.
On POWER5 systems with shared-processor logical partitioning we also
read both the PURR and the timebase at each timer interrupt and
context switch in order to determine how much time has been taken by
the hypervisor to run other partitions ("steal" time). Unfortunately,
since we need values of the PURR on both threads at the same time to
accurately calculate the steal time, and since we can only calculate
steal time on a per-core basis, the apportioning of the steal time
between idle time (time which we ceded to the hypervisor in the idle
loop) and actual stolen time is somewhat approximate at the moment.
This is all based quite heavily on what s390 does, and it uses the
generic interfaces that were added by the s390 developers,
i.e. account_system_time(), account_user_time(), etc.
This patch doesn't add any new interfaces between the kernel and
userspace, and doesn't change the units in which time is reported to
userspace by things such as /proc/stat, /proc/<pid>/stat, getrusage(),
times(), etc. Internally the various task and cpu times are stored in
timebase units, but they are converted to USER_HZ units (1/100th of a
second) when reported to userspace. Some precision is therefore lost
but there should not be any accumulating error, since the internal
accumulation is at full precision.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'include/asm-powerpc/ppc_asm.h')
-rw-r--r-- | include/asm-powerpc/ppc_asm.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/include/asm-powerpc/ppc_asm.h b/include/asm-powerpc/ppc_asm.h index ab8688d39024..dd1c0a913d5f 100644 --- a/include/asm-powerpc/ppc_asm.h +++ b/include/asm-powerpc/ppc_asm.h | |||
@@ -15,6 +15,48 @@ | |||
15 | #define SZL (BITS_PER_LONG/8) | 15 | #define SZL (BITS_PER_LONG/8) |
16 | 16 | ||
17 | /* | 17 | /* |
18 | * Stuff for accurate CPU time accounting. | ||
19 | * These macros handle transitions between user and system state | ||
20 | * in exception entry and exit and accumulate time to the | ||
21 | * user_time and system_time fields in the paca. | ||
22 | */ | ||
23 | |||
24 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING | ||
25 | #define ACCOUNT_CPU_USER_ENTRY(ra, rb) | ||
26 | #define ACCOUNT_CPU_USER_EXIT(ra, rb) | ||
27 | #else | ||
28 | #define ACCOUNT_CPU_USER_ENTRY(ra, rb) \ | ||
29 | beq 2f; /* if from kernel mode */ \ | ||
30 | BEGIN_FTR_SECTION; \ | ||
31 | mfspr ra,SPRN_PURR; /* get processor util. reg */ \ | ||
32 | END_FTR_SECTION_IFSET(CPU_FTR_PURR); \ | ||
33 | BEGIN_FTR_SECTION; \ | ||
34 | mftb ra; /* or get TB if no PURR */ \ | ||
35 | END_FTR_SECTION_IFCLR(CPU_FTR_PURR); \ | ||
36 | ld rb,PACA_STARTPURR(r13); \ | ||
37 | std ra,PACA_STARTPURR(r13); \ | ||
38 | subf rb,rb,ra; /* subtract start value */ \ | ||
39 | ld ra,PACA_USER_TIME(r13); \ | ||
40 | add ra,ra,rb; /* add on to user time */ \ | ||
41 | std ra,PACA_USER_TIME(r13); \ | ||
42 | 2: | ||
43 | |||
44 | #define ACCOUNT_CPU_USER_EXIT(ra, rb) \ | ||
45 | BEGIN_FTR_SECTION; \ | ||
46 | mfspr ra,SPRN_PURR; /* get processor util. reg */ \ | ||
47 | END_FTR_SECTION_IFSET(CPU_FTR_PURR); \ | ||
48 | BEGIN_FTR_SECTION; \ | ||
49 | mftb ra; /* or get TB if no PURR */ \ | ||
50 | END_FTR_SECTION_IFCLR(CPU_FTR_PURR); \ | ||
51 | ld rb,PACA_STARTPURR(r13); \ | ||
52 | std ra,PACA_STARTPURR(r13); \ | ||
53 | subf rb,rb,ra; /* subtract start value */ \ | ||
54 | ld ra,PACA_SYSTEM_TIME(r13); \ | ||
55 | add ra,ra,rb; /* add on to user time */ \ | ||
56 | std ra,PACA_SYSTEM_TIME(r13); | ||
57 | #endif | ||
58 | |||
59 | /* | ||
18 | * Macros for storing registers into and loading registers from | 60 | * Macros for storing registers into and loading registers from |
19 | * exception frames. | 61 | * exception frames. |
20 | */ | 62 | */ |