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

drm/amdgpu: improve sa_bo->fence by kernel fence

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Christian K?nig <christian.koenig@amd.com>

authored by

Chunming Zhou and committed by
Alex Deucher
4ce9891e 1aa4051b

+58 -34
+4 -4
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 441 441 unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring); 442 442 443 443 signed long amdgpu_fence_wait_multiple(struct amdgpu_device *adev, 444 - struct amdgpu_fence **array, 444 + struct fence **array, 445 445 uint32_t count, 446 446 bool wait_all, 447 447 bool intr, ··· 654 654 struct amdgpu_sa_manager *manager; 655 655 unsigned soffset; 656 656 unsigned eoffset; 657 - struct amdgpu_fence *fence; 657 + struct fence *fence; 658 658 }; 659 659 660 660 /* ··· 696 696 struct amdgpu_semaphore *semaphore); 697 697 void amdgpu_semaphore_free(struct amdgpu_device *adev, 698 698 struct amdgpu_semaphore **semaphore, 699 - struct amdgpu_fence *fence); 699 + struct fence *fence); 700 700 701 701 /* 702 702 * Synchronization ··· 717 717 int amdgpu_sync_rings(struct amdgpu_sync *sync, 718 718 struct amdgpu_ring *ring); 719 719 void amdgpu_sync_free(struct amdgpu_device *adev, struct amdgpu_sync *sync, 720 - struct amdgpu_fence *fence); 720 + struct fence *fence); 721 721 722 722 /* 723 723 * GART structures, functions & helpers
+11 -11
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
··· 836 836 return test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags); 837 837 } 838 838 839 - static bool amdgpu_test_signaled_any(struct amdgpu_fence **fences, uint32_t count) 839 + static bool amdgpu_test_signaled_any(struct fence **fences, uint32_t count) 840 840 { 841 841 int idx; 842 - struct amdgpu_fence *fence; 842 + struct fence *fence; 843 843 844 844 for (idx = 0; idx < count; ++idx) { 845 845 fence = fences[idx]; 846 846 if (fence) { 847 - if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags)) 847 + if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 848 848 return true; 849 849 } 850 850 } 851 851 return false; 852 852 } 853 853 854 - static bool amdgpu_test_signaled_all(struct amdgpu_fence **fences, uint32_t count) 854 + static bool amdgpu_test_signaled_all(struct fence **fences, uint32_t count) 855 855 { 856 856 int idx; 857 - struct amdgpu_fence *fence; 857 + struct fence *fence; 858 858 859 859 for (idx = 0; idx < count; ++idx) { 860 860 fence = fences[idx]; 861 861 if (fence) { 862 - if (!test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags)) 862 + if (!test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 863 863 return false; 864 864 } 865 865 } ··· 885 885 struct amdgpu_fence *fence = to_amdgpu_fence(f); 886 886 struct amdgpu_device *adev = fence->ring->adev; 887 887 888 - return amdgpu_fence_wait_multiple(adev, &fence, 1, false, intr, t); 888 + return amdgpu_fence_wait_multiple(adev, &f, 1, false, intr, t); 889 889 } 890 890 891 891 /** ··· 902 902 * If wait_all is false, it will return when any fence is signaled or timeout. 903 903 */ 904 904 signed long amdgpu_fence_wait_multiple(struct amdgpu_device *adev, 905 - struct amdgpu_fence **array, 905 + struct fence **array, 906 906 uint32_t count, 907 907 bool wait_all, 908 908 bool intr, ··· 910 910 { 911 911 long idx = 0; 912 912 struct amdgpu_wait_cb *cb; 913 - struct amdgpu_fence *fence; 913 + struct fence *fence; 914 914 915 915 BUG_ON(!array); 916 916 ··· 924 924 fence = array[idx]; 925 925 if (fence) { 926 926 cb[idx].task = current; 927 - if (fence_add_callback(&fence->base, 927 + if (fence_add_callback(fence, 928 928 &cb[idx].base, amdgpu_fence_wait_cb)) { 929 929 /* The fence is already signaled */ 930 930 if (wait_all) ··· 967 967 for (idx = 0; idx < count; ++idx) { 968 968 fence = array[idx]; 969 969 if (fence) 970 - fence_remove_callback(&fence->base, &cb[idx].base); 970 + fence_remove_callback(fence, &cb[idx].base); 971 971 } 972 972 973 973 err_free_cb:
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
··· 93 93 */ 94 94 void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib) 95 95 { 96 - amdgpu_sync_free(adev, &ib->sync, ib->fence); 97 - amdgpu_sa_bo_free(adev, &ib->sa_bo, ib->fence); 96 + amdgpu_sync_free(adev, &ib->sync, &ib->fence->base); 97 + amdgpu_sa_bo_free(adev, &ib->sa_bo, &ib->fence->base); 98 98 amdgpu_fence_unref(&ib->fence); 99 99 } 100 100
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
··· 193 193 unsigned size, unsigned align); 194 194 void amdgpu_sa_bo_free(struct amdgpu_device *adev, 195 195 struct amdgpu_sa_bo **sa_bo, 196 - struct amdgpu_fence *fence); 196 + struct fence *fence); 197 197 #if defined(CONFIG_DEBUG_FS) 198 198 void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager, 199 199 struct seq_file *m);
+37 -13
drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c
··· 139 139 return r; 140 140 } 141 141 142 + static uint32_t amdgpu_sa_get_ring_from_fence(struct fence *f) 143 + { 144 + struct amdgpu_fence *a_fence; 145 + struct amd_sched_fence *s_fence; 146 + 147 + s_fence = to_amd_sched_fence(f); 148 + if (s_fence) 149 + return s_fence->entity->scheduler->ring_id; 150 + a_fence = to_amdgpu_fence(f); 151 + if (a_fence) 152 + return a_fence->ring->idx; 153 + return 0; 154 + } 155 + 142 156 static void amdgpu_sa_bo_remove_locked(struct amdgpu_sa_bo *sa_bo) 143 157 { 144 158 struct amdgpu_sa_manager *sa_manager = sa_bo->manager; ··· 161 147 } 162 148 list_del_init(&sa_bo->olist); 163 149 list_del_init(&sa_bo->flist); 164 - amdgpu_fence_unref(&sa_bo->fence); 150 + fence_put(sa_bo->fence); 165 151 kfree(sa_bo); 166 152 } 167 153 ··· 175 161 sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, olist); 176 162 list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { 177 163 if (sa_bo->fence == NULL || 178 - !fence_is_signaled(&sa_bo->fence->base)) { 164 + !fence_is_signaled(sa_bo->fence)) { 179 165 return; 180 166 } 181 167 amdgpu_sa_bo_remove_locked(sa_bo); ··· 260 246 } 261 247 262 248 static bool amdgpu_sa_bo_next_hole(struct amdgpu_sa_manager *sa_manager, 263 - struct amdgpu_fence **fences, 249 + struct fence **fences, 264 250 unsigned *tries) 265 251 { 266 252 struct amdgpu_sa_bo *best_bo = NULL; ··· 289 275 sa_bo = list_first_entry(&sa_manager->flist[i], 290 276 struct amdgpu_sa_bo, flist); 291 277 292 - if (!fence_is_signaled(&sa_bo->fence->base)) { 278 + if (!fence_is_signaled(sa_bo->fence)) { 293 279 fences[i] = sa_bo->fence; 294 280 continue; 295 281 } ··· 313 299 } 314 300 315 301 if (best_bo) { 316 - ++tries[best_bo->fence->ring->idx]; 302 + uint32_t idx = amdgpu_sa_get_ring_from_fence(best_bo->fence); 303 + ++tries[idx]; 317 304 sa_manager->hole = best_bo->olist.prev; 318 305 319 306 /* we knew that this one is signaled, ··· 330 315 struct amdgpu_sa_bo **sa_bo, 331 316 unsigned size, unsigned align) 332 317 { 333 - struct amdgpu_fence *fences[AMDGPU_MAX_RINGS]; 318 + struct fence *fences[AMDGPU_MAX_RINGS]; 334 319 unsigned tries[AMDGPU_MAX_RINGS]; 335 320 int i, r; 336 321 signed long t; ··· 388 373 } 389 374 390 375 void amdgpu_sa_bo_free(struct amdgpu_device *adev, struct amdgpu_sa_bo **sa_bo, 391 - struct amdgpu_fence *fence) 376 + struct fence *fence) 392 377 { 393 378 struct amdgpu_sa_manager *sa_manager; 394 379 ··· 398 383 399 384 sa_manager = (*sa_bo)->manager; 400 385 spin_lock(&sa_manager->wq.lock); 401 - if (fence && !fence_is_signaled(&fence->base)) { 402 - (*sa_bo)->fence = amdgpu_fence_ref(fence); 403 - list_add_tail(&(*sa_bo)->flist, 404 - &sa_manager->flist[fence->ring->idx]); 386 + if (fence && !fence_is_signaled(fence)) { 387 + uint32_t idx; 388 + (*sa_bo)->fence = fence_get(fence); 389 + idx = amdgpu_sa_get_ring_from_fence(fence); 390 + list_add_tail(&(*sa_bo)->flist, &sa_manager->flist[idx]); 405 391 } else { 406 392 amdgpu_sa_bo_remove_locked(*sa_bo); 407 393 } ··· 429 413 seq_printf(m, "[0x%010llx 0x%010llx] size %8lld", 430 414 soffset, eoffset, eoffset - soffset); 431 415 if (i->fence) { 432 - seq_printf(m, " protected by 0x%016llx on ring %d", 433 - i->fence->seq, i->fence->ring->idx); 416 + struct amdgpu_fence *a_fence = to_amdgpu_fence(i->fence); 417 + struct amd_sched_fence *s_fence = to_amd_sched_fence(i->fence); 418 + if (a_fence) 419 + seq_printf(m, " protected by 0x%016llx on ring %d", 420 + a_fence->seq, a_fence->ring->idx); 421 + if (s_fence) 422 + seq_printf(m, " protected by 0x%016llx on ring %d", 423 + s_fence->v_seq, 424 + s_fence->entity->scheduler->ring_id); 425 + 434 426 } 435 427 seq_printf(m, "\n"); 436 428 }
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_semaphore.c
··· 87 87 88 88 void amdgpu_semaphore_free(struct amdgpu_device *adev, 89 89 struct amdgpu_semaphore **semaphore, 90 - struct amdgpu_fence *fence) 90 + struct fence *fence) 91 91 { 92 92 if (semaphore == NULL || *semaphore == NULL) { 93 93 return;
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c
··· 234 234 */ 235 235 void amdgpu_sync_free(struct amdgpu_device *adev, 236 236 struct amdgpu_sync *sync, 237 - struct amdgpu_fence *fence) 237 + struct fence *fence) 238 238 { 239 239 unsigned i; 240 240
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
··· 1042 1042 } 1043 1043 1044 1044 amdgpu_ring_unlock_commit(ring); 1045 - amdgpu_sync_free(adev, &sync, *fence); 1045 + amdgpu_sync_free(adev, &sync, &(*fence)->base); 1046 1046 1047 1047 return 0; 1048 1048 }