cregit-Linux how code gets into the kernel

Release 4.15 drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c

/*
 * Copyright 2014 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#include <linux/slab.h>
#include <linux/list.h>
#include "kfd_device_queue_manager.h"
#include "kfd_priv.h"
#include "kfd_kernel_queue.h"


static inline struct process_queue_node *get_queue_by_qid( struct process_queue_manager *pqm, unsigned int qid) { struct process_queue_node *pqn; list_for_each_entry(pqn, &pqm->queues, process_queue_list) { if ((pqn->q && pqn->q->properties.queue_id == qid) || (pqn->kq && pqn->kq->queue->properties.queue_id == qid)) return pqn; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz7093.33%150.00%
Kent Russell56.67%150.00%
Total75100.00%2100.00%


static int find_available_queue_slot(struct process_queue_manager *pqm, unsigned int *qid) { unsigned long found; found = find_first_zero_bit(pqm->queue_slot_bitmap, KFD_MAX_NUM_OF_QUEUES_PER_PROCESS); pr_debug("The new slot id %lu\n", found); if (found >= KFD_MAX_NUM_OF_QUEUES_PER_PROCESS) { pr_info("Cannot open more queues for process with pasid %d\n", pqm->process->pasid); return -ENOMEM; } set_bit(found, pqm->queue_slot_bitmap); *qid = found; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz7494.87%133.33%
Kent Russell22.56%133.33%
Oded Gabbay22.56%133.33%
Total78100.00%3100.00%


void kfd_process_dequeue_from_device(struct kfd_process_device *pdd) { struct kfd_dev *dev = pdd->dev; if (pdd->already_dequeued) return; dev->dqm->ops.process_termination(dev->dqm, &pdd->qpd); pdd->already_dequeued = true; }

Contributors

PersonTokensPropCommitsCommitProp
Felix Kuehling50100.00%1100.00%
Total50100.00%1100.00%


void kfd_process_dequeue_from_all_devices(struct kfd_process *p) { struct kfd_process_device *pdd; list_for_each_entry(pdd, &p->per_device_data, per_device_list) kfd_process_dequeue_from_device(pdd); }

Contributors

PersonTokensPropCommitsCommitProp
Felix Kuehling28100.00%1100.00%
Total28100.00%1100.00%


int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p) { INIT_LIST_HEAD(&pqm->queues); pqm->queue_slot_bitmap = kzalloc(DIV_ROUND_UP(KFD_MAX_NUM_OF_QUEUES_PER_PROCESS, BITS_PER_BYTE), GFP_KERNEL); if (!pqm->queue_slot_bitmap) return -ENOMEM; pqm->process = p; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz5796.61%133.33%
Oded Gabbay11.69%133.33%
Kent Russell11.69%133.33%
Total59100.00%3100.00%


void pqm_uninit(struct process_queue_manager *pqm) { struct process_queue_node *pqn, *next; list_for_each_entry_safe(pqn, next, &pqm->queues, process_queue_list) { uninit_queue(pqn->q); list_del(&pqn->process_queue_list); kfree(pqn); } kfree(pqm->queue_slot_bitmap); pqm->queue_slot_bitmap = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz5485.71%150.00%
Felix Kuehling914.29%150.00%
Total63100.00%2100.00%


static int create_cp_queue(struct process_queue_manager *pqm, struct kfd_dev *dev, struct queue **q, struct queue_properties *q_properties, struct file *f, unsigned int qid) { int retval; /* Doorbell initialized in user space*/ q_properties->doorbell_ptr = NULL; q_properties->doorbell_off = kfd_queue_id_to_doorbell(dev, pqm->process, qid); /* let DQM handle it*/ q_properties->vmid = 0; q_properties->queue_id = qid; retval = init_queue(q, q_properties); if (retval != 0) return retval; (*q)->device = dev; (*q)->process = pqm->process; pr_debug("PQM After init queue"); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz11696.67%133.33%
Kent Russell43.33%266.67%
Total120100.00%3100.00%


