From patchwork Sun Nov 5 11:01:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikko Perttunen X-Patchwork-Id: 10042091 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 EA85B60244 for ; Sun, 5 Nov 2017 11:20:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D538A292C1 for ; Sun, 5 Nov 2017 11:20:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA47B292E1; Sun, 5 Nov 2017 11:20:58 +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 896FF292C1 for ; Sun, 5 Nov 2017 11:20:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD1066E149; Sun, 5 Nov 2017 11:20:56 +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 E663C6E195 for ; Sun, 5 Nov 2017 11:20:54 +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=9wlwmKXqgl/Elybz1Qan7ErFboN+DxZ01LitWkVkXfc=; b=pX/1YwIC08KMZtjgapIC4Rf8AboFLxlrHmJYf1mz3ClfgMKjqsuJtDj8/kblL/tkiWnjjYGEZr7GOJTFp569SMfvHAq4UCKFYhFHStW+DA7DhVXVeWaNMAVovVSSqJBPNuMYfF9ALwDmbO9cYt+jgvpiPoH4OlJQzbs67+zqMXZTZE7y97l6sc+utQ3/oFosd1CGODEUeohvPEDXQxkO87TAu1a7OE1w8RhxpPfPu41qXpbTmyWUmAys3de7IYLQykIw2sc2JTT8IEgNsTbxizQect0dJmkLMniCa49oU9Khe3BwyyBh5IWmY59+nU28ss3cONGS4uY6NR14VS2IfA==; 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-7l; Sun, 05 Nov 2017 13:02:02 +0200 From: Mikko Perttunen To: thierry.reding@gmail.com, jonathanh@nvidia.com Subject: [PATCH 03/10] gpu: host1x: Add lock around channel allocation Date: Sun, 5 Nov 2017 13:01:11 +0200 Message-Id: <20171105110118.15142-4-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 With the new channel allocation model, multiple threads can be allocating channels simultaneously. Therefore we need to add a lock around the code. Signed-off-by: Mikko Perttunen --- drivers/gpu/host1x/channel.c | 7 +++++++ drivers/gpu/host1x/channel.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/drivers/gpu/host1x/channel.c b/drivers/gpu/host1x/channel.c index 2fb93c27c1d9..9d8cad12f9d8 100644 --- a/drivers/gpu/host1x/channel.c +++ b/drivers/gpu/host1x/channel.c @@ -42,6 +42,8 @@ int host1x_channel_list_init(struct host1x_channel_list *chlist, bitmap_zero(chlist->allocated_channels, num_channels); + mutex_init(&chlist->lock); + return 0; } @@ -111,8 +113,11 @@ static struct host1x_channel *acquire_unused_channel(struct host1x *host) unsigned int max_channels = host->info->nb_channels; unsigned int index; + mutex_lock(&chlist->lock); + index = find_first_zero_bit(chlist->allocated_channels, max_channels); if (index >= max_channels) { + mutex_unlock(&chlist->lock); dev_err(host->dev, "failed to find free channel\n"); return NULL; } @@ -121,6 +126,8 @@ static struct host1x_channel *acquire_unused_channel(struct host1x *host) set_bit(index, chlist->allocated_channels); + mutex_unlock(&chlist->lock); + return &chlist->channels[index]; } diff --git a/drivers/gpu/host1x/channel.h b/drivers/gpu/host1x/channel.h index 7068e42d42df..e68a8ae9a670 100644 --- a/drivers/gpu/host1x/channel.h +++ b/drivers/gpu/host1x/channel.h @@ -29,6 +29,8 @@ struct host1x_channel; struct host1x_channel_list { struct host1x_channel *channels; + + struct mutex lock; unsigned long *allocated_channels; };