Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/arch/powerpc/include/asm/cputime.h
26481 views
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2
/*
3
* Definitions for measuring cputime on powerpc machines.
4
*
5
* Copyright (C) 2006 Paul Mackerras, IBM Corp.
6
*
7
* If we have CONFIG_VIRT_CPU_ACCOUNTING_NATIVE, we measure cpu time in
8
* the same units as the timebase. Otherwise we measure cpu time
9
* in jiffies using the generic definitions.
10
*/
11
12
#ifndef __POWERPC_CPUTIME_H
13
#define __POWERPC_CPUTIME_H
14
15
#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
16
17
#include <linux/types.h>
18
#include <linux/time.h>
19
#include <asm/div64.h>
20
#include <asm/time.h>
21
#include <asm/param.h>
22
#include <asm/firmware.h>
23
24
#ifdef __KERNEL__
25
#define cputime_to_nsecs(cputime) tb_to_ns(cputime)
26
27
/*
28
* PPC64 uses PACA which is task independent for storing accounting data while
29
* PPC32 uses struct thread_info, therefore at task switch the accounting data
30
* has to be populated in the new task
31
*/
32
#ifdef CONFIG_PPC64
33
#define get_accounting(tsk) (&get_paca()->accounting)
34
#define raw_get_accounting(tsk) (&local_paca->accounting)
35
36
#else
37
#define get_accounting(tsk) (&task_thread_info(tsk)->accounting)
38
#define raw_get_accounting(tsk) get_accounting(tsk)
39
#endif
40
41
/*
42
* account_cpu_user_entry/exit runs "unreconciled", so can't trace,
43
* can't use get_paca()
44
*/
45
static notrace inline void account_cpu_user_entry(void)
46
{
47
unsigned long tb = mftb();
48
struct cpu_accounting_data *acct = raw_get_accounting(current);
49
50
acct->utime += (tb - acct->starttime_user);
51
acct->starttime = tb;
52
}
53
54
static notrace inline void account_cpu_user_exit(void)
55
{
56
unsigned long tb = mftb();
57
struct cpu_accounting_data *acct = raw_get_accounting(current);
58
59
acct->stime += (tb - acct->starttime);
60
acct->starttime_user = tb;
61
}
62
63
static notrace inline void account_stolen_time(void)
64
{
65
#ifdef CONFIG_PPC_SPLPAR
66
if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
67
struct lppaca *lp = local_paca->lppaca_ptr;
68
69
if (unlikely(local_paca->dtl_ridx != be64_to_cpu(lp->dtl_idx)))
70
pseries_accumulate_stolen_time();
71
}
72
#endif
73
}
74
75
#endif /* __KERNEL__ */
76
#else /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
77
static inline void account_cpu_user_entry(void)
78
{
79
}
80
static inline void account_cpu_user_exit(void)
81
{
82
}
83
static notrace inline void account_stolen_time(void)
84
{
85
}
86
#endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
87
#endif /* __POWERPC_CPUTIME_H */
88
89