Skip to contentSkip to conversation

PS3: Add logical performance monitor repository routines

PATCH Superseded Geoff Levand 2 participants 8 messages Jan 5, 2008 – Jan 6, 2008 1 message not in the archive

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 PS3: Add logical performance monitor repository routines

In reply to a message not in the archive

From: Takashi Yamamoto <[email protected]>

Add repository routines for the PS3 Logical Performance Monitor (lpm).

---
 arch/powerpc/platforms/ps3/platform.h   |    7 ++++
 arch/powerpc/platforms/ps3/repository.c |   48 ++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)
arch/powerpc/platforms/ps3/platform.h +6 -1
@@ -189,7 +189,7 @@ int ps3_repository_read_stor_dev_region(
 /* repository pu and memory info */
 
 int ps3_repository_read_num_pu(unsigned int *num_pu);
-int ps3_repository_read_ppe_id(unsigned int *pu_index, unsigned int *ppe_id);
+int ps3_repository_read_pu_id(unsigned int pu_index, u64 *pu_id);
 int ps3_repository_read_rm_base(unsigned int ppe_id, u64 *rm_base);
 int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size);
 int ps3_repository_read_region_total(u64 *region_total);
@@ -203,6 +203,11 @@ int ps3_repository_read_be_node_id(unsig
 int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq);
 int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq);
 
+/* repository performance monitor info */
+
+int ps3_repository_read_lpm_privileges(unsigned int be_index, u64 *lpar,
+	u64 *rights);
+
 /* repository 'Other OS' area */
 
 int ps3_repository_read_boot_dat_addr(u64 *lpar_addr);
arch/powerpc/platforms/ps3/repository.c +48 -0

54 lines not on this page · raw message

#2 lore raw

PATCH 2/3 PS3: Add logical performance monitor device support

In reply to a message not in the archive

Add PS3 logical performance monitor (lpm) device support to the PS3 system-bus and platform device registration routines.

---
 arch/powerpc/platforms/ps3/device-init.c |   95 ++++++++++++++++++++++++++++++-
 arch/powerpc/platforms/ps3/system-bus.c  |    5 +
 include/asm-powerpc/ps3.h                |    7 ++
 3 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/ps3/lpm.c
arch/powerpc/platforms/ps3/device-init.c +93 -0
@@ -30,6 +30,97 @@
 
 #include "platform.h"
 
+static int __init ps3_register_lpm_devices(void)
+{
+	int result;
+	unsigned int pu_count;
+	u64 tmp1;
+	u64 tmp2;
+	struct layout {
+		struct ps3_system_bus_device dev;
+	} *p;
+
+	pr_debug(" -> %s:%d\n", __func__, __LINE__);
+
+	p = kzalloc(sizeof(*p), GFP_KERNEL);
+	if (!p)
+		return -ENOMEM;
+
+	p->dev.match_id = PS3_MATCH_ID_LPM;
+	p->dev.dev_type = PS3_DEVICE_TYPE_LPM;
+
+	result = ps3_repository_read_num_pu(&pu_count);
+
+	if (result) {
+		pr_debug("%s:%d: ps3_repository_read_num_pu failed \n",
+			__func__, __LINE__);
+		goto fail_read_repo;
+	}
+
+	/* The current lpm driver only supports a single BE processor. */
+
+	if (pu_count > 1) {
+		pr_info("%s:%d: found %u BE processors, only one supported\n",
+			__func__, __LINE__, pu_count);
+	}
+
+	result = ps3_repository_read_pu_id(0, &p->dev.lpm.pu_id);
+
+	if (result) {
+		pr_debug("%s:%d: ps3_repository_read_pu_id failed \n",
+			__func__, __LINE__);
+		goto fail_read_repo;
+	}
+
+	result = ps3_repository_read_lpm_privileges(0, &tmp1,
+		&p->dev.lpm.rights);
+
+	if (result) {
+		pr_debug("%s:%d: ps3_repository_read_lpm_privleges failed \n",
+			__func__, __LINE__);
+		goto fail_read_repo;
+	}
+
+	lv1_get_logical_partition_id(&tmp2);
+
+	if (tmp1 != tmp2) {
+		pr_debug("%s:%d: wrong lpar\n",
+			__func__, __LINE__);
+		result = -1;
+		goto fail_rights;
+	}
+
+	if (!(p->dev.lpm.rights & PS3_LPM_RIGHTS_USE_LPM)) {
+		pr_debug("%s:%d: don't have rights to use lpm\n",
+			__func__, __LINE__);
+		result = -1;
+		goto fail_rights;
+	}
+
+	pr_debug("%s:%d: pu_id %lu, rights %lu(%lxh)\n",
+		__func__, __LINE__, p->dev.lpm.pu_id, p->dev.lpm.rights,
+		p->dev.lpm.rights);
+
+	result = ps3_system_bus_device_register(&p->dev);
+
+	if (result) {
+		pr_debug("%s:%d ps3_system_bus_device_register failed\n",
+			__func__, __LINE__);
+		goto fail_register;
+	}
+
+	pr_debug(" <- %s:%d\n", __func__, __LINE__);
+	return 0;
+
+
+fail_register:
+fail_rights:
+fail_read_repo:
+	kfree(p);
+	pr_debug(" <- %s:%d: failed\n", __func__, __LINE__);
+	return result;
+}
+
 /**
  * ps3_setup_gelic_device - Setup and register a gelic device instance.
  *
@@ -787,6 +878,8 @@ static int __init ps3_register_devices(v
 
 	ps3_register_sound_devices();
 
+	ps3_register_lpm_devices();
+
 	pr_debug(" <- %s:%d\n", __func__, __LINE__);
 	return 0;
 }
arch/powerpc/platforms/ps3/system-bus.c +5 -0
@@ -715,6 +715,7 @@ int ps3_system_bus_device_register(struc
 	static unsigned int dev_ioc0_count;
 	static unsigned int dev_sb_count;
 	static unsigned int dev_vuart_count;
+	static unsigned int dev_lpm_count;
 
 	if (!dev->core.parent)
 		dev->core.parent = &ps3_system_bus;
@@ -737,6 +738,10 @@ int ps3_system_bus_device_register(struc
 		snprintf(dev->core.bus_id, sizeof(dev->core.bus_id),
 			"vuart_%02x", ++dev_vuart_count);
 		break;
+	case PS3_DEVICE_TYPE_LPM:
+		snprintf(dev->core.bus_id, sizeof(dev->core.bus_id),
+			"lpm_%02x", ++dev_lpm_count);
+		break;
 	default:
 		BUG();
 	};
include/asm-powerpc/ps3.h +7 -0
@@ -317,6 +317,7 @@ enum ps3_match_id {
 	PS3_MATCH_ID_STOR_FLASH     = 8,
 	PS3_MATCH_ID_SOUND          = 9,
 	PS3_MATCH_ID_GRAPHICS       = 10,
+	PS3_MATCH_ID_LPM            = 11,
 };
 
 #define PS3_MODULE_ALIAS_EHCI           "ps3:1"
@@ -329,11 +330,13 @@ enum ps3_match_id {
 #define PS3_MODULE_ALIAS_STOR_FLASH     "ps3:8"
 #define PS3_MODULE_ALIAS_SOUND          "ps3:9"
 #define PS3_MODULE_ALIAS_GRAPHICS       "ps3:10"
+#define PS3_MODULE_ALIAS_LPM            "ps3:11"
 
 enum ps3_system_bus_device_type {
 	PS3_DEVICE_TYPE_IOC0 = 1,
 	PS3_DEVICE_TYPE_SB,
 	PS3_DEVICE_TYPE_VUART,
+	PS3_DEVICE_TYPE_LPM,
 };
 
 /**
@@ -350,6 +353,10 @@ struct ps3_system_bus_device {
 	struct ps3_dma_region *d_region;  /* SB, IOC0 */
 	struct ps3_mmio_region *m_region; /* SB, IOC0*/
 	unsigned int port_number;         /* VUART */
+	struct {                          /* LPM */
+		u64 pu_id;
+		u64 rights;
+	} lpm;
 
 /*	struct iommu_table *iommu_table; -- waiting for BenH's cleanups */
 	struct device core;
#5 lore raw

PATCH 3/3 PS3: Add logical performance monitor driver support

In reply to a message not in the archive

From: Takashi Yamamoto <[email protected]>

Add PS3 logical performance monitor (lpm) device driver.

The PS3's LV1 hypervisor provides a Logical Performance Monitor that abstarcts the Cell processor's performance monitor features for use by guest operating systems.

