Documentation/ABI: Add document for Mellanox PMC driver
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v4 1/4 Documentation/ABI: Add document for Mellanox PMC driver
Document the sysfs interface for programming and monitoring the performance counters in various HW blocks of Mellanox BlueField-1, BlueField-2 and BlueField-3.
--- .../ABI/testing/sysfs-platform-mellanox-pmc | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-platform-mellanox-pmc
Documentation/ABI/testing/sysfs-platform-mellanox-pmc new file +54 -0
@@ -0,0 +1,54 @@ +HID Driver Description +MLNXBFD0 mlxbf-pmc Performance counters (BlueField-1) +MLNXBFD1 mlxbf-pmc Performance counters (BlueField-2) +MLNXBFD2 mlxbf-pmc Performance counters (BlueField-3) + +What: /sys/bus/platform/devices/<HID>/hwmon/hwmonX/<block>/event_list +Date: Dec 2020 +KernelVersion: 5.10 +Contact: "Shravan Kumar Ramani <[email protected]>" +Description: + List of events supported by the counters in the specific block. + It is used to extract the event number or ID associated with + each event. + +What: /sys/bus/platform/devices/<HID>/hwmon/hwmonX/<block>/event<N> +Date: Dec 2020 +KernelVersion: 5.10 +Contact: "Shravan Kumar Ramani <[email protected]>" +Description: + Event monitored by corresponding counter. This is used to + program or read back the event that should be or is currently + being monitored by counter<N>. + +What: /sys/bus/platform/devices/<HID>/hwmon/hwmonX/<block>/counter<N> +Date: Dec 2020 +KernelVersion: 5.10 +Contact: "Shravan Kumar Ramani <[email protected]>" +Description: + Counter value of the event being monitored. This is used to + read the counter value of the event which was programmed using + event<N>. This is also used to clear or reset the counter value + by writing 0 to the counter sysfs. + +What: /sys/bus/platform/devices/<HID>/hwmon/hwmonX/<block>/enable +Date: Dec 2020 +KernelVersion: 5.10 +Contact: "Shravan Kumar Ramani <[email protected]>" +Description: + Start or stop counters. This is used to start the counters + for monitoring the programmed events and also to stop the + counters after the desired duration. Writing value 1 will + start all the counters in the block, and writing 0 will + stop all the counters together. + +What: /sys/bus/platform/devices/<HID>/hwmon/hwmonX/<block>/<reg> +Date: Dec 2020 +KernelVersion: 5.10 +Contact: "Shravan Kumar Ramani <[email protected]>" +Description: + Value of register. This is used to read or reset the registers + where various performance statistics are counted for each block. + Writing 0 to the sysfs will clear the counter, writing any other + value is not allowed. +
Signature · 1 line
2.43.2
PATCH v4 2/4 platform/mellanox: mlxbf-pmc: Add support for monitoring cycle count
In reply to a message not in the archiveAdd support for programming any counter to monitor the cycle count. This will allow the user to repurpose and dedicate any of the counters in the block to counting cycles.
--- drivers/platform/mellanox/mlxbf-pmc.c | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
drivers/platform/mellanox/mlxbf-pmc.c +61 -0
@@ -88,6 +88,7 @@#define MLXBF_PMC_CRSPACE_PERFMON_CTL (n) (n * MLXBF_PMC_CRSPACE_PERFMON_REG0_SZ)#define MLXBF_PMC_CRSPACE_PERFMON_EN BIT(30)#define MLXBF_PMC_CRSPACE_PERFMON_CLR BIT(28) +#define MLXBF_PMC_CRSPACE_PERFMON_COUNT_CLOCK (n) (MLXBF_PMC_CRSPACE_PERFMON_CTL(n) + 0x4)#define MLXBF_PMC_CRSPACE_PERFMON_VAL0 (n) (MLXBF_PMC_CRSPACE_PERFMON_CTL(n) + 0xc)/**
@@ -114,6 +115,7 @@ struct mlxbf_pmc_attribute {* @attr_event: Attributes for "event" sysfs files * @attr_event_list: Attributes for "event_list" sysfs files * @attr_enable: Attributes for "enable" sysfs files +* @attr_count_clock: Attributes for "count_clock" sysfs files * @block_attr: All attributes needed for the block * @block_attr_grp: Attribute group for the block */
@@ -126,6 +128,7 @@ struct mlxbf_pmc_block_info {struct mlxbf_pmc_attribute *attr_event;struct mlxbf_pmc_attribute attr_event_list;struct mlxbf_pmc_attribute attr_enable; +struct mlxbf_pmc_attribute attr_count_clock;struct attribute *block_attr[MLXBF_PMC_MAX_ATTRS ];struct attribute_group block_attr_grp; };
@@ -1763,6 +1766,49 @@ static ssize_t mlxbf_pmc_enable_store(struct device *dev,return count; } +/* Show function for "count_clock" sysfs files - only for crspace */ +static ssize_t mlxbf_pmc_count_clock_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct mlxbf_pmc_attribute *attr_count_clock =container_of ( + attr, struct mlxbf_pmc_attribute, dev_attr); +unsigned int blk_num; +u32 reg; + + blk_num = attr_count_clock->nr; + +if (mlxbf_pmc_readl (pmc->block[blk_num].mmio_base + +MLXBF_PMC_CRSPACE_PERFMON_COUNT_CLOCK (pmc->block[blk_num].counters), + ®)) +return -EINVAL ; + +return sysfs_emit (buf,"%u\n" , reg); +} + +/* Store function for "count_clock" sysfs files - only for crspace */ +static ssize_t mlxbf_pmc_count_clock_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct mlxbf_pmc_attribute *attr_count_clock =container_of ( + attr, struct mlxbf_pmc_attribute, dev_attr); +unsigned int blk_num; +u32 reg; +int err; + + blk_num = attr_count_clock->nr; + + err =kstrtouint (buf,0 , ®); +if (err <0 ) +return err; + +mlxbf_pmc_write (pmc->block[blk_num].mmio_base + +MLXBF_PMC_CRSPACE_PERFMON_COUNT_CLOCK (pmc->block[blk_num].counters), +MLXBF_PMC_WRITE_REG_32 , reg); + +return count; +} +/* Populate attributes for blocks with counters to monitor performance */ static int mlxbf_pmc_init_perftype_counter (struct device *dev,unsigned int blk_num) {
@@ -1801,6 +1847,21 @@ static int mlxbf_pmc_init_perftype_counter(struct device *dev, unsigned int blk_ attr =NULL ; } +if (pmc->block[blk_num].type ==MLXBF_PMC_TYPE_CRSPACE ) { +/* Program crspace counters to count clock cycles using "count_clock" sysfs */ + attr = &pmc->block[blk_num].attr_count_clock; + attr->dev_attr.attr.mode =0644 ; + attr->dev_attr.show = mlxbf_pmc_count_clock_show; + attr->dev_attr.store = mlxbf_pmc_count_clock_store; + attr->nr = blk_num; + attr->dev_attr.attr.name =devm_kasprintf (dev,GFP_KERNEL , +"count_clock" ); +if (!attr->dev_attr.attr.name) +return -ENOMEM ; + pmc->block[blk_num].block_attr[++i] = &attr->dev_attr.attr; + attr =NULL ; + } + pmc->block[blk_num].attr_counter =devm_kcalloc ( dev, pmc->block[blk_num].counters,sizeof (struct mlxbf_pmc_attribute ),GFP_KERNEL );
Signature · 1 line
2.43.2
PATCH v4 3/4 platform/mellanox: mlxbf-pmc: Add support for clock_measure performance block
In reply to a message not in the archiveThe HW clock_measure counter info is passed to the driver from ACPI. Create a new sub-directory for clock_measure events and provide read access to the user. Writes are blocked since the fields are RO.
--- drivers/platform/mellanox/mlxbf-pmc.c | 46 ++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-)
drivers/platform/mellanox/mlxbf-pmc.c +42 -4
@@ -862,6 +862,37 @@ static const struct mlxbf_pmc_events mlxbf_pmc_llt_miss_events[] = { {75, "HISTOGRAM_HISTOGRAM_BIN9"}, }; +static const struct mlxbf_pmc_events mlxbf_pmc_clock_events[] = { + {0x0 ,"FMON_CLK_LAST_COUNT_PLL_D1_INST0" }, + {0x4 ,"REFERENCE_WINDOW_WIDTH_PLL_D1_INST0" }, + {0x8 ,"FMON_CLK_LAST_COUNT_PLL_D1_INST1" }, + {0xc ,"REFERENCE_WINDOW_WIDTH_PLL_D1_INST1" }, + {0x10 ,"FMON_CLK_LAST_COUNT_PLL_G1" }, + {0x14 ,"REFERENCE_WINDOW_WIDTH_PLL_G1" }, + {0x18 ,"FMON_CLK_LAST_COUNT_PLL_W1" }, + {0x1c ,"REFERENCE_WINDOW_WIDTH_PLL_W1" }, + {0x20 ,"FMON_CLK_LAST_COUNT_PLL_T1" }, + {0x24 ,"REFERENCE_WINDOW_WIDTH_PLL_T1" }, + {0x28 ,"FMON_CLK_LAST_COUNT_PLL_A0" }, + {0x2c ,"REFERENCE_WINDOW_WIDTH_PLL_A0" }, + {0x30 ,"FMON_CLK_LAST_COUNT_PLL_C0" }, + {0x34 ,"REFERENCE_WINDOW_WIDTH_PLL_C0" }, + {0x38 ,"FMON_CLK_LAST_COUNT_PLL_N1" }, + {0x3c ,"REFERENCE_WINDOW_WIDTH_PLL_N1" }, + {0x40 ,"FMON_CLK_LAST_COUNT_PLL_I1" }, + {0x44 ,"REFERENCE_WINDOW_WIDTH_PLL_I1" }, + {0x48 ,"FMON_CLK_LAST_COUNT_PLL_R1" }, + {0x4c ,"REFERENCE_WINDOW_WIDTH_PLL_R1" }, + {0x50 ,"FMON_CLK_LAST_COUNT_PLL_P1" }, + {0x54 ,"REFERENCE_WINDOW_WIDTH_PLL_P1" }, + {0x58 ,"FMON_CLK_LAST_COUNT_REF_100_INST0" }, + {0x5c ,"REFERENCE_WINDOW_WIDTH_REF_100_INST0" }, + {0x60 ,"FMON_CLK_LAST_COUNT_REF_100_INST1" }, + {0x64 ,"REFERENCE_WINDOW_WIDTH_REF_100_INST1" }, + {0x68 ,"FMON_CLK_LAST_COUNT_REF_156" }, + {0x6c ,"REFERENCE_WINDOW_WIDTH_REF_156" }, +}; +static struct mlxbf_pmc_context *pmc;/* UUID used to probe ATF service. */
@@ -1035,6 +1066,9 @@ static const struct mlxbf_pmc_events *mlxbf_pmc_event_list(const char *blk, size }else if (strstr (blk,"llt" )) { events = mlxbf_pmc_llt_events; size =ARRAY_SIZE (mlxbf_pmc_llt_events); + }else if (strstr (blk,"clock_measure" )) { + events = mlxbf_pmc_clock_events; + size =ARRAY_SIZE (mlxbf_pmc_clock_events); }else { events =NULL ; size =0 ;
@@ -1469,14 +1503,15 @@ static int mlxbf_pmc_read_event(unsigned int blk_num, u32 cnt_num, bool is_l3, u/* Method to read a register */ static int mlxbf_pmc_read_reg (unsigned int blk_num,u32 offset,u64 *result) { -u32 ecc_out; +u32 reg; -if (strstr (pmc->block_name[blk_num],"ecc" )) { +if ((strstr (pmc->block_name[blk_num],"ecc" )) || + (strstr (pmc->block_name[blk_num],"clock_measure" ))) {if (mlxbf_pmc_readl (pmc->block[blk_num].mmio_base + offset, - &ecc_out)) + ®))return -EFAULT ; - *result = ecc_out; + *result = reg;return 0 ; }
@@ -1490,6 +1525,9 @@ static int mlxbf_pmc_read_reg(unsigned int blk_num, u32 offset, u64 *result)/* Method to write to a register */ static int mlxbf_pmc_write_reg (unsigned int blk_num,u32 offset,u64 data) { +if (strstr (pmc->block_name[blk_num],"clock_measure" )) +return -EINVAL ; +if (strstr (pmc->block_name[blk_num],"ecc" )) {return mlxbf_pmc_write (pmc->block[blk_num].mmio_base + offset,MLXBF_PMC_WRITE_REG_32 , data);
Signature · 1 line
2.43.2
PATCH v4 4/4 Documentation/ABI: Add new sysfs field to sysfs-platform-mellanox-pmc
In reply to a message not in the archiveDocument newly added "count_clock" sysfs entry for the Mellanox BlueField PMC driver.
--- Documentation/ABI/testing/sysfs-platform-mellanox-pmc | 11 +++++++++++ 1 file changed, 11 insertions(+)
Documentation/ABI/testing/sysfs-platform-mellanox-pmc +11 -0
@@ -52,3 +52,14 @@ Description: Writing 0 to the sysfs will clear the counter, writing any other value is not allowed. +What: /sys/bus/platform/devices/<HID>/hwmon/hwmonX/<block>/count_clock +Date: Jan 2025 +KernelVersion: 6.13 +Contact: "Shravan Kumar Ramani <[email protected]>" +Description: + Use a counter for counting cycles. This is used to repurpose/dedicate + any of the counters in the block to counting cycles. Each counter is + represented by a bit (bit 0 for counter0, bit1 for counter1 and so on) + and setting the corresponding bit will reserve that specific counter + for counting cycles and override the event<N> setting. +
Signature · 1 line
2.43.2