Commit 1681924d authored by Matthew Brost's avatar Matthew Brost Committed by John Harrison

drm/i915/guc: Add non blocking CTB send function

Add non blocking CTB send function, intel_guc_send_nb. GuC submission
will send CTBs in the critical path and does not need to wait for these
CTBs to complete before moving on, hence the need for this new function.

The non-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 a 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.

v2:
 (Michal)
  - Use define for H2G room calculations
  - Move INTEL_GUC_SEND_NB define
 (Daniel Vetter)
  - Use msleep_interruptible rather than cond_resched
v3:
 (Michal)
  - Move includes to following patch
  - s/INTEL_GUC_SEND_NB/INTEL_GUC_CT_SEND_NB/g
v4:
 (John H)
  - Update comment, add type local variable
Signed-off-by: default avatarJohn Harrison <John.C.Harrison@Intel.com>
Signed-off-by: default avatarMatthew Brost <matthew.brost@intel.com>
Reviewed-by: default avatarJohn Harrison <John.C.Harrison@Intel.com>
Signed-off-by: default avatarJohn Harrison <John.C.Harrison@Intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708162055.129996-5-matthew.brost@intel.com
parent c26e289f
...@@ -79,7 +79,8 @@ static_assert(sizeof(struct guc_ct_buffer_desc) == 64); ...@@ -79,7 +79,8 @@ static_assert(sizeof(struct guc_ct_buffer_desc) == 64);
* +---+-------+--------------------------------------------------------------+ * +---+-------+--------------------------------------------------------------+
*/ */
#define GUC_CTB_MSG_MIN_LEN 1u #define GUC_CTB_HDR_LEN 1u
#define GUC_CTB_MSG_MIN_LEN GUC_CTB_HDR_LEN
#define GUC_CTB_MSG_MAX_LEN 256u #define GUC_CTB_MSG_MAX_LEN 256u
#define GUC_CTB_MSG_0_FENCE (0xffff << 16) #define GUC_CTB_MSG_0_FENCE (0xffff << 16)
#define GUC_CTB_MSG_0_FORMAT (0xf << 12) #define GUC_CTB_MSG_0_FORMAT (0xf << 12)
......
...@@ -74,7 +74,14 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log) ...@@ -74,7 +74,14 @@ static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)
static static
inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len) 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);
}
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_CT_SEND_NB);
} }
static inline int static inline int
...@@ -82,7 +89,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len, ...@@ -82,7 +89,7 @@ intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,
u32 *response_buf, u32 response_buf_size) u32 *response_buf, u32 response_buf_size)
{ {
return intel_guc_ct_send(&guc->ct, action, len, 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) static inline void intel_guc_to_host_event_handler(struct intel_guc *guc)
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* Copyright © 2016-2019 Intel Corporation * Copyright © 2016-2019 Intel Corporation
*/ */
#include <linux/circ_buf.h>
#include "i915_drv.h" #include "i915_drv.h"
#include "intel_guc_ct.h" #include "intel_guc_ct.h"
#include "gt/intel_gt.h" #include "gt/intel_gt.h"
...@@ -373,7 +375,7 @@ static void write_barrier(struct intel_guc_ct *ct) ...@@ -373,7 +375,7 @@ static void write_barrier(struct intel_guc_ct *ct)
static int ct_write(struct intel_guc_ct *ct, static int ct_write(struct intel_guc_ct *ct,
const u32 *action, const u32 *action,
u32 len /* in dwords */, u32 len /* in dwords */,
u32 fence) u32 fence, u32 flags)
{ {
struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;
struct guc_ct_buffer_desc *desc = ctb->desc; struct guc_ct_buffer_desc *desc = ctb->desc;
...@@ -383,6 +385,7 @@ static int ct_write(struct intel_guc_ct *ct, ...@@ -383,6 +385,7 @@ static int ct_write(struct intel_guc_ct *ct,
u32 used; u32 used;
u32 header; u32 header;
u32 hxg; u32 hxg;
u32 type;
u32 *cmds = ctb->cmds; u32 *cmds = ctb->cmds;
unsigned int i; unsigned int i;
...@@ -408,8 +411,8 @@ static int ct_write(struct intel_guc_ct *ct, ...@@ -408,8 +411,8 @@ static int ct_write(struct intel_guc_ct *ct,
else else
used = tail - head; used = tail - head;
/* make sure there is a space including extra dw for the fence */ /* make sure there is a space including extra dw for the header */
if (unlikely(used + len + 1 >= size)) if (unlikely(used + len + GUC_CTB_HDR_LEN >= size))
return -ENOSPC; return -ENOSPC;
/* /*
...@@ -421,9 +424,11 @@ static int ct_write(struct intel_guc_ct *ct, ...@@ -421,9 +424,11 @@ static int ct_write(struct intel_guc_ct *ct,
FIELD_PREP(GUC_CTB_MSG_0_NUM_DWORDS, len) | FIELD_PREP(GUC_CTB_MSG_0_NUM_DWORDS, len) |
FIELD_PREP(GUC_CTB_MSG_0_FENCE, fence); FIELD_PREP(GUC_CTB_MSG_0_FENCE, fence);
hxg = FIELD_PREP(GUC_HXG_MSG_0_TYPE, GUC_HXG_TYPE_REQUEST) | type = (flags & INTEL_GUC_CT_SEND_NB) ? GUC_HXG_TYPE_EVENT :
FIELD_PREP(GUC_HXG_REQUEST_MSG_0_ACTION | GUC_HXG_TYPE_REQUEST;
GUC_HXG_REQUEST_MSG_0_DATA0, action[0]); hxg = FIELD_PREP(GUC_HXG_MSG_0_TYPE, type) |
FIELD_PREP(GUC_HXG_EVENT_MSG_0_ACTION |
GUC_HXG_EVENT_MSG_0_DATA0, action[0]);
CT_DEBUG(ct, "writing (tail %u) %*ph %*ph %*ph\n", CT_DEBUG(ct, "writing (tail %u) %*ph %*ph %*ph\n",
tail, 4, &header, 4, &hxg, 4 * (len - 1), &action[1]); tail, 4, &header, 4, &hxg, 4 * (len - 1), &action[1]);
...@@ -500,6 +505,48 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status) ...@@ -500,6 +505,48 @@ static int wait_for_ct_request_update(struct ct_request *req, u32 *status)
return err; return err;
} }
static inline bool h2g_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 = h2g_has_room(ctb, len + GUC_CTB_HDR_LEN);
if (unlikely(!ret)) {
ret = -EBUSY;
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, static int ct_send(struct intel_guc_ct *ct,
const u32 *action, const u32 *action,
u32 len, u32 len,
...@@ -507,8 +554,10 @@ static int ct_send(struct intel_guc_ct *ct, ...@@ -507,8 +554,10 @@ static int ct_send(struct intel_guc_ct *ct,
u32 response_buf_size, u32 response_buf_size,
u32 *status) u32 *status)
{ {
struct intel_guc_ct_buffer *ctb = &ct->ctbs.send;
struct ct_request request; struct ct_request request;
unsigned long flags; unsigned long flags;
unsigned int sleep_period_ms = 1;
u32 fence; u32 fence;
int err; int err;
...@@ -516,8 +565,24 @@ static int ct_send(struct intel_guc_ct *ct, ...@@ -516,8 +565,24 @@ static int ct_send(struct intel_guc_ct *ct,
GEM_BUG_ON(!len); GEM_BUG_ON(!len);
GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK);
GEM_BUG_ON(!response_buf && response_buf_size); 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(&ctb->lock, flags);
if (unlikely(!h2g_has_room(ctb, len + GUC_CTB_HDR_LEN))) {
spin_unlock_irqrestore(&ctb->lock, flags);
if (msleep_interruptible(sleep_period_ms))
return -EINTR;
sleep_period_ms = sleep_period_ms << 1;
spin_lock_irqsave(&ct->ctbs.send.lock, flags); goto retry;
}
fence = ct_get_next_fence(ct); fence = ct_get_next_fence(ct);
request.fence = fence; request.fence = fence;
...@@ -529,9 +594,9 @@ static int ct_send(struct intel_guc_ct *ct, ...@@ -529,9 +594,9 @@ static int ct_send(struct intel_guc_ct *ct,
list_add_tail(&request.link, &ct->requests.pending); list_add_tail(&request.link, &ct->requests.pending);
spin_unlock(&ct->requests.lock); 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); spin_unlock_irqrestore(&ctb->lock, flags);
if (unlikely(err)) if (unlikely(err))
goto unlink; goto unlink;
...@@ -571,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct, ...@@ -571,7 +636,7 @@ static int ct_send(struct intel_guc_ct *ct,
* Command Transport (CT) buffer based GuC send function. * Command Transport (CT) buffer based GuC send function.
*/ */
int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len, 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 */ u32 status = ~0; /* undefined */
int ret; int ret;
...@@ -581,6 +646,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len, ...@@ -581,6 +646,9 @@ int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len,
return -ENODEV; return -ENODEV;
} }
if (flags & INTEL_GUC_CT_SEND_NB)
return ct_send_nb(ct, action, len, flags);
ret = ct_send(ct, action, len, response_buf, response_buf_size, &status); ret = ct_send(ct, action, len, response_buf, response_buf_size, &status);
if (unlikely(ret < 0)) { if (unlikely(ret < 0)) {
CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n", CT_ERROR(ct, "Sending action %#x failed (err=%d status=%#X)\n",
......
...@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer { ...@@ -42,7 +42,6 @@ struct intel_guc_ct_buffer {
bool broken; bool broken;
}; };
/** Top-level structure for Command Transport related data /** Top-level structure for Command Transport related data
* *
* Includes a pair of CT buffers for bi-directional communication and tracking * Includes a pair of CT buffers for bi-directional communication and tracking
...@@ -87,8 +86,9 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct) ...@@ -87,8 +86,9 @@ static inline bool intel_guc_ct_enabled(struct intel_guc_ct *ct)
return ct->enabled; return ct->enabled;
} }
#define INTEL_GUC_CT_SEND_NB BIT(31)
int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len, 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); void intel_guc_ct_event_handler(struct intel_guc_ct *ct);
#endif /* _INTEL_GUC_CT_H_ */ #endif /* _INTEL_GUC_CT_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment