Commit 65781c78 authored by Monk Liu's avatar Monk Liu Committed by Alex Deucher

drm/amdgpu/SRIOV:implement guilty job TDR for(V2)

1,TDR will kickout guilty job if it hang exceed the threshold
of the given one from kernel paramter "job_hang_limit", that
way a bad command stream will not infinitly cause GPU hang.

by default this threshold is 1 so a job will be kicked out
after it hang.

2,if a job timeout TDR routine will not reset all sched/ring,
instead if will only reset on the givn one which is indicated
by @job of amdgpu_sriov_gpu_reset, that way we don't need to
reset and recover each sched/ring if we already know which job
cause GPU hang.

3,unblock sriov_gpu_reset for AI family.

V2:
1:put kickout guilty job after sched parked.
2:since parking scheduler prior to kickout already occupies a
while, we can do last check on the in question job before
doing hw_reset.

TODO:
1:when a job is considered as guilty, we should mark some flag
in its fence status flag, and let UMD side aware that this
fence signaling is not due to job complete but job hang.

2:if gpu reset cause all video memory lost, we need introduce
a new policy to implement TDR, like drop all jobs not yet
signaled, and all IOCTL on this device will return ERROR
DEVICE_LOST.
this will be implemented later.
Signed-off-by: default avatarMonk Liu <Monk.Liu@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 75fbed20
...@@ -109,6 +109,7 @@ extern int amdgpu_prim_buf_per_se; ...@@ -109,6 +109,7 @@ extern int amdgpu_prim_buf_per_se;
extern int amdgpu_pos_buf_per_se; extern int amdgpu_pos_buf_per_se;
extern int amdgpu_cntl_sb_buf_per_se; extern int amdgpu_cntl_sb_buf_per_se;
extern int amdgpu_param_buf_per_se; extern int amdgpu_param_buf_per_se;
extern int amdgpu_job_hang_limit;
#define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL /* 3GB by default */ #define AMDGPU_DEFAULT_GTT_SIZE_MB 3072ULL /* 3GB by default */
#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000 #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
......
...@@ -2617,7 +2617,7 @@ static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev, ...@@ -2617,7 +2617,7 @@ static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
*/ */
int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, struct amdgpu_job *job) int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, struct amdgpu_job *job)
{ {
int i, r = 0; int i, j, r = 0;
int resched; int resched;
struct amdgpu_bo *bo, *tmp; struct amdgpu_bo *bo, *tmp;
struct amdgpu_ring *ring; struct amdgpu_ring *ring;
...@@ -2630,19 +2630,36 @@ int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, struct amdgpu_job *job) ...@@ -2630,19 +2630,36 @@ int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, struct amdgpu_job *job)
/* block TTM */ /* block TTM */
resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev); resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
/* block scheduler */ /* we start from the ring trigger GPU hang */
for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { j = job ? job->ring->idx : 0;
ring = adev->rings[i];
/* block scheduler */
for (i = j; i < j + AMDGPU_MAX_RINGS; ++i) {
ring = adev->rings[i % AMDGPU_MAX_RINGS];
if (!ring || !ring->sched.thread) if (!ring || !ring->sched.thread)
continue; continue;
kthread_park(ring->sched.thread); kthread_park(ring->sched.thread);
if (job && j != i)
continue;
/* here give the last chance to check if fence signaled
* since we already pay some time on kthread_park */
if (job && dma_fence_is_signaled(&job->base.s_fence->finished)) {
kthread_unpark(ring->sched.thread);
goto give_up_reset;
}
if (amd_sched_invalidate_job(&job->base, amdgpu_job_hang_limit))
amd_sched_job_kickout(&job->base);
/* only do job_reset on the hang ring if @job not NULL */
amd_sched_hw_job_reset(&ring->sched); amd_sched_hw_job_reset(&ring->sched);
}
/* after all hw jobs are reset, hw fence is meaningless, so force_completion */ /* after all hw jobs are reset, hw fence is meaningless, so force_completion */
amdgpu_fence_driver_force_completion(adev); amdgpu_fence_driver_force_completion_ring(ring);
}
/* request to take full control of GPU before re-initialization */ /* request to take full control of GPU before re-initialization */
if (job) if (job)
...@@ -2695,20 +2712,28 @@ int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, struct amdgpu_job *job) ...@@ -2695,20 +2712,28 @@ int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, struct amdgpu_job *job)
} }
dma_fence_put(fence); dma_fence_put(fence);
for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { for (i = j; i < j + AMDGPU_MAX_RINGS; ++i) {
struct amdgpu_ring *ring = adev->rings[i]; ring = adev->rings[i % AMDGPU_MAX_RINGS];
if (!ring || !ring->sched.thread) if (!ring || !ring->sched.thread)
continue; continue;
if (job && j != i) {
kthread_unpark(ring->sched.thread);
continue;
}
amd_sched_job_recovery(&ring->sched); amd_sched_job_recovery(&ring->sched);
kthread_unpark(ring->sched.thread); kthread_unpark(ring->sched.thread);
} }
drm_helper_resume_force_mode(adev->ddev); drm_helper_resume_force_mode(adev->ddev);
give_up_reset:
ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched); ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
if (r) { if (r) {
/* bad news, how to tell it to userspace ? */ /* bad news, how to tell it to userspace ? */
dev_info(adev->dev, "GPU reset failed\n"); dev_info(adev->dev, "GPU reset failed\n");
} else {
dev_info(adev->dev, "GPU reset successed!\n");
} }
adev->gfx.in_reset = false; adev->gfx.in_reset = false;
......
...@@ -111,6 +111,7 @@ int amdgpu_prim_buf_per_se = 0; ...@@ -111,6 +111,7 @@ int amdgpu_prim_buf_per_se = 0;
int amdgpu_pos_buf_per_se = 0; int amdgpu_pos_buf_per_se = 0;
int amdgpu_cntl_sb_buf_per_se = 0; int amdgpu_cntl_sb_buf_per_se = 0;
int amdgpu_param_buf_per_se = 0; int amdgpu_param_buf_per_se = 0;
int amdgpu_job_hang_limit = 0;
MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing, in megabytes"); MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing, in megabytes");
module_param_named(vramlimit, amdgpu_vram_limit, int, 0600); module_param_named(vramlimit, amdgpu_vram_limit, int, 0600);
...@@ -233,6 +234,9 @@ module_param_named(cntl_sb_buf_per_se, amdgpu_cntl_sb_buf_per_se, int, 0444); ...@@ -233,6 +234,9 @@ module_param_named(cntl_sb_buf_per_se, amdgpu_cntl_sb_buf_per_se, int, 0444);
MODULE_PARM_DESC(param_buf_per_se, "the size of Off-Chip Pramater Cache per Shader Engine (default depending on gfx)"); MODULE_PARM_DESC(param_buf_per_se, "the size of Off-Chip Pramater Cache per Shader Engine (default depending on gfx)");
module_param_named(param_buf_per_se, amdgpu_param_buf_per_se, int, 0444); module_param_named(param_buf_per_se, amdgpu_param_buf_per_se, int, 0444);
MODULE_PARM_DESC(job_hang_limit, "how much time allow a job hang and not drop it (default 0)");
module_param_named(job_hang_limit, amdgpu_job_hang_limit, int ,0444);
static const struct pci_device_id pciidlist[] = { static const struct pci_device_id pciidlist[] = {
#ifdef CONFIG_DRM_AMDGPU_SI #ifdef CONFIG_DRM_AMDGPU_SI
......
...@@ -541,6 +541,12 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev) ...@@ -541,6 +541,12 @@ void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev)
} }
} }
void amdgpu_fence_driver_force_completion_ring(struct amdgpu_ring *ring)
{
if (ring)
amdgpu_fence_write(ring, ring->fence_drv.sync_seq);
}
/* /*
* Common fence implementation * Common fence implementation
*/ */
......
...@@ -76,6 +76,7 @@ struct amdgpu_fence_driver { ...@@ -76,6 +76,7 @@ struct amdgpu_fence_driver {
int amdgpu_fence_driver_init(struct amdgpu_device *adev); int amdgpu_fence_driver_init(struct amdgpu_device *adev);
void amdgpu_fence_driver_fini(struct amdgpu_device *adev); void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev); void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
void amdgpu_fence_driver_force_completion_ring(struct amdgpu_ring *ring);
int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
unsigned num_hw_submission); unsigned num_hw_submission);
......
...@@ -409,9 +409,18 @@ void amd_sched_hw_job_reset(struct amd_gpu_scheduler *sched) ...@@ -409,9 +409,18 @@ void amd_sched_hw_job_reset(struct amd_gpu_scheduler *sched)
&s_job->s_fence->cb)) { &s_job->s_fence->cb)) {
dma_fence_put(s_job->s_fence->parent); dma_fence_put(s_job->s_fence->parent);
s_job->s_fence->parent = NULL; s_job->s_fence->parent = NULL;
atomic_dec(&sched->hw_rq_count);
} }
} }
atomic_set(&sched->hw_rq_count, 0); spin_unlock(&sched->job_list_lock);
}
void amd_sched_job_kickout(struct amd_sched_job *s_job)
{
struct amd_gpu_scheduler *sched = s_job->sched;
spin_lock(&sched->job_list_lock);
list_del_init(&s_job->node);
spin_unlock(&sched->job_list_lock); spin_unlock(&sched->job_list_lock);
} }
......
...@@ -81,6 +81,7 @@ struct amd_sched_job { ...@@ -81,6 +81,7 @@ struct amd_sched_job {
struct list_head node; struct list_head node;
struct delayed_work work_tdr; struct delayed_work work_tdr;
uint64_t id; uint64_t id;
atomic_t karma;
}; };
extern const struct dma_fence_ops amd_sched_fence_ops_scheduled; extern const struct dma_fence_ops amd_sched_fence_ops_scheduled;
...@@ -96,6 +97,11 @@ static inline struct amd_sched_fence *to_amd_sched_fence(struct dma_fence *f) ...@@ -96,6 +97,11 @@ static inline struct amd_sched_fence *to_amd_sched_fence(struct dma_fence *f)
return NULL; return NULL;
} }
static inline bool amd_sched_invalidate_job(struct amd_sched_job *s_job, int threshold)
{
return (s_job && atomic_inc_return(&s_job->karma) > threshold);
}
/** /**
* Define the backend operations called by the scheduler, * Define the backend operations called by the scheduler,
* these functions should be implemented in driver side * these functions should be implemented in driver side
...@@ -160,4 +166,5 @@ void amd_sched_hw_job_reset(struct amd_gpu_scheduler *sched); ...@@ -160,4 +166,5 @@ void amd_sched_hw_job_reset(struct amd_gpu_scheduler *sched);
void amd_sched_job_recovery(struct amd_gpu_scheduler *sched); void amd_sched_job_recovery(struct amd_gpu_scheduler *sched);
bool amd_sched_dependency_optimized(struct dma_fence* fence, bool amd_sched_dependency_optimized(struct dma_fence* fence,
struct amd_sched_entity *entity); struct amd_sched_entity *entity);
void amd_sched_job_kickout(struct amd_sched_job *s_job);
#endif #endif
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