Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Break out dma_resv ww locking utilities to separate files

As we're about to add more ww-related functionality,
break out the dma_resv ww locking utilities to their own files

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210617063018.92802-3-thomas.hellstrom@linux.intel.com

authored by

Thomas Hellström and committed by
Matthew Auld
5c43ec5d 1c4dbe05

+87 -68
+1
drivers/gpu/drm/i915/Makefile
··· 166 166 i915_cmd_parser.o \ 167 167 i915_gem_evict.o \ 168 168 i915_gem_gtt.o \ 169 + i915_gem_ww.o \ 169 170 i915_gem.o \ 170 171 i915_globals.o \ 171 172 i915_query.o \
+1
drivers/gpu/drm/i915/gem/i915_gem_object.h
··· 14 14 #include "display/intel_frontbuffer.h" 15 15 #include "i915_gem_object_types.h" 16 16 #include "i915_gem_gtt.h" 17 + #include "i915_gem_ww.h" 17 18 #include "i915_vma_types.h" 18 19 19 20 /*
+1
drivers/gpu/drm/i915/gt/intel_renderstate.h
··· 8 8 9 9 #include <linux/types.h> 10 10 #include "i915_gem.h" 11 + #include "i915_gem_ww.h" 11 12 12 13 struct i915_request; 13 14 struct intel_context;
-56
drivers/gpu/drm/i915/i915_gem.c
··· 1201 1201 return ret; 1202 1202 } 1203 1203 1204 - void i915_gem_ww_ctx_init(struct i915_gem_ww_ctx *ww, bool intr) 1205 - { 1206 - ww_acquire_init(&ww->ctx, &reservation_ww_class); 1207 - INIT_LIST_HEAD(&ww->obj_list); 1208 - ww->intr = intr; 1209 - ww->contended = NULL; 1210 - } 1211 - 1212 - static void i915_gem_ww_ctx_unlock_all(struct i915_gem_ww_ctx *ww) 1213 - { 1214 - struct drm_i915_gem_object *obj; 1215 - 1216 - while ((obj = list_first_entry_or_null(&ww->obj_list, struct drm_i915_gem_object, obj_link))) { 1217 - list_del(&obj->obj_link); 1218 - i915_gem_object_unlock(obj); 1219 - i915_gem_object_put(obj); 1220 - } 1221 - } 1222 - 1223 - void i915_gem_ww_unlock_single(struct drm_i915_gem_object *obj) 1224 - { 1225 - list_del(&obj->obj_link); 1226 - i915_gem_object_unlock(obj); 1227 - i915_gem_object_put(obj); 1228 - } 1229 - 1230 - void i915_gem_ww_ctx_fini(struct i915_gem_ww_ctx *ww) 1231 - { 1232 - i915_gem_ww_ctx_unlock_all(ww); 1233 - WARN_ON(ww->contended); 1234 - ww_acquire_fini(&ww->ctx); 1235 - } 1236 - 1237 - int __must_check i915_gem_ww_ctx_backoff(struct i915_gem_ww_ctx *ww) 1238 - { 1239 - int ret = 0; 1240 - 1241 - if (WARN_ON(!ww->contended)) 1242 - return -EINVAL; 1243 - 1244 - i915_gem_ww_ctx_unlock_all(ww); 1245 - if (ww->intr) 1246 - ret = dma_resv_lock_slow_interruptible(ww->contended->base.resv, &ww->ctx); 1247 - else 1248 - dma_resv_lock_slow(ww->contended->base.resv, &ww->ctx); 1249 - 1250 - if (!ret) 1251 - list_add_tail(&ww->contended->obj_link, &ww->obj_list); 1252 - else 1253 - i915_gem_object_put(ww->contended); 1254 - 1255 - ww->contended = NULL; 1256 - 1257 - return ret; 1258 - } 1259 - 1260 1204 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 1261 1205 #include "selftests/mock_gem_device.c" 1262 1206 #include "selftests/i915_gem.c"
-12
drivers/gpu/drm/i915/i915_gem.h
··· 123 123 return test_bit(TASKLET_STATE_SCHED, &t->state); 124 124 } 125 125 126 - struct i915_gem_ww_ctx { 127 - struct ww_acquire_ctx ctx; 128 - struct list_head obj_list; 129 - bool intr; 130 - struct drm_i915_gem_object *contended; 131 - }; 132 - 133 - void i915_gem_ww_ctx_init(struct i915_gem_ww_ctx *ctx, bool intr); 134 - void i915_gem_ww_ctx_fini(struct i915_gem_ww_ctx *ctx); 135 - int __must_check i915_gem_ww_ctx_backoff(struct i915_gem_ww_ctx *ctx); 136 - void i915_gem_ww_unlock_single(struct drm_i915_gem_object *obj); 137 - 138 126 #endif /* __I915_GEM_H__ */
+63
drivers/gpu/drm/i915/i915_gem_ww.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + #include <linux/dma-resv.h> 6 + #include "i915_gem_ww.h" 7 + #include "gem/i915_gem_object.h" 8 + 9 + void i915_gem_ww_ctx_init(struct i915_gem_ww_ctx *ww, bool intr) 10 + { 11 + ww_acquire_init(&ww->ctx, &reservation_ww_class); 12 + INIT_LIST_HEAD(&ww->obj_list); 13 + ww->intr = intr; 14 + ww->contended = NULL; 15 + } 16 + 17 + static void i915_gem_ww_ctx_unlock_all(struct i915_gem_ww_ctx *ww) 18 + { 19 + struct drm_i915_gem_object *obj; 20 + 21 + while ((obj = list_first_entry_or_null(&ww->obj_list, struct drm_i915_gem_object, obj_link))) { 22 + list_del(&obj->obj_link); 23 + i915_gem_object_unlock(obj); 24 + i915_gem_object_put(obj); 25 + } 26 + } 27 + 28 + void i915_gem_ww_unlock_single(struct drm_i915_gem_object *obj) 29 + { 30 + list_del(&obj->obj_link); 31 + i915_gem_object_unlock(obj); 32 + i915_gem_object_put(obj); 33 + } 34 + 35 + void i915_gem_ww_ctx_fini(struct i915_gem_ww_ctx *ww) 36 + { 37 + i915_gem_ww_ctx_unlock_all(ww); 38 + WARN_ON(ww->contended); 39 + ww_acquire_fini(&ww->ctx); 40 + } 41 + 42 + int __must_check i915_gem_ww_ctx_backoff(struct i915_gem_ww_ctx *ww) 43 + { 44 + int ret = 0; 45 + 46 + if (WARN_ON(!ww->contended)) 47 + return -EINVAL; 48 + 49 + i915_gem_ww_ctx_unlock_all(ww); 50 + if (ww->intr) 51 + ret = dma_resv_lock_slow_interruptible(ww->contended->base.resv, &ww->ctx); 52 + else 53 + dma_resv_lock_slow(ww->contended->base.resv, &ww->ctx); 54 + 55 + if (!ret) 56 + list_add_tail(&ww->contended->obj_link, &ww->obj_list); 57 + else 58 + i915_gem_object_put(ww->contended); 59 + 60 + ww->contended = NULL; 61 + 62 + return ret; 63 + }
+21
drivers/gpu/drm/i915/i915_gem_ww.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2020 Intel Corporation 4 + */ 5 + #ifndef __I915_GEM_WW_H__ 6 + #define __I915_GEM_WW_H__ 7 + 8 + #include <drm/drm_drv.h> 9 + 10 + struct i915_gem_ww_ctx { 11 + struct ww_acquire_ctx ctx; 12 + struct list_head obj_list; 13 + struct drm_i915_gem_object *contended; 14 + bool intr; 15 + }; 16 + 17 + void i915_gem_ww_ctx_init(struct i915_gem_ww_ctx *ctx, bool intr); 18 + void i915_gem_ww_ctx_fini(struct i915_gem_ww_ctx *ctx); 19 + int __must_check i915_gem_ww_ctx_backoff(struct i915_gem_ww_ctx *ctx); 20 + void i915_gem_ww_unlock_single(struct drm_i915_gem_object *obj); 21 + #endif