Skip to content

Commit 46c3031

Browse files
svens-s390Vasily Gorbik
authored andcommitted
s390/vtime: Remove duplicate get_lowcore() calls
Assign the output from get_lowcore() to a local variable, so the code is easier to read. Acked-by: Heiko Carstens <[email protected]> Signed-off-by: Sven Schnelle <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent eb28ec2 commit 46c3031

File tree

2 files changed

+52
-42
lines changed

2 files changed

+52
-42
lines changed

arch/s390/include/asm/vtime.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44

55
static inline void update_timer_sys(void)
66
{
7-
get_lowcore()->system_timer += get_lowcore()->last_update_timer - get_lowcore()->exit_timer;
8-
get_lowcore()->user_timer += get_lowcore()->exit_timer - get_lowcore()->sys_enter_timer;
9-
get_lowcore()->last_update_timer = get_lowcore()->sys_enter_timer;
7+
struct lowcore *lc = get_lowcore();
8+
9+
lc->system_timer += lc->last_update_timer - lc->exit_timer;
10+
lc->user_timer += lc->exit_timer - lc->sys_enter_timer;
11+
lc->last_update_timer = lc->sys_enter_timer;
1012
}
1113

1214
static inline void update_timer_mcck(void)
1315
{
14-
get_lowcore()->system_timer += get_lowcore()->last_update_timer - get_lowcore()->exit_timer;
15-
get_lowcore()->user_timer += get_lowcore()->exit_timer - get_lowcore()->mcck_enter_timer;
16-
get_lowcore()->last_update_timer = get_lowcore()->mcck_enter_timer;
16+
struct lowcore *lc = get_lowcore();
17+
18+
lc->system_timer += lc->last_update_timer - lc->exit_timer;
19+
lc->user_timer += lc->exit_timer - lc->mcck_enter_timer;
20+
lc->last_update_timer = lc->mcck_enter_timer;
1721
}
1822

1923
#endif /* _S390_VTIME_H */

arch/s390/kernel/vtime.c

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ static DEFINE_PER_CPU(u64, mt_scaling_jiffies);
3535

3636
static inline void set_vtimer(u64 expires)
3737
{
38+
struct lowcore *lc = get_lowcore();
3839
u64 timer;
3940

4041
asm volatile(
4142
" stpt %0\n" /* Store current cpu timer value */
4243
" spt %1" /* Set new value imm. afterwards */
4344
: "=Q" (timer) : "Q" (expires));
44-
get_lowcore()->system_timer += get_lowcore()->last_update_timer - timer;
45-
get_lowcore()->last_update_timer = expires;
45+
lc->system_timer += lc->last_update_timer - timer;
46+
lc->last_update_timer = expires;
4647
}
4748

4849
static inline int virt_timer_forward(u64 elapsed)
@@ -117,22 +118,23 @@ static void account_system_index_scaled(struct task_struct *p, u64 cputime,
117118
static int do_account_vtime(struct task_struct *tsk)
118119
{
119120
u64 timer, clock, user, guest, system, hardirq, softirq;
121+
struct lowcore *lc = get_lowcore();
120122

121-
timer = get_lowcore()->last_update_timer;
122-
clock = get_lowcore()->last_update_clock;
123+
timer = lc->last_update_timer;
124+
clock = lc->last_update_clock;
123125
asm volatile(
124126
" stpt %0\n" /* Store current cpu timer value */
125127
" stckf %1" /* Store current tod clock value */
126-
: "=Q" (get_lowcore()->last_update_timer),
127-
"=Q" (get_lowcore()->last_update_clock)
128+
: "=Q" (lc->last_update_timer),
129+
"=Q" (lc->last_update_clock)
128130
: : "cc");
129-
clock = get_lowcore()->last_update_clock - clock;
130-
timer -= get_lowcore()->last_update_timer;
131+
clock = lc->last_update_clock - clock;
132+
timer -= lc->last_update_timer;
131133

132134
if (hardirq_count())
133-
get_lowcore()->hardirq_timer += timer;
135+
lc->hardirq_timer += timer;
134136
else
135-
get_lowcore()->system_timer += timer;
137+
lc->system_timer += timer;
136138

137139
/* Update MT utilization calculation */
138140
if (smp_cpu_mtid &&
@@ -141,16 +143,16 @@ static int do_account_vtime(struct task_struct *tsk)
141143

142144
/* Calculate cputime delta */
143145
user = update_tsk_timer(&tsk->thread.user_timer,
144-
READ_ONCE(get_lowcore()->user_timer));
146+
READ_ONCE(lc->user_timer));
145147
guest = update_tsk_timer(&tsk->thread.guest_timer,
146-
READ_ONCE(get_lowcore()->guest_timer));
148+
READ_ONCE(lc->guest_timer));
147149
system = update_tsk_timer(&tsk->thread.system_timer,
148-
READ_ONCE(get_lowcore()->system_timer));
150+
READ_ONCE(lc->system_timer));
149151
hardirq = update_tsk_timer(&tsk->thread.hardirq_timer,
150-
READ_ONCE(get_lowcore()->hardirq_timer));
152+
READ_ONCE(lc->hardirq_timer));
151153
softirq = update_tsk_timer(&tsk->thread.softirq_timer,
152-
READ_ONCE(get_lowcore()->softirq_timer));
153-
get_lowcore()->steal_timer +=
154+
READ_ONCE(lc->softirq_timer));
155+
lc->steal_timer +=
154156
clock - user - guest - system - hardirq - softirq;
155157

