Skip to contentSkip to conversation

ASoC: Factor write of widget power out into a separate function

PATCH New Mark Brown 1 participant 6 messages Oct 3, 2011

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/5 ASoC: Factor write of widget power out into a separate function

Split the decision about what the new power should be out from the implementation of that decision.

---
 sound/soc/soc-dapm.c |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)
sound/soc/soc-dapm.c +18 -11
index c277228..dcbd468 100644
@@ -1197,6 +1197,23 @@ static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
 	}
 }
 
+static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
+				  struct list_head *up_list,
+				  struct list_head *down_list)
+{
+	if (w->power == power)
+		return;
+
+	trace_snd_soc_dapm_widget_power(w, power);
+
+	if (power)
+		dapm_seq_insert(w, up_list, true);
+	else
+		dapm_seq_insert(w, down_list, false);
+
+	w->power = power;
+}
+
 static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
 				  struct list_head *up_list,
 				  struct list_head *down_list)
@@ -1241,17 +1258,7 @@ static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
 			}
 		}
 
-		if (w->power == power)
-			break;
-
-		trace_snd_soc_dapm_widget_power(w, power);
-
-		if (power)
-			dapm_seq_insert(w, up_list, true);
-		else
-			dapm_seq_insert(w, down_list, false);
-
-		w->power = power;
+		dapm_widget_set_power(w, power, up_list, down_list);
 		break;
 	}
 }
Signature · 1 line
1.7.6.3
author
#1 lore raw

PATCH 2/5 ASoC: Move bias level decision into main dapm_power_widgets()

Future patches will try to reduce the number of widgets we check on each DAPM run but we're still going to need to look and see if the devices is on at all so we can manage the overall device bias. Move these checks out into the main dapm_power_widgets() function so we don't have to think about them for now.

Once we're doing more incremental updates it'll probably be worth using refcounts for each bias level to avoid having to do the sweep over all widgets but that's not going to be where the big performance wins are.

---
 sound/soc/soc-dapm.c |   44 +++++++++++++++++++++++---------------------
 1 files changed, 23 insertions(+), 21 deletions(-)
sound/soc/soc-dapm.c +23 -21
index dcbd468..12bd01a 100644
@@ -1218,7 +1218,6 @@ static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
 				  struct list_head *up_list,
 				  struct list_head *down_list)
 {
-	struct snd_soc_dapm_context *d;
 	int power;
 
 	switch (w->id) {
@@ -1238,26 +1237,6 @@ static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
 		else
 			power = 1;
 
-		if (power) {
-			d = w->dapm;
-
-			/* Supplies and micbiases only bring the
-			 * context up to STANDBY as unless something
-			 * else is active and passing audio they
-			 * generally don't require full power.
-			 */
-			switch (w->id) {
-			case snd_soc_dapm_supply:
-			case snd_soc_dapm_micbias:
-				if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
-					d->target_bias_level = SND_SOC_BIAS_STANDBY;
-				break;
-			default:
-				d->target_bias_level = SND_SOC_BIAS_ON;
-				break;
-			}
-		}
-
 		dapm_widget_set_power(w, power, up_list, down_list);
 		break;
 	}
@@ -1302,6 +1281,29 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
 		dapm_power_one_widget(w, &up_list, &down_list);
 	}
 
+	list_for_each_entry(w, &card->widgets, list) {
+		if (w->power) {
+			d = w->dapm;
+
+			/* Supplies and micbiases only bring the
+			 * context up to STANDBY as unless something
+			 * else is active and passing audio they
+			 * generally don't require full power.
+			 */
+			switch (w->id) {
+			case snd_soc_dapm_supply:
+			case snd_soc_dapm_micbias:
+				if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
+					d->target_bias_level = SND_SOC_BIAS_STANDBY;
+				break;
+			default:
+				d->target_bias_level = SND_SOC_BIAS_ON;
+				break;
+			}
+		}
+
+	}
+
 	/* If there are no DAPM widgets then try to figure out power from the
 	 * event type.
 	 */
Signature · 1 line
1.7.6.3
author
#2 lore raw

PATCH 3/5 ASoC: Ensure all DAPM widgets have a power check callback

In reply to Mark Brown

Makes the code simpler.

---
 sound/soc/soc-dapm.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
sound/soc/soc-dapm.c +8 -3
index 12bd01a..8d76044 100644
@@ -857,6 +857,11 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
 	return power;
 }
 
+static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
+{
+	return 1;
+}
+
 static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
 			    struct snd_soc_dapm_widget *b,
 			    bool power_up)
@@ -1229,9 +1234,6 @@ static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
 		break;
 
 	default:
-		if (!w->power_check)
-			break;
-
 		if (!w->force)
 			power = w->power_check(w);
 		else
@@ -2090,6 +2092,9 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
 			break;
 		}
 
+		if (!w->power_check)
+			w->power_check = dapm_always_on_check_power;
+
 		/* Read the initial power state from the device */
 		if (w->reg >= 0) {
 			val = soc_widget_read(w, w->reg);
Signature · 1 line
1.7.6.3
author
#3 lore raw

PATCH 4/5 ASoC: Factor out widget power check operation

In reply to Mark Brown

We've got the same code in two different places, let's have it in a single place instead.

---
 sound/soc/soc-dapm.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)
sound/soc/soc-dapm.c +10 -11
index 8d76044..c1f3563 100644
@@ -771,6 +771,14 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w,
 }
 EXPORT_SYMBOL_GPL(dapm_reg_event);
 
+static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
+{
+	if (w->force)
+		return 1;
+	else
+		return w->power_check(w);
+}
+
 /* Generic check to see if a widget should be powered.
  */
 static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
@@ -840,13 +848,7 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
 		if (!path->sink)
 			continue;
 
-		if (path->sink->force) {
-			power = 1;
-			break;
-		}
-
-		if (path->sink->power_check &&
-		    path->sink->power_check(path->sink)) {
+		if (dapm_widget_power_check(path->sink)) {
 			power = 1;
 			break;
 		}
@@ -1234,10 +1236,7 @@ static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
 		break;
 
 	default:
-		if (!w->force)
-			power = w->power_check(w);
-		else
-			power = 1;
+		power = dapm_widget_power_check(w);
 
 		dapm_widget_set_power(w, power, up_list, down_list);
 		break;
Signature · 1 line
1.7.6.3
author
#4 lore raw

PATCH 5/5 ASoC: Do DAPM power checks only for widgets changed since last run

In reply to Mark Brown

In order to reduce the number of DAPM power checks we run keep a list of widgets which have been changed since the last DAPM run and iterate over that rather than the full widget list. Whenever we change the power state for a widget we add all the source and sink widgets it has to the dirty list, ensuring that all widgets in the path are checked.

This covers more widgets than we need to as some of the neighbour widgets won't be connected but it's simpler as a first step. On one system I tried this gave:

           Power    Path   Neighbour
Before:    207      1939   2461
After:     114      1066   1327

which seems useful.

---

Still testing this one but it's looking robust enough right now.

 include/sound/soc-dapm.h |    1 +
 include/sound/soc.h      |    1 +
 sound/soc/soc-core.c     |    1 +
 sound/soc/soc-dapm.c     |   52 ++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 51 insertions(+), 4 deletions(-)
include/sound/soc-dapm.h +1 -0
index bb59532..c080635 100644
@@ -492,6 +492,7 @@ struct snd_soc_dapm_widget {
 
 	/* used during DAPM updates */
 	struct list_head power_list;
+	struct list_head dirty;
 };
 
 struct snd_soc_dapm_update {
include/sound/soc.h +1 -0
index a4dc699..1224bc3 100644
@@ -827,6 +827,7 @@ struct snd_soc_card {
 	struct list_head widgets;
 	struct list_head paths;
 	struct list_head dapm_list;
+	struct list_head dapm_dirty;
 
 	/* Generic DAPM context for the card */
 	struct snd_soc_dapm_context dapm;
sound/soc/soc-core.c +1 -0
index 1ed8093..778c177 100644
@@ -2916,6 +2916,7 @@ int snd_soc_register_card(struct snd_soc_card *card)
 		card->rtd[i].dai_link = &card->dai_link[i];
 
 	INIT_LIST_HEAD(&card->list);
+	INIT_LIST_HEAD(&card->dapm_dirty);
 	card->instantiated = 0;
 	mutex_init(&card->mutex);
 
sound/soc/soc-dapm.c +48 -4

124 lines not on this page · raw message

Signature · 1 line
1.7.6.3
author
#5 lore raw

PATCH 1/1 ASoC: Mark mixer and mux neighbours as dirty when changing them

---
 sound/soc/soc-dapm.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
sound/soc/soc-dapm.c +7 -2
index 50517d8..06d8cfa 100644
@@ -1608,10 +1608,14 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
 
 		found = 1;
 		/* we now need to match the string in the enum to the path */
-		if (!(strcmp(path->name, e->texts[mux])))
+		if (!(strcmp(path->name, e->texts[mux]))) {
 			path->connect = 1; /* new connection */
-		else
+			dapm_mark_dirty(path->source);
+		} else {
+			if (path->connect)
+				dapm_mark_dirty(path->source);
 			path->connect = 0; /* old connection must be powered down */
+		}
 	}
 
 	if (found) {
@@ -1642,6 +1646,7 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
 		/* found, now check type */
 		found = 1;
 		path->connect = connect;
+		dapm_mark_dirty(path->source);
 	}
 
 	if (found) {
Signature · 1 line
1.7.6.3