mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Trinabh Gupta <trinabh@linux.vnet.ibm.com>
To: arjan@linux.intel.com, peterz@infradead.org, lenb@kernel.org,
	suresh.b.siddha@intel.com, benh@kernel.crashing.org,
	venki@google.com, ak@linux.intel.com
Cc: linux-kernel@vger.kernel.org
Subject: [RFC PATCH V1 1/2] cpuidle: Data structure changes for global cpuidle device
Date: Tue, 22 Mar 2011 18:18:02 +0530	[thread overview]
Message-ID: <20110322124750.29408.17788.stgit@tringupt.in.ibm.com> (raw)
In-Reply-To: <20110322124724.29408.12885.stgit@tringupt.in.ibm.com>

Currently cpuidle subsystem has the following data structures:

* Global cpuidle_driver which is maintained in a list for each
  registered driver

* cpuidle_device is per-cpu per-driver structure that contains the
  array of cpuidle_state defined for that CPU

* cpuidle_state contains the definition of the idle routine and place
  holders for statistics that are used by the governor to make the
  selection.

Proposed new data structures:

* Basically the cpuidle_state structure along with the cpuidle_device
  is made global and per-driver. The cpuidle_state contains the idle state
  definitions.

* The statistics part of the cpuidle_state that is needed by the
  governor on a per-cpu bases is split into a new per-cpu structure
  called cpuidle_state_stats.  This structure is generic and
  independent of the cpuidle_driver/device that is currently in force.


<<- Global--->>                 <<per-cpu>>

cpuidle_driver                  cpuidle_device_stats
  |                                    -> state_stats[]
  \
    -> cpuidle_device
        -> states[]


Open Issues:

* Handle per-cpu, per-driver's driver_data appropriately within the
  cpuidle_driver structure.  For this RFC, it is pushed into
  cpuidle_device_stats structure.

* Handle double initialization of kobj structs on multiple driver
  registration.

Signed-off-by: Trinabh Gupta <trinabh@linux.vnet.ibm.com>
---

 include/linux/cpuidle.h |   75 +++++++++++++++++++++++++++++++++--------------
 1 files changed, 52 insertions(+), 23 deletions(-)

diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
index a5f5fd0..16423df 100644
--- a/include/linux/cpuidle.h
+++ b/include/linux/cpuidle.h
@@ -22,6 +22,7 @@
 #define CPUIDLE_DESC_LEN	32
 
 struct cpuidle_device;
+struct cpuidle_state_stats;
 
 
 /****************************
@@ -31,18 +32,21 @@ struct cpuidle_device;
 struct cpuidle_state {
 	char		name[CPUIDLE_NAME_LEN];
 	char		desc[CPUIDLE_DESC_LEN];
-	void		*driver_data;
 
 	unsigned int	flags;
 	unsigned int	exit_latency; /* in US */
 	unsigned int	power_usage; /* in mW */
 	unsigned int	target_residency; /* in US */
 
-	unsigned long long	usage;
-	unsigned long long	time; /* in US */
-
 	int (*enter)	(struct cpuidle_device *dev,
-			 struct cpuidle_state *state);
+			 struct cpuidle_state *state,
+			 struct cpuidle_state_stats *state_stats);
+};
+
+struct cpuidle_state_stats {
+	void		*driver_data;
+	unsigned long long usage;
+	unsigned long long time; /* in US */
 };
 
 /* Idle State Flags */
@@ -55,9 +59,9 @@ struct cpuidle_state {
  * cpuidle_get_statedata - retrieves private driver state data
  * @state: the state
  */
-static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
+static inline void *cpuidle_get_statedata(struct cpuidle_state_stats *stats)
 {
-	return state->driver_data;
+	return stats->driver_data;
 }
 
 /**
@@ -66,9 +70,9 @@ static inline void * cpuidle_get_statedata(struct cpuidle_state *state)
  * @data: the private data
  */
 static inline void
-cpuidle_set_statedata(struct cpuidle_state *state, void *data)
+cpuidle_set_statedata(struct cpuidle_state_stats *state_stats, void *data)
 {
-	state->driver_data = data;
+	state_stats->driver_data = data;
 }
 
 struct cpuidle_state_kobj {
@@ -77,29 +81,42 @@ struct cpuidle_state_kobj {
 	struct kobject kobj;
 };
 
+struct cpuidle_device_stats {
+	unsigned int			enabled:1;
+	unsigned int			cpu;
+	int				last_residency;
+	struct cpuidle_state		*last_state;
+	struct cpuidle_state_stats	state_stats[CPUIDLE_STATE_MAX];
+
+	struct cpuidle_state_kobj	*kobjs[CPUIDLE_STATE_MAX];
+	struct kobject			kobj;
+	struct completion		kobj_unregister;
+
+	struct cpuidle_driver		*drv;
+};
+
 struct cpuidle_device {
 	unsigned int		registered:1;
 	unsigned int		enabled:1;
 	unsigned int		power_specified:1;
-	unsigned int		cpu;
 
-	int			last_residency;
 	int			state_count;
 	struct cpuidle_state	states[CPUIDLE_STATE_MAX];
-	struct cpuidle_state_kobj *kobjs[CPUIDLE_STATE_MAX];
-	struct cpuidle_state	*last_state;
 
-	struct list_head 	device_list;
 	struct cpuidle_driver	*drv;
-	struct kobject		kobj;
-	struct completion	kobj_unregister;
 	void			*governor_data;
 	struct cpuidle_state	*safe_state;
 
-	int (*prepare)		(struct cpuidle_device *dev);
+	int (*prepare)		(struct cpuidle_device_stats *dev_stats);
 };
 
-DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
+
+DECLARE_PER_CPU(struct cpuidle_device_stats, cpuidle_dev_stats);
+static inline struct cpuidle_state_stats *get_cpuidle_state_stats(int cpu,
+						int count)
+{
+	return &per_cpu(cpuidle_dev_stats, cpu).state_stats[count];
+}
 
 /**
  * cpuidle_get_last_residency - retrieves the last state's residency time
@@ -107,7 +124,7 @@ DECLARE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
  *
  * NOTE: this value is invalid if CPUIDLE_FLAG_TIME_VALID isn't set
  */
-static inline int cpuidle_get_last_residency(struct cpuidle_device *dev)
+static inline int cpuidle_get_last_residency(struct cpuidle_device_stats *dev)
 {
 	return dev->last_residency;
 }
@@ -122,6 +139,7 @@ struct cpuidle_driver {
 	struct module 		*owner;
 	unsigned int		priority;
 	struct list_head	driver_list;
+	struct cpuidle_device	*dev;
 };
 
 #ifdef CONFIG_CPU_IDLE
@@ -145,12 +163,22 @@ static inline struct cpuidle_driver *cpuidle_get_driver(void) {return NULL; }
 static inline void cpuidle_unregister_driver(struct cpuidle_driver *drv) { }
 static inline int cpuidle_register_device(struct cpuidle_device *dev)
 {return -ENODEV; }
+static inline int cpuidle_register_device_stats(
+				struct cpuidle_device_stats *dev_stats)
+{return -ENODEV; }
+static inline void cpuidle_unregister_device_stats(
+			struct cpuidle_device_stats *dev_stats) { };
 static inline void cpuidle_unregister_device(struct cpuidle_device *dev) { }
 
 static inline void cpuidle_pause_and_lock(void) { }
 static inline void cpuidle_resume_and_unlock(void) { }
 static inline int cpuidle_enable_device(struct cpuidle_device *dev)
 {return -ENODEV; }
+static inline int cpuidle_enable_device_stats(
+			struct cpuidle_device_stats *dev_stats)
+{return -ENODEV; }
+static inline void cpuidle_disable_device_stats(
+				struct cpuidle_device_stats *dev_stats) { }
 static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
 
 #endif
@@ -164,11 +192,12 @@ struct cpuidle_governor {
 	struct list_head 	governor_list;
 	unsigned int		rating;
 
-	int  (*enable)		(struct cpuidle_device *dev);
-	void (*disable)		(struct cpuidle_device *dev);
+	int  (*enable)		(struct cpuidle_device_stats *dev_stats);
+	void (*disable)		(struct cpuidle_device_stats *dev_stats);
 
-	int  (*select)		(struct cpuidle_device *dev);
-	void (*reflect)		(struct cpuidle_device *dev);
+	int  (*select)		(struct cpuidle_device *dev,
+					struct cpuidle_device_stats *dev_stats);
+	void (*reflect)		(struct cpuidle_device_stats *dev_stats);
 
 	struct module 		*owner;
 };


  reply	other threads:[~2011-03-22 12:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-22 12:47 [RFC PATCH V1 0/2] cpuidle: global registration of idle states with per-cpu statistics Trinabh Gupta
2011-03-22 12:48 ` Trinabh Gupta [this message]
2011-03-25  8:12   ` [RFC PATCH V1 1/2] cpuidle: Data structure changes for global cpuidle device Len Brown
2011-03-25 17:48     ` Vaidyanathan Srinivasan
2011-04-02  0:03       ` Len Brown
2011-03-22 12:48 ` [RFC PATCH V1 2/2] cpuidle: API changes in callers using new cpuidle_state_stats Trinabh Gupta
2011-03-25  7:28 ` [RFC PATCH V1 0/2] cpuidle: global registration of idle states with per-cpu statistics Len Brown
2011-03-25 17:15   ` Vaidyanathan Srinivasan

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=20110322124750.29408.17788.stgit@tringupt.in.ibm.com \
    --to=trinabh@linux.vnet.ibm.com \
    --cc=ak@linux.intel.com \
    --cc=arjan@linux.intel.com \
    --cc=benh@kernel.crashing.org \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=suresh.b.siddha@intel.com \
    --cc=venki@google.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

all inboxes | Powered by JetHome®