public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Cc: alsa-devel@alsa-project.org, lars@metafoo.de,
	lgirdwood@gmail.com, patches@opensource.wolfsonmicro.com
Subject: Re: [PATCH 2/2] ASoC: dapm: Add cache to speed up adding of routes
Date: Thu, 7 May 2015 13:48:11 +0100	[thread overview]
Message-ID: <20150507124811.GV15510@sirena.org.uk> (raw)
In-Reply-To: <1430994839-32584-2-git-send-email-ckeepax@opensource.wolfsonmicro.com>


[-- Attachment #1.1: Type: text/plain, Size: 2673 bytes --]

On Thu, May 07, 2015 at 11:33:59AM +0100, Charles Keepax wrote:
> 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

The idea here is good but I'm having a hard time loving the
implementation.  It feels like it's hacking this specific implementation
in many different places without really abstracting things - having a
neat trick hidden in one place would be one thinng but it's spread
through several different places.

> +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);
> +		}

This will not be happy if there are fewer than n entries to look at.

>  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)

The fact that we're directly using the path structure as the type for
the cache here is a warning flag, it means that everywhere that knows
there is a cache at all needs to know about the specific type of the
cache.  If we were to improve the cache in the future, for example doing
something like building a hash that maps names to widgets for the
duration of probe, then everywhere would need to change.

> +	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;
> +	}
> +

This is the only place where we have _check_path_cache() calls so n is
always 2 here and it is unclear where that number comes from or what it
means without going and peering at the implementation and the commit
log.  It seems it would be better to hide that number inside the
function.

> +skip_search:
> +	if (cache) {
> +		cache->sink = wsink;
> +		cache->source = wsource;
> +	}
> +

Putting this into a store hit function would be good.

>  	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);

Should we just have the cache in the dapm context or the card instead of
locally?  It's only two pointers at the minute so there doesn't seem to
be much cost from keeping it around and it might generate somme more
hits for some use cases.  Or to put it another way why is the cache
optional and created and re-created here like this?

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



  parent reply	other threads:[~2015-05-07 13:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-07 10:33 [PATCH 1/2] ASoC: dapm: Break out of widget search when source and sink are located Charles Keepax
2015-05-07 10:33 ` [PATCH 2/2] ASoC: dapm: Add cache to speed up adding of routes Charles Keepax
2015-05-07 11:22   ` Lars-Peter Clausen
2015-05-07 12:35     ` Charles Keepax
2015-05-07 12:39     ` Mike Looijmans
2015-05-07 13:16     ` Mark Brown
2015-05-07 12:48   ` Mark Brown [this message]
2015-05-07 13:52     ` Charles Keepax
2015-05-07 14:09       ` Mark Brown
2015-05-07 14:53     ` Lars-Peter Clausen
2015-05-07 16:33       ` Mark Brown
2015-05-07 11:24 ` [PATCH 1/2] ASoC: dapm: Break out of widget search when source and sink are located Lars-Peter Clausen
2015-05-07 11:25 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150507124811.GV15510@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=ckeepax@opensource.wolfsonmicro.com \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=patches@opensource.wolfsonmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox