Skip to content

Commit 1ce2180

Browse files
fweisbecMartin Schwidefsky
authored andcommitted
s390/idle: convert open coded idle time seqcount
s390 uses open coded seqcount to synchronize idle time accounting. Lets consolidate it with the standard API. Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 200e7c0 commit 1ce2180

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010
#include <linux/types.h>
1111
#include <linux/device.h>
12+
#include <linux/seqlock.h>
1213

1314
struct s390_idle_data {
14-
unsigned int sequence;
15+
seqcount_t seqcount;
1516
unsigned long long idle_count;
1617
unsigned long long idle_time;
1718
unsigned long long clock_idle_enter;

‎arch/s390/kernel/idle.c‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ void enabled_wait(void)
3838
trace_hardirqs_off();
3939

4040
/* Account time spent with enabled wait psw loaded as idle time. */
41-
idle->sequence++;
42-
smp_wmb();
41+
write_seqcount_begin(&idle->seqcount);
4342
idle_time = idle->clock_idle_exit - idle->clock_idle_enter;
4443
idle->clock_idle_enter = idle->clock_idle_exit = 0ULL;
4544
idle->idle_time += idle_time;
4645
idle->idle_count++;
4746
account_idle_time(idle_time);
48-
smp_wmb();
49-
idle->sequence++;
47+
write_seqcount_end(&idle->seqcount);
5048
}
5149
NOKPROBE_SYMBOL(enabled_wait);
5250

@@ -55,14 +53,14 @@ static ssize_t show_idle_count(struct device *dev,
5553
{
5654
struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
5755
unsigned long long idle_count;
58-
unsigned int sequence;
56+
unsigned int seq;
5957

6058
do {
61-
sequence = ACCESS_ONCE(idle->sequence);
59+
seq = read_seqcount_begin(&idle->seqcount);
6260
idle_count = ACCESS_ONCE(idle->idle_count);
6361
if (ACCESS_ONCE(idle->clock_idle_enter))
6462
idle_count++;
65-
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
63+
} while (read_seqcount_retry(&idle->seqcount, seq));
6664
return sprintf(buf, "%llu\n", idle_count);
6765
}
6866
DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
@@ -72,15 +70,15 @@ static ssize_t show_idle_time(struct device *dev,
7270
{
7371
struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
7472
unsigned long long now, idle_time, idle_enter, idle_exit;
75-
unsigned int sequence;
73+
unsigned int seq;
7674

7775
do {
7876
now = get_tod_clock();
79-
sequence = ACCESS_ONCE(idle->sequence);
77+
seq = read_seqcount_begin(&idle->seqcount);
8078
idle_time = ACCESS_ONCE(idle->idle_time);
8179
idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
8280
idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
83-
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
81+
} while (read_seqcount_retry(&idle->seqcount, seq));
8482
idle_time += idle_enter ? ((idle_exit ? : now) - idle_enter) : 0;
8583
return sprintf(buf, "%llu\n", idle_time >> 12);
8684
}
@@ -90,14 +88,14 @@ cputime64_t arch_cpu_idle_time(int cpu)
9088
{
9189
struct s390_idle_data *idle = &per_cpu(s390_idle, cpu);
9290
unsigned long long now, idle_enter, idle_exit;
93-
unsigned int sequence;
91+
unsigned int seq;
9492

9593
do {
9694
now = get_tod_clock();
97-
sequence = ACCESS_ONCE(idle->sequence);
95+
seq = read_seqcount_begin(&idle->seqcount);
9896
idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
9997
idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
100-
} while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
98+
} while (read_seqcount_retry(&idle->seqcount, seq));
10199
return idle_enter ? ((idle_exit ?: now) - idle_enter) : 0;
102100
}
103101

0 commit comments

Comments
 (0)