From patchwork Thu Jul 10 21:54:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 4528281 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1DEF1BEEAA for ; Thu, 10 Jul 2014 23:33:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3011A201F2 for ; Thu, 10 Jul 2014 23:33:39 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1FE862011D for ; Thu, 10 Jul 2014 23:33:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 851A16E799; Thu, 10 Jul 2014 16:33:15 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f173.google.com (mail-we0-f173.google.com [74.125.82.173]) by gabe.freedesktop.org (Postfix) with ESMTP id 212A06E163 for ; Thu, 10 Jul 2014 14:56:41 -0700 (PDT) Received: by mail-we0-f173.google.com with SMTP id t60so191805wes.32 for ; Thu, 10 Jul 2014 14:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2kXO+DE4f2hbzSX1hp+qgxX8z60OstICssMrPmeUUu0=; b=hXNoevYyQ8qNuyOGOISFx9MA+3oA0QGGXMaLvkZs4ipq9Ye6vfCcYnvtJwTSxsfp8W lT7CzM95P4bKKOUuaEj1zq6jEBpwg2r92xxfGey6YUWoG4FbmsUNUn6Ww3u2oD/T8Iv1 pSKXnamXMK+WmpVzEU9WPgikhKN4SHSJ1ZyKh577M/dtFcPAvMdEZ8JW5vpAjVFB77Ev xhD8RZtthT/scmNrQkj6HpAE5dbcrcPYz6LernJwp8jRHI17GOd2EQSNnvAqa5+OVOrO vKA/13Wk1jkSN1pzTlEXKnDhFa/D1kH0mrwGEpziFmYJH+4L5mvcXXVK2OFWgCwT3oYo Xk5Q== X-Received: by 10.194.104.200 with SMTP id gg8mr60181569wjb.93.1405029400306; Thu, 10 Jul 2014 14:56:40 -0700 (PDT) Received: from localhost.localdomain ([77.127.59.49]) by mx.google.com with ESMTPSA id pq9sm831097wjc.35.2014.07.10.14.56.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jul 2014 14:56:39 -0700 (PDT) From: Oded Gabbay X-Google-Original-From: Oded Gabbay To: David Airlie , Alex Deucher , Jerome Glisse Subject: [PATCH 59/83] hsa/radeon: Exclusive access for perf. counters Date: Fri, 11 Jul 2014 00:54:15 +0300 Message-Id: <1405029279-6894-31-git-send-email-oded.gabbay@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405029279-6894-1-git-send-email-oded.gabbay@amd.com> References: <1405029279-6894-1-git-send-email-oded.gabbay@amd.com> X-Mailman-Approved-At: Thu, 10 Jul 2014 16:33:12 -0700 Cc: Andrew Lewycky , Ben Goz , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Evgeny Pinchuk , Alexey Skidanov , linux-api@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Evgeny Pinchuk Introducing IOCTL implementation for controlling exclusive access to performace counters. The exclusive access is per GPU device. Signed-off-by: Evgeny Pinchuk Signed-off-by: Oded Gabbay --- drivers/gpu/hsa/radeon/kfd_chardev.c | 61 ++++++++++++++++++++++++++++++++++++ drivers/gpu/hsa/radeon/kfd_device.c | 2 ++ drivers/gpu/hsa/radeon/kfd_priv.h | 5 +++ drivers/gpu/hsa/radeon/kfd_process.c | 8 +++-- include/uapi/linux/kfd_ioctl.h | 12 +++++++ 5 files changed, 86 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/hsa/radeon/kfd_chardev.c b/drivers/gpu/hsa/radeon/kfd_chardev.c index 80b702e..b39df68 100644 --- a/drivers/gpu/hsa/radeon/kfd_chardev.c +++ b/drivers/gpu/hsa/radeon/kfd_chardev.c @@ -387,6 +387,59 @@ static int kfd_ioctl_get_process_apertures(struct file *filp, struct kfd_process return 0; } +static long +kfd_ioctl_pmc_acquire_access(struct file *filp, struct kfd_process *p, void __user *arg) +{ + 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 = radeon_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) +{ + 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 = radeon_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) @@ -427,6 +480,14 @@ kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) err = kfd_ioctl_update_queue(filep, process, (void __user *)arg); break; + case KFD_IOC_PMC_ACQUIRE_ACCESS: + err = kfd_ioctl_pmc_acquire_access(filep, process, (void __user *) arg); + break; + + case KFD_IOC_PMC_RELEASE_ACCESS: + err = kfd_ioctl_pmc_release_access(filep, process, (void __user *) arg); + break; + default: dev_err(kfd_device, "unknown ioctl cmd 0x%x, arg 0x%lx)\n", diff --git a/drivers/gpu/hsa/radeon/kfd_device.c b/drivers/gpu/hsa/radeon/kfd_device.c index c602e16..9af812b 100644 --- a/drivers/gpu/hsa/radeon/kfd_device.c +++ b/drivers/gpu/hsa/radeon/kfd_device.c @@ -185,6 +185,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/hsa/radeon/kfd_priv.h b/drivers/gpu/hsa/radeon/kfd_priv.h index 049671b..e6d4993 100644 --- a/drivers/gpu/hsa/radeon/kfd_priv.h +++ b/drivers/gpu/hsa/radeon/kfd_priv.h @@ -135,6 +135,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/hsa/radeon/kfd_process.c b/drivers/gpu/hsa/radeon/kfd_process.c index f967c15..9bb5cab 100644 --- a/drivers/gpu/hsa/radeon/kfd_process.c +++ b/drivers/gpu/hsa/radeon/kfd_process.c @@ -96,9 +96,13 @@ static void free_process(struct kfd_process *p) BUG_ON(p == NULL); - /* doorbell mappings: automatic */ - 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); diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h index d58231d..509c4a0 100644 --- a/include/uapi/linux/kfd_ioctl.h +++ b/include/uapi/linux/kfd_ioctl.h @@ -103,6 +103,16 @@ struct kfd_ioctl_get_process_apertures_args { uint8_t num_of_nodes; /* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS]*/ }; +struct kfd_ioctl_pmc_acquire_access_args { + uint32_t gpu_id; /* to KFD */ + uint64_t trace_id; /* to KFD */ +}; + +struct kfd_ioctl_pmc_release_access_args { + uint32_t gpu_id; /* to KFD */ + uint64_t trace_id; /* to KFD */ +}; + #define KFD_IOC_MAGIC 'K' #define KFD_IOC_GET_VERSION _IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args) @@ -112,6 +122,8 @@ struct kfd_ioctl_get_process_apertures_args { #define KFD_IOC_GET_CLOCK_COUNTERS _IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args) #define KFD_IOC_GET_PROCESS_APERTURES _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args) #define KFD_IOC_UPDATE_QUEUE _IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args) +#define KFD_IOC_PMC_ACQUIRE_ACCESS _IOW(KFD_IOC_MAGIC, 12, struct kfd_ioctl_pmc_acquire_access_args) +#define KFD_IOC_PMC_RELEASE_ACCESS _IOW(KFD_IOC_MAGIC, 13, struct kfd_ioctl_pmc_release_access_args) #pragma pack(pop)