xref: /linux/arch/s390/include/asm/vtime.h (revision 375d5d57545f53d2bc3e15ada0e9da360fc68bea)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _S390_VTIME_H
3 #define _S390_VTIME_H
4 
5 #include <asm/lowcore.h>
6 #include <asm/cpu_mf.h>
7 #include <asm/idle.h>
8 
9 DECLARE_PER_CPU(u64, mt_cycles[8]);
10 
11 void vtime_init(void);
12 
update_timer_sys(void)13 static inline void update_timer_sys(void)
14 {
15 	struct lowcore *lc = get_lowcore();
16 
17 	lc->system_timer += lc->last_update_timer - lc->exit_timer;
18 	lc->user_timer += lc->exit_timer - lc->sys_enter_timer;
19 	lc->last_update_timer = lc->sys_enter_timer;
20 }
21 
update_timer_mcck(void)22 static inline void update_timer_mcck(void)
23 {
24 	struct lowcore *lc = get_lowcore();
25 
26 	lc->system_timer += lc->last_update_timer - lc->exit_timer;
27 	lc->user_timer += lc->exit_timer - lc->mcck_enter_timer;
28 	lc->last_update_timer = lc->mcck_enter_timer;
29 }
30 
update_timer_idle(void)31 static inline void update_timer_idle(void)
32 {
33 	struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
34 	struct lowcore *lc = get_lowcore();
35 	u64 cycles_new[8];
36 	int i, mtid;
37 
38 	mtid = smp_cpu_mtid;
39 	if (mtid) {
40 		stcctm(MT_DIAG, mtid, cycles_new);
41 		for (i = 0; i < mtid; i++)
42 			__this_cpu_add(mt_cycles[i], cycles_new[i] - idle->mt_cycles_enter[i]);
43 	}
44 	/*
45 	 * This is a bit subtle: Forward last_update_clock so it excludes idle
46 	 * time. For correct steal time calculation in do_account_vtime() add
47 	 * passed wall time before idle_enter to steal_timer:
48 	 * During the passed wall time before idle_enter CPU time may have
49 	 * been accounted to system, hardirq, softirq, etc. lowcore fields.
50 	 * The accounted CPU times will be subtracted again from steal_timer
51 	 * when accumulated steal time is calculated in do_account_vtime().
52 	 */
53 	lc->steal_timer += idle->clock_idle_enter.tod - lc->last_update_clock;
54 	lc->last_update_clock = lc->int_clock.tod;
55 	lc->system_timer += lc->last_update_timer - idle->timer_idle_enter;
56 	lc->last_update_timer = lc->sys_enter_timer;
57 }
58 
59 #endif /* _S390_VTIME_H */
60