Skip to content

Commit 62eaf0a

Browse files
mbrost05johnharr-intel
authored andcommitted
drm/i915/guc: Support request cancellation
This adds GuC backend support for i915_request_cancel(), which in turn makes CONFIG_DRM_I915_REQUEST_TIMEOUT work. This implementation makes use of fence while there are likely simplier options. A fence was chosen because of another feature coming soon which requires a user to block on a context until scheduling is disabled. In that case we return the fence to the user and the user can wait on that fence. v2: (Daniele) - A comment about locking the blocked incr / decr - A comments about the use of the fence - Update commit message explaining why fence - Delete redundant check blocked count in unblock function - Ring buffer implementation - Comment about blocked in submission path - Shorter rpm path v3: (Checkpatch) - Fix typos in commit message (Daniel) - Rework to simplier locking structure in guc_context_block / unblock Signed-off-by: Matthew Brost <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Reviewed-by: Daniele Ceraolo Spurio <[email protected]> Signed-off-by: John Harrison <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent ae8ac10 commit 62eaf0a

File tree

7 files changed

+251
-14
lines changed

7 files changed

+251
-14
lines changed

drivers/gpu/drm/i915/gt/intel_context.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ static int __intel_context_active(struct i915_active *active)
366366
return 0;
367367
}
368368

369+
static int sw_fence_dummy_notify(struct i915_sw_fence *sf,
370+
enum i915_sw_fence_notify state)
371+
{
372+
return NOTIFY_DONE;
373+
}
374+
369375
void
370376
intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
371377
{
@@ -399,6 +405,13 @@ intel_context_init(struct intel_context *ce, struct intel_engine_cs *engine)
399405
ce->guc_id = GUC_INVALID_LRC_ID;
400406
INIT_LIST_HEAD(&ce->guc_id_link);
401407

408+
/*
409+
* Initialize fence to be complete as this is expected to be complete
410+
* unless there is a pending schedule disable outstanding.
411+
*/
412+
i915_sw_fence_init(&ce->guc_blocked, sw_fence_dummy_notify);
413+
i915_sw_fence_commit(&ce->guc_blocked);
414+
402415
i915_active_init(&ce->active,
403416
__intel_context_active, __intel_context_retire, 0);
404417
}

drivers/gpu/drm/i915/gt/intel_context.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ intel_context_is_pinned(struct intel_context *ce)
7070
return atomic_read(&ce->pin_count);
7171
}
7272

73+
static inline void intel_context_cancel_request(struct intel_context *ce,
74+
struct i915_request *rq)
75+
{
76+
GEM_BUG_ON(!ce->ops->cancel_request);
77+
return ce->ops->cancel_request(ce, rq);
78+
}
79+
7380
/**
7481
* intel_context_unlock_pinned - Releases the earlier locking of 'pinned' status
7582
* @ce - the context

drivers/gpu/drm/i915/gt/intel_context_types.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/types.h>
1414

1515
#include "i915_active_types.h"
16+
#include "i915_sw_fence.h"
1617
#include "i915_utils.h"
1718
#include "intel_engine_types.h"
1819
#include "intel_sseu.h"
@@ -42,6 +43,9 @@ struct intel_context_ops {
4243
void (*unpin)(struct intel_context *ce);
4344
void (*post_unpin)(struct intel_context *ce);
4445

46+
void (*cancel_request)(struct intel_context *ce,
47+
struct i915_request *rq);
48+
4549
void (*enter)(struct intel_context *ce);
4650
void (*exit)(struct intel_context *ce);
4751

@@ -156,7 +160,7 @@ struct intel_context {
156160
* sched_state: scheduling state of this context using GuC
157161
* submission
158162
*/
159-
u8 sched_state;
163+
u16 sched_state;
160164
/*
161165
* fences: maintains of list of requests that have a submit
162166
* fence related to GuC submission
@@ -184,6 +188,9 @@ struct intel_context {
184188
* GuC ID link - in list when unpinned but guc_id still valid in GuC
185189
*/
186190
struct list_head guc_id_link;
191+
192+
/* GuC context blocked fence */
193+
struct i915_sw_fence guc_blocked;
187194
};
188195

189196
#endif /* __INTEL_CONTEXT_TYPES__ */

drivers/gpu/drm/i915/gt/intel_execlists_submission.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
#include "gen8_engine_cs.h"
115115
#include "intel_breadcrumbs.h"
116116
#include "intel_context.h"
117+
#include "intel_engine_heartbeat.h"
117118
#include "intel_engine_pm.h"
118119
#include "intel_engine_stats.h"
119120
#include "intel_execlists_submission.h"
@@ -2587,11 +2588,26 @@ static int execlists_context_alloc(struct intel_context *ce)
25872588
return lrc_alloc(ce, ce->engine);
25882589
}
25892590

2591+
static void execlists_context_cancel_request(struct intel_context *ce,
2592+
struct i915_request *rq)
2593+
{
2594+
struct intel_engine_cs *engine = NULL;
2595+
2596+
i915_request_active_engine(rq, &engine);
2597+
2598+
if (engine && intel_engine_pulse(engine))
2599+
intel_gt_handle_error(engine->gt, engine->mask, 0,
2600+
"request cancellation by %s",
2601+
current->comm);
2602+
}
2603+
25902604
static const struct intel_context_ops execlists_context_ops = {
25912605
.flags = COPS_HAS_INFLIGHT,
25922606

25932607
.alloc = execlists_context_alloc,
25942608

2609+
.cancel_request = execlists_context_cancel_request,
2610+
25952611
.pre_pin = execlists_context_pre_pin,
25962612
.pin = execlists_context_pin,
25972613
.unpin = lrc_unpin,
@@ -3608,6 +3624,8 @@ static const struct intel_context_ops virtual_context_ops = {
36083624

36093625
.alloc = virtual_context_alloc,
36103626

3627+
.cancel_request = execlists_context_cancel_request,
3628+
36113629
.pre_pin = virtual_context_pre_pin,
36123630
.pin = virtual_context_pin,
36133631
.unpin = lrc_unpin,

drivers/gpu/drm/i915/gt/intel_ring_submission.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "intel_reset.h"
1717
#include "intel_ring.h"
1818
#include "shmem_utils.h"
19+
#include "intel_engine_heartbeat.h"
1920

2021
/* Rough estimate of the typical request size, performing a flush,
2122
* set-context and then emitting the batch.
@@ -604,9 +605,24 @@ static void ring_context_ban(struct intel_context *ce,
604605
}
605606
}
606607

608+
static void ring_context_cancel_request(struct intel_context *ce,
609+
struct i915_request *rq)
610+
{
611+
struct intel_engine_cs *engine = NULL;
612+
613+
i915_request_active_engine(rq, &engine);
614+
615+
if (engine && intel_engine_pulse(engine))
616+
intel_gt_handle_error(engine->gt, engine->mask, 0,
617+
"request cancellation by %s",
618+
current->comm);
619+
}
620+
607621
static const struct intel_context_ops ring_context_ops = {
608622
.alloc = ring_context_alloc,
609623

624+
.cancel_request = ring_context_cancel_request,
625+
610626
.ban = ring_context_ban,
611627

612628
.pre_pin = ring_context_pre_pin,

0 commit comments

Comments
 (0)