Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4472262rwl; Tue, 28 Mar 2023 07:26:09 -0700 (PDT) X-Google-Smtp-Source: AKy350bSZBHhdDAfJCHJmq4+sHakiv0hnyJD4h7weu1Devxyx52yWj7huOd7H0kjIauTF42lIWpu X-Received: by 2002:a17:907:9c08:b0:93f:9b4a:12f3 with SMTP id ld8-20020a1709079c0800b0093f9b4a12f3mr12449627ejc.10.1680013569578; Tue, 28 Mar 2023 07:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680013569; cv=none; d=google.com; s=arc-20160816; b=EmQ6UteKD4EjbNeks6OYC3W46HPPkLMBdp+iSzeGwB0DHQ2idUcsKL18jtRx+ADSAP Zl/5VjeFKdkH02Ev4oteih69wa1bS1jQV3YIICOWgtAZxXv4c3rRiKpCzycKMZme/0Bx WGg3LbRvS4L8LMgenY+jgjwI2tAhFH8HHPyimvZI4G9BCRt5E6WBkhhsyGx328jw7HGx MtbiCaKmAddkAnHMwcMRUUEsSzfluoCXbc3dIlyozQC4KsXEWsntg+3on2l+A93vwiFS XshQxttIGzpX2yla6f2sPPuEDAiCtSl3E4rLHJm6zR6CmjP/J366KcYL6l2KQGIDCUe6 RKhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=HMIxd4bwu7Snn5kbKkHbe9IQA9AKXV5gy9MQJGOBV3Y=; b=TWOftuXkb4p07o1qihoG0MygB2M68dGF4yOiZUY+7CCEH8F+gxb+fhrwkIpFMh4+MU i5zNNc8Q/hEkyEh6UiFFbCwRw6Pil+SmoHIGUTeFHOPBxiogJiZeZbe5jd0+583sNkGv JTdZYKdtlvnscaUNkdl2jy1iA3CzwStt9n1aHUuBUjf5CEUZ6XLlx0ZnLL0CbjVLboVI YiqoYZx+IkFdQ8H6Nw0HhWeYup4xCYqGnfRVcN7/LNFSUoOYBIRiKN37n8aphWZCl/yP TZX8FXIHP1GERxb9FyIlGg65rF9nSzEYmzMYq0yp8btdIWZgBVBFtUn+e3ym5uxcuTWd LyEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TJE1q6Nv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w26-20020a170906131a00b00946b646c08fsi1846546ejb.907.2023.03.28.07.25.44; Tue, 28 Mar 2023 07:26:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TJE1q6Nv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232810AbjC1OYz (ORCPT + 99 others); Tue, 28 Mar 2023 10:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232877AbjC1OYt (ORCPT ); Tue, 28 Mar 2023 10:24:49 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D636E8A4C for ; Tue, 28 Mar 2023 07:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680013487; x=1711549487; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=G5WMzWIE0ojBdHoFJAsh9KYOhyFRY/F1VB3tEmTC0Yo=; b=TJE1q6NvRkBofPFloCW44ONNlgvJ5hzEzplFfeVb14f/xkh7U0nORCGh 5kS0WmOBAI2OxN3FR1YoP7Y875jDeeAANDIwmJvTfCLWGeZM0iCV0ykLe +YmzKgsmrQ2oGBvFHseUcQXO7+9pjBk9J+btOmyG+DXHpC8xZKQ8aSymX 7mPLukFeMMOgXb2WojdgmItHaIFNRTdomdFuZIxGtZKLlnSghFyZXQioC DFbgIknZbdxCQd2ycyJ3T29UMdufWTH6tAIQpG2W2np4VSeD2pu07uJuT SWvHFjBFPgA9/nsCBaSi1o9n4dM/61WPnvBOtR4s453mcUtZmp+He2VWB Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="339299585" X-IronPort-AV: E=Sophos;i="5.98,297,1673942400"; d="scan'208";a="339299585" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2023 07:24:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="683918096" X-IronPort-AV: E=Sophos;i="5.98,297,1673942400"; d="scan'208";a="683918096" Received: from wheelerj-mobl.ger.corp.intel.com (HELO [10.213.213.242]) ([10.213.213.242]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2023 07:24:44 -0700 Message-ID: <3fd504bf-0415-3466-78c5-918a295dcf93@linux.intel.com> Date: Tue, 28 Mar 2023 15:24:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v10 09/15] drm/syncobj: Add deadline support for syncobj waits Content-Language: en-US To: Rob Clark , dri-devel@lists.freedesktop.org Cc: Rob Clark , =?UTF-8?Q?Christian_K=c3=b6nig?= , intel-gfx@lists.freedesktop.org, open list , Luben Tuikov , Thomas Zimmermann , Rodrigo Vivi , Matt Turner , freedreno@lists.freedesktop.org References: <20230308155322.344664-1-robdclark@gmail.com> <20230308155322.344664-10-robdclark@gmail.com> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc In-Reply-To: <20230308155322.344664-10-robdclark@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/03/2023 15:53, Rob Clark wrote: > From: Rob Clark > > Add a new flag to let userspace provide a deadline as a hint for syncobj > and timeline waits. This gives a hint to the driver signaling the > backing fences about how soon userspace needs it to compete work, so it > can addjust GPU frequency accordingly. An immediate deadline can be adjust > given to provide something equivalent to i915 "wait boost". > > v2: Use absolute u64 ns value for deadline hint, drop cap and driver > feature flag in favor of allowing count_handles==0 as a way for > userspace to probe kernel for support of new flag > v3: More verbose comments about UAPI > > Signed-off-by: Rob Clark > --- > drivers/gpu/drm/drm_syncobj.c | 64 ++++++++++++++++++++++++++++------- > include/uapi/drm/drm.h | 17 ++++++++++ > 2 files changed, 68 insertions(+), 13 deletions(-) > > diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c > index 0c2be8360525..a85e9464f07b 100644 > --- a/drivers/gpu/drm/drm_syncobj.c > +++ b/drivers/gpu/drm/drm_syncobj.c > @@ -126,6 +126,11 @@ > * synchronize between the two. > * This requirement is inherited from the Vulkan fence API. > * > + * If &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE is set, the ioctl will also set > + * a fence deadline hint on the backing fences before waiting, to provide the > + * fence signaler with an appropriate sense of urgency. The deadline is > + * specified as an absolute &CLOCK_MONOTONIC value in units of ns. > + * > * Similarly, &DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT takes an array of syncobj > * handles as well as an array of u64 points and does a host-side wait on all > * of syncobj fences at the given points simultaneously. > @@ -973,7 +978,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, > uint32_t count, > uint32_t flags, > signed long timeout, > - uint32_t *idx) > + uint32_t *idx, > + ktime_t *deadline) > { > struct syncobj_wait_entry *entries; > struct dma_fence *fence; > @@ -1053,6 +1059,15 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, > drm_syncobj_fence_add_wait(syncobjs[i], &entries[i]); > } > > + if (deadline) { > + for (i = 0; i < count; ++i) { > + fence = entries[i].fence; > + if (!fence) > + continue; > + dma_fence_set_deadline(fence, *deadline); > + } > + } > + > do { > set_current_state(TASK_INTERRUPTIBLE); > > @@ -1151,7 +1166,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev, > struct drm_file *file_private, > struct drm_syncobj_wait *wait, > struct drm_syncobj_timeline_wait *timeline_wait, > - struct drm_syncobj **syncobjs, bool timeline) > + struct drm_syncobj **syncobjs, bool timeline, > + ktime_t *deadline) > { > signed long timeout = 0; > uint32_t first = ~0; > @@ -1162,7 +1178,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev, > NULL, > wait->count_handles, > wait->flags, > - timeout, &first); > + timeout, &first, > + deadline); > if (timeout < 0) > return timeout; > wait->first_signaled = first; > @@ -1172,7 +1189,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev, > u64_to_user_ptr(timeline_wait->points), > timeline_wait->count_handles, > timeline_wait->flags, > - timeout, &first); > + timeout, &first, > + deadline); > if (timeout < 0) > return timeout; > timeline_wait->first_signaled = first; > @@ -1243,17 +1261,22 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, > { > struct drm_syncobj_wait *args = data; > struct drm_syncobj **syncobjs; > + unsigned possible_flags; > + ktime_t t, *tp = NULL; > int ret = 0; > > if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) > return -EOPNOTSUPP; > > - if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL | > - DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT)) > + possible_flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL | > + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT | > + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE; > + > + if (args->flags & ~possible_flags) > return -EINVAL; > > if (args->count_handles == 0) > - return -EINVAL; > + return 0; > > ret = drm_syncobj_array_find(file_private, > u64_to_user_ptr(args->handles), > @@ -1262,8 +1285,13 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, > if (ret < 0) > return ret; > > + if (args->flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE) { > + t = ns_to_ktime(args->deadline_ns); > + tp = &t; > + } > + > ret = drm_syncobj_array_wait(dev, file_private, > - args, NULL, syncobjs, false); > + args, NULL, syncobjs, false, tp); > > drm_syncobj_array_free(syncobjs, args->count_handles); > > @@ -1276,18 +1304,23 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data, > { > struct drm_syncobj_timeline_wait *args = data; > struct drm_syncobj **syncobjs; > + unsigned possible_flags; > + ktime_t t, *tp = NULL; > int ret = 0; > > if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE)) > return -EOPNOTSUPP; > > - if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL | > - DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT | > - DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE)) > + possible_flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL | > + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT | > + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE | > + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE; > + > + if (args->flags & ~possible_flags) > return -EINVAL; > > if (args->count_handles == 0) > - return -EINVAL; > + return -0; > > ret = drm_syncobj_array_find(file_private, > u64_to_user_ptr(args->handles), > @@ -1296,8 +1329,13 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data, > if (ret < 0) > return ret; > > + if (args->flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE) { > + t = ns_to_ktime(args->deadline_ns); > + tp = &t; > + } > + > ret = drm_syncobj_array_wait(dev, file_private, > - NULL, args, syncobjs, true); > + NULL, args, syncobjs, true, tp); > > drm_syncobj_array_free(syncobjs, args->count_handles); > > diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h > index 642808520d92..bff0509ac8b6 100644 > --- a/include/uapi/drm/drm.h > +++ b/include/uapi/drm/drm.h > @@ -887,6 +887,7 @@ struct drm_syncobj_transfer { > #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0) > #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1) > #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2) /* wait for time point to become available */ > +#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE (1 << 3) /* set fence deadline based to deadline_ns */ s/based// ? > struct drm_syncobj_wait { > __u64 handles; > /* absolute timeout */ > @@ -895,6 +896,14 @@ struct drm_syncobj_wait { > __u32 flags; > __u32 first_signaled; /* only valid when not waiting all */ > __u32 pad; > + /** > + * @deadline_ns - fence deadline hint > + * > + * Deadline hint, in absolute CLOCK_MONOTONIC, to set on backing > + * fence(s) if the DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE flag is > + * set. > + */ > + __u64 deadline_ns; > }; > > struct drm_syncobj_timeline_wait { > @@ -907,6 +916,14 @@ struct drm_syncobj_timeline_wait { > __u32 flags; > __u32 first_signaled; /* only valid when not waiting all */ > __u32 pad; > + /** > + * @deadline_ns - fence deadline hint > + * > + * Deadline hint, in absolute CLOCK_MONOTONIC, to set on backing > + * fence(s) if the DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE flag is > + * set. > + */ > + __u64 deadline_ns; > }; > > FWIW, Reviewed-by: Tvrtko Ursulin Regards, Tvrtko