Commit b8b9ba58 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Alex Deucher

drm/amdkfd: Use non-atomic bitmap functions when possible

All uses of the 'kfd->gtt_sa_bitmap' bitmap are protected with the
'kfd->gtt_sa_lock' mutex.

So:
   - prefer the non-atomic '__set_bit()' function
   - use the non-atomic 'bitmap_[set|clear]()' functions instead of
     equivalent 'for' loops. These functions can work on several bits at a
     time
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent f43a9f18
...@@ -967,7 +967,7 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size, ...@@ -967,7 +967,7 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size,
/* If we need only one chunk, mark it as allocated and get out */ /* If we need only one chunk, mark it as allocated and get out */
if (size <= kfd->gtt_sa_chunk_size) { if (size <= kfd->gtt_sa_chunk_size) {
pr_debug("Single bit\n"); pr_debug("Single bit\n");
set_bit(found, kfd->gtt_sa_bitmap); __set_bit(found, kfd->gtt_sa_bitmap);
goto kfd_gtt_out; goto kfd_gtt_out;
} }
...@@ -1005,10 +1005,8 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size, ...@@ -1005,10 +1005,8 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size,
(*mem_obj)->range_start, (*mem_obj)->range_end); (*mem_obj)->range_start, (*mem_obj)->range_end);
/* Mark the chunks as allocated */ /* Mark the chunks as allocated */
for (found = (*mem_obj)->range_start; bitmap_set(kfd->gtt_sa_bitmap, (*mem_obj)->range_start,
found <= (*mem_obj)->range_end; (*mem_obj)->range_end - (*mem_obj)->range_start + 1);
found++)
set_bit(found, kfd->gtt_sa_bitmap);
kfd_gtt_out: kfd_gtt_out:
mutex_unlock(&kfd->gtt_sa_lock); mutex_unlock(&kfd->gtt_sa_lock);
...@@ -1023,8 +1021,6 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size, ...@@ -1023,8 +1021,6 @@ int kfd_gtt_sa_allocate(struct kfd_dev *kfd, unsigned int size,
int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj) int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj)
{ {
unsigned int bit;
/* Act like kfree when trying to free a NULL object */ /* Act like kfree when trying to free a NULL object */
if (!mem_obj) if (!mem_obj)
return 0; return 0;
...@@ -1035,10 +1031,8 @@ int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj) ...@@ -1035,10 +1031,8 @@ int kfd_gtt_sa_free(struct kfd_dev *kfd, struct kfd_mem_obj *mem_obj)
mutex_lock(&kfd->gtt_sa_lock); mutex_lock(&kfd->gtt_sa_lock);
/* Mark the chunks as free */ /* Mark the chunks as free */
for (bit = mem_obj->range_start; bitmap_clear(kfd->gtt_sa_bitmap, mem_obj->range_start,
bit <= mem_obj->range_end; mem_obj->range_end - mem_obj->range_start + 1);
bit++)
clear_bit(bit, kfd->gtt_sa_bitmap);
mutex_unlock(&kfd->gtt_sa_lock); mutex_unlock(&kfd->gtt_sa_lock);
......
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