From patchwork Thu May 7 10:33:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 6356861 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 14C3C9F32E for ; Thu, 7 May 2015 10:43:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E73B20386 for ; Thu, 7 May 2015 10:43:33 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id EAC1B20392 for ; Thu, 7 May 2015 10:43:31 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 08A402651DB; Thu, 7 May 2015 12:43:31 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 0E74E2606A5; Thu, 7 May 2015 12:42:58 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id A098A260682; Thu, 7 May 2015 12:42:56 +0200 (CEST) Received: from opensource.wolfsonmicro.com (opensource.wolfsonmicro.com [80.75.67.52]) by alsa0.perex.cz (Postfix) with ESMTP id B9A052606A5 for ; Thu, 7 May 2015 12:42:46 +0200 (CEST) Received: from localhost.localdomain (unknown [87.246.78.26]) by opensource.wolfsonmicro.com (Postfix) with ESMTPSA id 0F23B3B4101; Thu, 7 May 2015 11:42:46 +0100 (BST) From: Charles Keepax To: broonie@kernel.org Date: Thu, 7 May 2015 11:33:59 +0100 Message-Id: <1430994839-32584-2-git-send-email-ckeepax@opensource.wolfsonmicro.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1430994839-32584-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> References: <1430994839-32584-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> Cc: alsa-devel@alsa-project.org, lars@metafoo.de, lgirdwood@gmail.com, patches@opensource.wolfsonmicro.com Subject: [alsa-devel] [PATCH 2/2] ASoC: dapm: Add cache to speed up adding of routes X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Some CODECs have a significant number of DAPM routes and for each route, when it is added to the card, the entire card widget list must be searched. When adding routes it is very likely, however, that adjacent routes will require adjacent widgets. For example all the routes for a mux are likely added in a block and the sink widget will be the same each time and it is also quite likely that the source widgets are sequential located in the widget list. This patch adds an optional cache argument to snd_soc_dapm_add_route, if given, this argument will hold the source and sink widgets from the last call to snd_soc_dapm_add_route. A small search of the widget list will be made from those points for both the sink and source. Currently this search only checks both the last widget and the one adjacent to it. On wm8280 which has approximately 500 widgets and 30000 routes (one of the largest CODECs in mainline), the number of paths that hit the cache is 24000, which significantly improves probe time. Signed-off-by: Charles Keepax --- sound/soc/soc-dapm.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 38 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index ea3348e..95d3ea5 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -2585,8 +2585,26 @@ err: return ret; } +static struct snd_soc_dapm_widget * +dapm_check_path_cache(const char *name, struct snd_soc_dapm_widget *w, int n) +{ + int i; + + if (w) { + for (i = 0; i < n; i++) { + if (!strcmp(name, w->name)) + return w; + + w = list_next_entry(w, list); + } + } + + return NULL; +} + static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm, - const struct snd_soc_dapm_route *route) + const struct snd_soc_dapm_route *route, + struct snd_soc_dapm_path *cache) { struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; @@ -2610,6 +2628,14 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm, source = route->source; } + if (cache) { + wsink = dapm_check_path_cache(sink, cache->sink, 2); + wsource = dapm_check_path_cache(source, cache->source, 2); + + if (wsink && wsource) + goto skip_search; + } + /* * find src and dest widgets over all widgets but favor a widget from * current DAPM context @@ -2650,6 +2676,12 @@ static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm, return -ENODEV; } +skip_search: + if (cache) { + cache->sink = wsink; + cache->source = wsource; + } + ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control, route->connected); if (ret) @@ -2741,10 +2773,14 @@ int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, const struct snd_soc_dapm_route *route, int num) { int i, r, ret = 0; + struct snd_soc_dapm_path cache = { + .source = NULL, + .sink = NULL, + }; mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); for (i = 0; i < num; i++) { - r = snd_soc_dapm_add_route(dapm, route); + r = snd_soc_dapm_add_route(dapm, route, &cache); if (r < 0) { dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n", route->source,