int pqm_create_queue(struct process_queue_manager *pqm, struct kfd_dev *dev, struct file *f, struct queue_properties *properties, unsigned int *qid) { int retval; struct kfd_process_device *pdd; struct queue *q; struct process_queue_node *pqn; struct kernel_queue *kq; enum kfd_queue_type type = properties->type; unsigned int max_queues = 127; /* HWS limit */ q = NULL; kq = NULL; pdd = kfd_get_process_device_data(dev, pqm->process); if (!pdd) { pr_err("Process device data doesn't exist\n"); return -1; } /* * for debug process, verify that it is within the static queues limit * currently limit is set to half of the total avail HQD slots * If we are just about to create DIQ, the is_debug flag is not set yet * Hence we also check the type as well */ if ((pdd->qpd.is_debug) || (type == KFD_QUEUE_TYPE_DIQ)) max_queues = dev->device_info->max_no_of_hqd/2; if (pdd->qpd.queue_count >= max_queues) return -ENOSPC; retval = find_available_queue_slot(pqm, qid); if (retval != 0) return retval; if (list_empty(&pdd->qpd.queues_list) && list_empty(&pdd->qpd.priv_queue_list)) { pdd->qpd.pqm = pqm; dev->dqm->ops.register_process(dev->dqm, &pdd->qpd); } pqn = kzalloc(sizeof(*pqn), GFP_KERNEL); if (!pqn) { retval = -ENOMEM; goto err_allocate_pqn; } switch (type) { case KFD_QUEUE_TYPE_SDMA: if (dev->dqm->queue_count >= CIK_SDMA_QUEUES_PER_ENGINE * CIK_SDMA_ENGINE_NUM) { pr_err("Over-subscription is not allowed for SDMA.\n"); retval = -EPERM; goto err_create_queue; } retval = create_cp_queue(pqm, dev, &q, properties, f, *qid); if (retval != 0) goto err_create_queue; pqn->q = q; pqn->kq = NULL; retval = dev->dqm->ops.create_queue(dev->dqm, q, &pdd->qpd, &q->properties.vmid); pr_debug("DQM returned %d for create_queue\n", retval); print_queue(q); break; case KFD_QUEUE_TYPE_COMPUTE: /* check if there is over subscription */ if ((sched_policy == KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION) && ((dev->dqm->processes_count >= dev->vm_info.vmid_num_kfd) || (dev->dqm->queue_count >= get_queues_num(dev->dqm)))) { pr_err("Over-subscription is not allowed in radeon_kfd.sched_policy == 1\n"); retval = -EPERM; goto err_create_queue; } retval = create_cp_queue(pqm, dev, &q, properties, f, *qid); if (retval != 0) goto err_create_queue; pqn->q = q; pqn->kq = NULL; retval = dev->dqm->ops.create_queue(dev->dqm, q, &pdd->qpd, &q->properties.vmid); pr_debug("DQM returned %d for create_queue\n", retval); print_queue(q); break; case KFD_QUEUE_TYPE_DIQ: kq = kernel_queue_init(dev, KFD_QUEUE_TYPE_DIQ); if (!kq) { retval = -ENOMEM; goto err_create_queue; } kq->queue->properties.queue_id = *qid; pqn->kq = kq; pqn->q = NULL; retval = dev->dqm->ops.create_kernel_queue(dev->dqm, kq, &pdd->qpd); break; default: WARN(1, "Invalid queue type %d", type); retval = -EINVAL; } if (retval != 0) { pr_err("DQM create queue failed\n"); goto err_create_queue; } pr_debug("PQM After DQM create queue\n"); list_add(&pqn->process_queue_list, &pqm->queues); if (q) { pr_debug("PQM done creating queue\n"); print_queue_properties(&q->properties); } return retval; err_create_queue: kfree(pqn); err_allocate_pqn: /* check if queues list is empty unregister process from device */ clear_bit(*qid, pqm->queue_slot_bitmap); if (list_empty(&pdd->qpd.queues_list) && list_empty(&pdd->qpd.priv_queue_list)) dev->dqm->ops.unregister_process(dev->dqm, &pdd->qpd); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz47467.23%420.00%
Felix Kuehling14520.57%420.00%
Yair Shachar253.55%15.00%
Yong Zhao162.27%210.00%
Oded Gabbay131.84%210.00%
Alexey Skidanov121.70%15.00%
Kent Russell81.13%315.00%
Andres Rodriguez60.85%15.00%
Dan Carpenter40.57%15.00%
Dave Airlie20.28%15.00%
Total705100.00%20100.00%


int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid) { struct process_queue_node *pqn; struct kfd_process_device *pdd; struct device_queue_manager *dqm; struct kfd_dev *dev; int retval; dqm = NULL; retval = 0; pqn = get_queue_by_qid(pqm, qid); if (!pqn) { pr_err("Queue id does not match any known queue\n"); return -EINVAL; } dev = NULL; if (pqn->kq) dev = pqn->kq->dev; if (pqn->q) dev = pqn->q->device; if (WARN_ON(!dev)) return -ENODEV; pdd = kfd_get_process_device_data(dev, pqm->process); if (!pdd) { pr_err("Process device data doesn't exist\n"); return -1; } if (pqn->kq) { /* destroy kernel queue (DIQ) */ dqm = pqn->kq->dev->dqm; dqm->ops.destroy_kernel_queue(dqm, pqn->kq, &pdd->qpd); kernel_queue_uninit(pqn->kq); } if (pqn->q) { dqm = pqn->q->device->dqm; retval = dqm->ops.destroy_queue(dqm, &pdd->qpd, pqn->q); uninit_queue(pqn->q); } list_del(&pqn->process_queue_list); kfree(pqn); clear_bit(qid, pqm->queue_slot_bitmap); if (list_empty(&pdd->qpd.queues_list) && list_empty(&pdd->qpd.priv_queue_list)) dqm->ops.unregister_process(dqm, &pdd->qpd); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz26390.38%228.57%
Alexey Skidanov124.12%114.29%
Felix Kuehling82.75%114.29%
Oded Gabbay62.06%114.29%
Kent Russell20.69%228.57%
Total291100.00%7100.00%


int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, struct queue_properties *p) { int retval; struct process_queue_node *pqn; pqn = get_queue_by_qid(pqm, qid); if (!pqn) { pr_debug("No queue %d exists for update operation\n", qid); return -EFAULT; } pqn->q->properties.queue_address = p->queue_address; pqn->q->properties.queue_size = p->queue_size; pqn->q->properties.queue_percent = p->queue_percent; pqn->q->properties.priority = p->priority; retval = pqn->q->device->dqm->ops.update_queue(pqn->q->device->dqm, pqn->q); if (retval != 0) return retval; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz12588.65%125.00%
Oded Gabbay1510.64%250.00%
Kent Russell10.71%125.00%
Total141100.00%4100.00%


struct kernel_queue *pqm_get_kernel_queue( struct process_queue_manager *pqm, unsigned int qid) { struct process_queue_node *pqn; pqn = get_queue_by_qid(pqm, qid); if (pqn && pqn->kq) return pqn->kq; return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Ben Goz2860.87%150.00%
Yair Shachar1839.13%150.00%
Total46100.00%2100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Ben Goz127776.38%416.67%
Felix Kuehling24014.35%520.83%
Yair Shachar432.57%28.33%
Oded Gabbay372.21%312.50%
Alexey Skidanov241.44%14.17%
Kent Russell231.38%416.67%
Yong Zhao160.96%28.33%
Andres Rodriguez60.36%14.17%
Dan Carpenter40.24%14.17%
Dave Airlie20.12%14.17%
Total1672100.00%24100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.