File Index
Files and directories
Sign in
FILE

idle.c

File preview with syntax highlighting.

linux-6.19.14/arch/s390/kernel/idle.c C
  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 update_timer_idle(void)
 25{
 26	struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
 27	struct lowcore *lc = get_lowcore();
 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	lc->steal_timer += idle->clock_idle_enter - lc->last_update_clock;
 38	lc->last_update_clock = lc->int_clock;
 39
 40	lc->system_timer += lc->last_update_timer - idle->timer_idle_enter;
 41	lc->last_update_timer = lc->sys_enter_timer;
 42}
 43
 44void account_idle_time_irq(void)
 45{
 46	struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
 47	unsigned long idle_time;
 48
 49	idle_time = get_lowcore()->int_clock - idle->clock_idle_enter;
 50
 51	/* Account time spent with enabled wait psw loaded as idle time. */
 52	WRITE_ONCE(idle->idle_time, READ_ONCE(idle->idle_time) + idle_time);
 53	WRITE_ONCE(idle->idle_count, READ_ONCE(idle->idle_count) + 1);
 54	account_idle_time(cputime_to_nsecs(idle_time));
 55}
 56
 57void noinstr arch_cpu_idle(void)
 58{
 59	struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
 60	unsigned long psw_mask;
 61
 62	/* Wait for external, I/O or machine check interrupt. */
 63	psw_mask = PSW_KERNEL_BITS | PSW_MASK_WAIT |
 64		   PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
 65	clear_cpu_flag(CIF_NOHZ_DELAY);
 66	set_cpu_flag(CIF_ENABLED_WAIT);
 67	if (smp_cpu_mtid)
 68		stcctm(MT_DIAG, smp_cpu_mtid, (u64 *)&idle->mt_cycles_enter);
 69	idle->clock_idle_enter = get_tod_clock_fast();
 70	idle->timer_idle_enter = get_cpu_timer();
 71	bpon();
 72	__load_psw_mask(psw_mask);
 73}
 74
 75static ssize_t show_idle_count(struct device *dev,
 76			       struct device_attribute *attr, char *buf)
 77{
 78	struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
 79
 80	return sysfs_emit(buf, "%lu\n", READ_ONCE(idle->idle_count));
 81}
 82DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
 83
 84static ssize_t show_idle_time(struct device *dev,
 85			      struct device_attribute *attr, char *buf)
 86{
 87	struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
 88
 89	return sysfs_emit(buf, "%lu\n", READ_ONCE(idle->idle_time) >> 12);
 90}
 91DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL);
 92
 93void arch_cpu_idle_enter(void)
 94{
 95}
 96
 97void arch_cpu_idle_exit(void)
 98{
 99}
100
101void __noreturn arch_cpu_idle_dead(void)
102{
103	cpu_die();
104}
~/ Read-only file preview.