Skip to content

sched: Fix missing irq time when CONFIG_IRQ_TIME_ACCOUNTING is enabled

Yafang Shao cgroups lkml 10 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest2 patches 4 repliesIn review
  2. v8 posting 2/24 patches 6 repliesApplied
  3. v8 posting 1/24 patches 0 repliesSuperseded
Earlier versions · 7
VersionPostedPatchesRepliesStatus
v74 patches1 replySuperseded
v64 patches3 repliesSuperseded
v54 patches12 repliesSuperseded
v44 patches6 repliesSuperseded
v34 patches1 replySuperseded
v24 patches3 repliesSuperseded
v13 patches1 replySuperseded

Changes in v9 from the cover letter

- Rebase it after the discussion with Ingo
https://lore.kernel.org/all/[email protected]/
- Mark sched_clock_irqtime with __read_mostly to avoid possible cacheline false sharing issue

Patches in v9 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2sched: Fix cgroup irq time for CONFIG_IRQ_TIME_ACCOUNTINGkernel/sched/core.c kernel/sched/psi.c kernel/sched/sched.h +1 more+39 -162 replies
2/2sched: Annotate sched_clock_irqtime with __read_mostlykernel/sched/cputime.c+1 -12 replies

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchEric DumazetMichal Koutný
1/2
2/2Debugged-by R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v9 thread

Cover letter [PATCH v9 0/2] sched: Fix missing irq time when CONFIG_IRQ_TIME_ACCOUNTING is enabled

After enabling CONFIG_IRQ_TIME_ACCOUNTING to track IRQ pressure in our container environment, we encountered several user-visible behavioral changes:

- Interrupted IRQ/softirq time is excluded in the cpuacct cgroup

This breaks userspace applications that rely on CPU usage data from cgroups to monitor CPU pressure. This patchset resolves the issue by ensuring that IRQ/softirq time is included in the cgroup of the interrupted tasks.

- getrusage(2) does not include time interrupted by IRQ/softirq

Some services use getrusage(2) to check if workloads are experiencing CPU pressure. Since IRQ/softirq time is no longer included in task runtime, getrusage(2) can no longer reflect the CPU pressure caused by heavy interrupts.

This patchset addresses the first issue, which is relatively straightforward. Once this solution is accepted, I will address the second issue in a follow-up patchset.

Enabling CONFIG_IRQ_TIME_ACCOUNTING results in the CPU utilization metric excluding the time spent in IRQs. This means we lose visibility into how long the CPU was actually interrupted in comparison to its total utilization. The user will misleadlingly consider the *interrupted irq time* as *sleep time* as follows,

|<----Runtime---->|<----Sleep---->|<----Runtime---->|<---Sleep-->|

While actually it is:

|<----Runtime---->|<--Interrupted time-->|<----Runtime---->|<---Sleep-->|

Currently, the only ways to monitor interrupt time are through IRQ PSI or the IRQ time recorded in delay accounting. However, these metrics are independent of CPU utilization, which makes it difficult to combine them into a single, unified measure

CPU utilization is a critical metric for almost all workloads, and it's problematic if it fails to reflect the full extent of system pressure. This situation is similar to iowait: when a task is in iowait, it could be due to other tasks performing I/O. It doesn’t matter if the I/O is being done by one of your tasks or by someone else's; what matters is that your task is stalled and waiting on I/O. Similarly, a comprehensive CPU utilization metric should reflect all sources of pressure, including IRQ time, to provide a more accurate representation of workload behavior.

One of the applications impacted by this issue is our Redis load-balancing service. The setup operates as follows:

                   ----------------
                   | Load Balancer|
                   ----------------
                /    |      |        \
               /     |      |         \ 
          Server1 Server2 Server3 ... ServerN

Although the load balancer's algorithm is complex, it follows some core principles:

- When server CPU utilization increases, it adds more servers and deploys additional instances to meet SLA requirements.
- When server CPU utilization decreases, it scales down by decommissioning servers and reducing the number of instances to save on costs.

On our servers, the majority of IRQ/softIRQ activity originates from network traffic, and we consistently enable Receive Flow Steering (RFS) [0]. This configuration ensures that softIRQs are more likely to interrupt the tasks responsible for processing the corresponding packets. As a result, the distribution of softIRQs is not random but instead closely aligned with the packet-handling tasks.

The load balancer is malfunctioning due to the exclusion of IRQ time from CPU utilization calculations. What's worse, there is no effective way to add the irq time back into the CPU utilization based on current available metrics. Therefore, we have to change the kernel code.

Changes:
v8->v9:
- Rebase it after the discussion with Ingo
https://lore.kernel.org/all/[email protected]/
- Mark sched_clock_irqtime with __read_mostly to avoid possible cacheline false sharing issue

v7->v8: https://lore.kernel.org/all/[email protected]/
- Fix a build failure report by kernel test robot

v6->v7: https://lore.kernel.org/all/[email protected]/
- Fix psi_show() (Michal)

v5->v6: https://lore.kernel.org/all/[email protected]/
- Return EOPNOTSUPP in psi_show() if irqtime is disabled (Michal)
- Collect Reviewed-by from Michal

v4->v5: https://lore.kernel.org/all/[email protected]/
- Don't use static key in the IRQ_TIME_ACCOUNTING=n case (Peter)
- Rename psi_irq_time to irq_time (Peter)
- Use CPUTIME_IRQ instead of CPUTIME_SOFTIRQ (Peter)

v3->v4: https://lore.kernel.org/all/[email protected]/
- Rebase

v2->v3:
- Add a helper account_irqtime() to avoid redundant code (Johannes)

v1->v2: https://lore.kernel.org/cgroups/[email protected]/
- Fix lockdep issues reported by kernel test robot <[email protected]>

v1: https://lore.kernel.org/all/[email protected]/

Yafang Shao (2):
sched: Fix cgroup irq time for CONFIG_IRQ_TIME_ACCOUNTING
sched: Annotate sched_clock_irqtime with __read_mostly

 kernel/sched/core.c    | 33 +++++++++++++++++++++++++++++++--
 kernel/sched/cputime.c |  2 +-
 kernel/sched/psi.c     | 13 +++----------
 kernel/sched/sched.h   |  2 +-
 kernel/sched/stats.h   |  7 ++++---
 5 files changed, 40 insertions(+), 17 deletions(-)
Signature · 1 line
2.43.5