From: Gautham R Shenoy <ego@in.ibm.com>
To: Joel Schopp <jschopp@austin.ibm.com>,
len.brown@intel.com, Peter Zijlstra <a.p.zijlstra@chello.nl>,
Balbir Singh <balbir@in.ibm.com>,
Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
shaohua.li@intel.com, Ingo Molnar <mingo@elte.hu>,
Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>,
Dipankar Sarma <dipankar@in.ibm.com>,
"Darrick J. Wong" <djwong@us.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] cpu: Implement cpu-offline-state callbacks for pSeries.
Date: Wed, 05 Aug 2009 19:56:03 +0530 [thread overview]
Message-ID: <20090805142603.553.55888.stgit@sofia.in.ibm.com> (raw)
In-Reply-To: <20090805142311.553.78286.stgit@sofia.in.ibm.com>
This patch implements the callbacks to handle the reads/writes into the sysfs
interfaces
/sys/devices/system/cpu/cpu<number>/available_offline_states
and
/sys/devices/system/cpu/cpu<number>/preferred_offline_state
Currently, the patch defines two states which the processor can go to when it
is offlined. They are
- deallocate: The current behaviour when the cpu is offlined.
The CPU would call make an rtas_stop_self() call and hand over the
CPU back to the resource pool, thereby effectively deallocating
that vCPU from the LPAR.
- deactivate: This is expected to cede the processor to the hypervisor, so
that on processors which support appropriate low-power states, they can
be exploited. This can be considered as an extended tickless idle state.
The patch only implements the callbacks which will display the available
states, and record the preferred states. The code bits to call
rtas_stop_self() or H_CEDE, depending on the preferred_offline_state is
implemented in the next patch.
Signed-off-by: Gautham R Shenoy <ego@in.ibm.com>
---
arch/powerpc/platforms/pseries/hotplug-cpu.c | 90 +++++++++++++++++++++++
arch/powerpc/platforms/pseries/offline_driver.h | 16 ++++
2 files changed, 106 insertions(+), 0 deletions(-)
create mode 100644 arch/powerpc/platforms/pseries/offline_driver.h
diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index a20ead8..f15de99 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -30,6 +30,95 @@
#include <asm/pSeries_reconfig.h>
#include "xics.h"
#include "plpar_wrappers.h"
+#include "offline_driver.h"
+
+struct cpu_offline_state {
+ enum cpu_state_vals state_val;
+ const char *state_name;
+} pSeries_cpu_offline_states[] = {
+ {CPU_DEACTIVATE, "deactivate"},
+ {CPU_DEALLOCATE, "deallocate"},
+};
+
+DEFINE_PER_CPU(enum cpu_state_vals, preferred_offline_state) = CPU_DEALLOCATE;
+
+ssize_t pSeries_show_available_states(struct sys_device *dev,
+ struct sysdev_attribute *attr, char *buf)
+{
+ int state;
+ ssize_t ret = 0;
+
+ for (state = CPU_DEACTIVATE; state < CPU_MAX_OFFLINE_STATES; state++) {
+ if (state == CPU_STATE_ONLINE)
+ continue;
+
+ if (ret >= (ssize_t) ((PAGE_SIZE / sizeof(char))
+ - (CPU_STATES_LEN + 2)))
+ goto out;
+ ret += scnprintf(&buf[ret], CPU_STATES_LEN, "%s ",
+ pSeries_cpu_offline_states[state].state_name);
+ }
+
+out:
+ ret += sprintf(&buf[ret], "\n");
+ return ret;
+}
+
+ssize_t pSeries_show_preferred_state(struct sys_device *dev,
+ struct sysdev_attribute *attr, char *buf)
+{
+ struct cpu *cpu = container_of(dev, struct cpu, sysdev);
+ int state = per_cpu(preferred_offline_state, cpu->sysdev.id);
+
+ return scnprintf(buf, CPU_STATES_LEN, "%s\n",
+ pSeries_cpu_offline_states[state].state_name);
+}
+
+ssize_t pSeries_store_preferred_state(struct sys_device *dev,
+ struct sysdev_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct cpu *cpu = container_of(dev, struct cpu, sysdev);
+ unsigned int ret = -EINVAL;
+ char state_name[CPU_STATES_LEN];
+ int i;
+ cpu_maps_update_begin();
+ ret = sscanf(buf, "%15s", state_name);
+
+ if (ret != 1) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
+ for (i = CPU_DEACTIVATE; i < CPU_MAX_OFFLINE_STATES; i++)
+ if (!strnicmp(state_name,
+ pSeries_cpu_offline_states[i].state_name,
+ CPU_STATES_LEN))
+ break;
+
+ if (i == CPU_MAX_OFFLINE_STATES) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
+ per_cpu(preferred_offline_state, cpu->sysdev.id) =
+ pSeries_cpu_offline_states[i].state_val;
+ ret = 0;
+
+out_unlock:
+ cpu_maps_update_done();
+
+ if (ret)
+ return ret;
+ else
+ return count;
+}
+
+struct cpu_offline_driver pSeries_offline_driver = {
+ .show_available_states = pSeries_show_available_states,
+ .show_preferred_state = pSeries_show_preferred_state,
+ .store_preferred_state = pSeries_store_preferred_state,
+};
/* This version can't take the spinlock, because it never returns */
static struct rtas_args rtas_stop_self_args = {
@@ -281,6 +370,7 @@ static int __init pseries_cpu_hotplug_init(void)
ppc_md.cpu_die = pseries_mach_cpu_die;
smp_ops->cpu_disable = pseries_cpu_disable;
smp_ops->cpu_die = pseries_cpu_die;
+ register_cpu_offline_driver(&pSeries_offline_driver);
/* Processors can be added/removed only on LPAR */
if (firmware_has_feature(FW_FEATURE_LPAR))
diff --git a/arch/powerpc/platforms/pseries/offline_driver.h b/arch/powerpc/platforms/pseries/offline_driver.h
new file mode 100644
index 0000000..bdae76a
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/offline_driver.h
@@ -0,0 +1,16 @@
+#ifndef _OFFLINE_DRIVER_H_
+#define _OFFLINE_DRIVER_H_
+
+#define CPU_STATES_LEN 16
+
+/* Cpu offline states go here */
+enum cpu_state_vals {
+ CPU_DEACTIVATE,
+ CPU_DEALLOCATE,
+ CPU_STATE_ONLINE,
+ CPU_MAX_OFFLINE_STATES
+};
+
+DECLARE_PER_CPU(enum cpu_state_vals, preferred_offline_state);
+
+#endif
next prev parent reply other threads:[~2009-08-05 14:26 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-05 14:25 [PATCH 0/3] cpu: idle state framework for offline CPUs Gautham R Shenoy
2009-08-05 14:25 ` [PATCH 1/3] cpu: Offline state Framework Gautham R Shenoy
2009-08-05 14:26 ` Gautham R Shenoy [this message]
2009-08-05 14:26 ` [PATCH 3/3] pSeries: cpu: Cede CPU during a deactivate-offline Gautham R Shenoy
2009-08-06 1:58 ` [PATCH 0/3] cpu: idle state framework for offline CPUs Shaohua Li
2009-08-06 4:33 ` Vaidyanathan Srinivasan
2009-08-06 15:03 ` Peter Zijlstra
2009-08-06 15:13 ` Peter Zijlstra
2009-08-09 12:08 ` Pavel Machek
2009-08-06 13:48 ` Gautham R Shenoy
2009-08-07 1:02 ` Shaohua Li
2009-08-09 12:08 ` Pavel Machek
2009-08-09 13:22 ` Rafael J. Wysocki
2009-08-10 2:00 ` Vaidyanathan Srinivasan
2009-08-10 8:19 ` Pavel Machek
2009-08-11 0:22 ` Pallipadi, Venkatesh
2009-08-11 17:53 ` Dipankar Sarma
2009-08-12 11:58 ` Pavel Machek
2009-08-12 12:05 ` Peter Zijlstra
2009-08-12 19:57 ` Dipankar Sarma
2009-08-13 0:45 ` Len Brown
2009-08-13 4:59 ` Dipankar Sarma
2009-08-14 11:30 ` Pavel Machek
2009-08-16 18:26 ` Dipankar Sarma
2009-08-16 19:44 ` Balbir Singh
2009-08-16 21:53 ` Peter Zijlstra
2009-08-17 6:24 ` Dipankar Sarma
2009-08-17 7:15 ` Peter Zijlstra
2009-08-17 7:58 ` Dipankar Sarma
2009-08-17 14:40 ` Dipankar Sarma
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=20090805142603.553.55888.stgit@sofia.in.ibm.com \
--to=ego@in.ibm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=balbir@in.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=dipankar@in.ibm.com \
--cc=djwong@us.ibm.com \
--cc=jschopp@austin.ibm.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mingo@elte.hu \
--cc=shaohua.li@intel.com \
--cc=svaidy@linux.vnet.ibm.com \
--cc=venkatesh.pallipadi@intel.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).