From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org, linux-pm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Radim Krcmar <rkrcmar@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Wanpeng Li <kernellwp@gmail.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Raslan KarimAllah <karahmed@amazon.de>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Ankur Arora <ankur.a.arora@oracle.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 2/5] cpuidle: add get_poll_time callback
Date: Mon, 01 Jul 2019 15:53:12 -0300 [thread overview]
Message-ID: <20190701185528.115106953@asus.localdomain> (raw)
In-Reply-To: 20190701185310.540706841@asus.localdomain
Add a "get_poll_time" callback to the cpuidle_governor structure,
and change poll state to poll for that amount of time.
Provide a default method for it, while allowing individual governors
to override it.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
drivers/cpuidle/cpuidle.c | 40 ++++++++++++++++++++++++++++++++++++++++
drivers/cpuidle/poll_state.c | 11 ++---------
include/linux/cpuidle.h | 8 ++++++++
3 files changed, 50 insertions(+), 9 deletions(-)
Index: linux-2.6-newcpuidle.git/drivers/cpuidle/cpuidle.c
===================================================================
--- linux-2.6-newcpuidle.git.orig/drivers/cpuidle/cpuidle.c
+++ linux-2.6-newcpuidle.git/drivers/cpuidle/cpuidle.c
@@ -362,6 +362,46 @@ void cpuidle_reflect(struct cpuidle_devi
}
/**
+ * cpuidle_default_poll_time - default routine used to return poll time
+ * governors can override it if necessary
+ *
+ * @drv: the cpuidle driver tied with the cpu
+ * @dev: the cpuidle device
+ *
+ */
+static u64 cpuidle_default_poll_time(struct cpuidle_driver *drv,
+ struct cpuidle_device *dev)
+{
+ int i;
+
+ for (i = 1; i < drv->state_count; i++) {
+ if (drv->states[i].disabled || dev->states_usage[i].disable)
+ continue;
+
+ return (u64)drv->states[i].target_residency * NSEC_PER_USEC;
+ }
+
+ return TICK_NSEC;
+}
+
+/**
+ * cpuidle_get_poll_time - tell the polling driver how much time to poll,
+ * in nanoseconds.
+ *
+ * @drv: the cpuidle driver tied with the cpu
+ * @dev: the cpuidle device
+ *
+ */
+u64 cpuidle_get_poll_time(struct cpuidle_driver *drv,
+ struct cpuidle_device *dev)
+{
+ if (cpuidle_curr_governor->get_poll_time)
+ return cpuidle_curr_governor->get_poll_time(drv, dev);
+
+ return cpuidle_default_poll_time(drv, dev);
+}
+
+/**
* cpuidle_install_idle_handler - installs the cpuidle idle loop handler
*/
void cpuidle_install_idle_handler(void)
Index: linux-2.6-newcpuidle.git/drivers/cpuidle/poll_state.c
===================================================================
--- linux-2.6-newcpuidle.git.orig/drivers/cpuidle/poll_state.c
+++ linux-2.6-newcpuidle.git/drivers/cpuidle/poll_state.c
@@ -20,16 +20,9 @@ static int __cpuidle poll_idle(struct cp
local_irq_enable();
if (!current_set_polling_and_test()) {
unsigned int loop_count = 0;
- u64 limit = TICK_NSEC;
- int i;
+ u64 limit;
- for (i = 1; i < drv->state_count; i++) {
- if (drv->states[i].disabled || dev->states_usage[i].disable)
- continue;
-
- limit = (u64)drv->states[i].target_residency * NSEC_PER_USEC;
- break;
- }
+ limit = cpuidle_get_poll_time(drv, dev);
while (!need_resched()) {
cpu_relax();
Index: linux-2.6-newcpuidle.git/include/linux/cpuidle.h
===================================================================
--- linux-2.6-newcpuidle.git.orig/include/linux/cpuidle.h
+++ linux-2.6-newcpuidle.git/include/linux/cpuidle.h
@@ -132,6 +132,8 @@ extern int cpuidle_select(struct cpuidle
extern int cpuidle_enter(struct cpuidle_driver *drv,
struct cpuidle_device *dev, int index);
extern void cpuidle_reflect(struct cpuidle_device *dev, int index);
+extern u64 cpuidle_get_poll_time(struct cpuidle_driver *drv,
+ struct cpuidle_device *dev);
extern int cpuidle_register_driver(struct cpuidle_driver *drv);
extern struct cpuidle_driver *cpuidle_get_driver(void);
@@ -166,6 +168,9 @@ static inline int cpuidle_enter(struct c
struct cpuidle_device *dev, int index)
{return -ENODEV; }
static inline void cpuidle_reflect(struct cpuidle_device *dev, int index) { }
+extern u64 cpuidle_get_poll_time(struct cpuidle_driver *drv,
+ struct cpuidle_device *dev)
+{return 0; }
static inline int cpuidle_register_driver(struct cpuidle_driver *drv)
{return -ENODEV; }
static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
@@ -246,6 +251,9 @@ struct cpuidle_governor {
struct cpuidle_device *dev,
bool *stop_tick);
void (*reflect) (struct cpuidle_device *dev, int index);
+
+ u64 (*get_poll_time) (struct cpuidle_driver *drv,
+ struct cpuidle_device *dev);
};
#ifdef CONFIG_CPU_IDLE
next prev parent reply other threads:[~2019-07-01 18:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-01 18:53 [patch 0/5] cpuidle haltpoll driver and governor (v5) Marcelo Tosatti
2019-07-01 18:53 ` [patch 1/5] add cpuidle-haltpoll driver Marcelo Tosatti
2019-07-03 9:54 ` Rafael J. Wysocki
2019-07-01 18:53 ` Marcelo Tosatti [this message]
2019-07-03 9:50 ` [patch 2/5] cpuidle: add get_poll_time callback Rafael J. Wysocki
2019-07-01 18:53 ` [patch 3/5] cpuidle: add haltpoll governor Marcelo Tosatti
2019-07-03 10:04 ` Rafael J. Wysocki
2019-07-01 18:53 ` [patch 4/5] kvm: x86: add host poll control msrs Marcelo Tosatti
2019-07-01 18:53 ` [patch 5/5] cpuidle-haltpoll: disable host side polling when kvm virtualized Marcelo Tosatti
-- strict thread matches above, loose matches on Subject: below --
2019-06-13 22:45 [patch 0/5] cpuidle haltpoll driver and governor (v4) Marcelo Tosatti
2019-06-13 22:45 ` [patch 2/5] cpuidle: add get_poll_time callback Marcelo Tosatti
2019-06-25 21:52 ` Rafael J. Wysocki
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=20190701185528.115106953@asus.localdomain \
--to=mtosatti@redhat.com \
--cc=aarcange@redhat.com \
--cc=ankur.a.arora@oracle.com \
--cc=boris.ostrovsky@oracle.com \
--cc=borntraeger@de.ibm.com \
--cc=karahmed@amazon.de \
--cc=kernellwp@gmail.com \
--cc=konrad.wilk@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rafael.j.wysocki@intel.com \
--cc=rkrcmar@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;
as well as URLs for NNTP newsgroup(s).