From patchwork Sun Nov 5 11:01:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikko Perttunen X-Patchwork-Id: 10042083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D781560244 for ; Sun, 5 Nov 2017 11:20:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C20802922D for ; Sun, 5 Nov 2017 11:20:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6A4A29257; Sun, 5 Nov 2017 11:20:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 23D0D292EB for ; Sun, 5 Nov 2017 11:20:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5FBAF6E115; Sun, 5 Nov 2017 11:20:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0D4026E09A for ; Sun, 5 Nov 2017 11:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=u+/rNgP2x4CvhnYmkjIX2oQp5AbrDr93a3qxEJgxbeQ=; b=wclKiCgW3seY35XJfbAyaqS1HKnsqzk+5dedgxnMyW7Cb3XqWIAeUXPVY0dx0NPgzxve735tp95ppLmDAXi7s/krQ5gDhHPVhJnuAso4VsYoNWJUgImETVKddlYksuLsRXE6RSpsFiemo5/QzJF5kCKepSH8OHBO7IpoXJRClbarpkT8TrhOG1TyOWFAaFkPW2YoSsnWb4DTODHBvqYjn1j8ZUSVFmOiQzxmzHtDcjAhFwFbFl/r1MBEJk4qaYn7TmyhY6Fg2vf4UyeMUWd5152AB+/X5ZrByP2D0oHTLVsTBABDVN6YqqGQnEb46vfOQWJkPDPnrR+DjFFEXJ/FPQ==; Received: from dsl-hkibng22-54f983-249.dhcp.inet.fi ([84.249.131.249] helo=localhost.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1eBIgk-0006dR-Mw; Sun, 05 Nov 2017 13:02:02 +0200 From: Mikko Perttunen To: thierry.reding@gmail.com, jonathanh@nvidia.com Subject: [PATCH 08/10] drm/tegra: Implement dynamic channel allocation model Date: Sun, 5 Nov 2017 13:01:16 +0200 Message-Id: <20171105110118.15142-9-mperttunen@nvidia.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171105110118.15142-1-mperttunen@nvidia.com> References: <20171105110118.15142-1-mperttunen@nvidia.com> X-SA-Exim-Connect-IP: 84.249.131.249 X-SA-Exim-Mail-From: mperttunen@nvidia.com X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Cc: linux-tegra@vger.kernel.org, digetx@gmail.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Mikko Perttunen X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP In the traditional channel allocation model, a single hardware channel was allocated for each client. This is simple from an implementation perspective but prevents use of hardware scheduling. This patch implements a channel allocation model where when a user submits a job for a context, a hardware channel is allocated for that context. The same channel is kept for as long as there are incomplete jobs for that context. This way we can use hardware scheduling and channel isolation between userspace processes, but also prevent idling contexts from taking up hardware resources. For now, this patch only adapts VIC to the new model. Signed-off-by: Mikko Perttunen --- drivers/gpu/drm/tegra/drm.c | 46 ++++++++++++++++++++++++++ drivers/gpu/drm/tegra/drm.h | 7 +++- drivers/gpu/drm/tegra/vic.c | 79 +++++++++++++++++++++++---------------------- 3 files changed, 92 insertions(+), 40 deletions(-) diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index b964e18e3058..658bc8814f38 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -382,6 +382,51 @@ static int host1x_waitchk_copy_from_user(struct host1x_waitchk *dest, return 0; } +/** + * tegra_drm_context_get_channel() - Get a channel for submissions + * @context: Context for which to get a channel for + * + * Request a free hardware host1x channel for this user context, or if the + * context already has one, bump its refcount. + * + * Returns 0 on success, or -EBUSY if there were no free hardware channels. + */ +int tegra_drm_context_get_channel(struct tegra_drm_context *context) +{ + struct host1x_client *client = &context->client->base; + + mutex_lock(&context->lock); + + if (context->pending_jobs == 0) { + context->channel = host1x_channel_request(client->dev); + if (!context->channel) { + mutex_unlock(&context->lock); + return -EBUSY; + } + } + + context->pending_jobs++; + + mutex_unlock(&context->lock); + + return 0; +} + +/** + * tegra_drm_context_put_channel() - Put a previously gotten channel + * @context: Context which channel is no longer needed + * + * Decrease the refcount of the channel associated with this context, + * freeing it if the refcount drops to zero. + */ +void tegra_drm_context_put_channel(struct tegra_drm_context *context) +{ + mutex_lock(&context->lock); + if (--context->pending_jobs == 0) + host1x_channel_put(context->channel); + mutex_unlock(&context->lock); +} + static void tegra_drm_job_done(struct host1x_job *job) { struct tegra_drm_context *context = job->callback_data; @@ -737,6 +782,7 @@ static int tegra_open_channel(struct drm_device *drm, void *data, kfree(context); kref_init(&context->ref); + mutex_init(&context->lock); mutex_unlock(&fpriv->lock); return err; diff --git a/drivers/gpu/drm/tegra/drm.h b/drivers/gpu/drm/tegra/drm.h index 11d690846fd0..d0c3f1f779f6 100644 --- a/drivers/gpu/drm/tegra/drm.h +++ b/drivers/gpu/drm/tegra/drm.h @@ -78,9 +78,12 @@ struct tegra_drm_context { struct kref ref; struct tegra_drm_client *client; + unsigned int id; + + struct mutex lock; struct host1x_channel *channel; struct host1x_syncpt *syncpt; - unsigned int id; + unsigned int pending_jobs; }; struct tegra_drm_client_ops { @@ -95,6 +98,8 @@ struct tegra_drm_client_ops { void (*submit_done)(struct tegra_drm_context *context); }; +int tegra_drm_context_get_channel(struct tegra_drm_context *context); +void tegra_drm_context_put_channel(struct tegra_drm_context *context); int tegra_drm_submit(struct tegra_drm_context *context, struct drm_tegra_submit *args, struct drm_device *drm, struct drm_file *file); diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c index efe5f3af933e..0cacf023a890 100644 --- a/drivers/gpu/drm/tegra/vic.c +++ b/drivers/gpu/drm/tegra/vic.c @@ -33,7 +33,6 @@ struct vic { void __iomem *regs; struct tegra_drm_client client; - struct host1x_channel *channel; struct iommu_domain *domain; struct device *dev; struct clk *clk; @@ -161,28 +160,12 @@ static int vic_init(struct host1x_client *client) goto detach_device; } - vic->channel = host1x_channel_request(client->dev); - if (!vic->channel) { - err = -ENOMEM; - goto detach_device; - } - - client->syncpts[0] = host1x_syncpt_request(client->dev, 0); - if (!client->syncpts[0]) { - err = -ENOMEM; - goto free_channel; - } - err = tegra_drm_register_client(tegra, drm); if (err < 0) - goto free_syncpt; + goto detach_device; return 0; -free_syncpt: - host1x_syncpt_free(client->syncpts[0]); -free_channel: - host1x_channel_put(vic->channel); detach_device: if (tegra->domain) iommu_detach_device(tegra->domain, vic->dev); @@ -202,9 +185,6 @@ static int vic_exit(struct host1x_client *client) if (err < 0) return err; - host1x_syncpt_free(client->syncpts[0]); - host1x_channel_put(vic->channel); - if (vic->domain) { iommu_detach_device(vic->domain, vic->dev); vic->domain = NULL; @@ -221,7 +201,24 @@ static const struct host1x_client_ops vic_client_ops = { static int vic_open_channel(struct tegra_drm_client *client, struct tegra_drm_context *context) { - struct vic *vic = to_vic(client); + context->syncpt = host1x_syncpt_request(client->base.dev, 0); + if (!context->syncpt) + return -ENOMEM; + + return 0; +} + +static void vic_close_channel(struct tegra_drm_context *context) +{ + host1x_syncpt_free(context->syncpt); +} + +static int vic_submit(struct tegra_drm_context *context, + struct drm_tegra_submit *args, struct drm_device *drm, + struct drm_file *file) +{ + struct host1x_client *client = &context->client->base; + struct vic *vic = dev_get_drvdata(client->dev); int err; err = pm_runtime_get_sync(vic->dev); @@ -229,35 +226,41 @@ static int vic_open_channel(struct tegra_drm_client *client, return err; err = vic_boot(vic); - if (err < 0) { - pm_runtime_put(vic->dev); - return err; - } + if (err < 0) + goto put_vic; - context->channel = host1x_channel_get(vic->channel); - if (!context->channel) { - pm_runtime_put(vic->dev); - return -ENOMEM; - } + err = tegra_drm_context_get_channel(context); + if (err < 0) + goto put_vic; - context->syncpt = client->base.syncpts[0]; + err = tegra_drm_submit(context, args, drm, file); + if (err) + goto put_channel; return 0; + +put_channel: + tegra_drm_context_put_channel(context); +put_vic: + pm_runtime_put(vic->dev); + + return err; } -static void vic_close_channel(struct tegra_drm_context *context) +static void vic_submit_done(struct tegra_drm_context *context) { - struct vic *vic = to_vic(context->client); - - host1x_channel_put(context->channel); + struct host1x_client *client = &context->client->base; + struct vic *vic = dev_get_drvdata(client->dev); + tegra_drm_context_put_channel(context); pm_runtime_put(vic->dev); } static const struct tegra_drm_client_ops vic_ops = { .open_channel = vic_open_channel, .close_channel = vic_close_channel, - .submit = tegra_drm_submit, + .submit = vic_submit, + .submit_done = vic_submit_done, }; #define NVIDIA_TEGRA_124_VIC_FIRMWARE "nvidia/tegra124/vic03_ucode.bin" @@ -340,8 +343,6 @@ static int vic_probe(struct platform_device *pdev) vic->client.base.ops = &vic_client_ops; vic->client.base.dev = dev; vic->client.base.class = HOST1X_CLASS_VIC; - vic->client.base.syncpts = syncpts; - vic->client.base.num_syncpts = 1; vic->dev = dev; vic->config = vic_config;