[PATCH 2/4] Scheduler changes
From: Tianqiang Xu
Date: Mon Aug 30 2021 - 22:00:29 EST
available_idle_cpu_sched() invokes pcpu_is_idle() to detect whether
a pCPU where the preempted vCPU most recently run is idle or not, which
is used by the guest OS.
get_cpu_nr_running() gets the run queue of current cpu, which is used
by the host KVM to know whether a pCPU where the preempted vCPU mostly
recently run is idle or not.
--
Authors: Tianqiang Xu, Dingji Li, Zeyu Mi
Shanghai Jiao Tong University
Signed-off-by: Tianqiang Xu <skyele@xxxxxxxxxxx>
---
include/linux/sched.h | 1 +
kernel/sched/core.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index ec8d07d88641..dd4c41d2d8d3 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1736,6 +1736,7 @@ extern int can_nice(const struct task_struct *p, const int nice);
extern int task_curr(const struct task_struct *p);
extern int idle_cpu(int cpu);
extern int available_idle_cpu(int cpu);
+extern int available_idle_cpu_sched(int cpu);
extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *);
extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *);
extern void sched_set_fifo(struct task_struct *p);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f3b27c6c5153..c777dbcbeb9c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6752,6 +6752,17 @@ int available_idle_cpu(int cpu)
return 1;
}
+int available_idle_cpu_sched(int cpu)
+{
+ if (!idle_cpu(cpu))
+ return 0;
+
+ if (!pcpu_is_idle(cpu))
+ return 0;
+
+ return 1;
+}
+
/**
* idle_task - return the idle task for a given CPU.
* @cpu: the processor in question.
@@ -10504,3 +10515,9 @@ void call_trace_sched_update_nr_running(struct rq *rq, int count)
{
trace_sched_update_nr_running_tp(rq, count);
}
+
+int get_cpu_nr_running(int cpu)
+{
+ return cpu_rq(cpu)->nr_running;
+}
+EXPORT_SYMBOL_GPL(get_cpu_nr_running);
--
2.26.0