Re: [PATCH v2 08/11] powerpc/perf: add support for the hv gpci (get performance counter info) interface

2014-02-25 Thread Cody P Schafer

On 02/24/2014 07:33 PM, Michael Ellerman wrote:

On Fri, 2014-14-02 at 22:02:12 UTC, Cody P Schafer wrote:

This provides a basic link between perf and hv_gpci. Notably, it does
not yet support transactions and does not list any events (they can
still be manually composed).


Can you explain how the HV_CAPS stuff ends up looking.

I'm not against adding it, but I'd like to understand how we expect it to be
used a bit better.


It's just a quick mechanism for me to expose some relevant information 
to userspace via sysfs using the hv_perf_caps_get() function's returned 
data. Documentation for this sysfs interface (and the rest) is in a 
later patch.
I don't expect any more uses to show up unless the firmware decides to 
add another capability bit (in which case I'll want to expose it as well).



diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
new file mode 100644
index 000..1f5d96d
--- /dev/null
+++ b/arch/powerpc/perf/hv-gpci.c
+
+static struct pmu h_gpci_pmu = {
+   .task_ctx_nr = perf_invalid_context,
+
+   .name = hv_gpci,
+   .attr_groups = attr_groups,
+   .event_init  = h_gpci_event_init,
+   .add = h_gpci_event_add,
+   .del = h_gpci_event_del,

 = h_gpci_event_stop,


+   .start   = h_gpci_event_start,
+   .stop= h_gpci_event_stop,
+   .read= h_gpci_event_read,

 = h_gpci_event_update


+   .event_idx = perf_swevent_event_idx,
+};


whoops, thought I had fixed those 2 already.

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH v2 08/11] powerpc/perf: add support for the hv gpci (get performance counter info) interface

2014-02-24 Thread Michael Ellerman
On Fri, 2014-14-02 at 22:02:12 UTC, Cody P Schafer wrote:
 This provides a basic link between perf and hv_gpci. Notably, it does
 not yet support transactions and does not list any events (they can
 still be manually composed).

Can you explain how the HV_CAPS stuff ends up looking.

I'm not against adding it, but I'd like to understand how we expect it to be
used a bit better.

cheers

 diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
 new file mode 100644
 index 000..1f5d96d
 --- /dev/null
 +++ b/arch/powerpc/perf/hv-gpci.c
 +
 +static struct pmu h_gpci_pmu = {
 + .task_ctx_nr = perf_invalid_context,
 +
 + .name = hv_gpci,
 + .attr_groups = attr_groups,
 + .event_init  = h_gpci_event_init,
 + .add = h_gpci_event_add,
 + .del = h_gpci_event_del,
 = h_gpci_event_stop,

 + .start   = h_gpci_event_start,
 + .stop= h_gpci_event_stop,
 + .read= h_gpci_event_read,
 = h_gpci_event_update

 + .event_idx = perf_swevent_event_idx,
 +};


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v2 08/11] powerpc/perf: add support for the hv gpci (get performance counter info) interface

2014-02-14 Thread Cody P Schafer
This provides a basic link between perf and hv_gpci. Notably, it does
not yet support transactions and does not list any events (they can
still be manually composed).

Signed-off-by: Cody P Schafer c...@linux.vnet.ibm.com
---
 arch/powerpc/perf/hv-gpci.c | 290 
 1 file changed, 290 insertions(+)
 create mode 100644 arch/powerpc/perf/hv-gpci.c

diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
new file mode 100644
index 000..1f5d96d
--- /dev/null
+++ b/arch/powerpc/perf/hv-gpci.c
@@ -0,0 +1,290 @@
+/*
+ * Hypervisor supplied gpci (get performance counter info) performance
+ * counter support
+ *
+ * Author: Cody P Schafer c...@linux.vnet.ibm.com
+ * Copyright 2014 IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+#define pr_fmt(fmt) hv-gpci:  fmt
+
+#include linux/init.h
+#include linux/perf_event.h
+#include asm/firmware.h
+#include asm/hvcall.h
+#include asm/io.h
+
+#include hv-gpci.h
+#include hv-common.h
+
+PMU_RANGE_ATTR(request, config, 0, 31); /* u32 */
+PMU_RANGE_ATTR(starting_index, config, 32, 63); /* u32 */
+PMU_RANGE_ATTR(secondary_index, config1, 0, 15); /* u16 */
+PMU_RANGE_ATTR(counter_info_version, config1, 16, 23); /* u8 */
+PMU_RANGE_ATTR(length, config1, 24, 31); /* u8, bytes of data (1-8) */
+PMU_RANGE_ATTR(offset, config1, 32, 63); /* u32, byte offset */
+
+static struct attribute *format_attrs[] = {
+   format_attr_request.attr,
+   format_attr_starting_index.attr,
+   format_attr_secondary_index.attr,
+   format_attr_counter_info_version.attr,
+
+   format_attr_offset.attr,
+   format_attr_length.attr,
+   NULL,
+};
+
+static struct attribute_group format_group = {
+   .name = format,
+   .attrs = format_attrs,
+};
+
+#define HV_CAPS_ATTR(_name, _format)   \
+static ssize_t _name##_show(struct device *dev,\
+   struct device_attribute *attr,  \
+   char *page) \
+{  \
+   struct hv_perf_caps caps;   \
+   unsigned long hret = hv_perf_caps_get(caps);   \
+   if (hret)   \
+   return -EIO;\
+   \
+   return sprintf(page, _format, caps._name);  \
+}  \
+static struct device_attribute hv_caps_attr_##_name = __ATTR_RO(_name)
+
+static ssize_t kernel_version_show(struct device *dev,
+  struct device_attribute *attr,
+  char *page)
+{
+   return sprintf(page, 0x%x\n, COUNTER_INFO_VERSION_CURRENT);
+}
+
+DEVICE_ATTR_RO(kernel_version);
+HV_CAPS_ATTR(version, 0x%x\n);
+HV_CAPS_ATTR(ga, %d\n);
+HV_CAPS_ATTR(expanded, %d\n);
+HV_CAPS_ATTR(lab, %d\n);
+HV_CAPS_ATTR(collect_privileged, %d\n);
+
+static struct attribute *interface_attrs[] = {
+   dev_attr_kernel_version.attr,
+   hv_caps_attr_version.attr,
+   hv_caps_attr_ga.attr,
+   hv_caps_attr_expanded.attr,
+   hv_caps_attr_lab.attr,
+   hv_caps_attr_collect_privileged.attr,
+   NULL,
+};
+
+static struct attribute_group interface_group = {
+   .name = interface,
+   .attrs = interface_attrs,
+};
+
+static const struct attribute_group *attr_groups[] = {
+   format_group,
+   interface_group,
+   NULL,
+};
+
+#define GPCI_MAX_DATA_BYTES \
+   (1024 - sizeof(struct hv_get_perf_counter_info_params))
+
+static unsigned long single_gpci_request(u32 req, u32 starting_index,
+   u16 secondary_index, u8 version_in, u32 offset, u8 length,
+   u64 *value)
+{
+   unsigned long ret;
+   size_t i;
+   u64 count;
+
+   struct {
+   struct hv_get_perf_counter_info_params params;
+   uint8_t bytes[GPCI_MAX_DATA_BYTES];
+   } __packed __aligned(sizeof(uint64_t)) arg = {
+   .params = {
+   .counter_request = cpu_to_be32(req),
+   .starting_index = cpu_to_be32(starting_index),
+   .secondary_index = cpu_to_be16(secondary_index),
+   .counter_info_version_in = version_in,
+   }
+   };
+
+   ret = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO,
+   virt_to_phys(arg), sizeof(arg));
+   if (ret) {
+   pr_devel(hcall failed: 0x%lx\n, ret);
+   return ret;
+   }
+
+   /*
+* we verify offset and length are within the zeroed buffer