From: Parth Shah <parth@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: ego@linux.vnet.ibm.com, mikey@neuling.org,
srikar@linux.vnet.ibm.com, parths1229@gmail.com,
svaidy@linux.vnet.ibm.com
Subject: [RFC 2/2] kernel/idle: Update and use idle-hint in VPA region
Date: Tue, 13 Jul 2021 10:54:33 +0530 [thread overview]
Message-ID: <20210713052433.257003-3-parth@linux.ibm.com> (raw)
In-Reply-To: <20210713052433.257003-1-parth@linux.ibm.com>
In guest, Set idle_hint to 1 when the prev_cpu of a vCPU goes into idle state,
similarly set idle_hint to 0 when exiting an idle state.
Since the idle_hint is in VPA region, the available_idle_cpu() in guest can
read this region every time to find if a vCPU can be scheduled instantly by
the hypervsior or not.
Signed-off-by: Parth Shah <parth@linux.ibm.com>
---
arch/powerpc/include/asm/paravirt.h | 12 ++++++++++--
kernel/sched/idle.c | 3 +++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/include/asm/paravirt.h b/arch/powerpc/include/asm/paravirt.h
index bcb7b5f917be..b20e4d25bd00 100644
--- a/arch/powerpc/include/asm/paravirt.h
+++ b/arch/powerpc/include/asm/paravirt.h
@@ -21,6 +21,12 @@ static inline bool is_shared_processor(void)
return static_branch_unlikely(&shared_processor);
}
+static inline int idle_hint_of(int cpu)
+{
+ __be32 idle_hint = READ_ONCE(lppaca_of(cpu).idle_hint);
+ return be32_to_cpu(idle_hint);
+}
+
/* If bit 0 is set, the cpu has been preempted */
static inline u32 yield_count_of(int cpu)
{
@@ -109,8 +115,10 @@ static inline bool vcpu_is_preempted(int cpu)
}
#endif
- if (yield_count_of(cpu) & 1)
- return true;
+ if (yield_count_of(cpu) & 1) {
+ if (idle_hint_of(cpu) == 0)
+ return true;
+ }
return false;
}
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index 7ca3d3d86c2a..fdc8d1d474f0 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -7,6 +7,7 @@
* tasks which are handled in sched/fair.c )
*/
#include "sched.h"
+#include <asm/idle_hint.h>
#include <trace/events/power.h>
@@ -290,6 +291,7 @@ static void do_idle(void)
arch_cpu_idle_dead();
}
+ set_idle_hint(cpu, 1);
arch_cpu_idle_enter();
rcu_nocb_flush_deferred_wakeup();
@@ -306,6 +308,7 @@ static void do_idle(void)
cpuidle_idle_call();
}
arch_cpu_idle_exit();
+ set_idle_hint(cpu, 0);
}
/*
--
2.26.3
prev parent reply other threads:[~2021-07-13 5:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-13 5:24 [RFC 0/2] Paravirtualize idle CPU wakeup optimization Parth Shah
2021-07-13 5:24 ` [RFC 1/2] powerpc/book3s_hv: Add new idle-hint attribute in VPA region Parth Shah
2021-07-13 5:24 ` Parth Shah [this message]
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=20210713052433.257003-3-parth@linux.ibm.com \
--to=parth@linux.ibm.com \
--cc=ego@linux.vnet.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mikey@neuling.org \
--cc=parths1229@gmail.com \
--cc=srikar@linux.vnet.ibm.com \
--cc=svaidy@linux.vnet.ibm.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;
as well as URLs for NNTP newsgroup(s).