1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Definitions for measuring cputime on powerpc machines.
5 * Copyright (C) 2006 Paul Mackerras, IBM Corp.
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.
12 #ifndef __POWERPC_CPUTIME_H
13 #define __POWERPC_CPUTIME_H
15 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
17 #include <linux/types.h>
18 #include <linux/time.h>
19 #include <asm/div64.h>
21 #include <asm/param.h>
22 #include <asm/firmware.h>
25 #define cputime_to_nsecs(cputime) tb_to_ns(cputime)
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
33 #define get_accounting(tsk) (&get_paca()->accounting)
34 #define raw_get_accounting(tsk) (&local_paca->accounting)
35 static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
38 #define get_accounting(tsk) (&task_thread_info(tsk)->accounting)
39 #define raw_get_accounting(tsk) get_accounting(tsk)
41 * Called from the context switch with interrupts disabled, to charge all
42 * accumulated times to the current process, and to prepare accounting on
45 static inline void arch_vtime_task_switch(struct task_struct *prev)
47 struct cpu_accounting_data *acct = get_accounting(current);
48 struct cpu_accounting_data *acct0 = get_accounting(prev);
50 acct->starttime = acct0->starttime;
55 * account_cpu_user_entry/exit runs "unreconciled", so can't trace,
56 * can't use get_paca()
58 static notrace inline void account_cpu_user_entry(void)
60 unsigned long tb = mftb();
61 struct cpu_accounting_data *acct = raw_get_accounting(current);
63 acct->utime += (tb - acct->starttime_user);
67 static notrace inline void account_cpu_user_exit(void)
69 unsigned long tb = mftb();
70 struct cpu_accounting_data *acct = raw_get_accounting(current);
72 acct->stime += (tb - acct->starttime);
73 acct->starttime_user = tb;
76 static notrace inline void account_stolen_time(void)
78 #ifdef CONFIG_PPC_SPLPAR
79 if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
80 struct lppaca *lp = local_paca->lppaca_ptr;
82 if (unlikely(local_paca->dtl_ridx != be64_to_cpu(lp->dtl_idx)))
83 pseries_accumulate_stolen_time();
88 #endif /* __KERNEL__ */
89 #else /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
90 static inline void account_cpu_user_entry(void)
93 static inline void account_cpu_user_exit(void)
96 static notrace inline void account_stolen_time(void)
99 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
100 #endif /* __POWERPC_CPUTIME_H */