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 606D5C64ED9 for ; Tue, 21 Feb 2023 19:40:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbjBUTkJ (ORCPT ); Tue, 21 Feb 2023 14:40:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbjBUTkH (ORCPT ); Tue, 21 Feb 2023 14:40:07 -0500 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2084.outbound.protection.outlook.com [40.107.96.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 352CC2CC61; Tue, 21 Feb 2023 11:40:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fwdvHTmJKX5JbLkIXhDNsHbTdrHyeDdBkT8c/Mhnlgijgl4zLtGAKyhBKI++49fpSVdrIdeiyClwvzuRgWnNYLC95jBfv9l8c2icSr/dmYQyZBFu27NbZxEw7JXvzzlvh12KQ7vB/AwztVBQ8HSYfwFWhrsK8epW8inbztGh12exqq1+hhXr20HL8h34m2k8W7VYIuWuzjmD4wEnigbASjKOBmQ27qPmUcCgzuz/f1p4CZpxnT5Jk/DoEzxi6h0N8mV2YRn+M7nLkgw2qprifrfqF0FJGokVoHV9hVh3m7u22aT5nYOWI83QvTmm+GI2OnhjZqLZmCENlxkTxEvWFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1xp+gxamV+PWsFQh/1Bw1ioRLDwnPxBqbFOy78zM2XY=; b=cxEhYahqPAF0VPCWu7Jm91XH2gdrONlSnfvlHAMc6pY4GNJRnLIAgqe7qVR2oL18+FHUIEgH1QllJXszUq8AzamAIVVeOh+bgcVogHXG5UdDr8uWorIvnzIAdcZrWE5P2pp5rBBF7s4DhpJoPjkwcblGZkOJAilJGLUAtECqIhjiwsvWxmZok5HqxUH+gFv+ET7bAyP3W+PXTYgS1/eS4gkDbOnKpw1ck4WL5h2htHXoZGremvezZf7tcAAww9tOiIop/b5H+BFUG3xusQKXxfbsEkNn1PhdrHwIE96h019BdYBSfcLwc5Xb46c6Xguk+SI2YAyTy87vOVXN304Z4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1xp+gxamV+PWsFQh/1Bw1ioRLDwnPxBqbFOy78zM2XY=; b=mzlHx225/FzZw1yTFrKXGNd4Qlwsyv3Z44pgoMSjyLAXcvR9f4ahafnuplPlehfzBogjgELbSfBLDjHxWVBHRXt0yrhgpn+utylQXCovYpZ3YFRrvThdJf7sh0uSMhAqpe67TvgNDfUyDk4B798zK1YtvxS76fWnqKo4a4MupWA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB3370.namprd12.prod.outlook.com (2603:10b6:5:38::25) by DM6PR12MB4436.namprd12.prod.outlook.com (2603:10b6:5:2a3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.21; Tue, 21 Feb 2023 19:40:02 +0000 Received: from DM6PR12MB3370.namprd12.prod.outlook.com ([fe80::4df2:b32a:e628:c57e]) by DM6PR12MB3370.namprd12.prod.outlook.com ([fe80::4df2:b32a:e628:c57e%7]) with mapi id 15.20.6111.021; Tue, 21 Feb 2023 19:40:02 +0000 Message-ID: <1da7a010-eb22-0044-b68a-44ffd76dc471@amd.com> Date: Tue, 21 Feb 2023 14:40:00 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Content-Language: en-CA To: Rob Clark , 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 , Rob Clark , David Airlie , Sumit Semwal , =?UTF-8?Q?Christian_K=c3=b6nig?= , open list , "open list:DMA BUFFER SHARING FRAMEWORK" , "moderated list:DMA BUFFER SHARING FRAMEWORK" References: <20230218211608.1630586-1-robdclark@gmail.com> <20230218211608.1630586-9-robdclark@gmail.com> From: Luben Tuikov Subject: Re: [PATCH v4 08/14] drm/scheduler: Add fence deadline support In-Reply-To: <20230218211608.1630586-9-robdclark@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: YT4P288CA0090.CANP288.PROD.OUTLOOK.COM (2603:10b6:b01:d0::23) To DM6PR12MB3370.namprd12.prod.outlook.com (2603:10b6:5:38::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3370:EE_|DM6PR12MB4436:EE_ X-MS-Office365-Filtering-Correlation-Id: 7dcf29d6-ad4b-49d8-a5d9-08db14436cc2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: za94yaP9jRmjzOBxSx5Pppt3dGNWThxcjeuZonqJ2sr5npQoIv+qE0nmzxmiGwzS6Onjfk3ETV7Wrp3jM9hEztXo8fFDK6d5k5yBTRRlCUIslGwDCXhH14Fku740WK9DX2SXRXv5DtpBYNMhLRmSfrLakVLLAqtCjyvuDjv9m0sbfFHobxjlcQbUa4cxBIVWNc2dV2mNU1kp0jdNiZz5Am+Z5TZ00YE4ku3adRM0x9nDUgsy9Dfbf4ZqMTHLf6mkxkAE/RNRq3Av3z7RpU5hOwbIVZ48vhqtBvaA1lo34WpG011nvAo4E4A3N3feKJRGVCvnCO4rn7TQjD0R7J6RuhdUl2rpfxJ7SXZRtlYTGzTG5utmo9Qo91Zy4VlULUG903lxv9VEqblzEX+nYWrdqKhAAmi+7+Pu084n4icMPKEsfQEAMI1MwSHn+42Blq62WcnYaOJdVobjWgotdtgck81YlZRt+uIqwHYSGybbaOkpVlGCUY6OP2l2n3KrJCkTvEGqHx7J5osxHTwyK0SBszVRxyp2XFa4RnRmQ3e37vkFHvPXJZvH33ysyCrLqNmHGdbMZ6nmmz+gJDsK7BFDCyefJJAFRYClx2MBEZPNTRH0KaIUeEJz7fDn3TskNLd5gWr6nGJ0lRQL1vsmRbEGc06arIZjKycGuKfzk3snizeKatv61/mw08bG6xBUNDDH33q+kEn+gBMQUtLNZ/oMElET8X+1vj4wf1QuUPnLvlY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3370.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(376002)(366004)(396003)(136003)(346002)(451199018)(31686004)(8936002)(31696002)(36756003)(86362001)(41300700001)(5660300002)(44832011)(7416002)(2906002)(83380400001)(38100700002)(66946007)(66556008)(66476007)(478600001)(8676002)(6486002)(54906003)(316002)(26005)(55236004)(53546011)(186003)(6512007)(2616005)(4326008)(6506007)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam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hNTM2MGxVVkoraDhVQjJIeERQbm1oY2dF?= =?utf-8?B?NDJMRXB4WG9hSk1WYnRiak1yTWxwbmd4RTZDTkRKQ0FwRWNGSXh1NlJlREM0?= =?utf-8?B?Vk9mWGdaWEZQMlIvQ1I3NkdqOTU4em9yTVRTL0dvby9PRmgza096NVF5cGtQ?= =?utf-8?B?VHJrZC8yK2JkSWJUcUh0VkVrc2RENzAwRFZwVzlaSjNFcm9wa3E2YnlaSFkz?= =?utf-8?B?dE43UjBRVFlBeEMzZkxBbXRoS1d3Q3NTbUJVcDdhbFd4ZGpWb1BoQzZDZGNj?= =?utf-8?B?VmtGaGVybkQ4UlBYcEJ2K0ZCRTRsVGUrUUI3ck9qdzVJK3BVaTJqTjRhNk8z?= =?utf-8?Q?eJUPXnmemCAW45gsZ1NZTrfKe?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7dcf29d6-ad4b-49d8-a5d9-08db14436cc2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3370.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Feb 2023 19:40:02.5148 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5+2/yJ+fN3SNWmkii9gfmSXnUyIRe/CjyeHugHrKqp2cUtbTDBLixBhxf4ARD1gN X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4436 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-02-18 16:15, Rob Clark wrote: > As the finished fence is the one that is exposed to userspace, and > therefore the one that other operations, like atomic update, would > block on, we need to propagate the deadline from from the finished > fence to the actual hw fence. > > v2: Split into drm_sched_fence_set_parent() (ckoenig) > v3: Ensure a thread calling drm_sched_fence_set_deadline_finished() sees > fence->parent set before drm_sched_fence_set_parent() does this > test_bit(DMA_FENCE_FLAG_HAS_DEADLINE_BIT). > > Signed-off-by: Rob Clark Looks good. This patch is Acked-by: Luben Tuikov -- Regards, Luben > --- > drivers/gpu/drm/scheduler/sched_fence.c | 46 +++++++++++++++++++++++++ > drivers/gpu/drm/scheduler/sched_main.c | 2 +- > include/drm/gpu_scheduler.h | 8 +++++ > 3 files changed, 55 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/scheduler/sched_fence.c b/drivers/gpu/drm/scheduler/sched_fence.c > index 7fd869520ef2..43e2d4f5fe3b 100644 > --- a/drivers/gpu/drm/scheduler/sched_fence.c > +++ b/drivers/gpu/drm/scheduler/sched_fence.c > @@ -123,6 +123,37 @@ static void drm_sched_fence_release_finished(struct dma_fence *f) > dma_fence_put(&fence->scheduled); > } > > +static void drm_sched_fence_set_deadline_finished(struct dma_fence *f, > + ktime_t deadline) > +{ > + struct drm_sched_fence *fence = to_drm_sched_fence(f); > + struct dma_fence *parent; > + unsigned long flags; > + > + spin_lock_irqsave(&fence->lock, flags); > + > + /* If we already have an earlier deadline, keep it: */ > + if (test_bit(DMA_FENCE_FLAG_HAS_DEADLINE_BIT, &f->flags) && > + ktime_before(fence->deadline, deadline)) { > + spin_unlock_irqrestore(&fence->lock, flags); > + return; > + } > + > + fence->deadline = deadline; > + set_bit(DMA_FENCE_FLAG_HAS_DEADLINE_BIT, &f->flags); > + > + spin_unlock_irqrestore(&fence->lock, flags); > + > + /* > + * smp_load_aquire() to ensure that if we are racing another > + * thread calling drm_sched_fence_set_parent(), that we see > + * the parent set before it calls test_bit(HAS_DEADLINE_BIT) > + */ > + parent = smp_load_acquire(&fence->parent); > + if (parent) > + dma_fence_set_deadline(parent, deadline); > +} > + > static const struct dma_fence_ops drm_sched_fence_ops_scheduled = { > .get_driver_name = drm_sched_fence_get_driver_name, > .get_timeline_name = drm_sched_fence_get_timeline_name, > @@ -133,6 +164,7 @@ static const struct dma_fence_ops drm_sched_fence_ops_finished = { > .get_driver_name = drm_sched_fence_get_driver_name, > .get_timeline_name = drm_sched_fence_get_timeline_name, > .release = drm_sched_fence_release_finished, > + .set_deadline = drm_sched_fence_set_deadline_finished, > }; > > struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f) > @@ -147,6 +179,20 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f) > } > EXPORT_SYMBOL(to_drm_sched_fence); > > +void drm_sched_fence_set_parent(struct drm_sched_fence *s_fence, > + struct dma_fence *fence) > +{ > + /* > + * smp_store_release() to ensure another thread racing us > + * in drm_sched_fence_set_deadline_finished() sees the > + * fence's parent set before test_bit() > + */ > + smp_store_release(&s_fence->parent, dma_fence_get(fence)); > + if (test_bit(DMA_FENCE_FLAG_HAS_DEADLINE_BIT, > + &s_fence->finished.flags)) > + dma_fence_set_deadline(fence, s_fence->deadline); > +} > + > struct drm_sched_fence *drm_sched_fence_alloc(struct drm_sched_entity *entity, > void *owner) > { > diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c > index 4e6ad6e122bc..007f98c48f8d 100644 > --- a/drivers/gpu/drm/scheduler/sched_main.c > +++ b/drivers/gpu/drm/scheduler/sched_main.c > @@ -1019,7 +1019,7 @@ static int drm_sched_main(void *param) > drm_sched_fence_scheduled(s_fence); > > if (!IS_ERR_OR_NULL(fence)) { > - s_fence->parent = dma_fence_get(fence); > + drm_sched_fence_set_parent(s_fence, fence); > /* Drop for original kref_init of the fence */ > dma_fence_put(fence); > > diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h > index 9db9e5e504ee..8b31a954a44d 100644 > --- a/include/drm/gpu_scheduler.h > +++ b/include/drm/gpu_scheduler.h > @@ -280,6 +280,12 @@ struct drm_sched_fence { > */ > struct dma_fence finished; > > + /** > + * @deadline: deadline set on &drm_sched_fence.finished which > + * potentially needs to be propagated to &drm_sched_fence.parent > + */ > + ktime_t deadline; > + > /** > * @parent: the fence returned by &drm_sched_backend_ops.run_job > * when scheduling the job on hardware. We signal the > @@ -568,6 +574,8 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity, > enum drm_sched_priority priority); > bool drm_sched_entity_is_ready(struct drm_sched_entity *entity); > > +void drm_sched_fence_set_parent(struct drm_sched_fence *s_fence, > + struct dma_fence *fence); > struct drm_sched_fence *drm_sched_fence_alloc( > struct drm_sched_entity *s_entity, void *owner); > void drm_sched_fence_init(struct drm_sched_fence *fence,