---
 arch/powerpc/platforms/ps3/Kconfig |   14 
 drivers/ps3/Makefile               |    1 
 drivers/ps3/ps3-lpm.c              | 1171 +++++++++++++++++++++++++++++++++++++
 include/asm-powerpc/ps3.h          |   37 +
 4 files changed, 1223 insertions(+)
 create mode 100644 arch/powerpc/platforms/ps3/ps3-lpm.c
arch/powerpc/platforms/ps3/Kconfig +14 -0
@@ -138,4 +138,18 @@ config PS3_FLASH
 	  be disabled on the kernel command line using "ps3flash=off", to
 	  not allocate this fixed buffer.
 
+config PS3_LPM
+	tristate "PS3 Logical Performance Monitor support"
+	depends on PPC_PS3
+	default n
+	help
+	  Include support for the PS3 Logical Performance Monitor.
+
+	  This support is required to use the logical performance monitor
+	  of the PS3's LV1 hypervisor.
+
+	  If you intend to use the advanced performance monitoring and
+	  profiling support of the Cell processor with programs like
+	  oprofile and perfmon, then say Y or M, otherwise say N.
+
 endmenu
drivers/ps3/Makefile +1 -0
@@ -4,3 +4,4 @@ ps3av_mod-objs		+= ps3av.o ps3av_cmd.o
 obj-$(CONFIG_PPC_PS3) += sys-manager-core.o
 obj-$(CONFIG_PS3_SYS_MANAGER) += ps3-sys-manager.o
 obj-$(CONFIG_PS3_STORAGE) += ps3stor_lib.o
+obj-$(CONFIG_PS3_LPM) += ps3-lpm.o
drivers/ps3/ps3-lpm.c new file +1171 -0

1,171 lines not on this page · raw message

