Skip to content

Commit 11ecbdd

Browse files
drm/i915/perf: introduce global sseu pinning
On Gen11 powergating half the execution units is a functional requirement when using the VME samplers. Not fullfilling this requirement can lead to hangs. This unfortunately plays fairly poorly with the NOA requirements. NOA requires a stable power configuration to maintain its configuration. As a result using OA (and NOA feeding into it) so far has required us to use a power configuration that can work for all contexts. The only power configuration fullfilling this is powergating half the execution units. This makes performance analysis for 3D workloads somewhat pointless. Failing to find a solution that would work for everybody, this change introduces a new i915-perf stream open parameter that punts the decision off to userspace. If this parameter is omitted, the existing Gen11 behavior remains (half EU array powergating). This change takes the initiative to move all perf related sseu configuration into i915_perf.c v2: Make parameter priviliged if different from default v3: Fix context modifying its sseu config while i915-perf is enabled v4: Always consider global sseu a privileged operation (Tvrtko) Override req_sseu point in intel_sseu_make_rpcs() (Tvrtko) Remove unrelated changes (Tvrtko) v5: Some typos (Tvrtko) Process sseu param in read_properties_unlocked() (Tvrtko) v6: Actually commit the bits from v5... Fixup some checkpath warnings v7: Only compare engine uabi field (Chris) Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20200317132222.2638719-3-lionel.g.landwerlin@intel.com
1 parent 371aba6 commit 11ecbdd

6 files changed

Lines changed: 108 additions & 33 deletions

File tree

‎drivers/gpu/drm/i915/gem/i915_gem_context.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,10 @@ static int get_ringsize(struct i915_gem_context *ctx,
14011401
return 0;
14021402
}
14031403

1404-
static int
1405-
user_to_context_sseu(struct drm_i915_private *i915,
1406-
const struct drm_i915_gem_context_param_sseu *user,
1407-
struct intel_sseu *context)
1404+
int
1405+
i915_gem_user_to_context_sseu(struct drm_i915_private *i915,
1406+
const struct drm_i915_gem_context_param_sseu *user,
1407+
struct intel_sseu *context)
14081408
{
14091409
const struct sseu_dev_info *device = &RUNTIME_INFO(i915)->sseu;
14101410

@@ -1539,7 +1539,7 @@ static int set_sseu(struct i915_gem_context *ctx,
15391539
goto out_ce;
15401540
}
15411541

1542-
ret = user_to_context_sseu(i915, &user_sseu, &sseu);
1542+
ret = i915_gem_user_to_context_sseu(i915, &user_sseu, &sseu);
15431543
if (ret)
15441544
goto out_ce;
15451545

‎drivers/gpu/drm/i915/gem/i915_gem_context.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,8 @@ i915_gem_engines_iter_next(struct i915_gem_engines_iter *it);
225225
struct i915_lut_handle *i915_lut_handle_alloc(void);
226226
void i915_lut_handle_free(struct i915_lut_handle *lut);
227227

228+
int i915_gem_user_to_context_sseu(struct drm_i915_private *i915,
229+
const struct drm_i915_gem_context_param_sseu *user,
230+
struct intel_sseu *context);
231+
228232
#endif /* !__I915_GEM_CONTEXT_H__ */

‎drivers/gpu/drm/i915/gt/intel_sseu.c‎

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ u32 intel_sseu_make_rpcs(struct drm_i915_private *i915,
6565
{
6666
const struct sseu_dev_info *sseu = &RUNTIME_INFO(i915)->sseu;
6767
bool subslice_pg = sseu->has_subslice_pg;
68-
struct intel_sseu ctx_sseu;
6968
u8 slices, subslices;
7069
u32 rpcs = 0;
7170

@@ -78,31 +77,13 @@ u32 intel_sseu_make_rpcs(struct drm_i915_private *i915,
7877

7978
/*
8079
* If i915/perf is active, we want a stable powergating configuration
81-
* on the system.
82-
*
83-
* We could choose full enablement, but on ICL we know there are use
84-
* cases which disable slices for functional, apart for performance
85-
* reasons. So in this case we select a known stable subset.
80+
* on the system. Use the configuration pinned by i915/perf.
8681
*/
87-
if (!i915->perf.exclusive_stream) {
88-
ctx_sseu = *req_sseu;
89-
} else {
90-
ctx_sseu = intel_sseu_from_device_info(sseu);
91-
92-
if (IS_GEN(i915, 11)) {
93-
/*
94-
* We only need subslice count so it doesn't matter
95-
* which ones we select - just turn off low bits in the
96-
* amount of half of all available subslices per slice.
97-
*/
98-
ctx_sseu.subslice_mask =
99-
~(~0 << (hweight8(ctx_sseu.subslice_mask) / 2));
100-
ctx_sseu.slice_mask = 0x1;
101-
}
102-
}
82+
if (i915->perf.exclusive_stream)
83+
req_sseu = &i915->perf.sseu;
10384

104-
slices = hweight8(ctx_sseu.slice_mask);
105-
subslices = hweight8(ctx_sseu.subslice_mask);
85+
slices = hweight8(req_sseu->slice_mask);
86+
subslices = hweight8(req_sseu->subslice_mask);
10687

10788
/*
10889
* Since the SScount bitfield in GEN8_R_PWR_CLK_STATE is only three bits
@@ -175,13 +156,13 @@ u32 intel_sseu_make_rpcs(struct drm_i915_private *i915,
175156
if (sseu->has_eu_pg) {
176157
u32 val;
177158

178-
val = ctx_sseu.min_eus_per_subslice << GEN8_RPCS_EU_MIN_SHIFT;
159+
val = req_sseu->min_eus_per_subslice << GEN8_RPCS_EU_MIN_SHIFT;
179160
GEM_BUG_ON(val & ~GEN8_RPCS_EU_MIN_MASK);
180161
val &= GEN8_RPCS_EU_MIN_MASK;
181162

182163
rpcs |= val;
183164

184-
val = ctx_sseu.max_eus_per_subslice << GEN8_RPCS_EU_MAX_SHIFT;
165+
val = req_sseu->max_eus_per_subslice << GEN8_RPCS_EU_MAX_SHIFT;
185166
GEM_BUG_ON(val & ~GEN8_RPCS_EU_MAX_MASK);
186167
val &= GEN8_RPCS_EU_MAX_MASK;
187168

‎drivers/gpu/drm/i915/i915_perf.c‎

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ static const struct i915_oa_format gen12_oa_formats[I915_OA_FORMAT_MAX] = {
344344
* @oa_periodic: Whether to enable periodic OA unit sampling
345345
* @oa_period_exponent: The OA unit sampling period is derived from this
346346
* @engine: The engine (typically rcs0) being monitored by the OA unit
347+
* @has_sseu: Whether @sseu was specified by userspace
348+
* @sseu: internal SSEU configuration computed either from the userspace
349+
* specified configuration in the opening parameters or a default value
350+
* (see get_default_sseu_config())
347351
*
348352
* As read_properties_unlocked() enumerates and validates the properties given
349353
* to open a stream of metrics the configuration is built up in the structure
@@ -363,6 +367,9 @@ struct perf_open_properties {
363367
int oa_period_exponent;
364368

365369
struct intel_engine_cs *engine;
370+
371+
bool has_sseu;
372+
struct intel_sseu sseu;
366373
};
367374

368375
struct i915_oa_config_bo {
@@ -2720,6 +2727,39 @@ static int i915_perf_stream_enable_sync(struct i915_perf_stream *stream)
27202727
return 0;
27212728
}
27222729

2730+
static void
2731+
get_default_sseu_config(struct intel_sseu *out_sseu,
2732+
struct intel_engine_cs *engine)
2733+
{
2734+
const struct sseu_dev_info *devinfo_sseu =
2735+
&RUNTIME_INFO(engine->i915)->sseu;
2736+
2737+
*out_sseu = intel_sseu_from_device_info(devinfo_sseu);
2738+
2739+
if (IS_GEN(engine->i915, 11)) {
2740+
/*
2741+
* We only need subslice count so it doesn't matter which ones
2742+
* we select - just turn off low bits in the amount of half of
2743+
* all available subslices per slice.
2744+
*/
2745+
out_sseu->subslice_mask =
2746+
~(~0 << (hweight8(out_sseu->subslice_mask) / 2));
2747+
out_sseu->slice_mask = 0x1;
2748+
}
2749+
}
2750+
2751+
static int
2752+
get_sseu_config(struct intel_sseu *out_sseu,
2753+
struct intel_engine_cs *engine,
2754+
const struct drm_i915_gem_context_param_sseu *drm_sseu)
2755+
{
2756+
if (drm_sseu->engine.engine_class != engine->uabi_class ||
2757+
drm_sseu->engine.engine_instance != engine->uabi_instance)
2758+
return -EINVAL;
2759+
2760+
return i915_gem_user_to_context_sseu(engine->i915, drm_sseu, out_sseu);
2761+
}
2762+
27232763
/**
27242764
* i915_oa_stream_init - validate combined props for OA stream and init
27252765
* @stream: An i915 perf stream
@@ -2852,6 +2892,8 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
28522892
goto err_oa_buf_alloc;
28532893

28542894
stream->ops = &i915_oa_stream_ops;
2895+
2896+
perf->sseu = props->sseu;
28552897
WRITE_ONCE(perf->exclusive_stream, stream);
28562898

28572899
ret = i915_perf_stream_enable_sync(stream);
@@ -3397,6 +3439,14 @@ i915_perf_open_ioctl_locked(struct i915_perf *perf,
33973439
privileged_op = true;
33983440
}
33993441

3442+
/*
3443+
* Asking for SSEU configuration is a priviliged operation.
3444+
*/
3445+
if (props->has_sseu)
3446+
privileged_op = true;
3447+
else
3448+
get_default_sseu_config(&props->sseu, props->engine);
3449+
34003450
/* Similar to perf's kernel.perf_paranoid_cpu sysctl option
34013451
* we check a dev.i915.perf_stream_paranoid sysctl option
34023452
* to determine if it's ok to access system wide OA counters
@@ -3492,6 +3542,7 @@ static int read_properties_unlocked(struct i915_perf *perf,
34923542
{
34933543
u64 __user *uprop = uprops;
34943544
u32 i;
3545+
int ret;
34953546

34963547
memset(props, 0, sizeof(struct perf_open_properties));
34973548

@@ -3523,7 +3574,6 @@ static int read_properties_unlocked(struct i915_perf *perf,
35233574
for (i = 0; i < n_props; i++) {
35243575
u64 oa_period, oa_freq_hz;
35253576
u64 id, value;
3526-
int ret;
35273577

35283578
ret = get_user(id, uprop);
35293579
if (ret)
@@ -3609,6 +3659,24 @@ static int read_properties_unlocked(struct i915_perf *perf,
36093659
case DRM_I915_PERF_PROP_HOLD_PREEMPTION:
36103660
props->hold_preemption = !!value;
36113661
break;
3662+
case DRM_I915_PERF_PROP_GLOBAL_SSEU: {
3663+
struct drm_i915_gem_context_param_sseu user_sseu;
3664+
3665+
if (copy_from_user(&user_sseu,
3666+
u64_to_user_ptr(value),
3667+
sizeof(user_sseu))) {
3668+
DRM_DEBUG("Unable to copy global sseu parameter\n");
3669+
return -EFAULT;
3670+
}
3671+
3672+
ret = get_sseu_config(&props->sseu, props->engine, &user_sseu);
3673+
if (ret) {
3674+
DRM_DEBUG("Invalid SSEU configuration\n");
3675+
return ret;
3676+
}
3677+
props->has_sseu = true;
3678+
break;
3679+
}
36123680
case DRM_I915_PERF_PROP_MAX:
36133681
MISSING_CASE(id);
36143682
return -EINVAL;
@@ -4382,8 +4450,12 @@ int i915_perf_ioctl_version(void)
43824450
* preemption on a particular context so that performance data is
43834451
* accessible from a delta of MI_RPC reports without looking at the
43844452
* OA buffer.
4453+
*
4454+
* 4: Add DRM_I915_PERF_PROP_ALLOWED_SSEU to limit what contexts can
4455+
* be run for the duration of the performance recording based on
4456+
* their SSEU configuration.
43854457
*/
4386-
return 3;
4458+
return 4;
43874459
}
43884460

43894461
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)

