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 B372CC7618A for ; Mon, 20 Mar 2023 17:01:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232936AbjCTRBM (ORCPT ); Mon, 20 Mar 2023 13:01:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232638AbjCTRAd (ORCPT ); Mon, 20 Mar 2023 13:00:33 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eae::600]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 250004C0F; Mon, 20 Mar 2023 09:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aIiwPN87+x8eX6MyDxhzqIdbrhINIXO4/lDVfZ4F6T3aaQlTH5oVRJQzTPNog0arTHwdYuIxgsMBFfHhxZ8x6+DjVCsHOEDFADuVbVfL+st4xDxj02KHfS5l8uT9ZLQo5mv2uVwwDkTm+kABpc9gM+naUX9OLZ1zETCbq5x4AoqljyIAV8mfOdWCPKdQVV6V2OK/YDwVCiv5Y9kS+btvdmOYNawwa5hioLJ4xVgf3+AIiAxwh6UczRIgxWxIAXu05T54epwKOISeQloBK6AguB1CxeNPG503jLsg71cRQ3Sfo6/mpuzc69TiGZ+TxJk9DpeKdvmkX1FQ9tYuoiRm/Q== 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=c9d8g+D7cgBaHSkKEI1xXWyLloVAj2P0HYquGlLNu8w=; b=nl5voy+NScgRISPTGTFfRGHqozMqKo0yMlVAeUjEvwYWQr5BKwfA8YZlWfN3b45YFVWPSpwykc4tdJpv2VJVm4uuf0hzNqCsiKHVYT03HRzWsjvEbhQpNBMrT2vUzAdNwF8oJMfAYEqhPZ6cOYo9yz01eVYcCJ5vTVHcGC6KsgQOqcuyAPnIvORodx3Np+IH2fULoAJYBgn5/7bkNeX9SlWg2DjEuo15qIl3XpSlUIwl6dZG45yv+NdKa2QZSKRN4ye3l+OFRA8O2wEY2F0Omr9GMM1T3EtFw0xARqy0Zcr/dKJU1j3r1xtxGRduzX4dQsq9LnUFYJLO0ECDdbhpuQ== 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=c9d8g+D7cgBaHSkKEI1xXWyLloVAj2P0HYquGlLNu8w=; b=34rMvCeD2jObZx8vIf68p5W5B4uElUEiFE1gNyHHuQ4kyntPa0tIGmsaOI72TbwwF+0MdX9oX/nO7E36pcXQZCTtYw5fwnNNSqjvdHcfnoJAzOQONpnXXcpYysm1HE5APuWO6yAfjCCoFQny6zlZDWuy67UpkXfD3mqrwwXUhoM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by SN7PR12MB7297.namprd12.prod.outlook.com (2603:10b6:806:2ad::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Mon, 20 Mar 2023 16:52:23 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::d23f:bb1:df95:3918]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::d23f:bb1:df95:3918%4]) with mapi id 15.20.6178.037; Mon, 20 Mar 2023 16:52:23 +0000 Message-ID: <25bd9a77-a703-6eb6-e142-5da9e54754a0@amd.com> Date: Mon, 20 Mar 2023 17:52:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v2 01/23] drm/msm: Pre-allocate hw_fence Content-Language: en-US To: Rob Clark , dri-devel@lists.freedesktop.org Cc: Daniel Vetter , freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Sumit Semwal , open list , "open list:DMA BUFFER SHARING FRAMEWORK" , "moderated list:DMA BUFFER SHARING FRAMEWORK" References: <20230320144356.803762-1-robdclark@gmail.com> <20230320144356.803762-2-robdclark@gmail.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: <20230320144356.803762-2-robdclark@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR3P281CA0187.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a4::15) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8PR12MB3587:EE_|SN7PR12MB7297:EE_ X-MS-Office365-Filtering-Correlation-Id: c023df50-08f5-4aba-28a4-08db29637a11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v5Mw+iL0mPTy3qaBFr4FBOUFvAzDV3W6Qdlx5KhUB50lo0bvCP7N71EYD7b5aWbyoM/kxh6n/1h7cVKZzyr7zePi+tn9ZfoHgvX6iF/paaAtz1aaXl0tm+3NwJFL1iCMgYtkD/B+/tOMQxiQs/dZcSl6vGLg/S5Bs2FZfsGLVbi1dqfEkxXOdtO6Hwkl9S3coapTrqapwnDMHimYRsbNMXue/qHKhOhu2zL9iKw2nnw/eQiKaiVk5WTFTvhvt2hTneoHS4ldK5QzpJAwJ+hYW92iHhF26DPTAiOmzgQSh+jdm+DAPKKpu4Ajfz2YJdifG3cn9jYglH45HsfA/X4IMKhqi/Te8NYKDZpweAlcWDOxyzLwfKBnsCOb89C+ddPCJpjb3nTz6tkp5sRkk9RhVegPrzC2ZZkY2wCpyufzd7Wk1EKM2T/a4/ABr+d/LATTmWiDNMQO5w42Me15/MF4Mm5MCCzNdyZdZTt2bkFeVV4ZbGtxzVoo/Y6Rk+7F91RdXm/7aGX0XZSpiJAuXZMr8F0gNK5baJGRQV4GiYSnApg0PoZreoBHSH+j0gkQFHOL/d/aIjGc+SdvOct786OPxWZSFD9XNzUYQMCQ63BrWjm+1jLMQ5JhVBclFmRsK6t9xYYpLx6igsfgQP4P3leHRTGCWLm3sZBQcWxh0f56BIZKORazZhhU3mRhj0dgT56nIeLSZg7ebRHtbMTQWFPWxEAhmP7KRa2ahQ0yIYLVtOU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(346002)(376002)(136003)(366004)(39860400002)(396003)(451199018)(316002)(54906003)(6666004)(38100700002)(66946007)(8676002)(4326008)(31686004)(66556008)(478600001)(66476007)(2906002)(6486002)(41300700001)(2616005)(86362001)(186003)(6512007)(8936002)(6506007)(83380400001)(31696002)(36756003)(5660300002)(7416002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?djJ3cEhvMWpUbWFtZXhtekN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= =?utf-8?B?MjJ1UjRiZCttdDhpbDlibmVSZy9obE5xcDFGdndkZGtXcGgrRGlmNFNsN1F0?= =?utf-8?B?U1l0Q0dtTDJ5cjNueU16NWplbVZzM2lrZDNaQjRtNys5TGcwb3FmSHpXcS8v?= =?utf-8?B?MkVrNUluSy9hMlcyellXbGVlbWhUQUR6bEk2SDdPUVFJMU0yL3VKS2E1ZTh3?= =?utf-8?B?cThCS1dRVUw2ZktZTVdzUUJYNnVEUFdDR2x0SGpPeDNvbG9JUWY0L29Wd1dV?= =?utf-8?B?TFlwaWhYQ1NrMnRva1NaMkNiSjdDck13Z3pYS3FlbklPS0thOW1wYjluTWJr?= =?utf-8?B?MWV2cjJtUTQ2UjVNUUhzRmdlenJmQnlORlFhWHRoakw2bXk1bGZoV2tTMWtU?= =?utf-8?Q?va4O+tGu+RPyWc4jdayAVlIuRZtCUvrapq8OJMo/S9Dd?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c023df50-08f5-4aba-28a4-08db29637a11 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2023 16:52:23.2002 (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: rdbn+sS7mUDRbNlJ9IjtrDYyx6vzQaP/ZyqAcdA8QhFt+/pzuaXSsLhajeTC9xOE X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7297 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 20.03.23 um 15:43 schrieb Rob Clark: > From: Rob Clark > > Avoid allocating memory in job_run() by pre-allocating the hw_fence. > > Signed-off-by: Rob Clark > --- > drivers/gpu/drm/msm/msm_fence.c | 12 +++++++++--- > drivers/gpu/drm/msm/msm_fence.h | 3 ++- > drivers/gpu/drm/msm/msm_gem_submit.c | 7 +++++++ > drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- > 4 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/msm/msm_fence.c b/drivers/gpu/drm/msm/msm_fence.c > index 56641408ea74..bab3d84f1686 100644 > --- a/drivers/gpu/drm/msm/msm_fence.c > +++ b/drivers/gpu/drm/msm/msm_fence.c > @@ -99,7 +99,7 @@ static const struct dma_fence_ops msm_fence_ops = { > }; > > struct dma_fence * > -msm_fence_alloc(struct msm_fence_context *fctx) > +msm_fence_alloc(void) > { > struct msm_fence *f; > > @@ -107,10 +107,16 @@ msm_fence_alloc(struct msm_fence_context *fctx) > if (!f) > return ERR_PTR(-ENOMEM); > > + return &f->base; > +} > + > +void > +msm_fence_init(struct dma_fence *fence, struct msm_fence_context *fctx) > +{ > + struct msm_fence *f = to_msm_fence(fence); > + > f->fctx = fctx; > > dma_fence_init(&f->base, &msm_fence_ops, &fctx->spinlock, > fctx->context, ++fctx->last_fence); > - > - return &f->base; > } > diff --git a/drivers/gpu/drm/msm/msm_fence.h b/drivers/gpu/drm/msm/msm_fence.h > index 7f1798c54cd1..f913fa22d8fe 100644 > --- a/drivers/gpu/drm/msm/msm_fence.h > +++ b/drivers/gpu/drm/msm/msm_fence.h > @@ -61,7 +61,8 @@ void msm_fence_context_free(struct msm_fence_context *fctx); > bool msm_fence_completed(struct msm_fence_context *fctx, uint32_t fence); > void msm_update_fence(struct msm_fence_context *fctx, uint32_t fence); > > -struct dma_fence * msm_fence_alloc(struct msm_fence_context *fctx); > +struct dma_fence * msm_fence_alloc(void); > +void msm_fence_init(struct dma_fence *fence, struct msm_fence_context *fctx); > > static inline bool > fence_before(uint32_t a, uint32_t b) > diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c > index be4bf77103cd..2570c018b0cb 100644 > --- a/drivers/gpu/drm/msm/msm_gem_submit.c > +++ b/drivers/gpu/drm/msm/msm_gem_submit.c > @@ -41,6 +41,13 @@ static struct msm_gem_submit *submit_create(struct drm_device *dev, > if (!submit) > return ERR_PTR(-ENOMEM); > > + submit->hw_fence = msm_fence_alloc(); > + if (IS_ERR(submit->hw_fence)) { > + ret = PTR_ERR(submit->hw_fence); > + kfree(submit); > + return ERR_PTR(ret); > + } > + > ret = drm_sched_job_init(&submit->base, queue->entity, queue); > if (ret) { > kfree(submit); You probably need some error handling here or otherwise leak submit->hw_fence. Apart from that looks good to me. Christian. > diff --git a/drivers/gpu/drm/msm/msm_ringbuffer.c b/drivers/gpu/drm/msm/msm_ringbuffer.c > index 57a8e9564540..a62b45e5a8c3 100644 > --- a/drivers/gpu/drm/msm/msm_ringbuffer.c > +++ b/drivers/gpu/drm/msm/msm_ringbuffer.c > @@ -18,7 +18,7 @@ static struct dma_fence *msm_job_run(struct drm_sched_job *job) > struct msm_gpu *gpu = submit->gpu; > int i; > > - submit->hw_fence = msm_fence_alloc(fctx); > + msm_fence_init(submit->hw_fence, fctx); > > for (i = 0; i < submit->nr_bos; i++) { > struct drm_gem_object *obj = &submit->bos[i].obj->base;