Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2/*
 3 * Idle functions for s390.
 4 *
 5 * Copyright IBM Corp. 2014
 6 *
 7 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
 8 */
 9
10#include <linux/kernel.h>
11#include <linux/kernel_stat.h>
 
12#include <linux/notifier.h>
13#include <linux/init.h>
14#include <linux/cpu.h>
15#include <trace/events/power.h>
16#include <asm/cpu_mf.h>
17#include <asm/cputime.h>
18#include <asm/nmi.h>
19#include <asm/smp.h>
20#include "entry.h"
21
22static DEFINE_PER_CPU(struct s390_idle_data, s390_idle);
23
24void account_idle_time_irq(void)
25{
26	struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
27	unsigned long idle_time;
28	u64 cycles_new[8];
29	int i;
30
31	if (smp_cpu_mtid) {
32		stcctm(MT_DIAG, smp_cpu_mtid, cycles_new);
33		for (i = 0; i < smp_cpu_mtid; i++)
34			this_cpu_add(mt_cycles[i], cycles_new[i] - idle->mt_cycles_enter[i]);
35	}
36
37	idle_time = S390_lowcore.int_clock - idle->clock_idle_enter;
38
39	S390_lowcore.steal_timer += idle->clock_idle_enter - S390_lowcore.last_update_clock;
40	S390_lowcore.last_update_clock = S390_lowcore.int_clock;
41
42	S390_lowcore.system_timer += S390_lowcore.last_update_timer - idle->timer_idle_enter;
43	S390_lowcore.last_update_timer = S390_lowcore.sys_enter_timer;
44
45	/* Account time spent with enabled wait psw loaded as idle time. */
46	WRITE_ONCE(idle->idle_time, READ_ONCE(idle->idle_time) + idle_time);
47	WRITE_ONCE(idle->idle_count, READ_ONCE(idle->idle_count) + 1);
48	account_idle_time(cputime_to_nsecs(idle_time));
49}
50
51void noinstr arch_cpu_idle(void)
52{
53	struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
 
54	unsigned long psw_mask;
55
 
 
56	/* Wait for external, I/O or machine check interrupt. */
57	psw_mask = PSW_KERNEL_BITS | PSW_MASK_WAIT |
58		   PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
59	clear_cpu_flag(CIF_NOHZ_DELAY);
60
61	/* psw_idle() returns with interrupts disabled. */
62	psw_idle(idle, psw_mask);
 
 
 
 
 
 
 
 
 
 
 
63}
 
64
65static ssize_t show_idle_count(struct device *dev,
66			       struct device_attribute *attr, char *buf)
67{
68	struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
 
 
69
70	return sysfs_emit(buf, "%lu\n", READ_ONCE(idle->idle_count));
 
 
 
 
 
 
71}
72DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
73
74static ssize_t show_idle_time(struct device *dev,
75			      struct device_attribute *attr, char *buf)
76{
77	struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
 
 
78
79	return sysfs_emit(buf, "%lu\n", READ_ONCE(idle->idle_time) >> 12);
 
 
 
 
 
 
 
 
80}
81DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL);
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83void arch_cpu_idle_enter(void)
84{
 
 
 
 
 
 
 
 
 
85}
86
87void arch_cpu_idle_exit(void)
88{
 
 
 
89}
90
91void __noreturn arch_cpu_idle_dead(void)
92{
93	cpu_die();
94}
v4.17
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Idle functions for s390.
  4 *
  5 * Copyright IBM Corp. 2014
  6 *
  7 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  8 */
  9
 10#include <linux/kernel.h>
 11#include <linux/kernel_stat.h>
 12#include <linux/kprobes.h>
 13#include <linux/notifier.h>
 14#include <linux/init.h>
 15#include <linux/cpu.h>
 16#include <linux/sched/cputime.h>
 
 
 17#include <asm/nmi.h>
 18#include <asm/smp.h>
 19#include "entry.h"
 20
 21static DEFINE_PER_CPU(struct s390_idle_data, s390_idle);
 22
 23void enabled_wait(void)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 24{
 25	struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
 26	unsigned long long idle_time;
 27	unsigned long psw_mask;
 28
 29	trace_hardirqs_on();
 30
 31	/* Wait for external, I/O or machine check interrupt. */
 32	psw_mask = PSW_KERNEL_BITS | PSW_MASK_WAIT | PSW_MASK_DAT |
 33		PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
 34	clear_cpu_flag(CIF_NOHZ_DELAY);
 35
 36	/* Call the assembler magic in entry.S */
 37	psw_idle(idle, psw_mask);
 38
 39	trace_hardirqs_off();
 40
 41	/* Account time spent with enabled wait psw loaded as idle time. */
 42	write_seqcount_begin(&idle->seqcount);
 43	idle_time = idle->clock_idle_exit - idle->clock_idle_enter;
 44	idle->clock_idle_enter = idle->clock_idle_exit = 0ULL;
 45	idle->idle_time += idle_time;
 46	idle->idle_count++;
 47	account_idle_time(cputime_to_nsecs(idle_time));
 48	write_seqcount_end(&idle->seqcount);
 49}
 50NOKPROBE_SYMBOL(enabled_wait);
 51
 52static ssize_t show_idle_count(struct device *dev,
 53				struct device_attribute *attr, char *buf)
 54{
 55	struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
 56	unsigned long long idle_count;
 57	unsigned int seq;
 58
 59	do {
 60		seq = read_seqcount_begin(&idle->seqcount);
 61		idle_count = READ_ONCE(idle->idle_count);
 62		if (READ_ONCE(idle->clock_idle_enter))
 63			idle_count++;
 64	} while (read_seqcount_retry(&idle->seqcount, seq));
 65	return sprintf(buf, "%llu\n", idle_count);
 66}
 67DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
 68
 69static ssize_t show_idle_time(struct device *dev,
 70				struct device_attribute *attr, char *buf)
 71{
 72	struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
 73	unsigned long long now, idle_time, idle_enter, idle_exit;
 74	unsigned int seq;
 75
 76	do {
 77		now = get_tod_clock();
 78		seq = read_seqcount_begin(&idle->seqcount);
 79		idle_time = READ_ONCE(idle->idle_time);
 80		idle_enter = READ_ONCE(idle->clock_idle_enter);
 81		idle_exit = READ_ONCE(idle->clock_idle_exit);
 82	} while (read_seqcount_retry(&idle->seqcount, seq));
 83	idle_time += idle_enter ? ((idle_exit ? : now) - idle_enter) : 0;
 84	return sprintf(buf, "%llu\n", idle_time >> 12);
 85}
 86DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL);
 87
 88u64 arch_cpu_idle_time(int cpu)
 89{
 90	struct s390_idle_data *idle = &per_cpu(s390_idle, cpu);
 91	unsigned long long now, idle_enter, idle_exit;
 92	unsigned int seq;
 93
 94	do {
 95		now = get_tod_clock();
 96		seq = read_seqcount_begin(&idle->seqcount);
 97		idle_enter = READ_ONCE(idle->clock_idle_enter);
 98		idle_exit = READ_ONCE(idle->clock_idle_exit);
 99	} while (read_seqcount_retry(&idle->seqcount, seq));
100
101	return cputime_to_nsecs(idle_enter ? ((idle_exit ?: now) - idle_enter) : 0);
102}
103
104void arch_cpu_idle_enter(void)
105{
106	local_mcck_disable();
107}
108
109void arch_cpu_idle(void)
110{
111	if (!test_cpu_flag(CIF_MCCK_PENDING))
112		/* Halt the cpu and keep track of cpu time accounting. */
113		enabled_wait();
114	local_irq_enable();
115}
116
117void arch_cpu_idle_exit(void)
118{
119	local_mcck_enable();
120	if (test_cpu_flag(CIF_MCCK_PENDING))
121		s390_handle_mcck();
122}
123
124void arch_cpu_idle_dead(void)
125{
126	cpu_die();
127}