‎drivers/gpu/drm/i915/i915_perf_types.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/uuid.h>
1717
#include <linux/wait.h>
1818

19+
#include "gt/intel_sseu.h"
1920
#include "i915_reg.h"
2021
#include "intel_wakeref.h"
2122

@@ -407,6 +408,12 @@ struct i915_perf {
407408
*/
408409
struct i915_perf_stream *exclusive_stream;
409410

411+
/**
412+
* @sseu: sseu configuration selected to run while perf is active,
413+
* applies to all contexts.
414+
*/
415+
struct intel_sseu sseu;
416+
410417
/**
411418
* For rate limiting any notifications of spurious
412419
* invalid OA reports

‎include/uapi/drm/i915_drm.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,17 @@ enum drm_i915_perf_property_id {
19691969
*/
19701970
DRM_I915_PERF_PROP_HOLD_PREEMPTION,
19711971

1972+
/**
1973+
* Specifying this pins all contexts to the specified SSEU power
1974+
* configuration for the duration of the recording.
1975+
*
1976+
* This parameter's value is a pointer to a struct
1977+
* drm_i915_gem_context_param_sseu.
1978+
*
1979+
* This property is available in perf revision 4.
1980+
*/
1981+
DRM_I915_PERF_PROP_GLOBAL_SSEU,
1982+
19721983
DRM_I915_PERF_PROP_MAX /* non-ABI */
19731984
};
19741985

0 commit comments

Comments
 (0)