Commit bb2d2128 authored by Felix Kuehling's avatar Felix Kuehling Committed by Alex Deucher

drm/amdkfd: Simplify eviction state logic

Always mark evicted queues with q->properties.is_evicted = true, even
queues that are inactive for other reason. This simplifies maintaining
the eviction state as it doesn't require updating is_evicted when other
queue activation conditions change.

On the other hand, we now need to check those other queue activation
conditions whenever an evicted queues is restored. To minimize code
duplication, move the queue activation check into a macro so it can be
maintained in one central place.
Signed-off-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: default avatarPhilip Cox <Philip.Cox@amd.com>
Acked-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 052af915
...@@ -289,13 +289,11 @@ static int create_queue_nocpsch(struct device_queue_manager *dqm, ...@@ -289,13 +289,11 @@ static int create_queue_nocpsch(struct device_queue_manager *dqm,
} }
q->properties.vmid = qpd->vmid; q->properties.vmid = qpd->vmid;
/* /*
* Eviction state logic: we only mark active queues as evicted * Eviction state logic: mark all queues as evicted, even ones
* to avoid the overhead of restoring inactive queues later * not currently active. Restoring inactive queues later only
* updates the is_evicted flag but is a no-op otherwise.
*/ */
if (qpd->evicted) q->properties.is_evicted = !!qpd->evicted;
q->properties.is_evicted = (q->properties.queue_size > 0 &&
q->properties.queue_percent > 0 &&
q->properties.queue_address != 0);
q->properties.tba_addr = qpd->tba_addr; q->properties.tba_addr = qpd->tba_addr;
q->properties.tma_addr = qpd->tma_addr; q->properties.tma_addr = qpd->tma_addr;
...@@ -518,14 +516,6 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q) ...@@ -518,14 +516,6 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q)
} }
mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type( mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
q->properties.type)]; q->properties.type)];
/*
* Eviction state logic: we only mark active queues as evicted
* to avoid the overhead of restoring inactive queues later
*/
if (pdd->qpd.evicted)
q->properties.is_evicted = (q->properties.queue_size > 0 &&
q->properties.queue_percent > 0 &&
q->properties.queue_address != 0);
/* Save previous activity state for counters */ /* Save previous activity state for counters */
prev_active = q->properties.is_active; prev_active = q->properties.is_active;
...@@ -590,7 +580,7 @@ static int evict_process_queues_nocpsch(struct device_queue_manager *dqm, ...@@ -590,7 +580,7 @@ static int evict_process_queues_nocpsch(struct device_queue_manager *dqm,
struct queue *q; struct queue *q;
struct mqd_manager *mqd_mgr; struct mqd_manager *mqd_mgr;
struct kfd_process_device *pdd; struct kfd_process_device *pdd;
int retval = 0; int retval, ret = 0;
dqm_lock(dqm); dqm_lock(dqm);
if (qpd->evicted++ > 0) /* already evicted, do nothing */ if (qpd->evicted++ > 0) /* already evicted, do nothing */
...@@ -600,25 +590,31 @@ static int evict_process_queues_nocpsch(struct device_queue_manager *dqm, ...@@ -600,25 +590,31 @@ static int evict_process_queues_nocpsch(struct device_queue_manager *dqm,
pr_info_ratelimited("Evicting PASID %u queues\n", pr_info_ratelimited("Evicting PASID %u queues\n",
pdd->process->pasid); pdd->process->pasid);
/* unactivate all active queues on the qpd */ /* Mark all queues as evicted. Deactivate all active queues on
* the qpd.
*/
list_for_each_entry(q, &qpd->queues_list, list) { list_for_each_entry(q, &qpd->queues_list, list) {
q->properties.is_evicted = true;
if (!q->properties.is_active) if (!q->properties.is_active)
continue; continue;
mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type( mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
q->properties.type)]; q->properties.type)];
q->properties.is_evicted = true;
q->properties.is_active = false; q->properties.is_active = false;
retval = mqd_mgr->destroy_mqd(mqd_mgr, q->mqd, retval = mqd_mgr->destroy_mqd(mqd_mgr, q->mqd,
KFD_PREEMPT_TYPE_WAVEFRONT_DRAIN, KFD_PREEMPT_TYPE_WAVEFRONT_DRAIN,
KFD_UNMAP_LATENCY_MS, q->pipe, q->queue); KFD_UNMAP_LATENCY_MS, q->pipe, q->queue);
if (retval) if (retval && !ret)
goto out; /* Return the first error, but keep going to
* maintain a consistent eviction state
*/
ret = retval;
dqm->queue_count--; dqm->queue_count--;
} }
out: out:
dqm_unlock(dqm); dqm_unlock(dqm);
return retval; return ret;
} }
static int evict_process_queues_cpsch(struct device_queue_manager *dqm, static int evict_process_queues_cpsch(struct device_queue_manager *dqm,
...@@ -636,11 +632,14 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm, ...@@ -636,11 +632,14 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm,
pr_info_ratelimited("Evicting PASID %u queues\n", pr_info_ratelimited("Evicting PASID %u queues\n",
pdd->process->pasid); pdd->process->pasid);
/* unactivate all active queues on the qpd */ /* Mark all queues as evicted. Deactivate all active queues on
* the qpd.
*/
list_for_each_entry(q, &qpd->queues_list, list) { list_for_each_entry(q, &qpd->queues_list, list) {
q->properties.is_evicted = true;
if (!q->properties.is_active) if (!q->properties.is_active)
continue; continue;
q->properties.is_evicted = true;
q->properties.is_active = false; q->properties.is_active = false;
dqm->queue_count--; dqm->queue_count--;
} }
...@@ -662,7 +661,7 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm, ...@@ -662,7 +661,7 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm,
struct mqd_manager *mqd_mgr; struct mqd_manager *mqd_mgr;
struct kfd_process_device *pdd; struct kfd_process_device *pdd;
uint64_t pd_base; uint64_t pd_base;
int retval = 0; int retval, ret = 0;
pdd = qpd_to_pdd(qpd); pdd = qpd_to_pdd(qpd);
/* Retrieve PD base */ /* Retrieve PD base */
...@@ -696,22 +695,28 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm, ...@@ -696,22 +695,28 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm,
*/ */
mm = get_task_mm(pdd->process->lead_thread); mm = get_task_mm(pdd->process->lead_thread);
if (!mm) { if (!mm) {
retval = -EFAULT; ret = -EFAULT;
goto out; goto out;
} }
/* activate all active queues on the qpd */ /* Remove the eviction flags. Activate queues that are not
* inactive for other reasons.
*/
list_for_each_entry(q, &qpd->queues_list, list) { list_for_each_entry(q, &qpd->queues_list, list) {
if (!q->properties.is_evicted) q->properties.is_evicted = false;
if (!QUEUE_IS_ACTIVE(q->properties))
continue; continue;
mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type( mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
q->properties.type)]; q->properties.type)];
q->properties.is_evicted = false;
q->properties.is_active = true; q->properties.is_active = true;
retval = mqd_mgr->load_mqd(mqd_mgr, q->mqd, q->pipe, retval = mqd_mgr->load_mqd(mqd_mgr, q->mqd, q->pipe,
q->queue, &q->properties, mm); q->queue, &q->properties, mm);
if (retval) if (retval && !ret)
goto out; /* Return the first error, but keep going to
* maintain a consistent eviction state
*/
ret = retval;
dqm->queue_count++; dqm->queue_count++;
} }
qpd->evicted = 0; qpd->evicted = 0;
...@@ -719,7 +724,7 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm, ...@@ -719,7 +724,7 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm,
if (mm) if (mm)
mmput(mm); mmput(mm);
dqm_unlock(dqm); dqm_unlock(dqm);
return retval; return ret;
} }
static int restore_process_queues_cpsch(struct device_queue_manager *dqm, static int restore_process_queues_cpsch(struct device_queue_manager *dqm,
...@@ -751,16 +756,16 @@ static int restore_process_queues_cpsch(struct device_queue_manager *dqm, ...@@ -751,16 +756,16 @@ static int restore_process_queues_cpsch(struct device_queue_manager *dqm,
/* activate all active queues on the qpd */ /* activate all active queues on the qpd */
list_for_each_entry(q, &qpd->queues_list, list) { list_for_each_entry(q, &qpd->queues_list, list) {
if (!q->properties.is_evicted)
continue;
q->properties.is_evicted = false; q->properties.is_evicted = false;
if (!QUEUE_IS_ACTIVE(q->properties))
continue;
q->properties.is_active = true; q->properties.is_active = true;
dqm->queue_count++; dqm->queue_count++;
} }
retval = execute_queues_cpsch(dqm, retval = execute_queues_cpsch(dqm,
KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0); KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0);
if (!retval) qpd->evicted = 0;
qpd->evicted = 0;
out: out:
dqm_unlock(dqm); dqm_unlock(dqm);
return retval; return retval;
...@@ -1199,13 +1204,12 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q, ...@@ -1199,13 +1204,12 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type( mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
q->properties.type)]; q->properties.type)];
/* /*
* Eviction state logic: we only mark active queues as evicted * Eviction state logic: mark all queues as evicted, even ones
* to avoid the overhead of restoring inactive queues later * not currently active. Restoring inactive queues later only
* updates the is_evicted flag but is a no-op otherwise.
*/ */
if (qpd->evicted) q->properties.is_evicted = !!qpd->evicted;
q->properties.is_evicted = (q->properties.queue_size > 0 &&
q->properties.queue_percent > 0 &&
q->properties.queue_address != 0);
dqm->asic_ops.init_sdma_vm(dqm, q, qpd); dqm->asic_ops.init_sdma_vm(dqm, q, qpd);
q->properties.tba_addr = qpd->tba_addr; q->properties.tba_addr = qpd->tba_addr;
q->properties.tma_addr = qpd->tma_addr; q->properties.tma_addr = qpd->tma_addr;
......
...@@ -231,10 +231,7 @@ static int __update_mqd(struct mqd_manager *mm, void *mqd, ...@@ -231,10 +231,7 @@ static int __update_mqd(struct mqd_manager *mm, void *mqd,
update_cu_mask(mm, mqd, q); update_cu_mask(mm, mqd, q);
q->is_active = (q->queue_size > 0 && q->is_active = QUEUE_IS_ACTIVE(*q);
q->queue_address != 0 &&
q->queue_percent > 0 &&
!q->is_evicted);
return 0; return 0;
} }
...@@ -275,10 +272,7 @@ static int update_mqd_sdma(struct mqd_manager *mm, void *mqd, ...@@ -275,10 +272,7 @@ static int update_mqd_sdma(struct mqd_manager *mm, void *mqd,
m->sdma_engine_id = q->sdma_engine_id; m->sdma_engine_id = q->sdma_engine_id;
m->sdma_queue_id = q->sdma_queue_id; m->sdma_queue_id = q->sdma_queue_id;
q->is_active = (q->queue_size > 0 && q->is_active = QUEUE_IS_ACTIVE(*q);
q->queue_address != 0 &&
q->queue_percent > 0 &&
!q->is_evicted);
return 0; return 0;
} }
...@@ -358,10 +352,7 @@ static int update_mqd_hiq(struct mqd_manager *mm, void *mqd, ...@@ -358,10 +352,7 @@ static int update_mqd_hiq(struct mqd_manager *mm, void *mqd,
m->cp_hqd_vmid = q->vmid; m->cp_hqd_vmid = q->vmid;
q->is_active = (q->queue_size > 0 && q->is_active = QUEUE_IS_ACTIVE(*q);
q->queue_address != 0 &&
q->queue_percent > 0 &&
!q->is_evicted);
return 0; return 0;
} }
......
...@@ -247,10 +247,7 @@ static int update_mqd(struct mqd_manager *mm, void *mqd, ...@@ -247,10 +247,7 @@ static int update_mqd(struct mqd_manager *mm, void *mqd,
update_cu_mask(mm, mqd, q); update_cu_mask(mm, mqd, q);
q->is_active = (q->queue_size > 0 && q->is_active = QUEUE_IS_ACTIVE(*q);
q->queue_address != 0 &&
q->queue_percent > 0 &&
!q->is_evicted);
return 0; return 0;
} }
...@@ -402,10 +399,7 @@ static int update_mqd_sdma(struct mqd_manager *mm, void *mqd, ...@@ -402,10 +399,7 @@ static int update_mqd_sdma(struct mqd_manager *mm, void *mqd,
m->sdma_queue_id = q->sdma_queue_id; m->sdma_queue_id = q->sdma_queue_id;
m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT; m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT;
q->is_active = (q->queue_size > 0 && q->is_active = QUEUE_IS_ACTIVE(*q);
q->queue_address != 0 &&
q->queue_percent > 0 &&
!q->is_evicted);
return 0; return 0;
} }
......
...@@ -238,10 +238,7 @@ static int __update_mqd(struct mqd_manager *mm, void *mqd, ...@@ -238,10 +238,7 @@ static int __update_mqd(struct mqd_manager *mm, void *mqd,
update_cu_mask(mm, mqd, q); update_cu_mask(mm, mqd, q);
q->is_active = (q->queue_size > 0 && q->is_active = QUEUE_IS_ACTIVE(*q);
q->queue_address != 0 &&
q->queue_percent > 0 &&
!q->is_evicted);
return 0; return 0;
} }
...@@ -396,10 +393,7 @@ static int update_mqd_sdma(struct mqd_manager *mm, void *mqd, ...@@ -396,10 +393,7 @@ static int update_mqd_sdma(struct mqd_manager *mm, void *mqd,
m->sdma_engine_id = q->sdma_engine_id; m->sdma_engine_id = q->sdma_engine_id;
m->sdma_queue_id = q->sdma_queue_id; m->sdma_queue_id = q->sdma_queue_id;
q->is_active = (q->queue_size > 0 && q->is_active = QUEUE_IS_ACTIVE(*q);
q->queue_address != 0 &&
q->queue_percent > 0 &&
!q->is_evicted);
return 0; return 0;
} }
......
...@@ -430,6 +430,11 @@ struct queue_properties { ...@@ -430,6 +430,11 @@ struct queue_properties {
uint32_t *cu_mask; uint32_t *cu_mask;
}; };
#define QUEUE_IS_ACTIVE(q) ((q).queue_size > 0 && \
(q).queue_address != 0 && \
(q).queue_percent > 0 && \
!(q).is_evicted)
/** /**
* struct queue * struct queue
* *
......
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