mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tiozhang <tiozhang@didiglobal.com>
To: <bigeasy@linutronix.de>, <tglx@linutronix.de>,
	<rostedt@goodmis.org>, <mingo@redhat.com>, <peterz@infradead.org>,
	<juri.lelli@redhat.com>, <vincent.guittot@linaro.org>
Cc: <linux-kernel@vger.kernel.org>, <dietmar.eggemann@arm.com>,
	<rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>,
	<bristot@redhat.com>, <vschneid@redhat.com>,
	<zyhtheonly@gmail.com>, <tiozhang@didiglobal.com>,
	<zyhtheonly@yeah.net>
Subject: [PATCH v3] sched/cputime: let ktimers align with ksoftirqd in accounting CPUTIME_SOFTIRQ
Date: Fri, 1 Dec 2023 16:05:41 +0800	[thread overview]
Message-ID: <20231201080522.GA31309@didi-ThinkCentre-M930t-N000> (raw)
In-Reply-To: <20231201073240.T9bFNCkU@linutronix.de>

In CONFIG_PREEMPT_RT kernel, ktimers also calls __do_softirq,
so when accounting CPUTIME_SOFTIRQ, ktimers need to be accounted the same
as ksoftirqd.

Signed-off-by: tiozhang <tiozhang@didiglobal.com>
---
 include/linux/interrupt.h | 5 +++++
 kernel/sched/cputime.c    | 6 ++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index a5091ac97fc6..a88646acaf3f 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -621,6 +621,11 @@ static inline unsigned int local_pending_timers(void)
         return __this_cpu_read(pending_timer_softirq);
 }
 
+static inline struct task_struct *this_cpu_ktimers(void)
+{
+	return this_cpu_read(timersd);
+}
+
 #else
 static inline void raise_timer_softirq(void)
 {
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index af7952f12e6c..2393c533314f 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -73,7 +73,8 @@ void irqtime_account_irq(struct task_struct *curr, unsigned int offset)
 	 */
 	if (pc & HARDIRQ_MASK)
 		irqtime_account_delta(irqtime, delta, CPUTIME_IRQ);
-	else if ((pc & SOFTIRQ_OFFSET) && curr != this_cpu_ksoftirqd())
+	else if (((pc & SOFTIRQ_OFFSET) && curr != this_cpu_ksoftirqd() &&
+		  (!IS_ENABLED(CONFIG_PREEMPT_RT) || curr != this_cpu_ktimers()))
 		irqtime_account_delta(irqtime, delta, CPUTIME_SOFTIRQ);
 }
 
@@ -391,7 +392,8 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick,
 
 	cputime -= other;
 
-	if (this_cpu_ksoftirqd() == p) {
+	if (this_cpu_ksoftirqd() == p ||
+	   (IS_ENABLED(CONFIG_PREEMPT_RT) && this_cpu_ktimers() == p)) {
 		/*
 		 * ksoftirqd time do not get accounted in cpu_softirq_time.
 		 * So, we have to handle it separately here.
-- 
2.17.1


  reply	other threads:[~2023-12-01  8:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-24  6:34 [PATCH] sched/cputime: exclude ktimer threads in irqtime_account_irq tiozhang
2023-11-27 18:07 ` Steven Rostedt
2023-11-30  9:41   ` [PATCH v2] sched/cputime: exclude ktimers " tiozhang
2023-11-30 12:00     ` Sebastian Andrzej Siewior
2023-12-01  7:27       ` Yuanhan Zhang
2023-12-01  7:32         ` Sebastian Andrzej Siewior
2023-12-01  8:05           ` tiozhang [this message]
2023-12-01 16:16             ` [PATCH v3] sched/cputime: let ktimers align with ksoftirqd in accounting CPUTIME_SOFTIRQ Sebastian Andrzej Siewior
2023-12-02 10:28               ` Yuanhan Zhang
2023-12-05 15:31                 ` Sebastian Andrzej Siewior
2023-12-07 10:43                   ` Yuanhan Zhang
2023-12-07 15:35                     ` Steven Rostedt
2023-12-07 17:19                       ` Yuanhan Zhang
2023-12-07 18:18                         ` Steven Rostedt
2023-12-08  9:26                           ` Sebastian Andrzej Siewior
2023-12-11 12:02                             ` [PATCH v4] sched/cputime: account ksoftirqd's time on SYSTEM in PREEMPT_RT Tio Zhang
2023-12-15 18:30                             ` [PATCH v3] sched/cputime: let ktimers align with ksoftirqd in accounting CPUTIME_SOFTIRQ Yuanhan Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231201080522.GA31309@didi-ThinkCentre-M930t-N000 \
    --to=tiozhang@didiglobal.com \
    --cc=bigeasy@linutronix.de \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=zyhtheonly@gmail.com \
    --cc=zyhtheonly@yeah.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®