Skip to content

Commit 8a4339f

Browse files
rtauro1895lucasdemarchi
authored andcommitted
drm/xe/xe_pmu: Add PMU support for per-function engine activity stats
Add PMU support for per-function engine activity stats. per-function engine activity is enabled when VF's are enabled. If 2 VF's are enabled, then the applicable function values are 0 - PF engine activity 1 - VF1 engine activity 2 - VF2 engine activity This can be read from perf tool as shown below ./perf stat -e xe_<bdf>/engine-active-ticks,gt=0,engine_class=0, engine_instance=0,function=1/ -I 1000 v2: fix documentation (Umesh) remove global for functions (Lucas, Michal) v3: fix commit message move function_id checks to same place (Michal) v4: fix comment (Umesh) Cc: Michal Wajdeczko <[email protected]> Signed-off-by: Riana Tauro <[email protected]> Reviewed-by: Umesh Nerlige Ramappa <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Lucas De Marchi <[email protected]>
1 parent 2de3f38 commit 8a4339f

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

drivers/gpu/drm/xe/xe_pmu.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "xe_hw_engine.h"
1414
#include "xe_pm.h"
1515
#include "xe_pmu.h"
16+
#include "xe_sriov_pf_helpers.h"
1617

1718
/**
1819
* DOC: Xe PMU (Performance Monitoring Unit)
@@ -32,9 +33,10 @@
3233
* gt[60:63] Selects gt for the event
3334
* engine_class[20:27] Selects engine-class for event
3435
* engine_instance[12:19] Selects the engine-instance for the event
36+
* function[44:59] Selects the function of the event (SRIOV enabled)
3537
*
3638
* For engine specific events (engine-*), gt, engine_class and engine_instance parameters must be
37-
* set as populated by DRM_XE_DEVICE_QUERY_ENGINES.
39+
* set as populated by DRM_XE_DEVICE_QUERY_ENGINES and function if SRIOV is enabled.
3840
*
3941
* For gt specific events (gt-*) gt parameter must be passed. All other parameters will be 0.
4042
*
@@ -49,6 +51,7 @@
4951
*/
5052

5153
#define XE_PMU_EVENT_GT_MASK GENMASK_ULL(63, 60)
54+
#define XE_PMU_EVENT_FUNCTION_MASK GENMASK_ULL(59, 44)
5255
#define XE_PMU_EVENT_ENGINE_CLASS_MASK GENMASK_ULL(27, 20)
5356
#define XE_PMU_EVENT_ENGINE_INSTANCE_MASK GENMASK_ULL(19, 12)
5457
#define XE_PMU_EVENT_ID_MASK GENMASK_ULL(11, 0)
@@ -58,6 +61,11 @@ static unsigned int config_to_event_id(u64 config)
5861
return FIELD_GET(XE_PMU_EVENT_ID_MASK, config);
5962
}
6063

64+
static unsigned int config_to_function_id(u64 config)
65+
{
66+
return FIELD_GET(XE_PMU_EVENT_FUNCTION_MASK, config);
67+
}
68+
6169
static unsigned int config_to_engine_class(u64 config)
6270
{
6371
return FIELD_GET(XE_PMU_EVENT_ENGINE_CLASS_MASK, config);
@@ -151,7 +159,7 @@ static bool event_supported(struct xe_pmu *pmu, unsigned int gt,
151159
static bool event_param_valid(struct perf_event *event)
152160
{
153161
struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
154-
unsigned int engine_class, engine_instance;
162+
unsigned int engine_class, engine_instance, function_id;
155163
u64 config = event->attr.config;
156164
struct xe_gt *gt;
157165

@@ -161,16 +169,26 @@ static bool event_param_valid(struct perf_event *event)
161169

162170
engine_class = config_to_engine_class(config);
163171
engine_instance = config_to_engine_instance(config);
172+
function_id = config_to_function_id(config);
164173

165174
switch (config_to_event_id(config)) {
166175
case XE_PMU_EVENT_GT_C6_RESIDENCY:
167-
if (engine_class || engine_instance)
176+
if (engine_class || engine_instance || function_id)
168177
return false;
169178
break;
170179
case XE_PMU_EVENT_ENGINE_ACTIVE_TICKS:
171180
case XE_PMU_EVENT_ENGINE_TOTAL_TICKS:
172181
if (!event_to_hwe(event))
173182
return false;
183+
184+
/* PF(0) and total vfs when SRIOV is enabled */
185+
if (IS_SRIOV_PF(xe)) {
186+
if (function_id > xe_sriov_pf_get_totalvfs(xe))
187+
return false;
188+
} else if (function_id) {
189+
return false;
190+
}
191+
174192
break;
175193
}
176194

@@ -242,14 +260,17 @@ static int xe_pmu_event_init(struct perf_event *event)
242260
static u64 read_engine_events(struct xe_gt *gt, struct perf_event *event)
243261
{
244262
struct xe_hw_engine *hwe;
245-
u64 val = 0;
263+
unsigned int function_id;
264+
u64 config, val = 0;
246265

247-
hwe = event_to_hwe(event);
266+
config = event->attr.config;
267+
function_id = config_to_function_id(config);
248268

249-
if (config_to_event_id(event->attr.config) == XE_PMU_EVENT_ENGINE_ACTIVE_TICKS)
250-
val = xe_guc_engine_activity_active_ticks(&gt->uc.guc, hwe, 0);
269+
hwe = event_to_hwe(event);
270+
if (config_to_event_id(config) == XE_PMU_EVENT_ENGINE_ACTIVE_TICKS)
271+
val = xe_guc_engine_activity_active_ticks(&gt->uc.guc, hwe, function_id);
251272
else
252-
val = xe_guc_engine_activity_total_ticks(&gt->uc.guc, hwe, 0);
273+
val = xe_guc_engine_activity_total_ticks(&gt->uc.guc, hwe, function_id);
253274

254275
return val;
255276
}
@@ -352,6 +373,7 @@ static void xe_pmu_event_del(struct perf_event *event, int flags)
352373
}
353374

354375
PMU_FORMAT_ATTR(gt, "config:60-63");
376+
PMU_FORMAT_ATTR(function, "config:44-59");
355377
PMU_FORMAT_ATTR(engine_class, "config:20-27");
356378
PMU_FORMAT_ATTR(engine_instance, "config:12-19");
357379
PMU_FORMAT_ATTR(event, "config:0-11");
@@ -360,6 +382,7 @@ static struct attribute *pmu_format_attrs[] = {
360382
&format_attr_event.attr,
361383
&format_attr_engine_class.attr,
362384
&format_attr_engine_instance.attr,
385+
&format_attr_function.attr,
363386
&format_attr_gt.attr,
364387
NULL,
365388
};

0 commit comments

Comments
 (0)