From patchwork Sun Jan 6 09:46:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bas Nieuwenhuizen X-Patchwork-Id: 10749489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 286B16C5 for ; Sun, 6 Jan 2019 09:47:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1055B28801 for ; Sun, 6 Jan 2019 09:47:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03681288D1; Sun, 6 Jan 2019 09:47:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B2E928801 for ; Sun, 6 Jan 2019 09:47:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CD38B6E721; Sun, 6 Jan 2019 09:47:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by gabe.freedesktop.org (Postfix) with ESMTPS id 410976E721 for ; Sun, 6 Jan 2019 09:47:18 +0000 (UTC) Received: by mail-ed1-x542.google.com with SMTP id y56so35228578edd.11 for ; Sun, 06 Jan 2019 01:47:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3qvt50BPsoQltUz0BQAfuFTown/Pr2SN3+HGpKY0eAo=; b=c9iNCDXJAPo8K2raz6ST8MwaNYfHQbgpbXZcRO1p5xeAo8JM/gby9PmFegVIvkdv18 CXNkvEocA1lAkBD52tjMCPD9u6t5pA2PdJBE7uxv7FQAZicbAfnTETL5NtCA+j4t9goo vdT/sSRKL2zqNlPl9cD7CpIavTyhV0s9NtX2qpHmqCZXGaUFi0ub8wqkxoQyzntddhMi Pz/DU6I6iqyULOLNZiXxWcIBvMW+Q6lHghp9059RBwg5elXjsaS45LEWZ5jSRsQ3sqoC R9gOA/xqjS+5lFvPhS+5VFvl3gSiifLYsOT392vwSQuJyoUn5LSI960nmHgyZ7M/8MIv 2Twg== X-Gm-Message-State: AA+aEWZI/ORM/Zvracp84rCe5c+vzxJkGVzxl0nDGCYHNtthdAdRfFZ9 RXP30lcfQWOwi6D/36u9Rcq49GPCWmI= X-Google-Smtp-Source: AFSGD/U3Bo+1EDlnuynQNSt0hIv2Zj10tms7xzWfn6clG04/ZCzdDfuukaMx2fZEG5ltpWnyFl4POw== X-Received: by 2002:a50:e8cc:: with SMTP id l12mr51363246edn.117.1546768036658; Sun, 06 Jan 2019 01:47:16 -0800 (PST) Received: from localhost.localdomain ([2a02:aa12:a77f:2000:7285:c2ff:fe4e:b21b]) by smtp.gmail.com with ESMTPSA id t15-v6sm15975271ejt.0.2019.01.06.01.47.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Jan 2019 01:47:15 -0800 (PST) From: Bas Nieuwenhuizen To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm] amdgpu: Allow amdgpu device creation without merging fds. Date: Sun, 6 Jan 2019 10:46:13 +0100 Message-Id: <20190106094613.19371-1-bas@basnieuwenhuizen.nl> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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-Virus-Scanned: ClamAV using ClamSMTP For radv we want to be able to pass in a master fd and be sure that the created libdrm_amdgpu device also uses that master fd, so we can use it for prioritized submission. radv does all interaction with other APIs/processes with dma-bufs, so we should not need the functionality in libdrm_amdgpu to only have a single fd for a device in the process. Signed-off-by: Bas Nieuwenhuizen --- amdgpu/amdgpu-symbol-check | 1 + amdgpu/amdgpu.h | 37 ++++++++++++++++++++++++ amdgpu/amdgpu_device.c | 59 ++++++++++++++++++++++++-------------- 3 files changed, 76 insertions(+), 21 deletions(-) diff --git a/amdgpu/amdgpu-symbol-check b/amdgpu/amdgpu-symbol-check index 6f5e0f95..bbf48985 100755 --- a/amdgpu/amdgpu-symbol-check +++ b/amdgpu/amdgpu-symbol-check @@ -56,6 +56,7 @@ amdgpu_cs_wait_fences amdgpu_cs_wait_semaphore amdgpu_device_deinitialize amdgpu_device_initialize +amdgpu_device_initialize2 amdgpu_find_bo_by_cpu_mapping amdgpu_get_marketing_name amdgpu_query_buffer_size_alignment diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h index dc51659a..e5ed39bb 100644 --- a/amdgpu/amdgpu.h +++ b/amdgpu/amdgpu.h @@ -66,6 +66,13 @@ struct drm_amdgpu_info_hw_ip; */ #define AMDGPU_QUERY_FENCE_TIMEOUT_IS_ABSOLUTE (1 << 0) +/** + * Uses in amdgpu_device_initialize2(), meaning that the passed in fd should + * not be deduplicated against other libdrm_amdgpu devices referring to the + * same kernel device. + */ +#define AMDGPU_DEVICE_DEDICATED_FD (1 << 0) + /*--------------------------------------------------------------------------*/ /* ----------------------------- Enums ------------------------------------ */ /*--------------------------------------------------------------------------*/ @@ -526,6 +533,36 @@ int amdgpu_device_initialize(int fd, uint32_t *minor_version, amdgpu_device_handle *device_handle); +/** + * + * \param fd - \c [in] File descriptor for AMD GPU device + * received previously as the result of + * e.g. drmOpen() call. + * For legacy fd type, the DRI2/DRI3 + * authentication should be done before + * calling this function. + * \param flags - \c [in] Bitmask of flags for device creation. + * \param major_version - \c [out] Major version of library. It is assumed + * that adding new functionality will cause + * increase in major version + * \param minor_version - \c [out] Minor version of library + * \param device_handle - \c [out] Pointer to opaque context which should + * be passed as the first parameter on each + * API call + * + * + * \return 0 on success\n + * <0 - Negative POSIX Error code + * + * + * \sa amdgpu_device_deinitialize() +*/ +int amdgpu_device_initialize2(int fd, + uint32_t flags, + uint32_t *major_version, + uint32_t *minor_version, + amdgpu_device_handle *device_handle); + /** * * When access to such library does not needed any more the special diff --git a/amdgpu/amdgpu_device.c b/amdgpu/amdgpu_device.c index 362494b1..b4bf3f76 100644 --- a/amdgpu/amdgpu_device.c +++ b/amdgpu/amdgpu_device.c @@ -100,7 +100,8 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev) pthread_mutex_lock(&fd_mutex); while (*node != dev && (*node)->next) node = &(*node)->next; - *node = (*node)->next; + if (*node == dev) + *node = (*node)->next; pthread_mutex_unlock(&fd_mutex); close(dev->fd); @@ -144,6 +145,16 @@ drm_public int amdgpu_device_initialize(int fd, uint32_t *major_version, uint32_t *minor_version, amdgpu_device_handle *device_handle) +{ + return amdgpu_device_initialize2(fd, 0, major_version, minor_version, + device_handle); +} + +drm_public int amdgpu_device_initialize2(int fd, + uint32_t flags, + uint32_t *major_version, + uint32_t *minor_version, + amdgpu_device_handle *device_handle) { struct amdgpu_device *dev; drmVersionPtr version; @@ -164,26 +175,28 @@ drm_public int amdgpu_device_initialize(int fd, return r; } - for (dev = fd_list; dev; dev = dev->next) - if (fd_compare(dev->fd, fd) == 0) - break; - - if (dev) { - r = amdgpu_get_auth(dev->fd, &flag_authexist); - if (r) { - fprintf(stderr, "%s: amdgpu_get_auth (2) failed (%i)\n", - __func__, r); + if (!(flags & AMDGPU_DEVICE_DEDICATED_FD)) { + for (dev = fd_list; dev; dev = dev->next) + if (fd_compare(dev->fd, fd) == 0) + break; + + if (dev) { + r = amdgpu_get_auth(dev->fd, &flag_authexist); + if (r) { + fprintf(stderr, "%s: amdgpu_get_auth (2) failed (%i)\n", + __func__, r); + pthread_mutex_unlock(&fd_mutex); + return r; + } + if ((flag_auth) && (!flag_authexist)) { + dev->flink_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0); + } + *major_version = dev->major_version; + *minor_version = dev->minor_version; + amdgpu_device_reference(device_handle, dev); pthread_mutex_unlock(&fd_mutex); - return r; - } - if ((flag_auth) && (!flag_authexist)) { - dev->flink_fd = fcntl(fd, F_DUPFD_CLOEXEC, 0); + return 0; } - *major_version = dev->major_version; - *minor_version = dev->minor_version; - amdgpu_device_reference(device_handle, dev); - pthread_mutex_unlock(&fd_mutex); - return 0; } dev = calloc(1, sizeof(struct amdgpu_device)); @@ -265,8 +278,12 @@ drm_public int amdgpu_device_initialize(int fd, *major_version = dev->major_version; *minor_version = dev->minor_version; *device_handle = dev; - dev->next = fd_list; - fd_list = dev; + + if (!(flags & AMDGPU_DEVICE_DEDICATED_FD)) { + dev->next = fd_list; + fd_list = dev; + } + pthread_mutex_unlock(&fd_mutex); return 0;