hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/sched/cputime.c
....@@ -47,13 +47,12 @@
4747 }
4848
4949 /*
50
- * Called after incrementing preempt_count on {soft,}irq_enter
50
+ * Called before incrementing preempt_count on {soft,}irq_enter
5151 * and before decrementing preempt_count on {soft,}irq_exit.
5252 */
53
-void irqtime_account_irq(struct task_struct *curr, unsigned int offset)
53
+void irqtime_account_irq(struct task_struct *curr)
5454 {
5555 struct irqtime *irqtime = this_cpu_ptr(&cpu_irqtime);
56
- unsigned int pc;
5756 s64 delta;
5857 int cpu;
5958
....@@ -63,7 +62,6 @@
6362 cpu = smp_processor_id();
6463 delta = sched_clock_cpu(cpu) - irqtime->irq_start_time;
6564 irqtime->irq_start_time += delta;
66
- pc = irq_count() - offset;
6765
6866 /*
6967 * We do not account for softirq time from ksoftirqd here.
....@@ -71,9 +69,9 @@
7169 * in that case, so as not to confuse scheduler with a special task
7270 * that do not consume any time, but still wants to run.
7371 */
74
- if (pc & HARDIRQ_MASK)
72
+ if (hardirq_count())
7573 irqtime_account_delta(irqtime, delta, CPUTIME_IRQ);
76
- else if ((pc & SOFTIRQ_OFFSET) && curr != this_cpu_ksoftirqd())
74
+ else if (in_serving_softirq() && curr != this_cpu_ksoftirqd())
7775 irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ);
7876
7977 trace_android_rvh_account_irq(curr, cpu, delta);
....@@ -432,21 +430,24 @@
432430 }
433431 # endif
434432
435
-void vtime_account_irq(struct task_struct *tsk, unsigned int offset)
433
+/*
434
+ * Archs that account the whole time spent in the idle task
435
+ * (outside irq) as idle time can rely on this and just implement
436
+ * vtime_account_kernel() and vtime_account_idle(). Archs that
437
+ * have other meaning of the idle time (s390 only includes the
438
+ * time spent by the CPU when it's in low power mode) must override
439
+ * vtime_account().
440
+ */
441
+#ifndef __ARCH_HAS_VTIME_ACCOUNT
442
+void vtime_account_irq_enter(struct task_struct *tsk)
436443 {
437
- unsigned int pc = irq_count() - offset;
438
-
439
- if (pc & HARDIRQ_OFFSET) {
440
- vtime_account_hardirq(tsk);
441
- } else if (pc & SOFTIRQ_OFFSET) {
442
- vtime_account_softirq(tsk);
443
- } else if (!IS_ENABLED(CONFIG_HAVE_VIRT_CPU_ACCOUNTING_IDLE) &&
444
- is_idle_task(tsk)) {
444
+ if (!in_interrupt() && is_idle_task(tsk))
445445 vtime_account_idle(tsk);
446
- } else {
446
+ else
447447 vtime_account_kernel(tsk);
448
- }
449448 }
449
+EXPORT_SYMBOL_GPL(vtime_account_irq_enter);
450
+#endif /* __ARCH_HAS_VTIME_ACCOUNT */
450451
451452 void cputime_adjust(struct task_cputime *curr, struct prev_cputime *prev,
452453 u64 *ut, u64 *st)