drm/amdkfd: Init mqd managers in device queue manager init
authorOak Zeng <ozeng@amd.com>
Wed, 5 Dec 2018 16:15:27 +0000 (10:15 -0600)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 24 May 2019 17:21:02 +0000 (12:21 -0500)
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: Oak Zeng <ozeng@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c

index a5cc64559bf17e0fb2a9abb4c46697f14cf22aa9..7e79fb32eb2b11dbccd2e2d493f111ced01292f8 100644 (file)
@@ -368,9 +368,7 @@ static int create_compute_queue_nocpsch(struct device_queue_manager *dqm,
        struct mqd_manager *mqd_mgr;
        int retval;
 
-       mqd_mgr = dqm->ops.get_mqd_manager(dqm, KFD_MQD_TYPE_COMPUTE);
-       if (!mqd_mgr)
-               return -ENOMEM;
+       mqd_mgr = dqm->mqd_mgrs[KFD_MQD_TYPE_COMPUTE];
 
        retval = allocate_hqd(dqm, q);
        if (retval)
@@ -425,10 +423,8 @@ static int destroy_queue_nocpsch_locked(struct device_queue_manager *dqm,
        int retval;
        struct mqd_manager *mqd_mgr;
 
-       mqd_mgr = dqm->ops.get_mqd_manager(dqm,
-               get_mqd_type_from_queue_type(q->properties.type));
-       if (!mqd_mgr)
-               return -ENOMEM;
+       mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
+                       q->properties.type)];
 
        if (q->properties.type == KFD_QUEUE_TYPE_COMPUTE) {
                deallocate_hqd(dqm, q);
@@ -501,12 +497,8 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q)
                retval = -ENODEV;
                goto out_unlock;
        }
-       mqd_mgr = dqm->ops.get_mqd_manager(dqm,
-                       get_mqd_type_from_queue_type(q->properties.type));
-       if (!mqd_mgr) {
-               retval = -ENOMEM;
-               goto out_unlock;
-       }
+       mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
+                       q->properties.type)];
        /*
         * Eviction state logic: we only mark active queues as evicted
         * to avoid the overhead of restoring inactive queues later
@@ -571,27 +563,6 @@ out_unlock:
        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,
                                        struct qcm_process_device *qpd)
 {
@@ -612,13 +583,8 @@ static int evict_process_queues_nocpsch(struct device_queue_manager *dqm,
        list_for_each_entry(q, &qpd->queues_list, list) {
                if (!q->properties.is_active)
                        continue;
-               mqd_mgr = dqm->ops.get_mqd_manager(dqm,
-                       get_mqd_type_from_queue_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;
-               }
+               mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
+                               q->properties.type)];
                q->properties.is_evicted = true;
                q->properties.is_active = false;
                retval = mqd_mgr->destroy_mqd(mqd_mgr, q->mqd,
@@ -717,13 +683,8 @@ static int restore_process_queues_nocpsch(struct device_queue_manager *dqm,
        list_for_each_entry(q, &qpd->queues_list, list) {
                if (!q->properties.is_evicted)
                        continue;
-               mqd_mgr = dqm->ops.get_mqd_manager(dqm,
-                       get_mqd_type_from_queue_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;
-               }
+               mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
+                               q->properties.type)];
                q->properties.is_evicted = false;
                q->properties.is_active = true;
                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,
        struct mqd_manager *mqd_mgr;
        int retval;
 
-       mqd_mgr = dqm->ops.get_mqd_manager(dqm, KFD_MQD_TYPE_SDMA);
-       if (!mqd_mgr)
-               return -ENOMEM;
+       mqd_mgr = dqm->mqd_mgrs[KFD_MQD_TYPE_SDMA];
 
        retval = allocate_sdma_queue(dqm, &q->sdma_id);
        if (retval)
@@ -1185,17 +1144,8 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
        if (retval)
                goto out_deallocate_sdma_queue;
 
-       /* Do init_mqd before dqm_lock(dqm) to avoid circular locking order:
-        * lock(dqm) -> bo::reserve
-        */
-       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;
-       }
-
+       mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
+                       q->properties.type)];
        /*
         * Eviction state logic: we only mark active queues as evicted
         * to avoid the overhead of restoring inactive queues later
@@ -1380,12 +1330,8 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm,
 
        }
 
-       mqd_mgr = dqm->ops.get_mqd_manager(dqm,
-                       get_mqd_type_from_queue_type(q->properties.type));
-       if (!mqd_mgr) {
-               retval = -ENOMEM;
-               goto failed;
-       }
+       mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
+                       q->properties.type)];
 
        deallocate_doorbell(qpd, q);
 
@@ -1419,7 +1365,6 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm,
 
        return retval;
 
-failed:
 failed_try_destroy_debugged_queue:
 
        dqm_unlock(dqm);
@@ -1566,11 +1511,7 @@ static int get_wave_state(struct device_queue_manager *dqm,
                goto dqm_unlock;
        }
 
-       mqd_mgr = dqm->ops.get_mqd_manager(dqm, KFD_MQD_TYPE_COMPUTE);
-       if (!mqd_mgr) {
-               r = -ENOMEM;
-               goto dqm_unlock;
-       }
+       mqd_mgr = dqm->mqd_mgrs[KFD_MQD_TYPE_COMPUTE];
 
        if (!mqd_mgr->get_wave_state) {
                r = -EINVAL;
@@ -1646,21 +1587,40 @@ static int process_termination_cpsch(struct device_queue_manager *dqm,
         * Do uninit_mqd() after dqm_unlock to avoid circular locking.
         */
        list_for_each_entry_safe(q, next, &qpd->queues_list, list) {
-               mqd_mgr = dqm->ops.get_mqd_manager(dqm,
-                       get_mqd_type_from_queue_type(q->properties.type));
-               if (!mqd_mgr) {
-                       retval = -ENOMEM;
-                       goto out;
-               }
+               mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
+                               q->properties.type)];
                list_del(&q->list);
                qpd->queue_count--;
                mqd_mgr->uninit_mqd(mqd_mgr, q->mqd, q->mqd_mem_obj);
        }
 