156158
/* Push account value */
@@ -176,17 +178,19 @@ static int do_account_vtime(struct task_struct *tsk)
176178

177179
void vtime_task_switch(struct task_struct *prev)
178180
{
181+
struct lowcore *lc = get_lowcore();
182+
179183
do_account_vtime(prev);
180-
prev->thread.user_timer = get_lowcore()->user_timer;
181-
prev->thread.guest_timer = get_lowcore()->guest_timer;
182-
prev->thread.system_timer = get_lowcore()->system_timer;
183-
prev->thread.hardirq_timer = get_lowcore()->hardirq_timer;
184-
prev->thread.softirq_timer = get_lowcore()->softirq_timer;
185-
get_lowcore()->user_timer = current->thread.user_timer;
186-
get_lowcore()->guest_timer = current->thread.guest_timer;
187-
get_lowcore()->system_timer = current->thread.system_timer;
188-
get_lowcore()->hardirq_timer = current->thread.hardirq_timer;
189-
get_lowcore()->softirq_timer = current->thread.softirq_timer;
184+
prev->thread.user_timer = lc->user_timer;
185+
prev->thread.guest_timer = lc->guest_timer;
186+
prev->thread.system_timer = lc->system_timer;
187+
prev->thread.hardirq_timer = lc->hardirq_timer;
188+
prev->thread.softirq_timer = lc->softirq_timer;
189+
lc->user_timer = current->thread.user_timer;
190+
lc->guest_timer = current->thread.guest_timer;
191+
lc->system_timer = current->thread.system_timer;
192+
lc->hardirq_timer = current->thread.hardirq_timer;
193+
lc->softirq_timer = current->thread.softirq_timer;
190194
}
191195

192196
/*
@@ -196,28 +200,29 @@ void vtime_task_switch(struct task_struct *prev)
196200
*/
197201
void vtime_flush(struct task_struct *tsk)
198202
{
203+
struct lowcore *lc = get_lowcore();
199204
u64 steal, avg_steal;
200205

201206
if (do_account_vtime(tsk))
202207
virt_timer_expire();
203208

204-
steal = get_lowcore()->steal_timer;
205-
avg_steal = get_lowcore()->avg_steal_timer;
209+
steal = lc->steal_timer;
210+
avg_steal = lc->avg_steal_timer;
206211
if ((s64) steal > 0) {
207-
get_lowcore()->steal_timer = 0;
212+
lc->steal_timer = 0;
208213
account_steal_time(cputime_to_nsecs(steal));
209214
avg_steal += steal;
210215
}
211-
get_lowcore()->avg_steal_timer = avg_steal / 2;
216+
lc->avg_steal_timer = avg_steal / 2;
212217
}
213218

214219
static u64 vtime_delta(void)
215220
{
216-
u64 timer = get_lowcore()->last_update_timer;
217-
218-
get_lowcore()->last_update_timer = get_cpu_timer();
221+
struct lowcore *lc = get_lowcore();
222+
u64 timer = lc->last_update_timer;
219223

220-
return timer - get_lowcore()->last_update_timer;
224+
lc->last_update_timer = get_cpu_timer();
225+
return timer - lc->last_update_timer;
221226
}
222227

223228
/*
@@ -226,12 +231,13 @@ static u64 vtime_delta(void)
226231
*/
227232
void vtime_account_kernel(struct task_struct *tsk)
228233
{
234+
struct lowcore *lc = get_lowcore();
229235
u64 delta = vtime_delta();
230236

231237
if (tsk->flags & PF_VCPU)
232-
get_lowcore()->guest_timer += delta;
238+
lc->guest_timer += delta;
233239
else
234-
get_lowcore()->system_timer += delta;
240+
lc->system_timer += delta;
235241

236242
virt_timer_forward(delta);
237243
}

0 commit comments

Comments
 (0)