diff options
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c')
| -rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 123 |
1 files changed, 25 insertions, 98 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c index 93794a85f83d..b70e85ec147d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | |||
| @@ -135,9 +135,6 @@ void amdgpu_ring_commit(struct amdgpu_ring *ring) | |||
| 135 | 135 | ||
| 136 | if (ring->funcs->end_use) | 136 | if (ring->funcs->end_use) |
| 137 | ring->funcs->end_use(ring); | 137 | ring->funcs->end_use(ring); |
| 138 | |||
| 139 | if (ring->funcs->type != AMDGPU_RING_TYPE_KIQ) | ||
| 140 | amdgpu_ring_lru_touch(ring->adev, ring); | ||
| 141 | } | 138 | } |
| 142 | 139 | ||
| 143 | /** | 140 | /** |
| @@ -320,8 +317,6 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, | |||
| 320 | ring->max_dw = max_dw; | 317 | ring->max_dw = max_dw; |
| 321 | ring->priority = DRM_SCHED_PRIORITY_NORMAL; | 318 | ring->priority = DRM_SCHED_PRIORITY_NORMAL; |
| 322 | mutex_init(&ring->priority_mutex); | 319 | mutex_init(&ring->priority_mutex); |
| 323 | INIT_LIST_HEAD(&ring->lru_list); | ||
| 324 | amdgpu_ring_lru_touch(adev, ring); | ||
| 325 | 320 | ||
| 326 | for (i = 0; i < DRM_SCHED_PRIORITY_MAX; ++i) | 321 | for (i = 0; i < DRM_SCHED_PRIORITY_MAX; ++i) |
| 327 | atomic_set(&ring->num_jobs[i], 0); | 322 | atomic_set(&ring->num_jobs[i], 0); |
| @@ -368,99 +363,6 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring) | |||
| 368 | ring->adev->rings[ring->idx] = NULL; | 363 | ring->adev->rings[ring->idx] = NULL; |
| 369 | } | 364 | } |
| 370 | 365 | ||
| 371 | static void amdgpu_ring_lru_touch_locked(struct amdgpu_device *adev, | ||
| 372 | struct amdgpu_ring *ring) | ||
| 373 | { | ||
| 374 | /* list_move_tail handles the case where ring isn't part of the list */ | ||
| 375 | list_move_tail(&ring->lru_list, &adev->ring_lru_list); | ||
| 376 | } | ||
| 377 | |||
| 378 | static bool amdgpu_ring_is_blacklisted(struct amdgpu_ring *ring, | ||
| 379 | int *blacklist, int num_blacklist) | ||
| 380 | { | ||
| 381 | int i; | ||
| 382 | |||
| 383 | for (i = 0; i < num_blacklist; i++) { | ||
| 384 | if (ring->idx == blacklist[i]) | ||
| 385 | return true; | ||
| 386 | } | ||
| 387 | |||
| 388 | return false; | ||
| 389 | } | ||
| 390 | |||
| 391 | /** | ||
| 392 | * amdgpu_ring_lru_get - get the least recently used ring for a HW IP block | ||
| 393 | * | ||
| 394 | * @adev: amdgpu_device pointer | ||
| 395 | * @type: amdgpu_ring_type enum | ||
| 396 | * @blacklist: blacklisted ring ids array | ||
| 397 | * @num_blacklist: number of entries in @blacklist | ||
| 398 | * @lru_pipe_order: find a ring from the least recently used pipe | ||
| 399 | * @ring: output ring | ||
| 400 | * | ||
| 401 | * Retrieve the amdgpu_ring structure for the least recently used ring of | ||
| 402 | * a specific IP block (all asics). | ||
| 403 | * Returns 0 on success, error on failure. | ||
| 404 | */ | ||
| 405 | int amdgpu_ring_lru_get(struct amdgpu_device *adev, int type, | ||
| 406 | int *blacklist, int num_blacklist, | ||
| 407 | bool lru_pipe_order, struct amdgpu_ring **ring) | ||
| 408 | { | ||
| 409 | struct amdgpu_ring *entry; | ||
| 410 | |||
| 411 | /* List is sorted in LRU order, find first entry corresponding | ||
| 412 | * to the desired HW IP */ | ||
| 413 | *ring = NULL; | ||
| 414 | spin_lock(&adev->ring_lru_list_lock); | ||
| 415 | list_for_each_entry(entry, &adev->ring_lru_list, lru_list) { | ||
| 416 | if (entry->funcs->type != type) | ||
| 417 | continue; | ||
| 418 | |||
| 419 | if (amdgpu_ring_is_blacklisted(entry, blacklist, num_blacklist)) | ||
| 420 | continue; | ||
| 421 | |||
| 422 | if (!*ring) { | ||
| 423 | *ring = entry; | ||
| 424 | |||
| 425 | /* We are done for ring LRU */ | ||
| 426 | if (!lru_pipe_order) | ||
| 427 | break; | ||
| 428 | } | ||
| 429 | |||
| 430 | /* Move all rings on the same pipe to the end of the list */ | ||
| 431 | if (entry->pipe == (*ring)->pipe) | ||
| 432 | amdgpu_ring_lru_touch_locked(adev, entry); | ||
| 433 | } | ||
| 434 | |||
| 435 | /* Move the ring we found to the end of the list */ | ||
| 436 | if (*ring) | ||
| 437 | amdgpu_ring_lru_touch_locked(adev, *ring); | ||
| 438 | |||
| 439 | spin_unlock(&adev->ring_lru_list_lock); | ||
| 440 | |||
| 441 | if (!*ring) { | ||
| 442 | DRM_ERROR("Ring LRU contains no entries for ring type:%d\n", type); | ||
| 443 | return -EINVAL; | ||
| 444 | } | ||
| 445 | |||
| 446 | return 0; | ||
| 447 | } | ||
| 448 | |||
| 449 | /** | ||
| 450 | * amdgpu_ring_lru_touch - mark a ring as recently being used | ||
| 451 | * | ||
| 452 | * @adev: amdgpu_device pointer | ||
| 453 | * @ring: ring to touch | ||
| 454 | * | ||
| 455 | * Move @ring to the tail of the lru list | ||
| 456 | */ | ||
| 457 | void amdgpu_ring_lru_touch(struct amdgpu_device *adev, struct amdgpu_ring *ring) | ||
| 458 | { | ||
| 459 | spin_lock(&adev->ring_lru_list_lock); | ||
| 460 | amdgpu_ring_lru_touch_locked(adev, ring); | ||
| 461 | spin_unlock(&adev->ring_lru_list_lock); | ||
| 462 | } | ||
| 463 | |||
| 464 | /** | 366 | /** |
| 465 | * amdgpu_ring_emit_reg_write_reg_wait_helper - ring helper | 367 | * amdgpu_ring_emit_reg_write_reg_wait_helper - ring helper |
| 466 | * | 368 | * |
| @@ -481,6 +383,31 @@ void amdgpu_ring_emit_reg_write_reg_wait_helper(struct amdgpu_ring *ring, | |||
| 481 | amdgpu_ring_emit_reg_wait(ring, reg1, mask, mask); | 383 | amdgpu_ring_emit_reg_wait(ring, reg1, mask, mask); |
| 482 | } | 384 | } |
| 483 | 385 | ||
| 386 | /** | ||
| 387 | * amdgpu_ring_soft_recovery - try to soft recover a ring lockup | ||
| 388 | * | ||
| 389 | * @ring: ring to try the recovery on | ||
| 390 | * @vmid: VMID we try to get going again | ||
| 391 | * @fence: timedout fence | ||
| 392 | * | ||
| 393 | * Tries to get a ring proceeding again when it is stuck. | ||
| 394 | */ | ||
| 395 | bool amdgpu_ring_soft_recovery(struct amdgpu_ring *ring, unsigned int vmid, | ||
| 396 | struct dma_fence *fence) | ||
| 397 | { | ||
| 398 | ktime_t deadline = ktime_add_us(ktime_get(), 10000); | ||
| 399 | |||
| 400 | if (!ring->funcs->soft_recovery) | ||
| 401 | return false; | ||
| 402 | |||
| 403 | atomic_inc(&ring->adev->gpu_reset_counter); | ||
| 404 | while (!dma_fence_is_signaled(fence) && | ||
| 405 | ktime_to_ns(ktime_sub(deadline, ktime_get())) > 0) | ||
| 406 | ring->funcs->soft_recovery(ring, vmid); | ||
| 407 | |||
| 408 | return dma_fence_is_signaled(fence); | ||
| 409 | } | ||
| 410 | |||
| 484 | /* | 411 | /* |
| 485 | * Debugfs info | 412 | * Debugfs info |
| 486 | */ | 413 | */ |
