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>
23 typedef u64 __nocast cputime_t;
24 typedef u64 __nocast cputime64_t;
26 #define cmpxchg_cputime(ptr, old, new) cmpxchg(ptr, old, new)
30 * Convert cputime <-> microseconds
32 extern u64 __cputime_usec_factor;
34 static inline unsigned long cputime_to_usecs(const cputime_t ct)
36 return mulhdu((__force u64) ct, __cputime_usec_factor);
40 * PPC64 uses PACA which is task independent for storing accounting data while
41 * PPC32 uses struct thread_info, therefore at task switch the accounting data
42 * has to be populated in the new task
45 #define get_accounting(tsk) (&get_paca()->accounting)
46 static inline void arch_vtime_task_switch(struct task_struct *tsk) { }
48 #define get_accounting(tsk) (&task_thread_info(tsk)->accounting)
50 * Called from the context switch with interrupts disabled, to charge all
51 * accumulated times to the current process, and to prepare accounting on
54 static inline void arch_vtime_task_switch(struct task_struct *prev)
56 struct cpu_accounting_data *acct = get_accounting(current);
57 struct cpu_accounting_data *acct0 = get_accounting(prev);
59 acct->starttime = acct0->starttime;
63 #endif /* __KERNEL__ */
64 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
65 #endif /* __POWERPC_CPUTIME_H */