Skip to content

Commit 5637797

Browse files
committed
drm/xe/oa/uapi: Expose an unblock after N reports OA property
Expose an "unblock after N reports" OA property, to allow userspace threads to be woken up less frequently. Co-developed-by: Umesh Nerlige Ramappa <[email protected]> Signed-off-by: Umesh Nerlige Ramappa <[email protected]> Signed-off-by: Ashutosh Dixit <[email protected]> Reviewed-by: Jonathan Cavitt <[email protected]> Reviewed-by: Umesh Nerlige Ramappa <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent d9a1ae0 commit 5637797

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

drivers/gpu/drm/xe/xe_oa.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct xe_oa_open_param {
9797
int num_syncs;
9898
struct xe_sync_entry *syncs;
9999
size_t oa_buffer_size;
100+
int wait_num_reports;
100101
};
101102

102103
struct xe_oa_config_bo {
@@ -241,11 +242,10 @@ static void oa_timestamp_clear(struct xe_oa_stream *stream, u32 *report)
241242
static bool xe_oa_buffer_check_unlocked(struct xe_oa_stream *stream)
242243
{
243244
u32 gtt_offset = xe_bo_ggtt_addr(stream->oa_buffer.bo);
245+
u32 tail, hw_tail, partial_report_size, available;
244246
int report_size = stream->oa_buffer.format->size;
245-
u32 tail, hw_tail;
246247
unsigned long flags;
247248
bool pollin;
248-
u32 partial_report_size;
249249

250250
spin_lock_irqsave(&stream->oa_buffer.ptr_lock, flags);
251251

@@ -289,8 +289,8 @@ static bool xe_oa_buffer_check_unlocked(struct xe_oa_stream *stream)
289289

290290
stream->oa_buffer.tail = tail;
291291

292-
pollin = xe_oa_circ_diff(stream, stream->oa_buffer.tail,
293-
stream->oa_buffer.head) >= report_size;
292+
available = xe_oa_circ_diff(stream, stream->oa_buffer.tail, stream->oa_buffer.head);
293+
pollin = available >= stream->wait_num_reports * report_size;
294294

295295
spin_unlock_irqrestore(&stream->oa_buffer.ptr_lock, flags);
296296

@@ -1285,6 +1285,17 @@ static int xe_oa_set_prop_oa_buffer_size(struct xe_oa *oa, u64 value,
12851285
return 0;
12861286
}
12871287

1288+
static int xe_oa_set_prop_wait_num_reports(struct xe_oa *oa, u64 value,
1289+
struct xe_oa_open_param *param)
1290+
{
1291+
if (!value) {
1292+
drm_dbg(&oa->xe->drm, "wait_num_reports %llu\n", value);
1293+
return -EINVAL;
1294+
}
1295+
param->wait_num_reports = value;
1296+
return 0;
1297+
}
1298+
12881299
static int xe_oa_set_prop_ret_inval(struct xe_oa *oa, u64 value,
12891300
struct xe_oa_open_param *param)
12901301
{
@@ -1306,6 +1317,7 @@ static const xe_oa_set_property_fn xe_oa_set_property_funcs_open[] = {
13061317
[DRM_XE_OA_PROPERTY_NUM_SYNCS] = xe_oa_set_prop_num_syncs,
13071318
[DRM_XE_OA_PROPERTY_SYNCS] = xe_oa_set_prop_syncs_user,
13081319
[DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE] = xe_oa_set_prop_oa_buffer_size,
1320+
[DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS] = xe_oa_set_prop_wait_num_reports,
13091321
};
13101322

13111323
static const xe_oa_set_property_fn xe_oa_set_property_funcs_config[] = {
@@ -1321,6 +1333,7 @@ static const xe_oa_set_property_fn xe_oa_set_property_funcs_config[] = {
13211333
[DRM_XE_OA_PROPERTY_NUM_SYNCS] = xe_oa_set_prop_num_syncs,
13221334
[DRM_XE_OA_PROPERTY_SYNCS] = xe_oa_set_prop_syncs_user,
13231335
[DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE] = xe_oa_set_prop_ret_inval,
1336+
[DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS] = xe_oa_set_prop_ret_inval,
13241337
};
13251338

13261339
static int xe_oa_user_ext_set_property(struct xe_oa *oa, enum xe_oa_user_extn_from from,
@@ -1797,6 +1810,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,
17971810
stream->periodic = param->period_exponent > 0;
17981811
stream->period_exponent = param->period_exponent;
17991812
stream->no_preempt = param->no_preempt;
1813+
stream->wait_num_reports = param->wait_num_reports;
18001814

18011815
stream->xef = xe_file_get(param->xef);
18021816
stream->num_syncs = param->num_syncs;
@@ -2156,6 +2170,14 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, u64 data, struct drm_file *f
21562170
if (!param.oa_buffer_size)
21572171
param.oa_buffer_size = DEFAULT_XE_OA_BUFFER_SIZE;
21582172

2173+
if (!param.wait_num_reports)
2174+
param.wait_num_reports = 1;
2175+
if (param.wait_num_reports > param.oa_buffer_size / f->size) {
2176+
drm_dbg(&oa->xe->drm, "wait_num_reports %d\n", param.wait_num_reports);
2177+
ret = -EINVAL;
2178+
goto err_exec_q;
2179+
}
2180+
21592181
ret = xe_oa_parse_syncs(oa, &param);
21602182
if (ret)
21612183
goto err_exec_q;

drivers/gpu/drm/xe/xe_oa_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ struct xe_oa_stream {
218218
/** @pollin: Whether there is data available to read */
219219
bool pollin;
220220

221+
/** @wait_num_reports: Number of reports to wait for before signalling pollin */
222+
int wait_num_reports;
223+
221224
/** @periodic: Whether periodic sampling is currently enabled */
222225
bool periodic;
223226

drivers/gpu/drm/xe/xe_query.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ static int query_oa_units(struct xe_device *xe,
672672
du->oa_unit_type = u->type;
673673
du->oa_timestamp_freq = xe_oa_timestamp_frequency(gt);
674674
du->capabilities = DRM_XE_OA_CAPS_BASE | DRM_XE_OA_CAPS_SYNCS |
675-
DRM_XE_OA_CAPS_OA_BUFFER_SIZE;
675+
DRM_XE_OA_CAPS_OA_BUFFER_SIZE |
676+
DRM_XE_OA_CAPS_WAIT_NUM_REPORTS;
676677

677678
j = 0;
678679
for_each_hw_engine(hwe, gt, hwe_id) {

include/uapi/drm/xe_drm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,7 @@ struct drm_xe_oa_unit {
14871487
#define DRM_XE_OA_CAPS_BASE (1 << 0)
14881488
#define DRM_XE_OA_CAPS_SYNCS (1 << 1)
14891489
#define DRM_XE_OA_CAPS_OA_BUFFER_SIZE (1 << 2)
1490+
#define DRM_XE_OA_CAPS_WAIT_NUM_REPORTS (1 << 3)
14901491

14911492
/** @oa_timestamp_freq: OA timestamp freq */
14921493
__u64 oa_timestamp_freq;
@@ -1660,6 +1661,12 @@ enum drm_xe_oa_property_id {
16601661
* buffer is allocated by default.
16611662
*/
16621663
DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE,
1664+
1665+
/**
1666+
* @DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS: Number of reports to wait
1667+
* for before unblocking poll or read
1668+
*/
1669+
DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS,
16631670
};
16641671

16651672
/**

0 commit comments

Comments
 (0)