[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240923090028.16368-2-laoar.shao@gmail.com>
Date: Mon, 23 Sep 2024 17:00:26 +0800
From: Yafang Shao <laoar.shao@...il.com>
To: mingo@...hat.com,
peterz@...radead.org,
juri.lelli@...hat.com,
vincent.guittot@...aro.org,
dietmar.eggemann@....com,
rostedt@...dmis.org,
bsegall@...gle.com,
mgorman@...e.de,
vschneid@...hat.com
Cc: linux-kernel@...r.kernel.org,
Yafang Shao <laoar.shao@...il.com>
Subject: [PATCH 1/3] sched: Fix cgroup irq accounting for CONFIG_IRQ_TIME_ACCOUNTING
After enabling CONFIG_IRQ_TIME_ACCOUNTING to monitor IRQ pressure in our
container environment, we observed several noticeable behavioral changes.
One of our IRQ-heavy services, such as Redis, reported a significant
reduction in CPU usage after upgrading to the new kernel with
CONFIG_IRQ_TIME_ACCOUNTING enabled. However, despite adding more threads
to handle an increased workload, the CPU usage could not be raised. In
other words, even though the container’s CPU usage appeared low, it was
unable to process more workloads to utilize additional CPU resources, which
caused issues.
This behavior can be demonstrated using netperf:
function start_server() {
for j in `seq 1 3`; do
netserver -p $[12345+j] > /dev/null &
done
}
server_ip=$1
function start_client() {
# That applies to cgroup2 as well.
mkdir -p /sys/fs/cgroup/cpuacct/test
echo $$ > /sys/fs/cgroup/cpuacct/test/cgroup.procs
for j in `seq 1 3`; do
port=$[12345+j]
taskset -c 0 netperf -H ${server_ip} -l ${run_time:-30000} \
-t TCP_STREAM -p $port -- -D -m 1k -M 1K -s 8k -S 8k \
> /dev/null &
done
}
start_server
start_client
We can verify the CPU usage of the test cgroup using cpuacct.stat. The
output shows:
system: 53
user: 2
The CPU usage of the cgroup is relatively low at around 55%, but this usage
doesn't increase, even with more netperf tasks. The reason is that CPU0 is
at 100% utilization, as confirmed by mpstat:
02:56:22 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
02:56:23 PM 0 0.99 0.00 55.45 0.00 0.99 42.57 0.00 0.00 0.00 0.00
02:56:23 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
02:56:24 PM 0 2.00 0.00 55.00 0.00 0.00 43.00 0.00 0.00 0.00 0.00
This behavior is unexpected. We should account for IRQ time to the cgroup
to reflect the pressure the group is under.
After a thorough analysis, I discovered that this change in behavior is due
to commit 305e6835e055 ("sched: Do not account irq time to current task"),
which altered whether IRQ time should be charged to the interrupted task.
While I agree that a task should not be penalized by random interrupts, the
task itself cannot progress while interrupted. Therefore, the interrupted
time should be reported to the user.
The system metric in cpuacct.stat is crucial in indicating whether a
container is under heavy system pressure, including IRQ/softirq activity.
Hence, IRQ/softirq time should be accounted for in the cpuacct system
usage, which also applies to cgroup2’s rstat.
This patch reintroduces IRQ/softirq accounting to cgroups.
Signed-off-by: Yafang Shao <laoar.shao@...il.com>
---
kernel/sched/cputime.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 0bed0fa1acd9..4586db5cf3a8 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -34,7 +34,8 @@ void disable_sched_clock_irqtime(void)
sched_clock_irqtime = 0;
}
-static void irqtime_account_delta(struct irqtime *irqtime, u64 delta,
+static void irqtime_account_delta(struct task_struct *curr,
+ struct irqtime *irqtime, u64 delta,
enum cpu_usage_stat idx)
{
u64 *cpustat = kcpustat_this_cpu->cpustat;
@@ -44,6 +45,9 @@ static void irqtime_account_delta(struct irqtime *irqtime, u64 delta,
irqtime->total += delta;
irqtime->tick_delta += delta;
u64_stats_update_end(&irqtime->sync);
+
+ cgroup_account_cputime(curr, delta);
+ cgroup_account_cputime_field(curr, idx, delta);
}
/*
@@ -72,9 +76,9 @@ void irqtime_account_irq(struct task_struct *curr, unsigned int offset)
* that do not consume any time, but still wants to run.
*/
if (pc & HARDIRQ_MASK)
- irqtime_account_delta(irqtime, delta, CPUTIME_IRQ);
+ irqtime_account_delta(curr, irqtime, delta, CPUTIME_IRQ);
else if ((pc & SOFTIRQ_OFFSET) && curr != this_cpu_ksoftirqd())
- irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ);
+ irqtime_account_delta(curr, irqtime, delta, CPUTIME_SOFTIRQ);
}
static u64 irqtime_tick_accounted(u64 maxtime)
--
2.43.5
Powered by blists - more mailing lists