Skip to content

Commit b5f87f1

Browse files
author
Martin Schwidefsky
committed
s390/idle: consolidate idle functions and definitions
Move the C functions and definitions related to the idle state handling to arch/s390/include/asm/idle.h and arch/s390/kernel/idle.c. The function s390_get_idle_time is renamed to arch_cpu_idle_time and vtime_stop_cpu to enabled_wait. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent fe0f497 commit b5f87f1

12 files changed

Lines changed: 166 additions & 144 deletions

File tree

‎arch/s390/include/asm/cputime.h‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#define _S390_CPUTIME_H
99

1010
#include <linux/types.h>
11-
#include <linux/percpu.h>
12-
#include <linux/spinlock.h>
1311
#include <asm/div64.h>
1412

1513

@@ -165,20 +163,8 @@ static inline clock_t cputime64_to_clock_t(cputime64_t cputime)
165163
return clock;
166164
}
167165

168-
struct s390_idle_data {
169-
unsigned int sequence;
170-
unsigned long long idle_count;
171-
unsigned long long idle_time;
172-
unsigned long long clock_idle_enter;
173-
unsigned long long clock_idle_exit;
174-
unsigned long long timer_idle_enter;
175-
unsigned long long timer_idle_exit;
176-
};
166+
cputime64_t arch_cpu_idle_time(int cpu);
177167

178-
DECLARE_PER_CPU(struct s390_idle_data, s390_idle);
179-
180-
cputime64_t s390_get_idle_time(int cpu);
181-
182-
#define arch_idle_time(cpu) s390_get_idle_time(cpu)
168+
#define arch_idle_time(cpu) arch_cpu_idle_time(cpu)
183169

184170
#endif /* _S390_CPUTIME_H */

‎arch/s390/include/asm/idle.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright IBM Corp. 2014
3+
*
4+
* Author: Martin Schwidefsky <schwidefsky@de.ibm.com>
5+
*/
6+
7+
#ifndef _S390_IDLE_H
8+
#define _S390_IDLE_H
9+
10+
#include <linux/types.h>
11+
#include <linux/device.h>
12+
13+
struct s390_idle_data {
14+
unsigned int sequence;
15+
unsigned long long idle_count;
16+
unsigned long long idle_time;
17+
unsigned long long clock_idle_enter;
18+
unsigned long long clock_idle_exit;
19+
unsigned long long timer_idle_enter;
20+
unsigned long long timer_idle_exit;
21+
};
22+
23+
extern struct device_attribute dev_attr_idle_count;
24+
extern struct device_attribute dev_attr_idle_time_us;
25+
26+
#endif /* _S390_IDLE_H */

‎arch/s390/include/asm/processor.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,12 @@ static inline unsigned long __rewind_psw(psw_t psw, unsigned long ilc)
289289
return (psw.addr - ilc) & mask;
290290
#endif
291291
}
292-
292+
293+
/*
294+
* Function to stop a processor until the next interrupt occurs
295+
*/
296+
void enabled_wait(void);
297+
293298
/*
294299
* Function to drop a processor into disabled wait state
295300
*/

‎arch/s390/include/asm/vtimer.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,4 @@ extern int del_virt_timer(struct vtimer_list *timer);
2828
extern void init_cpu_vtimer(void);
2929
extern void vtime_init(void);
3030

31-
extern void vtime_stop_cpu(void);
32-
3331
#endif /* _ASM_S390_TIMER_H */

‎arch/s390/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"'
2828

2929
CFLAGS_sysinfo.o += -Iinclude/math-emu -Iarch/s390/math-emu -w
3030

31-
obj-y := traps.o time.o process.o base.o early.o setup.o vtime.o
31+
obj-y := traps.o time.o process.o base.o early.o setup.o idle.o vtime.o
3232
obj-y += processor.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o nmi.o
3333
obj-y += debug.o irq.o ipl.o dis.o diag.o sclp.o vdso.o
3434
obj-y += sysinfo.o jump_label.o lgr.o os_info.o machine_kexec.o pgm_check.o

