From patchwork Thu Jul 17 13:29:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 4575391 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 506B29F1D6 for ; Thu, 17 Jul 2014 13:34:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4C4062018A for ; Thu, 17 Jul 2014 13:34:09 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 09F0E2011B for ; Thu, 17 Jul 2014 13:34:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 308906E672; Thu, 17 Jul 2014 06:34:07 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2lp0237.outbound.protection.outlook.com [207.46.163.237]) by gabe.freedesktop.org (Postfix) with ESMTP id 6CCC96E672 for ; Thu, 17 Jul 2014 06:34:05 -0700 (PDT) Received: from BY1PR0201CA0042.namprd02.prod.outlook.com (25.160.191.180) by BY2PR02MB043.namprd02.prod.outlook.com (10.242.44.23) with Microsoft SMTP Server (TLS) id 15.0.990.7; Thu, 17 Jul 2014 13:34:03 +0000 Received: from BN1BFFO11FD038.protection.gbl (2a01:111:f400:7c10::1:144) by BY1PR0201CA0042.outlook.office365.com (2a01:111:e400:4814::52) with Microsoft SMTP Server (TLS) id 15.0.990.7 via Frontend Transport; Thu, 17 Jul 2014 13:34:03 +0000 Received: from atltwp02.amd.com (165.204.84.222) by BN1BFFO11FD038.mail.protection.outlook.com (10.58.144.101) with Microsoft SMTP Server id 15.0.980.11 via Frontend Transport; Thu, 17 Jul 2014 13:34:02 +0000 X-WSS-ID: 0N8UZ0O-08-725-02 X-M-MSG: Received: from satlvexedge02.amd.com (satlvexedge02.amd.com [10.177.96.29]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by atltwp02.amd.com (Axway MailGate 5.3.1) with ESMTPS id 2C15CD16071; Thu, 17 Jul 2014 08:33:59 -0500 (CDT) Received: from SATLEXDAG05.amd.com (10.181.40.11) by SATLVEXEDGE02.amd.com (10.177.96.29) with Microsoft SMTP Server (TLS) id 14.2.328.9; Thu, 17 Jul 2014 08:34:04 -0500 Received: from STOREXDAG01.amd.com (10.1.13.10) by satlexdag05.amd.com (10.181.40.11) with Microsoft SMTP Server (TLS) id 14.2.328.9; Thu, 17 Jul 2014 09:34:01 -0400 Received: from AMD (10.20.0.84) by storexdag01.amd.com (10.1.13.10) with Microsoft SMTP Server (TLS) id 14.2.328.9; Thu, 17 Jul 2014 09:33:59 -0400 From: Oded Gabbay To: David Airlie , Jerome Glisse , "Alex Deucher" , Andrew Morton Subject: [PATCH v2 25/25] amdkfd: Implement the PMC Acquire/Release IOCTLs Date: Thu, 17 Jul 2014 16:29:32 +0300 Message-ID: <1405603773-32688-26-git-send-email-oded.gabbay@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405603773-32688-1-git-send-email-oded.gabbay@amd.com> References: <1405603773-32688-1-git-send-email-oded.gabbay@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.20.0.84] X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.222; CTRY:US; IPV:NLI; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(6009001)(428002)(189002)(199002)(85306003)(81342001)(93916002)(83322001)(62966002)(19580405001)(74662001)(107046002)(50986999)(77156001)(76176999)(84676001)(87936001)(88136002)(31966008)(104166001)(87286001)(74502001)(83072002)(85852003)(77096002)(102836001)(81542001)(92566001)(97736001)(36756003)(92726001)(95666004)(21056001)(77982001)(79102001)(80022001)(47776003)(20776003)(68736004)(44976005)(101416001)(86362001)(89996001)(46102001)(64706001)(99396002)(33646002)(4396001)(48376002)(106466001)(50466002)(76482001)(229853001)(19580395003)(105586002)(50226001); DIR:OUT; SFP:; SCL:1; SRVR:BY2PR02MB043; H:atltwp02.amd.com; FPR:; MLV:sfv; PTR:InfoDomainNonexistent; MX:1; LANG:en; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID: X-Forefront-PRVS: 027578BB13 Received-SPF: None (: amd.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is 165.204.84.222) smtp.mailfrom=Oded.Gabbay@amd.com; X-OriginatorOrg: amd4.onmicrosoft.com Cc: Andrew Lewycky , =?UTF-8?q?Michel=20D=C3=A4nzer?= , linux-kernel@vger.kernel.org, Evgeny Pinchuk , Alexey Skidanov , dri-devel@lists.freedesktop.org, Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 Signed-off-by: Ben Goz Signed-off-by: Oded Gabbay --- 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);