blob: 2cdeca062db32c04388c654b2429381b4c17a23f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +02002#ifndef _LINUX_KERNEL_VTIME_H
3#define _LINUX_KERNEL_VTIME_H
4
Frederic Weisbeckerb0493402013-07-12 03:10:15 +02005#include <linux/context_tracking_state.h>
Frederic Weisbeckera5725ac2013-07-16 18:50:52 +02006#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
7#include <asm/vtime.h>
8#endif
9
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020010
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020011struct task_struct;
12
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020013/*
Frederic Weisbeckere44fcb42019-10-16 04:56:54 +020014 * vtime_accounting_enabled_this_cpu() definitions/declarations
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020015 */
Frederic Weisbecker8612f172016-07-13 16:50:04 +020016#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE)
Frederic Weisbecker8d495472019-10-03 18:17:45 +020017
Frederic Weisbeckere44fcb42019-10-16 04:56:54 +020018static inline bool vtime_accounting_enabled_this_cpu(void) { return true; }
Frederic Weisbecker8d495472019-10-03 18:17:45 +020019extern void vtime_task_switch(struct task_struct *prev);
20
Frederic Weisbecker8612f172016-07-13 16:50:04 +020021#elif defined(CONFIG_VIRT_CPU_ACCOUNTING_GEN)
Frederic Weisbecker8d495472019-10-03 18:17:45 +020022
Frederic Weisbeckere5925392015-11-19 16:47:33 +010023/*
24 * Checks if vtime is enabled on some CPU. Cputime readers want to be careful
25 * in that case and compute the tickless cputime.
26 * For now vtime state is tied to context tracking. We might want to decouple
27 * those later if necessary.
28 */
29static inline bool vtime_accounting_enabled(void)
30{
Frederic Weisbecker74c57872019-10-16 04:56:51 +020031 return context_tracking_enabled();
Frederic Weisbeckere5925392015-11-19 16:47:33 +010032}
33
Frederic Weisbecker9adbb9d2019-10-16 04:56:55 +020034static inline bool vtime_accounting_enabled_cpu(int cpu)
35{
Frederic Weisbecker023e9de2019-10-16 04:56:56 +020036 return context_tracking_enabled_cpu(cpu);
Frederic Weisbecker9adbb9d2019-10-16 04:56:55 +020037}
38
Frederic Weisbeckere44fcb42019-10-16 04:56:54 +020039static inline bool vtime_accounting_enabled_this_cpu(void)
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020040{
Frederic Weisbecker023e9de2019-10-16 04:56:56 +020041 return context_tracking_enabled_this_cpu();
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020042}
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020043
Frederic Weisbecker8d495472019-10-03 18:17:45 +020044extern void vtime_task_switch_generic(struct task_struct *prev);
45
46static inline void vtime_task_switch(struct task_struct *prev)
47{
Frederic Weisbeckere44fcb42019-10-16 04:56:54 +020048 if (vtime_accounting_enabled_this_cpu())
Frederic Weisbecker8d495472019-10-03 18:17:45 +020049 vtime_task_switch_generic(prev);
50}
51
52#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
53
Frederic Weisbecker9adbb9d2019-10-16 04:56:55 +020054static inline bool vtime_accounting_enabled_cpu(int cpu) {return false; }
Frederic Weisbeckere44fcb42019-10-16 04:56:54 +020055static inline bool vtime_accounting_enabled_this_cpu(void) { return false; }
Frederic Weisbecker8d495472019-10-03 18:17:45 +020056static inline void vtime_task_switch(struct task_struct *prev) { }
57
58#endif
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020059
60/*
61 * Common vtime APIs
62 */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020063#ifdef CONFIG_VIRT_CPU_ACCOUNTING
Frederic Weisbeckerf83eeb12019-10-03 18:17:44 +020064extern void vtime_account_kernel(struct task_struct *tsk);
Frederic Weisbeckerfd25b4c2012-11-13 18:21:22 +010065extern void vtime_account_idle(struct task_struct *tsk);
Frederic Weisbecker3f4724e2012-07-16 18:00:34 +020066#else /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbeckerf83eeb12019-10-03 18:17:44 +020067static inline void vtime_account_kernel(struct task_struct *tsk) { }
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020068#endif /* !CONFIG_VIRT_CPU_ACCOUNTING */
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +020069
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020070#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
Frederic Weisbecker6a616712012-12-16 20:00:34 +010071extern void arch_vtime_task_switch(struct task_struct *tsk);
Frederic Weisbecker6a616712012-12-16 20:00:34 +010072extern void vtime_user_enter(struct task_struct *tsk);
Frederic Weisbecker1c3eda02017-06-29 19:15:07 +020073extern void vtime_user_exit(struct task_struct *tsk);
Frederic Weisbecker6a616712012-12-16 20:00:34 +010074extern void vtime_guest_enter(struct task_struct *tsk);
75extern void vtime_guest_exit(struct task_struct *tsk);
Frederic Weisbecker45eacc62013-05-15 22:16:32 +020076extern void vtime_init_idle(struct task_struct *tsk, int cpu);
Frederic Weisbeckerb0493402013-07-12 03:10:15 +020077#else /* !CONFIG_VIRT_CPU_ACCOUNTING_GEN */
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020078static inline void vtime_user_enter(struct task_struct *tsk) { }
79static inline void vtime_user_exit(struct task_struct *tsk) { }
Frederic Weisbecker6a616712012-12-16 20:00:34 +010080static inline void vtime_guest_enter(struct task_struct *tsk) { }
81static inline void vtime_guest_exit(struct task_struct *tsk) { }
Frederic Weisbecker45eacc62013-05-15 22:16:32 +020082static inline void vtime_init_idle(struct task_struct *tsk, int cpu) { }
Frederic Weisbeckerabf917c2012-07-25 07:56:04 +020083#endif
84
Frederic Weisbecker8612f172016-07-13 16:50:04 +020085#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
86extern void vtime_account_irq_enter(struct task_struct *tsk);
87static inline void vtime_account_irq_exit(struct task_struct *tsk)
88{
89 /* On hard|softirq exit we always account to hard|softirq cputime */
Frederic Weisbeckerf83eeb12019-10-03 18:17:44 +020090 vtime_account_kernel(tsk);
Frederic Weisbecker8612f172016-07-13 16:50:04 +020091}
Frederic Weisbeckerc8d7dab2017-01-05 18:11:50 +010092extern void vtime_flush(struct task_struct *tsk);
Frederic Weisbecker8612f172016-07-13 16:50:04 +020093#else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
94static inline void vtime_account_irq_enter(struct task_struct *tsk) { }
95static inline void vtime_account_irq_exit(struct task_struct *tsk) { }
Frederic Weisbeckerc8d7dab2017-01-05 18:11:50 +010096static inline void vtime_flush(struct task_struct *tsk) { }
Frederic Weisbecker8612f172016-07-13 16:50:04 +020097#endif
98
99
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200100#ifdef CONFIG_IRQ_TIME_ACCOUNTING
101extern void irqtime_account_irq(struct task_struct *tsk);
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200102#else
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200103static inline void irqtime_account_irq(struct task_struct *tsk) { }
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200104#endif
105
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100106static inline void account_irq_enter_time(struct task_struct *tsk)
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200107{
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100108 vtime_account_irq_enter(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200109 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200110}
111
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100112static inline void account_irq_exit_time(struct task_struct *tsk)
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200113{
Frederic Weisbecker6a616712012-12-16 20:00:34 +0100114 vtime_account_irq_exit(tsk);
Frederic Weisbecker3e1df4f52012-10-06 05:23:22 +0200115 irqtime_account_irq(tsk);
Frederic Weisbeckerfa5058f2012-10-06 04:07:19 +0200116}
117
Frederic Weisbeckerdcbf8322012-10-05 23:07:19 +0200118#endif /* _LINUX_KERNEL_VTIME_H */