Basic GuC submission support in the i915
Subsystems (3)
Re: [RFC PATCH 32/97] drm/i915: Introduce i915_sched_engine object
In reply to Matthew BrostQuoted 4 lines · Matthew Brost
Introduce
i915_sched_engineobject which is lower level data structure thati915_scheduler/ generic code can operate on without touching execlist specific structures. This allows additional submission backends to be added without breaking the layer.
Maybe add a comment here that this is defacto a detour since we're now aiming to use drm/scheduler instead. But also since the current code is a bit a mess, we expect this detour to be overall faster since we can then refactor in-tree.
Maybe also highlight this a bit more in the rfc to make sure this is clear.
-Daniel
Quoted 2,705 lines
Cc Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 +- drivers/gpu/drm/i915/gt/intel_engine.h | 16 - drivers/gpu/drm/i915/gt/intel_engine_cs.c | 77 ++-- .../gpu/drm/i915/gt/intel_engine_heartbeat.c | 4 +- drivers/gpu/drm/i915/gt/intel_engine_pm.c | 10 +- drivers/gpu/drm/i915/gt/intel_engine_types.h | 42 +-- drivers/gpu/drm/i915/gt/intel_engine_user.c | 2 +- .../drm/i915/gt/intel_execlists_submission.c | 350 +++++++++++------- .../gpu/drm/i915/gt/intel_ring_submission.c | 13 +- drivers/gpu/drm/i915/gt/mock_engine.c | 17 +- drivers/gpu/drm/i915/gt/selftest_execlists.c | 36 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 6 +- drivers/gpu/drm/i915/gt/selftest_lrc.c | 6 +- drivers/gpu/drm/i915/gt/selftest_reset.c | 2 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 75 ++-- drivers/gpu/drm/i915/i915_gpu_error.c | 7 +- drivers/gpu/drm/i915/i915_request.c | 50 +-- drivers/gpu/drm/i915/i915_request.h | 2 +- drivers/gpu/drm/i915/i915_scheduler.c | 168 ++++----- drivers/gpu/drm/i915/i915_scheduler.h | 65 +++- drivers/gpu/drm/i915/i915_scheduler_types.h | 63 ++++ 21 files changed, 575 insertions(+), 440 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_wait.c +2
-2@@ -104,8 +104,8 @@ static void fence_set_priority(struct dma_fence *fence, engine = rq->engine;rcu_read_lock ();/* RCU serialisation for set-wedged protection */ -if (engine->schedule) - engine->schedule (rq, attr); +if (engine->sched_engine->schedule) + engine->sched_engine->schedule (rq, attr);rcu_read_unlock (); }drivers/gpu/drm/i915/gt/intel_engine.h +0
-16@@ -123,20 +123,6 @@ execlists_active(const struct intel_engine_execlists *execlists)return active; } -static inline void -execlists_active_lock_bh (struct intel_engine_execlists *execlists) -{ -local_bh_disable ();/* prevent local softirq and lock recursion */ -tasklet_lock (&execlists->tasklet); -} - -static inline void -execlists_active_unlock_bh (struct intel_engine_execlists *execlists) -{ -tasklet_unlock (&execlists->tasklet); -local_bh_enable ();/* restore softirq, and kick ksoftirqd! */ -} -struct i915_request *execlists_unwind_incomplete_requests (struct intel_engine_execlists *execlists);@@ -257,8 +243,6 @@ intel_engine_find_active_request(struct intel_engine_cs *engine);u32 intel_engine_context_size (struct intel_gt *gt,u8 class); -void intel_engine_init_active (struct intel_engine_cs *engine, -unsigned int subclass);#define ENGINE_PHYSICAL 0#define ENGINE_MOCK 1#define ENGINE_VIRTUAL 2drivers/gpu/drm/i915/gt/intel_engine_cs.c +30
-47@@ -8,6 +8,7 @@#include "gem/i915_gem_context.h" #include "i915_drv.h" +#include "i915_scheduler.h" #include "intel_breadcrumbs.h" #include "intel_context.h" @@ -326,9 +327,6 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)if (engine->context_size)DRIVER_CAPS (i915)->has_logical_contexts = true; -/* Nothing to do here, execute in order of dependencies */ - engine->schedule =NULL ; -ewma__engine_latency_init (&engine->latency);seqcount_init (&engine->stats.lock);@@ -583,9 +581,6 @@ void intel_engine_init_execlists(struct intel_engine_cs *engine)memset (execlists->pending,0 ,sizeof (execlists->pending)); execlists->active =memset (execlists->inflight,0 ,sizeof (execlists->inflight)); - - execlists->queue_priority_hint =INT_MIN ; - execlists->queue =RB_ROOT_CACHED ; }static void cleanup_status_page (struct intel_engine_cs *engine)@@ -712,11 +707,17 @@ static int engine_setup_common(struct intel_engine_cs *engine) goto err_status; } + engine->sched_engine =i915_sched_engine_create (ENGINE_PHYSICAL ); +if (!engine->sched_engine) { + err = -ENOMEM ; + goto err_sched_engine; + } + engine->sched_engine->engine = engine; + err =intel_engine_init_cmd_parser (engine);if (err) goto err_cmd_parser; -intel_engine_init_active (engine,ENGINE_PHYSICAL );intel_engine_init_execlists (engine);intel_engine_init__pm (engine);intel_engine_init_retire (engine);@@ -735,6 +736,8 @@ static int engine_setup_common(struct intel_engine_cs *engine)return 0 ; err_cmd_parser: +i915_sched_engine_put (engine->sched_engine); +err_sched_engine:intel_breadcrumbs_free (engine->breadcrumbs); err_status:cleanup_status_page (engine);@@ -773,11 +776,11 @@ static int measure_breadcrumb_dw(struct intel_context *ce) frame->rq.ring = &frame->ring;mutex_lock (&ce->timeline->mutex); -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock); dw = engine->emit_fini_breadcrumb (&frame->rq, frame->cs) - frame->cs; -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock);mutex_unlock (&ce->timeline->mutex);GEM_BUG_ON (dw &1 );/* RING_TAIL must be qword aligned */ @@ -786,28 +789,6 @@ static int measure_breadcrumb_dw(struct intel_context *ce)return dw; } -void -intel_engine_init_active (struct intel_engine_cs *engine,unsigned int subclass) -{ -INIT_LIST_HEAD (&engine->active.requests); -INIT_LIST_HEAD (&engine->active.hold); - -spin_lock_init (&engine->active.lock); -lockdep_set_subclass (&engine->active.lock, subclass); - -/* -* Due to an interesting quirk in lockdep's internal debug tracking, -* after setting a subclass we must ensure the lock is used. Otherwise, -* nr_unused_locks is incremented once too often. -*/ -#ifdef CONFIG_DEBUG_LOCK_ALLOC -local_irq_disable (); -lock_map_acquire (&engine->active.lock.dep_map); -lock_map_release (&engine->active.lock.dep_map); -local_irq_enable (); -#endif -} -static struct intel_context * create_pinned_context(struct intel_engine_cs *engine, unsigned int hwsp,@@ -955,10 +936,10 @@ int intel_engines_init(struct intel_gt *gt)*/ void intel_engine_cleanup_common (struct intel_engine_cs *engine) { -GEM_BUG_ON (!list_empty (&engine->active.requests)); -tasklet_kill (&engine->execlists.tasklet);/* flush the callback */ +GEM_BUG_ON (!list_empty (&engine->sched_engine->requests));intel_breadcrumbs_free (engine->breadcrumbs); +i915_sched_engine_put (engine->sched_engine);intel_engine_fini_retire (engine);intel_engine_cleanup_cmd_parser (engine);@@ -1241,7 +1222,7 @@ static bool ring_is_idle(struct intel_engine_cs *engine)void __intel_engine_flush_submission (struct intel_engine_cs *engine,bool sync) { -struct tasklet_struct *t = &engine->execlists.tasklet; +struct tasklet_struct *t = &engine->sched_engine->tasklet;if (!t->callback)return ;@@ -1281,7 +1262,7 @@ bool intel_engine_is_idle(struct intel_engine_cs *engine)intel_engine_flush_submission (engine);/* ELSP is empty, but there are ready requests? E.g. after reset */ -if (!RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)) +if (!i915_sched_engine_is_empty (engine->sched_engine))return false;/* Ring stopped? */ @@ -1347,7 +1328,7 @@ static struct intel_timeline *get_timeline(struct i915_request *rq)struct intel_timeline *tl;/* -* Even though we are holding the engine->active.lock here, there +* Even though we are holding the engine->sched_engine->lock here, there * is no control over the submission queue per-se and we are * inspecting the active state at a random point in time, with an * unknown queue. Play safe and make sure the timeline remains valid. @@ -1502,10 +1483,10 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,drm_printf (m,"\tExeclist tasklet queued? %s (%s), preempt? %s, timeslice? %s\n" ,yesno (test_bit (TASKLET_STATE_SCHED , - &engine->execlists.tasklet.state)), -enableddisabled (!atomic_read (&engine->execlists.tasklet.count)), -repr_timer (&engine->execlists.preempt), -repr_timer (&engine->execlists.timer)); + &engine->sched_engine->tasklet.state)), +enableddisabled (!atomic_read (&engine->sched_engine->tasklet.count)), +repr_timer (&execlists->preempt), +repr_timer (&execlists->timer)); read = execlists->csb_head; write =READ_ONCE (*execlists->csb_write);@@ -1527,7 +1508,7 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine, idx, hws[idx * 2], hws[idx * 2 + 1]); } -execlists_active_lock_bh (execlists); +sched_engine_active_lock_bh (engine->sched_engine);rcu_read_lock ();for (port = execlists->active; (rq = *port); port++) {char hdr[160 ];@@ -1558,7 +1539,7 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,i915_request_show (m, rq, hdr,0 ); }rcu_read_unlock (); -execlists_active_unlock_bh (execlists); +sched_engine_active_unlock_bh (engine->sched_engine); }else if (INTEL_GEN (dev_priv) >6 ) {drm_printf (m,"\tPP_DIR_BASE: 0x%08x\n" ,ENGINE_READ (engine,RING_PP_DIR_BASE ));@@ -1694,7 +1675,7 @@ void intel_engine_dump(struct intel_engine_cs *engine,drm_printf (m,"\tRequests:\n" ); -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags); rq =intel_engine_find_active_request (engine);if (rq) {struct intel_timeline *tl =get_timeline (rq);@@ -1725,8 +1706,9 @@ void intel_engine_dump(struct intel_engine_cs *engine,hexdump (m, rq->context->lrc_reg_state,PAGE_SIZE ); } } -drm_printf (m,"\tOn hold?: %lu\n" ,list_count (&engine->active.hold)); -spin_unlock_irqrestore (&engine->active.lock, flags); +drm_printf (m,"\tOn hold?: %lu\n" , +list_count (&engine->sched_engine->hold)); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags);drm_printf (m,"\tMMIO base: 0x%08x\n" , engine->mmio_base); wakeref =intel_runtime_pm_get_if_in_use (engine->uncore->rpm);@@ -1806,7 +1788,7 @@ intel_engine_find_active_request(struct intel_engine_cs *engine)* At all other times, we must assume the GPU is still running, but * we only care about the snapshot of this moment. */ -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);rcu_read_lock (); request =execlists_active (&engine->execlists);@@ -1824,7 +1806,8 @@ intel_engine_find_active_request(struct intel_engine_cs *engine)if (active)return active; -list_for_each_entry (request, &engine->active.requests, sched.link) { +list_for_each_entry (request, &engine->sched_engine->requests, + sched.link) {if (__i915_request_is_complete (request))continue ;drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +2
-2@@ -121,7 +121,7 @@ static void heartbeat(struct work_struct *wrk)* but all other contexts, including the kernel * context are stuck waiting for the signal. */ - }else if (engine->schedule && + }else if (engine->sched_engine->schedule && rq->sched.attr.priority <I915_PRIORITY_BARRIER ) {/* * Gradually raise the priority of the heartbeat to @@ -136,7 +136,7 @@ static void heartbeat(struct work_struct *wrk) attr.priority =I915_PRIORITY_BARRIER ;local_bh_disable (); - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);local_bh_enable (); }else {if (IS_ENABLED (CONFIG_DRM_I915_DEBUG_GEM ))drivers/gpu/drm/i915/gt/intel_engine_pm.c +6
-4@@ -274,14 +274,16 @@ static int __engine_park(struct intel_wakeref *wf)intel_engine_park_heartbeat (engine);intel_breadcrumbs_park (engine->breadcrumbs); -/* Must be reset upon idling, or we may miss the busy wakeup. */ -GEM_BUG_ON (engine->execlists.queue_priority_hint !=INT_MIN ); +/* +* XXX: Must be reset upon idling, or we may miss the busy wakeup. +* queue_priority_hint only used in execlists submission but works in +* other modes as default is INT_MIN. +*/ +GEM_BUG_ON (engine->sched_engine->queue_priority_hint !=INT_MIN );if (engine->park) engine->park (engine); - engine->execlists.no_priolist = false; -/* While gt calls i915_vma_parked(), we have to break the lock cycle */ intel_gt_pm_put_async (engine->gt);return 0 ;drivers/gpu/drm/i915/gt/intel_engine_types.h +3
-39@@ -59,6 +59,7 @@ struct drm_i915_reg_table;struct i915_gem_context ;struct i915_request ;struct i915_sched_attr ; +struct i915_sched_engine ;struct intel_gt ;struct intel_ring ;struct intel_uncore ;@@ -137,11 +138,6 @@ struct st_preempt_hang {* driver and the hardware state for execlist mode of submission. */ struct intel_engine_execlists { -/** -* @tasklet: softirq tasklet for bottom handler -*/ -struct tasklet_struct tasklet; -/** * @timer: kick the current context if its timeslice expires */ @@ -152,11 +148,6 @@ struct intel_engine_execlists {*/ struct timer_list preempt; -/** -* @default_priolist: priority list for I915_PRIORITY_NORMAL -*/ -struct i915_priolist default_priolist; -/** * @ccid: identifier for contexts submitted to this engine */ @@ -191,11 +182,6 @@ struct intel_engine_execlists {*/ u32 reset_ccid; -/** -* @no_priolist: priority lists disabled -*/ -bool no_priolist; -/** * @submit_reg: gen-specific execlist submission register * set to the ExecList Submission Port (elsp) register pre-Gen11 and to @@ -238,23 +224,8 @@ struct intel_engine_execlists {unsigned int port_mask;/** -* @queue_priority_hint: Highest pending priority. -* -* When we add requests into the queue, or adjust the priority of -* executing requests, we compute the maximum priority of those -* pending requests. We can then use this value to determine if -* we need to preempt the executing requests to service the queue. -* However, since the we may have recorded the priority of an inflight -* request we wanted to preempt but since completed, at the time of -* dequeuing the priority hint may no longer may match the highest -* available request priority. +* @virtual: virtual of requests, in priority lists */ -int queue_priority_hint; - -/** -* @queue: queue of requests, in priority lists -*/ -struct rb_root_cached queue;struct rb_root_cached virtual;/** @@ -326,11 +297,7 @@ struct intel_engine_cs {struct intel_sseu sseu; -struct { -spinlock_t lock; -struct list_head requests; -struct list_head hold;/* ready requests, but on hold */ - } active; +struct i915_sched_engine *sched_engine;/* keep a request in reserve for a [pm] barrier under oom */ struct i915_request *request_pool;@@ -459,9 +426,6 @@ struct intel_engine_cs {* dependencies may need rescheduling. Note the request itself may * not be ready to run! */ -void (*schedule)(struct i915_request *request, -const struct i915_sched_attr *attr); -void (*release)(struct intel_engine_cs *engine);struct intel_engine_execlists execlists;drivers/gpu/drm/i915/gt/intel_engine_user.c +1
-1@@ -107,7 +107,7 @@ static void set_scheduler_caps(struct drm_i915_private *i915)for_each_uabi_engine (engine, i915) {/* all engines must agree! */ int i; -if (engine->schedule) +if (engine->sched_engine->schedule) enabled |= (I915_SCHEDULER_CAP_ENABLED |I915_SCHEDULER_CAP_PRIORITY );else drivers/gpu/drm/i915/gt/intel_execlists_submission.c +213
-137@@ -273,11 +273,11 @@ static int effective_prio(const struct i915_request *rq)return prio; } -static int queue_prio (const struct intel_engine_execlists *execlists) +static int queue_prio (const struct i915_sched_engine *sched_engine) {struct rb_node *rb; - rb =rb_first_cached (&execlists->queue); + rb =rb_first_cached (&sched_engine->queue);if (!rb)return INT_MIN ;@@ -318,14 +318,14 @@ static bool need_preempt(const struct intel_engine_cs *engine,* to preserve FIFO ordering of dependencies. */ last_prio =max (effective_prio (rq),I915_PRIORITY_NORMAL -1 ); -if (engine->execlists.queue_priority_hint <= last_prio) +if (engine->sched_engine->queue_priority_hint <= last_prio)return false;/* * Check against the first request in ELSP[1], it will, thanks to the * power of PI, be the highest priority of that context. */ -if (!list_is_last (&rq->sched.link, &engine->active.requests) && +if (!list_is_last (&rq->sched.link, &engine->sched_engine->requests) &&rq_prio (list_next_entry (rq, sched.link)) > last_prio)return true;@@ -340,7 +340,7 @@ static bool need_preempt(const struct intel_engine_cs *engine,* context, it's priority would not exceed ELSP[0] aka last_prio. */ return max (virtual_prio (&engine->execlists), -queue_prio (&engine->execlists)) > last_prio; +queue_prio (engine->sched_engine)) > last_prio; } __maybe_unused static bool@@ -367,10 +367,10 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)struct list_head *pl;int prio =I915_PRIORITY_INVALID ; -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);list_for_each_entry_safe_reverse (rq, rn, - &engine->active.requests, + &engine->sched_engine->requests, sched.link) {if (__i915_request_is_complete (rq)) {list_del_init (&rq->sched.link);@@ -382,9 +382,10 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID );if (rq_prio (rq) != prio) { prio =rq_prio (rq); - pl =i915_sched_lookup_priolist (engine, prio); + pl =i915_sched_lookup_priolist (engine->sched_engine, + prio); } -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine));list_move (&rq->sched.link, pl);set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags);@@ -534,13 +535,13 @@ resubmit_virtual_request(struct i915_request *rq, struct virtual_engine *ve) {struct intel_engine_cs *engine = rq->engine; -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock);clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags);WRITE_ONCE (rq->engine, &ve->base); ve->base.submit_request (rq); -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock); }static void kick_siblings (struct i915_request *rq,struct intel_context *ce)@@ -569,7 +570,7 @@ static void kick_siblings(struct i915_request *rq, struct intel_context *ce)resubmit_virtual_request (rq, ve);if (READ_ONCE (ve->request)) -tasklet_hi_schedule (&ve->base.execlists.tasklet); +i915_sched_engine_hi_kick (ve->base.sched_engine); } static void __execlists_schedule_out(struct i915_request * const rq,@@ -579,7 +580,7 @@ static void __execlists_schedule_out(struct i915_request * const rq,unsigned int ccid;/* -* NB process_csb() is not under the engine->active.lock and hence +* NB process_csb() is not under the engine->sched_engine->lock and hence * schedule_out can race with schedule_in meaning that we should * refrain from doing non-trivial work here. */ @@ -721,12 +722,11 @@ dump_port(char *buf, int buflen, const char *prefix, struct i915_request *rq) } static __maybe_unused noinline void -trace_ports (const struct intel_engine_execlists *execlists, +trace_ports (const struct intel_engine_cs *engine, +const struct intel_engine_execlists *execlists,const char *msg,struct i915_request *const *ports) { -const struct intel_engine_cs *engine = -container_of (execlists,typeof (*engine), execlists);char __maybe_unused p0[40 ], p1[40 ];if (!ports[0 ])@@ -738,25 +738,24 @@ trace_ports(const struct intel_engine_execlists *execlists, }static bool -reset_in_progress (const struct intel_engine_execlists *execlists) +reset_in_progress (const struct intel_engine_cs *engine) { -return unlikely (!__tasklet_is_enabled (&execlists->tasklet)); +return unlikely (!__tasklet_is_enabled (&engine->sched_engine->tasklet)); } static __maybe_unused noinline bool -assert_pending_valid (const struct intel_engine_execlists *execlists, +assert_pending_valid (struct intel_engine_cs *engine, +const struct intel_engine_execlists *execlists,const char *msg) { -struct intel_engine_cs *engine = -container_of (execlists,typeof (*engine), execlists);struct i915_request *const *port, *rq, *prev =NULL ;struct intel_context *ce =NULL ;u32 ccid =-1 ; -trace_ports (execlists, msg, execlists->pending); +trace_ports (engine, execlists, msg, execlists->pending);/* We may be messing around with the lists during reset, lalala */ -if (reset_in_progress (execlists)) +if (reset_in_progress (engine))return true;if (!execlists->pending[0 ]) {@@ -878,7 +877,7 @@ static void execlists_submit_ports(struct intel_engine_cs *engine)struct intel_engine_execlists *execlists = &engine->execlists;unsigned int n; -GEM_BUG_ON (!assert_pending_valid (execlists,"submit" )); +GEM_BUG_ON (!assert_pending_valid (engine, execlists,"submit" ));/* * We can skip acquiring intel_runtime_pm_get() here as it was taken @@ -1096,7 +1095,8 @@ static void defer_active(struct intel_engine_cs *engine)if (!rq)return ; -defer_request (rq,i915_sched_lookup_priolist (engine,rq_prio (rq))); +defer_request (rq,i915_sched_lookup_priolist (engine->sched_engine, +rq_prio (rq))); } static bool@@ -1133,13 +1133,14 @@ static bool needs_timeslice(const struct intel_engine_cs *engine,return false;/* If ELSP[1] is occupied, always check to see if worth slicing */ -if (!list_is_last_rcu (&rq->sched.link, &engine->active.requests)) { +if (!list_is_last_rcu (&rq->sched.link, + &engine->sched_engine->requests)) {ENGINE_TRACE (engine,"timeslice required for second inflight context\n" );return true; }/* Otherwise, ELSP[0] is by itself, but may be waiting in the queue */ -if (!RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)) { +if (!i915_sched_engine_is_empty (engine->sched_engine)) {ENGINE_TRACE (engine,"timeslice required for queue\n" );return true; }@@ -1187,7 +1188,7 @@ static void start_timeslice(struct intel_engine_cs *engine)* its timeslice, so recheck. */ if (!timer_pending (&el->timer)) -tasklet_hi_schedule (&el->tasklet); +i915_sched_engine_hi_kick (engine->sched_engine);return ; }@@ -1235,6 +1236,7 @@ static bool completed(const struct i915_request *rq)static void execlists_dequeue (struct intel_engine_cs *engine) { +struct i915_sched_engine *const sched_engine = engine->sched_engine;struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_request **port = execlists->pending;struct i915_request **const last_port = port + execlists->port_mask;@@ -1265,7 +1267,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* and context switches) submission. */ -spin_lock (&engine->active.lock); +spin_lock (&engine->sched_engine->lock);/* * If the queue is higher priority than the last @@ -1287,7 +1289,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine) last->fence.context, last->fence.seqno, last->sched.attr.priority, - execlists->queue_priority_hint); + sched_engine->queue_priority_hint);record_preemption (execlists);/* @@ -1313,7 +1315,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)yesno (timer_expired (&execlists->timer)), last->fence.context, last->fence.seqno,rq_prio (last), - execlists->queue_priority_hint, + sched_engine->queue_priority_hint, yesno(timeslice_yield(execlists, last)));/* @@ -1365,7 +1367,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* Even if ELSP[1] is occupied and not worthy * of timeslices, our queue might be. */ -spin_unlock (&engine->active.lock); +spin_unlock (&sched_engine->lock);return ; } }@@ -1375,7 +1377,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)while ((ve =first_virtual_engine (engine))) {struct i915_request *rq; -spin_lock (&ve->base.active.lock); +spin_lock (&ve->base.sched_engine->lock); rq = ve->request;if (unlikely (!virtual_matches (ve, rq, engine)))@@ -1384,14 +1386,14 @@ static void execlists_dequeue(struct intel_engine_cs *engine)GEM_BUG_ON (rq->engine != &ve->base);GEM_BUG_ON (rq->context != &ve->context); -if (unlikely (rq_prio (rq) <queue_prio (execlists))) { -spin_unlock (&ve->base.active.lock); +if (unlikely (rq_prio (rq) <queue_prio (sched_engine))) { +spin_unlock (&ve->base.sched_engine->lock);break ; }if (last && !can_merge_rq (last, rq)) { -spin_unlock (&ve->base.active.lock); -spin_unlock (&engine->active.lock); +spin_unlock (&ve->base.sched_engine->lock); +spin_unlock (&sched_engine->lock);return ;/* leave this for another sibling */ }@@ -1405,7 +1407,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine) yesno(engine != ve->siblings[0]));WRITE_ONCE (ve->request,NULL ); -WRITE_ONCE (ve->base.execlists.queue_priority_hint,INT_MIN ); +WRITE_ONCE (ve->base.sched_engine->queue_priority_hint,INT_MIN ); rb = &ve->nodes[engine->id].rb;rb_erase_cached (rb, &execlists->virtual);@@ -1437,7 +1439,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)i915_request_put (rq); unlock: -spin_unlock (&ve->base.active.lock); +spin_unlock (&ve->base.sched_engine->lock);/* * Hmm, we have a bunch of virtual engine requests, @@ -1450,7 +1452,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)break ; } -while ((rb =rb_first_cached (&execlists->queue))) { +while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;@@ -1529,7 +1531,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine) } } -rb_erase_cached (&p->node, &execlists->queue); +rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); } done:@@ -1551,8 +1553,9 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* request triggering preemption on the next dequeue (or subsequent * interrupt for secondary ports). */ - execlists->queue_priority_hint =queue_prio (execlists); -spin_unlock (&engine->active.lock); + sched_engine->queue_priority_hint =queue_prio (sched_engine); +i915_sched_engine_reset_on_empty (sched_engine); +spin_unlock (&sched_engine->lock);/* * We can skip poking the HW if we ended up with exactly the same set @@ -1767,8 +1770,8 @@ process_csb(struct intel_engine_cs *engine, struct i915_request **inactive)* access. Either we are inside the tasklet, or the tasklet is disabled * and we assume that is only inside the reset paths and so serialised. */ -GEM_BUG_ON (!tasklet_is_locked (&execlists->tasklet) && - !reset_in_progress (execlists)); +GEM_BUG_ON (!tasklet_is_locked (&engine->sched_engine->tasklet) && + !reset_in_progress (engine));/* * Note that csb_write, csb_status may be either in HWSP or mmio. @@ -1866,12 +1869,12 @@ process_csb(struct intel_engine_cs *engine, struct i915_request **inactive)smp_wmb ();/* notify execlists_active() */ /* cancel old inflight, prepare for switch */ -trace_ports (execlists,"preempted" , old); +trace_ports (engine, execlists,"preempted" , old);while (*old) *inactive++ = *old++;/* switch pending to inflight */ -GEM_BUG_ON (!assert_pending_valid (execlists,"promote" )); +GEM_BUG_ON (!assert_pending_valid (engine, execlists,"promote" ));copy_ports (execlists->inflight, execlists->pending,execlists_num_ports (execlists));@@ -1889,7 +1892,7 @@ process_csb(struct intel_engine_cs *engine, struct i915_request **inactive) }/* port0 completed, advanced to port1 */ -trace_ports (execlists,"completed" , execlists->active); +trace_ports (engine, execlists,"completed" , execlists->active);/* * We rely on the hardware being strongly @@ -1979,7 +1982,7 @@ static void __execlists_hold(struct i915_request *rq)__i915_request_unsubmit (rq);clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); -list_move_tail (&rq->sched.link, &rq->engine->active.hold); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->hold);i915_request_set_hold (rq);RQ_TRACE (rq,"on hold\n" );@@ -2016,7 +2019,7 @@ static bool execlists_hold(struct intel_engine_cs *engine,if (i915_request_on_hold (rq))return false; -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock);if (__i915_request_is_complete (rq)) {/* too late! */ rq =NULL ;@@ -2032,10 +2035,10 @@ static bool execlists_hold(struct intel_engine_cs *engine,GEM_BUG_ON (i915_request_on_hold (rq));GEM_BUG_ON (rq->engine != engine);__execlists_hold (rq); -GEM_BUG_ON (list_empty (&engine->active.hold)); +GEM_BUG_ON (list_empty (&engine->sched_engine->hold)); unlock: -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock);return rq; }@@ -2079,7 +2082,7 @@ static void __execlists_unhold(struct i915_request *rq)i915_request_clear_hold (rq);list_move_tail (&rq->sched.link, -i915_sched_lookup_priolist (rq->engine, +i915_sched_lookup_priolist (rq->engine->sched_engine,rq_prio (rq)));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags);@@ -2115,7 +2118,7 @@ static void __execlists_unhold(struct i915_request *rq)static void execlists_unhold (struct intel_engine_cs *engine,struct i915_request *rq) { -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock);/* * Move this request back to the priority queue, and all of its @@ -2123,12 +2126,12 @@ static void execlists_unhold(struct intel_engine_cs *engine,*/ __execlists_unhold (rq); -if (rq_prio (rq) > engine->execlists.queue_priority_hint) { - engine->execlists.queue_priority_hint =rq_prio (rq); -tasklet_hi_schedule (&engine->execlists.tasklet); +if (rq_prio (rq) > engine->sched_engine->queue_priority_hint) { + engine->sched_engine->queue_priority_hint =rq_prio (rq); +i915_sched_engine_hi_kick (engine->sched_engine); } -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock); }struct execlists_capture {@@ -2258,13 +2261,13 @@ static void execlists_capture(struct intel_engine_cs *engine)if (!cap)return ; -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock); cap->rq =active_context (engine,active_ccid (engine));if (cap->rq) { cap->rq =active_request (cap->rq->context->timeline, cap->rq); cap->rq =i915_request_get_rcu (cap->rq); } -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock);if (!cap->rq) goto err_free;@@ -2316,13 +2319,13 @@ static void execlists_reset(struct intel_engine_cs *engine, const char *msg)ENGINE_TRACE (engine,"reset for %s\n" , msg);/* Mark this tasklet as disabled to avoid waiting for it to complete */ -tasklet_disable_nosync (&engine->execlists.tasklet); +tasklet_disable_nosync (&engine->sched_engine->tasklet);ring_set_paused (engine,1 );/* Freeze the current request in place */ execlists_capture (engine);intel_engine_reset (engine, msg); -tasklet_enable (&engine->execlists.tasklet); +tasklet_enable (&engine->sched_engine->tasklet);clear_and_wake_up_bit (bit, lock); }@@ -2345,8 +2348,9 @@ static bool preempt_timeout(const struct intel_engine_cs *const engine)*/ static void execlists_submission_tasklet (struct tasklet_struct *t) { -struct intel_engine_cs *const engine = -from_tasklet (engine, t, execlists.tasklet); +struct i915_sched_engine *sched_engine = +from_tasklet (sched_engine, t, tasklet); +struct intel_engine_cs *const engine = sched_engine->engine;struct i915_request *post[2 *EXECLIST_MAX_PORTS ];struct i915_request **inactive;@@ -2421,13 +2425,16 @@ static void execlists_irq_handler(struct intel_engine_cs *engine, u16 iir)intel_engine_signal_breadcrumbs (engine);if (tasklet) -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); }static void __execlists_kick (struct intel_engine_execlists *execlists) { +struct intel_engine_cs *engine = +container_of (execlists,typeof (*engine), execlists); +/* Kick the tasklet for some interrupt coalescing and reset handling */ -tasklet_hi_schedule (&execlists->tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); }#define execlists_kick (t, member) \@@ -2448,19 +2455,20 @@ static void queue_request(struct intel_engine_cs *engine, {GEM_BUG_ON (!list_empty (&rq->sched.link));list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (engine,rq_prio (rq))); +i915_sched_lookup_priolist (engine->sched_engine, +rq_prio (rq)));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); }static bool submit_queue (struct intel_engine_cs *engine,const struct i915_request *rq) { -struct intel_engine_execlists *execlists = &engine->execlists; +struct i915_sched_engine *sched_engine = engine->sched_engine; -if (rq_prio (rq) <= execlists->queue_priority_hint) +if (rq_prio (rq) <= sched_engine->queue_priority_hint)return false; - execlists->queue_priority_hint =rq_prio (rq); + sched_engine->queue_priority_hint =rq_prio (rq);return true; }@@ -2468,7 +2476,7 @@ static bool ancestor_on_hold(const struct intel_engine_cs *engine, const struct i915_request *rq) {GEM_BUG_ON (i915_request_on_hold (rq)); -return !list_empty (&engine->active.hold) &&hold_request (rq); +return !list_empty (&engine->sched_engine->hold) &&hold_request (rq); }static void execlists_submit_request (struct i915_request *request)@@ -2477,23 +2485,24 @@ static void execlists_submit_request(struct i915_request *request)unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);if (unlikely (ancestor_on_hold (engine, request))) {RQ_TRACE (request,"ancestor on hold\n" ); -list_add_tail (&request->sched.link, &engine->active.hold); +list_add_tail (&request->sched.link, + &engine->sched_engine->hold);i915_request_set_hold (request); }else {queue_request (engine, request); -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine));GEM_BUG_ON (list_empty (&request->sched.link));if (submit_queue (engine, request)) -__execlists_kick (&engine->execlists); +i915_sched_engine_hi_kick (engine->sched_engine); } -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); } static int@@ -2800,10 +2809,10 @@ static int execlists_resume(struct intel_engine_cs *engine)static void execlists_reset_prepare (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine;ENGINE_TRACE (engine,"depth<-%d\n" , -atomic_read (&execlists->tasklet.count)); +atomic_read (&sched_engine->tasklet.count));/* * Prevent request submission to the hardware until we have @@ -2814,8 +2823,8 @@ static void execlists_reset_prepare(struct intel_engine_cs *engine)* Turning off the execlists->tasklet until the reset is over * prevents the race. */ -__tasklet_disable_sync_once (&execlists->tasklet); -GEM_BUG_ON (!reset_in_progress (execlists)); +__tasklet_disable_sync_once (&sched_engine->tasklet); +GEM_BUG_ON (!reset_in_progress (engine));/* * We stop engines, otherwise we might get failed reset and a @@ -2957,23 +2966,25 @@ static void execlists_reset_rewind(struct intel_engine_cs *engine, bool stalled)/* Push back any incomplete requests for replay after the reset. */ rcu_read_lock (); -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);__unwind_incomplete_requests (engine); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags);rcu_read_unlock (); }static void nop_submission_tasklet (struct tasklet_struct *t) { -struct intel_engine_cs *const engine = -from_tasklet (engine, t, execlists.tasklet); +struct i915_sched_engine *sched_engine = +from_tasklet (sched_engine, t, tasklet); +struct intel_engine_cs *const engine = sched_engine->engine;/* The driver is wedged; don't process any more events. */ -WRITE_ONCE (engine->execlists.queue_priority_hint,INT_MIN ); +WRITE_ONCE (engine->sched_engine->queue_priority_hint,INT_MIN ); }static void execlists_reset_cancel (struct intel_engine_cs *engine) { +struct i915_sched_engine *const sched_engine = engine->sched_engine;struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_request *rq, *rn;struct rb_node *rb;@@ -2998,15 +3009,15 @@ static void execlists_reset_cancel(struct intel_engine_cs *engine)execlists_reset_csb (engine, true);rcu_read_lock (); -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&sched_engine->lock, flags);/* Mark all executing requests as skipped. */ -list_for_each_entry (rq, &engine->active.requests, sched.link) +list_for_each_entry (rq, &sched_engine->requests, sched.link)i915_request_put (i915_request_mark_eio (rq));intel_engine_signal_breadcrumbs (engine);/* Flush the queued requests to the timeline list (for retiring). */ -while ((rb =rb_first_cached (&execlists->queue))) { +while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);priolist_for_each_request_consume (rq, rn, p) {@@ -3016,12 +3027,12 @@ static void execlists_reset_cancel(struct intel_engine_cs *engine) } } -rb_erase_cached (&p->node, &execlists->queue); +rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); }/* On-hold requests will be flushed to timeline upon their release */ -list_for_each_entry (rq, &engine->active.hold, sched.link) +list_for_each_entry (rq, &sched_engine->hold, sched.link)i915_request_put (i915_request_mark_eio (rq));/* Cancel all attached virtual engines */ @@ -3032,7 +3043,7 @@ static void execlists_reset_cancel(struct intel_engine_cs *engine)rb_erase_cached (rb, &execlists->virtual);RB_CLEAR_NODE (rb); -spin_lock (&ve->base.active.lock); +spin_lock (&ve->base.sched_engine->lock); rq =fetch_and_zero (&ve->request);if (rq) {if (i915_request_mark_eio (rq)) {@@ -3042,26 +3053,26 @@ static void execlists_reset_cancel(struct intel_engine_cs *engine) }i915_request_put (rq); - ve->base.execlists.queue_priority_hint =INT_MIN ; + ve->base.sched_engine->queue_priority_hint =INT_MIN ; } -spin_unlock (&ve->base.active.lock); +spin_unlock (&ve->base.sched_engine->lock); }/* Remaining _unready_ requests will be nop'ed when submitted */ - execlists->queue_priority_hint =INT_MIN ; - execlists->queue =RB_ROOT_CACHED ; + sched_engine->queue_priority_hint =INT_MIN ; + sched_engine->queue =RB_ROOT_CACHED ; -GEM_BUG_ON (__tasklet_is_enabled (&execlists->tasklet)); - execlists->tasklet.callback = nop_submission_tasklet; +GEM_BUG_ON (__tasklet_is_enabled (&sched_engine->tasklet)); + sched_engine->tasklet.callback = nop_submission_tasklet; -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags);rcu_read_unlock (); }static void execlists_reset_finish (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine;/* * After a GPU reset, we may have requests to replay. Do so now while @@ -3073,14 +3084,14 @@ static void execlists_reset_finish(struct intel_engine_cs *engine)* reset as the next level of recovery, and as a final resort we * will declare the device wedged. */ -GEM_BUG_ON (!reset_in_progress (execlists)); +GEM_BUG_ON (!reset_in_progress (engine));/* And kick in case we missed a new request submission. */ -if (__tasklet_enable (&execlists->tasklet)) -__execlists_kick (execlists); +if (__tasklet_enable (&sched_engine->tasklet)) +i915_sched_engine_hi_kick (sched_engine);ENGINE_TRACE (engine,"depth->%d\n" , -atomic_read (&execlists->tasklet.count)); +atomic_read (&sched_engine->tasklet.count)); }static void gen8_logical_ring_enable_irq (struct intel_engine_cs *engine)@@ -3110,11 +3121,59 @@ static bool can_preempt(struct intel_engine_cs *engine)return engine->class !=RENDER_CLASS ; } +static void kick_execlists (const struct i915_request *rq,int prio) +{ +struct i915_sched_engine *sched_engine = rq->engine->sched_engine; +const struct i915_request *inflight; + +/* +* We only need to kick the tasklet once for the high priority +* new context we add into the queue. +*/ +if (prio <= sched_engine->queue_priority_hint) +return ; + +rcu_read_lock (); + +/* Nothing currently active? We're overdue for a submission! */ + inflight =execlists_active (&rq->engine->execlists); +if (!inflight) + goto unlock; + +/* +* If we are already the currently executing context, don't +* bother evaluating if we should preempt ourselves. +*/ +if (inflight->context == rq->context) + goto unlock; + +ENGINE_TRACE (rq->engine, +"bumping queue-priority-hint:%d for rq:%llx:%lld, inflight:%llx:%lld prio %d\n" , + prio, + rq->fence.context, rq->fence.seqno, + inflight->fence.context, inflight->fence.seqno, + inflight->sched.attr.priority); + + sched_engine->queue_priority_hint = prio; + +/* +* Allow preemption of low -> normal -> high, but we do +* not allow low priority tasks to preempt other low priority +* tasks under the impression that latency for low priority +* tasks does not matter (as much as background throughput), +* so kiss. +*/ +if (prio >=max (I915_PRIORITY_NORMAL ,rq_prio (inflight))) +i915_sched_engine_hi_kick (sched_engine); + +unlock: +rcu_read_unlock (); +} +static void execlists_set_default_submission (struct intel_engine_cs *engine) { engine->submit_request = execlists_submit_request; - engine->schedule = i915_schedule; - engine->execlists.tasklet.callback = execlists_submission_tasklet; + engine->sched_engine->tasklet.callback = execlists_submission_tasklet; }static void execlists_shutdown (struct intel_engine_cs *engine)@@ -3122,7 +3181,7 @@ static void execlists_shutdown(struct intel_engine_cs *engine)/* Synchronise with residual timers and any softirq they raise */ del_timer_sync (&engine->execlists.timer);del_timer_sync (&engine->execlists.preempt); -tasklet_kill (&engine->execlists.tasklet); +i915_sched_engine_kill (engine->sched_engine); }static void execlists_release (struct intel_engine_cs *engine)@@ -3238,10 +3297,14 @@ int intel_execlists_submission_setup(struct intel_engine_cs *engine)struct intel_uncore *uncore = engine->uncore;u32 base = engine->mmio_base; -tasklet_setup (&engine->execlists.tasklet, execlists_submission_tasklet); +tasklet_setup (&engine->sched_engine->tasklet, + execlists_submission_tasklet);timer_setup (&engine->execlists.timer, execlists_timeslice,0 );timer_setup (&engine->execlists.preempt, execlists_preempt,0 ); + engine->sched_engine->schedule = i915_schedule; + engine->sched_engine->kick_backend = kick_execlists; +logical_ring_default_vfuncs (engine);logical_ring_default_irqs (engine);@@ -3286,7 +3349,7 @@ int intel_execlists_submission_setup(struct intel_engine_cs *engine)static struct list_head *virtual_queue (struct virtual_engine *ve) { -return &ve->base.execlists.default_priolist.requests; +return &ve->base.sched_engine->default_priolist.requests; }static void rcu_virtual_context_destroy (struct work_struct *wrk)@@ -3301,7 +3364,7 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)if (unlikely (ve->request)) {struct i915_request *old; -spin_lock_irq (&ve->base.active.lock); +spin_lock_irq (&ve->base.sched_engine->lock); old =fetch_and_zero (&ve->request);if (old) {@@ -3310,7 +3373,7 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)i915_request_put (old); } -spin_unlock_irq (&ve->base.active.lock); +spin_unlock_irq (&ve->base.sched_engine->lock); }/* @@ -3320,7 +3383,7 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)* rbtrees as in the case it is running in parallel, it may reinsert * the rb_node into a sibling. */ -tasklet_kill (&ve->base.execlists.tasklet); +i915_sched_engine_kill (ve->base.sched_engine);/* Decouple ourselves from the siblings, no more access allowed. */ for (n =0 ; n < ve->num_siblings; n++) {@@ -3330,21 +3393,23 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)if (RB_EMPTY_NODE (node))continue ; -spin_lock_irq (&sibling->active.lock); +spin_lock_irq (&sibling->sched_engine->lock);/* Detachment is lazily performed in the execlists tasklet */ if (!RB_EMPTY_NODE (node))rb_erase_cached (node, &sibling->execlists.virtual); -spin_unlock_irq (&sibling->active.lock); +spin_unlock_irq (&sibling->sched_engine->lock); } -GEM_BUG_ON (__tasklet_is_scheduled (&ve->base.execlists.tasklet)); +GEM_BUG_ON (__tasklet_is_scheduled (&ve->base.sched_engine->tasklet));GEM_BUG_ON (!list_empty (virtual_queue (ve)));lrc_fini (&ve->context);intel_context_fini (&ve->context);intel_breadcrumbs_free (ve->base.breadcrumbs); +if (ve->base.sched_engine) +i915_sched_engine_put (ve->base.sched_engine);intel_engine_free_request_pool (&ve->base);kfree (ve->bonds);@@ -3475,16 +3540,18 @@ static intel_engine_mask_t virtual_submission_mask(struct virtual_engine *ve)ENGINE_TRACE (&ve->base,"rq=%llx:%lld, mask=%x, prio=%d\n" , rq->fence.context, rq->fence.seqno, - mask, ve->base.execlists.queue_priority_hint); + mask, ve->base.sched_engine->queue_priority_hint);return mask; }static void virtual_submission_tasklet (struct tasklet_struct *t) { +struct i915_sched_engine *sched_engine = +from_tasklet (sched_engine, t, tasklet);struct virtual_engine *const ve = -from_tasklet (ve, t, base.execlists.tasklet); -const int prio =READ_ONCE (ve->base.execlists.queue_priority_hint); + (struct virtual_engine *)sched_engine->engine; +const int prio =READ_ONCE (ve->base.sched_engine->queue_priority_hint);intel_engine_mask_t mask;unsigned int n;@@ -3503,7 +3570,7 @@ static void virtual_submission_tasklet(struct tasklet_struct *t)if (!READ_ONCE (ve->request))break ;/* already handled by a sibling's tasklet */ -spin_lock_irq (&sibling->active.lock); +spin_lock_irq (&sibling->sched_engine->lock);if (unlikely (!(mask & sibling->mask))) {if (!RB_EMPTY_NODE (&node->rb)) {@@ -3552,11 +3619,11 @@ static void virtual_submission_tasklet(struct tasklet_struct *t) submit_engine:GEM_BUG_ON (RB_EMPTY_NODE (&node->rb)); node->prio = prio; -if (first && prio > sibling->execlists.queue_priority_hint) -tasklet_hi_schedule (&sibling->execlists.tasklet); +if (first && prio > sibling->sched_engine->queue_priority_hint) +i915_sched_engine_hi_kick (sibling->sched_engine); unlock_engine: -spin_unlock_irq (&sibling->active.lock); +spin_unlock_irq (&sibling->sched_engine->lock);if (intel_context_inflight (&ve->context))break ;@@ -3574,7 +3641,7 @@ static void virtual_submit_request(struct i915_request *rq)GEM_BUG_ON (ve->base.submit_request != virtual_submit_request); -spin_lock_irqsave (&ve->base.active.lock, flags); +spin_lock_irqsave (&ve->base.sched_engine->lock, flags);/* By the time we resubmit a request, it may be completed */ if (__i915_request_is_complete (rq)) {@@ -3588,16 +3655,16 @@ static void virtual_submit_request(struct i915_request *rq)i915_request_put (ve->request); } - ve->base.execlists.queue_priority_hint =rq_prio (rq); + ve->base.sched_engine->queue_priority_hint =rq_prio (rq); ve->request =i915_request_get (rq);GEM_BUG_ON (!list_empty (virtual_queue (ve)));list_move_tail (&rq->sched.link,virtual_queue (ve)); -tasklet_hi_schedule (&ve->base.execlists.tasklet); +i915_sched_engine_hi_kick (ve->base.sched_engine); unlock: -spin_unlock_irqrestore (&ve->base.active.lock, flags); +spin_unlock_irqrestore (&ve->base.sched_engine->lock, flags); } static struct ve_bond *@@ -3681,19 +3748,24 @@ intel_execlists_create_virtual(struct intel_engine_cs **siblings,snprintf (ve->base.name,sizeof (ve->base.name),"virtual" ); -intel_engine_init_active (&ve->base,ENGINE_VIRTUAL ); -intel_engine_init_execlists (&ve->base); + ve->base.sched_engine =i915_sched_engine_create (ENGINE_VIRTUAL ); +if (!ve->base.sched_engine) { +kfree (ve); +return ERR_PTR (-ENOMEM ); + } + ve->base.sched_engine->engine = &ve->base; ve->base.cops = &virtual_context_ops; ve->base.request_alloc = execlists_request_alloc; - ve->base.schedule = i915_schedule; + ve->base.sched_engine->schedule = i915_schedule; ve->base.submit_request = virtual_submit_request; ve->base.bond_execute = virtual_bond_execute;INIT_LIST_HEAD (virtual_queue (ve)); - ve->base.execlists.queue_priority_hint =INT_MIN ; -tasklet_setup (&ve->base.execlists.tasklet, virtual_submission_tasklet); + ve->base.sched_engine->queue_priority_hint =INT_MIN ; +tasklet_setup (&ve->base.sched_engine->tasklet, + virtual_submission_tasklet);intel_context_init (&ve->context, &ve->base);@@ -3721,7 +3793,7 @@ intel_execlists_create_virtual(struct intel_engine_cs **siblings,* layering if we handle cloning of the requests and * submitting a copy into each backend. */ -if (sibling->execlists.tasklet.callback != +if (sibling->sched_engine->tasklet.callback != execlists_submission_tasklet) { err = -ENODEV ; goto err_put;@@ -3756,6 +3828,9 @@ intel_execlists_create_virtual(struct intel_engine_cs **siblings, "v%dx%d", ve->base.class, count); ve->base.context_size = sibling->context_size; + ve->base.sched_engine->kick_backend = + sibling->sched_engine->kick_backend; + ve->base.emit_bb_start = sibling->emit_bb_start; ve->base.emit_flush = sibling->emit_flush; ve->base.emit_init_breadcrumb = sibling->emit_init_breadcrumb;@@ -3848,17 +3923,18 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine, int indent), unsigned int max) { +const struct i915_sched_engine *sched_engine = engine->sched_engine;const struct intel_engine_execlists *execlists = &engine->execlists;struct i915_request *rq, *last;unsigned long flags;unsigned int count;struct rb_node *rb; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags); last =NULL ; count =0 ; -list_for_each_entry (rq, &engine->active.requests, sched.link) { +list_for_each_entry (rq, &sched_engine->requests, sched.link) {if (count++ < max -1 )show_request (m, rq,"\t\t" ,0 );else @@ -3873,13 +3949,13 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,show_request (m, last,"\t\t" ,0 ); } -if (execlists->queue_priority_hint !=INT_MIN ) +if (sched_engine->queue_priority_hint !=INT_MIN )drm_printf (m,"\t\tQueue priority hint: %d\n" , -READ_ONCE (execlists->queue_priority_hint)); +READ_ONCE (sched_engine->queue_priority_hint)); last =NULL ; count =0 ; -for (rb =rb_first_cached (&execlists->queue); rb; rb =rb_next (rb)) { +for (rb =rb_first_cached (&sched_engine->queue); rb; rb =rb_next (rb)) {struct i915_priolist *p =rb_entry (rb,typeof (*p), node);priolist_for_each_request (rq, p) {@@ -3921,7 +3997,7 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,show_request (m, last,"\t\t" ,0 ); } -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST )drivers/gpu/drm/i915/gt/intel_ring_submission.c +7
-6@@ -339,9 +339,9 @@ static void reset_rewind(struct intel_engine_cs *engine, bool stalled)u32 head; rq =NULL ; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);rcu_read_lock (); -list_for_each_entry (pos, &engine->active.requests, sched.link) { +list_for_each_entry (pos, &engine->sched_engine->requests, sched.link) {if (!__i915_request_is_complete (pos)) { rq = pos;break ;@@ -396,7 +396,7 @@ static void reset_rewind(struct intel_engine_cs *engine, bool stalled) } engine->legacy.ring->head =intel_ring_wrap (engine->legacy.ring, head); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void reset_finish (struct intel_engine_cs *engine)@@ -408,16 +408,17 @@ static void reset_cancel(struct intel_engine_cs *engine)struct i915_request *request;unsigned long flags; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);/* Mark all submitted requests as skipped. */ -list_for_each_entry (request, &engine->active.requests, sched.link) +list_for_each_entry (request, &engine->sched_engine->requests, + sched.link)i915_request_put (i915_request_mark_eio (request));intel_engine_signal_breadcrumbs (engine);/* Remaining _unready_ requests will be nop'ed when submitted */ -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void i9xx_submit_request (struct i915_request *request)drivers/gpu/drm/i915/gt/mock_engine.c +12
-5@@ -253,10 +253,10 @@ static void mock_reset_cancel(struct intel_engine_cs *engine)del_timer_sync (&mock->hw_delay); -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);/* Mark all submitted requests as skipped. */ -list_for_each_entry (rq, &engine->active.requests, sched.link) +list_for_each_entry (rq, &engine->sched_engine->requests, sched.link)i915_request_put (i915_request_mark_eio (rq));intel_engine_signal_breadcrumbs (engine);@@ -269,7 +269,7 @@ static void mock_reset_cancel(struct intel_engine_cs *engine) }INIT_LIST_HEAD (&mock->hw_queue); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void mock_reset_finish (struct intel_engine_cs *engine)@@ -283,6 +283,7 @@ static void mock_engine_release(struct intel_engine_cs *engine)GEM_BUG_ON (timer_pending (&mock->hw_delay)); +i915_sched_engine_put (engine->sched_engine);intel_breadcrumbs_free (engine->breadcrumbs);intel_context_unpin (engine->kernel_context);@@ -345,14 +346,18 @@ int mock_engine_init(struct intel_engine_cs *engine) {struct intel_context *ce; -intel_engine_init_active (engine,ENGINE_MOCK ); + engine->sched_engine =i915_sched_engine_create (ENGINE_MOCK ); +if (!engine->sched_engine) +return -ENOMEM ; + engine->sched_engine->engine = engine; +intel_engine_init_execlists (engine);intel_engine_init__pm (engine);intel_engine_init_retire (engine); engine->breadcrumbs =intel_breadcrumbs_create (NULL );if (!engine->breadcrumbs) -return -ENOMEM ; + goto err_schedule; ce =create_kernel_context (engine);if (IS_ERR (ce))@@ -366,6 +371,8 @@ int mock_engine_init(struct intel_engine_cs *engine) err_breadcrumbs:intel_breadcrumbs_free (engine->breadcrumbs); +err_schedule: +i915_sched_engine_put (engine->sched_engine);return -ENOMEM ; }drivers/gpu/drm/i915/gt/selftest_execlists.c +18
-18@@ -43,7 +43,7 @@ static int wait_for_submit(struct intel_engine_cs *engine, unsigned long timeout) {/* Ignore our own attempts to suppress excess tasklets */ -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); timeout += jiffies; do {@@ -273,7 +273,7 @@ static int live_unlite_restore(struct intel_gt *gt, int prio) };/* Alternatively preempt the spinner with ce[1] */ - engine->schedule (rq[1 ], &attr); + engine->sched_engine->schedule (rq[1 ], &attr); }/* And switch back to ce[0] for good measure */ @@ -606,9 +606,9 @@ static int live_hold_reset(void *arg) err = -EBUSY ; goto out; } -tasklet_disable (&engine->execlists.tasklet); +tasklet_disable (&engine->sched_engine->tasklet); - engine->execlists.tasklet.callback (&engine->execlists.tasklet); + engine->sched_engine->tasklet.callback (&engine->sched_engine->tasklet);GEM_BUG_ON (execlists_active (&engine->execlists) != rq);i915_request_get (rq);@@ -618,7 +618,7 @@ static int live_hold_reset(void *arg)__intel_engine_reset_bh (engine,NULL );GEM_BUG_ON (rq->fence.error != -EIO ); -tasklet_enable (&engine->execlists.tasklet); +tasklet_enable (&engine->sched_engine->tasklet);clear_and_wake_up_bit (I915_RESET_ENGINE + id, >->reset.flags);local_bh_enable ();@@ -900,7 +900,7 @@ release_queue(struct intel_engine_cs *engine,i915_request_add (rq);local_bh_disable (); - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);local_bh_enable ();/* kick tasklet */ i915_request_put (rq);@@ -1183,7 +1183,7 @@ static int live_timeslice_rewind(void *arg)while (i915_request_is_active (rq[A2 ])) {/* semaphore yield! */ /* Wait for the timeslice to kick in */ del_timer (&engine->execlists.timer); -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine);intel_engine_flush_submission (engine); }/* -> ELSP[] = { { A:rq1 }, { B:rq1 } } */ @@ -1325,7 +1325,7 @@ static int live_timeslice_queue(void *arg) err =PTR_ERR (rq); goto err_heartbeat; } - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr); err =wait_for_submit (engine, rq,HZ /2 );if (err) { pr_err("%s: Timed out trying to submit semaphores\n",@@ -1867,7 +1867,7 @@ static int live_late_preempt(void *arg) } attr.priority =I915_PRIORITY_MAX ; - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);if (!igt_wait_for_spinner (&spin_hi, rq)) {pr_err ("High priority context failed to preempt the low priority context\n" );@@ -2480,7 +2480,7 @@ static int live_suppress_self_preempt(void *arg)i915_request_add (rq_b);GEM_BUG_ON (i915_request_completed (rq_a)); - engine->schedule (rq_a, &attr); + engine->sched_engine->schedule (rq_a, &attr);igt_spinner_end (&a.spin);if (!igt_wait_for_spinner (&b.spin, rq_b)) {@@ -2612,7 +2612,7 @@ static int live_chain_preempt(void *arg)i915_request_get (rq);i915_request_add (rq); - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);igt_spinner_end (&hi.spin);if (i915_request_wait (rq,0 ,HZ /5 ) <0 ) {@@ -2971,7 +2971,7 @@ static int live_preempt_gang(void *arg)break ;/* Submit each spinner at increasing priority */ - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr); }while (prio <=I915_PRIORITY_MAX && !__igt_timeout (end_time,NULL )); pr_debug("%s: Preempt chain of %d requests\n",@@ -3219,7 +3219,7 @@ static int preempt_user(struct intel_engine_cs *engine,i915_request_get (rq);i915_request_add (rq); - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);if (i915_request_wait (rq,0 ,HZ /2 ) <0 ) err = -ETIME ;@@ -4593,15 +4593,15 @@ static int reset_virtual_engine(struct intel_gt *gt, err = -EBUSY ; goto out_heartbeat; } -tasklet_disable (&engine->execlists.tasklet); +tasklet_disable (&engine->sched_engine->tasklet); - engine->execlists.tasklet.callback (&engine->execlists.tasklet); + engine->sched_engine->tasklet.callback (&engine->sched_engine->tasklet);GEM_BUG_ON (execlists_active (&engine->execlists) != rq);/* Fake a preemption event; failed of course */ -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock);__unwind_incomplete_requests (engine); -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock);GEM_BUG_ON (rq->engine != engine);/* Reset the engine while keeping our active request on hold */ @@ -4612,7 +4612,7 @@ static int reset_virtual_engine(struct intel_gt *gt,GEM_BUG_ON (rq->fence.error != -EIO );/* Release our grasp on the engine, letting CS flow again */ -tasklet_enable (&engine->execlists.tasklet); +tasklet_enable (&engine->sched_engine->tasklet);clear_and_wake_up_bit (I915_RESET_ENGINE + engine->id, >->reset.flags);local_bh_enable ();drivers/gpu/drm/i915/gt/selftest_hangcheck.c +3
-3@@ -858,12 +858,12 @@ static int active_engine(void *data) rq[idx] =i915_request_get (new);i915_request_add (new); -if (engine->schedule && arg->flags &TEST_PRIORITY ) { +if (engine->sched_engine->schedule && arg->flags &TEST_PRIORITY ) {struct i915_sched_attr attr = { .priority =i915_prandom_u32_max_state (512 , &prng), }; - engine->schedule (rq[idx], &attr); + engine->sched_engine->schedule (rq[idx], &attr); } err =active_request_put (old);@@ -1702,7 +1702,7 @@ static int __igt_atomic_reset_engine(struct intel_engine_cs *engine,const struct igt_atomic_section *p, const char *mode) { - struct tasklet_struct * const t = &engine->execlists.tasklet; + struct tasklet_struct * const t = &engine->sched_engine->tasklet;int err; GEM_TRACE("i915_reset_engine(%s:%s) under %s\n",drivers/gpu/drm/i915/gt/selftest_lrc.c +3
-3@@ -49,7 +49,7 @@ static int wait_for_submit(struct intel_engine_cs *engine, unsigned long timeout) {/* Ignore our own attempts to suppress excess tasklets */ -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); timeout += jiffies; do {@@ -1613,12 +1613,12 @@ static void garbage_reset(struct intel_engine_cs *engine,local_bh_disable ();if (!test_and_set_bit (bit, lock)) { -tasklet_disable (&engine->execlists.tasklet); +tasklet_disable (&engine->sched_engine->tasklet);if (!rq->fence.error)__intel_engine_reset_bh (engine,NULL ); -tasklet_enable (&engine->execlists.tasklet); +tasklet_enable (&engine->sched_engine->tasklet);clear_and_wake_up_bit (bit, lock); }local_bh_enable ();drivers/gpu/drm/i915/gt/selftest_reset.c +1
-1@@ -321,7 +321,7 @@ static int igt_atomic_engine_reset(void *arg) goto out_unlock;for_each_engine (engine, gt, id) { -struct tasklet_struct *t = &engine->execlists.tasklet; +struct tasklet_struct *t = &engine->sched_engine->tasklet;if (t->func)tasklet_disable (t);drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +40
-35@@ -181,6 +181,7 @@ static void schedule_out(struct i915_request *rq)static void __guc_dequeue (struct intel_engine_cs *engine) { +struct i915_sched_engine *const sched_engine = engine->sched_engine;struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_request **first = execlists->inflight;struct i915_request **const last_port = first + execlists->port_mask;@@ -189,7 +190,7 @@ static void __guc_dequeue(struct intel_engine_cs *engine)bool submit = false;struct rb_node *rb; -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);if (last) {if (*++first)@@ -204,7 +205,7 @@ static void __guc_dequeue(struct intel_engine_cs *engine)* event. */ port = first; -while ((rb =rb_first_cached (&execlists->queue))) { +while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;@@ -224,11 +225,11 @@ static void __guc_dequeue(struct intel_engine_cs *engine) last = rq; } -rb_erase_cached (&p->node, &execlists->queue); +rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); } done: - execlists->queue_priority_hint = + sched_engine->queue_priority_hint = rb ?to_priolist (rb)->priority :INT_MIN ;if (submit) { *port =schedule_in (last, port - execlists->inflight);@@ -240,13 +241,14 @@ static void __guc_dequeue(struct intel_engine_cs *engine)static void guc_submission_tasklet (struct tasklet_struct *t) { -struct intel_engine_cs *const engine = -from_tasklet (engine, t, execlists.tasklet); +struct i915_sched_engine *sched_engine = +from_tasklet (sched_engine, t, tasklet); +struct intel_engine_cs *const engine = sched_engine->engine;struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_request **port, *rq;unsigned long flags; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);for (port = execlists->inflight; (rq = *port); port++) {if (!i915_request_completed (rq))@@ -262,20 +264,22 @@ static void guc_submission_tasklet(struct tasklet_struct *t)__guc_dequeue (engine); -spin_unlock_irqrestore (&engine->active.lock, flags); +i915_sched_engine_reset_on_empty (engine->sched_engine); + +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void cs_irq_handler (struct intel_engine_cs *engine,u16 iir) {if (iir >_RENDER_USER_INTERRUPT ) {intel_engine_signal_breadcrumbs (engine); -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); } }static void guc_reset_prepare (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine;ENGINE_TRACE (engine,"\n" );@@ -283,12 +287,12 @@ static void guc_reset_prepare(struct intel_engine_cs *engine)* Prevent request submission to the hardware until we have * completed the reset in i915_gem_reset_finish(). If a request * is completed by one engine, it may then queue a request -* to a second via its execlists->tasklet *just* as we are +* to a second via its sched_engine->tasklet *just* as we are * calling engine->init_hw() and also writing the ELSP. -* Turning off the execlists->tasklet until the reset is over +* Turning off the sched_engine->tasklet until the reset is over * prevents the race. */ -__tasklet_disable_sync_once (&execlists->tasklet); +__tasklet_disable_sync_once (&sched_engine->tasklet); } static void guc_reset_state(struct intel_context *ce,@@ -319,7 +323,7 @@ static void guc_reset_rewind(struct intel_engine_cs *engine, bool stalled)struct i915_request *rq;unsigned long flags; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);/* Push back any incomplete requests for replay after the reset. */ rq =execlists_unwind_incomplete_requests (execlists);@@ -333,12 +337,12 @@ static void guc_reset_rewind(struct intel_engine_cs *engine, bool stalled)guc_reset_state (rq->context, engine, rq->head, stalled); out_unlock: -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void guc_reset_cancel (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine;struct i915_request *rq, *rn;struct rb_node *rb;unsigned long flags;@@ -359,16 +363,16 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)* submission's irq state, we also wish to remind ourselves that * it is irq state.) */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);/* Mark all executing requests as skipped. */ -list_for_each_entry (rq, &engine->active.requests, sched.link) { +list_for_each_entry (rq, &engine->sched_engine->requests, sched.link) {i915_request_set_error_once (rq, -EIO );i915_request_mark_complete (rq); }/* Flush the queued requests to the timeline list (for retiring). */ -while ((rb =rb_first_cached (&execlists->queue))) { +while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);priolist_for_each_request_consume (rq, rn, p) {@@ -378,28 +382,28 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)i915_request_mark_complete (rq); } -rb_erase_cached (&p->node, &execlists->queue); +rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); }/* Remaining _unready_ requests will be nop'ed when submitted */ - execlists->queue_priority_hint =INT_MIN ; - execlists->queue =RB_ROOT_CACHED ; + sched_engine->queue_priority_hint =INT_MIN ; + sched_engine->queue =RB_ROOT_CACHED ; -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void guc_reset_finish (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine; -if (__tasklet_enable (&execlists->tasklet)) +if (__tasklet_enable (&sched_engine->tasklet))/* And kick in case we missed a new request submission. */ -tasklet_hi_schedule (&execlists->tasklet); +i915_sched_engine_hi_kick (sched_engine);ENGINE_TRACE (engine,"depth->%d\n" , -atomic_read (&execlists->tasklet.count)); +atomic_read (&sched_engine->tasklet.count)); }/* @@ -500,7 +504,7 @@ static inline void queue_request(struct intel_engine_cs *engine, {GEM_BUG_ON (!list_empty (&rq->sched.link));list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (engine, prio)); +i915_sched_lookup_priolist (engine->sched_engine, prio));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); }@@ -510,16 +514,16 @@ static void guc_submit_request(struct i915_request *rq)unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);queue_request (engine, rq,rq_prio (rq)); -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine));GEM_BUG_ON (list_empty (&rq->sched.link)); -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -597,7 +601,7 @@ static void guc_release(struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ -tasklet_kill (&engine->execlists.tasklet); +tasklet_kill (&engine->sched_engine->tasklet);intel_engine_cleanup_common (engine);lrc_fini_wa_ctx (engine);@@ -612,7 +616,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; - engine->schedule = i915_schedule; + engine->sched_engine->schedule = i915_schedule; engine->reset.prepare = guc_reset_prepare; engine->reset.rewind = guc_reset_rewind;@@ -676,7 +680,8 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)*/ GEM_BUG_ON (INTEL_GEN (i915) <11 ); -tasklet_setup (&engine->execlists.tasklet, guc_submission_tasklet); +tasklet_setup (&engine->sched_engine->tasklet, guc_submission_tasklet); + engine->sched_engine->schedule = i915_schedule;guc_default_vfuncs (engine);guc_default_irqs (engine);drivers/gpu/drm/i915/i915_gpu_error.c +4
-3@@ -1247,7 +1247,8 @@ static void record_request(const struct i915_request *request,static void engine_record_execlists (struct intel_engine_coredump *ee) { -const struct intel_engine_execlists *const el = &ee->engine->execlists; +const struct intel_engine_execlists *const el = + &ee->engine->execlists;struct i915_request *const *port = el->active;unsigned int n =0 ;@@ -1441,12 +1442,12 @@ capture_engine(struct intel_engine_cs *engine,if (!ee)return NULL ; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags); rq =intel_engine_find_active_request (engine);if (rq) capture =intel_engine_coredump_add_request (ee, rq,ATOMIC_MAYFAIL ); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags);if (!capture) {kfree (ee);return NULL ;drivers/gpu/drm/i915/i915_request.c +25
-25@@ -272,11 +272,11 @@ i915_request_active_engine(struct i915_request *rq,* check that we have acquired the lock on the final engine. */ locked =READ_ONCE (rq->engine); -spin_lock_irq (&locked->active.lock); +spin_lock_irq (&locked->sched_engine->lock);while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { -spin_unlock (&locked->active.lock); +spin_unlock (&locked->sched_engine->lock); locked = engine; -spin_lock (&locked->active.lock); +spin_lock (&locked->sched_engine->lock); }if (i915_request_is_active (rq)) {@@ -285,7 +285,7 @@ i915_request_active_engine(struct i915_request *rq, ret = true; } -spin_unlock_irq (&locked->active.lock); +spin_unlock_irq (&locked->sched_engine->lock);return ret; }@@ -302,10 +302,10 @@ static void remove_from_engine(struct i915_request *rq)* check that the rq still belongs to the newly locked engine. */ locked =READ_ONCE (rq->engine); -spin_lock_irq (&locked->active.lock); +spin_lock_irq (&locked->sched_engine->lock);while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { -spin_unlock (&locked->active.lock); -spin_lock (&engine->active.lock); +spin_unlock (&locked->sched_engine->lock); +spin_lock (&engine->sched_engine->lock); locked = engine; }list_del_init (&rq->sched.link);@@ -316,7 +316,7 @@ static void remove_from_engine(struct i915_request *rq)/* Prevent further __await_execution() registering a cb, then flush */ set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); -spin_unlock_irq (&locked->active.lock); +spin_unlock_irq (&locked->sched_engine->lock);__notify_execute_cb_imm (rq); }@@ -481,7 +481,7 @@ static bool __request_in_flight(const struct i915_request *signal)* may either perform a context switch to the second inflight execlists, * or it may switch to the pending set of execlists. In the case of the * latter, it may send the ACK and we process the event copying the -* pending[] over top of inflight[], _overwriting_ our *active. Since +* pending[] over top of inflight[], _overwriting_ our *active-> Since * this implies the HW is arbitrating and not struck in *active, we do * not worry about complete accuracy, but we do require no read/write * tearing of the pointer [the read of the pointer must be valid, even @@ -490,7 +490,7 @@ static bool __request_in_flight(const struct i915_request *signal)* * Note that the read of *execlists->active may race with the promotion * of execlists->pending[] to execlists->inflight[], overwritting -* the value at *execlists->active. This is fine. The promotion implies +* the value at *execlists->active-> This is fine. The promotion implies * that we received an ACK from the HW, and so the context is not * stuck -- if we do not see ourselves in *active, the inflight status * is valid. If instead we see ourselves being copied into *active, @@ -545,7 +545,7 @@ __await_execution(struct i915_request *rq,/* * Register the callback first, then see if the signaler is already -* active. This ensures that if we race with the +* active-> This ensures that if we race with the * __notify_execute_cb from i915_request_submit() and we are not * included in that list, we get a second bite of the cherry and * execute it ourselves. After this point, a future @@ -637,7 +637,7 @@ bool __i915_request_submit(struct i915_request *request)RQ_TRACE (request,"\n" );GEM_BUG_ON (!irqs_disabled ()); -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);/* * With the advent of preempt-to-busy, we frequently encounter @@ -649,9 +649,9 @@ bool __i915_request_submit(struct i915_request *request)* * We must remove the request from the caller's priority queue, * and the caller must only call us when the request is in their -* priority queue, under the active.lock. This ensures that the +* priority queue, under the active->lock. This ensures that the * request has *not* yet been retired and we can safely move -* the request into the engine->active.list where it will be +* the request into the engine->sched_engine->list where it will be * dropped upon retiring. (Otherwise if resubmit a *retired* * request, this would be a horrible use-after-free.) */ @@ -694,7 +694,7 @@ bool __i915_request_submit(struct i915_request *request) result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags)); -list_move_tail (&request->sched.link, &engine->active.requests); +list_move_tail (&request->sched.link, &engine->sched_engine->requests); active:clear_bit (I915_FENCE_FLAG_PQUEUE , &request->fence.flags);set_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags);@@ -724,11 +724,11 @@ void i915_request_submit(struct i915_request *request)unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);__i915_request_submit (request); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }void __i915_request_unsubmit (struct i915_request *request)@@ -742,7 +742,7 @@ void __i915_request_unsubmit(struct i915_request *request)RQ_TRACE (request,"\n" );GEM_BUG_ON (!irqs_disabled ()); -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);/* * Before we remove this breadcrumb from the signal list, we have @@ -775,11 +775,11 @@ void i915_request_unsubmit(struct i915_request *request)unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);__i915_request_unsubmit (request); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void __cancel_request (struct i915_request *rq)@@ -1343,7 +1343,7 @@ __i915_request_await_execution(struct i915_request *to, }/* Couple the dependency tree for PI on this exposed to->fence */ -if (to->engine->schedule) { +if (to->engine->sched_engine->schedule) { err =i915_sched_node_add_dependency (&to->sched, &from->sched,I915_DEPENDENCY_WEAK );@@ -1484,7 +1484,7 @@ i915_request_await_request(struct i915_request *to, struct i915_request *from)return 0 ; } -if (to->engine->schedule) { +if (to->engine->sched_engine->schedule) { ret =i915_sched_node_add_dependency (&to->sched, &from->sched,I915_DEPENDENCY_EXTERNAL );@@ -1671,7 +1671,7 @@ __i915_request_add_to_timeline(struct i915_request *rq)__i915_sw_fence_await_dma_fence (&rq->submit, &prev->fence, &rq->dmaq); -if (rq->engine->schedule) +if (rq->engine->sched_engine->schedule) __i915_sched_node_add_dependency(&rq->sched, &prev->sched, &rq->dep,@@ -1743,8 +1743,8 @@ void __i915_request_queue(struct i915_request *rq,* decide whether to preempt the entire chain so that it is ready to * run at the earliest possible convenience. */ -if (attr && rq->engine->schedule) - rq->engine->schedule (rq, attr); +if (attr && rq->engine->sched_engine->schedule) + rq->engine->sched_engine->schedule (rq, attr);local_bh_disable ();__i915_request_queue_bh (rq);drivers/gpu/drm/i915/i915_request.h +1
-1@@ -613,7 +613,7 @@ i915_request_active_timeline(const struct i915_request *rq)* this submission. */ return rcu_dereference_protected (rq->timeline, -lockdep_is_held (&rq->engine->active.lock)); +lockdep_is_held (&rq->engine->sched_engine->lock)); } static inline u32drivers/gpu/drm/i915/i915_scheduler.c +77
-91@@ -40,7 +40,7 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -static void assert_priolists (struct intel_engine_execlists *const execlists) +static void assert_priolists (struct i915_sched_engine *const sched_engine) {struct rb_node *rb;long last_prio;@@ -48,11 +48,11 @@ static void assert_priolists(struct intel_engine_execlists * const execlists)if (!IS_ENABLED (CONFIG_DRM_I915_DEBUG_GEM ))return ; -GEM_BUG_ON (rb_first_cached (&execlists->queue) != -rb_first (&execlists->queue.rb_root)); +GEM_BUG_ON (rb_first_cached (&sched_engine->queue) != +rb_first (&sched_engine->queue.rb_root)); last_prio =INT_MAX ; -for (rb =rb_first_cached (&execlists->queue); rb; rb =rb_next (rb)) { +for (rb =rb_first_cached (&sched_engine->queue); rb; rb =rb_next (rb)) {const struct i915_priolist *p =to_priolist (rb);GEM_BUG_ON (p->priority > last_prio);@@ -61,23 +61,22 @@ static void assert_priolists(struct intel_engine_execlists * const execlists) }struct list_head * -i915_sched_lookup_priolist (struct intel_engine_cs *engine,int prio) +i915_sched_lookup_priolist (struct i915_sched_engine *sched_engine,int prio) { -struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_priolist *p;struct rb_node **parent, *rb;bool first = true; -lockdep_assert_held (&engine->active.lock); -assert_priolists (execlists); +lockdep_assert_held (&sched_engine->lock); +assert_priolists (sched_engine); -if (unlikely (execlists->no_priolist)) +if (unlikely (sched_engine->no_priolist)) prio =I915_PRIORITY_NORMAL ; find_priolist:/* most positive priority is scheduled first, equal priorities fifo */ rb =NULL ; - parent = &execlists->queue.rb_root.rb_node; + parent = &sched_engine->queue.rb_root.rb_node;while (*parent) { rb = *parent; p =to_priolist (rb);@@ -92,7 +91,7 @@ i915_sched_lookup_priolist(struct intel_engine_cs *engine, int prio) }if (prio ==I915_PRIORITY_NORMAL ) { - p = &execlists->default_priolist; + p = &sched_engine->default_priolist; }else { p =kmem_cache_alloc (global.slab_priorities,GFP_ATOMIC );/* Convert an allocation failure to a priority bump */ @@ -107,7 +106,7 @@ i915_sched_lookup_priolist(struct intel_engine_cs *engine, int prio)* requests, so if userspace lied about their * dependencies that reordering may be visible. */ - execlists->no_priolist = true; + sched_engine->no_priolist = true; goto find_priolist; } }@@ -116,7 +115,7 @@ i915_sched_lookup_priolist(struct intel_engine_cs *engine, int prio)INIT_LIST_HEAD (&p->requests);rb_link_node (&p->node, rb, parent); -rb_insert_color_cached (&p->node, &execlists->queue, first); +rb_insert_color_cached (&p->node, &sched_engine->queue, first);return &p->requests; }@@ -130,13 +129,13 @@ struct sched_cache {struct list_head *priolist; }; -static struct intel_engine_cs * -sched_lock_engine (const struct i915_sched_node *node, -struct intel_engine_cs *locked, +static struct i915_sched_engine * +lock_sched_engine (struct i915_sched_node *node, +struct i915_sched_engine *locked,struct sched_cache *cache) {const struct i915_request *rq =node_to_request (node); -struct intel_engine_cs *engine; +struct i915_sched_engine *sched_engine;GEM_BUG_ON (!locked);@@ -146,81 +145,22 @@ sched_lock_engine(const struct i915_sched_node *node,* engine lock. The simple ploy we use is to take the lock then * check that the rq still belongs to the newly locked engine. */ -while (locked != (engine =READ_ONCE (rq->engine))) { -spin_unlock (&locked->active.lock); +while (locked != (sched_engine = rq->engine->sched_engine)) { +spin_unlock (&locked->lock);memset (cache,0 ,sizeof (*cache)); -spin_lock (&engine->active.lock); - locked = engine; +spin_lock (&sched_engine->lock); + locked = sched_engine; } -GEM_BUG_ON (locked != engine); +GEM_BUG_ON (locked != sched_engine);return locked; } -static inline int rq_prio (const struct i915_request *rq) -{ -return rq->sched.attr.priority; -} - -static inline bool need_preempt (int prio,int active) -{ -/* -* Allow preemption of low -> normal -> high, but we do -* not allow low priority tasks to preempt other low priority -* tasks under the impression that latency for low priority -* tasks does not matter (as much as background throughput), -* so kiss. -*/ -return prio >=max (I915_PRIORITY_NORMAL , active); -} - -static void kick_submission (struct intel_engine_cs *engine, -const struct i915_request *rq, -int prio) -{ -const struct i915_request *inflight; - -/* -* We only need to kick the tasklet once for the high priority -* new context we add into the queue. -*/ -if (prio <= engine->execlists.queue_priority_hint) -return ; - -rcu_read_lock (); - -/* Nothing currently active? We're overdue for a submission! */ - inflight =execlists_active (&engine->execlists); -if (!inflight) - goto unlock; - -/* -* If we are already the currently executing context, don't -* bother evaluating if we should preempt ourselves. -*/ -if (inflight->context == rq->context) - goto unlock; - -ENGINE_TRACE (engine, -"bumping queue-priority-hint:%d for rq:%llx:%lld, inflight:%llx:%lld prio %d\n" , - prio, - rq->fence.context, rq->fence.seqno, - inflight->fence.context, inflight->fence.seqno, - inflight->sched.attr.priority); - - engine->execlists.queue_priority_hint = prio; -if (need_preempt (prio,rq_prio (inflight))) -tasklet_hi_schedule (&engine->execlists.tasklet); - -unlock: -rcu_read_unlock (); -} -static void __i915_schedule (struct i915_sched_node *node,const struct i915_sched_attr *attr) {const int prio =max (attr->priority, node->attr.priority); -struct intel_engine_cs *engine; +struct i915_sched_engine *sched_engine;struct i915_dependency *dep, *p;struct i915_dependency stack;struct sched_cache cache;@@ -295,23 +235,24 @@ static void __i915_schedule(struct i915_sched_node *node, }memset (&cache,0 ,sizeof (cache)); - engine =node_to_request (node)->engine; -spin_lock (&engine->active.lock); + sched_engine =node_to_request (node)->engine->sched_engine; +spin_lock (&sched_engine->lock);/* Fifo and depth-first replacement ensure our deps execute before us */ - engine =sched_lock_engine (node, engine, &cache); + sched_engine =lock_sched_engine (node, sched_engine, &cache);list_for_each_entry_safe_reverse (dep, p, &dfs, dfs_link) {INIT_LIST_HEAD (&dep->dfs_link); node = dep->signaler; - engine =sched_lock_engine (node, engine, &cache); -lockdep_assert_held (&engine->active.lock); + sched_engine =lock_sched_engine (node, sched_engine, &cache); +lockdep_assert_held (&sched_engine->lock);/* Recheck after acquiring the engine->timeline.lock */ if (prio <= node->attr.priority ||node_signaled (node))continue ; -GEM_BUG_ON (node_to_request (node)->engine != engine); +GEM_BUG_ON (node_to_request (node)->engine->sched_engine != + sched_engine);WRITE_ONCE (node->attr.priority, prio);@@ -329,16 +270,17 @@ static void __i915_schedule(struct i915_sched_node *node,if (i915_request_in_priority_queue (node_to_request (node))) {if (!cache.priolist) cache.priolist = -i915_sched_lookup_priolist (engine, +i915_sched_lookup_priolist (sched_engine, prio);list_move_tail (&node->link, cache.priolist); }/* Defer (tasklet) submission until after all of our updates. */ -kick_submission (engine,node_to_request (node), prio); +if (sched_engine->kick_backend) + sched_engine->kick_backend (node_to_request (node), prio); } -spin_unlock (&engine->active.lock); +spin_unlock (&sched_engine->lock); }void i915_schedule (struct i915_request *rq,const struct i915_sched_attr *attr)@@ -489,6 +431,50 @@ void i915_request_show_with_schedule(struct drm_printer *m,rcu_read_unlock (); } +void i915_sched_engine_free (struct kref *kref) +{ +struct i915_sched_engine *sched_engine = +container_of (kref,typeof (*sched_engine), ref); + +i915_sched_engine_kill (sched_engine);/* flush the callback */ +kfree (sched_engine); +} + +struct i915_sched_engine * +i915_sched_engine_create (unsigned int subclass) +{ +struct i915_sched_engine *sched_engine; + + sched_engine =kzalloc (sizeof (*sched_engine),GFP_KERNEL ); +if (!sched_engine) +return NULL ; + +kref_init (&sched_engine->ref); + + sched_engine->queue =RB_ROOT_CACHED ; + sched_engine->queue_priority_hint =INT_MIN ; + +INIT_LIST_HEAD (&sched_engine->requests); +INIT_LIST_HEAD (&sched_engine->hold); + +spin_lock_init (&sched_engine->lock); +lockdep_set_subclass (&sched_engine->lock, subclass); + +/* +* Due to an interesting quirk in lockdep's internal debug tracking, +* after setting a subclass we must ensure the lock is used. Otherwise, +* nr_unused_locks is incremented once too often. +*/ +#ifdef CONFIG_DEBUG_LOCK_ALLOC +local_irq_disable (); +lock_map_acquire (&sched_engine->lock.dep_map); +lock_map_release (&sched_engine->lock.dep_map); +local_irq_enable (); +#endif + +return sched_engine; +} +static void i915_global_scheduler_shrink (void ) {kmem_cache_shrink (global.slab_dependencies);drivers/gpu/drm/i915/i915_scheduler.h +64
-1@@ -39,7 +39,7 @@ void i915_schedule(struct i915_request *request, const struct i915_sched_attr *attr);struct list_head * -i915_sched_lookup_priolist (struct intel_engine_cs *engine,int prio); +i915_sched_lookup_priolist (struct i915_sched_engine *sched_engine,int prio);void __i915_priolist_free (struct i915_priolist *p);static inline void i915_priolist_free (struct i915_priolist *p)@@ -53,4 +53,67 @@ void i915_request_show_with_schedule(struct drm_printer *m,const char *prefix, int indent); +struct i915_sched_engine * +i915_sched_engine_create (unsigned int subclass); + +void i915_sched_engine_free (struct kref *kref); + +static inline struct i915_sched_engine * +i915_sched_engine_get (struct i915_sched_engine *sched_engine) +{ +kref_get (&sched_engine->ref); +return sched_engine; +} + +static inline void +i915_sched_engine_put (struct i915_sched_engine *sched_engine) +{ +kref_put (&sched_engine->ref, i915_sched_engine_free); +} + +static inline bool +i915_sched_engine_is_empty (struct i915_sched_engine *sched_engine) +{ +return RB_EMPTY_ROOT (&sched_engine->queue.rb_root); +} + +static inline void +i915_sched_engine_reset_on_empty (struct i915_sched_engine *sched_engine) +{ +if (i915_sched_engine_is_empty (sched_engine)) + sched_engine->no_priolist = false; +} + +static inline void +i915_sched_engine_hi_kick (struct i915_sched_engine *sched_engine) +{ +tasklet_hi_schedule (&sched_engine->tasklet); +} + +static inline void +i915_sched_engine_kick (struct i915_sched_engine *sched_engine) +{ +tasklet_schedule (&sched_engine->tasklet); +} + +static inline void +i915_sched_engine_kill (struct i915_sched_engine *sched_engine) +{ +tasklet_kill (&sched_engine->tasklet); +} + +static inline void +sched_engine_active_lock_bh (struct i915_sched_engine *sched_engine) +{ +local_bh_disable ();/* prevent local softirq and lock recursion */ +tasklet_lock (&sched_engine->tasklet); +} + +static inline void +sched_engine_active_unlock_bh (struct i915_sched_engine *sched_engine) +{ +tasklet_unlock (&sched_engine->tasklet); +local_bh_enable ();/* restore softirq, and kick ksoftirqd! */ +} +#endif /* _I915_SCHEDULER_H_ */ drivers/gpu/drm/i915/i915_scheduler_types.h +63
-0@@ -91,4 +91,67 @@ struct i915_dependency { &(rq__)->sched.signalers_list, \ signal_link) +struct i915_sched_engine { +struct kref ref; + +/* +* @lock: Protects requests in priority lists, requests, hold, and +* tasklet while running. +*/ +spinlock_t lock; + +/* Execlist specific lists, needed here as protected by lock */ +struct list_head requests; +struct list_head hold;/* ready requests, but on hold */ + +/** +* @tasklet: softirq tasklet for bottom handler +*/ +struct tasklet_struct tasklet; + +/** +* @default_priolist: priority list for I915_PRIORITY_NORMAL +*/ +struct i915_priolist default_priolist; + +/** +* @queue_priority_hint: Highest pending priority. +* +* When we add requests into the queue, or adjust the priority of +* executing requests, we compute the maximum priority of those +* pending requests. We can then use this value to determine if +* we need to preempt the executing requests to service the queue. +* However, since the we may have recorded the priority of an inflight +* request we wanted to preempt but since completed, at the time of +* dequeuing the priority hint may no longer may match the highest +* available request priority. +*/ +int queue_priority_hint; + +/** +* @queue: queue of requests, in priority lists +*/ +struct rb_root_cached queue; + +/** +* @no_priolist: priority lists disabled +*/ +bool no_priolist; + +/* Back pointer to engine */ +struct intel_engine_cs *engine; + +/* Kick backend */ +void (*kick_backend)(const struct i915_request *rq, +int prio); + +/* +* Call when the priority on a request has changed and it and its +* dependencies may need rescheduling. Note the request itself may +* not be ready to run! +*/ +void (*schedule)(struct i915_request *request, +const struct i915_sched_attr *attr); +}; +#endif /* _I915_SCHEDULER_TYPES_H_ */ Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [RFC PATCH 32/97] drm/i915: Introduce i915_sched_engine object
Quoted 11 lines · Daniel Vetter
Quoted 4 lines · Matthew Brost
Introduce
i915_sched_engineobject which is lower level data structure thati915_scheduler/ generic code can operate on without touching execlist specific structures. This allows additional submission backends to be added without breaking the layer.Maybe add a comment here that this is defacto a detour since we're now aiming to use drm/scheduler instead. But also since the current code is a bit a mess, we expect this detour to be overall faster since we can then refactor in-tree.
Agree. I think in the end we will still have a i915_sched_engine which more or less encapsulates a 'struct drm_gpu_scheduler' plus a few common variables between the execlist and GuC backends.
Matt
Quoted 2,701 lines
Maybe also highlight this a bit more in the rfc to make sure this is clear.
-DanielQuoted 2,697 lines
Cc Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_wait.c | 4 +- drivers/gpu/drm/i915/gt/intel_engine.h | 16 - drivers/gpu/drm/i915/gt/intel_engine_cs.c | 77 ++-- .../gpu/drm/i915/gt/intel_engine_heartbeat.c | 4 +- drivers/gpu/drm/i915/gt/intel_engine_pm.c | 10 +- drivers/gpu/drm/i915/gt/intel_engine_types.h | 42 +-- drivers/gpu/drm/i915/gt/intel_engine_user.c | 2 +- .../drm/i915/gt/intel_execlists_submission.c | 350 +++++++++++------- .../gpu/drm/i915/gt/intel_ring_submission.c | 13 +- drivers/gpu/drm/i915/gt/mock_engine.c | 17 +- drivers/gpu/drm/i915/gt/selftest_execlists.c | 36 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 6 +- drivers/gpu/drm/i915/gt/selftest_lrc.c | 6 +- drivers/gpu/drm/i915/gt/selftest_reset.c | 2 +- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 75 ++-- drivers/gpu/drm/i915/i915_gpu_error.c | 7 +- drivers/gpu/drm/i915/i915_request.c | 50 +-- drivers/gpu/drm/i915/i915_request.h | 2 +- drivers/gpu/drm/i915/i915_scheduler.c | 168 ++++----- drivers/gpu/drm/i915/i915_scheduler.h | 65 +++- drivers/gpu/drm/i915/i915_scheduler_types.h | 63 ++++ 21 files changed, 575 insertions(+), 440 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_wait.c +2
-2@@ -104,8 +104,8 @@ static void fence_set_priority(struct dma_fence *fence, engine = rq->engine;rcu_read_lock ();/* RCU serialisation for set-wedged protection */ -if (engine->schedule) - engine->schedule (rq, attr); +if (engine->sched_engine->schedule) + engine->sched_engine->schedule (rq, attr);rcu_read_unlock (); }drivers/gpu/drm/i915/gt/intel_engine.h +0
-16@@ -123,20 +123,6 @@ execlists_active(const struct intel_engine_execlists *execlists)return active; } -static inline void -execlists_active_lock_bh (struct intel_engine_execlists *execlists) -{ -local_bh_disable ();/* prevent local softirq and lock recursion */ -tasklet_lock (&execlists->tasklet); -} - -static inline void -execlists_active_unlock_bh (struct intel_engine_execlists *execlists) -{ -tasklet_unlock (&execlists->tasklet); -local_bh_enable ();/* restore softirq, and kick ksoftirqd! */ -} -struct i915_request *execlists_unwind_incomplete_requests (struct intel_engine_execlists *execlists);@@ -257,8 +243,6 @@ intel_engine_find_active_request(struct intel_engine_cs *engine);u32 intel_engine_context_size (struct intel_gt *gt,u8 class); -void intel_engine_init_active (struct intel_engine_cs *engine, -unsigned int subclass);#define ENGINE_PHYSICAL 0#define ENGINE_MOCK 1#define ENGINE_VIRTUAL 2drivers/gpu/drm/i915/gt/intel_engine_cs.c +30
-47@@ -8,6 +8,7 @@#include "gem/i915_gem_context.h" #include "i915_drv.h" +#include "i915_scheduler.h" #include "intel_breadcrumbs.h" #include "intel_context.h" @@ -326,9 +327,6 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)if (engine->context_size)DRIVER_CAPS (i915)->has_logical_contexts = true; -/* Nothing to do here, execute in order of dependencies */ - engine->schedule =NULL ; -ewma__engine_latency_init (&engine->latency);seqcount_init (&engine->stats.lock);@@ -583,9 +581,6 @@ void intel_engine_init_execlists(struct intel_engine_cs *engine)memset (execlists->pending,0 ,sizeof (execlists->pending)); execlists->active =memset (execlists->inflight,0 ,sizeof (execlists->inflight)); - - execlists->queue_priority_hint =INT_MIN ; - execlists->queue =RB_ROOT_CACHED ; }static void cleanup_status_page (struct intel_engine_cs *engine)@@ -712,11 +707,17 @@ static int engine_setup_common(struct intel_engine_cs *engine) goto err_status; } + engine->sched_engine =i915_sched_engine_create (ENGINE_PHYSICAL ); +if (!engine->sched_engine) { + err = -ENOMEM ; + goto err_sched_engine; + } + engine->sched_engine->engine = engine; + err =intel_engine_init_cmd_parser (engine);if (err) goto err_cmd_parser; -intel_engine_init_active (engine,ENGINE_PHYSICAL );intel_engine_init_execlists (engine);intel_engine_init__pm (engine);intel_engine_init_retire (engine);@@ -735,6 +736,8 @@ static int engine_setup_common(struct intel_engine_cs *engine)return 0 ; err_cmd_parser: +i915_sched_engine_put (engine->sched_engine); +err_sched_engine:intel_breadcrumbs_free (engine->breadcrumbs); err_status:cleanup_status_page (engine);@@ -773,11 +776,11 @@ static int measure_breadcrumb_dw(struct intel_context *ce) frame->rq.ring = &frame->ring;mutex_lock (&ce->timeline->mutex); -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock); dw = engine->emit_fini_breadcrumb (&frame->rq, frame->cs) - frame->cs; -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock);mutex_unlock (&ce->timeline->mutex);GEM_BUG_ON (dw &1 );/* RING_TAIL must be qword aligned */ @@ -786,28 +789,6 @@ static int measure_breadcrumb_dw(struct intel_context *ce)return dw; } -void -intel_engine_init_active (struct intel_engine_cs *engine,unsigned int subclass) -{ -INIT_LIST_HEAD (&engine->active.requests); -INIT_LIST_HEAD (&engine->active.hold); - -spin_lock_init (&engine->active.lock); -lockdep_set_subclass (&engine->active.lock, subclass); - -/* -* Due to an interesting quirk in lockdep's internal debug tracking, -* after setting a subclass we must ensure the lock is used. Otherwise, -* nr_unused_locks is incremented once too often. -*/ -#ifdef CONFIG_DEBUG_LOCK_ALLOC -local_irq_disable (); -lock_map_acquire (&engine->active.lock.dep_map); -lock_map_release (&engine->active.lock.dep_map); -local_irq_enable (); -#endif -} -static struct intel_context * create_pinned_context(struct intel_engine_cs *engine, unsigned int hwsp,@@ -955,10 +936,10 @@ int intel_engines_init(struct intel_gt *gt)*/ void intel_engine_cleanup_common (struct intel_engine_cs *engine) { -GEM_BUG_ON (!list_empty (&engine->active.requests)); -tasklet_kill (&engine->execlists.tasklet);/* flush the callback */ +GEM_BUG_ON (!list_empty (&engine->sched_engine->requests));intel_breadcrumbs_free (engine->breadcrumbs); +i915_sched_engine_put (engine->sched_engine);intel_engine_fini_retire (engine);intel_engine_cleanup_cmd_parser (engine);@@ -1241,7 +1222,7 @@ static bool ring_is_idle(struct intel_engine_cs *engine)void __intel_engine_flush_submission (struct intel_engine_cs *engine,bool sync) { -struct tasklet_struct *t = &engine->execlists.tasklet; +struct tasklet_struct *t = &engine->sched_engine->tasklet;if (!t->callback)return ;@@ -1281,7 +1262,7 @@ bool intel_engine_is_idle(struct intel_engine_cs *engine)intel_engine_flush_submission (engine);/* ELSP is empty, but there are ready requests? E.g. after reset */ -if (!RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)) +if (!i915_sched_engine_is_empty (engine->sched_engine))return false;/* Ring stopped? */ @@ -1347,7 +1328,7 @@ static struct intel_timeline *get_timeline(struct i915_request *rq)struct intel_timeline *tl;/* -* Even though we are holding the engine->active.lock here, there +* Even though we are holding the engine->sched_engine->lock here, there * is no control over the submission queue per-se and we are * inspecting the active state at a random point in time, with an * unknown queue. Play safe and make sure the timeline remains valid. @@ -1502,10 +1483,10 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,drm_printf (m,"\tExeclist tasklet queued? %s (%s), preempt? %s, timeslice? %s\n" ,yesno (test_bit (TASKLET_STATE_SCHED , - &engine->execlists.tasklet.state)), -enableddisabled (!atomic_read (&engine->execlists.tasklet.count)), -repr_timer (&engine->execlists.preempt), -repr_timer (&engine->execlists.timer)); + &engine->sched_engine->tasklet.state)), +enableddisabled (!atomic_read (&engine->sched_engine->tasklet.count)), +repr_timer (&execlists->preempt), +repr_timer (&execlists->timer)); read = execlists->csb_head; write =READ_ONCE (*execlists->csb_write);@@ -1527,7 +1508,7 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine, idx, hws[idx * 2], hws[idx * 2 + 1]); } -execlists_active_lock_bh (execlists); +sched_engine_active_lock_bh (engine->sched_engine);rcu_read_lock ();for (port = execlists->active; (rq = *port); port++) {char hdr[160 ];@@ -1558,7 +1539,7 @@ static void intel_engine_print_registers(struct intel_engine_cs *engine,i915_request_show (m, rq, hdr,0 ); }rcu_read_unlock (); -execlists_active_unlock_bh (execlists); +sched_engine_active_unlock_bh (engine->sched_engine); }else if (INTEL_GEN (dev_priv) >6 ) {drm_printf (m,"\tPP_DIR_BASE: 0x%08x\n" ,ENGINE_READ (engine,RING_PP_DIR_BASE ));@@ -1694,7 +1675,7 @@ void intel_engine_dump(struct intel_engine_cs *engine,drm_printf (m,"\tRequests:\n" ); -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags); rq =intel_engine_find_active_request (engine);if (rq) {struct intel_timeline *tl =get_timeline (rq);@@ -1725,8 +1706,9 @@ void intel_engine_dump(struct intel_engine_cs *engine,hexdump (m, rq->context->lrc_reg_state,PAGE_SIZE ); } } -drm_printf (m,"\tOn hold?: %lu\n" ,list_count (&engine->active.hold)); -spin_unlock_irqrestore (&engine->active.lock, flags); +drm_printf (m,"\tOn hold?: %lu\n" , +list_count (&engine->sched_engine->hold)); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags);drm_printf (m,"\tMMIO base: 0x%08x\n" , engine->mmio_base); wakeref =intel_runtime_pm_get_if_in_use (engine->uncore->rpm);@@ -1806,7 +1788,7 @@ intel_engine_find_active_request(struct intel_engine_cs *engine)* At all other times, we must assume the GPU is still running, but * we only care about the snapshot of this moment. */ -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);rcu_read_lock (); request =execlists_active (&engine->execlists);@@ -1824,7 +1806,8 @@ intel_engine_find_active_request(struct intel_engine_cs *engine)if (active)return active; -list_for_each_entry (request, &engine->active.requests, sched.link) { +list_for_each_entry (request, &engine->sched_engine->requests, + sched.link) {if (__i915_request_is_complete (request))continue ;drivers/gpu/drm/i915/gt/intel_engine_heartbeat.c +2
-2@@ -121,7 +121,7 @@ static void heartbeat(struct work_struct *wrk)* but all other contexts, including the kernel * context are stuck waiting for the signal. */ - }else if (engine->schedule && + }else if (engine->sched_engine->schedule && rq->sched.attr.priority <I915_PRIORITY_BARRIER ) {/* * Gradually raise the priority of the heartbeat to @@ -136,7 +136,7 @@ static void heartbeat(struct work_struct *wrk) attr.priority =I915_PRIORITY_BARRIER ;local_bh_disable (); - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);local_bh_enable (); }else {if (IS_ENABLED (CONFIG_DRM_I915_DEBUG_GEM ))drivers/gpu/drm/i915/gt/intel_engine_pm.c +6
-4@@ -274,14 +274,16 @@ static int __engine_park(struct intel_wakeref *wf)intel_engine_park_heartbeat (engine);intel_breadcrumbs_park (engine->breadcrumbs); -/* Must be reset upon idling, or we may miss the busy wakeup. */ -GEM_BUG_ON (engine->execlists.queue_priority_hint !=INT_MIN ); +/* +* XXX: Must be reset upon idling, or we may miss the busy wakeup. +* queue_priority_hint only used in execlists submission but works in +* other modes as default is INT_MIN. +*/ +GEM_BUG_ON (engine->sched_engine->queue_priority_hint !=INT_MIN );if (engine->park) engine->park (engine); - engine->execlists.no_priolist = false; -/* While gt calls i915_vma_parked(), we have to break the lock cycle */ intel_gt_pm_put_async (engine->gt);return 0 ;drivers/gpu/drm/i915/gt/intel_engine_types.h +3
-39@@ -59,6 +59,7 @@ struct drm_i915_reg_table;struct i915_gem_context ;struct i915_request ;struct i915_sched_attr ; +struct i915_sched_engine ;struct intel_gt ;struct intel_ring ;struct intel_uncore ;@@ -137,11 +138,6 @@ struct st_preempt_hang {* driver and the hardware state for execlist mode of submission. */ struct intel_engine_execlists { -/** -* @tasklet: softirq tasklet for bottom handler -*/ -struct tasklet_struct tasklet; -/** * @timer: kick the current context if its timeslice expires */ @@ -152,11 +148,6 @@ struct intel_engine_execlists {*/ struct timer_list preempt; -/** -* @default_priolist: priority list for I915_PRIORITY_NORMAL -*/ -struct i915_priolist default_priolist; -/** * @ccid: identifier for contexts submitted to this engine */ @@ -191,11 +182,6 @@ struct intel_engine_execlists {*/ u32 reset_ccid; -/** -* @no_priolist: priority lists disabled -*/ -bool no_priolist; -/** * @submit_reg: gen-specific execlist submission register * set to the ExecList Submission Port (elsp) register pre-Gen11 and to @@ -238,23 +224,8 @@ struct intel_engine_execlists {unsigned int port_mask;/** -* @queue_priority_hint: Highest pending priority. -* -* When we add requests into the queue, or adjust the priority of -* executing requests, we compute the maximum priority of those -* pending requests. We can then use this value to determine if -* we need to preempt the executing requests to service the queue. -* However, since the we may have recorded the priority of an inflight -* request we wanted to preempt but since completed, at the time of -* dequeuing the priority hint may no longer may match the highest -* available request priority. +* @virtual: virtual of requests, in priority lists */ -int queue_priority_hint; - -/** -* @queue: queue of requests, in priority lists -*/ -struct rb_root_cached queue;struct rb_root_cached virtual;/** @@ -326,11 +297,7 @@ struct intel_engine_cs {struct intel_sseu sseu; -struct { -spinlock_t lock; -struct list_head requests; -struct list_head hold;/* ready requests, but on hold */ - } active; +struct i915_sched_engine *sched_engine;/* keep a request in reserve for a [pm] barrier under oom */ struct i915_request *request_pool;@@ -459,9 +426,6 @@ struct intel_engine_cs {* dependencies may need rescheduling. Note the request itself may * not be ready to run! */ -void (*schedule)(struct i915_request *request, -const struct i915_sched_attr *attr); -void (*release)(struct intel_engine_cs *engine);struct intel_engine_execlists execlists;drivers/gpu/drm/i915/gt/intel_engine_user.c +1
-1@@ -107,7 +107,7 @@ static void set_scheduler_caps(struct drm_i915_private *i915)for_each_uabi_engine (engine, i915) {/* all engines must agree! */ int i; -if (engine->schedule) +if (engine->sched_engine->schedule) enabled |= (I915_SCHEDULER_CAP_ENABLED |I915_SCHEDULER_CAP_PRIORITY );else drivers/gpu/drm/i915/gt/intel_execlists_submission.c +213
-137@@ -273,11 +273,11 @@ static int effective_prio(const struct i915_request *rq)return prio; } -static int queue_prio (const struct intel_engine_execlists *execlists) +static int queue_prio (const struct i915_sched_engine *sched_engine) {struct rb_node *rb; - rb =rb_first_cached (&execlists->queue); + rb =rb_first_cached (&sched_engine->queue);if (!rb)return INT_MIN ;@@ -318,14 +318,14 @@ static bool need_preempt(const struct intel_engine_cs *engine,* to preserve FIFO ordering of dependencies. */ last_prio =max (effective_prio (rq),I915_PRIORITY_NORMAL -1 ); -if (engine->execlists.queue_priority_hint <= last_prio) +if (engine->sched_engine->queue_priority_hint <= last_prio)return false;/* * Check against the first request in ELSP[1], it will, thanks to the * power of PI, be the highest priority of that context. */ -if (!list_is_last (&rq->sched.link, &engine->active.requests) && +if (!list_is_last (&rq->sched.link, &engine->sched_engine->requests) &&rq_prio (list_next_entry (rq, sched.link)) > last_prio)return true;@@ -340,7 +340,7 @@ static bool need_preempt(const struct intel_engine_cs *engine,* context, it's priority would not exceed ELSP[0] aka last_prio. */ return max (virtual_prio (&engine->execlists), -queue_prio (&engine->execlists)) > last_prio; +queue_prio (engine->sched_engine)) > last_prio; } __maybe_unused static bool@@ -367,10 +367,10 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)struct list_head *pl;int prio =I915_PRIORITY_INVALID ; -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);list_for_each_entry_safe_reverse (rq, rn, - &engine->active.requests, + &engine->sched_engine->requests, sched.link) {if (__i915_request_is_complete (rq)) {list_del_init (&rq->sched.link);@@ -382,9 +382,10 @@ __unwind_incomplete_requests(struct intel_engine_cs *engine)GEM_BUG_ON (rq_prio (rq) ==I915_PRIORITY_INVALID );if (rq_prio (rq) != prio) { prio =rq_prio (rq); - pl =i915_sched_lookup_priolist (engine, prio); + pl =i915_sched_lookup_priolist (engine->sched_engine, + prio); } -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine));list_move (&rq->sched.link, pl);set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags);@@ -534,13 +535,13 @@ resubmit_virtual_request(struct i915_request *rq, struct virtual_engine *ve) {struct intel_engine_cs *engine = rq->engine; -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock);clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags);WRITE_ONCE (rq->engine, &ve->base); ve->base.submit_request (rq); -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock); }static void kick_siblings (struct i915_request *rq,struct intel_context *ce)@@ -569,7 +570,7 @@ static void kick_siblings(struct i915_request *rq, struct intel_context *ce)resubmit_virtual_request (rq, ve);if (READ_ONCE (ve->request)) -tasklet_hi_schedule (&ve->base.execlists.tasklet); +i915_sched_engine_hi_kick (ve->base.sched_engine); } static void __execlists_schedule_out(struct i915_request * const rq,@@ -579,7 +580,7 @@ static void __execlists_schedule_out(struct i915_request * const rq,unsigned int ccid;/* -* NB process_csb() is not under the engine->active.lock and hence +* NB process_csb() is not under the engine->sched_engine->lock and hence * schedule_out can race with schedule_in meaning that we should * refrain from doing non-trivial work here. */ @@ -721,12 +722,11 @@ dump_port(char *buf, int buflen, const char *prefix, struct i915_request *rq) } static __maybe_unused noinline void -trace_ports (const struct intel_engine_execlists *execlists, +trace_ports (const struct intel_engine_cs *engine, +const struct intel_engine_execlists *execlists,const char *msg,struct i915_request *const *ports) { -const struct intel_engine_cs *engine = -container_of (execlists,typeof (*engine), execlists);char __maybe_unused p0[40 ], p1[40 ];if (!ports[0 ])@@ -738,25 +738,24 @@ trace_ports(const struct intel_engine_execlists *execlists, }static bool -reset_in_progress (const struct intel_engine_execlists *execlists) +reset_in_progress (const struct intel_engine_cs *engine) { -return unlikely (!__tasklet_is_enabled (&execlists->tasklet)); +return unlikely (!__tasklet_is_enabled (&engine->sched_engine->tasklet)); } static __maybe_unused noinline bool -assert_pending_valid (const struct intel_engine_execlists *execlists, +assert_pending_valid (struct intel_engine_cs *engine, +const struct intel_engine_execlists *execlists,const char *msg) { -struct intel_engine_cs *engine = -container_of (execlists,typeof (*engine), execlists);struct i915_request *const *port, *rq, *prev =NULL ;struct intel_context *ce =NULL ;u32 ccid =-1 ; -trace_ports (execlists, msg, execlists->pending); +trace_ports (engine, execlists, msg, execlists->pending);/* We may be messing around with the lists during reset, lalala */ -if (reset_in_progress (execlists)) +if (reset_in_progress (engine))return true;if (!execlists->pending[0 ]) {@@ -878,7 +877,7 @@ static void execlists_submit_ports(struct intel_engine_cs *engine)struct intel_engine_execlists *execlists = &engine->execlists;unsigned int n; -GEM_BUG_ON (!assert_pending_valid (execlists,"submit" )); +GEM_BUG_ON (!assert_pending_valid (engine, execlists,"submit" ));/* * We can skip acquiring intel_runtime_pm_get() here as it was taken @@ -1096,7 +1095,8 @@ static void defer_active(struct intel_engine_cs *engine)if (!rq)return ; -defer_request (rq,i915_sched_lookup_priolist (engine,rq_prio (rq))); +defer_request (rq,i915_sched_lookup_priolist (engine->sched_engine, +rq_prio (rq))); } static bool@@ -1133,13 +1133,14 @@ static bool needs_timeslice(const struct intel_engine_cs *engine,return false;/* If ELSP[1] is occupied, always check to see if worth slicing */ -if (!list_is_last_rcu (&rq->sched.link, &engine->active.requests)) { +if (!list_is_last_rcu (&rq->sched.link, + &engine->sched_engine->requests)) {ENGINE_TRACE (engine,"timeslice required for second inflight context\n" );return true; }/* Otherwise, ELSP[0] is by itself, but may be waiting in the queue */ -if (!RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)) { +if (!i915_sched_engine_is_empty (engine->sched_engine)) {ENGINE_TRACE (engine,"timeslice required for queue\n" );return true; }@@ -1187,7 +1188,7 @@ static void start_timeslice(struct intel_engine_cs *engine)* its timeslice, so recheck. */ if (!timer_pending (&el->timer)) -tasklet_hi_schedule (&el->tasklet); +i915_sched_engine_hi_kick (engine->sched_engine);return ; }@@ -1235,6 +1236,7 @@ static bool completed(const struct i915_request *rq)static void execlists_dequeue (struct intel_engine_cs *engine) { +struct i915_sched_engine *const sched_engine = engine->sched_engine;struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_request **port = execlists->pending;struct i915_request **const last_port = port + execlists->port_mask;@@ -1265,7 +1267,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* and context switches) submission. */ -spin_lock (&engine->active.lock); +spin_lock (&engine->sched_engine->lock);/* * If the queue is higher priority than the last @@ -1287,7 +1289,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine) last->fence.context, last->fence.seqno, last->sched.attr.priority, - execlists->queue_priority_hint); + sched_engine->queue_priority_hint);record_preemption (execlists);/* @@ -1313,7 +1315,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)yesno (timer_expired (&execlists->timer)), last->fence.context, last->fence.seqno,rq_prio (last), - execlists->queue_priority_hint, + sched_engine->queue_priority_hint, yesno(timeslice_yield(execlists, last)));/* @@ -1365,7 +1367,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* Even if ELSP[1] is occupied and not worthy * of timeslices, our queue might be. */ -spin_unlock (&engine->active.lock); +spin_unlock (&sched_engine->lock);return ; } }@@ -1375,7 +1377,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)while ((ve =first_virtual_engine (engine))) {struct i915_request *rq; -spin_lock (&ve->base.active.lock); +spin_lock (&ve->base.sched_engine->lock); rq = ve->request;if (unlikely (!virtual_matches (ve, rq, engine)))@@ -1384,14 +1386,14 @@ static void execlists_dequeue(struct intel_engine_cs *engine)GEM_BUG_ON (rq->engine != &ve->base);GEM_BUG_ON (rq->context != &ve->context); -if (unlikely (rq_prio (rq) <queue_prio (execlists))) { -spin_unlock (&ve->base.active.lock); +if (unlikely (rq_prio (rq) <queue_prio (sched_engine))) { +spin_unlock (&ve->base.sched_engine->lock);break ; }if (last && !can_merge_rq (last, rq)) { -spin_unlock (&ve->base.active.lock); -spin_unlock (&engine->active.lock); +spin_unlock (&ve->base.sched_engine->lock); +spin_unlock (&sched_engine->lock);return ;/* leave this for another sibling */ }@@ -1405,7 +1407,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine) yesno(engine != ve->siblings[0]));WRITE_ONCE (ve->request,NULL ); -WRITE_ONCE (ve->base.execlists.queue_priority_hint,INT_MIN ); +WRITE_ONCE (ve->base.sched_engine->queue_priority_hint,INT_MIN ); rb = &ve->nodes[engine->id].rb;rb_erase_cached (rb, &execlists->virtual);@@ -1437,7 +1439,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)i915_request_put (rq); unlock: -spin_unlock (&ve->base.active.lock); +spin_unlock (&ve->base.sched_engine->lock);/* * Hmm, we have a bunch of virtual engine requests, @@ -1450,7 +1452,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine)break ; } -while ((rb =rb_first_cached (&execlists->queue))) { +while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;@@ -1529,7 +1531,7 @@ static void execlists_dequeue(struct intel_engine_cs *engine) } } -rb_erase_cached (&p->node, &execlists->queue); +rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); } done:@@ -1551,8 +1553,9 @@ static void execlists_dequeue(struct intel_engine_cs *engine)* request triggering preemption on the next dequeue (or subsequent * interrupt for secondary ports). */ - execlists->queue_priority_hint =queue_prio (execlists); -spin_unlock (&engine->active.lock); + sched_engine->queue_priority_hint =queue_prio (sched_engine); +i915_sched_engine_reset_on_empty (sched_engine); +spin_unlock (&sched_engine->lock);/* * We can skip poking the HW if we ended up with exactly the same set @@ -1767,8 +1770,8 @@ process_csb(struct intel_engine_cs *engine, struct i915_request **inactive)* access. Either we are inside the tasklet, or the tasklet is disabled * and we assume that is only inside the reset paths and so serialised. */ -GEM_BUG_ON (!tasklet_is_locked (&execlists->tasklet) && - !reset_in_progress (execlists)); +GEM_BUG_ON (!tasklet_is_locked (&engine->sched_engine->tasklet) && + !reset_in_progress (engine));/* * Note that csb_write, csb_status may be either in HWSP or mmio. @@ -1866,12 +1869,12 @@ process_csb(struct intel_engine_cs *engine, struct i915_request **inactive)smp_wmb ();/* notify execlists_active() */ /* cancel old inflight, prepare for switch */ -trace_ports (execlists,"preempted" , old); +trace_ports (engine, execlists,"preempted" , old);while (*old) *inactive++ = *old++;/* switch pending to inflight */ -GEM_BUG_ON (!assert_pending_valid (execlists,"promote" )); +GEM_BUG_ON (!assert_pending_valid (engine, execlists,"promote" ));copy_ports (execlists->inflight, execlists->pending,execlists_num_ports (execlists));@@ -1889,7 +1892,7 @@ process_csb(struct intel_engine_cs *engine, struct i915_request **inactive) }/* port0 completed, advanced to port1 */ -trace_ports (execlists,"completed" , execlists->active); +trace_ports (engine, execlists,"completed" , execlists->active);/* * We rely on the hardware being strongly @@ -1979,7 +1982,7 @@ static void __execlists_hold(struct i915_request *rq)__i915_request_unsubmit (rq);clear_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); -list_move_tail (&rq->sched.link, &rq->engine->active.hold); +list_move_tail (&rq->sched.link, &rq->engine->sched_engine->hold);i915_request_set_hold (rq);RQ_TRACE (rq,"on hold\n" );@@ -2016,7 +2019,7 @@ static bool execlists_hold(struct intel_engine_cs *engine,if (i915_request_on_hold (rq))return false; -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock);if (__i915_request_is_complete (rq)) {/* too late! */ rq =NULL ;@@ -2032,10 +2035,10 @@ static bool execlists_hold(struct intel_engine_cs *engine,GEM_BUG_ON (i915_request_on_hold (rq));GEM_BUG_ON (rq->engine != engine);__execlists_hold (rq); -GEM_BUG_ON (list_empty (&engine->active.hold)); +GEM_BUG_ON (list_empty (&engine->sched_engine->hold)); unlock: -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock);return rq; }@@ -2079,7 +2082,7 @@ static void __execlists_unhold(struct i915_request *rq)i915_request_clear_hold (rq);list_move_tail (&rq->sched.link, -i915_sched_lookup_priolist (rq->engine, +i915_sched_lookup_priolist (rq->engine->sched_engine,rq_prio (rq)));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags);@@ -2115,7 +2118,7 @@ static void __execlists_unhold(struct i915_request *rq)static void execlists_unhold (struct intel_engine_cs *engine,struct i915_request *rq) { -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock);/* * Move this request back to the priority queue, and all of its @@ -2123,12 +2126,12 @@ static void execlists_unhold(struct intel_engine_cs *engine,*/ __execlists_unhold (rq); -if (rq_prio (rq) > engine->execlists.queue_priority_hint) { - engine->execlists.queue_priority_hint =rq_prio (rq); -tasklet_hi_schedule (&engine->execlists.tasklet); +if (rq_prio (rq) > engine->sched_engine->queue_priority_hint) { + engine->sched_engine->queue_priority_hint =rq_prio (rq); +i915_sched_engine_hi_kick (engine->sched_engine); } -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock); }struct execlists_capture {@@ -2258,13 +2261,13 @@ static void execlists_capture(struct intel_engine_cs *engine)if (!cap)return ; -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock); cap->rq =active_context (engine,active_ccid (engine));if (cap->rq) { cap->rq =active_request (cap->rq->context->timeline, cap->rq); cap->rq =i915_request_get_rcu (cap->rq); } -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock);if (!cap->rq) goto err_free;@@ -2316,13 +2319,13 @@ static void execlists_reset(struct intel_engine_cs *engine, const char *msg)ENGINE_TRACE (engine,"reset for %s\n" , msg);/* Mark this tasklet as disabled to avoid waiting for it to complete */ -tasklet_disable_nosync (&engine->execlists.tasklet); +tasklet_disable_nosync (&engine->sched_engine->tasklet);ring_set_paused (engine,1 );/* Freeze the current request in place */ execlists_capture (engine);intel_engine_reset (engine, msg); -tasklet_enable (&engine->execlists.tasklet); +tasklet_enable (&engine->sched_engine->tasklet);clear_and_wake_up_bit (bit, lock); }@@ -2345,8 +2348,9 @@ static bool preempt_timeout(const struct intel_engine_cs *const engine)*/ static void execlists_submission_tasklet (struct tasklet_struct *t) { -struct intel_engine_cs *const engine = -from_tasklet (engine, t, execlists.tasklet); +struct i915_sched_engine *sched_engine = +from_tasklet (sched_engine, t, tasklet); +struct intel_engine_cs *const engine = sched_engine->engine;struct i915_request *post[2 *EXECLIST_MAX_PORTS ];struct i915_request **inactive;@@ -2421,13 +2425,16 @@ static void execlists_irq_handler(struct intel_engine_cs *engine, u16 iir)intel_engine_signal_breadcrumbs (engine);if (tasklet) -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); }static void __execlists_kick (struct intel_engine_execlists *execlists) { +struct intel_engine_cs *engine = +container_of (execlists,typeof (*engine), execlists); +/* Kick the tasklet for some interrupt coalescing and reset handling */ -tasklet_hi_schedule (&execlists->tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); }#define execlists_kick (t, member) \@@ -2448,19 +2455,20 @@ static void queue_request(struct intel_engine_cs *engine, {GEM_BUG_ON (!list_empty (&rq->sched.link));list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (engine,rq_prio (rq))); +i915_sched_lookup_priolist (engine->sched_engine, +rq_prio (rq)));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); }static bool submit_queue (struct intel_engine_cs *engine,const struct i915_request *rq) { -struct intel_engine_execlists *execlists = &engine->execlists; +struct i915_sched_engine *sched_engine = engine->sched_engine; -if (rq_prio (rq) <= execlists->queue_priority_hint) +if (rq_prio (rq) <= sched_engine->queue_priority_hint)return false; - execlists->queue_priority_hint =rq_prio (rq); + sched_engine->queue_priority_hint =rq_prio (rq);return true; }@@ -2468,7 +2476,7 @@ static bool ancestor_on_hold(const struct intel_engine_cs *engine, const struct i915_request *rq) {GEM_BUG_ON (i915_request_on_hold (rq)); -return !list_empty (&engine->active.hold) &&hold_request (rq); +return !list_empty (&engine->sched_engine->hold) &&hold_request (rq); }static void execlists_submit_request (struct i915_request *request)@@ -2477,23 +2485,24 @@ static void execlists_submit_request(struct i915_request *request)unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);if (unlikely (ancestor_on_hold (engine, request))) {RQ_TRACE (request,"ancestor on hold\n" ); -list_add_tail (&request->sched.link, &engine->active.hold); +list_add_tail (&request->sched.link, + &engine->sched_engine->hold);i915_request_set_hold (request); }else {queue_request (engine, request); -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine));GEM_BUG_ON (list_empty (&request->sched.link));if (submit_queue (engine, request)) -__execlists_kick (&engine->execlists); +i915_sched_engine_hi_kick (engine->sched_engine); } -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); } static int@@ -2800,10 +2809,10 @@ static int execlists_resume(struct intel_engine_cs *engine)static void execlists_reset_prepare (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine;ENGINE_TRACE (engine,"depth<-%d\n" , -atomic_read (&execlists->tasklet.count)); +atomic_read (&sched_engine->tasklet.count));/* * Prevent request submission to the hardware until we have @@ -2814,8 +2823,8 @@ static void execlists_reset_prepare(struct intel_engine_cs *engine)* Turning off the execlists->tasklet until the reset is over * prevents the race. */ -__tasklet_disable_sync_once (&execlists->tasklet); -GEM_BUG_ON (!reset_in_progress (execlists)); +__tasklet_disable_sync_once (&sched_engine->tasklet); +GEM_BUG_ON (!reset_in_progress (engine));/* * We stop engines, otherwise we might get failed reset and a @@ -2957,23 +2966,25 @@ static void execlists_reset_rewind(struct intel_engine_cs *engine, bool stalled)/* Push back any incomplete requests for replay after the reset. */ rcu_read_lock (); -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);__unwind_incomplete_requests (engine); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags);rcu_read_unlock (); }static void nop_submission_tasklet (struct tasklet_struct *t) { -struct intel_engine_cs *const engine = -from_tasklet (engine, t, execlists.tasklet); +struct i915_sched_engine *sched_engine = +from_tasklet (sched_engine, t, tasklet); +struct intel_engine_cs *const engine = sched_engine->engine;/* The driver is wedged; don't process any more events. */ -WRITE_ONCE (engine->execlists.queue_priority_hint,INT_MIN ); +WRITE_ONCE (engine->sched_engine->queue_priority_hint,INT_MIN ); }static void execlists_reset_cancel (struct intel_engine_cs *engine) { +struct i915_sched_engine *const sched_engine = engine->sched_engine;struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_request *rq, *rn;struct rb_node *rb;@@ -2998,15 +3009,15 @@ static void execlists_reset_cancel(struct intel_engine_cs *engine)execlists_reset_csb (engine, true);rcu_read_lock (); -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&sched_engine->lock, flags);/* Mark all executing requests as skipped. */ -list_for_each_entry (rq, &engine->active.requests, sched.link) +list_for_each_entry (rq, &sched_engine->requests, sched.link)i915_request_put (i915_request_mark_eio (rq));intel_engine_signal_breadcrumbs (engine);/* Flush the queued requests to the timeline list (for retiring). */ -while ((rb =rb_first_cached (&execlists->queue))) { +while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);priolist_for_each_request_consume (rq, rn, p) {@@ -3016,12 +3027,12 @@ static void execlists_reset_cancel(struct intel_engine_cs *engine) } } -rb_erase_cached (&p->node, &execlists->queue); +rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); }/* On-hold requests will be flushed to timeline upon their release */ -list_for_each_entry (rq, &engine->active.hold, sched.link) +list_for_each_entry (rq, &sched_engine->hold, sched.link)i915_request_put (i915_request_mark_eio (rq));/* Cancel all attached virtual engines */ @@ -3032,7 +3043,7 @@ static void execlists_reset_cancel(struct intel_engine_cs *engine)rb_erase_cached (rb, &execlists->virtual);RB_CLEAR_NODE (rb); -spin_lock (&ve->base.active.lock); +spin_lock (&ve->base.sched_engine->lock); rq =fetch_and_zero (&ve->request);if (rq) {if (i915_request_mark_eio (rq)) {@@ -3042,26 +3053,26 @@ static void execlists_reset_cancel(struct intel_engine_cs *engine) }i915_request_put (rq); - ve->base.execlists.queue_priority_hint =INT_MIN ; + ve->base.sched_engine->queue_priority_hint =INT_MIN ; } -spin_unlock (&ve->base.active.lock); +spin_unlock (&ve->base.sched_engine->lock); }/* Remaining _unready_ requests will be nop'ed when submitted */ - execlists->queue_priority_hint =INT_MIN ; - execlists->queue =RB_ROOT_CACHED ; + sched_engine->queue_priority_hint =INT_MIN ; + sched_engine->queue =RB_ROOT_CACHED ; -GEM_BUG_ON (__tasklet_is_enabled (&execlists->tasklet)); - execlists->tasklet.callback = nop_submission_tasklet; +GEM_BUG_ON (__tasklet_is_enabled (&sched_engine->tasklet)); + sched_engine->tasklet.callback = nop_submission_tasklet; -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags);rcu_read_unlock (); }static void execlists_reset_finish (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine;/* * After a GPU reset, we may have requests to replay. Do so now while @@ -3073,14 +3084,14 @@ static void execlists_reset_finish(struct intel_engine_cs *engine)* reset as the next level of recovery, and as a final resort we * will declare the device wedged. */ -GEM_BUG_ON (!reset_in_progress (execlists)); +GEM_BUG_ON (!reset_in_progress (engine));/* And kick in case we missed a new request submission. */ -if (__tasklet_enable (&execlists->tasklet)) -__execlists_kick (execlists); +if (__tasklet_enable (&sched_engine->tasklet)) +i915_sched_engine_hi_kick (sched_engine);ENGINE_TRACE (engine,"depth->%d\n" , -atomic_read (&execlists->tasklet.count)); +atomic_read (&sched_engine->tasklet.count)); }static void gen8_logical_ring_enable_irq (struct intel_engine_cs *engine)@@ -3110,11 +3121,59 @@ static bool can_preempt(struct intel_engine_cs *engine)return engine->class !=RENDER_CLASS ; } +static void kick_execlists (const struct i915_request *rq,int prio) +{ +struct i915_sched_engine *sched_engine = rq->engine->sched_engine; +const struct i915_request *inflight; + +/* +* We only need to kick the tasklet once for the high priority +* new context we add into the queue. +*/ +if (prio <= sched_engine->queue_priority_hint) +return ; + +rcu_read_lock (); + +/* Nothing currently active? We're overdue for a submission! */ + inflight =execlists_active (&rq->engine->execlists); +if (!inflight) + goto unlock; + +/* +* If we are already the currently executing context, don't +* bother evaluating if we should preempt ourselves. +*/ +if (inflight->context == rq->context) + goto unlock; + +ENGINE_TRACE (rq->engine, +"bumping queue-priority-hint:%d for rq:%llx:%lld, inflight:%llx:%lld prio %d\n" , + prio, + rq->fence.context, rq->fence.seqno, + inflight->fence.context, inflight->fence.seqno, + inflight->sched.attr.priority); + + sched_engine->queue_priority_hint = prio; + +/* +* Allow preemption of low -> normal -> high, but we do +* not allow low priority tasks to preempt other low priority +* tasks under the impression that latency for low priority +* tasks does not matter (as much as background throughput), +* so kiss. +*/ +if (prio >=max (I915_PRIORITY_NORMAL ,rq_prio (inflight))) +i915_sched_engine_hi_kick (sched_engine); + +unlock: +rcu_read_unlock (); +} +static void execlists_set_default_submission (struct intel_engine_cs *engine) { engine->submit_request = execlists_submit_request; - engine->schedule = i915_schedule; - engine->execlists.tasklet.callback = execlists_submission_tasklet; + engine->sched_engine->tasklet.callback = execlists_submission_tasklet; }static void execlists_shutdown (struct intel_engine_cs *engine)@@ -3122,7 +3181,7 @@ static void execlists_shutdown(struct intel_engine_cs *engine)/* Synchronise with residual timers and any softirq they raise */ del_timer_sync (&engine->execlists.timer);del_timer_sync (&engine->execlists.preempt); -tasklet_kill (&engine->execlists.tasklet); +i915_sched_engine_kill (engine->sched_engine); }static void execlists_release (struct intel_engine_cs *engine)@@ -3238,10 +3297,14 @@ int intel_execlists_submission_setup(struct intel_engine_cs *engine)struct intel_uncore *uncore = engine->uncore;u32 base = engine->mmio_base; -tasklet_setup (&engine->execlists.tasklet, execlists_submission_tasklet); +tasklet_setup (&engine->sched_engine->tasklet, + execlists_submission_tasklet);timer_setup (&engine->execlists.timer, execlists_timeslice,0 );timer_setup (&engine->execlists.preempt, execlists_preempt,0 ); + engine->sched_engine->schedule = i915_schedule; + engine->sched_engine->kick_backend = kick_execlists; +logical_ring_default_vfuncs (engine);logical_ring_default_irqs (engine);@@ -3286,7 +3349,7 @@ int intel_execlists_submission_setup(struct intel_engine_cs *engine)static struct list_head *virtual_queue (struct virtual_engine *ve) { -return &ve->base.execlists.default_priolist.requests; +return &ve->base.sched_engine->default_priolist.requests; }static void rcu_virtual_context_destroy (struct work_struct *wrk)@@ -3301,7 +3364,7 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)if (unlikely (ve->request)) {struct i915_request *old; -spin_lock_irq (&ve->base.active.lock); +spin_lock_irq (&ve->base.sched_engine->lock); old =fetch_and_zero (&ve->request);if (old) {@@ -3310,7 +3373,7 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)i915_request_put (old); } -spin_unlock_irq (&ve->base.active.lock); +spin_unlock_irq (&ve->base.sched_engine->lock); }/* @@ -3320,7 +3383,7 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)* rbtrees as in the case it is running in parallel, it may reinsert * the rb_node into a sibling. */ -tasklet_kill (&ve->base.execlists.tasklet); +i915_sched_engine_kill (ve->base.sched_engine);/* Decouple ourselves from the siblings, no more access allowed. */ for (n =0 ; n < ve->num_siblings; n++) {@@ -3330,21 +3393,23 @@ static void rcu_virtual_context_destroy(struct work_struct *wrk)if (RB_EMPTY_NODE (node))continue ; -spin_lock_irq (&sibling->active.lock); +spin_lock_irq (&sibling->sched_engine->lock);/* Detachment is lazily performed in the execlists tasklet */ if (!RB_EMPTY_NODE (node))rb_erase_cached (node, &sibling->execlists.virtual); -spin_unlock_irq (&sibling->active.lock); +spin_unlock_irq (&sibling->sched_engine->lock); } -GEM_BUG_ON (__tasklet_is_scheduled (&ve->base.execlists.tasklet)); +GEM_BUG_ON (__tasklet_is_scheduled (&ve->base.sched_engine->tasklet));GEM_BUG_ON (!list_empty (virtual_queue (ve)));lrc_fini (&ve->context);intel_context_fini (&ve->context);intel_breadcrumbs_free (ve->base.breadcrumbs); +if (ve->base.sched_engine) +i915_sched_engine_put (ve->base.sched_engine);intel_engine_free_request_pool (&ve->base);kfree (ve->bonds);@@ -3475,16 +3540,18 @@ static intel_engine_mask_t virtual_submission_mask(struct virtual_engine *ve)ENGINE_TRACE (&ve->base,"rq=%llx:%lld, mask=%x, prio=%d\n" , rq->fence.context, rq->fence.seqno, - mask, ve->base.execlists.queue_priority_hint); + mask, ve->base.sched_engine->queue_priority_hint);return mask; }static void virtual_submission_tasklet (struct tasklet_struct *t) { +struct i915_sched_engine *sched_engine = +from_tasklet (sched_engine, t, tasklet);struct virtual_engine *const ve = -from_tasklet (ve, t, base.execlists.tasklet); -const int prio =READ_ONCE (ve->base.execlists.queue_priority_hint); + (struct virtual_engine *)sched_engine->engine; +const int prio =READ_ONCE (ve->base.sched_engine->queue_priority_hint);intel_engine_mask_t mask;unsigned int n;@@ -3503,7 +3570,7 @@ static void virtual_submission_tasklet(struct tasklet_struct *t)if (!READ_ONCE (ve->request))break ;/* already handled by a sibling's tasklet */ -spin_lock_irq (&sibling->active.lock); +spin_lock_irq (&sibling->sched_engine->lock);if (unlikely (!(mask & sibling->mask))) {if (!RB_EMPTY_NODE (&node->rb)) {@@ -3552,11 +3619,11 @@ static void virtual_submission_tasklet(struct tasklet_struct *t) submit_engine:GEM_BUG_ON (RB_EMPTY_NODE (&node->rb)); node->prio = prio; -if (first && prio > sibling->execlists.queue_priority_hint) -tasklet_hi_schedule (&sibling->execlists.tasklet); +if (first && prio > sibling->sched_engine->queue_priority_hint) +i915_sched_engine_hi_kick (sibling->sched_engine); unlock_engine: -spin_unlock_irq (&sibling->active.lock); +spin_unlock_irq (&sibling->sched_engine->lock);if (intel_context_inflight (&ve->context))break ;@@ -3574,7 +3641,7 @@ static void virtual_submit_request(struct i915_request *rq)GEM_BUG_ON (ve->base.submit_request != virtual_submit_request); -spin_lock_irqsave (&ve->base.active.lock, flags); +spin_lock_irqsave (&ve->base.sched_engine->lock, flags);/* By the time we resubmit a request, it may be completed */ if (__i915_request_is_complete (rq)) {@@ -3588,16 +3655,16 @@ static void virtual_submit_request(struct i915_request *rq)i915_request_put (ve->request); } - ve->base.execlists.queue_priority_hint =rq_prio (rq); + ve->base.sched_engine->queue_priority_hint =rq_prio (rq); ve->request =i915_request_get (rq);GEM_BUG_ON (!list_empty (virtual_queue (ve)));list_move_tail (&rq->sched.link,virtual_queue (ve)); -tasklet_hi_schedule (&ve->base.execlists.tasklet); +i915_sched_engine_hi_kick (ve->base.sched_engine); unlock: -spin_unlock_irqrestore (&ve->base.active.lock, flags); +spin_unlock_irqrestore (&ve->base.sched_engine->lock, flags); } static struct ve_bond *@@ -3681,19 +3748,24 @@ intel_execlists_create_virtual(struct intel_engine_cs **siblings,snprintf (ve->base.name,sizeof (ve->base.name),"virtual" ); -intel_engine_init_active (&ve->base,ENGINE_VIRTUAL ); -intel_engine_init_execlists (&ve->base); + ve->base.sched_engine =i915_sched_engine_create (ENGINE_VIRTUAL ); +if (!ve->base.sched_engine) { +kfree (ve); +return ERR_PTR (-ENOMEM ); + } + ve->base.sched_engine->engine = &ve->base; ve->base.cops = &virtual_context_ops; ve->base.request_alloc = execlists_request_alloc; - ve->base.schedule = i915_schedule; + ve->base.sched_engine->schedule = i915_schedule; ve->base.submit_request = virtual_submit_request; ve->base.bond_execute = virtual_bond_execute;INIT_LIST_HEAD (virtual_queue (ve)); - ve->base.execlists.queue_priority_hint =INT_MIN ; -tasklet_setup (&ve->base.execlists.tasklet, virtual_submission_tasklet); + ve->base.sched_engine->queue_priority_hint =INT_MIN ; +tasklet_setup (&ve->base.sched_engine->tasklet, + virtual_submission_tasklet);intel_context_init (&ve->context, &ve->base);@@ -3721,7 +3793,7 @@ intel_execlists_create_virtual(struct intel_engine_cs **siblings,* layering if we handle cloning of the requests and * submitting a copy into each backend. */ -if (sibling->execlists.tasklet.callback != +if (sibling->sched_engine->tasklet.callback != execlists_submission_tasklet) { err = -ENODEV ; goto err_put;@@ -3756,6 +3828,9 @@ intel_execlists_create_virtual(struct intel_engine_cs **siblings, "v%dx%d", ve->base.class, count); ve->base.context_size = sibling->context_size; + ve->base.sched_engine->kick_backend = + sibling->sched_engine->kick_backend; + ve->base.emit_bb_start = sibling->emit_bb_start; ve->base.emit_flush = sibling->emit_flush; ve->base.emit_init_breadcrumb = sibling->emit_init_breadcrumb;@@ -3848,17 +3923,18 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine, int indent), unsigned int max) { +const struct i915_sched_engine *sched_engine = engine->sched_engine;const struct intel_engine_execlists *execlists = &engine->execlists;struct i915_request *rq, *last;unsigned long flags;unsigned int count;struct rb_node *rb; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags); last =NULL ; count =0 ; -list_for_each_entry (rq, &engine->active.requests, sched.link) { +list_for_each_entry (rq, &sched_engine->requests, sched.link) {if (count++ < max -1 )show_request (m, rq,"\t\t" ,0 );else @@ -3873,13 +3949,13 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,show_request (m, last,"\t\t" ,0 ); } -if (execlists->queue_priority_hint !=INT_MIN ) +if (sched_engine->queue_priority_hint !=INT_MIN )drm_printf (m,"\t\tQueue priority hint: %d\n" , -READ_ONCE (execlists->queue_priority_hint)); +READ_ONCE (sched_engine->queue_priority_hint)); last =NULL ; count =0 ; -for (rb =rb_first_cached (&execlists->queue); rb; rb =rb_next (rb)) { +for (rb =rb_first_cached (&sched_engine->queue); rb; rb =rb_next (rb)) {struct i915_priolist *p =rb_entry (rb,typeof (*p), node);priolist_for_each_request (rq, p) {@@ -3921,7 +3997,7 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,show_request (m, last,"\t\t" ,0 ); } -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }#if IS_ENABLED (CONFIG_DRM_I915_SELFTEST )drivers/gpu/drm/i915/gt/intel_ring_submission.c +7
-6@@ -339,9 +339,9 @@ static void reset_rewind(struct intel_engine_cs *engine, bool stalled)u32 head; rq =NULL ; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);rcu_read_lock (); -list_for_each_entry (pos, &engine->active.requests, sched.link) { +list_for_each_entry (pos, &engine->sched_engine->requests, sched.link) {if (!__i915_request_is_complete (pos)) { rq = pos;break ;@@ -396,7 +396,7 @@ static void reset_rewind(struct intel_engine_cs *engine, bool stalled) } engine->legacy.ring->head =intel_ring_wrap (engine->legacy.ring, head); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void reset_finish (struct intel_engine_cs *engine)@@ -408,16 +408,17 @@ static void reset_cancel(struct intel_engine_cs *engine)struct i915_request *request;unsigned long flags; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);/* Mark all submitted requests as skipped. */ -list_for_each_entry (request, &engine->active.requests, sched.link) +list_for_each_entry (request, &engine->sched_engine->requests, + sched.link)i915_request_put (i915_request_mark_eio (request));intel_engine_signal_breadcrumbs (engine);/* Remaining _unready_ requests will be nop'ed when submitted */ -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void i9xx_submit_request (struct i915_request *request)drivers/gpu/drm/i915/gt/mock_engine.c +12
-5@@ -253,10 +253,10 @@ static void mock_reset_cancel(struct intel_engine_cs *engine)del_timer_sync (&mock->hw_delay); -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);/* Mark all submitted requests as skipped. */ -list_for_each_entry (rq, &engine->active.requests, sched.link) +list_for_each_entry (rq, &engine->sched_engine->requests, sched.link)i915_request_put (i915_request_mark_eio (rq));intel_engine_signal_breadcrumbs (engine);@@ -269,7 +269,7 @@ static void mock_reset_cancel(struct intel_engine_cs *engine) }INIT_LIST_HEAD (&mock->hw_queue); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void mock_reset_finish (struct intel_engine_cs *engine)@@ -283,6 +283,7 @@ static void mock_engine_release(struct intel_engine_cs *engine)GEM_BUG_ON (timer_pending (&mock->hw_delay)); +i915_sched_engine_put (engine->sched_engine);intel_breadcrumbs_free (engine->breadcrumbs);intel_context_unpin (engine->kernel_context);@@ -345,14 +346,18 @@ int mock_engine_init(struct intel_engine_cs *engine) {struct intel_context *ce; -intel_engine_init_active (engine,ENGINE_MOCK ); + engine->sched_engine =i915_sched_engine_create (ENGINE_MOCK ); +if (!engine->sched_engine) +return -ENOMEM ; + engine->sched_engine->engine = engine; +intel_engine_init_execlists (engine);intel_engine_init__pm (engine);intel_engine_init_retire (engine); engine->breadcrumbs =intel_breadcrumbs_create (NULL );if (!engine->breadcrumbs) -return -ENOMEM ; + goto err_schedule; ce =create_kernel_context (engine);if (IS_ERR (ce))@@ -366,6 +371,8 @@ int mock_engine_init(struct intel_engine_cs *engine) err_breadcrumbs:intel_breadcrumbs_free (engine->breadcrumbs); +err_schedule: +i915_sched_engine_put (engine->sched_engine);return -ENOMEM ; }drivers/gpu/drm/i915/gt/selftest_execlists.c +18
-18@@ -43,7 +43,7 @@ static int wait_for_submit(struct intel_engine_cs *engine, unsigned long timeout) {/* Ignore our own attempts to suppress excess tasklets */ -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); timeout += jiffies; do {@@ -273,7 +273,7 @@ static int live_unlite_restore(struct intel_gt *gt, int prio) };/* Alternatively preempt the spinner with ce[1] */ - engine->schedule (rq[1 ], &attr); + engine->sched_engine->schedule (rq[1 ], &attr); }/* And switch back to ce[0] for good measure */ @@ -606,9 +606,9 @@ static int live_hold_reset(void *arg) err = -EBUSY ; goto out; } -tasklet_disable (&engine->execlists.tasklet); +tasklet_disable (&engine->sched_engine->tasklet); - engine->execlists.tasklet.callback (&engine->execlists.tasklet); + engine->sched_engine->tasklet.callback (&engine->sched_engine->tasklet);GEM_BUG_ON (execlists_active (&engine->execlists) != rq);i915_request_get (rq);@@ -618,7 +618,7 @@ static int live_hold_reset(void *arg)__intel_engine_reset_bh (engine,NULL );GEM_BUG_ON (rq->fence.error != -EIO ); -tasklet_enable (&engine->execlists.tasklet); +tasklet_enable (&engine->sched_engine->tasklet);clear_and_wake_up_bit (I915_RESET_ENGINE + id, >->reset.flags);local_bh_enable ();@@ -900,7 +900,7 @@ release_queue(struct intel_engine_cs *engine,i915_request_add (rq);local_bh_disable (); - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);local_bh_enable ();/* kick tasklet */ i915_request_put (rq);@@ -1183,7 +1183,7 @@ static int live_timeslice_rewind(void *arg)while (i915_request_is_active (rq[A2 ])) {/* semaphore yield! */ /* Wait for the timeslice to kick in */ del_timer (&engine->execlists.timer); -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine);intel_engine_flush_submission (engine); }/* -> ELSP[] = { { A:rq1 }, { B:rq1 } } */ @@ -1325,7 +1325,7 @@ static int live_timeslice_queue(void *arg) err =PTR_ERR (rq); goto err_heartbeat; } - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr); err =wait_for_submit (engine, rq,HZ /2 );if (err) { pr_err("%s: Timed out trying to submit semaphores\n",@@ -1867,7 +1867,7 @@ static int live_late_preempt(void *arg) } attr.priority =I915_PRIORITY_MAX ; - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);if (!igt_wait_for_spinner (&spin_hi, rq)) {pr_err ("High priority context failed to preempt the low priority context\n" );@@ -2480,7 +2480,7 @@ static int live_suppress_self_preempt(void *arg)i915_request_add (rq_b);GEM_BUG_ON (i915_request_completed (rq_a)); - engine->schedule (rq_a, &attr); + engine->sched_engine->schedule (rq_a, &attr);igt_spinner_end (&a.spin);if (!igt_wait_for_spinner (&b.spin, rq_b)) {@@ -2612,7 +2612,7 @@ static int live_chain_preempt(void *arg)i915_request_get (rq);i915_request_add (rq); - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);igt_spinner_end (&hi.spin);if (i915_request_wait (rq,0 ,HZ /5 ) <0 ) {@@ -2971,7 +2971,7 @@ static int live_preempt_gang(void *arg)break ;/* Submit each spinner at increasing priority */ - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr); }while (prio <=I915_PRIORITY_MAX && !__igt_timeout (end_time,NULL )); pr_debug("%s: Preempt chain of %d requests\n",@@ -3219,7 +3219,7 @@ static int preempt_user(struct intel_engine_cs *engine,i915_request_get (rq);i915_request_add (rq); - engine->schedule (rq, &attr); + engine->sched_engine->schedule (rq, &attr);if (i915_request_wait (rq,0 ,HZ /2 ) <0 ) err = -ETIME ;@@ -4593,15 +4593,15 @@ static int reset_virtual_engine(struct intel_gt *gt, err = -EBUSY ; goto out_heartbeat; } -tasklet_disable (&engine->execlists.tasklet); +tasklet_disable (&engine->sched_engine->tasklet); - engine->execlists.tasklet.callback (&engine->execlists.tasklet); + engine->sched_engine->tasklet.callback (&engine->sched_engine->tasklet);GEM_BUG_ON (execlists_active (&engine->execlists) != rq);/* Fake a preemption event; failed of course */ -spin_lock_irq (&engine->active.lock); +spin_lock_irq (&engine->sched_engine->lock);__unwind_incomplete_requests (engine); -spin_unlock_irq (&engine->active.lock); +spin_unlock_irq (&engine->sched_engine->lock);GEM_BUG_ON (rq->engine != engine);/* Reset the engine while keeping our active request on hold */ @@ -4612,7 +4612,7 @@ static int reset_virtual_engine(struct intel_gt *gt,GEM_BUG_ON (rq->fence.error != -EIO );/* Release our grasp on the engine, letting CS flow again */ -tasklet_enable (&engine->execlists.tasklet); +tasklet_enable (&engine->sched_engine->tasklet);clear_and_wake_up_bit (I915_RESET_ENGINE + engine->id, >->reset.flags);local_bh_enable ();drivers/gpu/drm/i915/gt/selftest_hangcheck.c +3
-3@@ -858,12 +858,12 @@ static int active_engine(void *data) rq[idx] =i915_request_get (new);i915_request_add (new); -if (engine->schedule && arg->flags &TEST_PRIORITY ) { +if (engine->sched_engine->schedule && arg->flags &TEST_PRIORITY ) {struct i915_sched_attr attr = { .priority =i915_prandom_u32_max_state (512 , &prng), }; - engine->schedule (rq[idx], &attr); + engine->sched_engine->schedule (rq[idx], &attr); } err =active_request_put (old);@@ -1702,7 +1702,7 @@ static int __igt_atomic_reset_engine(struct intel_engine_cs *engine,const struct igt_atomic_section *p, const char *mode) { - struct tasklet_struct * const t = &engine->execlists.tasklet; + struct tasklet_struct * const t = &engine->sched_engine->tasklet;int err; GEM_TRACE("i915_reset_engine(%s:%s) under %s\n",drivers/gpu/drm/i915/gt/selftest_lrc.c +3
-3@@ -49,7 +49,7 @@ static int wait_for_submit(struct intel_engine_cs *engine, unsigned long timeout) {/* Ignore our own attempts to suppress excess tasklets */ -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); timeout += jiffies; do {@@ -1613,12 +1613,12 @@ static void garbage_reset(struct intel_engine_cs *engine,local_bh_disable ();if (!test_and_set_bit (bit, lock)) { -tasklet_disable (&engine->execlists.tasklet); +tasklet_disable (&engine->sched_engine->tasklet);if (!rq->fence.error)__intel_engine_reset_bh (engine,NULL ); -tasklet_enable (&engine->execlists.tasklet); +tasklet_enable (&engine->sched_engine->tasklet);clear_and_wake_up_bit (bit, lock); }local_bh_enable ();drivers/gpu/drm/i915/gt/selftest_reset.c +1
-1@@ -321,7 +321,7 @@ static int igt_atomic_engine_reset(void *arg) goto out_unlock;for_each_engine (engine, gt, id) { -struct tasklet_struct *t = &engine->execlists.tasklet; +struct tasklet_struct *t = &engine->sched_engine->tasklet;if (t->func)tasklet_disable (t);drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +40
-35@@ -181,6 +181,7 @@ static void schedule_out(struct i915_request *rq)static void __guc_dequeue (struct intel_engine_cs *engine) { +struct i915_sched_engine *const sched_engine = engine->sched_engine;struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_request **first = execlists->inflight;struct i915_request **const last_port = first + execlists->port_mask;@@ -189,7 +190,7 @@ static void __guc_dequeue(struct intel_engine_cs *engine)bool submit = false;struct rb_node *rb; -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);if (last) {if (*++first)@@ -204,7 +205,7 @@ static void __guc_dequeue(struct intel_engine_cs *engine)* event. */ port = first; -while ((rb =rb_first_cached (&execlists->queue))) { +while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);struct i915_request *rq, *rn;@@ -224,11 +225,11 @@ static void __guc_dequeue(struct intel_engine_cs *engine) last = rq; } -rb_erase_cached (&p->node, &execlists->queue); +rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); } done: - execlists->queue_priority_hint = + sched_engine->queue_priority_hint = rb ?to_priolist (rb)->priority :INT_MIN ;if (submit) { *port =schedule_in (last, port - execlists->inflight);@@ -240,13 +241,14 @@ static void __guc_dequeue(struct intel_engine_cs *engine)static void guc_submission_tasklet (struct tasklet_struct *t) { -struct intel_engine_cs *const engine = -from_tasklet (engine, t, execlists.tasklet); +struct i915_sched_engine *sched_engine = +from_tasklet (sched_engine, t, tasklet); +struct intel_engine_cs *const engine = sched_engine->engine;struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_request **port, *rq;unsigned long flags; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);for (port = execlists->inflight; (rq = *port); port++) {if (!i915_request_completed (rq))@@ -262,20 +264,22 @@ static void guc_submission_tasklet(struct tasklet_struct *t)__guc_dequeue (engine); -spin_unlock_irqrestore (&engine->active.lock, flags); +i915_sched_engine_reset_on_empty (engine->sched_engine); + +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void cs_irq_handler (struct intel_engine_cs *engine,u16 iir) {if (iir >_RENDER_USER_INTERRUPT ) {intel_engine_signal_breadcrumbs (engine); -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); } }static void guc_reset_prepare (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine;ENGINE_TRACE (engine,"\n" );@@ -283,12 +287,12 @@ static void guc_reset_prepare(struct intel_engine_cs *engine)* Prevent request submission to the hardware until we have * completed the reset in i915_gem_reset_finish(). If a request * is completed by one engine, it may then queue a request -* to a second via its execlists->tasklet *just* as we are +* to a second via its sched_engine->tasklet *just* as we are * calling engine->init_hw() and also writing the ELSP. -* Turning off the execlists->tasklet until the reset is over +* Turning off the sched_engine->tasklet until the reset is over * prevents the race. */ -__tasklet_disable_sync_once (&execlists->tasklet); +__tasklet_disable_sync_once (&sched_engine->tasklet); } static void guc_reset_state(struct intel_context *ce,@@ -319,7 +323,7 @@ static void guc_reset_rewind(struct intel_engine_cs *engine, bool stalled)struct i915_request *rq;unsigned long flags; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);/* Push back any incomplete requests for replay after the reset. */ rq =execlists_unwind_incomplete_requests (execlists);@@ -333,12 +337,12 @@ static void guc_reset_rewind(struct intel_engine_cs *engine, bool stalled)guc_reset_state (rq->context, engine, rq->head, stalled); out_unlock: -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void guc_reset_cancel (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine;struct i915_request *rq, *rn;struct rb_node *rb;unsigned long flags;@@ -359,16 +363,16 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)* submission's irq state, we also wish to remind ourselves that * it is irq state.) */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);/* Mark all executing requests as skipped. */ -list_for_each_entry (rq, &engine->active.requests, sched.link) { +list_for_each_entry (rq, &engine->sched_engine->requests, sched.link) {i915_request_set_error_once (rq, -EIO );i915_request_mark_complete (rq); }/* Flush the queued requests to the timeline list (for retiring). */ -while ((rb =rb_first_cached (&execlists->queue))) { +while ((rb =rb_first_cached (&sched_engine->queue))) {struct i915_priolist *p =to_priolist (rb);priolist_for_each_request_consume (rq, rn, p) {@@ -378,28 +382,28 @@ static void guc_reset_cancel(struct intel_engine_cs *engine)i915_request_mark_complete (rq); } -rb_erase_cached (&p->node, &execlists->queue); +rb_erase_cached (&p->node, &sched_engine->queue);i915_priolist_free (p); }/* Remaining _unready_ requests will be nop'ed when submitted */ - execlists->queue_priority_hint =INT_MIN ; - execlists->queue =RB_ROOT_CACHED ; + sched_engine->queue_priority_hint =INT_MIN ; + sched_engine->queue =RB_ROOT_CACHED ; -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void guc_reset_finish (struct intel_engine_cs *engine) { -struct intel_engine_execlists *const execlists = &engine->execlists; +struct i915_sched_engine *const sched_engine = engine->sched_engine; -if (__tasklet_enable (&execlists->tasklet)) +if (__tasklet_enable (&sched_engine->tasklet))/* And kick in case we missed a new request submission. */ -tasklet_hi_schedule (&execlists->tasklet); +i915_sched_engine_hi_kick (sched_engine);ENGINE_TRACE (engine,"depth->%d\n" , -atomic_read (&execlists->tasklet.count)); +atomic_read (&sched_engine->tasklet.count)); }/* @@ -500,7 +504,7 @@ static inline void queue_request(struct intel_engine_cs *engine, {GEM_BUG_ON (!list_empty (&rq->sched.link));list_add_tail (&rq->sched.link, -i915_sched_lookup_priolist (engine, prio)); +i915_sched_lookup_priolist (engine->sched_engine, prio));set_bit (I915_FENCE_FLAG_PQUEUE , &rq->fence.flags); }@@ -510,16 +514,16 @@ static void guc_submit_request(struct i915_request *rq)unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);queue_request (engine, rq,rq_prio (rq)); -GEM_BUG_ON (RB_EMPTY_ROOT (&engine->execlists.queue.rb_root)); +GEM_BUG_ON (i915_sched_engine_is_empty (engine->sched_engine));GEM_BUG_ON (list_empty (&rq->sched.link)); -tasklet_hi_schedule (&engine->execlists.tasklet); +i915_sched_engine_hi_kick (engine->sched_engine); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void sanitize_hwsp (struct intel_engine_cs *engine)@@ -597,7 +601,7 @@ static void guc_release(struct intel_engine_cs *engine) { engine->sanitize =NULL ;/* no longer in control, nothing to sanitize */ -tasklet_kill (&engine->execlists.tasklet); +tasklet_kill (&engine->sched_engine->tasklet);intel_engine_cleanup_common (engine);lrc_fini_wa_ctx (engine);@@ -612,7 +616,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine) engine->cops = &guc_context_ops; engine->request_alloc = guc_request_alloc; - engine->schedule = i915_schedule; + engine->sched_engine->schedule = i915_schedule; engine->reset.prepare = guc_reset_prepare; engine->reset.rewind = guc_reset_rewind;@@ -676,7 +680,8 @@ int intel_guc_submission_setup(struct intel_engine_cs *engine)*/ GEM_BUG_ON (INTEL_GEN (i915) <11 ); -tasklet_setup (&engine->execlists.tasklet, guc_submission_tasklet); +tasklet_setup (&engine->sched_engine->tasklet, guc_submission_tasklet); + engine->sched_engine->schedule = i915_schedule;guc_default_vfuncs (engine);guc_default_irqs (engine);drivers/gpu/drm/i915/i915_gpu_error.c +4
-3@@ -1247,7 +1247,8 @@ static void record_request(const struct i915_request *request,static void engine_record_execlists (struct intel_engine_coredump *ee) { -const struct intel_engine_execlists *const el = &ee->engine->execlists; +const struct intel_engine_execlists *const el = + &ee->engine->execlists;struct i915_request *const *port = el->active;unsigned int n =0 ;@@ -1441,12 +1442,12 @@ capture_engine(struct intel_engine_cs *engine,if (!ee)return NULL ; -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags); rq =intel_engine_find_active_request (engine);if (rq) capture =intel_engine_coredump_add_request (ee, rq,ATOMIC_MAYFAIL ); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags);if (!capture) {kfree (ee);return NULL ;drivers/gpu/drm/i915/i915_request.c +25
-25@@ -272,11 +272,11 @@ i915_request_active_engine(struct i915_request *rq,* check that we have acquired the lock on the final engine. */ locked =READ_ONCE (rq->engine); -spin_lock_irq (&locked->active.lock); +spin_lock_irq (&locked->sched_engine->lock);while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { -spin_unlock (&locked->active.lock); +spin_unlock (&locked->sched_engine->lock); locked = engine; -spin_lock (&locked->active.lock); +spin_lock (&locked->sched_engine->lock); }if (i915_request_is_active (rq)) {@@ -285,7 +285,7 @@ i915_request_active_engine(struct i915_request *rq, ret = true; } -spin_unlock_irq (&locked->active.lock); +spin_unlock_irq (&locked->sched_engine->lock);return ret; }@@ -302,10 +302,10 @@ static void remove_from_engine(struct i915_request *rq)* check that the rq still belongs to the newly locked engine. */ locked =READ_ONCE (rq->engine); -spin_lock_irq (&locked->active.lock); +spin_lock_irq (&locked->sched_engine->lock);while (unlikely (locked != (engine =READ_ONCE (rq->engine)))) { -spin_unlock (&locked->active.lock); -spin_lock (&engine->active.lock); +spin_unlock (&locked->sched_engine->lock); +spin_lock (&engine->sched_engine->lock); locked = engine; }list_del_init (&rq->sched.link);@@ -316,7 +316,7 @@ static void remove_from_engine(struct i915_request *rq)/* Prevent further __await_execution() registering a cb, then flush */ set_bit (I915_FENCE_FLAG_ACTIVE , &rq->fence.flags); -spin_unlock_irq (&locked->active.lock); +spin_unlock_irq (&locked->sched_engine->lock);__notify_execute_cb_imm (rq); }@@ -481,7 +481,7 @@ static bool __request_in_flight(const struct i915_request *signal)* may either perform a context switch to the second inflight execlists, * or it may switch to the pending set of execlists. In the case of the * latter, it may send the ACK and we process the event copying the -* pending[] over top of inflight[], _overwriting_ our *active. Since +* pending[] over top of inflight[], _overwriting_ our *active-> Since * this implies the HW is arbitrating and not struck in *active, we do * not worry about complete accuracy, but we do require no read/write * tearing of the pointer [the read of the pointer must be valid, even @@ -490,7 +490,7 @@ static bool __request_in_flight(const struct i915_request *signal)* * Note that the read of *execlists->active may race with the promotion * of execlists->pending[] to execlists->inflight[], overwritting -* the value at *execlists->active. This is fine. The promotion implies +* the value at *execlists->active-> This is fine. The promotion implies * that we received an ACK from the HW, and so the context is not * stuck -- if we do not see ourselves in *active, the inflight status * is valid. If instead we see ourselves being copied into *active, @@ -545,7 +545,7 @@ __await_execution(struct i915_request *rq,/* * Register the callback first, then see if the signaler is already -* active. This ensures that if we race with the +* active-> This ensures that if we race with the * __notify_execute_cb from i915_request_submit() and we are not * included in that list, we get a second bite of the cherry and * execute it ourselves. After this point, a future @@ -637,7 +637,7 @@ bool __i915_request_submit(struct i915_request *request)RQ_TRACE (request,"\n" );GEM_BUG_ON (!irqs_disabled ()); -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);/* * With the advent of preempt-to-busy, we frequently encounter @@ -649,9 +649,9 @@ bool __i915_request_submit(struct i915_request *request)* * We must remove the request from the caller's priority queue, * and the caller must only call us when the request is in their -* priority queue, under the active.lock. This ensures that the +* priority queue, under the active->lock. This ensures that the * request has *not* yet been retired and we can safely move -* the request into the engine->active.list where it will be +* the request into the engine->sched_engine->list where it will be * dropped upon retiring. (Otherwise if resubmit a *retired* * request, this would be a horrible use-after-free.) */ @@ -694,7 +694,7 @@ bool __i915_request_submit(struct i915_request *request) result = true;GEM_BUG_ON (test_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags)); -list_move_tail (&request->sched.link, &engine->active.requests); +list_move_tail (&request->sched.link, &engine->sched_engine->requests); active:clear_bit (I915_FENCE_FLAG_PQUEUE , &request->fence.flags);set_bit (I915_FENCE_FLAG_ACTIVE , &request->fence.flags);@@ -724,11 +724,11 @@ void i915_request_submit(struct i915_request *request)unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);__i915_request_submit (request); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }void __i915_request_unsubmit (struct i915_request *request)@@ -742,7 +742,7 @@ void __i915_request_unsubmit(struct i915_request *request)RQ_TRACE (request,"\n" );GEM_BUG_ON (!irqs_disabled ()); -lockdep_assert_held (&engine->active.lock); +lockdep_assert_held (&engine->sched_engine->lock);/* * Before we remove this breadcrumb from the signal list, we have @@ -775,11 +775,11 @@ void i915_request_unsubmit(struct i915_request *request)unsigned long flags;/* Will be called from irq-context when using foreign fences. */ -spin_lock_irqsave (&engine->active.lock, flags); +spin_lock_irqsave (&engine->sched_engine->lock, flags);__i915_request_unsubmit (request); -spin_unlock_irqrestore (&engine->active.lock, flags); +spin_unlock_irqrestore (&engine->sched_engine->lock, flags); }static void __cancel_request (struct i915_request *rq)@@ -1343,7 +1343,7 @@ __i915_request_await_execution(struct i915_request *to, }/* Couple the dependency tree for PI on this exposed to->fence */ -if (to->engine->schedule) { +if (to->engine->sched_engine->schedule) { err =i915_sched_node_add_dependency (&to->sched, &from->sched,I915_DEPENDENCY_WEAK );@@ -1484,7 +1484,7 @@ i915_request_await_request(struct i915_request *to, struct i915_request *from)return 0 ; } -if (to->engine->schedule) { +if (to->engine->sched_engine->schedule) { ret =i915_sched_node_add_dependency (&to->sched, &from->sched,I915_DEPENDENCY_EXTERNAL );@@ -1671,7 +1671,7 @@ __i915_request_add_to_timeline(struct i915_request *rq)__i915_sw_fence_await_dma_fence (&rq->submit, &prev->fence, &rq->dmaq); -if (rq->engine->schedule) +if (rq->engine->sched_engine->schedule) __i915_sched_node_add_dependency(&rq->sched, &prev->sched, &rq->dep,@@ -1743,8 +1743,8 @@ void __i915_request_queue(struct i915_request *rq,* decide whether to preempt the entire chain so that it is ready to * run at the earliest possible convenience. */ -if (attr && rq->engine->schedule) - rq->engine->schedule (rq, attr); +if (attr && rq->engine->sched_engine->schedule) + rq->engine->sched_engine->schedule (rq, attr);local_bh_disable ();__i915_request_queue_bh (rq);drivers/gpu/drm/i915/i915_request.h +1
-1@@ -613,7 +613,7 @@ i915_request_active_timeline(const struct i915_request *rq)* this submission. */ return rcu_dereference_protected (rq->timeline, -lockdep_is_held (&rq->engine->active.lock)); +lockdep_is_held (&rq->engine->sched_engine->lock)); } static inline u32drivers/gpu/drm/i915/i915_scheduler.c +77
-91@@ -40,7 +40,7 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -static void assert_priolists (struct intel_engine_execlists *const execlists) +static void assert_priolists (struct i915_sched_engine *const sched_engine) {struct rb_node *rb;long last_prio;@@ -48,11 +48,11 @@ static void assert_priolists(struct intel_engine_execlists * const execlists)if (!IS_ENABLED (CONFIG_DRM_I915_DEBUG_GEM ))return ; -GEM_BUG_ON (rb_first_cached (&execlists->queue) != -rb_first (&execlists->queue.rb_root)); +GEM_BUG_ON (rb_first_cached (&sched_engine->queue) != +rb_first (&sched_engine->queue.rb_root)); last_prio =INT_MAX ; -for (rb =rb_first_cached (&execlists->queue); rb; rb =rb_next (rb)) { +for (rb =rb_first_cached (&sched_engine->queue); rb; rb =rb_next (rb)) {const struct i915_priolist *p =to_priolist (rb);GEM_BUG_ON (p->priority > last_prio);@@ -61,23 +61,22 @@ static void assert_priolists(struct intel_engine_execlists * const execlists) }struct list_head * -i915_sched_lookup_priolist (struct intel_engine_cs *engine,int prio) +i915_sched_lookup_priolist (struct i915_sched_engine *sched_engine,int prio) { -struct intel_engine_execlists *const execlists = &engine->execlists;struct i915_priolist *p;struct rb_node **parent, *rb;bool first = true; -lockdep_assert_held (&engine->active.lock); -assert_priolists (execlists); +lockdep_assert_held (&sched_engine->lock); +assert_priolists (sched_engine); -if (unlikely (execlists->no_priolist)) +if (unlikely (sched_engine->no_priolist)) prio =I915_PRIORITY_NORMAL ; find_priolist:/* most positive priority is scheduled first, equal priorities fifo */ rb =NULL ; - parent = &execlists->queue.rb_root.rb_node; + parent = &sched_engine->queue.rb_root.rb_node;while (*parent) { rb = *parent; p =to_priolist (rb);@@ -92,7 +91,7 @@ i915_sched_lookup_priolist(struct intel_engine_cs *engine, int prio) }if (prio ==I915_PRIORITY_NORMAL ) { - p = &execlists->default_priolist; + p = &sched_engine->default_priolist; }else { p =kmem_cache_alloc (global.slab_priorities,GFP_ATOMIC );/* Convert an allocation failure to a priority bump */ @@ -107,7 +106,7 @@ i915_sched_lookup_priolist(struct intel_engine_cs *engine, int prio)* requests, so if userspace lied about their * dependencies that reordering may be visible. */ - execlists->no_priolist = true; + sched_engine->no_priolist = true; goto find_priolist; } }@@ -116,7 +115,7 @@ i915_sched_lookup_priolist(struct intel_engine_cs *engine, int prio)INIT_LIST_HEAD (&p->requests);rb_link_node (&p->node, rb, parent); -rb_insert_color_cached (&p->node, &execlists->queue, first); +rb_insert_color_cached (&p->node, &sched_engine->queue, first);return &p->requests; }@@ -130,13 +129,13 @@ struct sched_cache {struct list_head *priolist; }; -static struct intel_engine_cs * -sched_lock_engine (const struct i915_sched_node *node, -struct intel_engine_cs *locked, +static struct i915_sched_engine * +lock_sched_engine (struct i915_sched_node *node, +struct i915_sched_engine *locked,struct sched_cache *cache) {const struct i915_request *rq =node_to_request (node); -struct intel_engine_cs *engine; +struct i915_sched_engine *sched_engine;GEM_BUG_ON (!locked);@@ -146,81 +145,22 @@ sched_lock_engine(const struct i915_sched_node *node,* engine lock. The simple ploy we use is to take the lock then * check that the rq still belongs to the newly locked engine. */ -while (locked != (engine =READ_ONCE (rq->engine))) { -spin_unlock (&locked->active.lock); +while (locked != (sched_engine = rq->engine->sched_engine)) { +spin_unlock (&locked->lock);memset (cache,0 ,sizeof (*cache)); -spin_lock (&engine->active.lock); - locked = engine; +spin_lock (&sched_engine->lock); + locked = sched_engine; } -GEM_BUG_ON (locked != engine); +GEM_BUG_ON (locked != sched_engine);return locked; } -static inline int rq_prio (const struct i915_request *rq) -{ -return rq->sched.attr.priority; -} - -static inline bool need_preempt (int prio,int active) -{ -/* -* Allow preemption of low -> normal -> high, but we do -* not allow low priority tasks to preempt other low priority -* tasks under the impression that latency for low priority -* tasks does not matter (as much as background throughput), -* so kiss. -*/ -return prio >=max (I915_PRIORITY_NORMAL , active); -} - -static void kick_submission (struct intel_engine_cs *engine, -const struct i915_request *rq, -int prio) -{ -const struct i915_request *inflight; - -/* -* We only need to kick the tasklet once for the high priority -* new context we add into the queue. -*/ -if (prio <= engine->execlists.queue_priority_hint) -return ; - -rcu_read_lock (); - -/* Nothing currently active? We're overdue for a submission! */ - inflight =execlists_active (&engine->execlists); -if (!inflight) - goto unlock; - -/* -* If we are already the currently executing context, don't -* bother evaluating if we should preempt ourselves. -*/ -if (inflight->context == rq->context) - goto unlock; - -ENGINE_TRACE (engine, -"bumping queue-priority-hint:%d for rq:%llx:%lld, inflight:%llx:%lld prio %d\n" , - prio, - rq->fence.context, rq->fence.seqno, - inflight->fence.context, inflight->fence.seqno, - inflight->sched.attr.priority); - - engine->execlists.queue_priority_hint = prio; -if (need_preempt (prio,rq_prio (inflight))) -tasklet_hi_schedule (&engine->execlists.tasklet); - -unlock: -rcu_read_unlock (); -} -static void __i915_schedule (struct i915_sched_node *node,const struct i915_sched_attr *attr) {const int prio =max (attr->priority, node->attr.priority); -struct intel_engine_cs *engine; +struct i915_sched_engine *sched_engine;struct i915_dependency *dep, *p;struct i915_dependency stack;struct sched_cache cache;@@ -295,23 +235,24 @@ static void __i915_schedule(struct i915_sched_node *node, }memset (&cache,0 ,sizeof (cache)); - engine =node_to_request (node)->engine; -spin_lock (&engine->active.lock); + sched_engine =node_to_request (node)->engine->sched_engine; +spin_lock (&sched_engine->lock);/* Fifo and depth-first replacement ensure our deps execute before us */ - engine =sched_lock_engine (node, engine, &cache); + sched_engine =lock_sched_engine (node, sched_engine, &cache);list_for_each_entry_safe_reverse (dep, p, &dfs, dfs_link) {INIT_LIST_HEAD (&dep->dfs_link); node = dep->signaler; - engine =sched_lock_engine (node, engine, &cache); -lockdep_assert_held (&engine->active.lock); + sched_engine =lock_sched_engine (node, sched_engine, &cache); +lockdep_assert_held (&sched_engine->lock);/* Recheck after acquiring the engine->timeline.lock */ if (prio <= node->attr.priority ||node_signaled (node))continue ; -GEM_BUG_ON (node_to_request (node)->engine != engine); +GEM_BUG_ON (node_to_request (node)->engine->sched_engine != + sched_engine);WRITE_ONCE (node->attr.priority, prio);@@ -329,16 +270,17 @@ static void __i915_schedule(struct i915_sched_node *node,if (i915_request_in_priority_queue (node_to_request (node))) {if (!cache.priolist) cache.priolist = -i915_sched_lookup_priolist (engine, +i915_sched_lookup_priolist (sched_engine, prio);list_move_tail (&node->link, cache.priolist); }/* Defer (tasklet) submission until after all of our updates. */ -kick_submission (engine,node_to_request (node), prio); +if (sched_engine->kick_backend) + sched_engine->kick_backend (node_to_request (node), prio); } -spin_unlock (&engine->active.lock); +spin_unlock (&sched_engine->lock); }void i915_schedule (struct i915_request *rq,const struct i915_sched_attr *attr)@@ -489,6 +431,50 @@ void i915_request_show_with_schedule(struct drm_printer *m,rcu_read_unlock (); } +void i915_sched_engine_free (struct kref *kref) +{ +struct i915_sched_engine *sched_engine = +container_of (kref,typeof (*sched_engine), ref); + +i915_sched_engine_kill (sched_engine);/* flush the callback */ +kfree (sched_engine); +} + +struct i915_sched_engine * +i915_sched_engine_create (unsigned int subclass) +{ +struct i915_sched_engine *sched_engine; + + sched_engine =kzalloc (sizeof (*sched_engine),GFP_KERNEL ); +if (!sched_engine) +return NULL ; + +kref_init (&sched_engine->ref); + + sched_engine->queue =RB_ROOT_CACHED ; + sched_engine->queue_priority_hint =INT_MIN ; + +INIT_LIST_HEAD (&sched_engine->requests); +INIT_LIST_HEAD (&sched_engine->hold); + +spin_lock_init (&sched_engine->lock); +lockdep_set_subclass (&sched_engine->lock, subclass); + +/* +* Due to an interesting quirk in lockdep's internal debug tracking, +* after setting a subclass we must ensure the lock is used. Otherwise, +* nr_unused_locks is incremented once too often. +*/ +#ifdef CONFIG_DEBUG_LOCK_ALLOC +local_irq_disable (); +lock_map_acquire (&sched_engine->lock.dep_map); +lock_map_release (&sched_engine->lock.dep_map); +local_irq_enable (); +#endif + +return sched_engine; +} +static void i915_global_scheduler_shrink (void ) {kmem_cache_shrink (global.slab_dependencies);drivers/gpu/drm/i915/i915_scheduler.h +64
-1@@ -39,7 +39,7 @@ void i915_schedule(struct i915_request *request, const struct i915_sched_attr *attr);struct list_head * -i915_sched_lookup_priolist (struct intel_engine_cs *engine,int prio); +i915_sched_lookup_priolist (struct i915_sched_engine *sched_engine,int prio);void __i915_priolist_free (struct i915_priolist *p);static inline void i915_priolist_free (struct i915_priolist *p)@@ -53,4 +53,67 @@ void i915_request_show_with_schedule(struct drm_printer *m,const char *prefix, int indent); +struct i915_sched_engine * +i915_sched_engine_create (unsigned int subclass); + +void i915_sched_engine_free (struct kref *kref); + +static inline struct i915_sched_engine * +i915_sched_engine_get (struct i915_sched_engine *sched_engine) +{ +kref_get (&sched_engine->ref); +return sched_engine; +} + +static inline void +i915_sched_engine_put (struct i915_sched_engine *sched_engine) +{ +kref_put (&sched_engine->ref, i915_sched_engine_free); +} + +static inline bool +i915_sched_engine_is_empty (struct i915_sched_engine *sched_engine) +{ +return RB_EMPTY_ROOT (&sched_engine->queue.rb_root); +} + +static inline void +i915_sched_engine_reset_on_empty (struct i915_sched_engine *sched_engine) +{ +if (i915_sched_engine_is_empty (sched_engine)) + sched_engine->no_priolist = false; +} + +static inline void +i915_sched_engine_hi_kick (struct i915_sched_engine *sched_engine) +{ +tasklet_hi_schedule (&sched_engine->tasklet); +} + +static inline void +i915_sched_engine_kick (struct i915_sched_engine *sched_engine) +{ +tasklet_schedule (&sched_engine->tasklet); +} + +static inline void +i915_sched_engine_kill (struct i915_sched_engine *sched_engine) +{ +tasklet_kill (&sched_engine->tasklet); +} + +static inline void +sched_engine_active_lock_bh (struct i915_sched_engine *sched_engine) +{ +local_bh_disable ();/* prevent local softirq and lock recursion */ +tasklet_lock (&sched_engine->tasklet); +} + +static inline void +sched_engine_active_unlock_bh (struct i915_sched_engine *sched_engine) +{ +tasklet_unlock (&sched_engine->tasklet); +local_bh_enable ();/* restore softirq, and kick ksoftirqd! */ +} +#endif /* _I915_SCHEDULER_H_ */ drivers/gpu/drm/i915/i915_scheduler_types.h +59
-0@@ -91,4 +91,67 @@ struct i915_dependency { &(rq__)->sched.signalers_list, \ signal_link) +struct i915_sched_engine { +struct kref ref; + +/* +* @lock: Protects requests in priority lists, requests, hold, and +* tasklet while running. +*/ +spinlock_t lock; + +/* Execlist specific lists, needed here as protected by lock */ +struct list_head requests; +struct list_head hold;/* ready requests, but on hold */ + +/** +* @tasklet: softirq tasklet for bottom handler +*/ +struct tasklet_struct tasklet; + +/** +* @default_priolist: priority list for I915_PRIORITY_NORMAL +*/ +struct i915_priolist default_priolist; + +/** +* @queue_priority_hint: Highest pending priority. +* +* When we add requests into the queue, or adjust the priority of +* executing requests, we compute the maximum priority of those +* pending requests. We can then use this value to determine if +* we need to preempt the executing requests to service the queue. +* However, since the we may have recorded the priority of an inflight +* request we wanted to preempt but since completed, at the time of +* dequeuing the priority hint may no longer may match the highest +* available request priority. +*/ +int queue_priority_hint; + +/** +* @queue: queue of requests, in priority lists +*/ +struct rb_root_cached queue; + +/** +* @no_priolist: priority lists disabled +*/ +bool no_priolist; + +/* Back pointer to engine */ +struct intel_engine_cs *engine; + +/* Kick backend */ +void (*kick_backend)(const struct i915_request *rq, +int prio); + +/* +* Call when the priority on a request has changed and it and its +* dependencies may need rescheduling. Note the request itself may +* not be ready to run! +*/
Quoted 13 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_scheduler_types.h +4
-0+void (*schedule)(struct i915_request *request, + const struct i915_sched_attr *attr); +}; +#endif /* _I915_SCHEDULER_TYPES_H_ */ Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 33/97 drm/i915: Engine relative MMIO
In reply to Matthew BrostFrom: John Harrison <[email protected]>
With virtual engines, it is no longer possible to know which specific physical engine a given request will be executed on at the time that request is generated. This means that the request itself must be engine agnostic - any direct register writes must be relative to the engine and not absolute addresses.
The LRI command has support for engine relative addressing. However, the mechanism is not transparent to the driver. The scheme for Gen11 (MI_LRI_ADD_CS_MMIO_START) requires the LRI address to have no absolute engine base component. The hardware then adds on the correct engine offset at execution time.
Due to the non-trivial and differing schemes on different hardware, it is not possible to simply update the code that creates the LRI commands to set a remap flag and let the hardware get on with it. Instead, this patch adds function wrappers for generating the LRI command itself and then for constructing the correct address to use with the LRI.
Bspec: 45606
--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 7 +++--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 25 ++++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_engine_types.h | 3 +++ drivers/gpu/drm/i915/gt/intel_gpu_commands.h | 5 ++++ drivers/gpu/drm/i915/i915_perf.c | 6 +++++ 5 files changed, 43 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +4 -3
@@ -1211,7 +1211,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data) {struct i915_address_space *vm = rq->context->vm;struct intel_engine_cs *engine = rq->engine; -u32 base = engine->mmio_base; +u32 base = engine->lri_mmio_base;u32 *cs;int i;
@@ -1223,7 +1223,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)if (IS_ERR (cs))return PTR_ERR (cs); - *cs++ =MI_LOAD_REGISTER_IMM (2 ); + *cs++ =MI_LOAD_REGISTER_IMM (2 ) | engine->lri_cmd_mode; *cs++ =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,0 )); *cs++ =upper_32_bits (pd_daddr);
@@ -1245,7 +1245,8 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)if (IS_ERR (cs))return PTR_ERR (cs); - *cs++ =MI_LOAD_REGISTER_IMM (2 *GEN8_3LVL_PDPES ) |MI_LRI_FORCE_POSTED ; + *cs++ =MI_LOAD_REGISTER_IMM (2 *GEN8_3LVL_PDPES ) | +MI_LRI_FORCE_POSTED | engine->lri_cmd_mode;for (i =GEN8_3LVL_PDPES ; i--; ) {const dma_addr_t pd_daddr =i915_page_dir_dma_addr (ppgtt, i);
drivers/gpu/drm/i915/gt/intel_engine_cs.c +25 -0
@@ -16,6 +16,7 @@#include "intel_engine_pm.h" #include "intel_engine_user.h" #include "intel_execlists_submission.h" +#include "intel_gpu_commands.h" #include "intel_gt.h" #include "intel_gt_requests.h" #include "intel_gt_pm.h"
@@ -223,6 +224,28 @@ static u32 __engine_mmio_base(struct drm_i915_private *i915,return bases[i].base; } +static bool i915_engine_has_relative_lri (const struct intel_engine_cs *engine) +{ +if (INTEL_GEN (engine->i915) <11 ) +return false; + +if (engine->class ==COPY_ENGINE_CLASS ) +return false; + +return true; +} + +static void lri_init (struct intel_engine_cs *engine) +{ +if (i915_engine_has_relative_lri (engine)) { + engine->lri_cmd_mode =MI_LRI_LRM_CS_MMIO ; + engine->lri_mmio_base =0 ; + }else { + engine->lri_cmd_mode =0 ; + engine->lri_mmio_base = engine->mmio_base; + } +} +static void __sprint_engine_name (struct intel_engine_cs *engine) {/*
@@ -327,6 +350,8 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)if (engine->context_size)DRIVER_CAPS (i915)->has_logical_contexts = true; +lri_init (engine); +ewma__engine_latency_init (&engine->latency);seqcount_init (&engine->stats.lock);
drivers/gpu/drm/i915/gt/intel_engine_types.h +3 -0
@@ -281,6 +281,9 @@ struct intel_engine_cs {u32 context_size;u32 mmio_base; +u32 lri_mmio_base; +u32 lri_cmd_mode; +/* * Some w/a require forcewake to be held (which prevents RC6) while * a particular engine is active. If so, we set fw_domain to which
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +5 -0
@@ -134,6 +134,11 @@* simply ignores the register load under certain conditions. * - One can actually load arbitrary many arbitrary registers: Simply issue x * address/value pairs. Don't overdue it, though, x <= 2^4 must hold! +* - Newer hardware supports engine relative addressing but older hardware does +* not. This is required for hw engine load balancing. Hence the MI_LRI +* instruction itself is prefixed with '__' and should only be used on +* legacy hardware code paths. Generic code must always use the MI_LRI +* and i915_get_lri_reg() helper functions instead. */ #define MI_LOAD_REGISTER_IMM (x) MI_INSTR(0x22, 2*(x)-1)/* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */
drivers/gpu/drm/i915/i915_perf.c +6 -0
@@ -2118,6 +2118,11 @@ gen8_update_reg_state_unlocked(const struct intel_context *ce,u32 *reg_state = ce->lrc_reg_state;int i; +/* +* NB: The LRI instruction is generated by the hardware. +* Should we read it in and assert that the offset flag is set? +*/ + reg_state[ctx_oactxctrl +1 ] = (stream->period_exponent <<GEN8_OA_TIMER_PERIOD_SHIFT ) | (stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) |
@@ -2174,6 +2179,7 @@ gen8_load_flex(struct i915_request *rq, *cs++ =MI_LOAD_REGISTER_IMM (count);do { +/* FIXME: Is this table LRI remap/offset friendly? */ *cs++ =i915_mmio_reg_offset (flex->reg); *cs++ = flex->value; }while (flex++, --count);
Signature · 1 line
2.28.0
Re: [Intel-gfx] [RFC PATCH 33/97] drm/i915: Engine relative MMIO
Quoted 50 lines · Matthew Brost
From: John Harrison <[email protected]>
With virtual engines, it is no longer possible to know which specific physical engine a given request will be executed on at the time that request is generated. This means that the request itself must be engine agnostic - any direct register writes must be relative to the engine and not absolute addresses.
The LRI command has support for engine relative addressing. However, the mechanism is not transparent to the driver. The scheme for Gen11 (
MI_LRI_ADD_CS_MMIO_START) requires the LRI address to have no absolute engine base component. The hardware then adds on the correct engine offset at execution time.Due to the non-trivial and differing schemes on different hardware, it is not possible to simply update the code that creates the LRI commands to set a remap flag and let the hardware get on with it. Instead, this patch adds function wrappers for generating the LRI command itself and then for constructing the correct address to use with the LRI.
Bspec: 45606
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>CC Rodrigo Vivi <[email protected]>CC Tvrtko Ursulin <[email protected]>CC Chris P Wilson <[email protected]>CC Daniele Ceraolo Spurio <[email protected]>--- drivers/gpu/drm/i915/gem/i915_gem_context.c | 7 +++--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 25 ++++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_engine_types.h | 3 +++ drivers/gpu/drm/i915/gt/intel_gpu_commands.h | 5 ++++ drivers/gpu/drm/i915/i915_perf.c | 6 +++++ 5 files changed, 43 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gem/i915_gem_context.c +1
-1@@ -1211,7 +1211,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data) {struct i915_address_space *vm = rq->context->vm;struct intel_engine_cs *engine = rq->engine; -u32 base = engine->mmio_base; +u32 base = engine->lri_mmio_base;u32 *cs;int i;
drivers/gpu/drm/i915/gem/i915_gem_context.c static int emit_ppgtt_update(struct i915_request *rq, void *data) · line 1226
Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +1
-1@@ -1223,7 +1223,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)if (IS_ERR (cs))return PTR_ERR (cs); - *cs++ =MI_LOAD_REGISTER_IMM (2 ); + *cs++ =MI_LOAD_REGISTER_IMM (2 ) | engine->lri_cmd_mode;
Would a helper like MI_LOAD_REGISTER_IMM_REL(engine, n) look better?
Quoted 82 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +2
-1*cs++ =i915_mmio_reg_offset (GEN8_RING_PDP_UDW (base,0 )); *cs++ =upper_32_bits (pd_daddr);@@ -1245,7 +1245,8 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)if (IS_ERR (cs))return PTR_ERR (cs); - *cs++ =MI_LOAD_REGISTER_IMM (2 *GEN8_3LVL_PDPES ) |MI_LRI_FORCE_POSTED ; + *cs++ =MI_LOAD_REGISTER_IMM (2 *GEN8_3LVL_PDPES ) | +MI_LRI_FORCE_POSTED | engine->lri_cmd_mode;for (i =GEN8_3LVL_PDPES ; i--; ) {const dma_addr_t pd_daddr =i915_page_dir_dma_addr (ppgtt, i);drivers/gpu/drm/i915/gt/intel_engine_cs.c +25
-0@@ -16,6 +16,7 @@#include "intel_engine_pm.h" #include "intel_engine_user.h" #include "intel_execlists_submission.h" +#include "intel_gpu_commands.h" #include "intel_gt.h" #include "intel_gt_requests.h" #include "intel_gt_pm.h" @@ -223,6 +224,28 @@ static u32 __engine_mmio_base(struct drm_i915_private *i915,return bases[i].base; } +static bool i915_engine_has_relative_lri (const struct intel_engine_cs *engine) +{ +if (INTEL_GEN (engine->i915) <11 ) +return false; + +if (engine->class ==COPY_ENGINE_CLASS ) +return false; + +return true; +} + +static void lri_init (struct intel_engine_cs *engine) +{ +if (i915_engine_has_relative_lri (engine)) { + engine->lri_cmd_mode =MI_LRI_LRM_CS_MMIO ; + engine->lri_mmio_base =0 ; + }else { + engine->lri_cmd_mode =0 ; + engine->lri_mmio_base = engine->mmio_base; + } +} +static void __sprint_engine_name (struct intel_engine_cs *engine) {/* @@ -327,6 +350,8 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)if (engine->context_size)DRIVER_CAPS (i915)->has_logical_contexts = true; +lri_init (engine); +ewma__engine_latency_init (&engine->latency);seqcount_init (&engine->stats.lock);drivers/gpu/drm/i915/gt/intel_engine_types.h +3
-0@@ -281,6 +281,9 @@ struct intel_engine_cs {u32 context_size;u32 mmio_base; +u32 lri_mmio_base; +u32 lri_cmd_mode; +/* * Some w/a require forcewake to be held (which prevents RC6) while * a particular engine is active. If so, we set fw_domain to which drivers/gpu/drm/i915/gt/intel_gpu_commands.h +0
-0
drivers/gpu/drm/i915/gt/intel_gpu_commands.h line 141
Quoted 8 lines
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +5
-0@@ -134,6 +134,11 @@* simply ignores the register load under certain conditions. * - One can actually load arbitrary many arbitrary registers: Simply issue x * address/value pairs. Don't overdue it, though, x <= 2^4 must hold! +* - Newer hardware supports engine relative addressing but older hardware does +* not. This is required for hw engine load balancing. Hence the MI_LRI +* instruction itself is prefixed with '__' and should only be used on +* legacy hardware code paths. Generic code must always use the MI_LRI +* and i915_get_lri_reg() helper functions instead.
Stale comment.
Quoted 21 lines
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +0
-0*/ #define MI_LOAD_REGISTER_IMM (x) MI_INSTR(0x22, 2*(x)-1)/* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */ drivers/gpu/drm/i915/i915_perf.c +5
-0@@ -2118,6 +2118,11 @@ gen8_update_reg_state_unlocked(const struct intel_context *ce,u32 *reg_state = ce->lrc_reg_state;int i; +/* +* NB: The LRI instruction is generated by the hardware. +* Should we read it in and assert that the offset flag is set? +*/ + reg_state[ctx_oactxctrl +1 ] = (stream->period_exponent <<GEN8_OA_TIMER_PERIOD_SHIFT ) | (stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) |
drivers/gpu/drm/i915/i915_perf.c gen8_load_flex(struct i915_request *rq, · line 2185
Quoted 7 lines
drivers/gpu/drm/i915/i915_perf.c +1
-0@@ -2174,6 +2179,7 @@ gen8_load_flex(struct i915_request *rq, *cs++ =MI_LOAD_REGISTER_IMM (count);do { +/* FIXME: Is this table LRI remap/offset friendly? */ *cs++ =i915_mmio_reg_offset (flex->reg); *cs++ = flex->value; }while (flex++, --count);
NB and FIXME would ideally be resolved before merging.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 34/97 drm/i915/guc: Use guc_class instead of engine_class in fw interface
In reply to Matthew BrostFrom: Daniele Ceraolo Spurio <[email protected]>
GuC has its own defines for the engine classes. They're currently mapping 1:1 to the defines used by the driver, but there is no guarantee this will continue in the future. Given that we've been caught off-guard in the past by similar divergences, we can prepare for the changes by introducing helper functions to convert from engine class to GuC class and back again.
--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 6 +++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 20 +++++++++------- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 26 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +4 -2
@@ -289,6 +289,7 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)const struct engine_info *info = &intel_engines[id];struct drm_i915_private *i915 = gt->i915;struct intel_engine_cs *engine; +u8 guc_class;BUILD_BUG_ON (MAX_ENGINE_CLASS >=BIT (GEN11_ENGINE_CLASS_WIDTH ));BUILD_BUG_ON (MAX_ENGINE_INSTANCE >=BIT (GEN11_ENGINE_INSTANCE_WIDTH ));
@@ -317,9 +318,10 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id) engine->i915 = i915; engine->gt = gt; engine->uncore = gt->uncore; - engine->mmio_base =__engine_mmio_base (i915, info->mmio_bases); engine->hw_id = info->hw_id; - engine->guc_id =MAKE_GUC_ID (info->class, info->instance); + guc_class =engine_class_to_guc_class (info->class); + engine->guc_id =MAKE_GUC_ID (guc_class, info->instance); + engine->mmio_base =__engine_mmio_base (i915, info->mmio_bases); engine->irq_handler = nop_irq_handler;
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +12 -8
@@ -6,6 +6,7 @@#include "gt/intel_gt.h" #include "gt/intel_lrc.h" #include "intel_guc_ads.h" +#include "intel_guc_fwif.h" #include "intel_uc.h" #include "i915_drv.h"
@@ -78,7 +79,7 @@ static void guc_mapping_table_init(struct intel_gt *gt,GUC_MAX_INSTANCES_PER_CLASS ;for_each_engine (engine, gt, id) { -u8 guc_class = engine->class; +u8 guc_class =engine_class_to_guc_class (engine->class); system_info->mapping_table[guc_class][engine->instance] = engine->instance;
@@ -98,7 +99,7 @@ static void __guc_ads_init(struct intel_guc *guc)struct __guc_ads_blob *blob = guc->ads_blob;const u32 skipped_size =LRC_PPHWSP_SZ *PAGE_SIZE +LR_HW_CONTEXT_SIZE ;u32 base; -u8 engine_class; +u8 engine_class, guc_class;/* GuC scheduling policies */ guc_policies_init (&blob->policies);
@@ -114,22 +115,25 @@ static void __guc_ads_init(struct intel_guc *guc)for (engine_class =0 ; engine_class <=MAX_ENGINE_CLASS ; ++engine_class) {if (engine_class ==OTHER_CLASS )continue ; + + guc_class =engine_class_to_guc_class (engine_class); +/* * TODO: Set context pointer to default state to allow * GuC to re-init guilty contexts after internal reset. */ - blob->ads.golden_context_lrca[engine_class] =0 ; - blob->ads.eng_state_size[engine_class] = + blob->ads.golden_context_lrca[guc_class] =0 ; + blob->ads.eng_state_size[guc_class] =intel_engine_context_size (guc_to_gt (guc), engine_class) - skipped_size; }/* System info */ - blob->system_info.engine_enabled_masks[RENDER_CLASS ] =1 ; - blob->system_info.engine_enabled_masks[COPY_ENGINE_CLASS ] =1 ; - blob->system_info.engine_enabled_masks[VIDEO_DECODE_CLASS ] =VDBOX_MASK (gt); - blob->system_info.engine_enabled_masks[VIDEO_ENHANCEMENT_CLASS ] =VEBOX_MASK (gt); + blob->system_info.engine_enabled_masks[GUC_RENDER_CLASS ] =1 ; + blob->system_info.engine_enabled_masks[GUC_BLITTER_CLASS ] =1 ; + blob->system_info.engine_enabled_masks[GUC_VIDEO_CLASS ] =VDBOX_MASK (gt); + blob->system_info.engine_enabled_masks[GUC_VIDEOENHANCE_CLASS ] =VEBOX_MASK (gt); blob->system_info.generic_gt_sysinfo[GUC_GENERIC_GT_SYSINFO_SLICE_ENABLED ] =hweight8 (gt->info.sseu.slice_mask);
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +26 -0
@@ -15,6 +15,7 @@#include "abi/guc_communication_mmio_abi.h" #include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +#include "gt/intel_engine_types.h" #define GUC_CLIENT_PRIORITY_KMD_HIGH 0#define GUC_CLIENT_PRIORITY_HIGH 1
@@ -32,6 +33,12 @@#define GUC_VIDEO_ENGINE2 4#define GUC_MAX_ENGINES_NUM (GUC_VIDEO_ENGINE2 + 1) +#define GUC_RENDER_CLASS 0 +#define GUC_VIDEO_CLASS 1 +#define GUC_VIDEOENHANCE_CLASS 2 +#define GUC_BLITTER_CLASS 3 +#define GUC_RESERVED_CLASS 4 +#define GUC_LAST_ENGINE_CLASS GUC_RESERVED_CLASS#define GUC_MAX_ENGINE_CLASSES 16#define GUC_MAX_INSTANCES_PER_CLASS 32
@@ -129,6 +136,25 @@#define GUC_ID_TO_ENGINE_INSTANCE (guc_id) \ (((guc_id) & GUC_ENGINE_INSTANCE_MASK) >> GUC_ENGINE_INSTANCE_SHIFT) +static inline u8 engine_class_to_guc_class (u8 class) +{ +BUILD_BUG_ON (GUC_RENDER_CLASS !=RENDER_CLASS ); +BUILD_BUG_ON (GUC_BLITTER_CLASS !=COPY_ENGINE_CLASS ); +BUILD_BUG_ON (GUC_VIDEO_CLASS !=VIDEO_DECODE_CLASS ); +BUILD_BUG_ON (GUC_VIDEOENHANCE_CLASS !=VIDEO_ENHANCEMENT_CLASS ); +GEM_BUG_ON (class >MAX_ENGINE_CLASS || class ==OTHER_CLASS ); + +return class; +} + +static inline u8 guc_class_to_engine_class (u8 guc_class) +{ +GEM_BUG_ON (guc_class >GUC_LAST_ENGINE_CLASS ); +GEM_BUG_ON (guc_class ==GUC_RESERVED_CLASS ); + +return guc_class; +} +/* Work item for submitting workloads into work queue of GuC. */ struct guc_wq_item {u32 header;
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC PATCH 34/97] drm/i915/guc: Use guc_class instead of engine_class in fw interface
Quoted 9 lines · Matthew Brost
From: Daniele Ceraolo Spurio <[email protected]>
GuC has its own defines for the engine classes. They're currently mapping 1:1 to the defines used by the driver, but there is no guarantee this will continue in the future. Given that we've been caught off-guard in the past by similar divergences, we can prepare for the changes by introducing helper functions to convert from engine class to GuC class and back again.
Quoted 4 lines
Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>Cc John Harrison <[email protected]>Cc Michal Wajdeczko <[email protected]>
Quoted 147 lines
--- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 6 +++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c | 20 +++++++++------- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 26 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/intel_engine_cs.c +4
-2@@ -289,6 +289,7 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)const struct engine_info *info = &intel_engines[id];struct drm_i915_private *i915 = gt->i915;struct intel_engine_cs *engine; +u8 guc_class;BUILD_BUG_ON (MAX_ENGINE_CLASS >=BIT (GEN11_ENGINE_CLASS_WIDTH ));BUILD_BUG_ON (MAX_ENGINE_INSTANCE >=BIT (GEN11_ENGINE_INSTANCE_WIDTH ));@@ -317,9 +318,10 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id) engine->i915 = i915; engine->gt = gt; engine->uncore = gt->uncore; - engine->mmio_base =__engine_mmio_base (i915, info->mmio_bases); engine->hw_id = info->hw_id; - engine->guc_id =MAKE_GUC_ID (info->class, info->instance); + guc_class =engine_class_to_guc_class (info->class); + engine->guc_id =MAKE_GUC_ID (guc_class, info->instance); + engine->mmio_base =__engine_mmio_base (i915, info->mmio_bases); engine->irq_handler = nop_irq_handler;drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c +12
-8@@ -6,6 +6,7 @@#include "gt/intel_gt.h" #include "gt/intel_lrc.h" #include "intel_guc_ads.h" +#include "intel_guc_fwif.h" #include "intel_uc.h" #include "i915_drv.h" @@ -78,7 +79,7 @@ static void guc_mapping_table_init(struct intel_gt *gt,GUC_MAX_INSTANCES_PER_CLASS ;for_each_engine (engine, gt, id) { -u8 guc_class = engine->class; +u8 guc_class =engine_class_to_guc_class (engine->class); system_info->mapping_table[guc_class][engine->instance] = engine->instance;@@ -98,7 +99,7 @@ static void __guc_ads_init(struct intel_guc *guc)struct __guc_ads_blob *blob = guc->ads_blob;const u32 skipped_size =LRC_PPHWSP_SZ *PAGE_SIZE +LR_HW_CONTEXT_SIZE ;u32 base; -u8 engine_class; +u8 engine_class, guc_class;/* GuC scheduling policies */ guc_policies_init (&blob->policies);@@ -114,22 +115,25 @@ static void __guc_ads_init(struct intel_guc *guc)for (engine_class =0 ; engine_class <=MAX_ENGINE_CLASS ; ++engine_class) {if (engine_class ==OTHER_CLASS )continue ; + + guc_class =engine_class_to_guc_class (engine_class); +/* * TODO: Set context pointer to default state to allow * GuC to re-init guilty contexts after internal reset. */ - blob->ads.golden_context_lrca[engine_class] =0 ; - blob->ads.eng_state_size[engine_class] = + blob->ads.golden_context_lrca[guc_class] =0 ; + blob->ads.eng_state_size[guc_class] =intel_engine_context_size (guc_to_gt (guc), engine_class) - skipped_size; }/* System info */ - blob->system_info.engine_enabled_masks[RENDER_CLASS ] =1 ; - blob->system_info.engine_enabled_masks[COPY_ENGINE_CLASS ] =1 ; - blob->system_info.engine_enabled_masks[VIDEO_DECODE_CLASS ] =VDBOX_MASK (gt); - blob->system_info.engine_enabled_masks[VIDEO_ENHANCEMENT_CLASS ] =VEBOX_MASK (gt); + blob->system_info.engine_enabled_masks[GUC_RENDER_CLASS ] =1 ; + blob->system_info.engine_enabled_masks[GUC_BLITTER_CLASS ] =1 ; + blob->system_info.engine_enabled_masks[GUC_VIDEO_CLASS ] =VDBOX_MASK (gt); + blob->system_info.engine_enabled_masks[GUC_VIDEOENHANCE_CLASS ] =VEBOX_MASK (gt); blob->system_info.generic_gt_sysinfo[GUC_GENERIC_GT_SYSINFO_SLICE_ENABLED ] =hweight8 (gt->info.sseu.slice_mask);drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +26
-0@@ -15,6 +15,7 @@#include "abi/guc_communication_mmio_abi.h" #include "abi/guc_communication_ctb_abi.h" #include "abi/guc_messages_abi.h" +#include "gt/intel_engine_types.h" #define GUC_CLIENT_PRIORITY_KMD_HIGH 0#define GUC_CLIENT_PRIORITY_HIGH 1@@ -32,6 +33,12 @@#define GUC_VIDEO_ENGINE2 4#define GUC_MAX_ENGINES_NUM (GUC_VIDEO_ENGINE2 + 1) +#define GUC_RENDER_CLASS 0 +#define GUC_VIDEO_CLASS 1 +#define GUC_VIDEOENHANCE_CLASS 2 +#define GUC_BLITTER_CLASS 3 +#define GUC_RESERVED_CLASS 4 +#define GUC_LAST_ENGINE_CLASS GUC_RESERVED_CLASS#define GUC_MAX_ENGINE_CLASSES 16#define GUC_MAX_INSTANCES_PER_CLASS 32@@ -129,6 +136,25 @@#define GUC_ID_TO_ENGINE_INSTANCE (guc_id) \ (((guc_id) & GUC_ENGINE_INSTANCE_MASK) >> GUC_ENGINE_INSTANCE_SHIFT) +static inline u8 engine_class_to_guc_class (u8 class) +{ +BUILD_BUG_ON (GUC_RENDER_CLASS !=RENDER_CLASS ); +BUILD_BUG_ON (GUC_BLITTER_CLASS !=COPY_ENGINE_CLASS ); +BUILD_BUG_ON (GUC_VIDEO_CLASS !=VIDEO_DECODE_CLASS ); +BUILD_BUG_ON (GUC_VIDEOENHANCE_CLASS !=VIDEO_ENHANCEMENT_CLASS ); +GEM_BUG_ON (class >MAX_ENGINE_CLASS || class ==OTHER_CLASS ); + +return class; +} + +static inline u8 guc_class_to_engine_class (u8 guc_class) +{ +GEM_BUG_ON (guc_class >GUC_LAST_ENGINE_CLASS ); +GEM_BUG_ON (guc_class ==GUC_RESERVED_CLASS ); + +return guc_class; +} +/* Work item for submitting workloads into work queue of GuC. */ struct guc_wq_item {u32 header;Signature · 1 line
2.28.0
RFC PATCH 35/97 drm/i915/guc: Improve error message for unsolicited CT response
In reply to Matthew BrostImprove the error message when a unsolicited CT response is received by printing fence that couldn't be found, the last fence, and all requests with a response outstanding.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7 -3
@@ -703,12 +703,16 @@ static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r found = true;break ; } -spin_unlock_irqrestore (&ct->requests.lock, flags); -if (!found) {CT_ERROR (ct,"Unsolicited response (fence %u)\n" , fence); -return -ENOKEY ; +CT_ERROR (ct,"Could not find fence=%u, last_fence=%u\n" , fence, + ct->requests.last_fence); +list_for_each_entry (req, &ct->requests.pending, link) +CT_ERROR (ct,"request %u awaits response\n" , + req->fence); + err = -ENOKEY ; } +spin_unlock_irqrestore (&ct->requests.lock, flags);if (unlikely (err))return err;
Signature · 1 line
2.28.0
Re: [RFC PATCH 35/97] drm/i915/guc: Improve error message for unsolicited CT response
Quoted 14 lines · Matthew Brost
Improve the error message when a unsolicited CT response is received by printing fence that couldn't be found, the last fence, and all requests with a response outstanding.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 709
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-3@@ -703,12 +703,16 @@ static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r found = true;break ; } -spin_unlock_irqrestore (&ct->requests.lock, flags); -if (!found) {CT_ERROR (ct,"Unsolicited response (fence %u)\n" , fence); -return -ENOKEY ; +CT_ERROR (ct,"Could not find fence=%u, last_fence=%u\n" , fence, + ct->requests.last_fence);
nit: this new wording may suggest that it's our fault, but that's not necessary true
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 712
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0+list_for_each_entry (req, &ct->requests.pending, link) +CT_ERROR (ct,"request %u awaits response\n" , + req->fence);
usually we don't send multiple requests that expects responses, so it's very likely that list with pending requests will be empty, and even if list is not empty, I'm not sure what is the relation between those pending requests to this unsolicited response, thus wondering how these extra errors could improve our debugging experience ?
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0+ err = -ENOKEY ; } +spin_unlock_irqrestore (&ct->requests.lock, flags);if (unlikely (err))return err;
Re: [RFC PATCH 35/97] drm/i915/guc: Improve error message for unsolicited CT response
Quoted 22 lines · Michal Wajdeczko
Quoted 19 lines · Matthew Brost
Improve the error message when a unsolicited CT response is received by printing fence that couldn't be found, the last fence, and all requests with a response outstanding.
Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-2@@ -703,12 +703,16 @@ static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r found = true;break ; } -spin_unlock_irqrestore (&ct->requests.lock, flags); -
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 709
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-1if (!found) {CT_ERROR (ct,"Unsolicited response (fence %u)\n" , fence); -return -ENOKEY ; +CT_ERROR (ct,"Could not find fence=%u, last_fence=%u\n" , fence, + ct->requests.last_fence);nit: this new wording may suggest that it's our fault, but that's not necessary true
I don't think is implies whos fault this is either way.
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *r · line 712
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0+list_for_each_entry (req, &ct->requests.pending, link) +CT_ERROR (ct,"request %u awaits response\n" , + req->fence);usually we don't send multiple requests that expects responses, so it's very likely that list with pending requests will be empty, and even if list is not empty, I'm not sure what is the relation between those pending requests to this unsolicited response, thus wondering how these extra errors could improve our debugging experience ?
The more information when this occurs the better.
Matt
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0+ err = -ENOKEY ; } +spin_unlock_irqrestore (&ct->requests.lock, flags);if (unlikely (err))return err;
RFC PATCH 36/97 drm/i915/guc: Add non blocking CTB send function
In reply to Matthew BrostAdd non blocking CTB send function, intel_guc_send_nb. In order to support a non blocking CTB send function a spin lock is needed to protect the CTB descriptors fields. Also the non blocking call must not update the fence value as this value is owned by the blocking call (intel_guc_send).
The blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with properly sized buffer.
The function, intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 96 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 7 +- 3 files changed, 105 insertions(+), 10 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +10 -2
@@ -75,7 +75,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int
@@ -83,7 +91,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +90 -6
167 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +5 -2
@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h"
@@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking
@@ -69,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time; };void intel_guc_ct_init_early (struct intel_guc_ct *ct);
@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Signature · 1 line
2.28.0
Re: [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 2 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. In order to support a non blocking CTB send function a spin lock is needed to
spin lock was added in 16/97
Quoted 3 lines
protect the CTB descriptors fields. Also the non blocking call must not update the fence value as this value is owned by the blocking call (
intel_guc_send).
all H2G messages are using "fence", nb variant also needs to update it
Quoted 2 lines
The blocking CTB now must have a flow control mechanism to ensure the
s/blocking/non-blocking
Quoted 2 lines
buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with properly sized buffer.
as this new nb function is still not used in this patch, then maybe better to move flow control to separate patch for easier review ?
Quoted 59 lines
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 96 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 7 +- 3 files changed, 105 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-2@@ -75,7 +75,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -83,7 +91,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h"
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c int intel_guc_ct_enable(struct intel_guc_ct *ct) · line 316
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -308,6 +313,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct)if (unlikely (err)) goto err_deregister; + ct->requests.last_fence =1 ;
not needed
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0ct->enabled = true;return 0 ;@@ -343,10 +349,22 @@ static u32 ct_get_next_fence(struct intel_guc_ct *ct)return ++ct->requests.last_fence; } +static void write_barrier (struct intel_guc_ct *ct) {
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static u32 ct_get_next_fence(struct intel_guc_ct *ct) · line 362
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+struct intel_guc *guc =ct_to_guc (ct); +struct intel_gt *gt =guc_to_gt (guc); + +if (i915_gem_object_is_lmem (guc->ct.vma->obj)) { +GEM_BUG_ON (guc->send_regs.fw_domains); +intel_uncore_write_fw (gt->uncore,GEN11_SOFT_SCRATCH (0 ),0 ); + }else { +wmb (); + } +}
this chunk seems to be good candidate for separate patch that could be introduced earlier
Quoted 27 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-4+static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -393,9 +411,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence); - hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 439
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0@@ -412,6 +434,12 @@ static int ct_write(struct intel_guc_ct *ct, }GEM_BUG_ON (tail > size); +/* +* make sure H2G buffer update and LRC tail update (if this triggering a +* submission) are visable before updating the descriptor tail
typo
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0+*/ +write_barrier (ct); +/* now update descriptor */ WRITE_ONCE (desc->tail, tail);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 503
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0@@ -466,6 +494,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size);
shouldn't we use READ_ONCE for reading the tail?
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+ +return space >= len_dw; +} + +static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len,
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 520
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+ u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =ctb_has_room (ctb, len +1 );
why +1 ?
Quoted 31 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +17
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 563
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-0+might_sleep (); +/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) {
why +1 ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 567
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }
hmm, full CTB can also be seen in case of nb, but it looks that only in case of blocking call you want to use lazy spin, why ?
also, what if situation is not improving ?
will we be looping here forever ?
Quoted 52 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-2fence =ct_get_next_fence (ct); request.fence = fence;@@ -495,7 +576,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -537,7 +618,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -547,6 +628,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 74
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -69,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time;
this should be introduced in 37/97
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1};void intel_guc_ct_init_early (struct intel_guc_ct *ct);@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Re: [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 12 lines · Michal Wajdeczko
Quoted 2 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. In order to support a non blocking CTB send function a spin lock is needed tospin lock was added in 16/97
Quoted 3 lines
protect the CTB descriptors fields. Also the non blocking call must not update the fence value as this value is owned by the blocking call (
intel_guc_send).
Quoted 7 lines
all H2G messages are using "fence", nb variant also needs to update it
Quoted 2 lines
The blocking CTB now must have a flow control mechanism to ensure the
s/blocking/non-blocking
Will fix the comments as these are a bit stale.
Quoted 6 lines
Quoted 2 lines
buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with properly sized buffer.
as this new nb function is still not used in this patch, then maybe better to move flow control to separate patch for easier review ?
You can't do non-blocking without flow control, it just doesn't work. IMO that makes the review harder.
Quoted 62 lines
Quoted 62 lines
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 96 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 7 +- 3 files changed, 105 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-2@@ -75,7 +75,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -83,7 +91,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-0@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -308,6 +313,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct)if (unlikely (err)) goto err_deregister;
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c int intel_guc_ct_enable(struct intel_guc_ct *ct) · line 316
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+ ct->requests.last_fence =1 ;not needed
Yep.
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0ct->enabled = true;return 0 ;@@ -343,10 +349,22 @@ static u32 ct_get_next_fence(struct intel_guc_ct *ct)return ++ct->requests.last_fence; }
Quoted 15 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static u32 ct_get_next_fence(struct intel_guc_ct *ct) · line 362
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+static void write_barrier (struct intel_guc_ct *ct) { +struct intel_guc *guc =ct_to_guc (ct); +struct intel_gt *gt =guc_to_gt (guc); + +if (i915_gem_object_is_lmem (guc->ct.vma->obj)) { +GEM_BUG_ON (guc->send_regs.fw_domains); +intel_uncore_write_fw (gt->uncore,GEN11_SOFT_SCRATCH (0 ),0 ); + }else { +wmb (); + } +}this chunk seems to be good candidate for separate patch that could be introduced earlier
Yes. Will include patches 3-20 post as this technically is required once the mutex is removed.
Quoted 46 lines
Quoted 27 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +9
-4+static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -393,9 +411,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence); - hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 439
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0@@ -412,6 +434,12 @@ static int ct_write(struct intel_guc_ct *ct, }GEM_BUG_ON (tail > size); +/* +* make sure H2G buffer update and LRC tail update (if this triggering a +* submission) are visable before updating the descriptor tail typo
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0+*/ +write_barrier (ct); +/* now update descriptor */ WRITE_ONCE (desc->tail, tail);@@ -466,6 +494,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; }
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 503
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size);shouldn't we use
READ_ONCEfor reading the tail?
I don't think so. The above READ_ONCE should be sufficient as a barrier.
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+ +return space >= len_dw; +} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags;
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int wait_for_ct_request_update(struct ct_request *req, u32 *status) · line 520
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =ctb_has_room (ctb, len +1 );why +1 ?
The header is 2 DWs while the action array only include 1 DW for the action field which is stuffed into the header.
Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +18
-0+if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 563
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) {why +1 ?
Same as above.
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 567
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0+spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }hmm, full CTB can also be seen in case of nb, but it looks that only in case of blocking call you want to use lazy spin, why ?
Blocking calls are rare + no having credits is rare. No need to over engineering the wait.
Quoted 3 lines
also, what if situation is not improving ?
will we be looping here forever ?
Nope, see the following patch:
https://patchwork.freedesktop.org/patch/432325/?series=89844&rev=1
Quoted 47 lines
Quoted 47 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-2fence =ct_get_next_fence (ct); request.fence = fence;@@ -495,7 +576,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -537,7 +618,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -547,6 +628,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-0@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; };
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 74
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-1-/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -69,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time;this should be introduced in 37/97
Yep.
Matt
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +0
-0};void intel_guc_ct_init_early (struct intel_guc_ct *ct);@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 97
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
In reply to Matthew BrostQuoted 5 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. In order to support a non blocking CTB send function a spin lock is needed to protect the CTB descriptors fields. Also the non blocking call must not update the fence value as this value is owned by the blocking call (intel_guc_send).
Could the commit message say why the non-blocking send function is needed?
Quoted 71 lines
The blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 96 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 7 +- 3 files changed, 105 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-2@@ -75,7 +75,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -83,7 +91,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -308,6 +313,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct)if (unlikely (err)) goto err_deregister; + ct->requests.last_fence =1 ; ct->enabled = true;return 0 ;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static u32 ct_get_next_fence(struct intel_guc_ct *ct) · line 358
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0@@ -343,10 +349,22 @@ static u32 ct_get_next_fence(struct intel_guc_ct *ct)return ++ct->requests.last_fence; } +static void write_barrier (struct intel_guc_ct *ct) { +struct intel_guc *guc =ct_to_guc (ct); +struct intel_gt *gt =guc_to_gt (guc); + +if (i915_gem_object_is_lmem (guc->ct.vma->obj)) { +GEM_BUG_ON (guc->send_regs.fw_domains); +intel_uncore_write_fw (gt->uncore,GEN11_SOFT_SCRATCH (0 ),0 );
It's safe to write to this reg? Does it need a comment to explain it?
Quoted 99 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +60
-4+ }else { +wmb (); + } +} +static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -393,9 +411,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence); - hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -412,6 +434,12 @@ static int ct_write(struct intel_guc_ct *ct, }GEM_BUG_ON (tail > size); +/* +* make sure H2G buffer update and LRC tail update (if this triggering a +* submission) are visable before updating the descriptor tail +*/ +write_barrier (ct); +/* now update descriptor */ WRITE_ONCE (desc->tail, tail);@@ -466,6 +494,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw; +} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =ctb_has_room (ctb, len +1 ); +if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();
Sleep is just cond_resched below or there is more?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 567
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }
If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...
if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);
Then why is there a change in ct_send here, which is not the new non-blocking path?
Quoted 52 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-2fence =ct_get_next_fence (ct); request.fence = fence;@@ -495,7 +576,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -537,7 +618,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -547,6 +628,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 74
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -69,6 +69,9 @@ struct intel_guc_ct {struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time;
Unused in this patch.
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 97
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1};void intel_guc_ct_init_early (struct intel_guc_ct *ct);@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */
Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 10 lines · Tvrtko Ursulin
Quoted 5 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. In order to support a non blocking CTB send function a spin lock is needed to protect the CTB descriptors fields. Also the non blocking call must not update the fence value as this value is owned by the blocking call (intel_guc_send).Could the commit message say why the non-blocking send function is needed?
Sure. Something like:
'CTBs will be used in the critical patch of GuC submission and there is no need to wait for each CTB complete before moving on the i915'
Quoted 69 lines
Quoted 69 lines
The blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 96 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 7 +- 3 files changed, 105 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-2@@ -75,7 +75,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -83,7 +91,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -308,6 +313,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct)if (unlikely (err)) goto err_deregister; + ct->requests.last_fence =1 ; ct->enabled = true;return 0 ;@@ -343,10 +349,22 @@ static u32 ct_get_next_fence(struct intel_guc_ct *ct)return ++ct->requests.last_fence; } +static void write_barrier (struct intel_guc_ct *ct) {
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static u32 ct_get_next_fence(struct intel_guc_ct *ct) · line 358
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+struct intel_guc *guc =ct_to_guc (ct); +struct intel_gt *gt =guc_to_gt (guc); + +if (i915_gem_object_is_lmem (guc->ct.vma->obj)) { +GEM_BUG_ON (guc->send_regs.fw_domains); +intel_uncore_write_fw (gt->uncore,GEN11_SOFT_SCRATCH (0 ),0 );It's safe to write to this reg? Does it need a comment to explain it?
Yes, it is same. IMO 'SCRATCH' in the name is enough documentation.
Quoted 92 lines
Quoted 92 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +60
-4+ }else { +wmb (); + } +} +static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -393,9 +411,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence); - hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -412,6 +434,12 @@ static int ct_write(struct intel_guc_ct *ct, }GEM_BUG_ON (tail > size); +/* +* make sure H2G buffer update and LRC tail update (if this triggering a +* submission) are visable before updating the descriptor tail +*/ +write_barrier (ct); +/* now update descriptor */ WRITE_ONCE (desc->tail, tail);@@ -466,6 +494,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw; +} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =ctb_has_room (ctb, len +1 ); +if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Sleep is just
cond_reschedbelow or there is more?
Yes, the cond_resched.
Quoted 18 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 567
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...
Quoted 8 lines
if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);ret =
ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?
There is not a change to ct_send(), just to intel_guc_ct_send.
As for why intel_guc_ct_send is updated and we don't just a new public function, this was another reviewers suggestion. Again can't make everyone happy.
Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-2fence =ct_get_next_fence (ct); request.fence = fence;@@ -495,7 +576,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -537,7 +618,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -547,6 +628,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -69,6 +69,9 @@ struct intel_guc_ct {
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 74
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time;Unused in this patch.
Yea, wrong patch. Will fix.
Matt
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 96
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1};void intel_guc_ct_init_early (struct intel_guc_ct *ct);@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */ Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 9 lines · Matthew Brost
Quoted 8 lines · Tvrtko Ursulin
Quoted 5 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. In order to support a non blocking CTB send function a spin lock is needed to protect the CTB descriptors fields. Also the non blocking call must not update the fence value as this value is owned by the blocking call (intel_guc_send).
Quoted 7 lines
Quoted 2 lines
Could the commit message say why the non-blocking send function is needed?
Sure. Something like:
'CTBs will be used in the critical patch of GuC submission and there is no need to wait for each CTB complete before moving on the i915'
A bit more, like also mentioning the critical path is with interrupts disabled or so. And not just that there is no need to wait but waiting is not possible because this or that. So only choice is to do this busy loop send. It's a bit horrible so justification needs to be documented.
Quoted 78 lines
Quoted 68 lines
Quoted 68 lines
The blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 96 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 7 +- 3 files changed, 105 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-2@@ -75,7 +75,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -83,7 +91,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -308,6 +313,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct)if (unlikely (err)) goto err_deregister; + ct->requests.last_fence =1 ; ct->enabled = true;return 0 ;@@ -343,10 +349,22 @@ static u32 ct_get_next_fence(struct intel_guc_ct *ct)return ++ct->requests.last_fence; } +static void write_barrier (struct intel_guc_ct *ct) {Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static u32 ct_get_next_fence(struct intel_guc_ct *ct) · line 358
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+struct intel_guc *guc =ct_to_guc (ct); +struct intel_gt *gt =guc_to_gt (guc); + +if (i915_gem_object_is_lmem (guc->ct.vma->obj)) { +GEM_BUG_ON (guc->send_regs.fw_domains); +intel_uncore_write_fw (gt->uncore,GEN11_SOFT_SCRATCH (0 ),0 );It's safe to write to this reg? Does it need a comment to explain it?
Quoted 1 line
Yes, it is same. IMO 'SCRATCH' in the name is enough documentation.
Why would it be enough? It requires digging to figure it out since it appears these are some sort of GuC special registers and not generic scratch:
commit 2d4ed3a988e6b1ff9729d0edd74bf4890571253e
Author: Michal Wajdeczko <[email protected]> Date: Mon May 27 18:36:05 2019 +0000
drm/i915/guc: New GuC scratch registers for Gen11
If it was a normal scratch then async trashing of those from a random driver thread isn't per se safe if used from a GPU context running in parallel.
But then according to bspec they are called VF_SW_FLAG_<n> and not GEN11_SOFT_SCRATCH so yeah.
Quoted 126 lines
Quoted 93 lines
Quoted 93 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +60
-4+ }else { +wmb (); + } +} +static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -393,9 +411,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence); - hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -412,6 +434,12 @@ static int ct_write(struct intel_guc_ct *ct, }GEM_BUG_ON (tail > size); +/* +* make sure H2G buffer update and LRC tail update (if this triggering a +* submission) are visable before updating the descriptor tail +*/ +write_barrier (ct); +/* now update descriptor */ WRITE_ONCE (desc->tail, tail);@@ -466,6 +494,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw; +} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =ctb_has_room (ctb, len +1 ); +if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 567
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);
Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.
I was doing by the diff which says:
static int ct_send(struct intel_guc_ct *ct,
const u32 *action,
u32 len,
@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,
u32 response_buf_size,
u32 *status)
{
+ struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;
struct ct_request request;
unsigned long flags;
u32 fence;
@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,
GEM_BUG_ON(!len);
GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size);
+ might_sleep();
+ /*
+ * We use a lazy spin wait loop here as we believe that if the CT
+ * buffers are sized correctly the flow control condition should be
+ * rare.
+ */
+retry:
spin_lock_irqsave(&ct->ctbs.send.lock, flags);
+ if (unlikely(!ctb_has_room(ctb, len + 1))) {
+ spin_unlock_irqrestore(&ct->ctbs.send.lock, flags);
+ cond_resched();
+ goto retry;
+ }
So it looks like a change to ct_send to me. Is that wrong?
Regards,
Tvrtko
Quoted 76 lines
As for why
intel_guc_ct_sendis updated and we don't just a new public function, this was another reviewers suggestion. Again can't make everyone happy.Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-2fence =ct_get_next_fence (ct); request.fence = fence;@@ -495,7 +576,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -537,7 +618,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -547,6 +628,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -69,6 +69,9 @@ struct intel_guc_ct {Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 74
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time;Unused in this patch.
Yea, wrong patch. Will fix.
Matt
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 96
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1};void intel_guc_ct_init_early (struct intel_guc_ct *ct);@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */ Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 14 lines · Tvrtko Ursulin
Quoted 12 lines · Matthew Brost
Quoted 10 lines · Tvrtko Ursulin
Quoted 5 lines · Matthew Brost
Add non blocking CTB send function,
intel_guc_send_nb. In order to support a non blocking CTB send function a spin lock is needed to protect the CTB descriptors fields. Also the non blocking call must not update the fence value as this value is owned by the blocking call (intel_guc_send).Could the commit message say why the non-blocking send function is needed?
Quoted 7 lines
Quoted 4 lines
Sure. Something like:
'CTBs will be used in the critical patch of GuC submission and there is no need to wait for each CTB complete before moving on the i915'
A bit more, like also mentioning the critical path is with interrupts disabled or so. And not just that there is no need to wait but waiting is not possible because this or that. So only choice is to do this busy loop send. It's a bit horrible so justification needs to be documented.
Don't I basically say all this? Anyways I'll scrub this comment.
Quoted 83 lines
Quoted 78 lines
Quoted 68 lines
Quoted 68 lines
The blocking CTB now must have a flow control mechanism to ensure the buffer isn't overrun. A lazy spin wait is used as we believe the flow control condition should be rare with properly sized buffer.
The function,
intel_guc_send_nb, is exported in this patch but unused. Several patches later in the series make use of this function.Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 12 ++- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 96 +++++++++++++++++++++-- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 7 +- 3 files changed, 105 insertions(+), 10 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +10
-2@@ -75,7 +75,15 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)static inline int intel_guc_send (struct intel_guc *guc,const u32 *action,u32 len) { -return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ); +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 ,0 ); +} + +#define INTEL_GUC_SEND_NB BIT(31) +static +inline int intel_guc_send_nb (struct intel_guc *guc,const u32 *action,u32 len) +{ +return intel_guc_ct_send (&guc->ct, action, len,NULL ,0 , +INTEL_GUC_SEND_NB ); } static inline int@@ -83,7 +91,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, u32 *response_buf, u32 response_buf_size) {return intel_guc_ct_send (&guc->ct, action, len, - response_buf, response_buf_size); + response_buf, response_buf_size,0 ); }static inline void intel_guc_to_host_event_handler (struct intel_guc *guc)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0@@ -3,6 +3,11 @@* Copyright © 2016-2019 Intel Corporation */ +#include <linux/circ_buf.h> +#include <linux/ktime.h> +#include <linux/time64.h> +#include <linux/timekeeping.h> +#include "i915_drv.h" #include "intel_guc_ct.h" #include "gt/intel_gt.h" @@ -308,6 +313,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct)if (unlikely (err)) goto err_deregister; + ct->requests.last_fence =1 ; ct->enabled = true;return 0 ;@@ -343,10 +349,22 @@ static u32 ct_get_next_fence(struct intel_guc_ct *ct)return ++ct->requests.last_fence; } +static void write_barrier (struct intel_guc_ct *ct) {Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static u32 ct_get_next_fence(struct intel_guc_ct *ct) · line 358
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+struct intel_guc *guc =ct_to_guc (ct); +struct intel_gt *gt =guc_to_gt (guc); + +if (i915_gem_object_is_lmem (guc->ct.vma->obj)) { +GEM_BUG_ON (guc->send_regs.fw_domains); +intel_uncore_write_fw (gt->uncore,GEN11_SOFT_SCRATCH (0 ),0 );It's safe to write to this reg? Does it need a comment to explain it?
Quoted 1 line
Yes, it is same. IMO 'SCRATCH' in the name is enough documentation.
Why would it be enough? It requires digging to figure it out since it appears these are some sort of GuC special registers and not generic scratch:
commit
2d4ed3a988e6b1ff9729d0edd74bf4890571253e
Quoted 9 lines
Author: Michal Wajdeczko <[email protected]> Date: Mon May 27 18:36:05 2019 +0000drm/i915/guc: New GuC scratch registers for Gen11
If it was a normal scratch then async trashing of those from a random driver thread isn't per se safe if used from a GPU context running in parallel.
But then according to bspec they are called VF_SW_FLAG_<n> and not
GEN11_SOFT_SCRATCHso yeah.
Moved this part into its own patch and added comment indicating why they are safe to use.
Matt
Quoted 166 lines
Quoted 125 lines
Quoted 92 lines
Quoted 92 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +60
-4+ }else { +wmb (); + } +} +static int ct_write (struct intel_guc_ct *ct,const u32 *action,u32 len/* in dwords */ , -u32 fence) +u32 fence,u32 flags) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc;@@ -393,9 +411,13 @@ static int ct_write(struct intel_guc_ct *ct,FIELD_PREP (GUC_CTB_MSG_0_NUM_DWORDS , len) |FIELD_PREP (GUC_CTB_MSG_0_FENCE , fence); - hxg =FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | -FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | -GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]); + hxg = (flags &INTEL_GUC_SEND_NB ) ? + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_EVENT ) | +FIELD_PREP (GUC_HXG_EVENT_MSG_0_ACTION | +GUC_HXG_EVENT_MSG_0_DATA0 , action[0 ])) : + (FIELD_PREP (GUC_HXG_MSG_0_TYPE ,GUC_HXG_TYPE_REQUEST ) | +FIELD_PREP (GUC_HXG_REQUEST_MSG_0_ACTION | +GUC_HXG_REQUEST_MSG_0_DATA0 , action[0 ]));CT_DEBUG (ct,"writing (tail %u) %*ph %*ph %*ph\n" , tail,4 , &header,4 , &hxg,4 * (len -1 ), &action[1 ]);@@ -412,6 +434,12 @@ static int ct_write(struct intel_guc_ct *ct, }GEM_BUG_ON (tail > size); +/* +* make sure H2G buffer update and LRC tail update (if this triggering a +* submission) are visable before updating the descriptor tail +*/ +write_barrier (ct); +/* now update descriptor */ WRITE_ONCE (desc->tail, tail);@@ -466,6 +494,46 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +{ +struct guc_ct_buffer_desc *desc = ctb->desc; +u32 head =READ_ONCE (desc->head); +u32 space; + + space =CIRC_SPACE (desc->tail, head, ctb->size); + +return space >= len_dw; +} + +static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =ctb_has_room (ctb, len +1 ); +if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 567
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +13
-0const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep (); +/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }So it looks like a change to
ct_sendto me. Is that wrong?
Quoted 78 lines
Regards,
Tvrtko
Quoted 74 lines
As for why
intel_guc_ct_sendis updated and we don't just a new public function, this was another reviewers suggestion. Again can't make everyone happy.Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-2fence =ct_get_next_fence (ct); request.fence = fence;@@ -495,7 +576,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -537,7 +618,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -547,6 +628,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -69,6 +69,9 @@ struct intel_guc_ct {Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 74
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time;Unused in this patch.
Yea, wrong patch. Will fix.
Matt
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 96
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1};void intel_guc_ct_init_early (struct intel_guc_ct *ct);@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */ Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +30
-0+static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =ctb_has_room (ctb, len +1 ); +if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 567
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep (); +/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?
What about this part - is the patch changing the blocking ct_send or not, and if it is why?
Regards,
Tvrtko
Quoted 79 lines
Quoted 79 lines
Regards,
Tvrtko
Quoted 74 lines
As for why
intel_guc_ct_sendis updated and we don't just a new public function, this was another reviewers suggestion. Again can't make everyone happy.Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-2fence =ct_get_next_fence (ct); request.fence = fence;@@ -495,7 +576,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -537,7 +618,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -547,6 +628,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -69,6 +69,9 @@ struct intel_guc_ct {Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 74
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time;Unused in this patch.
Yea, wrong patch. Will fix.
Matt
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 96
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1};void intel_guc_ct_init_early (struct intel_guc_ct *ct);@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */ Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +30
-0+static int ct_send_nb (struct intel_guc_ct *ct, +const u32 *action, +u32 len, +u32 flags) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +unsigned long spin_flags; +u32 fence; +int ret; + +spin_lock_irqsave (&ctb->lock, spin_flags); + + ret =ctb_has_room (ctb, len +1 ); +if (unlikely (ret)) + goto out; + + fence =ct_get_next_fence (ct); + ret =ct_write (ct, action, len, fence, flags); +if (unlikely (ret)) + goto out; + +intel_guc_notify (ct_to_guc (ct)); + +out: +spin_unlock_irqrestore (&ctb->lock, spin_flags); + +return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep ();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 567
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +11
-0+/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct ct_request request;unsigned long flags;u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,GEM_BUG_ON (!len);GEM_BUG_ON (len & ~GUC_CT_MSG_LEN_MASK );GEM_BUG_ON (!response_buf && response_buf_size); +might_sleep (); +/* +* We use a lazy spin wait loop here as we believe that if the CT +* buffers are sized correctly the flow control condition should be +* rare. +*/ +retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags); +if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +cond_resched (); + goto retry; + }
Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?
Yes, ct_send() changes. Sorry for the confusion.
This function needs to be updated to account for the H2G space and backoff if no space is available.
Matt
Quoted 84 lines
Regards,
Tvrtko
Quoted 79 lines
Quoted 79 lines
Regards,
Tvrtko
Quoted 74 lines
As for why
intel_guc_ct_sendis updated and we don't just a new public function, this was another reviewers suggestion. Again can't make everyone happy.Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-2fence =ct_get_next_fence (ct); request.fence = fence;@@ -495,7 +576,7 @@ static int ct_send(struct intel_guc_ct *ct,list_add_tail (&request.link, &ct->requests.pending);spin_unlock (&ct->requests.lock); - err =ct_write (ct, action, len, fence); + err =ct_write (ct, action, len, fence,0 );spin_unlock_irqrestore (&ct->ctbs.send.lock, flags);@@ -537,7 +618,7 @@ static int ct_send(struct intel_guc_ct *ct,* Command Transport (CT) buffer based GuC send function. */ int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size) +u32 *response_buf,u32 response_buf_size,u32 flags) {u32 status = ~0 ;/* undefined */ int ret;@@ -547,6 +628,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,return -ENODEV ; } +if (flags &INTEL_GUC_SEND_NB ) +return ct_send_nb (ct, action, len, flags); + ret =ct_send (ct, action, len, response_buf, response_buf_size, &status);if (unlikely (ret <0 )) { CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1@@ -9,6 +9,7 @@#include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/workqueue.h> +#include <linux/ktime.h> #include "intel_guc_fwif.h" @@ -42,7 +43,6 @@ struct intel_guc_ct_buffer {bool broken; }; -/** Top-level structure for Command Transport related data * * Includes a pair of CT buffers for bi-directional communication and tracking @@ -69,6 +69,9 @@ struct intel_guc_ct {Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct { · line 74
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0struct list_head incoming;/* incoming requests */ struct work_struct worker;/* handler for incoming requests */ } requests; + +/** @stall_time: time of first time a CTB submission is stalled */ +ktime_t stall_time;Unused in this patch.
Yea, wrong patch. Will fix.
Matt
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) · line 96
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +1
-1};void intel_guc_ct_init_early (struct intel_guc_ct *ct);@@ -88,7 +91,7 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) }int intel_guc_ct_send (struct intel_guc_ct *ct,const u32 *action,u32 len, -u32 *response_buf,u32 response_buf_size); +u32 *response_buf,u32 response_buf_size,u32 flags);void intel_guc_ct_event_handler (struct intel_guc_ct *ct);#endif /* _INTEL_GUC_CT_H_ */ Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 123 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +30
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 566
Quoted 12 lines
(quoted diff) +11
-0+ /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?
Quoted 4 lines
Yes,
ct_send()changes. Sorry for the confusion.This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a cond_resched busy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.
Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +30
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 566
Quoted 12 lines
(quoted diff) +11
-0+ /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.
Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said, IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
Matt
Quoted 4 lines
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 137 lines · Matthew Brost
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +30
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 566
Quoted 12 lines
(quoted diff) +11
-0+ /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.
Quoted 3 lines
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said,
Performance of what would be terrible? Something relating to submitting new jobs to the GPU I guess. Or something SRIOV related as you hint below.
But there is no real reason why CPU cycles/power should suffer if GuC is busy.
Okay, if it can't happen in real world then it's possibly passable as a design of a communication interface. But to me it leaves a bad taste and a doubt that there is this other aspect of the real world. And that is when the unexpected happens. Even the most trivial things like a bug in GuC firmware causes the driver to busy spin in there. So not much happening on the machine but CPU cores pinned burning cycles in this code. It's just lazy and not robust design. "Bug #nnnnn - High CPU usage and GUI blocked - Solution: Upgrade GuC firmware and _reboot_ the machine". Oh well..
At least I think the commit message should spell out clearly that a busy looping path is being added to the sleeping send as a downside of implementation choices. Still, for the record, I object to the design.
Regards,
Tvrtko
Quoted 21 lines
IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
Matt
Quoted 4 lines
Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 160 lines · Tvrtko Ursulin
Quoted 137 lines · Matthew Brost
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +30
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 566
Quoted 12 lines
(quoted diff) +11
-0+ /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...
if (flags &INTEL_GUC_SEND_NB)
returnct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.Quoted 3 lines
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said,
Performance of what would be terrible? Something relating to submitting new jobs to the GPU I guess. Or something SRIOV related as you hint below.
But there is no real reason why CPU cycles/power should suffer if GuC is busy.
Okay, if it can't happen in real world then it's possibly passable as a design of a communication interface. But to me it leaves a bad taste and a doubt that there is this other aspect of the real world. And that is when the unexpected happens. Even the most trivial things like a bug in GuC firmware causes the driver to busy spin in there. So not much happening on the machine but CPU cores pinned burning cycles in this code. It's just lazy and not robust design. "Bug #nnnnn - High CPU usage and GUI blocked - Solution: Upgrade GuC firmware and _reboot_ the machine". Oh well..
Quoted 18 lines
At least I think the commit message should spell out clearly that a busy looping path is being added to the sleeping send as a downside of implementation choices. Still, for the record, I object to the design.
Quoted 14 lines
IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
I'd do an s/cond_resched()/msleep(1)/ and comment explaining why we just don't care about this. That checks of the cpu wasting in this case (GuC is overloaded, it wont come back anytime soon anyway) and explains why we really don't want to make this any more clever or complex code (because comment can explain why we wont hit this in actual real world usage except when something else is on fire already anyway).
If you want to go absolutely overkill and it's not too much work, make the msleep interruptible or check for signals, and bail out. That way the process can be made unstuck with ^C at least.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 181 lines · Daniel Vetter
Quoted 160 lines · Tvrtko Ursulin
Quoted 137 lines · Matthew Brost
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +30
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 566
Quoted 12 lines
(quoted diff) +11
-0+ /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...
if (flags &INTEL_GUC_SEND_NB)
returnct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.Quoted 3 lines
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said,
Performance of what would be terrible? Something relating to submitting new jobs to the GPU I guess. Or something SRIOV related as you hint below.
But there is no real reason why CPU cycles/power should suffer if GuC is busy.
Okay, if it can't happen in real world then it's possibly passable as a design of a communication interface. But to me it leaves a bad taste and a doubt that there is this other aspect of the real world. And that is when the unexpected happens. Even the most trivial things like a bug in GuC firmware causes the driver to busy spin in there. So not much happening on the machine but CPU cores pinned burning cycles in this code. It's just lazy and not robust design. "Bug #nnnnn - High CPU usage and GUI blocked - Solution: Upgrade GuC firmware and _reboot_ the machine". Oh well..
Quoted 18 lines
At least I think the commit message should spell out clearly that a busy looping path is being added to the sleeping send as a downside of implementation choices. Still, for the record, I object to the design.
Quoted 14 lines
IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
Quoted 8 lines
I'd do an s/cond_resched()/msleep(1)/ and comment explaining why we just don't care about this. That checks of the cpu wasting in this case (GuC is overloaded, it wont come back anytime soon anyway) and explains why we really don't want to make this any more clever or complex code (because comment can explain why we wont hit this in actual real world usage except when something else is on fire already anyway).
Sounds good.
Quoted 3 lines
If you want to go absolutely overkill and it's not too much work, make the msleep interruptible or check for signals, and bail out. That way the process can be made unstuck with ^C at least.
This loop is already bound by a timer and if no forward progress is made we pop out of this loop. It is assumed if this happens the GuC / GPU is dead a and full GPU reset will have to be issued. A following patch adds the timer, a bit later in submission section of the series a patch is added to trigger the reset.
Matt
Quoted 5 lines
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 197 lines · Matthew Brost
Quoted 181 lines · Daniel Vetter
Quoted 160 lines · Tvrtko Ursulin
Quoted 137 lines · Matthew Brost
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +30
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 566
Quoted 12 lines
(quoted diff) +11
-0+ /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...
if (flags &INTEL_GUC_SEND_NB)
returnct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.Quoted 3 lines
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said,
Performance of what would be terrible? Something relating to submitting new jobs to the GPU I guess. Or something SRIOV related as you hint below.
But there is no real reason why CPU cycles/power should suffer if GuC is busy.
Okay, if it can't happen in real world then it's possibly passable as a design of a communication interface. But to me it leaves a bad taste and a doubt that there is this other aspect of the real world. And that is when the unexpected happens. Even the most trivial things like a bug in GuC firmware causes the driver to busy spin in there. So not much happening on the machine but CPU cores pinned burning cycles in this code. It's just lazy and not robust design. "Bug #nnnnn - High CPU usage and GUI blocked - Solution: Upgrade GuC firmware and _reboot_ the machine". Oh well..
Quoted 18 lines
At least I think the commit message should spell out clearly that a busy looping path is being added to the sleeping send as a downside of implementation choices. Still, for the record, I object to the design.
Quoted 14 lines
IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
Quoted 8 lines
I'd do an s/cond_resched()/msleep(1)/ and comment explaining why we just don't care about this. That checks of the cpu wasting in this case (GuC is overloaded, it wont come back anytime soon anyway) and explains why we really don't want to make this any more clever or complex code (because comment can explain why we wont hit this in actual real world usage except when something else is on fire already anyway).
Sounds good.
Quoted 3 lines
If you want to go absolutely overkill and it's not too much work, make the msleep interruptible or check for signals, and bail out. That way the process can be made unstuck with ^C at least.
Quoted 5 lines
This loop is already bound by a timer and if no forward progress is made we pop out of this loop. It is assumed if this happens the GuC / GPU is dead a and full GPU reset will have to be issued. A following patch adds the timer, a bit later in submission section of the series a patch is added to trigger the reset.
Yeah timeout bail-out works too, and if you then switch it from timeout to also interruptible it shouldn't be much more code. It's just nice to not have any uninterruptible sleep.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 204 lines · Daniel Vetter
Quoted 197 lines · Matthew Brost
Quoted 181 lines · Daniel Vetter
Quoted 160 lines · Tvrtko Ursulin
Quoted 137 lines · Matthew Brost
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
+static int ct_send_nb(struct intel_guc_ct *ct,
+ const u32 *action,
+ u32 len,
+ u32 flags)
+{
+ struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;
+ unsigned long spin_flags;
+ u32 fence;
+ int ret;
+
+ spin_lock_irqsave(&ctb->lock, spin_flags);
+
+ ret = ctb_has_room(ctb, len + 1);
+ if (unlikely(ret))
+ goto out;
+
+ fence = ct_get_next_fence(ct);
+ ret = ct_write(ct, action, len, fence, flags);
+ if (unlikely(ret))
+ goto out;
+
+ intel_guc_notify(ct_to_guc(ct));
+
+out:
+ spin_unlock_irqrestore(&ctb->lock, spin_flags);
+
+ return ret;
+}
+
static int ct_send(struct intel_guc_ct *ct,
const u32 *action,
u32 len,
@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,
u32 response_buf_size,
u32 *status)
{
+ struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;
struct ct_request request;
unsigned long flags;Quoted 9 lines
Quoted 6 lines
u32 fence;
@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,
GEM_BUG_ON(!len);
GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK);
GEM_BUG_ON(!response_buf && response_buf_size);
+ might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Quoted 12 lines
+ /*
+ * We use a lazy spin wait loop here as we believe that if the CT
+ * buffers are sized correctly the flow control condition should be
+ * rare.
+ */
+retry:
spin_lock_irqsave(&ct->ctbs.send.lock, flags);
+ if (unlikely(!ctb_has_room(ctb, len + 1))) {
+ spin_unlock_irqrestore(&ct->ctbs.send.lock, flags);
+ cond_resched();
+ goto retry;
+ }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...
if (flags &INTEL_GUC_SEND_NB)
returnct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.Quoted 3 lines
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said,
Performance of what would be terrible? Something relating to submitting new jobs to the GPU I guess. Or something SRIOV related as you hint below.
But there is no real reason why CPU cycles/power should suffer if GuC is busy.
Okay, if it can't happen in real world then it's possibly passable as a design of a communication interface. But to me it leaves a bad taste and a doubt that there is this other aspect of the real world. And that is when the unexpected happens. Even the most trivial things like a bug in GuC firmware causes the driver to busy spin in there. So not much happening on the machine but CPU cores pinned burning cycles in this code. It's just lazy and not robust design. "Bug #nnnnn - High CPU usage and GUI blocked - Solution: Upgrade GuC firmware and _reboot_ the machine". Oh well..
Quoted 18 lines
At least I think the commit message should spell out clearly that a busy looping path is being added to the sleeping send as a downside of implementation choices. Still, for the record, I object to the design.
Quoted 14 lines
IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
Quoted 8 lines
I'd do an s/cond_resched()/msleep(1)/ and comment explaining why we just don't care about this. That checks of the cpu wasting in this case (GuC is overloaded, it wont come back anytime soon anyway) and explains why we really don't want to make this any more clever or complex code (because comment can explain why we wont hit this in actual real world usage except when something else is on fire already anyway).
Sounds good.
Quoted 3 lines
If you want to go absolutely overkill and it's not too much work, make the msleep interruptible or check for signals, and bail out. That way the process can be made unstuck with ^C at least.
Quoted 5 lines
This loop is already bound by a timer and if no forward progress is made we pop out of this loop. It is assumed if this happens the GuC / GPU is dead a and full GPU reset will have to be issued. A following patch adds the timer, a bit later in submission section of the series a patch is added to trigger the reset.
Quoted 4 lines
Yeah timeout bail-out works too, and if you then switch it from timeout to also interruptible it shouldn't be much more code. It's just nice to not have any uninterruptible sleep.
-Daniel
I didn't get this in my next rev as I didn't know how to do this off hand but I think all I need to add is something like this to each iteration of the busy loops, right?
if (signal_pending_state(TASK_INTERRUPTIBLE, current))
bail out of busy loop, and return and error
Matt
Quoted 4 lines
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 210 lines · Matthew Brost
Quoted 204 lines · Daniel Vetter
Quoted 197 lines · Matthew Brost
Quoted 181 lines · Daniel Vetter
Quoted 160 lines · Tvrtko Ursulin
Quoted 137 lines · Matthew Brost
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 48 lines
+static int ct_send_nb(struct intel_guc_ct *ct,
+ const u32 *action,
+ u32 len,
+ u32 flags)
+{
+ struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;
+ unsigned long spin_flags;
+ u32 fence;
+ int ret;
+
+ spin_lock_irqsave(&ctb->lock, spin_flags);
+
+ ret = ctb_has_room(ctb, len + 1);
+ if (unlikely(ret))
+ goto out;
+
+ fence = ct_get_next_fence(ct);
+ ret = ct_write(ct, action, len, fence, flags);
+ if (unlikely(ret))
+ goto out;
+
+ intel_guc_notify(ct_to_guc(ct));
+
+out:
+ spin_unlock_irqrestore(&ctb->lock, spin_flags);
+
+ return ret;
+}
+
static int ct_send(struct intel_guc_ct *ct,
const u32 *action,
u32 len,
@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct,
u32 response_buf_size,
u32 *status)
{
+ struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;
struct ct_request request;
unsigned long flags;
u32 fence;
@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct,
GEM_BUG_ON(!len);
GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK);
GEM_BUG_ON(!response_buf && response_buf_size);
+ might_sleep();Sleep is just cond_resched below or there is more?
Yes, the
cond_resched.Quoted 21 lines
+ /*
+ * We use a lazy spin wait loop here as we believe that if the CT
+ * buffers are sized correctly the flow control condition should be
+ * rare.
+ */
+retry:
spin_lock_irqsave(&ct->ctbs.send.lock, flags);
+ if (unlikely(!ctb_has_room(ctb, len + 1))) {
+ spin_unlock_irqrestore(&ct->ctbs.send.lock, flags);
+ cond_resched();
+ goto retry;
+ }If this patch is about adding a non-blocking send function, and below we can
see that it creates a fork:intel_guc_ct_send:
...
if (flags & INTEL_GUC_SEND_NB)
return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);
Then why is there a change in ct_send here, which is not the new
non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.Quoted 3 lines
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said,
Performance of what would be terrible? Something relating to submitting new jobs to the GPU I guess. Or something SRIOV related as you hint below.
But there is no real reason why CPU cycles/power should suffer if GuC is busy.
Okay, if it can't happen in real world then it's possibly passable as a design of a communication interface. But to me it leaves a bad taste and a doubt that there is this other aspect of the real world. And that is when the unexpected happens. Even the most trivial things like a bug in GuC firmware causes the driver to busy spin in there. So not much happening on the machine but CPU cores pinned burning cycles in this code. It's just lazy and not robust design. "Bug #nnnnn - High CPU usage and GUI blocked - Solution: Upgrade GuC firmware and _reboot_ the machine". Oh well..
Quoted 18 lines
At least I think the commit message should spell out clearly that a busy looping path is being added to the sleeping send as a downside of implementation choices. Still, for the record, I object to the design.
Quoted 14 lines
IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
Quoted 8 lines
I'd do an s/cond_resched()/msleep(1)/ and comment explaining why we just don't care about this. That checks of the cpu wasting in this case (GuC is overloaded, it wont come back anytime soon anyway) and explains why we really don't want to make this any more clever or complex code (because comment can explain why we wont hit this in actual real world usage except when something else is on fire already anyway).
Sounds good.
Quoted 3 lines
If you want to go absolutely overkill and it's not too much work, make the msleep interruptible or check for signals, and bail out. That way the process can be made unstuck with ^C at least.
Quoted 5 lines
This loop is already bound by a timer and if no forward progress is made we pop out of this loop. It is assumed if this happens the GuC / GPU is dead a and full GPU reset will have to be issued. A following patch adds the timer, a bit later in submission section of the series a patch is added to trigger the reset.
Quoted 4 lines
Yeah timeout bail-out works too, and if you then switch it from timeout to also interruptible it shouldn't be much more code. It's just nice to not have any uninterruptible sleep.
-Daniel
Quoted 6 lines
I didn't get this in my next rev as I didn't know how to do this off hand but I think all I need to add is something like this to each iteration of the busy loops, right?
if (
signal_pending_state(TASK_INTERRUPTIBLE, current))
bail out of busy loop, and return and error
Yeah. Or since this is all hopeless already anyway, go with msleep_interruptible().
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
In reply to Tvrtko UrsulinQuoted 153 lines · Tvrtko Ursulin
Quoted 147 lines · Matthew Brost
Quoted 137 lines · Tvrtko Ursulin
Quoted 130 lines · Matthew Brost
Quoted 122 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 117 lines
Quoted 117 lines
Quoted 75 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +29
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} +static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +1
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 24 lines
Quoted 6 lines
(quoted diff) +2
-0+ /* + * We use a lazy spin wait loop here as we believe thatif the CT
+ * buffers are sized correctly the flow control condition should be
+ * rare.Quoted 8 lines
+ */
+retry:
spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { +spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); +cond_resched();
+ goto retry;
+ }If this patch is about adding a non-blocking send function, and below we can
see that it creates a fork:
intel_guc_ct_send:
...
if (flags &INTEL_GUC_SEND_NB)
returnct_send_nb(ct, action, len, flags);Quoted 8 lines
Quoted 6 lines
ret =
ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +4
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that ifthe CT
+ * buffers are sized correctly the flow control condition should be
+ * rare.
+ */
+retry:
spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) {
+spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); +cond_resched();
+ goto retry;
+ }Quoted 6 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not,
and if it is why?Quoted 4 lines
Yes,
ct_send()changes. Sorry for the confusion.This function needs to be updated to account for the H2G space and backoff if no space is available.
Quoted 8 lines
Since this one is the sleeping path, it probably can and needs to be smarter
than having acond_reschedbusy loop added. Like sleep and get woken up when
there is space. Otherwise it can degenerate to busy looping via contention
with the non-blocking path.Quoted 3 lines
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said,
Quoted 7 lines
Performance of what would be terrible? Something relating to submitting new jobs to the GPU I guess. Or something SRIOV related as you hint below.
But there is no real reason why CPU cycles/power should suffer if GuC is busy.
Okay, if it can't happen in real world then it's possibly passable as a
if that can't happen in real world, then maybe we can just return -ENOSPC/-EBUSY to report that 'unexpected' case, instead of hiding it behind silent busy loop ?
Quoted 42 lines
design of a communication interface. But to me it leaves a bad taste and a doubt that there is this other aspect of the real world. And that is when the unexpected happens. Even the most trivial things like a bug in GuC firmware causes the driver to busy spin in there. So not much happening on the machine but CPU cores pinned burning cycles in this code. It's just lazy and not robust design. "Bug #nnnnn - High CPU usage and GUI blocked - Solution: Upgrade GuC firmware and _reboot_ the machine". Oh well..
At least I think the commit message should spell out clearly that a busy looping path is being added to the sleeping send as a downside of implementation choices. Still, for the record, I object to the design.
Regards,
Tvrtko
Quoted 10 lines
IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Quoted 11 lines
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
Matt
Quoted 4 lines
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 159 lines · Michal Wajdeczko
Quoted 156 lines · Tvrtko Ursulin
Quoted 147 lines · Matthew Brost
Quoted 137 lines · Tvrtko Ursulin
Quoted 130 lines · Matthew Brost
Quoted 122 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 117 lines
Quoted 117 lines
Quoted 75 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +29
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} +static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +1
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 24 lines
Quoted 6 lines
(quoted diff) +2
-0+ /* + * We use a lazy spin wait loop here as we believe thatif the CT
+ * buffers are sized correctly the flow control condition should be
+ * rare.Quoted 8 lines
+ */
+retry:
spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { +spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); +cond_resched();
+ goto retry;
+ }If this patch is about adding a non-blocking send function, and below we can
see that it creates a fork:
intel_guc_ct_send:
...
if (flags &INTEL_GUC_SEND_NB)
returnct_send_nb(ct, action, len, flags);Quoted 8 lines
Quoted 6 lines
ret =
ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +4
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that ifthe CT
+ * buffers are sized correctly the flow control condition should be
+ * rare.
+ */
+retry:
spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) {
+spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); +cond_resched();
+ goto retry;
+ }Quoted 6 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not,
and if it is why?Quoted 4 lines
Yes,
ct_send()changes. Sorry for the confusion.This function needs to be updated to account for the H2G space and backoff if no space is available.
Quoted 8 lines
Since this one is the sleeping path, it probably can and needs to be smarter
than having acond_reschedbusy loop added. Like sleep and get woken up when
there is space. Otherwise it can degenerate to busy looping via contention
with the non-blocking path.Quoted 3 lines
That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said,
Performance of what would be terrible? Something relating to submitting new jobs to the GPU I guess. Or something SRIOV related as you hint below.
Quoted 9 lines
Quoted 4 lines
But there is no real reason why CPU cycles/power should suffer if GuC is busy.
Okay, if it can't happen in real world then it's possibly passable as a
if that can't happen in real world, then maybe we can just return -ENOSPC/-EBUSY to report that 'unexpected' case, instead of hiding it behind silent busy loop ?
No. This is a blocking call, hence it is ok for the function block if it doesn't have space /w a timeout.
Matt
Quoted 34 lines
Quoted 34 lines
design of a communication interface. But to me it leaves a bad taste and a doubt that there is this other aspect of the real world. And that is when the unexpected happens. Even the most trivial things like a bug in GuC firmware causes the driver to busy spin in there. So not much happening on the machine but CPU cores pinned burning cycles in this code. It's just lazy and not robust design. "Bug #nnnnn - High CPU usage and GUI blocked - Solution: Upgrade GuC firmware and _reboot_ the machine". Oh well..
At least I think the commit message should spell out clearly that a busy looping path is being added to the sleeping send as a downside of implementation choices. Still, for the record, I object to the design.
Regards,
Tvrtko
Quoted 17 lines
IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
Matt
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
In reply to Matthew BrostQuoted 150 lines · Matthew Brost
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +30
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 566
Quoted 12 lines
(quoted diff) +11
-0+ /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said, IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Quoted 4 lines
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
I guess the main problem is not with "blocking CTBs", as now only calling thread is "blocked" waiting for reply and other threads can still send their CTBs (blocked/nonblocking), but the fact that we are sending too many messages, stopping only when CTB is full, and even then trying hard to squeeze that message again.
it should be caller responsibility to throttle its stream of non-blocking CTBs if either we are running out of CTB but if we have too many "non-blocking" requests in flight.
making CTB buffer just larger and larger does not solve the problem, only makes it less visible
and as you are using busy-loop to send even 'non-blocking' CTBs, it might indicate that your code is not prepared to step-back in case of any temporary CTB congestion
also note that currently all CTB messages are asynchronous, REQUEST / RESPONSE pair could be processed in fully non-blocking approach, but that would require refactoring of part driver into event-driven state machine, as sometimes we can't move forward without information that we are waiting from the GuC (and blocking was simplest solution for that)
but if your submission code is already event-driven, then it should be easier to trigger state machine into 'retry' mode without using this busy-loop
Quoted 7 lines
Matt
Quoted 4 lines
Regards,
Tvrtko
Re: [Intel-gfx] [RFC PATCH 36/97] drm/i915/guc: Add non blocking CTB send function
Quoted 181 lines · Michal Wajdeczko
Quoted 150 lines · Matthew Brost
Quoted 127 lines · Tvrtko Ursulin
Quoted 125 lines · Matthew Brost
Quoted 116 lines · Tvrtko Ursulin
On 26/05/2021 19:10, Matthew Brost wrote:
[snip]
Quoted 111 lines
Quoted 111 lines
Quoted 72 lines
Quoted 39 lines
Quoted 39 lines
(quoted diff) +30
-0+static int ct_send_nb(struct intel_guc_ct *ct, + const u32 *action, + u32 len, + u32 flags) +{ + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + unsigned long spin_flags; + u32 fence; + int ret; + + spin_lock_irqsave(&ctb->lock, spin_flags); + + ret = ctb_has_room(ctb, len + 1); + if (unlikely(ret)) + goto out; + + fence = ct_get_next_fence(ct); + ret = ct_write(ct, action, len, fence, flags); + if (unlikely(ret)) + goto out; + + intel_guc_notify(ct_to_guc(ct)); + +out: + spin_unlock_irqrestore(&ctb->lock, spin_flags); + + return ret; +} + static int ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags;Quoted 9 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 554
Quoted 6 lines
(quoted diff) +1
-0u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep();Sleep is just
cond_reschedbelow or there is more?Yes, the
cond_resched.Quoted 21 lines
Review static int ct_send(struct intel_guc_ct *ct, · line 566
Quoted 12 lines
(quoted diff) +11
-0+ /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }If this patch is about adding a non-blocking send function, and below we can see that it creates a fork:
intel_guc_ct_send:
...if (flags & INTEL_GUC_SEND_NB) return ct_send_nb(ct, action, len, flags);Quoted 7 lines
Quoted 5 lines
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);Then why is there a change in
ct_sendhere, which is not the new non-blocking path?There is not a change to
ct_send(), just tointel_guc_ct_send.I was doing by the diff which says:
static int ct_send(struct
intel_guc_ct*ct,
const u32 *action,
u32 len,(quoted diff) +13
-0@@ -473,6 +541,7 @@ static int ct_send(struct intel_guc_ct *ct, u32 response_buf_size, u32 *status) { + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct ct_request request; unsigned long flags; u32 fence;@@ -482,8 +551,20 @@ static int ct_send(struct intel_guc_ct *ct, GEM_BUG_ON(!len); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(!response_buf && response_buf_size); + might_sleep(); + /* + * We use a lazy spin wait loop here as we believe that if the CT + * buffers are sized correctly the flow control condition should be + * rare. + */ +retry: spin_lock_irqsave(&ct->ctbs.send.lock, flags); + if (unlikely(!ctb_has_room(ctb, len + 1))) { + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); + cond_resched(); + goto retry; + }Quoted 5 lines
Quoted 1 line
Quoted 1 line
So it looks like a change to
ct_sendto me. Is that wrong?What about this part - is the patch changing the blocking
ct_sendor not, and if it is why?Yes,
ct_send()changes. Sorry for the confusion.Quoted 8 lines
Quoted 2 lines
This function needs to be updated to account for the H2G space and backoff if no space is available.
Since this one is the sleeping path, it probably can and needs to be smarter than having a
cond_reschedbusy loop added. Like sleep and get woken up when there is space. Otherwise it can degenerate to busy looping via contention with the non-blocking path.That screams over enginerring a simple problem to me. If the CT channel is full we are really in trouble anyways - i.e. the performance is going to terrible as we overwhelmed the GuC with traffic. That being said, IGTs can do this but that really isn't a real world use case. For the real world, this buffer is large enough that it won't ever be full hence the comment + lazy spin loop.
Next, it isn't like we get an interrupt or something when space becomes available so how would we wake this thread? Could we come up with a convoluted scheme where we insert ops that generated an interrupt at regular intervals, probably? Would it be super complicated, totally unnecessary, and gain use nothing - absolutely.
Quoted 4 lines
Lastly, blocking CTBs really shouldn't ever be used. Certainly the submission code doesn't use these. I think SRIOV might, but those can probably be reworked too to use non-blocking. At some point we might want to scrub the driver and just delete the blocking path.
I guess the main problem is not with "blocking CTBs", as now only calling thread is "blocked" waiting for reply and other threads can still send their CTBs (blocked/nonblocking), but the fact that we are sending too many messages, stopping only when CTB is full, and even then trying hard to squeeze that message again.
it should be caller responsibility to throttle its stream of non-blocking CTBs if either we are running out of CTB but if we have too many "non-blocking" requests in flight.
making CTB buffer just larger and larger does not solve the problem, only makes it less visible
and as you are using busy-loop to send even 'non-blocking' CTBs, it might indicate that your code is not prepared to step-back in case of any temporary CTB congestion
also note that currently all CTB messages are asynchronous, REQUEST / RESPONSE pair could be processed in fully non-blocking approach, but that would require refactoring of part driver into event-driven state machine, as sometimes we can't move forward without information that we are waiting from the GuC (and blocking was simplest solution for that)
Quoted 3 lines
but if your submission code is already event-driven, then it should be easier to trigger state machine into 'retry' mode without using this busy-loop
Yes, the state-machine is used in most cases as a back off where it makes sense. Some cases we still just use a busy-loop. See my comments about over engineering solutions - sometimes it is better to use something simple for something that rare.
Matt
Quoted 8 lines
Quoted 8 lines
Matt
Quoted 4 lines
Regards,
Tvrtko
RFC PATCH 37/97 drm/i915/guc: Add stall timer to non blocking CTB send function
In reply to Matthew BrostImplement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to ct_write to return -EDEADLK rather than -EPIPE on a corrupted descriptor.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +45 -3
@@ -69,6 +69,8 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)#define CTB_H2G_BUFFER_SIZE (SZ_4K)#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define MAX_US_STALL_CTB 1000000 +struct ct_request {struct list_head link;u32 fence;
@@ -315,6 +317,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) ct->requests.last_fence =1 ; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;
@@ -378,7 +381,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EDEADLK ;if (unlikely (desc->status)) goto corrupted;
@@ -449,7 +452,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EDEADLK ; }/**
@@ -494,6 +497,17 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +bool ret =ktime_us_delta (ktime_get (), ct->stall_time) > +MAX_US_STALL_CTB ; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" ); + +return ret; +} +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;
@@ -505,6 +519,26 @@ static inline bool ctb_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!ctb_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +else +return -EBUSY ; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,
@@ -517,7 +551,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =ctb_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
@@ -561,11 +595,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!ctb_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ; + fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;
Signature · 1 line
2.28.0
Re: [RFC PATCH 37/97] drm/i915/guc: Add stall timer to non blocking CTB send function
Quoted 5 lines · Matthew Brost
Implement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to
ct_writeto return-EDEADLKrather than-EPIPEon a corrupted descriptor.
broken descriptor is really separate issue compared to no progress from GuC side, I would really like to keep old error code
note that broken CTB descriptor is unrecoverable error, while on other hand, in theory, we could recover from temporary non-moving CTB
Quoted 13 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 72
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0@@ -69,6 +69,8 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)#define CTB_H2G_BUFFER_SIZE (SZ_4K)#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define MAX_US_STALL_CTB 1000000
nit: maybe we should make it a CONFIG value ?
Quoted 85 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +36
-3+struct ct_request {struct list_head link;u32 fence;@@ -315,6 +317,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) ct->requests.last_fence =1 ; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;@@ -378,7 +381,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EDEADLK ;if (unlikely (desc->status)) goto corrupted;@@ -449,7 +452,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EDEADLK ; }/** @@ -494,6 +497,17 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +bool ret =ktime_us_delta (ktime_get (), ct->stall_time) > +MAX_US_STALL_CTB ; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" ); + +return ret; +} +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;@@ -505,6 +519,26 @@ static inline bool ctb_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!ctb_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +else +return -EBUSY ; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -517,7 +551,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =ctb_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 604
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0@@ -561,11 +595,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!ctb_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +
likely, instead of duplicating code, you can reuse has_room_nb here
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ; + fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;
Re: [RFC PATCH 37/97] drm/i915/guc: Add stall timer to non blocking CTB send function
Quoted 12 lines · Michal Wajdeczko
Quoted 5 lines · Matthew Brost
Implement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to
ct_writeto return-EDEADLKrather than-EPIPEon a corrupted descriptor.broken descriptor is really separate issue compared to no progress from GuC side, I would really like to keep old error code
I know you do as you have brought it up several times. Again to the rest of the stack these two things mean the exact same thing.
Quoted 3 lines
note that broken CTB descriptor is unrecoverable error, while on other hand, in theory, we could recover from temporary non-moving CTB
Yea but we don't, in both cases we disable submission which in turn triggers a full GPU reset.
Quoted 16 lines
Quoted 16 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0@@ -69,6 +69,8 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)#define CTB_H2G_BUFFER_SIZE (SZ_4K)#define CTB_G2H_BUFFER_SIZE (SZ_4K)
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 72
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+#define MAX_US_STALL_CTB 1000000nit: maybe we should make it a CONFIG value ?
Sure.
Quoted 84 lines
Quoted 84 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +36
-3+struct ct_request {struct list_head link;u32 fence;@@ -315,6 +317,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) ct->requests.last_fence =1 ; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;@@ -378,7 +381,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EDEADLK ;if (unlikely (desc->status)) goto corrupted;@@ -449,7 +452,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EDEADLK ; }/** @@ -494,6 +497,17 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +bool ret =ktime_us_delta (ktime_get (), ct->stall_time) > +MAX_US_STALL_CTB ; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" ); + +return ret; +} +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;@@ -505,6 +519,26 @@ static inline bool ctb_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!ctb_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +else +return -EBUSY ; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -517,7 +551,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =ctb_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;
Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 604
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0@@ -561,11 +595,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!ctb_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +likely, instead of duplicating code, you can reuse
has_room_nbhere
In this patch yes, in the following patch no as this check changes between non-blockig and blocking once we introduce G2H credits. I'd rather just leave it as is than churning on the patches.
Matt
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 613
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ; + fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC PATCH 37/97] drm/i915/guc: Add stall timer to non blocking CTB send function
Quoted 10 lines · Matthew Brost
Quoted 9 lines · Michal Wajdeczko
Quoted 5 lines · Matthew Brost
Implement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to
ct_writeto return-EDEADLKrather than-EPIPEon a corrupted descriptor.
Quoted 6 lines
Quoted 3 lines
broken descriptor is really separate issue compared to no progress from GuC side, I would really like to keep old error code
I know you do as you have brought it up several times. Again to the rest of the stack these two things mean the exact same thing.
but I guess 'the rest of the stack' is only interested if returned error is EBUSY or not, as all other errors are treated in the same way, thus no need change existing error codes
Quoted 7 lines
Quoted 4 lines
note that broken CTB descriptor is unrecoverable error, while on other hand, in theory, we could recover from temporary non-moving CTB
Yea but we don't, in both cases we disable submission which in turn triggers a full GPU reset.
is this current limitation or long term design?
I would rather expect that decision to trigger full GPU is done on solid foundations, like definite lost communication with the GuC or missed heartbeats, not that we temporarily push CTB to the limit
or if do we want to treat CTB processing as kind of hw health checkout too, what if heartbeat timeout and CTB stall time do not match ?
Quoted 139 lines
Quoted 17 lines
Quoted 17 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0@@ -69,6 +69,8 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)#define CTB_H2G_BUFFER_SIZE (SZ_4K)#define CTB_G2H_BUFFER_SIZE (SZ_4K)Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 72
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+#define MAX_US_STALL_CTB 1000000nit: maybe we should make it a CONFIG value ?
Sure.
Quoted 84 lines
Quoted 84 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +36
-3+struct ct_request {struct list_head link;u32 fence;@@ -315,6 +317,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) ct->requests.last_fence =1 ; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;@@ -378,7 +381,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EDEADLK ;if (unlikely (desc->status)) goto corrupted;@@ -449,7 +452,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EDEADLK ; }/** @@ -494,6 +497,17 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +bool ret =ktime_us_delta (ktime_get (), ct->stall_time) > +MAX_US_STALL_CTB ; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" ); + +return ret; +} +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;@@ -505,6 +519,26 @@ static inline bool ctb_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!ctb_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +else +return -EBUSY ; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -517,7 +551,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =ctb_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 604
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0@@ -561,11 +595,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!ctb_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +likely, instead of duplicating code, you can reuse
has_room_nbhereIn this patch yes, in the following patch no as this check changes between non-blockig and blocking once we introduce G2H credits. I'd rather just leave it as is than churning on the patches.
Matt
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ; + fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;
Re: [RFC PATCH 37/97] drm/i915/guc: Add stall timer to non blocking CTB send function
Quoted 17 lines · Michal Wajdeczko
Quoted 14 lines · Matthew Brost
Quoted 12 lines · Michal Wajdeczko
Quoted 5 lines · Matthew Brost
Implement a stall timer which fails H2G CTBs once a period of time with no forward progress is reached to prevent deadlock.
Also update to
ct_writeto return-EDEADLKrather than-EPIPEon a corrupted descriptor.broken descriptor is really separate issue compared to no progress from GuC side, I would really like to keep old error code
Quoted 7 lines
Quoted 2 lines
I know you do as you have brought it up several times. Again to the rest of the stack these two things mean the exact same thing.
but I guess 'the rest of the stack' is only interested if returned error is EBUSY or not, as all other errors are treated in the same way, thus no need change existing error codes
No, -ENODEV means something else too. I'd rather have a single explicit error code which means H2G is broken, take action to fix it. This is a bikeshed, we made a decession internally to return a single error code we really need to move on.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
note that broken CTB descriptor is unrecoverable error, while on other hand, in theory, we could recover from temporary non-moving CTB
Yea but we don't, in both cases we disable submission which in turn triggers a full GPU reset.
is this current limitation or long term design?
Long term design.
Quoted 4 lines
I would rather expect that decision to trigger full GPU is done on solid foundations, like definite lost communication with the GuC or missed heartbeats, not that we temporarily push CTB to the limit
The intent is to have a large enough value here that if it is reached it is assumed the GuC is toast and we need a full GPU reset.
Quoted 3 lines
or if do we want to treat CTB processing as kind of hw health checkout too, what if heartbeat timeout and CTB stall time do not match ?
It is a health check of H2G channel.
No need for these two values to match. One is checking if the GuC can continue make forward progress processing H2G the other is checking if an engine can make forward progress.
Matt
Quoted 139 lines
Quoted 139 lines
Quoted 17 lines
Quoted 17 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Daniele Ceraolo Spurio <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0@@ -69,6 +69,8 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)#define CTB_H2G_BUFFER_SIZE (SZ_4K)#define CTB_G2H_BUFFER_SIZE (SZ_4K)Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 72
Quoted 1 line
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-0+#define MAX_US_STALL_CTB 1000000nit: maybe we should make it a CONFIG value ?
Sure.
Quoted 84 lines
Quoted 84 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +36
-3+struct ct_request {struct list_head link;u32 fence;@@ -315,6 +317,7 @@ int intel_guc_ct_enable(struct intel_guc_ct *ct) ct->requests.last_fence =1 ; ct->enabled = true; + ct->stall_time =KTIME_MAX ;return 0 ;@@ -378,7 +381,7 @@ static int ct_write(struct intel_guc_ct *ct,unsigned int i;if (unlikely (ctb->broken)) -return -EPIPE ; +return -EDEADLK ;if (unlikely (desc->status)) goto corrupted;@@ -449,7 +452,7 @@ static int ct_write(struct intel_guc_ct *ct,CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u status=%#x\n" , desc->head, desc->tail, desc->status); ctb->broken = true; -return -EPIPE ; +return -EDEADLK ; }/** @@ -494,6 +497,17 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)return err; } +static inline bool ct_deadlocked (struct intel_guc_ct *ct) +{ +bool ret =ktime_us_delta (ktime_get (), ct->stall_time) > +MAX_US_STALL_CTB ; + +if (unlikely (ret)) +CT_ERROR (ct,"CT deadlocked\n" ); + +return ret; +} +static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) {struct guc_ct_buffer_desc *desc = ctb->desc;@@ -505,6 +519,26 @@ static inline bool ctb_has_room(struct intel_guc_ct_buffer *ctb, u32 len_dw)return space >= len_dw; } +static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) +{ +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; + +lockdep_assert_held (&ct->ctbs.send.lock); + +if (unlikely (!ctb_has_room (ctb, len_dw))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get (); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +else +return -EBUSY ; + } + + ct->stall_time =KTIME_MAX ; +return 0 ; +} + static int ct_send_nb(struct intel_guc_ct *ct, const u32 *action, u32 len,@@ -517,7 +551,7 @@ static int ct_send_nb(struct intel_guc_ct *ct,spin_lock_irqsave (&ctb->lock, spin_flags); - ret =ctb_has_room (ctb, len +1 ); + ret =has_room_nb (ct, len +1 );if (unlikely (ret)) goto out;Quoted 14 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 604
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0@@ -561,11 +595,19 @@ static int ct_send(struct intel_guc_ct *ct, retry:spin_lock_irqsave (&ct->ctbs.send.lock, flags);if (unlikely (!ctb_has_room (ctb, len +1 ))) { +if (ct->stall_time ==KTIME_MAX ) + ct->stall_time =ktime_get ();spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); + +if (unlikely (ct_deadlocked (ct))) +return -EDEADLK ; +likely, instead of duplicating code, you can reuse
has_room_nbhereIn this patch yes, in the following patch no as this check changes between non-blockig and blocking once we introduce G2H credits. I'd rather just leave it as is than churning on the patches.
Matt
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +2
-0cond_resched (); goto retry; } + ct->stall_time =KTIME_MAX ; + fence =ct_get_next_fence (ct); request.fence = fence; request.status =0 ;
RFC PATCH 38/97 drm/i915/guc: Optimize CTB writes and reads
In reply to Matthew BrostCTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail, size) which could result in accesses across the PCIe bus, store shadow local copies and only read/write the descriptor values when absolutely necessary.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 78 +++++++++++++---------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 52 insertions(+), 32 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +46 -32
@@ -127,6 +127,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }
@@ -371,10 +375,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;
@@ -386,25 +388,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence)
@@ -444,7 +435,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;return 0 ;
@@ -460,7 +453,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value.
@@ -508,24 +501,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw) { -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head); +if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;return space >= len_dw; }static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!ctb_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();
@@ -593,11 +597,11 @@ static int ct_send(struct intel_guc_ct *ct,* rare. */ retry: -spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_lock_irqsave (&ctb->lock, flags); +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (ct_deadlocked (ct)))return -EDEADLK ;
@@ -620,7 +624,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);if (unlikely (err)) goto unlink;
@@ -708,7 +712,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;
@@ -723,12 +727,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) { +CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;
@@ -778,6 +791,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +6 -0
@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @head: local shadow copy of head in dwords +* @tail: local shadow copy of tail in dwords +* @space: local shadow copy of space in dwords * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {
@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;bool broken; };
Signature · 1 line
2.28.0
Re: [RFC PATCH 38/97] drm/i915/guc: Optimize CTB writes and reads
Quoted 3 lines · Matthew Brost
CTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail, size) which could result in accesses across the PCIe
size was removed from the descriptor in 25/97
Quoted 2 lines
bus, store shadow local copies and only read/write the descriptor values when absolutely necessary.
maybe worth to add some words about caching available space ?
Quoted 37 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 78 +++++++++++++---------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 52 insertions(+), 32 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3@@ -127,6 +127,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }@@ -371,10 +375,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;@@ -386,25 +388,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status))
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 396
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-2goto corrupted; -if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted;
nit: as we are now caching tail value, we can start comparing it with the value in descriptor and report GUC_CTB_STATUS_MISMATCH if needed
Quoted 38 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-14} - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence) @@ -444,7 +435,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;return 0 ;@@ -460,7 +453,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value.
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 504
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -508,24 +501,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; } -static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw)
this function was introduced moment ago ... can we minimize number of changes between patches ?
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-3{ -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head);
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 523
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-0+if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ; + ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;
shouldn't we update our ctb->head with new head value?
Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-3return space >= len_dw; }static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!ctb_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -593,11 +597,11 @@ static int ct_send(struct intel_guc_ct *ct,* rare.
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 604
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-3*/ retry: -spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_lock_irqsave (&ctb->lock, flags); +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);
this ...
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 627
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1if (unlikely (ct_deadlocked (ct)))return -EDEADLK ;@@ -620,7 +624,7 @@ static int ct_send(struct intel_guc_ct *ct, err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);
and this likely could be done in earlier patch
Quoted 16 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1if (unlikely (err)) goto unlink;@@ -708,7 +712,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;@@ -723,12 +727,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted;
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 738
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-1-if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) {
we are in control of cached 'ctb->head' so it shall never be > size
Quoted 33 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;@@ -778,6 +791,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @head: local shadow copy of head in dwords +* @tail: local shadow copy of tail in dwords +* @space: local shadow copy of space in dwords * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 51
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;u32 size; +u32 tail; +u32 head; +u32 space;bool broken; };
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC PATCH 38/97] drm/i915/guc: Optimize CTB writes and reads
Quoted 9 lines · Michal Wajdeczko
Quoted 3 lines · Matthew Brost
CTB writes are now in the path of command submission and should be optimized for performance. Rather than reading CTB descriptor values (e.g. head, tail, size) which could result in accesses across the PCIe
size was removed from the descriptor in 25/97
Yep, stale comment.
Quoted 5 lines
Quoted 2 lines
bus, store shadow local copies and only read/write the descriptor values when absolutely necessary.
maybe worth to add some words about caching available space ?
Yea.
Quoted 39 lines
Quoted 39 lines
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 78 +++++++++++++---------- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h | 6 ++ 2 files changed, 52 insertions(+), 32 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +5
-3@@ -127,6 +127,10 @@ static void guc_ct_buffer_desc_init(struct guc_ct_buffer_desc *desc)static void guc_ct_buffer_reset (struct intel_guc_ct_buffer *ctb) { ctb->broken = false; + ctb->tail =0 ; + ctb->head =0 ; + ctb->space =CIRC_SPACE (ctb->tail, ctb->head, ctb->size); +guc_ct_buffer_desc_init (ctb->desc); }@@ -371,10 +375,8 @@ static int ct_write(struct intel_guc_ct *ct, {struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; -u32 tail = desc->tail; +u32 tail = ctb->tail;u32 size = ctb->size; -u32 used;u32 header;u32 hxg;u32 *cmds = ctb->cmds;@@ -386,25 +388,14 @@ static int ct_write(struct intel_guc_ct *ct,if (unlikely (desc->status)) goto corrupted;
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_write(struct intel_guc_ct *ct, · line 396
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-2-if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , - head, tail, size); + desc->head, desc->tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted;nit: as we are now caching tail value, we can start comparing it with the value in descriptor and report
GUC_CTB_STATUS_MISMATCHif needed
Sure.
Quoted 41 lines
Quoted 41 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-14} - -/* -* tail == head condition indicates empty. GuC FW does not support -* using up the entire buffer to get tail == head meaning full. -*/ -if (tail < head) - used = (size - head) + tail; -else - used = tail - head; - -/* make sure there is a space including extra dw for the fence */ -if (unlikely (used + len +1 >= size)) -return -ENOSPC ; +#endif /* * dw0: CT header (including fence) @@ -444,7 +435,9 @@ static int ct_write(struct intel_guc_ct *ct,write_barrier (ct);/* now update descriptor */ + ctb->tail = tail;WRITE_ONCE (desc->tail, tail); + ctb->space -= len +1 ;return 0 ;@@ -460,7 +453,7 @@ static int ct_write(struct intel_guc_ct *ct,* @req: pointer to pending request * @status: placeholder for status * -* For each sent request, Guc shall send bac CT response message. +* For each sent request, GuC shall send back CT response message. * Our message handler will update status of tracked request once * response message with given fence is received. Wait here and * check for valid response status value. @@ -508,24 +501,35 @@ static inline bool ct_deadlocked(struct intel_guc_ct *ct)return ret; }
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 504
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1-static inline bool ctb_has_room (struct intel_guc_ct_buffer *ctb,u32 len_dw) +static inline bool h2g_has_room (struct intel_guc_ct *ct,u32 len_dw)this function was introduced moment ago ... can we minimize number of changes between patches ?
Yep.
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +10
-3{ -struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head =READ_ONCE (desc->head); +struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; +u32 head;u32 space; - space =CIRC_SPACE (desc->tail, head, ctb->size); +if (ctb->space >= len_dw) +return true; + + head =READ_ONCE (ctb->desc->head); +if (unlikely (head > ctb->size)) { +CT_ERROR (ct,"Corrupted descriptor head=%u tail=%u size=%u\n" , + ctb->desc->head, ctb->desc->tail, ctb->size); + ctb->desc->status |=GUC_CTB_STATUS_OVERFLOW ;
Quoted 9 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline bool ct_deadlocked(struct intel_guc_ct *ct) · line 523
Quoted 6 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +6
-0+ ctb->broken = true; +return false; + } + + space =CIRC_SPACE (ctb->tail, head, ctb->size); + ctb->space = space;shouldn't we update our
ctb->headwith new head value?
Don't need it here as the cached H2G head value isn't used by the i915, only the space value is. The G2H head value is used.
Quoted 35 lines
Quoted 17 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-3return space >= len_dw; }static int has_room_nb (struct intel_guc_ct *ct,u32 len_dw) { -struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; -lockdep_assert_held (&ct->ctbs.send.lock); -if (unlikely (!ctb_has_room (ctb, len_dw))) { +if (unlikely (!h2g_has_room (ct, len_dw))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get ();@@ -593,11 +597,11 @@ static int ct_send(struct intel_guc_ct *ct,* rare. drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 604
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-3*/ retry: -spin_lock_irqsave (&ct->ctbs.send.lock, flags); -if (unlikely (!ctb_has_room (ctb, len +1 ))) { +spin_lock_irqsave (&ctb->lock, flags); +if (unlikely (!h2g_has_room (ct, len +1 ))) {if (ct->stall_time ==KTIME_MAX ) ct->stall_time =ktime_get (); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);this ...
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0if (unlikely (ct_deadlocked (ct)))return -EDEADLK ;@@ -620,7 +624,7 @@ static int ct_send(struct intel_guc_ct *ct,
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_send(struct intel_guc_ct *ct, · line 627
Quoted 4 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1err =ct_write (ct, action, len, fence,0 ); -spin_unlock_irqrestore (&ct->ctbs.send.lock, flags); +spin_unlock_irqrestore (&ctb->lock, flags);and this likely could be done in earlier patch
Probably.
Quoted 63 lines
Quoted 16 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1if (unlikely (err)) goto unlink;@@ -708,7 +712,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) {struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv;struct guc_ct_buffer_desc *desc = ctb->desc; -u32 head = desc->head; +u32 head = ctb->head;u32 tail = desc->tail;u32 size = ctb->size;u32 *cmds = ctb->cmds;@@ -723,12 +727,21 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)if (unlikely (desc->status)) goto corrupted;drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 738
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-1-if (unlikely ((tail | head) >= size)) { +#ifdef CONFIG_DRM_I915_DEBUG_GUC +if (unlikely ((desc->tail | desc->head) >= size)) {CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , head, tail, size); desc->status |=GUC_CTB_STATUS_OVERFLOW ; goto corrupted; } +#else +if (unlikely ((tail | ctb->head) >= size)) {we are in control of cached '
ctb->head' so it shall never be > sizeQuoted 34 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-0+CT_ERROR (ct,"Invalid offsets head=%u tail=%u (size=%u)\n" , + head, tail, size); + desc->status |=GUC_CTB_STATUS_OVERFLOW ; + goto corrupted; + } +#endif /* tail == head condition indicates empty */ available = tail - head;@@ -778,6 +791,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) }CT_DEBUG (ct,"received %*ph\n" ,4 * len, (*msg)->msg); + ctb->head = head;/* now update descriptor */ WRITE_ONCE (desc->head, head);drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0@@ -33,6 +33,9 @@ struct intel_guc;* @desc: pointer to the buffer descriptor * @cmds: pointer to the commands buffer * @size: size of the commands buffer in dwords +* @head: local shadow copy of head in dwords +* @tail: local shadow copy of tail in dwords +* @space: local shadow copy of space in dwords * @broken: flag to indicate if descriptor data is broken */ struct intel_guc_ct_buffer {@@ -40,6 +43,9 @@ struct intel_guc_ct_buffer {struct guc_ct_buffer_desc *desc;u32 *cmds;
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h struct intel_guc_ct_buffer { · line 51
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h +3
-0u32 size; +u32 tail; +u32 head; +u32 space;bool broken; };
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 39/97 drm/i915/guc: Increase size of CTB buffers
In reply to Matthew BrostWith the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8 -3
@@ -63,11 +63,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 16 bytes which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)#define MAX_US_STALL_CTB 1000000
@@ -753,7 +758,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 ); header = cmds[head];
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 39/97] drm/i915/guc: Increase size of CTB buffers
Quoted 16 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 68
Quoted 7 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-1@@ -63,11 +63,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 16 bytes which gives us a maximum 256 queue'd requests. Hopefully this
nit: all our CTB calculations are in dwords now, not bytes
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 71
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0+* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot.
hmm, but we are not checking G2H CTB yet
will start doing it around patch 54/97
so maybe this other patch should be introduced earlier ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 75
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1*/ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)
in theory, we (host) should be faster than GuC, so G2H CTB shall be almost always empty, if this is not a case, maybe we should start monitoring what is happening and report some warnings if G2H is half full ?
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 764
Quoted 13 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1#define MAX_US_STALL_CTB 1000000@@ -753,7 +758,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 ); header = cmds[head];
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 39/97] drm/i915/guc: Increase size of CTB buffers
Quoted 14 lines · Michal Wajdeczko
Quoted 11 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
Quoted 15 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 68
Quoted 12 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-1@@ -63,11 +63,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 16 bytes which gives us a maximum 256 queue'd requests. Hopefully this nit: all our CTB calculations are in dwords now, not bytes
I can change the wording to DW sizes.
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 71
Quoted 3 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +3
-0+* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. hmm, but we are not checking G2H CTB yet
will start doing it around patch 54/97
so maybe this other patch should be introduced earlier ?
Yes, that patch is going to be pulled down to an earlier spot in the series.
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) · line 75
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1*/ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)in theory, we (host) should be faster than GuC, so G2H CTB shall be almost always empty, if this is not a case, maybe we should start monitoring what is happening and report some warnings if G2H is half full ?
Certainly some IGTs put some more pressure on the G2H channel than the H2G channel at least I think. This is something we can tune over time after this lands upstream. IMO a message at this point is overkill.
Matt
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1#define MAX_US_STALL_CTB 1000000@@ -753,7 +758,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 );
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 764
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +0
-0header = cmds[head];
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 39/97] drm/i915/guc: Increase size of CTB buffers
In reply to Matthew BrostQuoted 4 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
I'd move this before the patch which adds the non-blocking send since that one claims congestion should be rare with properly sized buffers. So it makes sense to have them sized properly back before that one.
Regards,
Tvrtko
Quoted 31 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-2@@ -63,11 +63,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 16 bytes which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)#define MAX_US_STALL_CTB 1000000
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) · line 764
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1@@ -753,7 +758,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 ); header = cmds[head];
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 39/97] drm/i915/guc: Increase size of CTB buffers
Quoted 11 lines · Tvrtko Ursulin
Quoted 4 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
I'd move this before the patch which adds the non-blocking send since that one claims congestion should be rare with properly sized buffers. So it makes sense to have them sized properly back before that one.
IMO patch ordering is a bit of bikeshed. All these CTBs changes required for GuC submission (34-40, 54) will get posted its own series and get merged together. None of the individual patches break anything or is any of this code really used until GuC submission is turned on. I can move this when I post these patches by themselves but I just don't really see the point either way.
Matt
Quoted 32 lines
Regards,
Tvrtko
Quoted 28 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +7
-2@@ -63,11 +63,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 16 bytes which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)#define MAX_US_STALL_CTB 1000000@@ -753,7 +758,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +1
-1/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 ); header = cmds[head];
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [Intel-gfx] [RFC PATCH 39/97] drm/i915/guc: Increase size of CTB buffers
Quoted 13 lines · Matthew Brost
Quoted 11 lines · Tvrtko Ursulin
Quoted 4 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
I'd move this before the patch which adds the non-blocking send since that one claims congestion should be rare with properly sized buffers. So it makes sense to have them sized properly back before that one.
Quoted 6 lines
IMO patch ordering is a bit of bikeshed. All these CTBs changes required for GuC submission (34-40, 54) will get posted its own series and get merged together. None of the individual patches break anything or is any of this code really used until GuC submission is turned on. I can move this when I post these patches by themselves but I just don't really see the point either way.
As a general principle we do try to have work in the order which makes sense functionality wise.
That includes trying to avoid adding and then removing, or changing a lot, the same code within the series. And also adding functionality which is known to not work completely well until later in the series.
With a master switch at the end of series you can sometimes get away with it, but if nothing else it at least makes it much easier to read if things are flowing in the expected way within (the series).
In this particular example sizing the buffers appropriately before starting to use the facility a lot more certainly sounds like a no brainer to me, especially since the patch is so trivial to move conflict wise.
Regards,
Tvrtko
Quoted 42 lines
Matt
Quoted 40 lines
Regards,
Tvrtko
Quoted 36 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-3@@ -63,11 +63,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 16 bytes which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)#define MAX_US_STALL_CTB 1000000@@ -753,7 +758,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 ); header = cmds[head];
Re: [Intel-gfx] [RFC PATCH 39/97] drm/i915/guc: Increase size of CTB buffers
Quoted 29 lines · Tvrtko Ursulin
Quoted 13 lines · Matthew Brost
Quoted 11 lines · Tvrtko Ursulin
Quoted 4 lines · Matthew Brost
With the introduction of non-blocking CTBs more than one CTB can be in flight at a time. Increasing the size of the CTBs should reduce how often software hits the case where no space is available in the CTB buffer.
I'd move this before the patch which adds the non-blocking send since that one claims congestion should be rare with properly sized buffers. So it makes sense to have them sized properly back before that one.
Quoted 6 lines
IMO patch ordering is a bit of bikeshed. All these CTBs changes required for GuC submission (34-40, 54) will get posted its own series and get merged together. None of the individual patches break anything or is any of this code really used until GuC submission is turned on. I can move this when I post these patches by themselves but I just don't really see the point either way.
As a general principle we do try to have work in the order which makes sense functionality wise.
That includes trying to avoid adding and then removing, or changing a lot, the same code within the series. And also adding functionality which is known to not work completely well until later in the series.
Quoted 8 lines
With a master switch at the end of series you can sometimes get away with it, but if nothing else it at least makes it much easier to read if things are flowing in the expected way within (the series).
In this particular example sizing the buffers appropriately before starting to use the facility a lot more certainly sounds like a no brainer to me, especially since the patch is so trivial to move conflict wise.
Fair enough. I'll reorder these patches when I do a post to merge these ones.
Matt
Quoted 45 lines
Regards,
Tvrtko
Quoted 41 lines
Matt
Quoted 40 lines
Regards,
Tvrtko
Quoted 36 lines
Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8
-3@@ -63,11 +63,16 @@ static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct)* +--------+-----------------------------------------------+------+ * * Size of each `CT Buffer`_ must be multiple of 4K. -* As we don't expect too many messages, for now use minimum sizes. +* We don't expect too many messages in flight at any time, unless we are +* using the GuC submission. In that case each request requires a minimum +* 16 bytes which gives us a maximum 256 queue'd requests. Hopefully this +* enough space to avoid backpressure on the driver. We increase the size +* of the receive buffer (relative to the send) to ensure a G2H response +* CTB has a landing spot. */ #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)#define CTB_H2G_BUFFER_SIZE (SZ_4K) -#define CTB_G2H_BUFFER_SIZE (SZ_4K) +#define CTB_G2H_BUFFER_SIZE (4 * CTB_H2G_BUFFER_SIZE)#define MAX_US_STALL_CTB 1000000@@ -753,7 +758,7 @@ static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg)/* beware of buffer wrap case */ if (unlikely (available <0 )) available += size; -CT_DEBUG (ct,"available %d (%u:%u)\n" , available, head, tail); +CT_DEBUG (ct,"available %d (%u:%u:%u)\n" , available, head, tail, size);GEM_BUG_ON (available <0 ); header = cmds[head];
RFC PATCH 40/97 drm/i915/guc: Module load failure test for CT buffer creation
In reply to Matthew BrostFrom: John Harrison <[email protected]>
Add several module failure load inject points in the CT buffer creation code path.
--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +8 -0
@@ -177,6 +177,10 @@ static int ct_register_buffer(struct intel_guc_ct *ct, u32 type, {int err; + err =i915_inject_probe_error (guc_to_gt (ct_to_guc (ct))->i915, -ENXIO ); +if (unlikely (err)) +return err; + err =guc_action_register_ct_buffer (ct_to_guc (ct), type, desc_addr, buff_addr, size);if (unlikely (err))
@@ -228,6 +232,10 @@ int intel_guc_ct_init(struct intel_guc_ct *ct)u32 *cmds;int err; + err =i915_inject_probe_error (guc_to_gt (guc)->i915, -ENXIO ); +if (err) +return err; +GEM_BUG_ON (ct->vma); blob_size =2 *CTB_DESC_SIZE +CTB_H2G_BUFFER_SIZE +CTB_G2H_BUFFER_SIZE ;
Signature · 1 line
2.28.0
Re: [RFC PATCH 40/97] drm/i915/guc: Module load failure test for CT buffer creation
Quoted 28 lines · Matthew Brost
From: John Harrison <[email protected]>
Add several module failure load inject points in the CT buffer creation code path.
Signed-off-by John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0@@ -177,6 +177,10 @@ static int ct_register_buffer(struct intel_guc_ct *ct, u32 type, {int err; + err =i915_inject_probe_error (guc_to_gt (ct_to_guc (ct))->i915, -ENXIO ); +if (unlikely (err)) +return err; + err =guc_action_register_ct_buffer (ct_to_guc (ct), type, desc_addr, buff_addr, size);if (unlikely (err))
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c int intel_guc_ct_init(struct intel_guc_ct *ct) · line 241
Quoted 10 lines
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c +4
-0@@ -228,6 +232,10 @@ int intel_guc_ct_init(struct intel_guc_ct *ct)u32 *cmds;int err; + err =i915_inject_probe_error (guc_to_gt (guc)->i915, -ENXIO ); +if (err) +return err; +GEM_BUG_ON (ct->vma); blob_size =2 *CTB_DESC_SIZE +CTB_H2G_BUFFER_SIZE +CTB_G2H_BUFFER_SIZE ;
likely could be introduced earlier, maybe right after patch 5/97
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 41/97 drm/i915/guc: Add new GuC interface defines and structures
In reply to Matthew BrostAdd new GuC interface defines and structures while maintaining old ones in parallel.
--- .../gpu/drm/i915/gt/uc/abi/guc_actions_abi.h | 18 ++++++++ drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 41 +++++++++++++++++++ 2 files changed, 59 insertions(+)
drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h +18 -0
@@ -121,13 +121,31 @@ enum intel_guc_action {INTEL_GUC_ACTION_DEALLOCATE_DOORBELL =0x20 ,INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE =0x30 ,INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING =0x40 , +INTEL_GUC_ACTION_LOG_CACHE_CRASH_DUMP =0x200 , +INTEL_GUC_ACTION_GLOBAL_DEBUG_ACTIONS =0x301 ,INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH =0x302 , +INTEL_GUC_ACTION_LOG_VERBOSITY_SELECT =0x400 ,INTEL_GUC_ACTION_ENTER_S_STATE =0x501 ,INTEL_GUC_ACTION_EXIT_S_STATE =0x502 , +INTEL_GUC_ACTION_GLOBAL_SCHED_POLICY_CHANGE =0x506 , +INTEL_GUC_ACTION_SCHED_CONTEXT =0x1000 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_SET =0x1001 , +INTEL_GUC_ACTION_SCHED_CONTEXT_MODE_DONE =0x1002 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_SET =0x1003 , +INTEL_GUC_ACTION_SCHED_ENGINE_MODE_DONE =0x1004 , +INTEL_GUC_ACTION_SET_CONTEXT_PRIORITY =0x1005 , +INTEL_GUC_ACTION_SET_CONTEXT_EXECUTION_QUANTUM =0x1006 , +INTEL_GUC_ACTION_SET_CONTEXT_PREEMPTION_TIMEOUT =0x1007 , +INTEL_GUC_ACTION_CONTEXT_RESET_NOTIFICATION =0x1008 , +INTEL_GUC_ACTION_ENGINE_FAILURE_NOTIFICATION =0x1009 ,INTEL_GUC_ACTION_SLPC_REQUEST =0x3003 , +INTEL_GUC_ACTION_SETUP_GUCRC =0x3004 ,INTEL_GUC_ACTION_AUTHENTICATE_HUC =0x4000 , +INTEL_GUC_ACTION_REGISTER_CONTEXT =0x4502 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT =0x4503 ,INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER =0x4505 ,INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER =0x4506 , +INTEL_GUC_ACTION_DEREGISTER_CONTEXT_DONE =0x4600 ,INTEL_GUC_ACTION_LIMIT };
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +41 -0
59 lines not on this page · raw message
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
RFC PATCH 42/97 drm/i915/guc: Remove GuC stage descriptor, add lrc descriptor
In reply to Matthew BrostRemove old GuC stage descriptor, add lrc descriptor which will be used by the new GuC interface implemented in this patch series.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 +- drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h | 65 ----------------- .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 72 ++++++------------- 3 files changed, 25 insertions(+), 116 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2 -2
@@ -44,8 +44,8 @@ struct intel_guc {struct i915_vma *ads_vma;struct __guc_ads_blob *ads_blob; -struct i915_vma *stage_desc_pool; -void *stage_desc_pool_vaddr; +struct i915_vma *lrc_desc_pool; +void *lrc_desc_pool_vaddr;/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h +0 -65
77 lines not on this page · raw message
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +23 -49
121 lines not on this page · raw message
Signature · 1 line
2.28.0
RFC PATCH 43/97 drm/i915/guc: Add lrc descriptor context lookup array
In reply to Matthew BrostAdd lrc descriptor context lookup array which can resolve the intel_context from the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.
--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gt/uc/intel_guc.h +5 -0
@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h" +#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h"
@@ -47,6 +49,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr; +/* guc_id to intel_context lookup */ +struct xarray context_lookup; +/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30 -2
@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;
@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;
@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */
@@ -404,6 +430,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }
Signature · 1 line
2.28.0
Re: [RFC PATCH 43/97] drm/i915/guc: Add lrc descriptor context lookup array
Quoted 27 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h" +#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h"
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 53
Quoted 5 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0@@ -47,6 +49,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr; +/* guc_id to intel_context lookup */ +struct xarray context_lookup;
The current code sets a disastrous example, but for stuff like this it's always good to explain the locking, and who's holding references and how you're handling cycles. Since I guess the intel_context also holds the guc_id alive somehow.
Again holds for the entire series, where it makes sense (as in we don't expect to rewrite the entire code anyway).
-Daniel
Quoted 71 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */ @@ -404,6 +430,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }Signature · 1 line
2.28.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [RFC PATCH 43/97] drm/i915/guc: Add lrc descriptor context lookup array
Quoted 31 lines · Daniel Vetter
Quoted 30 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h" +#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -47,6 +49,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;
Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 53
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0+/* guc_id to intel_context lookup */ +struct xarray context_lookup;The current code sets a disastrous example, but for stuff like this it's always good to explain the locking, and who's holding references and how you're handling cycles. Since I guess the
intel_contextalso holds theguc_idalive somehow.
I think (?) I know what you mean by this comment. How about adding:
'If an entry in the the context_lookup is present, that means a context associated with the guc_id is registered with the GuC. We use this xarray as a lookup mechanism when the GuC communicate with the i915 about the context.'
Quoted 2 lines
Again holds for the entire series, where it makes sense (as in we don't expect to rewrite the entire code anyway).
Slightly out of order but one of the last patches in the series, 'Update GuC documentation' adds a big section of comments that attempts to clarify how all of this code works. I likely should add a section explaining the data structures as well.
Matt
Quoted 78 lines
-Daniel
Quoted 71 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */ @@ -404,6 +430,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [RFC PATCH 43/97] drm/i915/guc: Add lrc descriptor context lookup array
Quoted 41 lines · Matthew Brost
Quoted 31 lines · Daniel Vetter
Quoted 30 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h" +#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -47,6 +49,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 53
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0+/* guc_id to intel_context lookup */ +struct xarray context_lookup;The current code sets a disastrous example, but for stuff like this it's always good to explain the locking, and who's holding references and how you're handling cycles. Since I guess the
intel_contextalso holds theguc_idalive somehow.
Quoted 5 lines
I think (?) I know what you mean by this comment. How about adding:
'If an entry in the the
context_lookupis present, that means a context associated with theguc_idis registered with the GuC. We use this xarray as a lookup mechanism when the GuC communicate with the i915 about the context.'
So no idea how this works, but generally we put a "Protecte by &struct.lock" or similar in here (so you get a nice link plus something you can use as jump label in your ide too). Plus since intel_context has some lifetime rules, explaining whether you're allowed to use the pointer after you unlock, or whether you need to grab a reference or what exactly is going on. Usually there's three options:
- No refcounting, you cannot access a pointer obtained through this after you unluck.
- Weak reference, you upgrade to a full reference with kref_get_unless_zero. If that fails it indicates a lookup failure, since you raced with destruction. If it succeeds you can use the pointer after unlock.
- Strong reference, you get your own reference that stays valid with kref_get().
I'm just bringing this up because the current i915-gem code is full of very tricky locking and lifetime rules, and explains roughly nothing of it in the data structures. Minimally some hints about the locking/lifetime rules of important structs should be there.
For locking rules it's good to double-down on them by adding lockdep_assert_held to all relevant functions (where appropriate only ofc).
What I generally don't think makes sense is to then also document the locking in the kerneldoc for the functions. That tends to be one place too many and ime just gets out of date and not useful at all.
Quoted 7 lines
Quoted 2 lines
Again holds for the entire series, where it makes sense (as in we don't expect to rewrite the entire code anyway).
Slightly out of order but one of the last patches in the series, 'Update GuC documentation' adds a big section of comments that attempts to clarify how all of this code works. I likely should add a section explaining the data structures as well.
Yeah that would be nice.
-Daniel
Quoted 81 lines
Matt
Quoted 78 lines
-Daniel
Quoted 71 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */ @@ -404,6 +430,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [RFC PATCH 43/97] drm/i915/guc: Add lrc descriptor context lookup array
Quoted 55 lines · Daniel Vetter
Quoted 41 lines · Matthew Brost
Quoted 31 lines · Daniel Vetter
Quoted 30 lines · Matthew Brost
Add lrc descriptor context lookup array which can resolve the
intel_contextfrom the lrc descriptor index. In addition to lookup, it can determine in the lrc descriptor context is currently registered with the GuC by checking if an entry for a descriptor index is present. Future patches in the series will make use of this array.Cc John Harrison <[email protected]>Signed-off-by Matthew Brost <[email protected]>--- drivers/gpu/drm/i915/gt/uc/intel_guc.h | 5 +++ .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 32 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0@@ -6,6 +6,8 @@#ifndef _INTEL_GUC_H_#define _INTEL_GUC_H_ +#include "linux/xarray.h" +#include "intel_uncore.h" #include "intel_guc_fw.h" #include "intel_guc_fwif.h" @@ -47,6 +49,9 @@ struct intel_guc {struct i915_vma *lrc_desc_pool;void *lrc_desc_pool_vaddr;Quoted 8 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h struct intel_guc { · line 53
Quoted 2 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +2
-0+/* guc_id to intel_context lookup */ +struct xarray context_lookup;The current code sets a disastrous example, but for stuff like this it's always good to explain the locking, and who's holding references and how you're handling cycles. Since I guess the
intel_contextalso holds theguc_idalive somehow.Quoted 5 lines
I think (?) I know what you mean by this comment. How about adding:
'If an entry in the the
context_lookupis present, that means a context associated with theguc_idis registered with the GuC. We use this xarray as a lookup mechanism when the GuC communicate with the i915 about the context.'So no idea how this works, but generally we put a "Protecte by &struct.lock" or similar in here (so you get a nice link plus something you can use as jump label in your ide too). Plus since
intel_contexthas some lifetime rules, explaining whether you're allowed to use the pointer after you unlock, or whether you need to grab a reference or what exactly is going on. Usually there's three options:
Quoted 9 lines
- No refcounting, you cannot access a pointer obtained through this after you unluck.
- Weak reference, you upgrade to a full reference withkref_get_unless_zero. If that fails it indicates a lookup failure, since you raced with destruction. If it succeeds you can use the pointer after unlock.
- Strong reference, you get your own reference that stays valid withkref_get().
I think the rules for this are 'if this exists in the xarray, we have ref'. Likewise if the GuC knows about the context we have a ref to the context.
Quoted 5 lines
I'm just bringing this up because the current i915-gem code is full of very tricky locking and lifetime rules, and explains roughly nothing of it in the data structures. Minimally some hints about the locking/lifetime rules of important structs should be there.
Agree. I'll add some comments here and to other structures this code uses.
Quoted 4 lines
For locking rules it's good to double-down on them by adding
lockdep_assert_heldto all relevant functions (where appropriate only ofc).
Agree. I think I mostly do that in series. That being said the locking is going to be a bit ugly until we switch to the DRM scheduler because currently multiple processes can enter the GuC backend in parallel. With the DRM scheduler we allow a single point of entry which simplifies things quite a bit.
The current locking rules are explained in the documentation patch: 'Update GuC documentation'. As the locking evolves so will the documentation + lockdep asserts.
Matt
Quoted 102 lines
What I generally don't think makes sense is to then also document the locking in the kerneldoc for the functions. That tends to be one place too many and ime just gets out of date and not useful at all.
Quoted 7 lines
Quoted 2 lines
Again holds for the entire series, where it makes sense (as in we don't expect to rewrite the entire code anyway).
Slightly out of order but one of the last patches in the series, 'Update GuC documentation' adds a big section of comments that attempts to clarify how all of this code works. I likely should add a section explaining the data structures as well.
Yeah that would be nice.
-DanielQuoted 81 lines
Matt
Quoted 78 lines
-Daniel
Quoted 71 lines
drivers/gpu/drm/i915/gt/uc/intel_guc.h +1
-0+/* Control params for fw initialization */ u32 params[GUC_CTL_MAX_DWORDS ];drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +30
-2@@ -65,8 +65,6 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb) return rb_entry(rb, struct i915_priolist, node); } -/* Future patches will use this function */ -__attribute__ ((unused))static struct guc_lrc_desc *__get_lrc_desc (struct intel_guc *guc,u32 index) {struct guc_lrc_desc *base = guc->lrc_desc_pool_vaddr;@@ -76,6 +74,15 @@ static struct guc_lrc_desc *__get_lrc_desc(struct intel_guc *guc, u32 index)return &base[index]; } +static inline struct intel_context *__get_context (struct intel_guc *guc,u32 id) +{ +struct intel_context *ce =xa_load (&guc->context_lookup, id); + +GEM_BUG_ON (id >=GUC_MAX_LRC_DESCRIPTORS ); + +return ce; +} +static int guc_lrc_desc_pool_create (struct intel_guc *guc) {u32 size;@@ -96,6 +103,25 @@ static void guc_lrc_desc_pool_destroy(struct intel_guc *guc)i915_vma_unpin_and_release (&guc->lrc_desc_pool,I915_VMA_RELEASE_MAP ); } +static inline void reset_lrc_desc (struct intel_guc *guc,u32 id) +{ +struct guc_lrc_desc *desc =__get_lrc_desc (guc, id); + +memset (desc,0 ,sizeof (*desc)); +xa_erase_irq (&guc->context_lookup, id); +} + +static inline bool lrc_desc_registered (struct intel_guc *guc,u32 id) +{ +return __get_context (guc, id); +} + +static inline void set_lrc_desc_registered (struct intel_guc *guc,u32 id, +struct intel_context *ce) +{ +xa_store_irq (&guc->context_lookup, id, ce,GFP_ATOMIC ); +} +static void guc_add_request (struct intel_guc *guc,struct i915_request *rq) {/* Leaving stub as this function will be used in future patches */ @@ -404,6 +430,8 @@ int intel_guc_submission_init(struct intel_guc *guc)*/ GEM_BUG_ON (!guc->lrc_desc_pool); +xa_init_flags (&guc->context_lookup,XA_FLAGS_LOCK_IRQ ); +return 0 ; }Signature · 1 line
2.28.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.chSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
RFC PATCH 44/97 drm/i915/guc: Implement GuC submission tasklet
In reply to Matthew BrostImplement GuC submission tasklet for new interface. The new GuC interface uses H2G to submit contexts to the GuC. Since H2G use a single channel, a single tasklet submits is used for the submission path. As such a global struct intel_engine_cs has been added to leverage the existing scheduling code.
Also the per engine interrupt handler has been updated to disable the rescheduling of the physical engine tasklet, when using GuC scheduling, as the physical engine tasklet is no longer used.
In this patch the field, guc_id, has been added to intel_context and is not assigned. Patches later in the series will assign this value.
--- drivers/gpu/drm/i915/gt/intel_context_types.h | 9 + drivers/gpu/drm/i915/gt/uc/intel_guc.h | 4 + .../gpu/drm/i915/gt/uc/intel_guc_submission.c | 233 +++++++++--------- 3 files changed, 127 insertions(+), 119 deletions(-)
drivers/gpu/drm/i915/gt/intel_context_types.h +9 -0
@@ -136,6 +136,15 @@ struct intel_context {struct intel_sseu sseu;u8 wa_bb_page;/* if set, page num reserved for context workarounds */ + +/* GuC scheduling state that does not require a lock. */ +atomic_t guc_sched_state_no_lock; + +/* +* GuC lrc descriptor ID - Not assigned in this patch but future patches +* in the series will. +*/ + u16 guc_id; };#endif /* __INTEL_CONTEXT_TYPES__ */
drivers/gpu/drm/i915/gt/uc/intel_guc.h +4 -0
@@ -30,6 +30,10 @@ struct intel_guc {struct intel_guc_log log;struct intel_guc_ct ct; +/* Global engine used to submit requests to GuC */ +struct i915_sched_engine *sched_engine; +struct i915_request *stalled_request; +/* intel_guc_recv interrupt related state */ spinlock_t irq_lock;unsigned int msg_enabled_mask;
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c +114 -119
350 lines not on this page · raw message
Signature · 6 lines
2.28.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx