diff mbox series

[2/4] Scheduler changes

Message ID 20210831015919.13006-2-skyele@sjtu.edu.cn (mailing list archive)
State New, archived
Headers show
Series [1/4] KVM: x86: Introduce .pcpu_is_idle() stub infrastructure | expand

Commit Message

Tianqiang Xu Aug. 31, 2021, 1:59 a.m. UTC
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@sjtu.edu.cn>

---
 include/linux/sched.h |  1 +
 kernel/sched/core.c   | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

Comments

Peter Zijlstra Aug. 31, 2021, 7:14 a.m. UTC | #1
On Tue, Aug 31, 2021 at 09:59:17AM +0800, Tianqiang Xu wrote:
> Authors: Tianqiang Xu, Dingji Li, Zeyu Mi
> 	 Shanghai Jiao Tong University
> 
> Signed-off-by: Tianqiang Xu <skyele@sjtu.edu.cn>

Authors is not a valid tag, please see our Documentation on submitting
patches.

> @@ -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);

Yeah, not going to happen.
diff mbox series

Patch

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);