forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/arch/s390/kernel/vtime.c
....@@ -37,7 +37,7 @@
3737 {
3838 u64 timer;
3939
40
- asm volatile("stpt %0" : "=m" (timer));
40
+ asm volatile("stpt %0" : "=Q" (timer));
4141 return timer;
4242 }
4343
....@@ -48,7 +48,7 @@
4848 asm volatile(
4949 " stpt %0\n" /* Store current cpu timer value */
5050 " spt %1" /* Set new value imm. afterwards */
51
- : "=m" (timer) : "m" (expires));
51
+ : "=Q" (timer) : "Q" (expires));
5252 S390_lowcore.system_timer += S390_lowcore.last_update_timer - timer;
5353 S390_lowcore.last_update_timer = expires;
5454 }
....@@ -69,7 +69,7 @@
6969 u64 delta, fac, mult, div;
7070 int i;
7171
72
- stcctm5(smp_cpu_mtid + 1, cycles_new);
72
+ stcctm(MT_DIAG, smp_cpu_mtid + 1, cycles_new);
7373 cycles_old = this_cpu_ptr(mt_cycles);
7474 fac = 1;
7575 mult = div = 0;
....@@ -124,7 +124,7 @@
124124 */
125125 static int do_account_vtime(struct task_struct *tsk)
126126 {
127
- u64 timer, clock, user, guest, system, hardirq, softirq, steal;
127
+ u64 timer, clock, user, guest, system, hardirq, softirq;
128128
129129 timer = S390_lowcore.last_update_timer;
130130 clock = S390_lowcore.last_update_clock;
....@@ -135,8 +135,9 @@
135135 #else
136136 " stck %1" /* Store current tod clock value */
137137 #endif
138
- : "=m" (S390_lowcore.last_update_timer),
139
- "=m" (S390_lowcore.last_update_clock));
138
+ : "=Q" (S390_lowcore.last_update_timer),
139
+ "=Q" (S390_lowcore.last_update_clock)
140
+ : : "cc");
140141 clock = S390_lowcore.last_update_clock - clock;
141142 timer -= S390_lowcore.last_update_timer;
142143
....@@ -182,12 +183,6 @@
182183 if (softirq)
183184 account_system_index_scaled(tsk, softirq, CPUTIME_SOFTIRQ);
184185
185
- steal = S390_lowcore.steal_timer;
186
- if ((s64) steal > 0) {
187
- S390_lowcore.steal_timer = 0;
188
- account_steal_time(cputime_to_nsecs(steal));
189
- }
190
-
191186 return virt_timer_forward(user + guest + system + hardirq + softirq);
192187 }
193188
....@@ -213,38 +208,64 @@
213208 */
214209 void vtime_flush(struct task_struct *tsk)
215210 {
211
+ u64 steal, avg_steal;
212
+
216213 if (do_account_vtime(tsk))
217214 virt_timer_expire();
215
+
216
+ steal = S390_lowcore.steal_timer;
217
+ avg_steal = S390_lowcore.avg_steal_timer / 2;
218
+ if ((s64) steal > 0) {
219
+ S390_lowcore.steal_timer = 0;
220
+ account_steal_time(cputime_to_nsecs(steal));
221
+ avg_steal += steal;
222
+ }
223
+ S390_lowcore.avg_steal_timer = avg_steal;
224
+}
225
+
226
+static u64 vtime_delta(void)
227
+{
228
+ u64 timer = S390_lowcore.last_update_timer;
229
+
230
+ S390_lowcore.last_update_timer = get_vtimer();
231
+
232
+ return timer - S390_lowcore.last_update_timer;
218233 }
219234
220235 /*
221236 * Update process times based on virtual cpu times stored by entry.S
222237 * to the lowcore fields user_timer, system_timer & steal_clock.
223238 */
224
-void vtime_account_irq_enter(struct task_struct *tsk)
239
+void vtime_account_kernel(struct task_struct *tsk)
225240 {
226
- u64 timer;
241
+ u64 delta = vtime_delta();
227242
228
- timer = S390_lowcore.last_update_timer;
229
- S390_lowcore.last_update_timer = get_vtimer();
230
- timer -= S390_lowcore.last_update_timer;
231
-
232
- if ((tsk->flags & PF_VCPU) && (irq_count() == 0))
233
- S390_lowcore.guest_timer += timer;
234
- else if (hardirq_count())
235
- S390_lowcore.hardirq_timer += timer;
236
- else if (in_serving_softirq())
237
- S390_lowcore.softirq_timer += timer;
243
+ if (tsk->flags & PF_VCPU)
244
+ S390_lowcore.guest_timer += delta;
238245 else
239
- S390_lowcore.system_timer += timer;
246
+ S390_lowcore.system_timer += delta;
240247
241
- virt_timer_forward(timer);
248
+ virt_timer_forward(delta);
242249 }
243
-EXPORT_SYMBOL_GPL(vtime_account_irq_enter);
250
+EXPORT_SYMBOL_GPL(vtime_account_kernel);
244251
245
-void vtime_account_system(struct task_struct *tsk)
246
-__attribute__((alias("vtime_account_irq_enter")));
247
-EXPORT_SYMBOL_GPL(vtime_account_system);
252
+void vtime_account_softirq(struct task_struct *tsk)
253
+{
254
+ u64 delta = vtime_delta();
255
+
256
+ S390_lowcore.softirq_timer += delta;
257
+
258
+ virt_timer_forward(delta);
259
+}
260
+
261
+void vtime_account_hardirq(struct task_struct *tsk)
262
+{
263
+ u64 delta = vtime_delta();
264
+
265
+ S390_lowcore.hardirq_timer += delta;
266
+
267
+ virt_timer_forward(delta);
268
+}
248269
249270 /*
250271 * Sorted add to a list. List is linear searched until first bigger
....@@ -432,6 +453,6 @@
432453 __this_cpu_write(mt_scaling_jiffies, jiffies);
433454 __this_cpu_write(mt_scaling_mult, 1);
434455 __this_cpu_write(mt_scaling_div, 1);
435
- stcctm5(smp_cpu_mtid + 1, this_cpu_ptr(mt_cycles));
456
+ stcctm(MT_DIAG, smp_cpu_mtid + 1, this_cpu_ptr(mt_cycles));
436457 }
437458 }