From patchwork Mon Feb 27 19:35:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 657402 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45E78C7EE2E for ; Mon, 27 Feb 2023 19:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbjB0Tg2 (ORCPT ); Mon, 27 Feb 2023 14:36:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbjB0TgM (ORCPT ); Mon, 27 Feb 2023 14:36:12 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E64D1274AA; Mon, 27 Feb 2023 11:36:04 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id i10so7900473plr.9; Mon, 27 Feb 2023 11:36:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LNxsKWr79zliY+Ix7FyHLBv/jvOdd98Ee5355EN3fy4=; b=kPUcQyxxpm05goWDvLo1dDZedNX9BX61/F/oPQD/rogzHNKcrjBRHyp5HfUkm0jIMb oo4wwdgJQ3AOiWnQ/iqcejiRkYWP4xX2P+0yhJVSlqdITvFns0WnAe8h115A589YL0FS VmAPZq2WL/fFgPPhOQNxKo/84nIIo/FqP7rIHr7NlMaCbClO07d7yZATpDUzWZwROngN izR+1KnKVH+ixXnnAiAnYbvUXkbWMHpnLbhk4m5kDyedPbFEIM5fmgsREW6G66V8npSE lBpKO+3yZVWelSP1GxLN+4Z20eaMZ6Sxt2RT44EGp7FU7uYdG9WG0CMt4DYg3IH9N9LG 2xCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LNxsKWr79zliY+Ix7FyHLBv/jvOdd98Ee5355EN3fy4=; b=rdm9symQnuUjnJNRGL1xmoLVj/T02qYiIQ9VPe9Fu5PAxvsM3E+J+BlHEzIf1BpzZ/ Jeuwoq1evuBQpbXk2RHZcgA84h0qHRalnxtIDEtBx1YCDy25AAqCWxC/VAZl+/NmfQI1 5NOp7EghEL6K99PsR4xbFYYbbeKRBxx3Het4sUEV062RYj40WSCu4I69/8wqjjeBbl29 kZq7Tmfj2a2Fa1x6siOku5Dzn6PoDHRQIdELqFs8gVhcDjioPy3wHM+jhICirOpzbv8O Pprd74jP5xibW6MWXx3ryL34bV/cPfsx448QLIa0jFdTC0QMiOB/jGww0Gy1GrD2J02W MVHg== X-Gm-Message-State: AO0yUKWUWxoRtnIaxIzXed/hOeamw63v5musVN1qDX/06mvjBmeottK8 D2Wg5wq2ucRv2XFgTSAx/oo= X-Google-Smtp-Source: AK7set8aFROWB3JM7O+EwRDn3uJ6BxDpdV0bVN++OBmQjDQK2wy3/MuU7bDrxaniAacd9fi2QaT+ZA== X-Received: by 2002:a17:902:ea0b:b0:19c:fc7b:69a4 with SMTP id s11-20020a170902ea0b00b0019cfc7b69a4mr8993303plg.65.1677526564596; Mon, 27 Feb 2023 11:36:04 -0800 (PST) Received: from localhost ([2a00:79e1:abd:4a00:61b:48ed:72ab:435b]) by smtp.gmail.com with ESMTPSA id g24-20020a170902fe1800b001943d58268csm4965963plj.55.2023.02.27.11.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 11:36:04 -0800 (PST) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, Daniel Vetter , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Michel_D=C3=A4nzer?= , Tvrtko Ursulin , Rodrigo Vivi , Alex Deucher , Pekka Paalanen , Simon Ser , Luben Tuikov , Rob Clark , =?utf-8?q?Christian_K=C3=B6nig?= , Sumit Semwal , Gustavo Padovan , linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v7 07/15] dma-buf/sw_sync: Add fence deadline support Date: Mon, 27 Feb 2023 11:35:13 -0800 Message-Id: <20230227193535.2822389-8-robdclark@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230227193535.2822389-1-robdclark@gmail.com> References: <20230227193535.2822389-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Rob Clark This consists of simply storing the most recent deadline, and adding an ioctl to retrieve the deadline. This can be used in conjunction with the SET_DEADLINE ioctl on a fence fd for testing. Ie. create various sw_sync fences, merge them into a fence-array, set deadline on the fence-array and confirm that it is propagated properly to each fence. v2: Switch UABI to express deadline as u64 v3: More verbose UAPI docs, show how to convert from timespec Signed-off-by: Rob Clark Reviewed-by: Christian König --- drivers/dma-buf/sw_sync.c | 58 ++++++++++++++++++++++++++++++++++ drivers/dma-buf/sync_debug.h | 2 ++ include/uapi/linux/sync_file.h | 6 +++- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c index 348b3a9170fa..3e2315ee955b 100644 --- a/drivers/dma-buf/sw_sync.c +++ b/drivers/dma-buf/sw_sync.c @@ -52,12 +52,28 @@ struct sw_sync_create_fence_data { __s32 fence; /* fd of new fence */ }; +/** + * struct sw_sync_get_deadline - get the deadline hint of a sw_sync fence + * @deadline_ns: absolute time of the deadline + * @pad: must be zero + * @fence_fd: the sw_sync fence fd (in) + * + * The timebase for the deadline is CLOCK_MONOTONIC (same as vblank) + */ +struct sw_sync_get_deadline { + __u64 deadline_ns; + __u32 pad; + __s32 fence_fd; +}; + #define SW_SYNC_IOC_MAGIC 'W' #define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\ struct sw_sync_create_fence_data) #define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32) +#define SW_SYNC_GET_DEADLINE _IOWR(SW_SYNC_IOC_MAGIC, 2, \ + struct sw_sync_get_deadline) static const struct dma_fence_ops timeline_fence_ops; @@ -171,6 +187,13 @@ static void timeline_fence_timeline_value_str(struct dma_fence *fence, snprintf(str, size, "%d", parent->value); } +static void timeline_fence_set_deadline(struct dma_fence *fence, ktime_t deadline) +{ + struct sync_pt *pt = dma_fence_to_sync_pt(fence); + + pt->deadline = deadline; +} + static const struct dma_fence_ops timeline_fence_ops = { .get_driver_name = timeline_fence_get_driver_name, .get_timeline_name = timeline_fence_get_timeline_name, @@ -179,6 +202,7 @@ static const struct dma_fence_ops timeline_fence_ops = { .release = timeline_fence_release, .fence_value_str = timeline_fence_value_str, .timeline_value_str = timeline_fence_timeline_value_str, + .set_deadline = timeline_fence_set_deadline, }; /** @@ -387,6 +411,37 @@ static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg) return 0; } +static int sw_sync_ioctl_get_deadline(struct sync_timeline *obj, unsigned long arg) +{ + struct sw_sync_get_deadline data; + struct dma_fence *fence; + struct sync_pt *pt; + + if (copy_from_user(&data, (void __user *)arg, sizeof(data))) + return -EFAULT; + + if (data.deadline_ns || data.pad) + return -EINVAL; + + fence = sync_file_get_fence(data.fence_fd); + if (!fence) + return -EINVAL; + + pt = dma_fence_to_sync_pt(fence); + if (!pt) + return -EINVAL; + + + data.deadline_ns = ktime_to_ns(pt->deadline); + + dma_fence_put(fence); + + if (copy_to_user((void __user *)arg, &data, sizeof(data))) + return -EFAULT; + + return 0; +} + static long sw_sync_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -399,6 +454,9 @@ static long sw_sync_ioctl(struct file *file, unsigned int cmd, case SW_SYNC_IOC_INC: return sw_sync_ioctl_inc(obj, arg); + case SW_SYNC_GET_DEADLINE: + return sw_sync_ioctl_get_deadline(obj, arg); + default: return -ENOTTY; } diff --git a/drivers/dma-buf/sync_debug.h b/drivers/dma-buf/sync_debug.h index 6176e52ba2d7..2e0146d0bdbb 100644 --- a/drivers/dma-buf/sync_debug.h +++ b/drivers/dma-buf/sync_debug.h @@ -55,11 +55,13 @@ static inline struct sync_timeline *dma_fence_parent(struct dma_fence *fence) * @base: base fence object * @link: link on the sync timeline's list * @node: node in the sync timeline's tree + * @deadline: the most recently set fence deadline */ struct sync_pt { struct dma_fence base; struct list_head link; struct rb_node node; + ktime_t deadline; }; extern const struct file_operations sw_sync_debugfs_fops; diff --git a/include/uapi/linux/sync_file.h b/include/uapi/linux/sync_file.h index 49325cf6749b..dc6645b2598b 100644 --- a/include/uapi/linux/sync_file.h +++ b/include/uapi/linux/sync_file.h @@ -72,7 +72,11 @@ struct sync_file_info { * @deadline_ns: absolute time of the deadline * @pad: must be zero * - * The timebase for the deadline is CLOCK_MONOTONIC (same as vblank) + * The timebase for the deadline is CLOCK_MONOTONIC (same as vblank). For + * example: + * + * clock_gettime(CLOCK_MONOTONIC, &t); + * deadline_ns = (t.tv_sec * 1000000000L) + t.tv_nsec + duration_ns */ struct sync_set_deadline { __u64 deadline_ns;