2019-05-27 06:55:01 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
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>
2006-02-23 23:06:59 +00:00
|
|
|
/*
|
|
|
|
* Definitions for measuring cputime on powerpc machines.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Paul Mackerras, IBM Corp.
|
|
|
|
*
|
2012-07-25 05:56:04 +00:00
|
|
|
* If we have CONFIG_VIRT_CPU_ACCOUNTING_NATIVE, we measure cpu time in
|
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>
2006-02-23 23:06:59 +00:00
|
|
|
* the same units as the timebase. Otherwise we measure cpu time
|
|
|
|
* in jiffies using the generic definitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __POWERPC_CPUTIME_H
|
|
|
|
#define __POWERPC_CPUTIME_H
|
|
|
|
|
2017-01-31 03:09:51 +00:00
|
|
|
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
|
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>
2006-02-23 23:06:59 +00:00
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <asm/div64.h>
|
|
|
|
#include <asm/time.h>
|
|
|
|
#include <asm/param.h>
|
2022-05-06 09:14:24 +00:00
|
|
|
#include <asm/firmware.h>
|
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>
2006-02-23 23:06:59 +00:00
|
|
|
|
|
|
|
#ifdef __KERNEL__
|
2022-10-06 10:56:53 +00:00
|
|
|
#define cputime_to_nsecs(cputime) tb_to_ns(cputime)
|
2020-07-13 08:36:01 +00:00
|
|
|
|
2016-05-17 06:33:46 +00:00
|
|
|
/*
|
|
|
|
* PPC64 uses PACA which is task independent for storing accounting data while
|
|
|
|
* PPC32 uses struct thread_info, therefore at task switch the accounting data
|
|
|
|
* has to be populated in the new task
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_PPC64
|
2018-05-29 16:19:14 +00:00
|
|
|
#define get_accounting(tsk) (&get_paca()->accounting)
|
2020-02-25 17:35:34 +00:00
|
|
|
#define raw_get_accounting(tsk) (&local_paca->accounting)
|
2012-11-13 23:24:25 +00:00
|
|
|
static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
|
2020-02-25 17:35:34 +00:00
|
|
|
|
2016-05-17 06:33:46 +00:00
|
|
|
#else
|
2018-05-29 16:19:14 +00:00
|
|
|
#define get_accounting(tsk) (&task_thread_info(tsk)->accounting)
|
2020-02-25 17:35:34 +00:00
|
|
|
#define raw_get_accounting(tsk) get_accounting(tsk)
|
2018-05-29 16:19:14 +00:00
|
|
|
/*
|
|
|
|
* Called from the context switch with interrupts disabled, to charge all
|
|
|
|
* accumulated times to the current process, and to prepare accounting on
|
|
|
|
* the next process.
|
|
|
|
*/
|
|
|
|
static inline void arch_vtime_task_switch(struct task_struct *prev)
|
|
|
|
{
|
|
|
|
struct cpu_accounting_data *acct = get_accounting(current);
|
|
|
|
struct cpu_accounting_data *acct0 = get_accounting(prev);
|
|
|
|
|
|
|
|
acct->starttime = acct0->starttime;
|
|
|
|
}
|
2016-05-17 06:33:46 +00:00
|
|
|
#endif
|
2012-11-13 23:24:25 +00:00
|
|
|
|
2020-02-25 17:35:34 +00:00
|
|
|
/*
|
|
|
|
* account_cpu_user_entry/exit runs "unreconciled", so can't trace,
|
2020-07-26 00:38:03 +00:00
|
|
|
* can't use get_paca()
|
2020-02-25 17:35:34 +00:00
|
|
|
*/
|
|
|
|
static notrace inline void account_cpu_user_entry(void)
|
|
|
|
{
|
|
|
|
unsigned long tb = mftb();
|
|
|
|
struct cpu_accounting_data *acct = raw_get_accounting(current);
|
|
|
|
|
|
|
|
acct->utime += (tb - acct->starttime_user);
|
|
|
|
acct->starttime = tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static notrace inline void account_cpu_user_exit(void)
|
|
|
|
{
|
|
|
|
unsigned long tb = mftb();
|
|
|
|
struct cpu_accounting_data *acct = raw_get_accounting(current);
|
|
|
|
|
|
|
|
acct->stime += (tb - acct->starttime);
|
|
|
|
acct->starttime_user = tb;
|
|
|
|
}
|
|
|
|
|
2021-01-30 13:08:47 +00:00
|
|
|
static notrace inline void account_stolen_time(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PPC_SPLPAR
|
|
|
|
if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
|
|
|
|
struct lppaca *lp = local_paca->lppaca_ptr;
|
|
|
|
|
|
|
|
if (unlikely(local_paca->dtl_ridx != be64_to_cpu(lp->dtl_idx)))
|
2022-09-02 08:53:16 +00:00
|
|
|
pseries_accumulate_stolen_time();
|
2021-01-30 13:08:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2020-02-25 17:35:34 +00:00
|
|
|
|
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>
2006-02-23 23:06:59 +00:00
|
|
|
#endif /* __KERNEL__ */
|
2020-02-25 17:35:34 +00:00
|
|
|
#else /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
|
|
|
|
static inline void account_cpu_user_entry(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
static inline void account_cpu_user_exit(void)
|
|
|
|
{
|
|
|
|
}
|
2021-01-30 13:08:47 +00:00
|
|
|
static notrace inline void account_stolen_time(void)
|
|
|
|
{
|
|
|
|
}
|
2012-07-25 05:56:04 +00:00
|
|
|
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
|
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>
2006-02-23 23:06:59 +00:00
|
|
|
#endif /* __POWERPC_CPUTIME_H */
|