Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7629334rwl; Thu, 23 Mar 2023 06:55:15 -0700 (PDT) Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fABtsO48 X-Google-Smtp-Source: AK7set9b4e8PwBbWquATe1xTLEUQkoqsGrtiB2597TsZf+9kIssc07sbjnUkqHrtj9wWF5/EdqW2 X-Received: by 2002:a17:90b:1d90:b0:23b:2c51:6e7 with SMTP id pf16-20020a17090b1d9000b0023b2c5106e7mr7852201pjb.21.1679579714641; Thu, 23 Mar 2023 06:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679579714; cv=none; d=google.com; s=arc-20160816; b=tlvB0YoTKNziephxeiyt1mjCKxqq8rZ2FDbOkA3jxvZ/TRiuzhudJDYlxAfWVlPwe4 phBT35YwyMxytiU3CFMvtzcdpbu+dyRevUiucCi6B6dZ/sjkXXloJnnytwoMxiOgUNoz +TmlJUuScrGjP07ldACR0k7tuY0WglPX+KwnjXPohmQgNIw3aAE//gbVFB4PBsS1N2gH D3yatGlJQTrjsxsRci8SHVDtQ0gmLeIYszxaG/eeueQ8fN1xYjZ1X5stgQ043QwYR+J1 /tIzrNCzkEJ93BOjX+1F7WdqYZDnTwc1N4b6tuZG9aVlff6HVRuQSFVRZLsZ50lx7+O/ UaOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=QjOvv/ZPDbSli/SQ67teItUX/ZV6UdqvrawXfnsTP9c=; b=QA9ZxXzc/XXU3spLiJtaAJwKobkWgy8O13fjlUjWxHfn6ptMD3UXR9iF1QcfU5eAhG vjEtTay3RoW5W7b8D7LmyPo6UByr8Ya3yTcR9CQ8IsFfx/KGX6i+iKfYk0PEJYAkV2BA LZPy1UMys+EjuZp6SavpOg7XO0QIU4jGEYKC2p5iUTdKUIakqN2D6H73NmO/7vskN0vR XItPzgfUsj8klrRlHp7lagTGpFMhziorPku/t/WoxnO3WLt8abCJEehBc4xSjsVCk6Ho Rsr8gxMxoxW4UcQHTcdsWz2xXjVBWETBoGkev8mwsV9sADvl6BkKSgtatvSd/ckviOTl 8dpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fABtsO48; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e18-20020a17090a9a9200b0023f4e5dda3csi1957734pjp.7.2023.03.23.06.55.02; Thu, 23 Mar 2023 06:55:14 -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=@gmail.com header.s=20210112 header.b=fABtsO48; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231949AbjCWNyn (ORCPT + 99 others); Thu, 23 Mar 2023 09:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231794AbjCWNyZ (ORCPT ); Thu, 23 Mar 2023 09:54:25 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6954CE07A; Thu, 23 Mar 2023 06:54:17 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id x22-20020a056830409600b0069b30fb38f7so12150533ott.5; Thu, 23 Mar 2023 06:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679579656; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QjOvv/ZPDbSli/SQ67teItUX/ZV6UdqvrawXfnsTP9c=; b=fABtsO48pFpSWP4FcJ3dhrQvnIbnb6omivu7xuuBdoBA4dAX6OWqKUf4WBRar8getR uUDMYAy1h2w23MXumxi25yo+48vMiJEIn5x8S1NDp366vvkhUGWs+owx8UORr2HoHxlB ykH2TgdVhWu5Fksfm3zSNiK49GwWe2X3eh6MX118M+k0gIdAaLNdDqMqn75WkLB4TfR0 r9/ieRqMhlAB9Kw0+rhmW7lPPju/rMRdNh0TgpA3bu3aA0pl3Qbg/wT4E4pMSI3LEu2y yN7mf0oNFNDE0wW+qiibGf6aTFeFcMYFoCHx22IFdOen1v8Yj2+ioZPS7pS0fo1NhOXY mGtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679579656; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QjOvv/ZPDbSli/SQ67teItUX/ZV6UdqvrawXfnsTP9c=; b=qhIZ4zhWHp+oI6YwbqRP/+LQcodSDBy8yhAqSAmDZMQNyarCUGvPe0VXZ4GYubpKko V/LKadxUN+9iAZFGIa+kGiG0uSjA8g1K77hJtUGj6NKNty8TZjidkR3QPgFVxK3EKfMk STfpTEY9FimaBSJR2yseyIN2LefkjNeNrD8tGVDolGWXc2zMbnA1QfN/JglR0lEvVkvZ hz0G963kg4zgoK27Qdx9E2PyGCGC23RSRzsfuDeDRwa4A2doPJpOQ1UPNkugLAIBl0p5 rxoojBotrQYZrpQuAIOUgvCEEq4qlrAf8Ac3D/G4611Vihq37lcNLzeZxgLL+wX2eENv ltnA== X-Gm-Message-State: AO0yUKUcyg+cpM2L5hMOD1p90tEpVW/nx5lFjQyDNzeHhzjqQ++IHkDb N1LlDzR0Aquz+SwDIvEb/0D8hFY4AuZ9lMOq308= X-Received: by 2002:a05:6830:1483:b0:68b:cd1e:1ef1 with SMTP id s3-20020a056830148300b0068bcd1e1ef1mr2274617otq.7.1679579656288; Thu, 23 Mar 2023 06:54:16 -0700 (PDT) MIME-Version: 1.0 References: <20230322224403.35742-1-robdclark@gmail.com> In-Reply-To: From: Rob Clark Date: Thu, 23 Mar 2023 06:54:05 -0700 Message-ID: Subject: Re: [RFC] drm/scheduler: Unwrap job dependencies To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: dri-devel@lists.freedesktop.org, Rob Clark , Luben Tuikov , David Airlie , Daniel Vetter , Sumit Semwal , open list , "open list:DMA BUFFER SHARING FRAMEWORK" , "moderated list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Thu, Mar 23, 2023 at 12:35=E2=80=AFAM Christian K=C3=B6nig wrote: > > Am 22.03.23 um 23:44 schrieb Rob Clark: > > From: Rob Clark > > > > Container fences have burner contexts, which makes the trick to store a= t > > most one fence per context somewhat useless if we don't unwrap array or > > chain fences. > > Mhm, we intentionally kept them not unwrapped since this way they only > occupy one fence slot. > > But it might be better to unwrap them if you add many of those dependenci= es. > > > > > Signed-off-by: Rob Clark > > --- > > tbh, I'm not sure why we weren't doing this already, unless there is > > something I'm overlooking > > > > drivers/gpu/drm/scheduler/sched_main.c | 43 +++++++++++++++++--------= - > > 1 file changed, 28 insertions(+), 15 deletions(-) > > > > diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/s= cheduler/sched_main.c > > index c2ee44d6224b..f59e5335afbb 100644 > > --- a/drivers/gpu/drm/scheduler/sched_main.c > > +++ b/drivers/gpu/drm/scheduler/sched_main.c > > @@ -41,20 +41,21 @@ > > * 4. Entities themselves maintain a queue of jobs that will be sched= uled on > > * the hardware. > > * > > * The jobs in a entity are always scheduled in the order that they w= ere pushed. > > */ > > > > #include > > #include > > #include > > #include > > +#include > > #include > > #include > > > > #include > > #include > > #include > > #include > > > > #define CREATE_TRACE_POINTS > > #include "gpu_scheduler_trace.h" > > @@ -665,41 +666,27 @@ void drm_sched_job_arm(struct drm_sched_job *job) > > sched =3D entity->rq->sched; > > > > job->sched =3D sched; > > job->s_priority =3D entity->rq - sched->sched_rq; > > job->id =3D atomic64_inc_return(&sched->job_id_count); > > > > drm_sched_fence_init(job->s_fence, job->entity); > > } > > EXPORT_SYMBOL(drm_sched_job_arm); > > > > -/** > > - * drm_sched_job_add_dependency - adds the fence as a job dependency > > - * @job: scheduler job to add the dependencies to > > - * @fence: the dma_fence to add to the list of dependencies. > > - * > > - * Note that @fence is consumed in both the success and error cases. > > - * > > - * Returns: > > - * 0 on success, or an error on failing to expand the array. > > - */ > > -int drm_sched_job_add_dependency(struct drm_sched_job *job, > > - struct dma_fence *fence) > > +static int _add_dependency(struct drm_sched_job *job, struct dma_fence= *fence) > > Please keep the drm_sched_job_ prefix here even for static functions. > The symbol _add_dependency just sucks in a backtrace, especially when > it's tail optimized. > > > { > > struct dma_fence *entry; > > unsigned long index; > > u32 id =3D 0; > > int ret; > > > > - if (!fence) > > - return 0; > > - > > /* Deduplicate if we already depend on a fence from the same cont= ext. > > * This lets the size of the array of deps scale with the number = of > > * engines involved, rather than the number of BOs. > > */ > > xa_for_each(&job->dependencies, index, entry) { > > if (entry->context !=3D fence->context) > > continue; > > > > if (dma_fence_is_later(fence, entry)) { > > dma_fence_put(entry); > > @@ -709,20 +696,46 @@ int drm_sched_job_add_dependency(struct drm_sched= _job *job, > > } > > return 0; > > } > > > > ret =3D xa_alloc(&job->dependencies, &id, fence, xa_limit_32b, GF= P_KERNEL); > > if (ret !=3D 0) > > dma_fence_put(fence); > > > > return ret; > > } > > + > > +/** > > + * drm_sched_job_add_dependency - adds the fence as a job dependency > > + * @job: scheduler job to add the dependencies to > > + * @fence: the dma_fence to add to the list of dependencies. > > + * > > + * Note that @fence is consumed in both the success and error cases. > > + * > > + * Returns: > > + * 0 on success, or an error on failing to expand the array. > > + */ > > +int drm_sched_job_add_dependency(struct drm_sched_job *job, > > + struct dma_fence *fence) > > Maybe name the new function drm_sched_job_unwrap_add_dependency or > something like this. > > I need to double check, but I think for some cases we don't need or > don't even want this in the driver. I'd be curious to know the cases where you don't want this.. one thing I was thinking about, what if you have a container fence with two contained fences. One is on the same ctx as the job, one is not but signals sooner. You end up artificially waiting on both, which seems sub-optimal. Anyways, I can make this a new entrypoint which unwraps, and/or rename the internal static function, if we think this is a good idea. BR, -R > Christian. > > > +{ > > + struct dma_fence_unwrap iter; > > + struct dma_fence *f; > > + int ret =3D 0; > > + > > + dma_fence_unwrap_for_each (f, &iter, fence) { > > + ret =3D _add_dependency(job, f); > > + if (ret) > > + break; > > + } > > + > > + return ret; > > +} > > EXPORT_SYMBOL(drm_sched_job_add_dependency); > > > > /** > > * drm_sched_job_add_resv_dependencies - add all fences from the resv= to the job > > * @job: scheduler job to add the dependencies to > > * @resv: the dma_resv object to get the fences from > > * @usage: the dma_resv_usage to use to filter the fences > > * > > * This adds all fences matching the given usage from @resv to @job. > > * Must be called with the @resv lock held. >