Received: by 10.223.164.202 with SMTP id h10csp4331544wrb; Wed, 29 Nov 2017 04:51:06 -0800 (PST) X-Google-Smtp-Source: AGs4zMY5z4KBRXFcMkPs/fxnsXA3ONYjQwKIOXt6ev6vA36YVy7pwFrQrQe8U2mvBcxSZALgX8Gz X-Received: by 10.99.109.2 with SMTP id i2mr2718887pgc.269.1511959866268; Wed, 29 Nov 2017 04:51:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511959866; cv=none; d=google.com; s=arc-20160816; b=qpeQ6PpcFdsySZubJ0R7FLMKWVVXJ0mQys7/rMLoNemXpz8Em4UQEqpFNGB6/CX9qH 1QPsIAnXNzI4iVqq9JFO8RjECk6fvyf2exWdbAGizbm4NRJXGwrMPVmjrngQdXFtlHD5 qmJ45IDXA5Sqo1ElNdmdvHa2TRpQhPrCpnZhDgv780FKdd7jaX/FyYZ6R9VFV0QExX2d ZFv9NLGMR5fhW634WxIekEM/QRayq3FUzyq9JMPBhe+dfNrxTs5SGESb1yMC4c8OMhRM Goc80GS03K9N/+OfdDaJJDXGdvgn+S4qmRsu8bt5Lnvz962QxXoH7GDlt81VoWbWWmA3 jahw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:dkim-signature:arc-authentication-results; bh=sgGV6KBzV/gyVZpskYRKEWK3/G0bMZMRmk+On66kw1U=; b=I7XRL48y97DXf1RaQhXmIzsZ2++JuUFO9Tu8kmvwyqGkGGYWsvNs4itXQhwuzde2rN kq+PrP5+xzffgztT1fuVL0Gm443l0z2SHtLYvlBz4W10Si5VzuDLN7DVE2uOCoO3VslB y5BtbAxa9NO/xRmGX9b7ObUWDwk4NNCDmOK+nArL3qZ1QENM6JnLC6mE5n5xEQXkdiLk xh1tJ71Q72kh9vMjN6m1+fNAm8DAP6vQcSVPzMtuQ2OjzpxpKpgCTZKtsuLObuG19YZO L5nx57P1s8jSu666j3iUhJ0E0OoDX4sfaMffaor2L0szMMiLWf3c3ylIkcX5y7nniugq b1wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kapsi.fi header.s=20161220 header.b=AwZBcUhf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si1233190pls.398.2017.11.29.04.50.55; Wed, 29 Nov 2017 04:51:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kapsi.fi header.s=20161220 header.b=AwZBcUhf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753850AbdK2JJ4 (ORCPT + 70 others); Wed, 29 Nov 2017 04:09:56 -0500 Received: from mail.kapsi.fi ([91.232.154.25]:42678 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752075AbdK2JJv (ORCPT ); Wed, 29 Nov 2017 04:09:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject; bh=sgGV6KBzV/gyVZpskYRKEWK3/G0bMZMRmk+On66kw1U=; b=AwZBcUhfrVYBAd2Qur79aKCTuFETMO9lOO/JtmuY0sFDdoSGoK60Ogr/cV1V0upsxRq7oS104jGxiXwqtIQiUDishqY1NoDG3L28RWanrF8kRWe0PgCpz+c5tk69iMoVunVwOUR1GNXQW+BZbkP4UqvQ8cdDEqDOX4RH55Pgfk0niJI4xQx7OZKLB5+w1oM/CmBHPVUvEWPimWQpHWiHWFMQkDAGO2YT5uWX7wk4sFdxptqUfB2Xb+asPApc1F1nvqw3AXFj7gALFGlxdzwVmrcId3Ix/JUj1hiXlVYleFLADw48jmmAEDDyNuuZtm6d1ed9HHXXi5cGCZ9GBLwA3A==; Received: from [62.209.167.43] (helo=[10.21.26.144]) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1eJyNI-00065T-WA; Wed, 29 Nov 2017 11:09:49 +0200 Subject: Re: [PATCH 06/10] drm/tegra: Deliver job completion callback to client To: Dmitry Osipenko , Mikko Perttunen , thierry.reding@gmail.com, jonathanh@nvidia.com References: <20171105110118.15142-1-mperttunen@nvidia.com> <20171105110118.15142-7-mperttunen@nvidia.com> <1afa1ba9-3103-3672-2e15-fb8c7de2520b@gmail.com> Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org From: Mikko Perttunen Message-ID: <08af58dc-c044-337b-281f-87dc9071d35e@kapsi.fi> Date: Wed, 29 Nov 2017 11:09:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1afa1ba9-3103-3672-2e15-fb8c7de2520b@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 62.209.167.43 X-SA-Exim-Mail-From: cyndis@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16.11.2017 18:40, Dmitry Osipenko wrote: > On 05.11.2017 14:01, Mikko Perttunen wrote: >> To allow client drivers to free resources when jobs have completed, >> deliver job completion callbacks to them. This requires adding >> reference counting to context objects, as job completion can happen >> after the userspace application has closed the context. As such, >> also add kref-based refcounting for contexts. >> >> Signed-off-by: Mikko Perttunen >> --- >> drivers/gpu/drm/tegra/drm.c | 27 ++++++++++++++++++++++++--- >> drivers/gpu/drm/tegra/drm.h | 4 ++++ >> 2 files changed, 28 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c >> index 2cdd054520bf..3e2a4a19412e 100644 >> --- a/drivers/gpu/drm/tegra/drm.c >> +++ b/drivers/gpu/drm/tegra/drm.c >> @@ -281,8 +281,11 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) >> return 0; >> } >> >> -static void tegra_drm_context_free(struct tegra_drm_context *context) >> +static void tegra_drm_context_free(struct kref *ref) >> { >> + struct tegra_drm_context *context = >> + container_of(ref, struct tegra_drm_context, ref); >> + >> context->client->ops->close_channel(context); >> kfree(context); >> } >> @@ -379,6 +382,16 @@ static int host1x_waitchk_copy_from_user(struct host1x_waitchk *dest, >> return 0; >> } >> >> +static void tegra_drm_job_done(struct host1x_job *job) >> +{ >> + struct tegra_drm_context *context = job->callback_data; >> + >> + if (context->client->ops->submit_done) >> + context->client->ops->submit_done(context); >> + >> + kref_put(&context->ref, tegra_drm_context_free); >> +} >> + >> int tegra_drm_submit(struct tegra_drm_context *context, >> struct drm_tegra_submit *args, struct drm_device *drm, >> struct drm_file *file) >> @@ -560,6 +573,9 @@ int tegra_drm_submit(struct tegra_drm_context *context, >> job->syncpt_id = syncpt.id; >> job->timeout = 10000; >> >> + job->done = tegra_drm_job_done; >> + job->callback_data = context; >> + >> if (args->timeout && args->timeout < 10000) >> job->timeout = args->timeout; >> >> @@ -567,8 +583,11 @@ int tegra_drm_submit(struct tegra_drm_context *context, >> if (err) >> goto fail; >> >> + kref_get(&context->ref); >> + >> err = host1x_job_submit(job); >> if (err) { >> + kref_put(&context->ref, tegra_drm_context_free); >> host1x_job_unpin(job); >> goto fail; >> } >> @@ -717,6 +736,8 @@ static int tegra_open_channel(struct drm_device *drm, void *data, >> if (err < 0) >> kfree(context); >> >> + kref_init(&context->ref); >> + >> mutex_unlock(&fpriv->lock); >> return err; >> } >> @@ -738,7 +759,7 @@ static int tegra_close_channel(struct drm_device *drm, void *data, >> } >> >> idr_remove(&fpriv->contexts, context->id); >> - tegra_drm_context_free(context); >> + kref_put(&context->ref, tegra_drm_context_free); >> >> unlock: >> mutex_unlock(&fpriv->lock); >> @@ -1026,7 +1047,7 @@ static int tegra_drm_context_cleanup(int id, void *p, void *data) >> { >> struct tegra_drm_context *context = p; >> >> - tegra_drm_context_free(context); >> + kref_put(&context->ref, tegra_drm_context_free); >> > > Probably won't hurt to add and use tegra_drm_context_get()/tegra_drm_context_put(). > Yeah, maybe we have enough places where this is called for it to make sense. From 1584256411329824441@xxx Thu Nov 16 20:37:30 +0000 2017 X-GM-THRID: 1583223852123537973 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread