All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tianqiang Xu <skyele@sjtu.edu.cn>
To: x86@kernel.org
Cc: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com,
	wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org,
	tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	kvm@vger.kernel.org, hpa@zytor.com, jarkko@kernel.org,
	dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org,
	linux-sgx@vger.kernel.org, Tianqiang Xu <skyele@sjtu.edu.cn>
Subject: [PATCH 2/4] Scheduler changes
Date: Tue, 31 Aug 2021 09:59:17 +0800	[thread overview]
Message-ID: <20210831015919.13006-2-skyele@sjtu.edu.cn> (raw)
In-Reply-To: <20210831015919.13006-1-skyele@sjtu.edu.cn>

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(+)

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


  reply	other threads:[~2021-08-31  2:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31  1:59 [PATCH 1/4] KVM: x86: Introduce .pcpu_is_idle() stub infrastructure Tianqiang Xu
2021-08-31  1:59 ` Tianqiang Xu [this message]
2021-08-31  7:14   ` [PATCH 2/4] Scheduler changes Peter Zijlstra
2021-08-31  1:59 ` [PATCH 3/4] KVM host implementation Tianqiang Xu
2021-08-31  7:16   ` Peter Zijlstra
2021-08-31  7:17     ` Peter Zijlstra
2021-08-31  1:59 ` [PATCH 4/4] KVM guest implementation Tianqiang Xu
2021-08-31  7:21   ` Peter Zijlstra
2021-09-01  4:39 ` [PATCH 1/4] KVM: x86: Introduce .pcpu_is_idle() stub infrastructure Jarkko Sakkinen
2021-12-17  9:39 ` Jinrong Liang

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=20210831015919.13006-2-skyele@sjtu.edu.cn \
    --to=skyele@sjtu.edu.cn \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jarkko@kernel.org \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.