diff options
author | Rex Zhu <Rex.Zhu@amd.com> | 2016-05-12 01:27:28 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2016-05-13 14:30:22 -0400 |
commit | d573de2d00835e38cef1fb4bff7b49c174c68941 (patch) | |
tree | cb84cee91af7122f9503796aa5b390d47b83d999 /drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | |
parent | 8b41e7a03a306d93276f91c1dae39dc51a1af58d (diff) |
drm/amdgpu: create fence slab once when amdgpu module init.
This avoids problems with multiple GPUs. For example,
if the first GPU failed before amdgpu_fence_init() was
called, amdgpu_fence_slab_ref is still 0 and it will
get decremented in amdgpu_fence_driver_fini(). This
will lead to a crash during init of the second GPU since
amdgpu_fence_slab_ref is not 0.
v2: add functions for init/exit instead of
moving the variables into the driver.
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c index ba9c04283d01..7eb2fca871e8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | |||
@@ -55,8 +55,21 @@ struct amdgpu_fence { | |||
55 | }; | 55 | }; |
56 | 56 | ||
57 | static struct kmem_cache *amdgpu_fence_slab; | 57 | static struct kmem_cache *amdgpu_fence_slab; |
58 | static atomic_t amdgpu_fence_slab_ref = ATOMIC_INIT(0); | ||
59 | 58 | ||
59 | int amdgpu_fence_slab_init(void) | ||
60 | { | ||
61 | amdgpu_fence_slab = kmem_cache_create( | ||
62 | "amdgpu_fence", sizeof(struct amdgpu_fence), 0, | ||
63 | SLAB_HWCACHE_ALIGN, NULL); | ||
64 | if (!amdgpu_fence_slab) | ||
65 | return -ENOMEM; | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | void amdgpu_fence_slab_fini(void) | ||
70 | { | ||
71 | kmem_cache_destroy(amdgpu_fence_slab); | ||
72 | } | ||
60 | /* | 73 | /* |
61 | * Cast helper | 74 | * Cast helper |
62 | */ | 75 | */ |
@@ -396,13 +409,6 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, | |||
396 | */ | 409 | */ |
397 | int amdgpu_fence_driver_init(struct amdgpu_device *adev) | 410 | int amdgpu_fence_driver_init(struct amdgpu_device *adev) |
398 | { | 411 | { |
399 | if (atomic_inc_return(&amdgpu_fence_slab_ref) == 1) { | ||
400 | amdgpu_fence_slab = kmem_cache_create( | ||
401 | "amdgpu_fence", sizeof(struct amdgpu_fence), 0, | ||
402 | SLAB_HWCACHE_ALIGN, NULL); | ||
403 | if (!amdgpu_fence_slab) | ||
404 | return -ENOMEM; | ||
405 | } | ||
406 | if (amdgpu_debugfs_fence_init(adev)) | 412 | if (amdgpu_debugfs_fence_init(adev)) |
407 | dev_err(adev->dev, "fence debugfs file creation failed\n"); | 413 | dev_err(adev->dev, "fence debugfs file creation failed\n"); |
408 | 414 | ||
@@ -441,9 +447,6 @@ void amdgpu_fence_driver_fini(struct amdgpu_device *adev) | |||
441 | kfree(ring->fence_drv.fences); | 447 | kfree(ring->fence_drv.fences); |
442 | ring->fence_drv.initialized = false; | 448 | ring->fence_drv.initialized = false; |
443 | } | 449 | } |
444 | |||
445 | if (atomic_dec_and_test(&amdgpu_fence_slab_ref)) | ||
446 | kmem_cache_destroy(amdgpu_fence_slab); | ||
447 | } | 450 | } |
448 | 451 | ||
449 | /** | 452 | /** |