[PATCH 32/40] drm/i915: Limit C-states when waiting for the active request
Chris Wilson
chris at chris-wilson.co.uk
Mon Sep 17 15:43:05 UTC 2018
If we are waiting for the currently executing request, we have a good
idea that it will be completed in the very near future and so want to
cap the CPU_DMA_LATENCY to ensure that we wake up the client quickly.
v2: Not allowed to block in kmalloc after setting TASK_INTERRUPTIBLE.
v3: Avoid the blocking notifier as well for TASK_INTERRUPTIBLE
v4: Beautification?
v5: And ignore the preemptibility of queue_work before schedule.
v6: Use highpri wq to keep our pm_qos window as small as possible.
v7: Cancel pm_qos around preemption
Testcase: igt/gem_sync/store-default
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin at linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
Cc: Eero Tamminen <eero.t.tamminen at intel.com>
Cc: Francisco Jerez <currojerez at riseup.net>
Cc: Mika Kuoppala <mika.kuoppala at linux.intel.com>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin at intel.com>
---
drivers/gpu/drm/i915/i915_request.c | 58 +++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
index 8d15584a9bf3..51129b0d5582 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -1248,6 +1248,58 @@ static bool __i915_spin_request(const struct i915_request *rq,
return false;
}
+struct wait_dma_qos {
+ struct pm_qos_request req;
+ struct work_struct add, del;
+};
+
+static void __wait_dma_qos_add(struct work_struct *work)
+{
+ struct wait_dma_qos *qos = container_of(work, typeof(*qos), add);
+
+ pm_qos_add_request(&qos->req, PM_QOS_CPU_DMA_LATENCY, 50);
+}
+
+static void __wait_dma_qos_del(struct work_struct *work)
+{
+ struct wait_dma_qos *qos = container_of(work, typeof(*qos), del);
+
+ if (!cancel_work_sync(&qos->add))
+ pm_qos_remove_request(&qos->req);
+
+ kfree(qos);
+}
+
+static struct wait_dma_qos *wait_dma_qos_add(void)
+{
+ struct wait_dma_qos *qos;
+
+ /* Called under TASK_INTERRUPTIBLE, so not allowed to sleep/block. */
+ qos = kzalloc(sizeof(*qos), GFP_NOWAIT | __GFP_NOWARN);
+ if (!qos)
+ return NULL;
+
+ INIT_WORK(&qos->add, __wait_dma_qos_add);
+ INIT_WORK(&qos->del, __wait_dma_qos_del);
+
+ /*
+ * Schedule the enabling work on the local cpu so that it should only
+ * take effect if we actually sleep. If schedule() short circuits due to
+ * our request already being completed, we should then be able to cancel
+ * the work before it is even run.
+ */
+ queue_work_on(raw_smp_processor_id(), system_highpri_wq, &qos->add);
+
+ return qos;
+}
+
+static void wait_dma_qos_del(struct wait_dma_qos *qos)
+{
+ /* Defer to worker so not incur extra latency for our woken client. */
+ if (qos)
+ queue_work(system_highpri_wq, &qos->del);
+}
+
/**
* i915_request_wait - wait until execution of request has finished
* @rq: the request to wait upon
@@ -1274,6 +1326,7 @@ long i915_request_wait(struct i915_request *rq,
const int state = flags & I915_WAIT_INTERRUPTIBLE ?
TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;
DEFINE_WAIT_FUNC(exec, default_wake_function);
+ struct wait_dma_qos *qos = NULL;
struct intel_wait wait;
might_sleep();
@@ -1335,6 +1388,9 @@ long i915_request_wait(struct i915_request *rq,
break;
}
+ if (!qos && intel_engine_has_started(rq->engine, wait.seqno))
+ qos = wait_dma_qos_add();
+
timeout = io_schedule_timeout(timeout);
if (intel_wait_complete(&wait) &&
@@ -1359,6 +1415,7 @@ long i915_request_wait(struct i915_request *rq,
if (!intel_wait_check_request(&wait, rq)) {
intel_engine_remove_wait(rq->engine, &wait);
+ wait_dma_qos_del(fetch_and_zero(&qos));
goto restart;
}
}
@@ -1367,6 +1424,7 @@ long i915_request_wait(struct i915_request *rq,
complete:
__set_current_state(TASK_RUNNING);
remove_wait_queue(&rq->execute, &exec);
+ wait_dma_qos_del(qos);
trace_i915_request_wait_end(rq);
return timeout;
--
2.19.0
More information about the Intel-gfx-trybot
mailing list