History

drm/i915: Decouple execbuf uAPI from internal implementation

At the moment execbuf ring selection is fully coupled to internal ring ids which is not a good thing on its own. This dependency is also spread between two source files and not spelled out at either side which makes it hidden and fragile. This patch decouples this dependency by introducing an explicit translation table of execbuf uAPI to ring id close to the only call site (i915_gem_do_execbuffer). This way we are free to change driver internal implementation details without breaking userspace. All state relating to the uAPI is now contained in, or next to, i915_gem_do_execbuffer. As a side benefit, this patch decreases the compiled size of i915_gem_do_execbuffer. v2: Extract ring selection into eb_select_ring. (Chris Wilson)

Tvrtko Ursulin committed 10 years ago

Commit de1add31 parent 7c17d374 files · +81 −74Browse files

Unified · Split

4 files
  1. drivers/gpu/drm/i915/i915_drv.h +2 −2
  2. drivers/gpu/drm/i915/i915_gem.c +2 −0
  3. drivers/gpu/drm/i915/i915_gem_execbuffer.c +72 −67
  4. drivers/gpu/drm/i915/intel_ringbuffer.h +5 −5
drivers/gpu/drm/i915/i915_drv.h+2−2
@@ -334,7 +334,7 @@ struct drm_i915_file_private { · 333 unmodified lines
334334 unsigned boosts;
335335 } rps;
336336
337− struct intel_engine_cs *bsd_ring;
337+ unsigned int bsd_ring;
338338 };
339339
340340 enum intel_dpll_id {
@@ -1299,7 +1299,7 @@ struct i915_gem_mm { · 958 unmodified lines
12991299 bool busy;
13001300
13011301 /* the indicator for dispatch video commands on two BSD rings */
1302− int bsd_ring_dispatch_index;
1302+ unsigned int bsd_ring_dispatch_index;
13031303
13041304 /** Bit 6 swizzling required for X tiling */
13051305 uint32_t bit_6_swizzle_x;
drivers/gpu/drm/i915/i915_gem.c+2−0
@@ -5141,6 +5141,8 @@ int i915_gem_open(struct drm_device *dev, struct drm_file *file) · 5140 unmodified lines
51415141 spin_lock_init(&file_priv->mm.lock);
51425142 INIT_LIST_HEAD(&file_priv->mm.request_list);
51435143
5144+ file_priv->bsd_ring = -1;
5145+
51445146 ret = i915_gem_context_open(dev, file);
51455147 if (ret)
51465148 kfree(file_priv);
drivers/gpu/drm/i915/i915_gem_execbuffer.c+72−67
@@ -1325,33 +1325,23 @@ i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params, · 1324 unmodified lines
13251325
13261326 /**
13271327 * Find one BSD ring to dispatch the corresponding BSD command.
1328− * The Ring ID is returned.
1328+ * The ring index is returned.
13291329 */
1330−static int gen8_dispatch_bsd_ring(struct drm_device *dev,
1331− struct drm_file *file)
1330+static unsigned int
1331+gen8_dispatch_bsd_ring(struct drm_i915_private *dev_priv, struct drm_file *file)
13321332 {
1333− struct drm_i915_private *dev_priv = dev->dev_private;
13341333 struct drm_i915_file_private *file_priv = file->driver_priv;
13351334
1336− /* Check whether the file_priv is using one ring */
1337− if (file_priv->bsd_ring)
1338− return file_priv->bsd_ring->id;
1339− else {
1340− /* If no, use the ping-pong mechanism to select one ring */
1341− int ring_id;
1342−
1343− mutex_lock(&dev->struct_mutex);
1344− if (dev_priv->mm.bsd_ring_dispatch_index == 0) {
1345− ring_id = VCS;
1346− dev_priv->mm.bsd_ring_dispatch_index = 1;
1347− } else {
1348− ring_id = VCS2;
1349− dev_priv->mm.bsd_ring_dispatch_index = 0;
1350− }
1351− file_priv->bsd_ring = &dev_priv->ring[ring_id];
1352− mutex_unlock(&dev->struct_mutex);
1353− return ring_id;
1335+ /* Check whether the file_priv has already selected one ring. */
1336+ if ((int)file_priv->bsd_ring < 0) {
1337+ /* If not, use the ping-pong mechanism to select one. */
1338+ mutex_lock(&dev_priv->dev->struct_mutex);
1339+ file_priv->bsd_ring = dev_priv->mm.bsd_ring_dispatch_index;
1340+ dev_priv->mm.bsd_ring_dispatch_index ^= 1;
1341+ mutex_unlock(&dev_priv->dev->struct_mutex);
13541342 }
1343+
1344+ return file_priv->bsd_ring;
13551345 }
13561346
13571347 static struct drm_i915_gem_object *
@@ -1374,6 +1364,63 @@ eb_get_batch(struct eb_vmas *eb) · 16 unmodified lines
13741364 return vma->obj;
13751365 }
13761366
1367+#define I915_USER_RINGS (4)
1368+
1369+static const enum intel_ring_id user_ring_map[I915_USER_RINGS + 1] = {
1370+ [I915_EXEC_DEFAULT] = RCS,
1371+ [I915_EXEC_RENDER] = RCS,
1372+ [I915_EXEC_BLT] = BCS,
1373+ [I915_EXEC_BSD] = VCS,
1374+ [I915_EXEC_VEBOX] = VECS
1375+};
1376+
1377+static int
1378+eb_select_ring(struct drm_i915_private *dev_priv,
1379+ struct drm_file *file,
1380+ struct drm_i915_gem_execbuffer2 *args,
1381+ struct intel_engine_cs **ring)
1382+{
1383+ unsigned int user_ring_id = args->flags & I915_EXEC_RING_MASK;
1384+
1385+ if (user_ring_id > I915_USER_RINGS) {
1386+ DRM_DEBUG("execbuf with unknown ring: %u\n", user_ring_id);
1387+ return -EINVAL;
1388+ }
1389+
1390+ if ((user_ring_id != I915_EXEC_BSD) &&
1391+ ((args->flags & I915_EXEC_BSD_MASK) != 0)) {
1392+ DRM_DEBUG("execbuf with non bsd ring but with invalid "
1393+ "bsd dispatch flags: %d\n", (int)(args->flags));
1394+ return -EINVAL;
1395+ }
1396+
1397+ if (user_ring_id == I915_EXEC_BSD && HAS_BSD2(dev_priv)) {
1398+ unsigned int bsd_idx = args->flags & I915_EXEC_BSD_MASK;
1399+
1400+ if (bsd_idx == I915_EXEC_BSD_DEFAULT) {
1401+ bsd_idx = gen8_dispatch_bsd_ring(dev_priv, file);
1402+ } else if (bsd_idx >= I915_EXEC_BSD_RING1 &&
1403+ bsd_idx <= I915_EXEC_BSD_RING2) {
1404+ bsd_idx--;
1405+ } else {
1406+ DRM_DEBUG("execbuf with unknown bsd ring: %u\n",
1407+ bsd_idx);
1408+ return -EINVAL;
1409+ }
1410+
1411+ *ring = &dev_priv->ring[_VCS(bsd_idx)];
1412+ } else {
1413+ *ring = &dev_priv->ring[user_ring_map[user_ring_id]];
1414+ }
1415+
1416+ if (!intel_ring_initialized(*ring)) {
1417+ DRM_DEBUG("execbuf with invalid ring: %u\n", user_ring_id);
1418+ return -EINVAL;
1419+ }
1420+
1421+ return 0;
1422+}
1423+
13771424 static int
13781425 i915_gem_do_execbuffer(struct drm_device *dev, void *data,
13791426 struct drm_file *file,
@@ -1412,51 +1459,9 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, · 32 unmodified lines
14121459 if (args->flags & I915_EXEC_IS_PINNED)
14131460 dispatch_flags |= I915_DISPATCH_PINNED;
14141461
1415− if ((args->flags & I915_EXEC_RING_MASK) > LAST_USER_RING) {
1416− DRM_DEBUG("execbuf with unknown ring: %d\n",
1417− (int)(args->flags & I915_EXEC_RING_MASK));
1418− return -EINVAL;
1419− }
1420−
1421− if (((args->flags & I915_EXEC_RING_MASK) != I915_EXEC_BSD) &&
1422− ((args->flags & I915_EXEC_BSD_MASK) != 0)) {
1423− DRM_DEBUG("execbuf with non bsd ring but with invalid "
1424− "bsd dispatch flags: %d\n", (int)(args->flags));
1425− return -EINVAL;
1426− }
1427−
1428− if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_DEFAULT)
1429− ring = &dev_priv->ring[RCS];
1430− else if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_BSD) {
1431− if (HAS_BSD2(dev)) {
1432− int ring_id;
1433−
1434− switch (args->flags & I915_EXEC_BSD_MASK) {
1435− case I915_EXEC_BSD_DEFAULT:
1436− ring_id = gen8_dispatch_bsd_ring(dev, file);
1437− ring = &dev_priv->ring[ring_id];
1438− break;
1439− case I915_EXEC_BSD_RING1:
1440− ring = &dev_priv->ring[VCS];
1441− break;
1442− case I915_EXEC_BSD_RING2:
1443− ring = &dev_priv->ring[VCS2];
1444− break;
1445− default:
1446− DRM_DEBUG("execbuf with unknown bsd ring: %d\n",
1447− (int)(args->flags & I915_EXEC_BSD_MASK));
1448− return -EINVAL;
1449− }
1450− } else
1451− ring = &dev_priv->ring[VCS];
1452− } else
1453− ring = &dev_priv->ring[(args->flags & I915_EXEC_RING_MASK) - 1];
1454−
1455− if (!intel_ring_initialized(ring)) {
1456− DRM_DEBUG("execbuf with invalid ring: %d\n",
1457− (int)(args->flags & I915_EXEC_RING_MASK));
1458− return -EINVAL;
1459− }
1462+ ret = eb_select_ring(dev_priv, file, args, &ring);
1463+ if (ret)
1464+ return ret;
14601465
14611466 if (args->buffer_count < 1) {
14621467 DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count);
drivers/gpu/drm/i915/intel_ringbuffer.h+5−5
@@ -149,14 +149,14 @@ struct i915_ctx_workarounds { · 148 unmodified lines
149149 struct intel_engine_cs {
150150 const char *name;
151151 enum intel_ring_id {
152− RCS = 0x0,
153− VCS,
152+ RCS = 0,
154153 BCS,
155− VECS,
156− VCS2
154+ VCS,
155+ VCS2, /* Keep instances of the same type engine together. */
156+ VECS
157157 } id;
158158 #define I915_NUM_RINGS 5
159−#define LAST_USER_RING (VECS + 1)
159+#define _VCS(n) (VCS + (n))
160160 u32 mmio_base;
161161 struct drm_device *dev;
162162 struct intel_ringbuffer *buffer;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t