2011-12-22 06:29:42 +08:00
|
|
|
#include <linux/device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/percpu.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/sched.h>
|
2011-07-23 06:24:23 +08:00
|
|
|
#include <linux/export.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/nodemask.h>
|
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
|
|
|
|
#include <asm/current.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/cputable.h>
|
|
|
|
#include <asm/hvcall.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/machdep.h>
|
2005-11-07 10:18:13 +08:00
|
|
|
#include <asm/smp.h>
|
powerpc: Fix bug where perf_counters breaks oprofile
Currently there is a bug where if you use oprofile on a pSeries
machine, then use perf_counters, then use oprofile again, oprofile
will not work correctly; it will lose the PMU configuration the next
time the hypervisor does a partition context switch, and thereafter
won't count anything.
Maynard Johnson identified the sequence causing the problem:
- oprofile setup calls ppc_enable_pmcs(), which calls
pseries_lpar_enable_pmcs, which tells the hypervisor that we want
to use the PMU, and sets the "PMU in use" flag in the lppaca.
This flag tells the hypervisor whether it needs to save and restore
the PMU config.
- The perf_counter code sets and clears the "PMU in use" flag directly
as it context-switches the PMU between tasks, and leaves it clear
when it finishes.
- oprofile setup, called for a new oprofile run, calls ppc_enable_pmcs,
which does nothing because it has already been called. In particular
it doesn't set the "PMU in use" flag.
This fixes the problem by arranging for ppc_enable_pmcs to always set
the "PMU in use" flag. It makes the perf_counter code call
ppc_enable_pmcs also rather than calling the lower-level function
directly, and removes the setting of the "PMU in use" flag from
pseries_lpar_enable_pmcs, since that is now done in its caller.
This also removes the declaration of pasemi_enable_pmcs because it
isn't defined anywhere.
Reported-by: Maynard Johnson <mpjohn@us.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Cc: <stable@kernel.org)
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2009-09-09 09:26:03 +08:00
|
|
|
#include <asm/pmc.h>
|
2013-10-02 03:04:10 +08:00
|
|
|
#include <asm/firmware.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-24 02:55:54 +08:00
|
|
|
#include "cacheinfo.h"
|
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
#include <asm/paca.h>
|
|
|
|
#include <asm/lppaca.h>
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static DEFINE_PER_CPU(struct cpu, cpu_devices);
|
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
/*
|
|
|
|
* SMT snooze delay stuff, 64-bit only for now
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC64
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-09-22 18:30:14 +08:00
|
|
|
/* Time in microseconds we delay before sleeping in the idle loop */
|
2010-05-17 04:02:39 +08:00
|
|
|
DEFINE_PER_CPU(long, smt_snooze_delay) = { 100 };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t store_smt_snooze_delay(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2008-07-02 00:48:41 +08:00
|
|
|
const char *buf,
|
2005-04-17 06:20:36 +08:00
|
|
|
size_t count)
|
|
|
|
{
|
2011-12-22 06:29:42 +08:00
|
|
|
struct cpu *cpu = container_of(dev, struct cpu, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssize_t ret;
|
2010-05-17 04:02:39 +08:00
|
|
|
long snooze;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-05-17 04:02:39 +08:00
|
|
|
ret = sscanf(buf, "%ld", &snooze);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ret != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
per_cpu(smt_snooze_delay, cpu->dev.id) = snooze;
|
2005-04-17 06:20:36 +08:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t show_smt_snooze_delay(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2008-07-02 00:48:41 +08:00
|
|
|
char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-12-22 06:29:42 +08:00
|
|
|
struct cpu *cpu = container_of(dev, struct cpu, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
return sprintf(buf, "%ld\n", per_cpu(smt_snooze_delay, cpu->dev.id));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static DEVICE_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay,
|
2005-04-17 06:20:36 +08:00
|
|
|
store_smt_snooze_delay);
|
|
|
|
|
|
|
|
static int __init setup_smt_snooze_delay(char *str)
|
|
|
|
{
|
|
|
|
unsigned int cpu;
|
2010-05-17 04:02:39 +08:00
|
|
|
long snooze;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!cpu_has_feature(CPU_FTR_SMT))
|
|
|
|
return 1;
|
|
|
|
|
2010-05-17 04:02:39 +08:00
|
|
|
snooze = simple_strtol(str, NULL, 10);
|
|
|
|
for_each_possible_cpu(cpu)
|
|
|
|
per_cpu(smt_snooze_delay, cpu) = snooze;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("smt-snooze-delay=", setup_smt_snooze_delay);
|
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* CONFIG_PPC64 */
|
2005-08-09 09:13:36 +08:00
|
|
|
|
2013-12-17 16:17:02 +08:00
|
|
|
#ifdef CONFIG_PPC_FSL_BOOK3E
|
|
|
|
#define MAX_BIT 63
|
|
|
|
|
|
|
|
static u64 pw20_wt;
|
|
|
|
static u64 altivec_idle_wt;
|
|
|
|
|
|
|
|
static unsigned int get_idle_ticks_bit(u64 ns)
|
|
|
|
{
|
|
|
|
u64 cycle;
|
|
|
|
|
|
|
|
if (ns >= 10000)
|
|
|
|
cycle = div_u64(ns + 500, 1000) * tb_ticks_per_usec;
|
|
|
|
else
|
|
|
|
cycle = div_u64(ns * tb_ticks_per_usec, 1000);
|
|
|
|
|
|
|
|
if (!cycle)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ilog2(cycle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_show_pwrmgtcr0(void *val)
|
|
|
|
{
|
|
|
|
u32 *value = val;
|
|
|
|
|
|
|
|
*value = mfspr(SPRN_PWRMGTCR0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_pw20_state(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
unsigned int cpu = dev->id;
|
|
|
|
|
|
|
|
smp_call_function_single(cpu, do_show_pwrmgtcr0, &value, 1);
|
|
|
|
|
|
|
|
value &= PWRMGTCR0_PW20_WAIT;
|
|
|
|
|
|
|
|
return sprintf(buf, "%u\n", value ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_store_pw20_state(void *val)
|
|
|
|
{
|
|
|
|
u32 *value = val;
|
|
|
|
u32 pw20_state;
|
|
|
|
|
|
|
|
pw20_state = mfspr(SPRN_PWRMGTCR0);
|
|
|
|
|
|
|
|
if (*value)
|
|
|
|
pw20_state |= PWRMGTCR0_PW20_WAIT;
|
|
|
|
else
|
|
|
|
pw20_state &= ~PWRMGTCR0_PW20_WAIT;
|
|
|
|
|
|
|
|
mtspr(SPRN_PWRMGTCR0, pw20_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_pw20_state(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
unsigned int cpu = dev->id;
|
|
|
|
|
|
|
|
if (kstrtou32(buf, 0, &value))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (value > 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
smp_call_function_single(cpu, do_store_pw20_state, &value, 1);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_pw20_wait_time(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
u64 tb_cycle = 1;
|
|
|
|
u64 time;
|
|
|
|
|
|
|
|
unsigned int cpu = dev->id;
|
|
|
|
|
|
|
|
if (!pw20_wt) {
|
|
|
|
smp_call_function_single(cpu, do_show_pwrmgtcr0, &value, 1);
|
|
|
|
value = (value & PWRMGTCR0_PW20_ENT) >>
|
|
|
|
PWRMGTCR0_PW20_ENT_SHIFT;
|
|
|
|
|
|
|
|
tb_cycle = (tb_cycle << (MAX_BIT - value + 1));
|
|
|
|
/* convert ms to ns */
|
|
|
|
if (tb_ticks_per_usec > 1000) {
|
|
|
|
time = div_u64(tb_cycle, tb_ticks_per_usec / 1000);
|
|
|
|
} else {
|
|
|
|
u32 rem_us;
|
|
|
|
|
|
|
|
time = div_u64_rem(tb_cycle, tb_ticks_per_usec,
|
|
|
|
&rem_us);
|
|
|
|
time = time * 1000 + rem_us * 1000 / tb_ticks_per_usec;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
time = pw20_wt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(buf, "%llu\n", time > 0 ? time : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_pw20_wait_entry_bit(void *val)
|
|
|
|
{
|
|
|
|
u32 *value = val;
|
|
|
|
u32 pw20_idle;
|
|
|
|
|
|
|
|
pw20_idle = mfspr(SPRN_PWRMGTCR0);
|
|
|
|
|
|
|
|
/* Set Automatic PW20 Core Idle Count */
|
|
|
|
/* clear count */
|
|
|
|
pw20_idle &= ~PWRMGTCR0_PW20_ENT;
|
|
|
|
|
|
|
|
/* set count */
|
|
|
|
pw20_idle |= ((MAX_BIT - *value) << PWRMGTCR0_PW20_ENT_SHIFT);
|
|
|
|
|
|
|
|
mtspr(SPRN_PWRMGTCR0, pw20_idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_pw20_wait_time(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
u32 entry_bit;
|
|
|
|
u64 value;
|
|
|
|
|
|
|
|
unsigned int cpu = dev->id;
|
|
|
|
|
|
|
|
if (kstrtou64(buf, 0, &value))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
entry_bit = get_idle_ticks_bit(value);
|
|
|
|
if (entry_bit > MAX_BIT)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
pw20_wt = value;
|
|
|
|
|
|
|
|
smp_call_function_single(cpu, set_pw20_wait_entry_bit,
|
|
|
|
&entry_bit, 1);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_altivec_idle(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
unsigned int cpu = dev->id;
|
|
|
|
|
|
|
|
smp_call_function_single(cpu, do_show_pwrmgtcr0, &value, 1);
|
|
|
|
|
|
|
|
value &= PWRMGTCR0_AV_IDLE_PD_EN;
|
|
|
|
|
|
|
|
return sprintf(buf, "%u\n", value ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_store_altivec_idle(void *val)
|
|
|
|
{
|
|
|
|
u32 *value = val;
|
|
|
|
u32 altivec_idle;
|
|
|
|
|
|
|
|
altivec_idle = mfspr(SPRN_PWRMGTCR0);
|
|
|
|
|
|
|
|
if (*value)
|
|
|
|
altivec_idle |= PWRMGTCR0_AV_IDLE_PD_EN;
|
|
|
|
else
|
|
|
|
altivec_idle &= ~PWRMGTCR0_AV_IDLE_PD_EN;
|
|
|
|
|
|
|
|
mtspr(SPRN_PWRMGTCR0, altivec_idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_altivec_idle(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
unsigned int cpu = dev->id;
|
|
|
|
|
|
|
|
if (kstrtou32(buf, 0, &value))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (value > 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
smp_call_function_single(cpu, do_store_altivec_idle, &value, 1);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_altivec_idle_wait_time(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
u64 tb_cycle = 1;
|
|
|
|
u64 time;
|
|
|
|
|
|
|
|
unsigned int cpu = dev->id;
|
|
|
|
|
|
|
|
if (!altivec_idle_wt) {
|
|
|
|
smp_call_function_single(cpu, do_show_pwrmgtcr0, &value, 1);
|
|
|
|
value = (value & PWRMGTCR0_AV_IDLE_CNT) >>
|
|
|
|
PWRMGTCR0_AV_IDLE_CNT_SHIFT;
|
|
|
|
|
|
|
|
tb_cycle = (tb_cycle << (MAX_BIT - value + 1));
|
|
|
|
/* convert ms to ns */
|
|
|
|
if (tb_ticks_per_usec > 1000) {
|
|
|
|
time = div_u64(tb_cycle, tb_ticks_per_usec / 1000);
|
|
|
|
} else {
|
|
|
|
u32 rem_us;
|
|
|
|
|
|
|
|
time = div_u64_rem(tb_cycle, tb_ticks_per_usec,
|
|
|
|
&rem_us);
|
|
|
|
time = time * 1000 + rem_us * 1000 / tb_ticks_per_usec;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
time = altivec_idle_wt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(buf, "%llu\n", time > 0 ? time : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_altivec_idle_wait_entry_bit(void *val)
|
|
|
|
{
|
|
|
|
u32 *value = val;
|
|
|
|
u32 altivec_idle;
|
|
|
|
|
|
|
|
altivec_idle = mfspr(SPRN_PWRMGTCR0);
|
|
|
|
|
|
|
|
/* Set Automatic AltiVec Idle Count */
|
|
|
|
/* clear count */
|
|
|
|
altivec_idle &= ~PWRMGTCR0_AV_IDLE_CNT;
|
|
|
|
|
|
|
|
/* set count */
|
|
|
|
altivec_idle |= ((MAX_BIT - *value) << PWRMGTCR0_AV_IDLE_CNT_SHIFT);
|
|
|
|
|
|
|
|
mtspr(SPRN_PWRMGTCR0, altivec_idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t store_altivec_idle_wait_time(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
u32 entry_bit;
|
|
|
|
u64 value;
|
|
|
|
|
|
|
|
unsigned int cpu = dev->id;
|
|
|
|
|
|
|
|
if (kstrtou64(buf, 0, &value))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
entry_bit = get_idle_ticks_bit(value);
|
|
|
|
if (entry_bit > MAX_BIT)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
altivec_idle_wt = value;
|
|
|
|
|
|
|
|
smp_call_function_single(cpu, set_altivec_idle_wait_entry_bit,
|
|
|
|
&entry_bit, 1);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable/Disable interface:
|
|
|
|
* 0, disable. 1, enable.
|
|
|
|
*/
|
|
|
|
static DEVICE_ATTR(pw20_state, 0600, show_pw20_state, store_pw20_state);
|
|
|
|
static DEVICE_ATTR(altivec_idle, 0600, show_altivec_idle, store_altivec_idle);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set wait time interface:(Nanosecond)
|
|
|
|
* Example: Base on TBfreq is 41MHZ.
|
|
|
|
* 1~48(ns): TB[63]
|
|
|
|
* 49~97(ns): TB[62]
|
|
|
|
* 98~195(ns): TB[61]
|
|
|
|
* 196~390(ns): TB[60]
|
|
|
|
* 391~780(ns): TB[59]
|
|
|
|
* 781~1560(ns): TB[58]
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
static DEVICE_ATTR(pw20_wait_time, 0600,
|
|
|
|
show_pw20_wait_time,
|
|
|
|
store_pw20_wait_time);
|
|
|
|
static DEVICE_ATTR(altivec_idle_wait_time, 0600,
|
|
|
|
show_altivec_idle_wait_time,
|
|
|
|
store_altivec_idle_wait_time);
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Enabling PMCs will slow partition context switch times so we only do
|
|
|
|
* it the first time we write to the PMCs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static DEFINE_PER_CPU(char, pmcs_enabled);
|
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
void ppc_enable_pmcs(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
powerpc: Fix bug where perf_counters breaks oprofile
Currently there is a bug where if you use oprofile on a pSeries
machine, then use perf_counters, then use oprofile again, oprofile
will not work correctly; it will lose the PMU configuration the next
time the hypervisor does a partition context switch, and thereafter
won't count anything.
Maynard Johnson identified the sequence causing the problem:
- oprofile setup calls ppc_enable_pmcs(), which calls
pseries_lpar_enable_pmcs, which tells the hypervisor that we want
to use the PMU, and sets the "PMU in use" flag in the lppaca.
This flag tells the hypervisor whether it needs to save and restore
the PMU config.
- The perf_counter code sets and clears the "PMU in use" flag directly
as it context-switches the PMU between tasks, and leaves it clear
when it finishes.
- oprofile setup, called for a new oprofile run, calls ppc_enable_pmcs,
which does nothing because it has already been called. In particular
it doesn't set the "PMU in use" flag.
This fixes the problem by arranging for ppc_enable_pmcs to always set
the "PMU in use" flag. It makes the perf_counter code call
ppc_enable_pmcs also rather than calling the lower-level function
directly, and removes the setting of the "PMU in use" flag from
pseries_lpar_enable_pmcs, since that is now done in its caller.
This also removes the declaration of pasemi_enable_pmcs because it
isn't defined anywhere.
Reported-by: Maynard Johnson <mpjohn@us.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Cc: <stable@kernel.org)
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2009-09-09 09:26:03 +08:00
|
|
|
ppc_set_pmu_inuse(1);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Only need to enable them once */
|
powerpc: Replace __get_cpu_var uses
This still has not been merged and now powerpc is the only arch that does
not have this change. Sorry about missing linuxppc-dev before.
V2->V2
- Fix up to work against 3.18-rc1
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
__this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
__this_cpu_inc(y)
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <paulus@samba.org>
Signed-off-by: Christoph Lameter <cl@linux.com>
[mpe: Fix build errors caused by set/or_softirq_pending(), and rework
assignment in __set_breakpoint() to use memcpy().]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2014-10-22 04:23:25 +08:00
|
|
|
if (__this_cpu_read(pmcs_enabled))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
powerpc: Replace __get_cpu_var uses
This still has not been merged and now powerpc is the only arch that does
not have this change. Sorry about missing linuxppc-dev before.
V2->V2
- Fix up to work against 3.18-rc1
__get_cpu_var() is used for multiple purposes in the kernel source. One of
them is address calculation via the form &__get_cpu_var(x). This calculates
the address for the instance of the percpu variable of the current processor
based on an offset.
Other use cases are for storing and retrieving data from the current
processors percpu area. __get_cpu_var() can be used as an lvalue when
writing data or on the right side of an assignment.
__get_cpu_var() is defined as :
__get_cpu_var() always only does an address determination. However, store
and retrieve operations could use a segment prefix (or global register on
other platforms) to avoid the address calculation.
this_cpu_write() and this_cpu_read() can directly take an offset into a
percpu area and use optimized assembly code to read and write per cpu
variables.
This patch converts __get_cpu_var into either an explicit address
calculation using this_cpu_ptr() or into a use of this_cpu operations that
use the offset. Thereby address calculations are avoided and less registers
are used when code is generated.
At the end of the patch set all uses of __get_cpu_var have been removed so
the macro is removed too.
The patch set includes passes over all arches as well. Once these operations
are used throughout then specialized macros can be defined in non -x86
arches as well in order to optimize per cpu access by f.e. using a global
register that may be set to the per cpu base.
Transformations done to __get_cpu_var()
1. Determine the address of the percpu instance of the current processor.
DEFINE_PER_CPU(int, y);
int *x = &__get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(&y);
2. Same as #1 but this time an array structure is involved.
DEFINE_PER_CPU(int, y[20]);
int *x = __get_cpu_var(y);
Converts to
int *x = this_cpu_ptr(y);
3. Retrieve the content of the current processors instance of a per cpu
variable.
DEFINE_PER_CPU(int, y);
int x = __get_cpu_var(y)
Converts to
int x = __this_cpu_read(y);
4. Retrieve the content of a percpu struct
DEFINE_PER_CPU(struct mystruct, y);
struct mystruct x = __get_cpu_var(y);
Converts to
memcpy(&x, this_cpu_ptr(&y), sizeof(x));
5. Assignment to a per cpu variable
DEFINE_PER_CPU(int, y)
__get_cpu_var(y) = x;
Converts to
__this_cpu_write(y, x);
6. Increment/Decrement etc of a per cpu variable
DEFINE_PER_CPU(int, y);
__get_cpu_var(y)++
Converts to
__this_cpu_inc(y)
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <paulus@samba.org>
Signed-off-by: Christoph Lameter <cl@linux.com>
[mpe: Fix build errors caused by set/or_softirq_pending(), and rework
assignment in __set_breakpoint() to use memcpy().]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2014-10-22 04:23:25 +08:00
|
|
|
__this_cpu_write(pmcs_enabled, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-08-09 09:13:36 +08:00
|
|
|
if (ppc_md.enable_pmcs)
|
|
|
|
ppc_md.enable_pmcs();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-08-18 12:23:51 +08:00
|
|
|
EXPORT_SYMBOL(ppc_enable_pmcs);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-05-21 14:32:37 +08:00
|
|
|
#define __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, EXTRA) \
|
2009-03-11 20:20:05 +08:00
|
|
|
static void read_##NAME(void *val) \
|
2005-04-17 06:20:36 +08:00
|
|
|
{ \
|
2009-03-27 03:29:06 +08:00
|
|
|
*(unsigned long *)val = mfspr(ADDRESS); \
|
2005-04-17 06:20:36 +08:00
|
|
|
} \
|
2009-03-27 03:29:06 +08:00
|
|
|
static void write_##NAME(void *val) \
|
2005-04-17 06:20:36 +08:00
|
|
|
{ \
|
2013-10-03 17:27:35 +08:00
|
|
|
EXTRA; \
|
2009-03-11 20:20:05 +08:00
|
|
|
mtspr(ADDRESS, *(unsigned long *)val); \
|
2014-05-21 14:32:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define __SYSFS_SPRSETUP_SHOW_STORE(NAME) \
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t show_##NAME(struct device *dev, \
|
|
|
|
struct device_attribute *attr, \
|
2008-07-02 00:48:41 +08:00
|
|
|
char *buf) \
|
2005-04-17 06:20:36 +08:00
|
|
|
{ \
|
2011-12-22 06:29:42 +08:00
|
|
|
struct cpu *cpu = container_of(dev, struct cpu, dev); \
|
2009-03-11 20:20:05 +08:00
|
|
|
unsigned long val; \
|
2011-12-22 06:29:42 +08:00
|
|
|
smp_call_function_single(cpu->dev.id, read_##NAME, &val, 1); \
|
2005-04-17 06:20:36 +08:00
|
|
|
return sprintf(buf, "%lx\n", val); \
|
|
|
|
} \
|
2008-01-25 05:16:20 +08:00
|
|
|
static ssize_t __used \
|
2011-12-22 06:29:42 +08:00
|
|
|
store_##NAME(struct device *dev, struct device_attribute *attr, \
|
2008-07-02 00:48:41 +08:00
|
|
|
const char *buf, size_t count) \
|
2005-04-17 06:20:36 +08:00
|
|
|
{ \
|
2011-12-22 06:29:42 +08:00
|
|
|
struct cpu *cpu = container_of(dev, struct cpu, dev); \
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long val; \
|
|
|
|
int ret = sscanf(buf, "%lx", &val); \
|
|
|
|
if (ret != 1) \
|
|
|
|
return -EINVAL; \
|
2011-12-22 06:29:42 +08:00
|
|
|
smp_call_function_single(cpu->dev.id, write_##NAME, &val, 1); \
|
2005-04-17 06:20:36 +08:00
|
|
|
return count; \
|
|
|
|
}
|
|
|
|
|
2014-05-21 14:32:37 +08:00
|
|
|
#define SYSFS_PMCSETUP(NAME, ADDRESS) \
|
|
|
|
__SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, ppc_enable_pmcs()) \
|
|
|
|
__SYSFS_SPRSETUP_SHOW_STORE(NAME)
|
|
|
|
#define SYSFS_SPRSETUP(NAME, ADDRESS) \
|
|
|
|
__SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, ) \
|
|
|
|
__SYSFS_SPRSETUP_SHOW_STORE(NAME)
|
|
|
|
|
|
|
|
#define SYSFS_SPRSETUP_SHOW_STORE(NAME) \
|
|
|
|
__SYSFS_SPRSETUP_SHOW_STORE(NAME)
|
2007-01-29 11:25:57 +08:00
|
|
|
|
|
|
|
/* Let's define all possible registers, we'll only hook up the ones
|
|
|
|
* that are implemented on the current processor
|
|
|
|
*/
|
|
|
|
|
2008-09-19 06:50:42 +08:00
|
|
|
#if defined(CONFIG_PPC64)
|
2008-08-18 12:23:51 +08:00
|
|
|
#define HAS_PPC_PMC_CLASSIC 1
|
|
|
|
#define HAS_PPC_PMC_IBM 1
|
|
|
|
#define HAS_PPC_PMC_PA6T 1
|
2008-09-19 06:50:42 +08:00
|
|
|
#elif defined(CONFIG_6xx)
|
2008-08-18 12:23:51 +08:00
|
|
|
#define HAS_PPC_PMC_CLASSIC 1
|
|
|
|
#define HAS_PPC_PMC_IBM 1
|
|
|
|
#define HAS_PPC_PMC_G4 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAS_PPC_PMC_CLASSIC
|
2005-04-17 06:20:36 +08:00
|
|
|
SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0);
|
|
|
|
SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1);
|
|
|
|
SYSFS_PMCSETUP(pmc1, SPRN_PMC1);
|
|
|
|
SYSFS_PMCSETUP(pmc2, SPRN_PMC2);
|
|
|
|
SYSFS_PMCSETUP(pmc3, SPRN_PMC3);
|
|
|
|
SYSFS_PMCSETUP(pmc4, SPRN_PMC4);
|
|
|
|
SYSFS_PMCSETUP(pmc5, SPRN_PMC5);
|
|
|
|
SYSFS_PMCSETUP(pmc6, SPRN_PMC6);
|
2008-08-18 12:23:51 +08:00
|
|
|
|
|
|
|
#ifdef HAS_PPC_PMC_G4
|
|
|
|
SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC64
|
2005-04-17 06:20:36 +08:00
|
|
|
SYSFS_PMCSETUP(pmc7, SPRN_PMC7);
|
|
|
|
SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
|
2008-08-18 12:23:51 +08:00
|
|
|
|
|
|
|
SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
|
2013-10-03 17:27:35 +08:00
|
|
|
SYSFS_SPRSETUP(purr, SPRN_PURR);
|
|
|
|
SYSFS_SPRSETUP(spurr, SPRN_SPURR);
|
|
|
|
SYSFS_SPRSETUP(pir, SPRN_PIR);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-02 03:04:10 +08:00
|
|
|
/*
|
|
|
|
Lets only enable read for phyp resources and
|
|
|
|
enable write when needed with a separate function.
|
|
|
|
Lets be conservative and default to pseries.
|
|
|
|
*/
|
2011-12-22 06:29:42 +08:00
|
|
|
static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
|
2013-05-06 13:02:40 +08:00
|
|
|
static DEVICE_ATTR(spurr, 0400, show_spurr, NULL);
|
2013-10-02 03:04:10 +08:00
|
|
|
static DEVICE_ATTR(purr, 0400, show_purr, store_purr);
|
2012-01-08 04:03:30 +08:00
|
|
|
static DEVICE_ATTR(pir, 0400, show_pir, NULL);
|
2011-03-02 23:18:48 +08:00
|
|
|
|
2015-05-21 14:43:04 +08:00
|
|
|
/*
|
|
|
|
* This is the system wide DSCR register default value. Any
|
|
|
|
* change to this default value through the sysfs interface
|
|
|
|
* will update all per cpu DSCR default values across the
|
|
|
|
* system stored in their respective PACA structures.
|
|
|
|
*/
|
2014-05-21 14:32:38 +08:00
|
|
|
static unsigned long dscr_default;
|
|
|
|
|
2015-05-21 14:43:04 +08:00
|
|
|
/**
|
|
|
|
* read_dscr() - Fetch the cpu specific DSCR default
|
|
|
|
* @val: Returned cpu specific DSCR default value
|
|
|
|
*
|
|
|
|
* This function returns the per cpu DSCR default value
|
|
|
|
* for any cpu which is contained in it's PACA structure.
|
|
|
|
*/
|
2014-05-21 14:32:38 +08:00
|
|
|
static void read_dscr(void *val)
|
|
|
|
{
|
|
|
|
*(unsigned long *)val = get_paca()->dscr_default;
|
|
|
|
}
|
|
|
|
|
2015-05-21 14:43:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* write_dscr() - Update the cpu specific DSCR default
|
|
|
|
* @val: New cpu specific DSCR default value to update
|
|
|
|
*
|
|
|
|
* This function updates the per cpu DSCR default value
|
|
|
|
* for any cpu which is contained in it's PACA structure.
|
|
|
|
*/
|
2014-05-21 14:32:38 +08:00
|
|
|
static void write_dscr(void *val)
|
|
|
|
{
|
|
|
|
get_paca()->dscr_default = *(unsigned long *)val;
|
|
|
|
if (!current->thread.dscr_inherit) {
|
|
|
|
current->thread.dscr = *(unsigned long *)val;
|
|
|
|
mtspr(SPRN_DSCR, *(unsigned long *)val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSFS_SPRSETUP_SHOW_STORE(dscr);
|
|
|
|
static DEVICE_ATTR(dscr, 0600, show_dscr, store_dscr);
|
2011-03-02 23:18:48 +08:00
|
|
|
|
2013-10-02 03:04:10 +08:00
|
|
|
static void add_write_permission_dev_attr(struct device_attribute *attr)
|
|
|
|
{
|
|
|
|
attr->attr.mode |= 0200;
|
|
|
|
}
|
|
|
|
|
2015-05-21 14:43:04 +08:00
|
|
|
/**
|
|
|
|
* show_dscr_default() - Fetch the system wide DSCR default
|
|
|
|
* @dev: Device structure
|
|
|
|
* @attr: Device attribute structure
|
|
|
|
* @buf: Interface buffer
|
|
|
|
*
|
|
|
|
* This function returns the system wide DSCR default value.
|
|
|
|
*/
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t show_dscr_default(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2011-03-02 23:18:48 +08:00
|
|
|
{
|
|
|
|
return sprintf(buf, "%lx\n", dscr_default);
|
|
|
|
}
|
|
|
|
|
2015-05-21 14:43:04 +08:00
|
|
|
/**
|
|
|
|
* store_dscr_default() - Update the system wide DSCR default
|
|
|
|
* @dev: Device structure
|
|
|
|
* @attr: Device attribute structure
|
|
|
|
* @buf: Interface buffer
|
|
|
|
* @count: Size of the update
|
|
|
|
*
|
|
|
|
* This function updates the system wide DSCR default value.
|
|
|
|
*/
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t __used store_dscr_default(struct device *dev,
|
|
|
|
struct device_attribute *attr, const char *buf,
|
2011-03-02 23:18:48 +08:00
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
unsigned long val;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = sscanf(buf, "%lx", &val);
|
|
|
|
if (ret != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
dscr_default = val;
|
|
|
|
|
2014-05-21 14:32:38 +08:00
|
|
|
on_each_cpu(write_dscr, &val, 1);
|
2012-09-04 00:47:56 +08:00
|
|
|
|
2011-03-02 23:18:48 +08:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static DEVICE_ATTR(dscr_default, 0600,
|
2011-03-02 23:18:48 +08:00
|
|
|
show_dscr_default, store_dscr_default);
|
|
|
|
|
|
|
|
static void sysfs_create_dscr_default(void)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
if (cpu_has_feature(CPU_FTR_DSCR))
|
2011-12-22 06:29:42 +08:00
|
|
|
err = device_create_file(cpu_subsys.dev_root, &dev_attr_dscr_default);
|
2011-03-02 23:18:48 +08:00
|
|
|
}
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* CONFIG_PPC64 */
|
|
|
|
|
|
|
|
#ifdef HAS_PPC_PMC_PA6T
|
2007-04-18 14:38:21 +08:00
|
|
|
SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0);
|
|
|
|
SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1);
|
|
|
|
SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2);
|
|
|
|
SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3);
|
|
|
|
SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4);
|
|
|
|
SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5);
|
2007-09-05 10:09:06 +08:00
|
|
|
#ifdef CONFIG_DEBUG_KERNEL
|
2013-10-03 17:27:35 +08:00
|
|
|
SYSFS_SPRSETUP(hid0, SPRN_HID0);
|
|
|
|
SYSFS_SPRSETUP(hid1, SPRN_HID1);
|
|
|
|
SYSFS_SPRSETUP(hid4, SPRN_HID4);
|
|
|
|
SYSFS_SPRSETUP(hid5, SPRN_HID5);
|
|
|
|
SYSFS_SPRSETUP(ima0, SPRN_PA6T_IMA0);
|
|
|
|
SYSFS_SPRSETUP(ima1, SPRN_PA6T_IMA1);
|
|
|
|
SYSFS_SPRSETUP(ima2, SPRN_PA6T_IMA2);
|
|
|
|
SYSFS_SPRSETUP(ima3, SPRN_PA6T_IMA3);
|
|
|
|
SYSFS_SPRSETUP(ima4, SPRN_PA6T_IMA4);
|
|
|
|
SYSFS_SPRSETUP(ima5, SPRN_PA6T_IMA5);
|
|
|
|
SYSFS_SPRSETUP(ima6, SPRN_PA6T_IMA6);
|
|
|
|
SYSFS_SPRSETUP(ima7, SPRN_PA6T_IMA7);
|
|
|
|
SYSFS_SPRSETUP(ima8, SPRN_PA6T_IMA8);
|
|
|
|
SYSFS_SPRSETUP(ima9, SPRN_PA6T_IMA9);
|
|
|
|
SYSFS_SPRSETUP(imaat, SPRN_PA6T_IMAAT);
|
|
|
|
SYSFS_SPRSETUP(btcr, SPRN_PA6T_BTCR);
|
|
|
|
SYSFS_SPRSETUP(pccr, SPRN_PA6T_PCCR);
|
|
|
|
SYSFS_SPRSETUP(rpccr, SPRN_PA6T_RPCCR);
|
|
|
|
SYSFS_SPRSETUP(der, SPRN_PA6T_DER);
|
|
|
|
SYSFS_SPRSETUP(mer, SPRN_PA6T_MER);
|
|
|
|
SYSFS_SPRSETUP(ber, SPRN_PA6T_BER);
|
|
|
|
SYSFS_SPRSETUP(ier, SPRN_PA6T_IER);
|
|
|
|
SYSFS_SPRSETUP(sier, SPRN_PA6T_SIER);
|
|
|
|
SYSFS_SPRSETUP(siar, SPRN_PA6T_SIAR);
|
|
|
|
SYSFS_SPRSETUP(tsr0, SPRN_PA6T_TSR0);
|
|
|
|
SYSFS_SPRSETUP(tsr1, SPRN_PA6T_TSR1);
|
|
|
|
SYSFS_SPRSETUP(tsr2, SPRN_PA6T_TSR2);
|
|
|
|
SYSFS_SPRSETUP(tsr3, SPRN_PA6T_TSR3);
|
2007-09-05 10:09:06 +08:00
|
|
|
#endif /* CONFIG_DEBUG_KERNEL */
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* HAS_PPC_PMC_PA6T */
|
2007-01-29 11:25:57 +08:00
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef HAS_PPC_PMC_IBM
|
2011-12-22 06:29:42 +08:00
|
|
|
static struct device_attribute ibm_common_attrs[] = {
|
|
|
|
__ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
|
|
|
|
__ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
|
2007-01-29 11:25:57 +08:00
|
|
|
};
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* HAS_PPC_PMC_G4 */
|
|
|
|
|
|
|
|
#ifdef HAS_PPC_PMC_G4
|
2011-12-22 06:29:42 +08:00
|
|
|
static struct device_attribute g4_common_attrs[] = {
|
|
|
|
__ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
|
|
|
|
__ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
|
|
|
|
__ATTR(mmcr2, 0600, show_mmcr2, store_mmcr2),
|
2008-08-18 12:23:51 +08:00
|
|
|
};
|
|
|
|
#endif /* HAS_PPC_PMC_G4 */
|
2007-01-29 11:25:57 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static struct device_attribute classic_pmc_attrs[] = {
|
|
|
|
__ATTR(pmc1, 0600, show_pmc1, store_pmc1),
|
|
|
|
__ATTR(pmc2, 0600, show_pmc2, store_pmc2),
|
|
|
|
__ATTR(pmc3, 0600, show_pmc3, store_pmc3),
|
|
|
|
__ATTR(pmc4, 0600, show_pmc4, store_pmc4),
|
|
|
|
__ATTR(pmc5, 0600, show_pmc5, store_pmc5),
|
|
|
|
__ATTR(pmc6, 0600, show_pmc6, store_pmc6),
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
2011-12-22 06:29:42 +08:00
|
|
|
__ATTR(pmc7, 0600, show_pmc7, store_pmc7),
|
|
|
|
__ATTR(pmc8, 0600, show_pmc8, store_pmc8),
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif
|
2007-01-29 11:25:57 +08:00
|
|
|
};
|
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef HAS_PPC_PMC_PA6T
|
2011-12-22 06:29:42 +08:00
|
|
|
static struct device_attribute pa6t_attrs[] = {
|
|
|
|
__ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
|
|
|
|
__ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
|
|
|
|
__ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0),
|
|
|
|
__ATTR(pmc1, 0600, show_pa6t_pmc1, store_pa6t_pmc1),
|
|
|
|
__ATTR(pmc2, 0600, show_pa6t_pmc2, store_pa6t_pmc2),
|
|
|
|
__ATTR(pmc3, 0600, show_pa6t_pmc3, store_pa6t_pmc3),
|
|
|
|
__ATTR(pmc4, 0600, show_pa6t_pmc4, store_pa6t_pmc4),
|
|
|
|
__ATTR(pmc5, 0600, show_pa6t_pmc5, store_pa6t_pmc5),
|
2007-09-05 10:09:06 +08:00
|
|
|
#ifdef CONFIG_DEBUG_KERNEL
|
2011-12-22 06:29:42 +08:00
|
|
|
__ATTR(hid0, 0600, show_hid0, store_hid0),
|
|
|
|
__ATTR(hid1, 0600, show_hid1, store_hid1),
|
|
|
|
__ATTR(hid4, 0600, show_hid4, store_hid4),
|
|
|
|
__ATTR(hid5, 0600, show_hid5, store_hid5),
|
|
|
|
__ATTR(ima0, 0600, show_ima0, store_ima0),
|
|
|
|
__ATTR(ima1, 0600, show_ima1, store_ima1),
|
|
|
|
__ATTR(ima2, 0600, show_ima2, store_ima2),
|
|
|
|
__ATTR(ima3, 0600, show_ima3, store_ima3),
|
|
|
|
__ATTR(ima4, 0600, show_ima4, store_ima4),
|
|
|
|
__ATTR(ima5, 0600, show_ima5, store_ima5),
|
|
|
|
__ATTR(ima6, 0600, show_ima6, store_ima6),
|
|
|
|
__ATTR(ima7, 0600, show_ima7, store_ima7),
|
|
|
|
__ATTR(ima8, 0600, show_ima8, store_ima8),
|
|
|
|
__ATTR(ima9, 0600, show_ima9, store_ima9),
|
|
|
|
__ATTR(imaat, 0600, show_imaat, store_imaat),
|
|
|
|
__ATTR(btcr, 0600, show_btcr, store_btcr),
|
|
|
|
__ATTR(pccr, 0600, show_pccr, store_pccr),
|
|
|
|
__ATTR(rpccr, 0600, show_rpccr, store_rpccr),
|
|
|
|
__ATTR(der, 0600, show_der, store_der),
|
|
|
|
__ATTR(mer, 0600, show_mer, store_mer),
|
|
|
|
__ATTR(ber, 0600, show_ber, store_ber),
|
|
|
|
__ATTR(ier, 0600, show_ier, store_ier),
|
|
|
|
__ATTR(sier, 0600, show_sier, store_sier),
|
|
|
|
__ATTR(siar, 0600, show_siar, store_siar),
|
|
|
|
__ATTR(tsr0, 0600, show_tsr0, store_tsr0),
|
|
|
|
__ATTR(tsr1, 0600, show_tsr1, store_tsr1),
|
|
|
|
__ATTR(tsr2, 0600, show_tsr2, store_tsr2),
|
|
|
|
__ATTR(tsr3, 0600, show_tsr3, store_tsr3),
|
2007-09-05 10:09:06 +08:00
|
|
|
#endif /* CONFIG_DEBUG_KERNEL */
|
2007-01-29 11:25:57 +08:00
|
|
|
};
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* HAS_PPC_PMC_PA6T */
|
|
|
|
#endif /* HAS_PPC_PMC_CLASSIC */
|
2007-01-29 11:25:57 +08:00
|
|
|
|
2013-06-25 03:30:09 +08:00
|
|
|
static void register_cpu_online(unsigned int cpu)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct cpu *c = &per_cpu(cpu_devices, cpu);
|
2011-12-22 06:29:42 +08:00
|
|
|
struct device *s = &c->dev;
|
|
|
|
struct device_attribute *attrs, *pmc_attrs;
|
2007-01-29 11:25:57 +08:00
|
|
|
int i, nattrs;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
2012-03-16 02:18:00 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_SMT))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(s, &dev_attr_smt_snooze_delay);
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* PMC stuff */
|
2007-01-29 11:25:57 +08:00
|
|
|
switch (cur_cpu_spec->pmc_type) {
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef HAS_PPC_PMC_IBM
|
2007-01-29 11:25:57 +08:00
|
|
|
case PPC_PMC_IBM:
|
|
|
|
attrs = ibm_common_attrs;
|
2011-12-22 06:29:42 +08:00
|
|
|
nattrs = sizeof(ibm_common_attrs) / sizeof(struct device_attribute);
|
2008-08-18 12:23:51 +08:00
|
|
|
pmc_attrs = classic_pmc_attrs;
|
2007-01-29 11:25:57 +08:00
|
|
|
break;
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* HAS_PPC_PMC_IBM */
|
|
|
|
#ifdef HAS_PPC_PMC_G4
|
|
|
|
case PPC_PMC_G4:
|
|
|
|
attrs = g4_common_attrs;
|
2011-12-22 06:29:42 +08:00
|
|
|
nattrs = sizeof(g4_common_attrs) / sizeof(struct device_attribute);
|
2008-08-18 12:23:51 +08:00
|
|
|
pmc_attrs = classic_pmc_attrs;
|
|
|
|
break;
|
|
|
|
#endif /* HAS_PPC_PMC_G4 */
|
|
|
|
#ifdef HAS_PPC_PMC_PA6T
|
2007-01-29 11:25:57 +08:00
|
|
|
case PPC_PMC_PA6T:
|
|
|
|
/* PA Semi starts counting at PMC0 */
|
|
|
|
attrs = pa6t_attrs;
|
2011-12-22 06:29:42 +08:00
|
|
|
nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute);
|
2007-01-29 11:25:57 +08:00
|
|
|
pmc_attrs = NULL;
|
|
|
|
break;
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* HAS_PPC_PMC_PA6T */
|
2007-01-29 11:25:57 +08:00
|
|
|
default:
|
|
|
|
attrs = NULL;
|
|
|
|
nattrs = 0;
|
|
|
|
pmc_attrs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nattrs; i++)
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(s, &attrs[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-01-29 11:25:57 +08:00
|
|
|
if (pmc_attrs)
|
|
|
|
for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(s, &pmc_attrs[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_MMCRA))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(s, &dev_attr_mmcra);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-02 03:04:10 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_PURR)) {
|
|
|
|
if (!firmware_has_feature(FW_FEATURE_LPAR))
|
|
|
|
add_write_permission_dev_attr(&dev_attr_purr);
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(s, &dev_attr_purr);
|
2013-10-02 03:04:10 +08:00
|
|
|
}
|
2006-12-08 14:46:58 +08:00
|
|
|
|
2006-12-08 14:51:13 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_SPURR))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(s, &dev_attr_spurr);
|
2006-12-08 14:51:13 +08:00
|
|
|
|
2006-12-08 14:46:58 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_DSCR))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(s, &dev_attr_dscr);
|
2011-11-11 03:58:53 +08:00
|
|
|
|
|
|
|
if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2))
|
2012-01-08 04:03:30 +08:00
|
|
|
device_create_file(s, &dev_attr_pir);
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* CONFIG_PPC64 */
|
2008-07-27 13:24:55 +08:00
|
|
|
|
2013-12-17 16:17:02 +08:00
|
|
|
#ifdef CONFIG_PPC_FSL_BOOK3E
|
|
|
|
if (PVR_VER(cur_cpu_spec->pvr_value) == PVR_VER_E6500) {
|
|
|
|
device_create_file(s, &dev_attr_pw20_state);
|
|
|
|
device_create_file(s, &dev_attr_pw20_wait_time);
|
|
|
|
|
|
|
|
device_create_file(s, &dev_attr_altivec_idle);
|
|
|
|
device_create_file(s, &dev_attr_altivec_idle_wait_time);
|
|
|
|
}
|
|
|
|
#endif
|
2008-12-24 02:55:54 +08:00
|
|
|
cacheinfo_cpu_online(cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
static void unregister_cpu_online(unsigned int cpu)
|
|
|
|
{
|
|
|
|
struct cpu *c = &per_cpu(cpu_devices, cpu);
|
2011-12-22 06:29:42 +08:00
|
|
|
struct device *s = &c->dev;
|
|
|
|
struct device_attribute *attrs, *pmc_attrs;
|
2007-01-29 11:25:57 +08:00
|
|
|
int i, nattrs;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-07 09:14:10 +08:00
|
|
|
BUG_ON(!c->hotpluggable);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-11-16 19:44:42 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
2012-03-16 02:18:00 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_SMT))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_remove_file(s, &dev_attr_smt_snooze_delay);
|
2008-11-16 19:44:42 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* PMC stuff */
|
2007-01-29 11:25:57 +08:00
|
|
|
switch (cur_cpu_spec->pmc_type) {
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef HAS_PPC_PMC_IBM
|
2007-01-29 11:25:57 +08:00
|
|
|
case PPC_PMC_IBM:
|
|
|
|
attrs = ibm_common_attrs;
|
2011-12-22 06:29:42 +08:00
|
|
|
nattrs = sizeof(ibm_common_attrs) / sizeof(struct device_attribute);
|
2008-08-18 12:23:51 +08:00
|
|
|
pmc_attrs = classic_pmc_attrs;
|
|
|
|
break;
|
|
|
|
#endif /* HAS_PPC_PMC_IBM */
|
|
|
|
#ifdef HAS_PPC_PMC_G4
|
|
|
|
case PPC_PMC_G4:
|
|
|
|
attrs = g4_common_attrs;
|
2011-12-22 06:29:42 +08:00
|
|
|
nattrs = sizeof(g4_common_attrs) / sizeof(struct device_attribute);
|
2008-08-18 12:23:51 +08:00
|
|
|
pmc_attrs = classic_pmc_attrs;
|
2007-01-29 11:25:57 +08:00
|
|
|
break;
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* HAS_PPC_PMC_G4 */
|
|
|
|
#ifdef HAS_PPC_PMC_PA6T
|
2007-01-29 11:25:57 +08:00
|
|
|
case PPC_PMC_PA6T:
|
|
|
|
/* PA Semi starts counting at PMC0 */
|
|
|
|
attrs = pa6t_attrs;
|
2011-12-22 06:29:42 +08:00
|
|
|
nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute);
|
2007-01-29 11:25:57 +08:00
|
|
|
pmc_attrs = NULL;
|
|
|
|
break;
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* HAS_PPC_PMC_PA6T */
|
2007-01-29 11:25:57 +08:00
|
|
|
default:
|
|
|
|
attrs = NULL;
|
|
|
|
nattrs = 0;
|
|
|
|
pmc_attrs = NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-01-29 11:25:57 +08:00
|
|
|
for (i = 0; i < nattrs; i++)
|
2011-12-22 06:29:42 +08:00
|
|
|
device_remove_file(s, &attrs[i]);
|
2007-01-29 11:25:57 +08:00
|
|
|
|
|
|
|
if (pmc_attrs)
|
|
|
|
for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
|
2011-12-22 06:29:42 +08:00
|
|
|
device_remove_file(s, &pmc_attrs[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-18 12:23:51 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_MMCRA))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_remove_file(s, &dev_attr_mmcra);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-28 11:58:37 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_PURR))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_remove_file(s, &dev_attr_purr);
|
2006-12-08 14:46:58 +08:00
|
|
|
|
2006-12-08 14:51:13 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_SPURR))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_remove_file(s, &dev_attr_spurr);
|
2006-12-08 14:51:13 +08:00
|
|
|
|
2006-12-08 14:46:58 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_DSCR))
|
2011-12-22 06:29:42 +08:00
|
|
|
device_remove_file(s, &dev_attr_dscr);
|
2011-11-11 03:58:53 +08:00
|
|
|
|
|
|
|
if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2))
|
2012-01-08 04:03:30 +08:00
|
|
|
device_remove_file(s, &dev_attr_pir);
|
2008-08-18 12:23:51 +08:00
|
|
|
#endif /* CONFIG_PPC64 */
|
2008-07-27 13:24:55 +08:00
|
|
|
|
2013-12-17 16:17:02 +08:00
|
|
|
#ifdef CONFIG_PPC_FSL_BOOK3E
|
|
|
|
if (PVR_VER(cur_cpu_spec->pvr_value) == PVR_VER_E6500) {
|
|
|
|
device_remove_file(s, &dev_attr_pw20_state);
|
|
|
|
device_remove_file(s, &dev_attr_pw20_wait_time);
|
|
|
|
|
|
|
|
device_remove_file(s, &dev_attr_altivec_idle);
|
|
|
|
device_remove_file(s, &dev_attr_altivec_idle_wait_time);
|
|
|
|
}
|
|
|
|
#endif
|
2008-12-24 02:55:54 +08:00
|
|
|
cacheinfo_cpu_offline(cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-11-26 01:23:25 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
|
|
|
|
ssize_t arch_cpu_probe(const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
if (ppc_md.cpu_probe)
|
|
|
|
return ppc_md.cpu_probe(buf, count);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t arch_cpu_release(const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
if (ppc_md.cpu_release)
|
|
|
|
return ppc_md.cpu_release(buf, count);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
|
|
|
|
2013-06-25 03:30:09 +08:00
|
|
|
static int sysfs_cpu_notify(struct notifier_block *self,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long action, void *hcpu)
|
|
|
|
{
|
|
|
|
unsigned int cpu = (unsigned int)(long)hcpu;
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case CPU_ONLINE:
|
2007-05-09 17:35:10 +08:00
|
|
|
case CPU_ONLINE_FROZEN:
|
2005-04-17 06:20:36 +08:00
|
|
|
register_cpu_online(cpu);
|
|
|
|
break;
|
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
case CPU_DEAD:
|
2007-05-09 17:35:10 +08:00
|
|
|
case CPU_DEAD_FROZEN:
|
2005-04-17 06:20:36 +08:00
|
|
|
unregister_cpu_online(cpu);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-25 03:30:09 +08:00
|
|
|
static struct notifier_block sysfs_cpu_nb = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.notifier_call = sysfs_cpu_notify,
|
|
|
|
};
|
|
|
|
|
2006-10-25 00:31:24 +08:00
|
|
|
static DEFINE_MUTEX(cpu_mutex);
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
int cpu_add_dev_attr(struct device_attribute *attr)
|
2006-10-25 00:31:24 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
mutex_lock(&cpu_mutex);
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(get_cpu_device(cpu), attr);
|
2006-10-25 00:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&cpu_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-22 06:29:42 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpu_add_dev_attr);
|
2006-10-25 00:31:24 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
int cpu_add_dev_attr_group(struct attribute_group *attrs)
|
2006-10-25 00:31:24 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
2011-12-22 06:29:42 +08:00
|
|
|
struct device *dev;
|
2007-09-05 10:43:17 +08:00
|
|
|
int ret;
|
2006-10-25 00:31:24 +08:00
|
|
|
|
|
|
|
mutex_lock(&cpu_mutex);
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
2011-12-22 06:29:42 +08:00
|
|
|
dev = get_cpu_device(cpu);
|
|
|
|
ret = sysfs_create_group(&dev->kobj, attrs);
|
2007-09-05 10:43:17 +08:00
|
|
|
WARN_ON(ret != 0);
|
2006-10-25 00:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&cpu_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-22 06:29:42 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpu_add_dev_attr_group);
|
2006-10-25 00:31:24 +08:00
|
|
|
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
void cpu_remove_dev_attr(struct device_attribute *attr)
|
2006-10-25 00:31:24 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
mutex_lock(&cpu_mutex);
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
2011-12-22 06:29:42 +08:00
|
|
|
device_remove_file(get_cpu_device(cpu), attr);
|
2006-10-25 00:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&cpu_mutex);
|
|
|
|
}
|
2011-12-22 06:29:42 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpu_remove_dev_attr);
|
2006-10-25 00:31:24 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
void cpu_remove_dev_attr_group(struct attribute_group *attrs)
|
2006-10-25 00:31:24 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
2011-12-22 06:29:42 +08:00
|
|
|
struct device *dev;
|
2006-10-25 00:31:24 +08:00
|
|
|
|
|
|
|
mutex_lock(&cpu_mutex);
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
2011-12-22 06:29:42 +08:00
|
|
|
dev = get_cpu_device(cpu);
|
|
|
|
sysfs_remove_group(&dev->kobj, attrs);
|
2006-10-25 00:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&cpu_mutex);
|
|
|
|
}
|
2011-12-22 06:29:42 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpu_remove_dev_attr_group);
|
2006-10-25 00:31:24 +08:00
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* NUMA stuff */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
static void register_nodes(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2006-06-27 17:53:38 +08:00
|
|
|
for (i = 0; i < MAX_NUMNODES; i++)
|
|
|
|
register_one_node(i);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-05-02 03:16:12 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
int sysfs_add_device_to_node(struct device *dev, int nid)
|
2006-05-02 03:16:12 +08:00
|
|
|
{
|
2012-12-12 08:00:56 +08:00
|
|
|
struct node *node = node_devices[nid];
|
2011-12-22 06:48:43 +08:00
|
|
|
return sysfs_create_link(&node->dev.kobj, &dev->kobj,
|
2006-05-02 03:16:12 +08:00
|
|
|
kobject_name(&dev->kobj));
|
|
|
|
}
|
2007-07-05 17:35:33 +08:00
|
|
|
EXPORT_SYMBOL_GPL(sysfs_add_device_to_node);
|
2006-05-02 03:16:12 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
void sysfs_remove_device_from_node(struct device *dev, int nid)
|
2006-05-02 03:16:12 +08:00
|
|
|
{
|
2012-12-12 08:00:56 +08:00
|
|
|
struct node *node = node_devices[nid];
|
2011-12-22 06:48:43 +08:00
|
|
|
sysfs_remove_link(&node->dev.kobj, kobject_name(&dev->kobj));
|
2006-05-02 03:16:12 +08:00
|
|
|
}
|
2007-07-05 17:35:33 +08:00
|
|
|
EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node);
|
2006-05-02 03:16:12 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
|
|
|
static void register_nodes(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2006-05-02 03:16:12 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Only valid if CPU is present. */
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t show_physical_id(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-12-22 06:29:42 +08:00
|
|
|
struct cpu *cpu = container_of(dev, struct cpu, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->dev.id));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-12-22 06:29:42 +08:00
|
|
|
static DEVICE_ATTR(physical_id, 0444, show_physical_id, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int __init topology_init(void)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
register_nodes();
|
2014-03-11 04:36:31 +08:00
|
|
|
|
|
|
|
cpu_notifier_register_begin();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-29 06:50:51 +08:00
|
|
|
for_each_possible_cpu(cpu) {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cpu *c = &per_cpu(cpu_devices, cpu);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For now, we just see if the system supports making
|
|
|
|
* the RTAS calls for CPU hotplug. But, there may be a
|
|
|
|
* more comprehensive way to do this for an individual
|
|
|
|
* CPU. For instance, the boot cpu might never be valid
|
|
|
|
* for hotplugging.
|
|
|
|
*/
|
2006-12-07 09:14:10 +08:00
|
|
|
if (ppc_md.cpu_die)
|
|
|
|
c->hotpluggable = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-07 09:14:10 +08:00
|
|
|
if (cpu_online(cpu) || c->hotpluggable) {
|
[PATCH] node hotplug: register cpu: remove node struct
With Goto-san's patch, we can add new pgdat/node at runtime. I'm now
considering node-hot-add with cpu + memory on ACPI.
I found acpi container, which describes node, could evaluate cpu before
memory. This means cpu-hot-add occurs before memory hot add.
In most part, cpu-hot-add doesn't depend on node hot add. But register_cpu(),
which creates symbolic link from node to cpu, requires that node should be
onlined before register_cpu(). When a node is onlined, its pgdat should be
there.
This patch-set holds off creating symbolic link from node to cpu
until node is onlined.
This removes node arguments from register_cpu().
Now, register_cpu() requires 'struct node' as its argument. But the array of
struct node is now unified in driver/base/node.c now (By Goto's node hotplug
patch). We can get struct node in generic way. So, this argument is not
necessary now.
This patch also guarantees add cpu under node only when node is onlined. It
is necessary for node-hot-add vs. cpu-hot-add patch following this.
Moreover, register_cpu calculates cpu->node_id by cpu_to_node() without regard
to its 'struct node *root' argument. This patch removes it.
Also modify callers of register_cpu()/unregister_cpu, whose args are changed
by register-cpu-remove-node-struct patch.
[Brice.Goglin@ens-lyon.org: fix it]
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Brice Goglin <Brice.Goglin@ens-lyon.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-27 17:53:41 +08:00
|
|
|
register_cpu(c, cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
device_create_file(&c->dev, &dev_attr_physical_id);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cpu_online(cpu))
|
|
|
|
register_cpu_online(cpu);
|
|
|
|
}
|
2014-03-11 04:36:31 +08:00
|
|
|
|
|
|
|
__register_cpu_notifier(&sysfs_cpu_nb);
|
|
|
|
|
|
|
|
cpu_notifier_register_done();
|
|
|
|
|
2011-03-02 23:18:48 +08:00
|
|
|
#ifdef CONFIG_PPC64
|
|
|
|
sysfs_create_dscr_default();
|
|
|
|
#endif /* CONFIG_PPC64 */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-05-03 01:11:49 +08:00
|
|
|
subsys_initcall(topology_init);
|