Commit fdfa090b authored by Oak Zeng's avatar Oak Zeng Committed by Alex Deucher

drm/amdkfd: Init mqd managers in device queue manager init

Previously mqd managers was initialized on demand. As there
are only a few type of mqd managers, the on demand initialization
doesn't save too much memory. Initialize them on device
queue initialization instead and delete the get_mqd_manager
interface. This makes codes more organized for future changes.
Signed-off-by: default avatarOak Zeng <ozeng@amd.com>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 59f650a0
...@@ -368,9 +368,7 @@ static int create_compute_queue_nocpsch(struct device_queue_manager *dqm, ...@@ -368,9 +368,7 @@ static int create_compute_queue_nocpsch(struct device_queue_manager *dqm,
struct mqd_manager *mqd_mgr; struct mqd_manager *mqd_mgr;
int retval; int retval;
mqd_mgr = dqm->ops.get_mqd_manager(dqm, KFD_MQD_TYPE_COMPUTE); mqd_mgr = dqm->mqd_mgrs[KFD_MQD_TYPE_COMPUTE];
if (!mqd_mgr)
return -ENOMEM;
retval = allocate_hqd(dqm, q); retval = allocate_hqd(dqm, q);
if (retval) if (retval)
...@@ -425,10 +423,8 @@ static int destroy_queue_nocpsch_locked(struct device_queue_manager *dqm, ...@@ -425,10 +423,8 @@ static int destroy_queue_nocpsch_locked(struct device_queue_manager *dqm,
int retval; int retval;
struct mqd_manager *mqd_mgr; struct mqd_manager *mqd_mgr;
mqd_mgr = dqm->ops.get_mqd_manager(dqm, mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
get_mqd_type_from_queue_type(q->properties.type)); q->properties.type)];
if (!mqd_mgr)
return -ENOMEM;
if (q->properties.type == KFD_QUEUE_TYPE_COMPUTE) { if (q->properties.type == KFD_QUEUE_TYPE_COMPUTE) {
deallocate_hqd(dqm, q); deallocate_hqd(dqm, q);
...@@ -501,12 +497,8 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q) ...@@ -501,12 +497,8 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q)
retval = -ENODEV; retval = -ENODEV;
goto out_unlock; goto out_unlock;
} }
mqd_mgr = dqm->ops.get_mqd_manager(dqm, mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
get_mqd_type_from_queue_type(q->properties.type)); q->properties.type)];
if (!mqd_mgr) {
retval = -ENOMEM;
goto out_unlock;
}
/* /*
* Eviction state logic: we only mark active queues as evicted * Eviction state logic: we only mark active queues as evicted
* to avoid the overhead of restoring inactive queues later * to avoid the overhead of restoring inactive queues later
...@@ -571,27 +563,6 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q) ...@@ -571,27 +563,6 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q)
return retval; return retval;
} }
static struct mqd_manager *get_mqd_manager(
struct device_queue_manager *dqm, enum KFD_MQD_TYPE type)
{
struct mqd_manager *mqd_mgr;
if (WARN_ON(type >= KFD_MQD_TYPE_MAX))
return NULL;
pr_debug("mqd type %d\n", type);
mqd_mgr = dqm->mqd_mgrs[type];
if (!mqd_mgr) {
mqd_mgr = dqm->asic_ops.mqd_manager_init(type, dqm->dev);
if (!mqd_mgr)
pr_err("mqd manager is NULL");
dqm->mqd_mgrs[type] = mqd_mgr;
}
return mqd_mgr;
}
static int evict_process_queues_nocpsch(struct device_queue_manager *dqm, static int evict_process_queues_nocpsch(struct device_queue_manager *dqm,
struct qcm_process_device *qpd) struct qcm_process_device *qpd)
{ {
...@@ -612,13 +583,8 @@ static int evict_process_queues_nocpsch(struct device_queue_manager *dqm, ...@@ -612,13 +583,8 @@ static int evict_process_queues_nocpsch(struct device_queue_manager *dqm,
list_for_each_entry(q, &qpd->queues_list, list) { list_for_each_entry(q, &qpd->queues_list, list) {
if (!q->properties.is_active) if (!q->properties.is_active)
continue; continue;
mqd_mgr = dqm->ops.get_mqd_manager(dqm, mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
get_mqd_type_from_queue_type(q->properties.type)); q->properties.type)];
if (!mqd_mgr) { /* should not be here */
pr_err("Cannot evict queue, mqd mgr is NULL\n");
retval = -ENOMEM;
goto out;
}
q->properties.is_evicted = true; 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,
...@@ -717,13 +683,8 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm, ...@@ -717,13 +683,8 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm,
list_for_each_entry(q, &qpd->queues_list, list) { list_for_each_entry(q, &qpd->queues_list, list) {
if (!q->properties.is_evicted) if (!q->properties.is_evicted)
continue; continue;
mqd_mgr = dqm->ops.get_mqd_manager(dqm, mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
get_mqd_type_from_queue_type(q->properties.type)); q->properties.type)];
if (!mqd_mgr) { /* should not be here */
pr_err("Cannot restore queue, mqd mgr is NULL\n");
retval = -ENOMEM;
goto out;
}
q->properties.is_evicted = false; 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,
...@@ -950,9 +911,7 @@ static int create_sdma_queue_nocpsch(struct device_queue_manager *dqm, ...@@ -950,9 +911,7 @@ static int create_sdma_queue_nocpsch(struct device_queue_manager *dqm,
struct mqd_manager *mqd_mgr; struct mqd_manager *mqd_mgr;
int retval; int retval;
mqd_mgr = dqm->ops.get_mqd_manager(dqm, KFD_MQD_TYPE_SDMA); mqd_mgr = dqm->mqd_mgrs[KFD_MQD_TYPE_SDMA];
if (!mqd_mgr)
return -ENOMEM;
retval = allocate_sdma_queue(dqm, &q->sdma_id); retval = allocate_sdma_queue(dqm, &q->sdma_id);
if (retval) if (retval)
...@@ -1185,17 +1144,8 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q, ...@@ -1185,17 +1144,8 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
if (retval) if (retval)
goto out_deallocate_sdma_queue; goto out_deallocate_sdma_queue;
/* Do init_mqd before dqm_lock(dqm) to avoid circular locking order: mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
* lock(dqm) -> bo::reserve q->properties.type)];
*/
mqd_mgr = dqm->ops.get_mqd_manager(dqm,
get_mqd_type_from_queue_type(q->properties.type));
if (!mqd_mgr) {
retval = -ENOMEM;
goto out_deallocate_doorbell;
}
/* /*
* Eviction state logic: we only mark active queues as evicted * Eviction state logic: we only mark active queues as evicted
* to avoid the overhead of restoring inactive queues later * to avoid the overhead of restoring inactive queues later
...@@ -1380,12 +1330,8 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm, ...@@ -1380,12 +1330,8 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm,
} }
mqd_mgr = dqm->ops.get_mqd_manager(dqm, mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
get_mqd_type_from_queue_type(q->properties.type)); q->properties.type)];
if (!mqd_mgr) {
retval = -ENOMEM;
goto failed;
}
deallocate_doorbell(qpd, q); deallocate_doorbell(qpd, q);
...@@ -1419,7 +1365,6 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm, ...@@ -1419,7 +1365,6 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm,
return retval; return retval;
failed:
failed_try_destroy_debugged_queue: failed_try_destroy_debugged_queue:
dqm_unlock(dqm); dqm_unlock(dqm);
...@@ -1566,11 +1511,7 @@ static int get_wave_state(struct device_queue_manager *dqm, ...@@ -1566,11 +1511,7 @@ static int get_wave_state(struct device_queue_manager *dqm,
goto dqm_unlock; goto dqm_unlock;
} }
mqd_mgr = dqm->ops.get_mqd_manager(dqm, KFD_MQD_TYPE_COMPUTE); mqd_mgr = dqm->mqd_mgrs[KFD_MQD_TYPE_COMPUTE];
if (!mqd_mgr) {
r = -ENOMEM;
goto dqm_unlock;
}
if (!mqd_mgr->get_wave_state) { if (!mqd_mgr->get_wave_state) {
r = -EINVAL; r = -EINVAL;
...@@ -1646,21 +1587,40 @@ static int process_termination_cpsch(struct device_queue_manager *dqm, ...@@ -1646,21 +1587,40 @@ static int process_termination_cpsch(struct device_queue_manager *dqm,
* Do uninit_mqd() after dqm_unlock to avoid circular locking. * Do uninit_mqd() after dqm_unlock to avoid circular locking.
*/ */
list_for_each_entry_safe(q, next, &qpd->queues_list, list) { list_for_each_entry_safe(q, next, &qpd->queues_list, list) {
mqd_mgr = dqm->ops.get_mqd_manager(dqm, mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
get_mqd_type_from_queue_type(q->properties.type)); q->properties.type)];
if (!mqd_mgr) {
retval = -ENOMEM;
goto out;
}
list_del(&q->list); list_del(&q->list);
qpd->queue_count--; qpd->queue_count--;
mqd_mgr->uninit_mqd(mqd_mgr, q->mqd, q->mqd_mem_obj); mqd_mgr->uninit_mqd(mqd_mgr, q->mqd, q->mqd_mem_obj);
} }
out:
return retval; return retval;
} }
static int init_mqd_managers(struct device_queue_manager *dqm)
{
int i, j;
struct mqd_manager *mqd_mgr;
for (i = 0; i < KFD_MQD_TYPE_MAX; i++) {
mqd_mgr = dqm->asic_ops.mqd_manager_init(i, dqm->dev);
if (!mqd_mgr) {
pr_err("mqd manager [%d] initialization failed\n", i);
goto out_free;
}
dqm->mqd_mgrs[i] = mqd_mgr;
}
return 0;
out_free:
for (j = 0; j < i; j++) {
kfree(dqm->mqd_mgrs[j]);
dqm->mqd_mgrs[j] = NULL;
}
return -ENOMEM;
}
struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev) struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev)
{ {
struct device_queue_manager *dqm; struct device_queue_manager *dqm;
...@@ -1698,7 +1658,6 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev) ...@@ -1698,7 +1658,6 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev)
dqm->ops.stop = stop_cpsch; dqm->ops.stop = stop_cpsch;
dqm->ops.destroy_queue = destroy_queue_cpsch; dqm->ops.destroy_queue = destroy_queue_cpsch;
dqm->ops.update_queue = update_queue; dqm->ops.update_queue = update_queue;
dqm->ops.get_mqd_manager = get_mqd_manager;
dqm->ops.register_process = register_process; dqm->ops.register_process = register_process;
dqm->ops.unregister_process = unregister_process; dqm->ops.unregister_process = unregister_process;
dqm->ops.uninitialize = uninitialize; dqm->ops.uninitialize = uninitialize;
...@@ -1718,7 +1677,6 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev) ...@@ -1718,7 +1677,6 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev)
dqm->ops.create_queue = create_queue_nocpsch; dqm->ops.create_queue = create_queue_nocpsch;
dqm->ops.destroy_queue = destroy_queue_nocpsch; dqm->ops.destroy_queue = destroy_queue_nocpsch;
dqm->ops.update_queue = update_queue; dqm->ops.update_queue = update_queue;
dqm->ops.get_mqd_manager = get_mqd_manager;
dqm->ops.register_process = register_process; dqm->ops.register_process = register_process;
dqm->ops.unregister_process = unregister_process; dqm->ops.unregister_process = unregister_process;
dqm->ops.initialize = initialize_nocpsch; dqm->ops.initialize = initialize_nocpsch;
...@@ -1769,6 +1727,9 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev) ...@@ -1769,6 +1727,9 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev)
goto out_free; goto out_free;
} }
if (init_mqd_managers(dqm))
goto out_free;
if (!dqm->ops.initialize(dqm)) if (!dqm->ops.initialize(dqm))
return dqm; return dqm;
......
...@@ -48,8 +48,6 @@ struct device_process_node { ...@@ -48,8 +48,6 @@ struct device_process_node {
* *
* @update_queue: Queue update routine. * @update_queue: Queue update routine.
* *
* @get_mqd_manager: Returns the mqd manager according to the mqd type.
*
* @exeute_queues: Dispatches the queues list to the H/W. * @exeute_queues: Dispatches the queues list to the H/W.
* *
* @register_process: This routine associates a specific process with device. * @register_process: This routine associates a specific process with device.
...@@ -97,10 +95,6 @@ struct device_queue_manager_ops { ...@@ -97,10 +95,6 @@ struct device_queue_manager_ops {
int (*update_queue)(struct device_queue_manager *dqm, int (*update_queue)(struct device_queue_manager *dqm,
struct queue *q); struct queue *q);
struct mqd_manager * (*get_mqd_manager)
(struct device_queue_manager *dqm,
enum KFD_MQD_TYPE type);
int (*register_process)(struct device_queue_manager *dqm, int (*register_process)(struct device_queue_manager *dqm,
struct qcm_process_device *qpd); struct qcm_process_device *qpd);
......
...@@ -58,12 +58,10 @@ static bool initialize(struct kernel_queue *kq, struct kfd_dev *dev, ...@@ -58,12 +58,10 @@ static bool initialize(struct kernel_queue *kq, struct kfd_dev *dev,
kq->nop_packet = nop.u32all; kq->nop_packet = nop.u32all;
switch (type) { switch (type) {
case KFD_QUEUE_TYPE_DIQ: case KFD_QUEUE_TYPE_DIQ:
kq->mqd_mgr = dev->dqm->ops.get_mqd_manager(dev->dqm, kq->mqd_mgr = dev->dqm->mqd_mgrs[KFD_MQD_TYPE_DIQ];
KFD_MQD_TYPE_DIQ);
break; break;
case KFD_QUEUE_TYPE_HIQ: case KFD_QUEUE_TYPE_HIQ:
kq->mqd_mgr = dev->dqm->ops.get_mqd_manager(dev->dqm, kq->mqd_mgr = dev->dqm->mqd_mgrs[KFD_MQD_TYPE_HIQ];
KFD_MQD_TYPE_HIQ);
break; break;
default: default:
pr_err("Invalid queue type %d\n", type); pr_err("Invalid queue type %d\n", type);
......
...@@ -461,8 +461,7 @@ int pqm_debugfs_mqds(struct seq_file *m, void *data) ...@@ -461,8 +461,7 @@ int pqm_debugfs_mqds(struct seq_file *m, void *data)
q->properties.type, q->device->id); q->properties.type, q->device->id);
continue; continue;
} }
mqd_mgr = q->device->dqm->ops.get_mqd_manager( mqd_mgr = q->device->dqm->mqd_mgrs[mqd_type];
q->device->dqm, mqd_type);
} else if (pqn->kq) { } else if (pqn->kq) {
q = pqn->kq->queue; q = pqn->kq->queue;
mqd_mgr = pqn->kq->mqd_mgr; mqd_mgr = pqn->kq->mqd_mgr;
......
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