IMC Instrumentation Support
Subsystems (2)
v11 cover IMC Instrumentation Support
Power9 has In-Memory-Collection (IMC) infrastructure which contains various Performance Monitoring Units (PMUs) at Nest level (these are on-chip but off-core), Core level and Thread level.
The Nest PMU counters are handled by a Nest IMC microcode which runs in the OCC (On-Chip Controller) complex. The microcode collects the counter data and moves the nest IMC counter data to memory.
The Core and Thread IMC PMU counters are handled in the core. Core level PMU counters give us the IMC counters' data per core and thread level PMU counters give us the IMC counters' data per CPU thread.
This patchset enables the nest IMC, core IMC and thread IMC PMUs and is based on the initial work done by Madhavan Srinivasan. "Nest Instrumentation Support" :
https://lists.ozlabs.org/pipermail/linuxppc-dev/2015-August/132078.html
v1 for this patchset can be found here :
https://lwn.net/Articles/705475/
Nest events:
Per-chip nest instrumentation provides various per-chip metrics such as memory, powerbus, Xlink and Alink bandwidth.
Core events:
Per-core IMC instrumentation provides various per-core metrics such as non-idle cycles, non-idle instructions, various cache and memory related metrics etc.
Thread events:
All the events for thread level are same as core level with the difference being in the domain. These are per-cpu metrics.
PMU Events' Information:
OPAL obtains the IMC PMU and event information from the IMC Catalog and passes on to the kernel via the device tree. The events' information contains :
- Event name
- Event Offset
- Event description
and, maybe :
- Event scale
- Event unit
Some PMUs may have a common scale and unit values for all their supported events. For those cases, the scale and unit properties for those events must be inherited from the PMU.
The event offset in the memory is where the counter data gets accumulated.
The OPAL-side patches are upstream :
https://lists.ozlabs.org/pipermail/skiboot/2017-June/007885.html
The kernel discovers the IMC counters information in the device tree at the "imc-counters" device node which has a compatible field "ibm,opal-in-memory-counters".
Parsing of the Events' information:
To parse the IMC PMUs and events information, the kernel has to discover the "imc-counters" node and walk through the pmu and event nodes.
Here is an excerpt of the dt showing the imc-counters with mcs (nest), core and thread node:
/dts-v1/;
/ {
name = "";
compatible = "ibm,opal-in-memory-counters";
#address-cells = <0x1>;
#size-cells = <0x1>;
version-id = "";
NEST_MCS: nest-mcs-events {
#address-cells = <0x1>;
#size-cells = <0x1>;
event at 0 {
event-name = "RRTO_QFULL_NO_DISP" ;
reg = <0x0 0x8>;
desc = "RRTO not dispatched in MCS0 due to capacity - pulses once for each time a valid RRTO op is not dispatched due to a command list full condition" ;
};
event at 8 {
event-name = "WRTO_QFULL_NO_DISP" ;
reg = <0x8 0x8>;
desc = "WRTO not dispatched in MCS0 due to capacity - pulses once for each time a valid WRTO op is not dispatched due to a command list full condition" ;
};
[...]
mcs01 {
compatible = "ibm,imc-counters";
events-prefix = "PM_MCS01_";
unit = "";
scale = "";
reg = <0x118 0x8>;
events = < &NEST_MCS >;
type = <0x10>;
};
mcs23 {
compatible = "ibm,imc-counters";
events-prefix = "PM_MCS23_";
unit = "";
scale = "";
reg = <0x198 0x8>;
events = < &NEST_MCS >;
type = <0x10>;
};
[...]
CORE_EVENTS: core-events {
#address-cells = <0x1>;
#size-cells = <0x1>;
event at e0 {
event-name = "0THRD_NON_IDLE_PCYC" ;
reg = <0xe0 0x8>;
desc = "The number of processor cycles when all threads are idle" ;
};
event at 120 {
event-name = "1THRD_NON_IDLE_PCYC" ;
reg = <0x120 0x8>;
desc = "The number of processor cycles when exactly one SMT thread is executing non-idle code" ;
};
[...]
core {
compatible = "ibm,imc-counters";
events-prefix = "CPM_";
unit = "";
scale = "";
reg = <0x0 0x8>;
events = < &CORE_EVENTS >;
type = <0x4>;
};
thread {
compatible = "ibm,imc-counters";
events-prefix = "CPM_";
unit = "";
scale = "";
reg = <0x0 0x8>;
events = < &CORE_EVENTS >;
type = <0x1>;
};
};Quoted 1 line
From the device tree, the kernel parses the PMUs and their events'
information.
After parsing the IMC PMUs and their events, the PMUs and their attributes are registered in the kernel.
This patchset (patches 9 and 10) configure the thread level IMC PMUs to count for tasks, which give us the thread level metric values per task.
Example Usage :
# perf list
[...]
nest_mcs01/PM_MCS01_64B_RD_DISP_PORT01/ [Kernel PMU event]
nest_mcs01/PM_MCS01_64B_RD_DISP_PORT23/ [Kernel PMU event]
[...]
core_imc/CPM_0THRD_NON_IDLE_PCYC/ [Kernel PMU event]
core_imc/CPM_1THRD_NON_IDLE_INST/ [Kernel PMU event]
[...]
thread_imc/CPM_0THRD_NON_IDLE_PCYC/ [Kernel PMU event]
thread_imc/CPM_1THRD_NON_IDLE_INST/ [Kernel PMU event]
To see per chip data for nest_mcs0/PM_MCS_DOWN_128B_DATA_XFER_MC0/ :
# ./perf stat -e "nest_mcs01/PM_MCS01_64B_WR_DISP_PORT01/" -a --per-socket
To see non-idle instructions for core 0 :
# ./perf stat -e "core_imc/CPM_NON_IDLE_INST/" -C 0 -I 1000
To see non-idle instructions for a "make" :
# ./perf stat -e "thread_imc/CPM_NON_IDLE_PCYC/" make
Comments/feedback/suggestions are welcome.
TODO:
1)Add a sysfs interface to disable the Core imc (both for ldbar and pdbar)
Changelog:
v10 -> v11
- cpuhotplug call unregistration for nest counters is handled.
- nest counters are also disable in case of kdump.
- alloc_pages_node is used for memory allocation for core and thread, instead of alloc_pages_exact_nid.
- base_addr calculations for nest, core, thread events are modified, as the 'config' now has more fields .
- event config fields are updated for nest,core and thread.
- cpuhotplug function for nest,core and thread are modified.
- opal-call api for start and stop is changed.
v9 -> v10
- reworked the cpu hot plug functions for nest and core
- Updated imc_get_mem_addr_nest
- Changed u64 vbase[IMC_MAX_PAGES]; to u64 *vbase[IMC_MAX_PAGES]; in struct imc_mem_info
v8 -> v9
- Updated nest, core, thread cpuhotplug functions.
- PMU node parsing logic is changed as there is change in the ima-catalog file. PMU nodes are identified based on the "type" property.
- Since imc-counters subtree accomodates the memory base address and offset for nest counter data, logic to get memory address for nest counters data is updated.
- Memory allocation functions for core and thread are updated.
- Data structures for imc instrumentation are updated.
- pmu reserve/release functions for nest,core,thread are moved to *_imc_event_init.
- Updated the comments.
- Included necessary checks in core_imc_change_cpu_context()
v7 -> v8:
- opal-call API for nest and core is changed. OPAL_NEST_IMC_COUNTERS_CONTROL and OPAL_CORE_IMC_COUNTERS_CONTROL is replaced with OPAL_IMC_COUNTERS_INIT, OPAL_IMC_COUNTERS_START and OPAL_IMC_COUNTERS_STOP.
- thread_ima doesn't have CPUMASK_ATTR, hence added a
fix in patch 09/10, which will swap the IMC_EVENT_ATTR
slot with IMC_CPUMASK_ATTR.
v6 -> v7:
- Updated the commit message and code comments.
- Changed the counter init code to disable the
nest/core counters by default and enable only
when it is used.
- Updated the pmu-setup code to register the
PMUs which doesn't have events.
- replaced imc_event_info_val() to imc_event_prop_update()
- Updated the imc_pmu_setup() code, by checking for the "value"
of compatible property instead of merely checking for compatible.
- removed imc_get_domain().
- init_imc_pmu() and imc_pmu_setup() are made __init.
- update_max_val() is invoked immediately after updating the offset value.
v5 -> v6:
- merged few patches for the readability and code flow
- Updated the commit message and code comments.
- updated cpuhotplug code and added checks for perf migration context
- Added READ_ONCE() when reading the counter data.
- replaced of_property_read_u32() with of_get_address() for "reg" property read
- replaced UNKNOWN_DOMAIN with IMC_DOMAIN_UNKNOWN
v4 -> v5:
- Updated opal call numbers
- Added a patch to disable Core-IMC device using shutdown callback
- Added patch to support cpuhotplug for thread-imc
- Added patch to disable and enable core imc engine in cpuhot plug path v3 -> v4 :
- Changed the events parser code to discover the PMU and events because of the changed format of the IMC DTS file (Patch 3).
- Implemented the two TODOs to include core and thread IMC support with this patchset (Patches 7 through 10).
- Changed the CPU hotplug code of Nest IMC PMUs to include a new state CPUHP_AP_PERF_POWERPC_NEST_ONLINE (Patch 6).
v2 -> v3 :
- Changed all references for IMA (In-Memory Accumulation) to IMC (In-Memory Collection).
v1 -> v2 :
- Account for the cases where a PMU can have a common scale and unit values for all its supported events (Patch 3/6).
- Fixed a Build error (for maple_defconfig) by enabling imc_pmu.o only for CONFIG_PPC_POWERNV=y (Patch 4/6)
- Read from the "event-name" property instead of "name" for an event node (Patch 3/6).
Anju T Sudhakar (6):
powerpc/powernv: Autoload IMC device driver module powerpc/perf: Add generic IMC pmu group and event functions powerpc/perf: IMC pmu cpumask and cpuhotplug support powerpc/powernv: Thread IMC events detection powerpc/perf: Thread IMC PMU functions powerpc/perf: Thread imc cpuhotplug support
Madhavan Srinivasan (4):
powerpc/powernv: Data structure and macros definitions for IMC powerpc/powernv: Detect supported IMC units and its events powerpc/powernv: Core IMC events detection powerpc/perf: PMU functions for Core IMC and hotplugging
arch/powerpc/include/asm/imc-pmu.h | 120 +++ arch/powerpc/include/asm/opal-api.h | 11 +- arch/powerpc/include/asm/opal.h | 4 + arch/powerpc/perf/Makefile | 3 + arch/powerpc/perf/imc-pmu.c | 970 +++++++++++++++++++++++++ arch/powerpc/platforms/powernv/Kconfig | 10 + arch/powerpc/platforms/powernv/Makefile | 1 + arch/powerpc/platforms/powernv/opal-imc.c | 562 ++++++++++++++ arch/powerpc/platforms/powernv/opal-wrappers.S | 3 + arch/powerpc/platforms/powernv/opal.c | 18 + include/linux/cpuhotplug.h | 3 + 11 files changed, 1704 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/include/asm/imc-pmu.h create mode 100644 arch/powerpc/perf/imc-pmu.c create mode 100644 arch/powerpc/platforms/powernv/opal-imc.c
Signature · 1 line
2.11.0
PATCH v11 1/10 powerpc/powernv: Data structure and macros definitions for IMC
From: Madhavan Srinivasan <[email protected]>
Create a new header file to add the data structures and macros needed for In-Memory Collection (IMC) counter support.
--- arch/powerpc/include/asm/imc-pmu.h | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 arch/powerpc/include/asm/imc-pmu.h
arch/powerpc/include/asm/imc-pmu.h new file +99 -0
@@ -0,0 +1,99 @@ +#ifndef PPC_POWERNV_IMC_PMU_DEF_H +#define PPC_POWERNV_IMC_PMU_DEF_H + +/* +* IMC Nest Performance Monitor counter support. +* +* Copyright (C) 2017 Madhavan Srinivasan, IBM Corporation. +* (C) 2017 Anju T Sudhakar, IBM Corporation. +* (C) 2017 Hemant K Shaw, 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 later version. +*/ + +#include <linux/perf_event.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/io.h> +#include <asm/opal.h> + +/* +* For static allocation of some of the structures. +*/ +#define IMC_MAX_PMUS 32 + +/* +* This macro is used for memory buffer allocation of +* event names and event string +*/ +#define IMC_MAX_NAME_VAL_LEN 96 + +/* +* Currently Microcode supports a max of 256KB of counter memory +* in the reserved memory region. Max pages to mmap (considering 4K PAGESIZE). +*/ +#define IMC_MAX_PAGES 64 + +/* +*Compatbility macros for IMC devices +*/ +#define IMC_DTB_COMPAT "ibm,opal-in-memory-counters" +#define IMC_DTB_UNIT_COMPAT "ibm,imc-counters" + +/* +* Structure to hold memory address information for imc units. +*/ +struct imc_mem_info { +u32 id; +u64 *vbase[IMC_MAX_PAGES ]; +}; + +/* +* Place holder for nest pmu events and values. +*/ +struct imc_events { +char *ev_name; +char *ev_value; +}; + +#define IMC_FORMAT_ATTR 0 +#define IMC_CPUMASK_ATTR 1 +#define IMC_EVENT_ATTR 2 +#define IMC_NULL_ATTR 3 + +/* +* Device tree parser code detects IMC pmu support and +* registers new IMC pmus. This structure will hold the +* pmu functions, events, counter memory information +* and attrs for each imc pmu and will be referenced at +* the time of pmu registration. +*/ +struct imc_pmu { +struct pmu pmu; +int domain; +/* +* flag to notify whether the memory is mmaped +* or allocated by kernel. +*/ +int imc_counter_mmaped; +struct imc_mem_info *mem_info; +struct imc_events *events; +u32 counter_mem_size; +/* +* Attribute groups for the PMU. Slot 0 used for +* format attribute, slot 1 used for cpusmask attribute, +* slot 2 used for event attribute. Slot 3 keep as +* NULL. +*/ +const struct attribute_group *attr_groups[4 ]; +}; + +/* +* Domains for IMC PMUs +*/ +#define IMC_DOMAIN_NEST 1 + +#endif /* PPC_POWERNV_IMC_PMU_DEF_H */
Signature · 1 line
2.7.4
PATCH v11 2/10 powerpc/powernv: Autoload IMC device driver module
In reply to Anju T SudhakarCode to create platform device for the IMC counters. Paltform devices are created based on the IMC compatibility string.
New Config flag "CONFIG_HV_PERF_IMC_CTRS" add to contain the IMC counter changes.
--- arch/powerpc/platforms/powernv/Kconfig | 10 +++++ arch/powerpc/platforms/powernv/Makefile | 1 + arch/powerpc/platforms/powernv/opal-imc.c | 73 +++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal.c | 18 ++++++++ 4 files changed, 102 insertions(+) create mode 100644 arch/powerpc/platforms/powernv/opal-imc.c
arch/powerpc/platforms/powernv/Kconfig +10 -0
@@ -30,3 +30,13 @@ config OPAL_PRD help This enables the opal-prd driver, a facility to run processor recovery diagnostics on OpenPower machines + +config HV_PERF_IMC_CTRS + bool "Hypervisor supplied In Memory Collection PMU events (Nest & Core)" + default y + depends on PERF_EVENTS && PPC_POWERNV + help + Enable access to hypervisor supplied in-memory collection counters + in perf. IMC counters are available from Power9 systems. + + If unsure, select Y.
arch/powerpc/platforms/powernv/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_PPC_SCOM) += opal-xscom.o obj-$(CONFIG_MEMORY_FAILURE) += opal-memory-errors.o obj-$(CONFIG_TRACEPOINTS) += opal-tracepoints.o obj-$(CONFIG_OPAL_PRD) += opal-prd.o +obj-$(CONFIG_HV_PERF_IMC_CTRS) += opal-imc.o
arch/powerpc/platforms/powernv/opal-imc.c new file +73 -0
73 lines not on this page · raw message
arch/powerpc/platforms/powernv/opal.c +18 -0
@@ -14,6 +14,7 @@#include <linux/printk.h> #include <linux/types.h> #include <linux/of.h> +#include <linux/of_address.h> #include <linux/of_fdt.h> #include <linux/of_platform.h> #include <linux/interrupt.h>
@@ -30,6 +31,7 @@#include <asm/opal.h> #include <asm/firmware.h> #include <asm/mce.h> +#include <asm/imc-pmu.h> #include "powernv.h"
@@ -705,6 +707,17 @@ static void opal_pdev_init(const char *compatible)of_platform_device_create (np,NULL ,NULL ); } +#ifdef CONFIG_HV_PERF_IMC_CTRS +static void __init opal_imc_init_dev (void ) +{ +struct device_node *np; + + np =of_find_compatible_node (NULL ,NULL ,IMC_DTB_COMPAT ); +if (np) +of_platform_device_create (np,NULL ,NULL ); +} +#endif +static int kopald (void *unused) {unsigned long timeout =msecs_to_jiffies (opal_heartbeat) +1 ;
@@ -778,6 +791,11 @@ static int __init opal_init(void)/* Setup a heatbeat thread if requested by OPAL */ opal_init_heartbeat (); +#ifdef CONFIG_HV_PERF_IMC_CTRS +/* Detect IMC pmu counters support and create PMUs */ +opal_imc_init_dev (); +#endif +/* Create leds platform devices */ leds =of_find_node_by_path ("/ibm,opal/leds" );if (leds) {
Signature · 1 line
2.7.4
PATCH v11 3/10 powerpc/powernv: Detect supported IMC units and its events
In reply to Anju T SudhakarFrom: Madhavan Srinivasan <[email protected]>
Parse device tree to detect IMC units. Traverse through each IMC unit node to find supported events and corresponding unit/scale files (if any).
The device tree for IMC counters starts at the node "imc-counters". This node contains all the IMC PMU nodes and event nodes
for these IMC PMUs. The PMU nodes have an "events" property which has a phandle value for the actual events node. The events are separated from the PMU nodes to abstract out the common events. For example, PMU node "mcs0", "mcs1" etc. will contain a pointer to "nest-mcs-events" since, the events are common between these PMUs. These events have a different prefix based on their relation to different PMUs, and hence, the PMU nodes themselves contain an "events-prefix" property. The value for this property concatenated to the event name, forms the actual event name. Also, the PMU have a "reg" field as the base offset for the events which belong to this PMU. This "reg" field is added to event's "reg" field in the "events" node, which gives us the location of the counter data. Kernel code uses this offset as event configuration value.
Device tree parser code also looks for scale/unit property in the event node and passes on the value as an event attr for perf interface to use in the post processing by the perf tool. Some PMUs may have common scale and unit properties which implies that all events supported by this PMU inherit the scale and unit properties of the PMU itself. For those events, we need to set the common unit and scale values.
For failure to initialize any unit or any event, disable that unit and continue setting up the rest of them.
--- arch/powerpc/include/asm/imc-pmu.h | 5 + arch/powerpc/platforms/powernv/opal-imc.c | 439 +++++++++++++++++++++++++++++- 2 files changed, 443 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/imc-pmu.h +5 -0
@@ -91,6 +91,11 @@ struct imc_pmu {const struct attribute_group *attr_groups[4 ]; }; +/* In-Memory Collection Counters Type */ +enum { +IMC_COUNTER_PER_CHIP =0x10 , +}; +/* * Domains for IMC PMUs */
arch/powerpc/platforms/powernv/opal-imc.c +438 -1
454 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v11 4/10 powerpc/perf: Add generic IMC pmu group and event functions
In reply to Anju T SudhakarDevice tree IMC driver code parses the IMC units and their events. It passes the information to IMC pmu code which is placed in powerpc/perf as "imc-pmu.c".
Patch adds a set of generic imc pmu related event functions to be used by each imc pmu unit. Add code to setup format attribute and to register imc pmus. Add a event_init function for nest_imc events.
Since, the IMC counters' data are periodically fed to a memory location, the functions to read/update, start/stop, add/del can be generic and can be used by all IMC PMU units.
--- arch/powerpc/include/asm/imc-pmu.h | 5 + arch/powerpc/perf/Makefile | 3 + arch/powerpc/perf/imc-pmu.c | 279 ++++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal-imc.c | 11 +- 4 files changed, 296 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/perf/imc-pmu.c
arch/powerpc/include/asm/imc-pmu.h +5 -0
@@ -63,6 +63,9 @@ struct imc_events {#define IMC_CPUMASK_ATTR 1#define IMC_EVENT_ATTR 2#define IMC_NULL_ATTR 3 +#define IMC_EVENT_OFFSET_MASK 0xffffffffULL +#define IMC_EVENT_RVALUE_MASK 0x100000000ULL +#define IMC_NEST_EVENT_MODE 0x1fe00000000ULL/* * Device tree parser code detects IMC pmu support and
@@ -101,4 +104,6 @@ enum {*/ #define IMC_DOMAIN_NEST 1 +extern struct imc_pmu *per_nest_pmu_arr[IMC_MAX_PMUS ]; +extern int init_imc_pmu (struct imc_events *events,int idx,struct imc_pmu *pmu_ptr);#endif /* PPC_POWERNV_IMC_PMU_DEF_H */
arch/powerpc/perf/Makefile +3 -0
@@ -6,6 +6,9 @@ obj-$(CONFIG_PPC_PERF_CTRS) += core-book3s.o bhrb.o obj64-$(CONFIG_PPC_PERF_CTRS) += power4-pmu.o ppc970-pmu.o power5-pmu.o \ power5+-pmu.o power6-pmu.o power7-pmu.o \ isa207-common.o power8-pmu.o power9-pmu.o + +obj-$(CONFIG_HV_PERF_IMC_CTRS) += imc-pmu.o + obj32-$(CONFIG_PPC_PERF_CTRS) += mpc7450-pmu.o obj-$(CONFIG_FSL_EMB_PERF_EVENT) += core-fsl-emb.o
arch/powerpc/perf/imc-pmu.c new file +279 -0
279 lines not on this page · raw message
arch/powerpc/platforms/powernv/opal-imc.c +9 -2
@@ -34,8 +34,6 @@#include <asm/cputable.h> #include <asm/imc-pmu.h> -struct imc_pmu *per_nest_pmu_arr[IMC_MAX_PMUS ]; -static int imc_event_prop_update (char *name,struct imc_events *events) {char *buf;
@@ -452,8 +450,17 @@ static int imc_pmu_create(struct device_node *parent, int pmu_index, int domain)if (prop)imc_events_setup (parent, pmu_index, pmu_ptr, prop, &idx); } +/* Function to register IMC pmu */ + ret =init_imc_pmu (pmu_ptr->events, idx, pmu_ptr); +if (ret) { +pr_err ("IMC PMU %s Register failed\n" , pmu_ptr->pmu.name); + goto free_events; + }return 0 ; +free_events: +if (pmu_ptr->events) +imc_free_events (pmu_ptr->events, idx); free_pmu:if (pmu_ptr)kfree (pmu_ptr);
Signature · 1 line
2.7.4
PATCH v11 6/10 powerpc/powernv: Core IMC events detection
In reply to Anju T SudhakarFrom: Madhavan Srinivasan <[email protected]>
This patch adds support for detection of core IMC events along with the Nest IMC events. It adds a new domain IMC_DOMAIN_CORE and its determined with the help of the "type" property in the IMC device tree.
--- arch/powerpc/include/asm/imc-pmu.h | 3 +++ arch/powerpc/perf/imc-pmu.c | 2 ++ arch/powerpc/platforms/powernv/opal-imc.c | 14 +++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/imc-pmu.h +3 -0
@@ -97,6 +97,7 @@ struct imc_pmu {/* In-Memory Collection Counters Type */ enum { +IMC_COUNTER_PER_CORE =0x4 ,IMC_COUNTER_PER_CHIP =0x10 , };
@@ -104,7 +105,9 @@ enum {* Domains for IMC PMUs */ #define IMC_DOMAIN_NEST 1 +#define IMC_DOMAIN_CORE 2extern struct imc_pmu *per_nest_pmu_arr[IMC_MAX_PMUS ]; +extern struct imc_pmu *core_imc_pmu;extern int init_imc_pmu (struct imc_events *events,int idx,struct imc_pmu *pmu_ptr);#endif /* PPC_POWERNV_IMC_PMU_DEF_H */
arch/powerpc/perf/imc-pmu.c +2 -0
@@ -31,6 +31,8 @@ static DEFINE_MUTEX(imc_nest_inited_reserve);static DEFINE_MUTEX (imc_nest_reserve); +struct imc_pmu *core_imc_pmu; +struct imc_pmu *imc_event_to_pmu (struct perf_event *event) { return container_of(event->pmu, struct imc_pmu, pmu);
arch/powerpc/platforms/powernv/opal-imc.c +11 -3
@@ -379,7 +379,7 @@ static int imc_get_mem_addr_nest(struct device_node *node,/* * imc_pmu_create : Takes the parent device which is the pmu unit, pmu_index * and domain as the inputs. -* Allocates memory for the pmu, sets up its domain (NEST), and +* Allocates memory for the pmu, sets up its domain (NEST/CORE), and * calls imc_events_setup() to allocate memory for the events supported * by this pmu. Assigns a name for the pmu. *
@@ -406,7 +406,10 @@ static int imc_pmu_create(struct device_node *parent, int pmu_index, int domain) pmu_ptr->domain = domain;/* Needed for hotplug/migration */ - per_nest_pmu_arr[pmu_index] = pmu_ptr; +if (pmu_ptr->domain ==IMC_DOMAIN_CORE ) + core_imc_pmu = pmu_ptr; +else if (pmu_ptr->domain ==IMC_DOMAIN_NEST ) + per_nest_pmu_arr[pmu_index] = pmu_ptr; pp =of_find_property (parent,"name" ,NULL );if (!pp) {
@@ -427,7 +430,10 @@ static int imc_pmu_create(struct device_node *parent, int pmu_index, int domain) goto free_pmu; }/* Save the name to register it later */ -sprintf (buf,"nest_%s" , (char *)pp->value); +if (pmu_ptr->domain ==IMC_DOMAIN_NEST ) +sprintf (buf,"nest_%s" , (char *)pp->value); +else +sprintf (buf,"%s_imc" , (char *)pp->value); pmu_ptr->pmu.name = (char *)buf;if (of_property_read_u32 (parent,"size" , &pmu_ptr->counter_mem_size))
@@ -504,6 +510,8 @@ static int opal_imc_counters_probe(struct platform_device *pdev)continue ;if (type ==IMC_COUNTER_PER_CHIP ) domain =IMC_DOMAIN_NEST ; +else if (type ==IMC_COUNTER_PER_CORE ) + domain =IMC_DOMAIN_CORE ;else continue ;if (!imc_pmu_create (imc_dev, pmu_count, domain))
Signature · 1 line
2.7.4
PATCH v11 8/10 powerpc/powernv: Thread IMC events detection
In reply to Anju T SudhakarCode to add support for detection of thread IMC events. It adds a new domain IMC_DOMAIN_THREAD and it is determined with the help of the "type" property in the imc device-tree.
--- arch/powerpc/include/asm/imc-pmu.h | 2 ++ arch/powerpc/platforms/powernv/opal-imc.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/imc-pmu.h +2 -0
@@ -98,6 +98,7 @@ struct imc_pmu {/* In-Memory Collection Counters Type */ enum { +IMC_COUNTER_PER_THREAD =0x1 ,IMC_COUNTER_PER_CORE =0x4 ,IMC_COUNTER_PER_CHIP =0x10 , };
@@ -107,6 +108,7 @@ enum {*/ #define IMC_DOMAIN_NEST 1#define IMC_DOMAIN_CORE 2 +#define IMC_DOMAIN_THREAD 3extern struct imc_pmu *per_nest_pmu_arr[IMC_MAX_PMUS ];extern struct imc_pmu *core_imc_pmu;
arch/powerpc/platforms/powernv/opal-imc.c +3 -1
@@ -380,7 +380,7 @@ static int imc_get_mem_addr_nest(struct device_node *node,/* * imc_pmu_create : Takes the parent device which is the pmu unit, pmu_index * and domain as the inputs. -* Allocates memory for the pmu, sets up its domain (NEST/CORE), and +* Allocates memory for the pmu, sets up its domain (NEST/CORE/THREAD), and * calls imc_events_setup() to allocate memory for the events supported * by this pmu. Assigns a name for the pmu. *
@@ -516,6 +516,8 @@ static int opal_imc_counters_probe(struct platform_device *pdev) domain =IMC_DOMAIN_NEST ; else if (type == IMC_COUNTER_PER_CORE) domain =IMC_DOMAIN_CORE ; + else if (type == IMC_COUNTER_PER_THREAD) + domain =IMC_DOMAIN_THREAD ; else continue;if (!imc_pmu_create (imc_dev, pmu_count, domain))
Signature · 1 line
2.7.4
PATCH v11 10/10 powerpc/perf: Thread imc cpuhotplug support
In reply to Anju T SudhakarCode to add support for thread IMC on cpuhotplug.
When a cpu goes offline, the LDBAR for that cpu is disabled, and when it comes back online the previous ldbar value is written back to the LDBAR for that cpu.
To register the hotplug functions for thread_imc, a new state CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE is added to the list of existing states.
--- arch/powerpc/perf/imc-pmu.c | 38 +++++++++++++++++++++++++++++++++++++- include/linux/cpuhotplug.h | 1 + 2 files changed, 38 insertions(+), 1 deletion(-)
arch/powerpc/perf/imc-pmu.c +37 -1
@@ -346,6 +346,37 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr)return 0 ; } +static int ppc_thread_imc_cpu_online (unsigned int cpu) +{ +int rc =0 ; +u64 ldbar_value; + +if (per_cpu (thread_imc_mem, cpu) ==NULL ) + rc =thread_imc_mem_alloc (cpu, thread_imc_mem_size); + +if (rc) +mtspr (SPRN_LDBAR ,0 ); + + ldbar_value = ((u64 )per_cpu (thread_imc_mem, cpu) & (u64 )THREAD_IMC_LDBAR_MASK ) | + (u64 )THREAD_IMC_ENABLE ; +mtspr (SPRN_LDBAR , ldbar_value); +return 0 ; +} + +static int ppc_thread_imc_cpu_offline (unsigned int cpu) +{ +mtspr (SPRN_LDBAR ,0 ); +return 0 ; +} + +void thread_imc_cpu_init (void ) +{ +cpuhp_setup_state (CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE , +"perf/powerpc/imc_thread:online" , + ppc_thread_imc_cpu_online, + ppc_thread_imc_cpu_offline); +} +static int ppc_core_imc_cpu_online (unsigned int cpu) {const struct cpumask *l_cpumask;
@@ -901,6 +932,9 @@ int init_imc_pmu(struct imc_events *events, int idx,if (ret)return ret;break ; +case IMC_DOMAIN_THREAD : +thread_imc_cpu_init (); +break ;default :return -1 ;/* Unknown domain */ }
@@ -942,7 +976,9 @@ int init_imc_pmu(struct imc_events *events, int idx,cpuhp_remove_state (CPUHP_AP_PERF_POWERPC_CORE_IMC_ONLINE ); }/* For thread_imc, we have allocated memory, we need to free it */ -if (pmu_ptr->domain ==IMC_DOMAIN_THREAD ) +if (pmu_ptr->domain ==IMC_DOMAIN_THREAD ) {cleanup_all_thread_imc_memory (); +cpuhp_remove_state (CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE ); + }return ret; }
include/linux/cpuhotplug.h +1 -0
@@ -141,6 +141,7 @@ enum cpuhp_state {CPUHP_AP_PERF_ARM_QCOM_L3_ONLINE ,CPUHP_AP_PERF_POWERPC_NEST_IMC_ONLINE ,CPUHP_AP_PERF_POWERPC_CORE_IMC_ONLINE , +CPUHP_AP_PERF_POWERPC_THREAD_IMC_ONLINE ,CPUHP_AP_WORKQUEUE_ONLINE ,CPUHP_AP_RCUTREE_ONLINE , CPUHP_AP_ONLINE_DYN,
Signature · 1 line
2.7.4