From patchwork Fri Aug 25 18:00:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 9922643 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 EC9F7602BD for ; Fri, 25 Aug 2017 18:00:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAA1328414 for ; Fri, 25 Aug 2017 18:00:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFA4C28438; Fri, 25 Aug 2017 18:00:46 +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 045CD28437 for ; Fri, 25 Aug 2017 18:00:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 083256E008; Fri, 25 Aug 2017 18:00:45 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 00B726E008 for ; Fri, 25 Aug 2017 18:00:43 +0000 (UTC) Received: by mail-pg0-x241.google.com with SMTP id q16so721983pgc.0 for ; Fri, 25 Aug 2017 11:00:43 -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:mime-version :content-transfer-encoding; bh=9+MrF9VGh7NaigtZ1BhZdWTipSv9opM/BZlnZlLzCW8=; b=kfmk56e/Lsku9dloRqCZ4W2zCD63UXE21FDIIN54IW7QWKY64h3zcqr+SZzr0876rK jp4bIjG4NMmn9bRykQYDI58ZwZu+NUoEgyv4yq4BnWcYibWi1UO/B8a1+HOaxraE1yqj 35+eila01/Wv0cGl/Eal3N0RgUWGUste3X4VUdcx23jUXWDamFZmu5X5iQW/zngw1PCe b6NYZWHpR/7zB5pBVmDADzcXa76qHZMqtHLWVCbZltFJietZquDYCCgw/3vh1ZbiNEj0 J33jRJxc+Ou/GjJJ6ynXiNzMuET0kOgoO9HGcGa89RlnKqY5ntFs9puu4+jobu24R4Q1 MAcg== 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=9+MrF9VGh7NaigtZ1BhZdWTipSv9opM/BZlnZlLzCW8=; b=ovtuD6TYLpvBIjmQFFcjjJb4ctlgcOq+Ud2kLOgsx5xHe1FgOZ3MQgACzMbGsPJkoZ 4iB7gb23LBHECKpwllcVHgK6lj8B04AiwZM2zqABrgeDJka+FKaCqDe+C2qg47FPGQLx HXy9tJ4teeF5lmQ4v/E8UlDFwtbVx5Tyd5qsJfsl7ytAn36Sxzryt57T5tQJmytUpYB3 KRME7RHMWVgx/sVH6OlSdTA2CdJ3ulah6tgzOexq/udim7Dw/jrmOO5ED/vdT7I8o9SN ITC5A9euCe3U34EPO8gv4ChCwnuHYk2AYmk6w9PXrWNbLzlwP898oc5cJf044egBR9C6 ys5g== X-Gm-Message-State: AHYfb5gsq0E4ba55wJdLGF6gQZBjHWKjCod4csx5G2JJxYHVorteHmvU S/htHcqwMlVcxJAX4BKJnQ== X-Received: by 10.98.211.27 with SMTP id q27mr10496717pfg.131.1503684042728; Fri, 25 Aug 2017 11:00:42 -0700 (PDT) Received: from omlet.jlekstrand.net (static-50-43-41-117.bvtn.or.frontiernet.net. [50.43.41.117]) by smtp.gmail.com with ESMTPSA id l22sm12517474pfj.138.2017.08.25.11.00.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Aug 2017 11:00:40 -0700 (PDT) From: Jason Ekstrand X-Google-Original-From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org Date: Fri, 25 Aug 2017 11:00:34 -0700 Message-Id: <1503684037-32006-1-git-send-email-jason.ekstrand@intel.com> X-Mailer: git-send-email 2.5.0.400.gff86faf MIME-Version: 1.0 Cc: Jason Ekstrand Subject: [Intel-gfx] [PATCH i-g-t 1/4] lib: Add some syncobj helpers (v2) X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jason Ekstrand --- lib/Makefile.sources | 2 + lib/igt_syncobj.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_syncobj.h | 71 ++++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100644 lib/igt_syncobj.c create mode 100644 lib/igt_syncobj.h diff --git a/lib/Makefile.sources b/lib/Makefile.sources index 53fdb54..692fe30 100644 --- a/lib/Makefile.sources +++ b/lib/Makefile.sources @@ -83,6 +83,8 @@ lib_source_list = \ uwildmat/uwildmat.c \ igt_kmod.c \ igt_kmod.h \ + igt_syncobj.c \ + igt_syncobj.h \ $(NULL) .PHONY: version.h.tmp diff --git a/lib/igt_syncobj.c b/lib/igt_syncobj.c new file mode 100644 index 0000000..5caef2a --- /dev/null +++ b/lib/igt_syncobj.c @@ -0,0 +1,207 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include + +#include "igt.h" +#include "igt_syncobj.h" + +static int +__syncobj_create(int fd, uint32_t *handle, uint32_t flags) +{ + struct drm_syncobj_create create = { 0 }; + int err = 0; + + create.flags = flags; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &create)) + err = -errno; + *handle = create.handle; + return err; +} + +uint32_t +syncobj_create(int fd, uint32_t flags) +{ + uint32_t handle; + igt_assert_eq(__syncobj_create(fd, &handle, flags), 0); + igt_assert(handle); + return handle; +} + +static int +__syncobj_destroy(int fd, uint32_t handle) +{ + struct drm_syncobj_destroy destroy = { 0 }; + int err = 0; + + destroy.handle = handle; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_DESTROY, &destroy)) + err = -errno; + return err; +} + +void +syncobj_destroy(int fd, uint32_t handle) +{ + igt_assert_eq(__syncobj_destroy(fd, handle), 0); +} + +int +__syncobj_handle_to_fd(int fd, struct drm_syncobj_handle *args) +{ + int err = 0; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, args)) + err = -errno; + return err; +} + +int +syncobj_handle_to_fd(int fd, uint32_t handle, uint32_t flags) +{ + struct drm_syncobj_handle args = { 0 }; + args.handle = handle; + args.flags = flags; + igt_assert_eq(__syncobj_handle_to_fd(fd, &args), 0); + igt_assert(args.fd >= 0); + return args.fd; +} + +int +__syncobj_fd_to_handle(int fd, struct drm_syncobj_handle *args) +{ + int err = 0; + if (drmIoctl(fd, DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, args)) + err = -errno; + return err; +} + +uint32_t +syncobj_fd_to_handle(int fd, int syncobj_fd, uint32_t flags) +{ + struct drm_syncobj_handle args = { 0 }; + args.fd = syncobj_fd; + args.flags = flags; + igt_assert_eq(__syncobj_fd_to_handle(fd, &args), 0); + igt_assert(args.handle > 0); + return args.handle; +} + +void +syncobj_import_sync_file(int fd, uint32_t handle, int sync_file) +{ + struct drm_syncobj_handle args = { 0 }; + args.handle = handle; + args.fd = sync_file; + args.flags = DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE; + igt_assert_eq(__syncobj_fd_to_handle(fd, &args), 0); +} + +int +__syncobj_wait(int fd, struct local_syncobj_wait *args) +{ + int err = 0; + if (drmIoctl(fd, LOCAL_IOCTL_SYNCOBJ_WAIT, args)) + err = -errno; + return err; +} + +int +syncobj_wait_err(int fd, uint32_t *handles, uint32_t count, + uint64_t abs_timeout_nsec, uint32_t flags) +{ + struct local_syncobj_wait wait; + + wait.handles = to_user_pointer(handles); + wait.timeout_nsec = abs_timeout_nsec; + wait.count_handles = count; + wait.flags = flags; + wait.first_signaled = 0; + wait.pad = 0; + + return __syncobj_wait(fd, &wait); +} + +bool +syncobj_wait(int fd, uint32_t *handles, uint32_t count, + uint64_t abs_timeout_nsec, uint32_t flags, + uint32_t *first_signaled) +{ + struct local_syncobj_wait wait; + int ret; + + wait.handles = to_user_pointer(handles); + wait.timeout_nsec = abs_timeout_nsec; + wait.count_handles = count; + wait.flags = flags; + wait.first_signaled = 0; + wait.pad = 0; + + ret = __syncobj_wait(fd, &wait); + if (ret == ETIME) + return false; + + igt_assert_eq(ret, 0); + if (first_signaled) + *first_signaled = wait.first_signaled; + + return true; +} + +static int +__syncobj_reset(int fd, uint32_t *handles, uint32_t count) +{ + struct local_syncobj_array array = { 0 }; + int err = 0; + + array.handles = to_user_pointer(handles); + array.count_handles = count; + if (drmIoctl(fd, LOCAL_IOCTL_SYNCOBJ_RESET, &array)) + err = -errno; + return err; +} + +void +syncobj_reset(int fd, uint32_t *handles, uint32_t count) +{ + igt_assert_eq(__syncobj_reset(fd, handles, count), 0); +} + +static int +__syncobj_signal(int fd, uint32_t *handles, uint32_t count) +{ + struct local_syncobj_array array = { 0 }; + int err = 0; + + array.handles = to_user_pointer(handles); + array.count_handles = count; + if (drmIoctl(fd, LOCAL_IOCTL_SYNCOBJ_SIGNAL, &array)) + err = -errno; + return err; +} + +void +syncobj_signal(int fd, uint32_t *handles, uint32_t count) +{ + igt_assert_eq(__syncobj_signal(fd, handles, count), 0); +} diff --git a/lib/igt_syncobj.h b/lib/igt_syncobj.h new file mode 100644 index 0000000..44d1378 --- /dev/null +++ b/lib/igt_syncobj.h @@ -0,0 +1,71 @@ +/* + * Copyright © 2017 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef IGT_SYNCOBJ_H +#define IGT_SYNCOBJ_H + +#include +#include +#include + +#define LOCAL_SYNCOBJ_CREATE_SIGNALED (1 << 0) + +#define LOCAL_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0) +#define LOCAL_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1) +struct local_syncobj_wait { + __u64 handles; + /* absolute timeout */ + __s64 timeout_nsec; + __u32 count_handles; + __u32 flags; + __u32 first_signaled; /* only valid when not waiting all */ + __u32 pad; +}; + +struct local_syncobj_array { + __u64 handles; + __u32 count_handles; + __u32 pad; +}; + +#define LOCAL_IOCTL_SYNCOBJ_WAIT DRM_IOWR(0xC3, struct local_syncobj_wait) +#define LOCAL_IOCTL_SYNCOBJ_RESET DRM_IOWR(0xC4, struct local_syncobj_array) +#define LOCAL_IOCTL_SYNCOBJ_SIGNAL DRM_IOWR(0xC5, struct local_syncobj_array) + +uint32_t syncobj_create(int fd, uint32_t flags); +void syncobj_destroy(int fd, uint32_t handle); +int __syncobj_handle_to_fd(int fd, struct drm_syncobj_handle *args); +int __syncobj_fd_to_handle(int fd, struct drm_syncobj_handle *args); +int syncobj_handle_to_fd(int fd, uint32_t handle, uint32_t flags); +uint32_t syncobj_fd_to_handle(int fd, int syncobj_fd, uint32_t flags); +void syncobj_import_sync_file(int fd, uint32_t handle, int sync_file); +int __syncobj_wait(int fd, struct local_syncobj_wait *args); +int syncobj_wait_err(int fd, uint32_t *handles, uint32_t count, + uint64_t abs_timeout_nsec, uint32_t flags); +bool syncobj_wait(int fd, uint32_t *handles, uint32_t count, + uint64_t abs_timeout_nsec, uint32_t flags, + uint32_t *first_signaled); +void syncobj_reset(int fd, uint32_t *handles, uint32_t count); +void syncobj_signal(int fd, uint32_t *handles, uint32_t count); + +#endif /* IGT_SYNCOBJ_H */