From: Huang Shijie <shijie@os.amperecomputing.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com
Cc: patches@amperecomputing.com, vincent.guittot@linaro.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
linux-kernel@vger.kernel.org, cl@linux.com,
Huang Shijie <shijie@os.amperecomputing.com>
Subject: [PATCH] sched/fair: start the HRTICK even when we pick the current task again
Date: Mon, 11 Nov 2024 15:48:41 +0800 [thread overview]
Message-ID: <20241111074841.8802-1-shijie@os.amperecomputing.com> (raw)
Assume HRTICK is enabled, when a task is running in its time slice,
a schedule() maybe called. For example, an IRQ(not HRTICK) may
set TIF_NEED_RESCHED to this task, and then calls schedule()
before it backs to user space.
slice start slice end
|<---------------------->|
----------------------------------------------
^
|
schedule()
The scheduler will first call hrtick_clear() to clear the HRTICK
in __schedule(). Then in pick_next_task_fair():
(1) if we pick a new task, we will start the HRTICK for it
in __set_next_task_fair(), it is okay.
(2) if we pick the current task again, we do not start the HRTICK
for current task.
Even when "rq->cfs.h_nr_running > 1" is true, the case (2) may still occur.
For example, we may follow the RUN_TO_PARITY.
This means the current task may run beyond its time slice:
Since the HRTICK does not work, the preemption is lost, the other tasks
should be scheduled may have to wait for a long time.
To fix this issue, this patch starts the HRTICK even when we pick
the current task again. If "rq->cfs.h_nr_running > 1" is true, it will
start a HRTICK for it.
Signed-off-by: Huang Shijie <shijie@os.amperecomputing.com>
---
kernel/sched/fair.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index c338df26d26d..c7b54eb069a6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8949,6 +8949,9 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf
set_next_entity(cfs_rq, se);
__set_next_task_fair(rq, p, true);
+ } else {
+ if (hrtick_enabled_fair(rq))
+ hrtick_start_fair(rq, p);
}
return p;
--
2.40.1
reply other threads:[~2024-11-11 7:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20241111074841.8802-1-shijie@os.amperecomputing.com \
--to=shijie@os.amperecomputing.com \
--cc=bsegall@google.com \
--cc=cl@linux.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=patches@amperecomputing.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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®