-out:
        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 *dqm;
@@ -1698,7 +1658,6 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev)
                dqm->ops.stop = stop_cpsch;
                dqm->ops.destroy_queue = destroy_queue_cpsch;
                dqm->ops.update_queue = update_queue;
-               dqm->ops.get_mqd_manager = get_mqd_manager;
                dqm->ops.register_process = register_process;
                dqm->ops.unregister_process = unregister_process;
                dqm->ops.uninitialize = uninitialize;
@@ -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.destroy_queue = destroy_queue_nocpsch;
                dqm->ops.update_queue = update_queue;
-               dqm->ops.get_mqd_manager = get_mqd_manager;
                dqm->ops.register_process = register_process;
                dqm->ops.unregister_process = unregister_process;
                dqm->ops.initialize = initialize_nocpsch;
@@ -1769,6 +1727,9 @@ struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev)
                goto out_free;
        }
 
+       if (init_mqd_managers(dqm))
+               goto out_free;
+
        if (!dqm->ops.initialize(dqm))
                return dqm;
 
index a5d83ec1c6a8410d8ca94362076266739389d595..a5ef7a6650a50da2326eba27ecbf6c55666e15c9 100644 (file)
@@ -48,8 +48,6 @@ struct device_process_node {
  *
  * @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.
  *
  * @register_process: This routine associates a specific process with device.
@@ -97,10 +95,6 @@ struct device_queue_manager_ops {
        int     (*update_queue)(struct device_queue_manager *dqm,
                                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,
                                        struct qcm_process_device *qpd);
 
index 58bb3ad233a11d2984036200c08a93e360977e60..7a737b50bed494b02bdf354bcbab44f3bd20094b 100644 (file)
@@ -58,12 +58,10 @@ static bool initialize(struct kernel_queue *kq, struct kfd_dev *dev,
        kq->nop_packet = nop.u32all;
        switch (type) {
        case KFD_QUEUE_TYPE_DIQ:
-               kq->mqd_mgr = dev->dqm->ops.get_mqd_manager(dev->dqm,
-                                               KFD_MQD_TYPE_DIQ);
+               kq->mqd_mgr = dev->dqm->mqd_mgrs[KFD_MQD_TYPE_DIQ];
                break;
        case KFD_QUEUE_TYPE_HIQ:
-               kq->mqd_mgr = dev->dqm->ops.get_mqd_manager(dev->dqm,
-                                               KFD_MQD_TYPE_HIQ);
+               kq->mqd_mgr = dev->dqm->mqd_mgrs[KFD_MQD_TYPE_HIQ];
                break;
        default:
                pr_err("Invalid queue type %d\n", type);
index 7671658ef1f162cc16e43e2a1df96d36850060b5..f18d9cdf9aac96d80b741d897a53d087c633edeb 100644 (file)
@@ -461,8 +461,7 @@ int pqm_debugfs_mqds(struct seq_file *m, void *data)
                                           q->properties.type, q->device->id);
                                continue;
                        }
-                       mqd_mgr = q->device->dqm->ops.get_mqd_manager(
-                               q->device->dqm, mqd_type);
+                       mqd_mgr = q->device->dqm->mqd_mgrs[mqd_type];
                } else if (pqn->kq) {
                        q = pqn->kq->queue;
                        mqd_mgr = pqn->kq->mqd_mgr;