‎arch/s390/kernel/asm-offsets.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <linux/kbuild.h>
1010
#include <linux/kvm_host.h>
1111
#include <linux/sched.h>
12-
#include <asm/cputime.h>
12+
#include <asm/idle.h>
1313
#include <asm/vdso.h>
1414
#include <asm/pgtable.h>
1515

‎arch/s390/kernel/entry.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <linux/types.h>
55
#include <linux/signal.h>
66
#include <asm/ptrace.h>
7-
#include <asm/cputime.h>
7+
#include <asm/idle.h>
88

99
extern void *restart_stack;
1010
extern unsigned long suspend_zero_pages;

‎arch/s390/kernel/idle.c‎

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Idle functions for s390.
3+
*
4+
* Copyright IBM Corp. 2014
5+
*
6+
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7+
*/
8+
9+
#include <linux/kernel.h>
10+
#include <linux/kernel_stat.h>
11+
#include <linux/kprobes.h>
12+
#include <linux/notifier.h>
13+
#include <linux/init.h>
14+
#include <linux/cpu.h>
15+
#include <asm/cputime.h>
16+
#include <asm/nmi.h>
17+
#include <asm/smp.h>
18+
#include "entry.h"
19+
20+
static DEFINE_PER_CPU(struct s390_idle_data, s390_idle);
21+
22+
void __kprobes enabled_wait(void)
23+
{
24+
struct s390_idle_data *idle = &__get_cpu_var(s390_idle);
25+
unsigned long long idle_time;
26+
unsigned long psw_mask;
27+
28+
trace_hardirqs_on();
29+
30+
/* Wait for external, I/O or machine check interrupt. */
31+
psw_mask = PSW_KERNEL_BITS | PSW_MASK_WAIT | PSW_MASK_DAT |
32+
PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
33+
clear_cpu_flag(CIF_NOHZ_DELAY);
34+
35+
/* Call the assembler magic in entry.S */
36+
psw_idle(idle, psw_mask);
37+
38+
/* Account time spent with enabled wait psw loaded as idle time. */
39+
idle->sequence++;
40+
smp_wmb();
41+
idle_time = idle->clock_idle_exit - idle->clock_idle_enter;
42+
idle->clock_idle_enter = idle->clock_idle_exit = 0ULL;
43+
idle->idle_time += idle_time;
44+
idle->idle_count++;
45+
account_idle_time(idle_time);
46+
smp_wmb();
47+
idle->sequence++;
48+
}
49+
50+
static ssize_t show_idle_count(struct device *dev,
51+
struct device_attribute *attr, char *buf)
52+
{
53+
struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
54+
unsigned long long idle_count;
55+
unsigned int sequence;
56+
57+
do {
58+
sequence = ACCESS_ONCE(idle->sequence);
59+
idle_count = ACCESS_ONCE(idle->idle_count);
60+
if (ACCESS_ONCE(idle->clock_idle_enter))
61+
idle_count++;
62+
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
63+
return sprintf(buf, "%llu\n", idle_count);
64+
}
65+
DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
66+
67+
static ssize_t show_idle_time(struct device *dev,
68+
struct device_attribute *attr, char *buf)
69+
{
70+
struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
71+
unsigned long long now, idle_time, idle_enter, idle_exit;
72+
unsigned int sequence;
73+
74+
do {
75+
now = get_tod_clock();
76+
sequence = ACCESS_ONCE(idle->sequence);
77+
idle_time = ACCESS_ONCE(idle->idle_time);
78+
idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
79+
idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
80+
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
81+
idle_time += idle_enter ? ((idle_exit ? : now) - idle_enter) : 0;
82+
return sprintf(buf, "%llu\n", idle_time >> 12);
83+
}
84+
DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL);
85+
86+
cputime64_t arch_cpu_idle_time(int cpu)
87+
{
88+
struct s390_idle_data *idle = &per_cpu(s390_idle, cpu);
89+
unsigned long long now, idle_enter, idle_exit;
90+
unsigned int sequence;
91+
92+
do {
93+
now = get_tod_clock();
94+
sequence = ACCESS_ONCE(idle->sequence);
95+
idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
96+
idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
97+
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
98+
return idle_enter ? ((idle_exit ?: now) - idle_enter) : 0;
99+
}
100+
101+
void arch_cpu_idle_enter(void)
102+
{
103+
local_mcck_disable();
104+
}
105+
106+
void arch_cpu_idle(void)
107+
{
108+
if (!test_cpu_flag(CIF_MCCK_PENDING))
109+
/* Halt the cpu and keep track of cpu time accounting. */
110+
enabled_wait();
111+
local_irq_enable();
112+
}
113+
114+
void arch_cpu_idle_exit(void)
115+
{
116+
local_mcck_enable();
117+
if (test_cpu_flag(CIF_MCCK_PENDING))
118+
s390_handle_mcck();
119+
}
120+
121+
void arch_cpu_idle_dead(void)
122+
{
123+
cpu_die();
124+
}

‎arch/s390/kernel/process.c‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
6161
return sf->gprs[8];
6262
}
6363

64-
void arch_cpu_idle(void)
65-
{
66-
local_mcck_disable();
67-
if (test_cpu_flag(CIF_MCCK_PENDING)) {
68-
local_mcck_enable();
69-
local_irq_enable();
70-
return;
71-
}
72-
/* Halt the cpu and keep track of cpu time accounting. */
73-
vtime_stop_cpu();
74-
local_irq_enable();
75-
}
76-
77-
void arch_cpu_idle_exit(void)
78-
{
79-
if (test_cpu_flag(CIF_MCCK_PENDING))
80-
s390_handle_mcck();
81-
}
82-
83-
void arch_cpu_idle_dead(void)
84-
{
85-
cpu_die();
86-
}
87-
8864
extern void __kprobes kernel_thread_starter(void);
8965

9066
/*

‎arch/s390/kernel/smp.c‎

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <asm/debug.h>
4646
#include <asm/os_info.h>
4747
#include <asm/sigp.h>
48+
#include <asm/idle.h>
4849
#include "entry.h"
4950

5051
enum {
@@ -661,7 +662,7 @@ static void smp_start_secondary(void *cpuvoid)
661662
cpu_init();
662663
preempt_disable();
663664
init_cpu_timer();
664-
init_cpu_vtimer();
665+
vtime_init();
665666
pfault_init();
666667
notify_cpu_starting(smp_processor_id());
667668
set_cpu_online(smp_processor_id(), true);
@@ -893,42 +894,6 @@ static struct attribute_group cpu_common_attr_group = {
893894
.attrs = cpu_common_attrs,
894895
};
895896

896-
static ssize_t show_idle_count(struct device *dev,
897-
struct device_attribute *attr, char *buf)
898-
{
899-
struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
900-
unsigned long long idle_count;
901-
unsigned int sequence;
902-
903-
do {
904-
sequence = ACCESS_ONCE(idle->sequence);
905-
idle_count = ACCESS_ONCE(idle->idle_count);
906-
if (ACCESS_ONCE(idle->clock_idle_enter))
907-
idle_count++;
908-
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
909-
return sprintf(buf, "%llu\n", idle_count);
910-
}
911-
static DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
912-
913-
static ssize_t show_idle_time(struct device *dev,
914-
struct device_attribute *attr, char *buf)
915-
{
916-
struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
917-
unsigned long long now, idle_time, idle_enter, idle_exit;
918-
unsigned int sequence;
919-
920-
do {
921-
now = get_tod_clock();
922-
sequence = ACCESS_ONCE(idle->sequence);
923-
idle_time = ACCESS_ONCE(idle->idle_time);
924-
idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
925-
idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
926-
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
927-
idle_time += idle_enter ? ((idle_exit ? : now) - idle_enter) : 0;
928-
return sprintf(buf, "%llu\n", idle_time >> 12);
929-
}
930-
static DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL);
931-
932897
static struct attribute *cpu_online_attrs[] = {
933898
&dev_attr_idle_count.attr,
934899
&dev_attr_idle_time_us.attr,

0 commit comments

Comments
 (0)