[<prev] [next>] [day] [month] [year] [list]
Message-ID: <1405603773-32688-26-git-send-email-oded.gabbay@amd.com>
Date: Thu, 17 Jul 2014 16:29:32 +0300
From: Oded Gabbay <oded.gabbay@....com>
To: David Airlie <airlied@...ux.ie>,
Jerome Glisse <j.glisse@...il.com>,
"Alex Deucher" <alexdeucher@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>
CC: John Bridgman <John.Bridgman@....com>,
Joerg Roedel <joro@...tes.org>,
Andrew Lewycky <Andrew.Lewycky@....com>,
Christian König <deathsimple@...afone.de>,
Michel Dänzer <michel.daenzer@....com>,
Ben Goz <Ben.Goz@....com>,
Alexey Skidanov <Alexey.Skidanov@....com>,
Evgeny Pinchuk <Evgeny.Pinchuk@....com>,
"Evgeny Pinchuk" <evgeny.pinchuk@....com>,
Ben Goz <ben.goz@....com>, Oded Gabbay <oded.gabbay@....com>,
Alex Deucher <alexander.deucher@....com>,
Christian König <christian.koenig@....com>,
<dri-devel@...ts.freedesktop.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH v2 25/25] amdkfd: Implement the PMC Acquire/Release IOCTLs
From: Evgeny Pinchuk <evgeny.pinchuk@....com>
Signed-off-by: Ben Goz <ben.goz@....com>
Signed-off-by: Oded Gabbay <oded.gabbay@....com>
---
drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c | 46 +++++++++++++++++++++++++++--
drivers/gpu/drm/radeon/amdkfd/kfd_device.c | 2 ++
drivers/gpu/drm/radeon/amdkfd/kfd_priv.h | 5 ++++
drivers/gpu/drm/radeon/amdkfd/kfd_process.c | 6 ++++
4 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c b/drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c
index 1e19504..be90ab9 100644
--- a/drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/radeon/amdkfd/kfd_chardev.c
@@ -391,12 +391,54 @@ static int kfd_ioctl_get_process_apertures(struct file *filp, struct kfd_process
static long kfd_ioctl_pmc_acquire_access(struct file *filp, struct kfd_process *p, void __user *arg)
{
- return -ENODEV;
+ struct kfd_ioctl_pmc_acquire_access_args args;
+ struct kfd_dev *dev;
+ int err = -EBUSY;
+
+ if (copy_from_user(&args, arg, sizeof(args)))
+ return -EFAULT;
+
+ dev = kfd_device_by_id(args.gpu_id);
+ if (dev == NULL)
+ return -EINVAL;
+
+ spin_lock(&dev->pmc_access_lock);
+ if (dev->pmc_locking_process == NULL) {
+ dev->pmc_locking_process = p;
+ dev->pmc_locking_trace = args.trace_id;
+ err = 0;
+ } else if (dev->pmc_locking_process == p && dev->pmc_locking_trace == args.trace_id) {
+ /* Same trace already has an access. Returning success */
+ err = 0;
+ }
+
+ spin_unlock(&dev->pmc_access_lock);
+
+ return err;
}
static long kfd_ioctl_pmc_release_access(struct file *filp, struct kfd_process *p, void __user *arg)
{
- return -ENODEV;
+ struct kfd_ioctl_pmc_release_access_args args;
+ struct kfd_dev *dev;
+ int err = -EINVAL;
+
+ if (copy_from_user(&args, arg, sizeof(args)))
+ return -EFAULT;
+
+ dev = kfd_device_by_id(args.gpu_id);
+ if (dev == NULL)
+ return -EINVAL;
+
+ spin_lock(&dev->pmc_access_lock);
+ if (dev->pmc_locking_process == p && dev->pmc_locking_trace == args.trace_id) {
+ dev->pmc_locking_process = NULL;
+ dev->pmc_locking_trace = 0;
+ err = 0;
+ }
+ spin_unlock(&dev->pmc_access_lock);
+
+ return err;
}
static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
diff --git a/drivers/gpu/drm/radeon/amdkfd/kfd_device.c b/drivers/gpu/drm/radeon/amdkfd/kfd_device.c
index 6a7a8b2..f1cbc46 100644
--- a/drivers/gpu/drm/radeon/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/radeon/amdkfd/kfd_device.c
@@ -184,6 +184,8 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
return false;
}
+ spin_lock_init(&kfd->pmc_access_lock);
+
kfd->init_complete = true;
dev_info(kfd_device, "added device (%x:%x)\n", kfd->pdev->vendor,
kfd->pdev->device);
diff --git a/drivers/gpu/drm/radeon/amdkfd/kfd_priv.h b/drivers/gpu/drm/radeon/amdkfd/kfd_priv.h
index 1db1ede..a5356d1 100644
--- a/drivers/gpu/drm/radeon/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/radeon/amdkfd/kfd_priv.h
@@ -131,6 +131,11 @@ struct kfd_dev {
/* QCM Device instance */
struct device_queue_manager *dqm;
+
+ /* Performance counters exclusivity lock */
+ spinlock_t pmc_access_lock;
+ struct kfd_process *pmc_locking_process;
+ uint64_t pmc_locking_trace;
};
/* KGD2KFD callbacks */
diff --git a/drivers/gpu/drm/radeon/amdkfd/kfd_process.c b/drivers/gpu/drm/radeon/amdkfd/kfd_process.c
index bcc004f..a67c239 100644
--- a/drivers/gpu/drm/radeon/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/radeon/amdkfd/kfd_process.c
@@ -98,6 +98,12 @@ static void free_process(struct kfd_process *p)
BUG_ON(p == NULL);
list_for_each_entry_safe(pdd, temp, &p->per_device_data, per_device_list) {
+ spin_lock(&pdd->dev->pmc_access_lock);
+ if (pdd->dev->pmc_locking_process == p) {
+ pdd->dev->pmc_locking_process = NULL;
+ pdd->dev->pmc_locking_trace = 0;
+ }
+ spin_unlock(&pdd->dev->pmc_access_lock);
amd_iommu_unbind_pasid(pdd->dev->pdev, p->pasid);
list_del(&pdd->per_device_list);
kfree(pdd);
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists