From patchwork Thu Aug 24 23:49:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 9921115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1656A60353 for ; Thu, 24 Aug 2017 23:50:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 078F820223 for ; Thu, 24 Aug 2017 23:50:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F029C20121; Thu, 24 Aug 2017 23:50:30 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 455902013D for ; Thu, 24 Aug 2017 23:50:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D40F06E7E7; Thu, 24 Aug 2017 23:50:02 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5BA016E7E7 for ; Thu, 24 Aug 2017 23:50:01 +0000 (UTC) Received: by mail-pg0-x244.google.com with SMTP id a7so1331046pgn.4 for ; Thu, 24 Aug 2017 16:50:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=Len9Eax4HllEHB13a2DlmkcIbNc/RpFqHxm/DojEUNg=; b=EWiwIGHwcjeK2byxrU5Eo6htTFtjHsFwYDV3/mLEpwTeHOrtbV+43NoFmlmwv+yyWc xykOjojaRcHVGbI9SW0Uujem8sFOTXE+hOBHefO7wP2xZ8rVIv8AxgXNDBGeCyvBRzFZ cYaN7IupF6N/tTUf3oTUTPlIqhuukntQrJ95IZix/kO2fCOymGgsQop4wqzg+ownY9L9 aQIzV/j37dscAoAchGLabMVz66vLfvbw5PC+ecUQz7pEImjXqXuK3Ntsitv+GfSUzj/i dx9UAJfl5ocxeh1ICtjsLNCwPZnTiTWXdJSYXbbTHyNrNZwJa21N5xmDPfsK/tWUjmin JHiQ== 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; bh=Len9Eax4HllEHB13a2DlmkcIbNc/RpFqHxm/DojEUNg=; b=sT6bkRgaOC59RkMF+idbCw/q8d7/4vXxeB28bgEx1WEUVz4+7bM3ZHV+52MCPRnkqW vgC2ZiIwZOnEpCYp2KGoz7+AOrlWJkVA/NzyacA5dibH08sl5+DH/KHDv7kqSv3UZu5+ IcTE9gvbLVzBEUuk1Y2GXlXXtY7zPz/fmsfzsA7lvZgYRIgVNcLBwEkAqV+FhdUG3oB5 yIRArGr0n2q+UhCecYTYq/3BhyX5TUgwdjsoHlUr37g7FmKVtyPrUquhk3SFXdiuie+d tEwCQuXFYCjV4Wsp83DHeOjx9AmQoq/MJHd79RhrrPblI73BWCWIWuapC09dcqujJ3Vt +w8g== X-Gm-Message-State: AHYfb5jzj/+vdD/X2XveCnxfdJgzI0FH2XUvYUqZqEbz/s7rat9tPyDf oxXe7BGQKcJjYbHk1AnjXg== X-Received: by 10.98.38.70 with SMTP id m67mr2317971pfm.178.1503618600593; Thu, 24 Aug 2017 16:50:00 -0700 (PDT) Received: from omlet.ak.intel.com ([134.134.139.78]) by smtp.gmail.com with ESMTPSA id z8sm8079110pgs.25.2017.08.24.16.49.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Aug 2017 16:49:59 -0700 (PDT) From: Jason Ekstrand X-Google-Original-From: Jason Ekstrand To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/syncobj: Add a signal ioctl Date: Thu, 24 Aug 2017 16:49:56 -0700 Message-Id: <1503618596-27591-1-git-send-email-jason.ekstrand@intel.com> X-Mailer: git-send-email 2.5.0.400.gff86faf Cc: Jason Ekstrand , Jason Ekstrand X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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-Virus-Scanned: ClamAV using ClamSMTP This IOCTL provides a mechanism for userspace to trigger a sync object directly. There are other ways that userspace can trigger a syncobj such as submitting a dummy batch somewhere or hanging on to a triggered sync_file and doing an import. This just provides an easy way to manually trigger the sync object without weird hacks. The motivation for this IOCTL is Vulkan fences. Vulkan lets you create a fence already in the signaled state so that you can wait on it immediatly without stalling. We could also handle this with a new create flag to ask the driver to create a syncobj that is already signaled but the IOCTL seemed a bit cleaner and more generic. Signed-off-by: Jason Ekstrand --- drivers/gpu/drm/drm_internal.h | 2 ++ drivers/gpu/drm/drm_ioctl.c | 2 ++ drivers/gpu/drm/drm_syncobj.c | 71 ++++++++++++++++++++++++++++++++++++++++++ include/uapi/drm/drm.h | 6 ++++ 4 files changed, 81 insertions(+) diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index 83f1615..fbc3f30 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -171,3 +171,5 @@ int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private); int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private); +int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_private); diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 4185483..4d8f548 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -661,6 +661,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_UNLOCKED|DRM_RENDER_ALLOW), DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_RESET, drm_syncobj_reset_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW), + DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl, + DRM_UNLOCKED|DRM_RENDER_ALLOW), }; #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 7dfdb98..8d3112e 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -831,3 +831,74 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, return 0; } + +struct drm_syncobj_null_fence { + struct dma_fence base; + spinlock_t lock; +}; + +static const char *drm_syncobj_null_fence_get_name(struct dma_fence *fence) +{ + return "syncobjnull"; +} + +static bool drm_syncobj_null_fence_enable_signaling(struct dma_fence *fence) +{ + dma_fence_enable_sw_signaling(fence); + return !dma_fence_is_signaled(fence); +} + +static const struct dma_fence_ops drm_syncobj_null_fence_ops = { + .get_driver_name = drm_syncobj_null_fence_get_name, + .get_timeline_name = drm_syncobj_null_fence_get_name, + .enable_signaling = drm_syncobj_null_fence_enable_signaling, + .wait = dma_fence_default_wait, + .release = NULL, +}; + +static struct dma_fence *drm_syncobj_create_null_fence(void) +{ + struct drm_syncobj_null_fence *fence; + fence = kzalloc(sizeof(*fence), GFP_KERNEL); + if (fence == NULL) + return NULL; + + spin_lock_init(&fence->lock); + dma_fence_init(&fence->base, &drm_syncobj_null_fence_ops, + &fence->lock, 0, 0); + return &fence->base; +} + +int +drm_syncobj_signal_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_private) +{ + struct drm_syncobj_signal *args = data; + struct drm_syncobj *syncobj; + struct dma_fence *null_fence; + + if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) + return -ENODEV; + + if (args->flags != 0) + return -EINVAL; + + syncobj = drm_syncobj_find(file_private, args->handle); + if (!syncobj) + return -ENOENT; + + null_fence = drm_syncobj_create_null_fence(); + if (!null_fence) { + drm_syncobj_put(syncobj); + return -ENOMEM; + } + + dma_fence_signal(null_fence); + + drm_syncobj_replace_fence(syncobj, null_fence); + + dma_fence_put(null_fence); + drm_syncobj_put(syncobj); + + return 0; +} diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h index f8ec8fe..350a6a2 100644 --- a/include/uapi/drm/drm.h +++ b/include/uapi/drm/drm.h @@ -735,6 +735,11 @@ struct drm_syncobj_reset { __u32 flags; }; +struct drm_syncobj_signal { + __u32 handle; + __u32 flags; +}; + #if defined(__cplusplus) } #endif @@ -859,6 +864,7 @@ extern "C" { #define DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE DRM_IOWR(0xC2, struct drm_syncobj_handle) #define DRM_IOCTL_SYNCOBJ_WAIT DRM_IOWR(0xC3, struct drm_syncobj_wait) #define DRM_IOCTL_SYNCOBJ_RESET DRM_IOWR(0xC4, struct drm_syncobj_reset) +#define DRM_IOCTL_SYNCOBJ_SIGNAL DRM_IOWR(0xC5, struct drm_syncobj_signal) /** * Device specific ioctls should only be in their respective headers