include/asm-powerpc/ps3.h +37 -0
@@ -24,6 +24,7 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/device.h>
+#include "cell-pmu.h"
 
 union ps3_firmware_version {
 	u64 raw;
@@ -445,5 +446,41 @@ struct ps3_prealloc {
 extern struct ps3_prealloc ps3fb_videomemory;
 extern struct ps3_prealloc ps3flash_bounce_buffer;
 
+/* logical performance monitor */
+
+enum ps3_lpm_rights {
+	PS3_LPM_RIGHTS_USE_LPM = 1,
+};
+
+int ps3_lpm_open(void *tb_cache, u64 tb_cache_size, u64 tb_type);
+int ps3_lpm_close(void);
+void ps3_set_bookmark(u64 bookmark);
+void ps3_set_pm_bookmark(u64 tag, u64 incident, u64 th_id);
+u64 ps3_copy_trace_buffer(u64 offset, u64 size, void *to, int to_user);
+int ps3_set_signal(u64 rtas_signal_group, u8 signal_bit, u16 sub_unit,
+	u8 bus_word);
+
+u32 ps3_read_phys_ctr(u32 cpu, u32 phys_ctr);
+void ps3_write_phys_ctr(u32 cpu, u32 phys_ctr, u32 val);
+u32 ps3_read_ctr(u32 cpu, u32 ctr);
+void ps3_write_ctr(u32 cpu, u32 ctr, u32 val);
+
+u32 ps3_read_pm07_control(u32 cpu, u32 ctr);
+void ps3_write_pm07_control(u32 cpu, u32 ctr, u32 val);
+u32 ps3_read_pm(u32 cpu, enum pm_reg_name reg);
+void ps3_write_pm(u32 cpu, enum pm_reg_name reg, u32 val);
+
+u32 ps3_get_ctr_size(u32 cpu, u32 phys_ctr);
+void ps3_set_ctr_size(u32 cpu, u32 phys_ctr, u32 ctr_size);
+
+void ps3_enable_pm(u32 cpu);
+void ps3_disable_pm(u32 cpu);
+void ps3_enable_pm_interrupts(u32 cpu, u32 thread, u32 mask);
+void ps3_disable_pm_interrupts(u32 cpu);
+
+u32 ps3_get_and_clear_pm_interrupts(u32 cpu);
+void ps3_sync_irq(int node);
+u32 ps3_get_hw_thread_id(int cpu);
+u64 ps3_get_spe_id(void *arg);
 
 #endif
#3 lore raw

Re: [patch 2/3] PS3: Add logical performance monitor device support

In reply to Geoff Levand

T24gU2F0dXJkYXkgMDUgSmFudWFyeSAyMDA4LCBHZW9mZiBMZXZhbmQgd3JvdGU6Cj4gKyAgICAg ICBzdHJ1Y3QgbGF5b3V0IHsKPiArICAgICAgICAgICAgICAgc3RydWN0IHBzM19zeXN0ZW1fYnVz X2RldmljZSBkZXY7Cj4gKyAgICAgICB9ICpwOwoKV2hhdCdzIHRoZSBwb2ludCBvZiB0aGlzIGRh dGEgc3RydWN0dXJlPyBZb3UgZG9uJ3QgdXNlIHRoZQpzdHJ1Y3QgYW55d2hlcmUsIGFuZCBpdCBv bmx5IGhhcyBvbmUgbWVtYmVyLCBzbyB5b3UgY291bGQKanVzdCBkZWNsYXJlIHRoYXQgZGlyZWN0 bHkuCgo+ICugoKCgoKCgaWYgKHRtcDEgIT0gdG1wMikgewo+ICugoKCgoKCgoKCgoKCgoKBwcl9k ZWJ1ZygiJXM6JWQ6IHdyb25nIGxwYXJcbiIsCj4gK6CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgX19m dW5jX18sIF9fTElORV9fKTsKPiAroKCgoKCgoKCgoKCgoKCgcmVzdWx0ID0gLTE7Cj4gK6CgoKCg oKCgoKCgoKCgoGdvdG8gZmFpbF9yaWdodHM7Cj4gK6CgoKCgoKB9Cj4gKwo+ICugoKCgoKCgaWYg KCEocC0+ZGV2LmxwbS5yaWdodHMgJiBQUzNfTFBNX1JJR0hUU19VU0VfTFBNKSkgewo+ICugoKCg oKCgoKCgoKCgoKBwcl9kZWJ1ZygiJXM6JWQ6IGRvbid0IGhhdmUgcmlnaHRzIHRvIHVzZSBscG1c biIsCj4gK6CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgX19mdW5jX18sIF9fTElORV9fKTsKPiAroKCg oKCgoKCgoKCgoKCgcmVzdWx0ID0gLTE7Cj4gK6CgoKCgoKCgoKCgoKCgoGdvdG8gZmFpbF9yaWdo dHM7Cj4gK6CgoKCgoKB9Cj4gKwoKSSB0aGluayBfX2luaXQgZnVuY3Rpb25zIHNob3VsZCByZXR1 cm4gZXJyb3IgY29kZXMgbGlrZSAtRVBFUk0gb3IKLUVJTlZBTCwgbm90IG51bWVyaWMgLTEuCgpB cGFydCBmcm9tIHRoYXQsIHRoZSBwYXRjaCBsb29rcyBnb29kLgoKCUFybmQgPD48Cg==

#6 lore raw

Re: [patch 3/3] PS3: Add logical performance monitor driver support

In reply to Geoff Levand
Quoted 10 lines · Geoff Levand

From: Takashi Yamamoto <[email protected]>

Add PS3 logical performance monitor (lpm) device driver.

The PS3's LV1 hypervisor provides a Logical Performance Monitor that abstarcts the Cell processor's performance monitor features for use by guest operating systems.

Wow, great stuff!

One bit of information I'm missing in the description is what the users of this code are. Your Kconfig text mentions that can be used for both perfmon and oprofile. Are these, or one of them, currently under work as well?

arch/powerpc/platforms/ps3/Kconfig config PS3_FLASH · line 144

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +4 -0
@@ -138,4 +138,18 @@ config PS3_FLASH
 	  be disabled on the kernel command line using "ps3flash=off", to
 	  not allocate this fixed buffer.
 
+config PS3_LPM
+	tristate "PS3 Logical Performance Monitor support"
+	depends on PPC_PS3
+	default n

'default n' is redundant.

arch/powerpc/platforms/ps3/Kconfig config PS3_FLASH · line 154

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +10 -0
+	help
+	  Include support for the PS3 Logical Performance Monitor.
+
+	  This support is required to use the logical performance monitor
+	  of the PS3's LV1 hypervisor.
+
+	  If you intend to use the advanced performance monitoring and
+	  profiling support of the Cell processor with programs like
+	  oprofile and perfmon, then say Y or M, otherwise say N.
+

Should that be perfmon2 instead of perfmon?

I think once they high-level drivers are merged, it would make sense to autoselected by these, so the user doesn't have to read through the help text.

Quoted 28 lines
arch/powerpc/platforms/ps3/Kconfig +28 -0
+/**
+ * struct ps3_lpm_priv - private lpm device data.
+ *
+ * @mutex: Open/close mutex.
+ * @rights: The lpm rigths granted by the system policy module.
+ * @pu_id: The lv1 id of the BE prosessor for this lpm instance.
+ * @lpm_id: The lv1 id of this lpm instance.
+ * @outlet_id: The outlet created by lv1 for this lpm instance.
+ * @constructed: A flag indicating the lpm driver has been opened -- can we just use (lpm_id == ???)
+ * @tb_size: The lv1 trace buffer size
+ * @tb_cache: Trace buffer cache
+ * @tb_cache_internal: A flag indicating the trace buffer cache was allocated
+ *                     by the driver.
+ * @tb_cache: Trace buffer cache
+ * @sizeof_traced_data: Traced data size
+ * @sbd: the struct ps3_system_bus_device attached to this driver
+ */
+
+struct ps3_lpm_priv {
+	struct mutex mutex;
+	u64 rights;
+	u64 pu_id;
+	u64 lpm_id;
+	u64 outlet_id;
+	int constructed;
+	u64 tb_size;
+	void *tb_cache;
+	u64 tb_cache_size;

arch/powerpc/platforms/ps3/Kconfig config PS3_FLASH

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +10 -0
+	int tb_cache_internal;
+	u64 sizeof_traced_data;
+	u64 sizeof_total_copied_data;
+	u64 shadow_pm_control;
+	u64 shadow_pm_start_stop;
+	u64 shadow_pm_interval;
+	u64 shadow_group_control;
+	u64 shadow_debug_bus_control;
+	struct ps3_system_bus_device *sbd;
+};

Some of the members in this struct are not present in the comment, which is somewhat confusing.

arch/powerpc/platforms/ps3/Kconfig

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +10 -0
+
+/**
+ * lpm_priv - Static instance of the lpm data.
+ *
+ * Since the exported routines don't support the notion of a device
+ * instance we need to hold the instance in this static variable
+ * and only allow at most one instance to be created.
+ */
+
+static struct ps3_lpm_priv *lpm_priv;

Hmmm, my gut feeling about this is that it would be better to actually pass this around through the exported functions. That would also provide some arbitration between the possible users, e.g. oprofile would get -EBUSY when asking for the ps3_lpm while perfmon2 is already active.

arch/powerpc/platforms/ps3/Kconfig

Quoted 2 lines
arch/powerpc/platforms/ps3/Kconfig +2 -0
+/* bookmark spr address */
+#define BOOKMARK_SPR_ADDR 1020

This one belongs to asm/reg.h and should be named SRPN_BKMK.

arch/powerpc/platforms/ps3/Kconfig

Quoted 5 lines
arch/powerpc/platforms/ps3/Kconfig +5 -0
+inline u32 ps3_get_hw_thread_id(int cpu)
+{
+	return cpu;
+}
+EXPORT_SYMBOL_GPL(ps3_get_hw_thread_id);

The 'inline' is bogus, as that doesn't work across exported functions and you are not using the function in this file.

Should you perhaps return hard_smp_processor_id(cpu) instead of cpu here?

Quoted 26 lines
arch/powerpc/platforms/ps3/Kconfig +26 -0
+/**
+ * _ps3_copy_trace_buffer - Copy the trace buffer.
+ */
+
+static u64 _ps3_copy_trace_buffer(u64 offset, u64 size, u64 *to, int to_user)
+{
+	int result;
+	u64 sizeof_copied_data;
+
+	if (offset >= lpm_priv->sizeof_traced_data)
+		return 0;
+
+	result = lv1_copy_lpm_trace_buffer(lpm_priv->lpm_id, offset, size,
+					&sizeof_copied_data);
+	if (result) {
+		dev_err(sbd_core(), "%s:%u: lv1_copy_lpm_trace_buffer failed: "
+			"offset 0x%lx, size 0x%lx: %s\n", __func__, __LINE__,
+			offset, size, ps3_result(result));
+		return 0;
+	}
+
+	if (to_user) {
+		result = copy_to_user((void __user *)to, lpm_priv->tb_cache,
+				      sizeof_copied_data);
+		if (result) {
+			dev_err(sbd_core(), "%s:%u: copy_to_user() error. "

arch/powerpc/platforms/ps3/Kconfig

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +10 -0
+				"offset:0x%lx size:0x%lx dest:0x%p src:0x%p\n",
+				__func__, __LINE__, offset, sizeof_copied_data,
+				to, lpm_priv->tb_cache);
+			return 0;
+		}
+	} else
+		memcpy(to, lpm_priv->tb_cache, sizeof_copied_data);
+
+	return sizeof_copied_data;
+}

I don't like how this functions uses the same argument for kernel and user pointers, this will cause sparse warnings in the code using it. How about making this two separate functions?

Quoted 7 lines
arch/powerpc/platforms/ps3/Kconfig +7 -0
+int ps3_lpm_open(void *tb_cache, u64 tb_cache_size, u64 tb_type)
+{
+	int result;
+	u64 cbe_node_id;
+	u64 tb_size;
+	u64 ctrl_opt;
+	u64 tb_cache_lpar_addr;

arch/powerpc/platforms/ps3/Kconfig

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +10 -0
+	u64 lpm_id;
+	u64 outlet_id;
+	u64 used_tb_size;
+
+	if (!lpm_priv) {
+		BUG();
+		return -ENODEV;
+	}
+
+	mutex_lock(&lpm_priv->mutex);

This mutex is documented as the 'open/close' mutex and you use it to prevent concurrent execution of the open and close functions. However, it's unclear what data structures are actually protected by it.

I think this is the result of unusual lifetime rules for the lpm_priv object, which I already mentioned above.

	Arnd <><
#4 lore raw

Re: [patch 2/3] PS3: Add logical performance monitor device support

In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

arch/powerpc/platforms/ps3/device-init.c line 41

Quoted 3 lines · Geoff Levand
arch/powerpc/platforms/ps3/device-init.c +3 -0
+       struct layout {
+               struct ps3_system_bus_device dev;
+       } *p;

What's the point of this data structure? You don't use the struct anywhere, and it only has one member, so you could just declare that directly.

Yes, this code was just cut and pasted from a device that had more members.

Quoted 9 lines
Quoted 9 lines
arch/powerpc/platforms/ps3/device-init.c +9 -0
+       if (tmp1 != tmp2) {
+               pr_debug("%s:%d: wrong lpar\n",
+                       __func__, __LINE__);
+               result = -1;
+               goto fail_rights;
+       }
+
+       if (!(p->dev.lpm.rights & PS3_LPM_RIGHTS_USE_LPM)) {
+               pr_debug("%s:%d: don't have rights to use lpm\n",
Quoted 8 lines

arch/powerpc/platforms/ps3/device-init.c line 92

Quoted 5 lines
arch/powerpc/platforms/ps3/device-init.c +5 -0
+                       __func__, __LINE__);
+               result = -1;
+               goto fail_rights;
+       }
+

I think __init functions should return error codes like -EPERM or -EINVAL, not numeric -1.

I'll fix it in the next post.

-Geoff

#7 lore raw

Re: [patch 3/3] PS3: Add logical performance monitor driver support

In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann
Quoted 10 lines · Geoff Levand

From: Takashi Yamamoto <[email protected]>

Add PS3 logical performance monitor (lpm) device driver.

The PS3's LV1 hypervisor provides a Logical Performance Monitor that abstarcts the Cell processor's performance monitor features for use by guest operating systems.

Quoted 6 lines

Wow, great stuff!

One bit of information I'm missing in the description is what the users of this code are. Your Kconfig text mentions that can be used for both perfmon and oprofile. Are these, or one of them, currently under work as well?

Yes, perfmon2 support is somewhat working, but still under development. I added the perfmon2 patches into ps3-linux.git, so the easy way would be to use those kernel sources. This info written before I merged perfmon2 into ps3-linux.git, but does give some info on how to use it:

http://www.kernel.org/pub/linux/kernel/people/geoff/cell/CELL-Linux-CL_20071220-ADDON/doc/ApplicationProgrammingEnvironment.html

I just started to work on the kernel oprofile support, but it is not usable yet. Any contributions would be welcome. Currently the patch is just something hacked up to use for testing:

http://git.kernel.org/?p=linux/kernel/git/geoff/ps3-linux-patches.git;a=blob;f=ps3-wip/ps3-oprofile.patch;hb=HEAD

Quoted 13 lines

arch/powerpc/platforms/ps3/Kconfig config PS3_FLASH · line 144

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +4 -0
@@ -138,4 +138,18 @@ config PS3_FLASH
 	  be disabled on the kernel command line using "ps3flash=off", to
 	  not allocate this fixed buffer.
 
+config PS3_LPM
+	tristate "PS3 Logical Performance Monitor support"
+	depends on PPC_PS3
+	default n

'default n' is redundant.

Quoted 12 lines

arch/powerpc/platforms/ps3/Kconfig config PS3_FLASH · line 154

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +10 -0
+	help
+	  Include support for the PS3 Logical Performance Monitor.
+
+	  This support is required to use the logical performance monitor
+	  of the PS3's LV1 hypervisor.
+
+	  If you intend to use the advanced performance monitoring and
+	  profiling support of the Cell processor with programs like
+	  oprofile and perfmon, then say Y or M, otherwise say N.
+

Should that be perfmon2 instead of perfmon?

Yes.

Quoted 3 lines

I think once they high-level drivers are merged, it would make sense to autoselected by these, so the user doesn't have to read through the help text.

Yes, many things can be improved.

Quoted 33 lines
Quoted 33 lines
arch/powerpc/platforms/ps3/Kconfig +33 -0
+/**
+ * struct ps3_lpm_priv - private lpm device data.
+ *
+ * @mutex: Open/close mutex.
+ * @rights: The lpm rigths granted by the system policy module.
+ * @pu_id: The lv1 id of the BE prosessor for this lpm instance.
+ * @lpm_id: The lv1 id of this lpm instance.
+ * @outlet_id: The outlet created by lv1 for this lpm instance.
+ * @constructed: A flag indicating the lpm driver has been opened -- can we just use (lpm_id == ???)
+ * @tb_size: The lv1 trace buffer size
+ * @tb_cache: Trace buffer cache
+ * @tb_cache_internal: A flag indicating the trace buffer cache was allocated
+ *                     by the driver.
+ * @tb_cache: Trace buffer cache
+ * @sizeof_traced_data: Traced data size
+ * @sbd: the struct ps3_system_bus_device attached to this driver
+ */
+
+struct ps3_lpm_priv {
+	struct mutex mutex;
+	u64 rights;
+	u64 pu_id;
+	u64 lpm_id;
+	u64 outlet_id;
+	int constructed;
+	u64 tb_size;
+	void *tb_cache;
+	u64 tb_cache_size;
+	int tb_cache_internal;
+	u64 sizeof_traced_data;
+	u64 sizeof_total_copied_data;
+	u64 shadow_pm_control;
+	u64 shadow_pm_start_stop;
Quoted 8 lines

arch/powerpc/platforms/ps3/Kconfig

Quoted 5 lines
arch/powerpc/platforms/ps3/Kconfig +5 -0
+	u64 shadow_pm_interval;
+	u64 shadow_group_control;
+	u64 shadow_debug_bus_control;
+	struct ps3_system_bus_device *sbd;
+};

Some of the members in this struct are not present in the comment, which is somewhat confusing.

I'll add those in for the next post.

Quoted 5 lines
Quoted 5 lines
arch/powerpc/platforms/ps3/Kconfig +5 -0
+
+/**
+ * lpm_priv - Static instance of the lpm data.
+ *
+ * Since the exported routines don't support the notion of a device
Quoted 8 lines

arch/powerpc/platforms/ps3/Kconfig

Quoted 5 lines

+ * instance we need to hold the instance in this static variable
+ * and only allow at most one instance to be created.
+ */

arch/powerpc/platforms/ps3/Kconfig +2 -0
+
+static struct ps3_lpm_priv *lpm_priv;

Hmmm, my gut feeling about this is that it would be better to actually pass this around through the exported functions.

Yes, I feel the same way. In general, I think we need to make a better platform abstraction of the processor's pm functions. That would include support for platform specific instance data, RTAS for blade, lpm for ps3.

Quoted 4 lines

That would also
provide some arbitration between the possible users, e.g. oprofile would get -EBUSY when asking for the ps3_lpm while perfmon2 is already active.

That already happens in ps3_lpm_open(), using the lpm_priv.constructed variable.

Quoted 11 lines

arch/powerpc/platforms/ps3/Kconfig

Quoted 5 lines
arch/powerpc/platforms/ps3/Kconfig +5 -0
+inline u32 ps3_get_hw_thread_id(int cpu)
+{
+	return cpu;
+}
+EXPORT_SYMBOL_GPL(ps3_get_hw_thread_id);

The 'inline' is bogus, as that doesn't work across exported functions and you are not using the function in this file.

Should you perhaps return hard_smp_processor_id(cpu) instead of cpu here?

Yes, good point.

Quoted 32 lines
Quoted 32 lines
arch/powerpc/platforms/ps3/Kconfig +32 -0
+/**
+ * _ps3_copy_trace_buffer - Copy the trace buffer.
+ */
+
+static u64 _ps3_copy_trace_buffer(u64 offset, u64 size, u64 *to, int to_user)
+{
+	int result;
+	u64 sizeof_copied_data;
+
+	if (offset >= lpm_priv->sizeof_traced_data)
+		return 0;
+
+	result = lv1_copy_lpm_trace_buffer(lpm_priv->lpm_id, offset, size,
+					&sizeof_copied_data);
+	if (result) {
+		dev_err(sbd_core(), "%s:%u: lv1_copy_lpm_trace_buffer failed: "
+			"offset 0x%lx, size 0x%lx: %s\n", __func__, __LINE__,
+			offset, size, ps3_result(result));
+		return 0;
+	}
+
+	if (to_user) {
+		result = copy_to_user((void __user *)to, lpm_priv->tb_cache,
+				      sizeof_copied_data);
+		if (result) {
+			dev_err(sbd_core(), "%s:%u: copy_to_user() error. "
+				"offset:0x%lx size:0x%lx dest:0x%p src:0x%p\n",
+				__func__, __LINE__, offset, sizeof_copied_data,
+				to, lpm_priv->tb_cache);
+			return 0;
+		}
+	} else
Quoted 8 lines

arch/powerpc/platforms/ps3/Kconfig

Quoted 4 lines
arch/powerpc/platforms/ps3/Kconfig +4 -0
+		memcpy(to, lpm_priv->tb_cache, sizeof_copied_data);
+
+	return sizeof_copied_data;
+}

I don't like how this functions uses the same argument for kernel and user pointers, this will cause sparse warnings in the code using it. How about making this two separate functions?

OK, good point, I'll consider it.

Quoted 23 lines
Quoted 7 lines
arch/powerpc/platforms/ps3/Kconfig +7 -0
+int ps3_lpm_open(void *tb_cache, u64 tb_cache_size, u64 tb_type)
+{
+	int result;
+	u64 cbe_node_id;
+	u64 tb_size;
+	u64 ctrl_opt;
+	u64 tb_cache_lpar_addr;

arch/powerpc/platforms/ps3/Kconfig

Quoted 10 lines
arch/powerpc/platforms/ps3/Kconfig +10 -0
+	u64 lpm_id;
+	u64 outlet_id;
+	u64 used_tb_size;
+
+	if (!lpm_priv) {
+		BUG();
+		return -ENODEV;
+	}
+
+	mutex_lock(&lpm_priv->mutex);

This mutex is documented as the 'open/close' mutex and you use it to prevent concurrent execution of the open and close functions. However, it's unclear what data structures are actually protected by it.

Quoted 2 lines

I think this is the result of unusual lifetime rules for the lpm_priv object, which I already mentioned above.

Yes, we really just need to use the mutex to allow only a single instance, and so do a mutex_trylock() in ps3_lpm_open() and return -EBUSY on fail, and then a mutex_unlock() in ps3_lpm_close().

-Geoff

#8 lore raw

Re: [patch 3/3] PS3: Add logical performance monitor driver support

Quoted 6 lines · Geoff Levand
Quoted 6 lines

This mutex is documented as the 'open/close' mutex and you use it to prevent concurrent execution of the open and close functions. However, it's unclear what data structures are actually protected by it.

Quoted 6 lines
Quoted 2 lines

I think this is the result of unusual lifetime rules for the lpm_priv object, which I already mentioned above.

Yes, we really just need to use the mutex to allow only a single instance, and so do a mutex_trylock() in ps3_lpm_open() and return -EBUSY on fail, and then a mutex_unlock() in ps3_lpm_close().

A simple atomic_test_and_set in open() should do the job just as well then.

	Arnd <><