ASoC: dapm: Cleanups and speed-ups
v2 cover ASoC: dapm: Cleanups and speed-ups
Only as few minor cleanup changes since v1. No change in functionallity.
Original cover letter from v1:
This series contains a few cleanups and speed-ups for the DAPM implementation. It starts with removing some dead or outdated code and optimizing some lesser used operations.
The first larger change introduced by this series is the categorization of widgets into sinks, sources, supplies and normal widgets. This is all the information the main DAPM algorithm needs and using these categories makes the code simpler and faster and hopefully easier to understand.
The second major change is to use more aggressive caching on the connected input and output paths of a widget. It takes advantage of the fact that typically only as subsection of the DAPM graph changes per operation. This allows to drastically reduce the number of neighbor and path checks for some DAPM operations. The change is most effective when the system is idle and when changing the graph routing for a widget with multiple inputs. This e.g. happens a lot when switching the audio profile. It still has quite good improvements for other operations as well and typically leads to at least a 50% reduction of path and neighbor checks.
Some before and after DAPM stats. All testing was done with the ADAU1761. Before is asoc/for-next, After~1 is asoc/for-next + this series except the last patch, After is asoc/for-next + this series.
Changing a single control on a 5 input mixer while the system is idle:
Power Path Neighbour Before: 2 25 32 After~1: 2 12 30
After: 2 1 2
Cumulative numbers for switching the audio profile which changes 7 controls while the system is idle:
Power Path Neighbour Before: 16 141 188 After~1: 16 80 170
After: 16 7 23
Cumulative numbers for switching the audio profile which changes 7 controls while playback is active:
Power Path Neighbour Before: 52 207 297 After~1: 51 123 273 After: 51 29 109
Starting (or stopping) the playback stream:
Power Path Neighbour Before: 35 80 125 After~1: 34 34 117 After: 34 17 69
- Lars
Lars-Peter Clausen (8):
ASoC: dapm: Only mark paths dirty when the connection status changed
ASoC: dapm: Do not add un-muxed paths to MUX control
ASoC: dapm: Do not pretend to support controls for non mixer/mux
widgets
ASoC: dapm: Introduce toplevel widget categories
ASoC: dapm: Add a flag to mark paths connected to supply widgets
ASoC: dapm: Mark endpoints instead of IO widgets dirty during
suspend/resume
ASoC: dapm: Add a few supply widget sanity checks
ASoC: dapm: Use more aggressive caching
include/sound/soc-dapm.h | 8 +- sound/soc/soc-core.c | 8 +- sound/soc/soc-dapm.c | 576 ++++++++++++++++++++++++++++------------------- 3 files changed, 353 insertions(+), 239 deletions(-)
Signature · 1 line
1.8.0
PATCH v2 1/8 ASoC: dapm: Only mark paths dirty when the connection status changed
Rework soc_dapm_{mixer,mux}_update_power() to only mark a path dirty if the connect state if the path has actually changed. This avoids unnecessary power state checks for the widgets involved.
Also factor out the common code that is involved in this into a helper function.
---
Changes since v1:
* Drop return type from soc_dapm_connect_path() since it is currently unused.
* Change '/**' to '/*' for static function documentation to prevent it from showing up in the generated public API documentation
--- sound/soc/soc-dapm.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)
sound/soc/soc-dapm.c +26 -13
@@ -1925,12 +1925,31 @@ static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)#endif +/* +* soc_dapm_connect_path() - Connects or disconnects a path +* @path: The path to update +* @connect: The new connect state of the path. True if the path is connected, +* false if it is disconneted. +* @reason: The reason why the path changed (for debugging only) +*/ +static void soc_dapm_connect_path (struct snd_soc_dapm_path *path, +bool connect,const char *reason) +{ +if (path->connect == connect) +return ; + + path->connect = connect; +dapm_mark_dirty (path->source, reason); +dapm_mark_dirty (path->sink, reason); +} +/* test and update the power status of a mux widget */ static int soc_dapm_mux_update_power (struct snd_soc_card *card,struct snd_kcontrol *kcontrol,int mux,struct soc_enum *e) {struct snd_soc_dapm_path *path;int found =0 ; +bool connect;lockdep_assert_held (&card->dapm_mutex);
@@ -1941,16 +1960,12 @@ static int soc_dapm_mux_update_power(struct snd_soc_card *card, found =1 ;/* we now need to match the string in the enum to the path */ -if (!(strcmp (path->name, e->texts[mux]))) { - path->connect =1 ;/* new connection */ -dapm_mark_dirty (path->source,"mux connection" ); - }else { -if (path->connect) -dapm_mark_dirty (path->source, -"mux disconnection" ); - path->connect =0 ;/* old connection must be powered down */ - } -dapm_mark_dirty (path->sink,"mux change" ); +if (!(strcmp (path->name, e->texts[mux]))) + connect = true; +else + connect = false; + +soc_dapm_connect_path (path, connect,"mux update" ); }if (found)
@@ -1989,9 +2004,7 @@ static int soc_dapm_mixer_update_power(struct snd_soc_card *card,/* find dapm widget path assoc with kcontrol */ dapm_kcontrol_for_each_path (path, kcontrol) { found =1 ; - path->connect = connect; -dapm_mark_dirty (path->source,"mixer connection" ); -dapm_mark_dirty (path->sink,"mixer update" ); +soc_dapm_connect_path (path, connect,"mixer update" ); }if (found)
Signature · 1 line
1.8.0
PATCH v2 2/8 ASoC: dapm: Do not add un-muxed paths to MUX control
In reply to Lars-Peter ClausenPaths that are directly connected to a MUX widget are not affected by changes to the MUX's control. Rather than checking if a path is directly connected each time the MUX is updated do it only once when MUX is created.
We can also remove the check for e->texts[mux] != NULL, since if that condition was true the code would have had already crashed much earlier (And generally speaking if a enum's 'texts' entry is NULL it's a bug in the driver).
---
No changes since v1
--- sound/soc/soc-dapm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
sound/soc/soc-dapm.c +4 -5
@@ -738,8 +738,10 @@ static int dapm_new_mux(struct snd_soc_dapm_widget *w)if (ret <0 )return ret; -list_for_each_entry (path, &w->sources, list_sink) -dapm_kcontrol_add_path (w->kcontrols[0 ], path); +list_for_each_entry (path, &w->sources, list_sink) { +if (path->name) +dapm_kcontrol_add_path (w->kcontrols[0 ], path); + }return 0 ; }
@@ -1955,9 +1957,6 @@ static int soc_dapm_mux_update_power(struct snd_soc_card *card,/* find dapm widget path assoc with kcontrol */ dapm_kcontrol_for_each_path (path, kcontrol) { -if (!path->name || !e->texts[mux]) -continue ; - found =1 ;/* we now need to match the string in the enum to the path */ if (!(strcmp (path->name, e->texts[mux])))
Signature · 1 line
1.8.0
PATCH v2 3/8 ASoC: dapm: Do not pretend to support controls for non mixer/mux widgets
In reply to Lars-Peter ClausenControls on a path only have an effect if the sink on the path is either a mixer or mux widget. Currently we sort of silently ignore controls on other paths, but since they don't do anything having them on other paths does not make much sense and it is probably safe to assume that if we see such a path it is a mistake in the driver that registered the path. This patch modifies snd_soc_dapm_add_path() to report an error if a path with and control is encountered where we didn't expect a control. This also allows to simplify the code quite a bit.
The patch also moves the connecting of the path lists out of dapm_connect_mux() and dapm_connect_mixer() into snd_soc_dapm_add_path().
---
Changes since v1:
* Rebased on topic/dapm
--- sound/soc/soc-dapm.c | 112 +++++++++++++++++---------------------------------- 1 file changed, 37 insertions(+), 75 deletions(-)
sound/soc/soc-dapm.c +37 -75
@@ -469,10 +469,9 @@ out:/* connect mux widget to its interconnecting audio paths */ static int dapm_connect_mux (struct snd_soc_dapm_context *dapm, -struct snd_soc_dapm_widget *src,struct snd_soc_dapm_widget *dest, -struct snd_soc_dapm_path *path,const char *control_name, -const struct snd_kcontrol_new *kcontrol) +struct snd_soc_dapm_path *path,const char *control_name) { +const struct snd_kcontrol_new *kcontrol = &path->sink->kcontrol_news[0 ];struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;unsigned int val, item;int i;
@@ -493,9 +492,6 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,for (i =0 ; i < e->items; i++) {if (!(strcmp (control_name, e->texts[i]))) { -list_add (&path->list, &dapm->card->paths); -list_add (&path->list_sink, &dest->sources); -list_add (&path->list_source, &src->sinks); path->name = e->texts[i];if (i == item) path->connect =1 ;
@@ -509,11 +505,10 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, }/* set up initial codec paths */ -static void dapm_set_mixer_path_status (struct snd_soc_dapm_widget *w, -struct snd_soc_dapm_path *p,int i) +static void dapm_set_mixer_path_status (struct snd_soc_dapm_path *p,int i) {struct soc_mixer_control *mc = (struct soc_mixer_control *) - w->kcontrol_news[i].private_value; + p->sink->kcontrol_news[i].private_value;unsigned int reg = mc->reg;unsigned int shift = mc->shift;unsigned int max = mc->max;
@@ -522,7 +517,7 @@ static void dapm_set_mixer_path_status(struct snd_soc_dapm_widget *w,unsigned int val;if (reg !=SND_SOC_NOPM ) { -soc_dapm_read (w->dapm, reg, &val); +soc_dapm_read (p->sink->dapm, reg, &val); val = (val >> shift) & mask;if (invert) val = max - val;
@@ -534,19 +529,15 @@ static void dapm_set_mixer_path_status(struct snd_soc_dapm_widget *w,/* connect mixer widget to its interconnecting audio paths */ static int dapm_connect_mixer (struct snd_soc_dapm_context *dapm, -struct snd_soc_dapm_widget *src,struct snd_soc_dapm_widget *dest,struct snd_soc_dapm_path *path,const char *control_name) {int i;/* search for mixer kcontrol */ -for (i =0 ; i < dest->num_kcontrols; i++) { -if (!strcmp (control_name, dest->kcontrol_news[i].name)) { -list_add (&path->list, &dapm->card->paths); -list_add (&path->list_sink, &dest->sources); -list_add (&path->list_source, &src->sinks); - path->name = dest->kcontrol_news[i].name; -dapm_set_mixer_path_status (dest, path, i); +for (i =0 ; i < path->sink->num_kcontrols; i++) { +if (!strcmp (control_name, path->sink->kcontrol_news[i].name)) { + path->name = path->sink->kcontrol_news[i].name; +dapm_set_mixer_path_status (path, i);return 0 ; } }
@@ -2272,69 +2263,40 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm, wsource->ext =1 ; } -dapm_mark_dirty (wsource,"Route added" ); -dapm_mark_dirty (wsink,"Route added" ); -/* connect static paths */ if (control ==NULL ) { -list_add (&path->list, &dapm->card->paths); -list_add (&path->list_sink, &wsink->sources); -list_add (&path->list_source, &wsource->sinks); path->connect =1 ; -return 0 ; - } - -/* connect dynamic paths */ -switch (wsink->id) { -case snd_soc_dapm_adc: -case snd_soc_dapm_dac: -case snd_soc_dapm_pga: -case snd_soc_dapm_out_drv: -case snd_soc_dapm_input: -case snd_soc_dapm_output: -case snd_soc_dapm_siggen: -case snd_soc_dapm_micbias: -case snd_soc_dapm_vmid: -case snd_soc_dapm_pre: -case snd_soc_dapm_post: -case snd_soc_dapm_supply: -case snd_soc_dapm_regulator_supply: -case snd_soc_dapm_clock_supply: -case snd_soc_dapm_aif_in: -case snd_soc_dapm_aif_out: -case snd_soc_dapm_dai_in: -case snd_soc_dapm_dai_out: -case snd_soc_dapm_dai_link: -case snd_soc_dapm_kcontrol: -list_add (&path->list, &dapm->card->paths); -list_add (&path->list_sink, &wsink->sources); -list_add (&path->list_source, &wsource->sinks); - path->connect =1 ; -return 0 ; -case snd_soc_dapm_mux: - ret =dapm_connect_mux (dapm, wsource, wsink, path, control, - &wsink->kcontrol_news[0 ]); -if (ret !=0 ) - goto err; -break ; -case snd_soc_dapm_switch: -case snd_soc_dapm_mixer: -case snd_soc_dapm_mixer_named_ctl: - ret =dapm_connect_mixer (dapm, wsource, wsink, path, control); -if (ret !=0 ) + }else { +/* connect dynamic paths */ +switch (wsink->id) { +case snd_soc_dapm_mux: + ret =dapm_connect_mux (dapm, path, control); +if (ret !=0 ) + goto err; +break ; +case snd_soc_dapm_switch: +case snd_soc_dapm_mixer: +case snd_soc_dapm_mixer_named_ctl: + ret =dapm_connect_mixer (dapm, path, control); +if (ret !=0 ) + goto err; +break ; +default : +dev_err (dapm->dev, +"Control not supported for path %s -> [%s] -> %s\n" , + wsource->name, control, wsink->name); + ret = -EINVAL ; goto err; -break ; -case snd_soc_dapm_hp: -case snd_soc_dapm_mic: -case snd_soc_dapm_line: -case snd_soc_dapm_spk: -list_add (&path->list, &dapm->card->paths); -list_add (&path->list_sink, &wsink->sources); -list_add (&path->list_source, &wsource->sinks); - path->connect =0 ; -return 0 ; + } } +list_add (&path->list, &dapm->card->paths); +list_add (&path->list_sink, &wsink->sources); +list_add (&path->list_source, &wsource->sinks); + +dapm_mark_dirty (wsource,"Route added" ); +dapm_mark_dirty (wsink,"Route added" ); +return 0 ; err:kfree (path);
Signature · 1 line
1.8.0
PATCH v2 4/8 ASoC: dapm: Introduce toplevel widget categories
In reply to Lars-Peter ClausenDAPM widgets can be classified into four categories:
* supply: Supply widgets do not affect the power state of their non-supply widget neighbors and unlike other widgets a supply widget is not powered up when it is on an active path, but when at least on of its neighbors is powered up.
* source: A source is a widget that receives data from outside the DAPM graph or generates data. This can for example be a microphone, the playback DMA or a signal generator. A source widget will be considered powered up if there is an active path to a sink widget.
* sink: A sink is a widget that transmits data to somewhere outside of the DAPM graph. This can e.g. be a speaker or the capture DMA. A sink widget will be considered powered up if there is an active path from a source widget.
* normal: Normal widgets are widgets not covered by the categories above. A normal widget will be considered powered up if it is on an active path between a source widget and a sink widget.
The way the number of input and output paths for a widget is calculated depends on its category. There are a bunch of factors which decide which category a widget is. Currently there is no formal classification of these categories and we calculate the category of the widget based on these factors whenever we want to know it. This is at least once for every widget during each power update sequence. The factors which determine the category of the widgets are mostly static though and if at all change rather seldom. This patch introduces three new per widget flags, one for each of non-normal widgets categories. Instead of re-computing the category each time we want to know them the flags will be checked. For the majority of widgets the category is solely determined by the widget id, which means it never changes and only has to be set once when the widget is created. The only widgets with dynamic categories are:
snd_soc_dapm_dai_out: Is considered a sink iff the capture stream is
active, otherwise normal.
snd_soc_dapm_dai_in: Is considered a source iff the playback stream
is active, otherwise normal.
snd_soc_dapm_input: Is considered a sink iff it has no outgoing
paths, otherwise normal.
snd_soc_dapm_output: Is considered a source iff it has no incoming
paths, otherwise normal.
snd_soc_dapm_line: Is considered a sink iff it has no outgoing paths
and is considered a source iff it has no incoming paths, otherwise normal.
For snd_soc_dapm_dai_out/snd_soc_dapm_dai_in widgets the category will be updated when a stream is started or stopped. For the other dynamic widgets the category will be updated when a path connecting to it is added or removed.
Introducing those new widget categories allows to make is_connected_{output,input}_ep, which are among the hottest paths of the DAPM algorithm, more generic and significantly shorter.
The before and after sizes for is_connected_{output,input}_ep are:
On ARM (defconfig + CONFIG_SND_SOC):
function old new delta is_connected_output_ep 480 340 -140 is_connected_input_ep 456 352 -104
On amd64 (defconfig + CONFIG_SND_SOC):
function old new delta is_connected_output_ep 579 427 -152 is_connected_input_ep 563 427 -136
Which is about a 25%-30% decrease, other architectures are expected to have similar numbers. At the same time the size of the snd_soc_dapm_widget struct does not change since the new flags are stored in the same word as the existing flags.
Note: that since the per widget 'ext' flag was only used to decide whether a snd_soc_dapm_input or snd_soc_dapm_output widget was a source or a sink it is now unused and can be removed.
---
Changes since v1:
* Change '/**' to '/*' for static function documentation to prevent it from showing up in the generated public API documentation
--- include/sound/soc-dapm.h | 4 +- sound/soc/soc-dapm.c | 210 +++++++++++++++++++++-------------------------- 2 files changed, 95 insertions(+), 119 deletions(-)
include/sound/soc-dapm.h +3 -1
@@ -543,11 +543,13 @@ struct snd_soc_dapm_widget { unsigned char active:1; /* active stream on DAC, ADC's */ unsigned char connected:1; /* connected codec pin */ unsigned char new:1; /* cnew complete */ - unsigned char ext:1; /* has external widgets */ unsigned char force:1; /* force state */ unsigned char ignore_suspend:1; /* kept enabled over suspend */ unsigned char new_power:1; /* power from this run */ unsigned char power_checked:1; /* power checked this run */ + unsigned char is_supply:1; /* Widget is a supply type widget */ + unsigned char is_sink:1; /* Widget is a sink type widget */ + unsigned char is_source:1; /* Widget is a source type widget */int subseq;/* sort within widget type */ int (*power_check)(struct snd_soc_dapm_widget *w);
sound/soc/soc-dapm.c +92 -118
296 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v2 5/8 ASoC: dapm: Add a flag to mark paths connected to supply widgets
In reply to Lars-Peter ClausenSupply widgets do not count towards the input and output widgets of their neighbors and for supply widgets themselves we do not care for the number of input or output paths. This means that a path that connects to a supply widget effectively behaves the same as a path that as the weak property set. This patch adds a new path flag that gets set to true when the path is connected to at least one supply widget. If a path with the flag set is encountered in is_connected_{input,output}_ep() is is skipped in the same way that weak paths are skipped. This slightly brings down the number of path checks.
Since both the weak and the supply flag are implemented as bitfields which are stored in the same word there is no runtime overhead due to checking both rather than just one and also the size of the path struct is not increased by this patch. Another advantage is that we do not have to handle supply widgets in is_connected_{input,output}_ep() anymore since it will never be called for supply widgets. The only exception is from dapm_widget_power_read_file() where a check is added to special case supply widgets.
Testing with the ADAU1761, which has a handful of supply widgets, shows the following changes in the DAPM stats for a playback stream start.
Power Path Neighbour Before: 34 78 117 After: 34 48 117
---
No changes since v1
--- include/sound/soc-dapm.h | 1 + sound/soc/soc-dapm.c | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-)
include/sound/soc-dapm.h +1 -0
@@ -510,6 +510,7 @@ struct snd_soc_dapm_path { u32 connect:1; /* source and sink widgets are connected */ u32 walking:1; /* path is in the process of being walked */ u32 weak:1; /* path ignored for power management */ + u32 is_supply:1; /* At least one of the connected widgets is a supply */int (*connected)(struct snd_soc_dapm_widget *source,struct snd_soc_dapm_widget *sink);
sound/soc/soc-dapm.c +13 -10
@@ -821,9 +821,6 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,DAPM_UPDATE_STAT (widget, path_checks); -if (widget->is_supply) -return 0 ; -if (widget->is_sink && widget->connected) { widget->outputs =snd_soc_dapm_suspend_check (widget);return widget->outputs;
@@ -832,7 +829,7 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,list_for_each_entry (path, &widget->sinks, list_source) {DAPM_UPDATE_STAT (widget, neighbour_checks); -if (path->weak) +if (path->weak || path->is_supply)continue ;if (path->walking)
@@ -882,9 +879,6 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,DAPM_UPDATE_STAT (widget, path_checks); -if (widget->is_supply) -return 0 ; -if (widget->is_source && widget->connected) { widget->inputs =snd_soc_dapm_suspend_check (widget);return widget->inputs;
@@ -893,7 +887,7 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,list_for_each_entry (path, &widget->sources, list_sink) {DAPM_UPDATE_STAT (widget, neighbour_checks); -if (path->weak) +if (path->weak || path->is_supply)continue ;if (path->walking)
@@ -1691,8 +1685,14 @@ static ssize_t dapm_widget_power_read_file(struct file *file,if (!buf)return -ENOMEM ; - in =is_connected_input_ep (w,NULL ); - out =is_connected_output_ep (w,NULL ); +/* Supply widgets are not handled by is_connected_{input,output}_ep() */ +if (w->is_supply) { + in =0 ; + out =0 ; + }else { + in =is_connected_input_ep (w,NULL ); + out =is_connected_output_ep (w,NULL ); + } ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", w->name, w->power ? "On" : "Off",
@@ -2213,6 +2213,9 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,INIT_LIST_HEAD (&path->list_source);INIT_LIST_HEAD (&path->list_sink); +if (wsource->is_supply || wsink->is_supply) + path->is_supply =1 ; +/* connect static paths */ if (control ==NULL ) { path->connect =1 ;
Signature · 1 line
1.8.0
PATCH v2 6/8 ASoC: dapm: Mark endpoints instead of IO widgets dirty during suspend/resume
In reply to Lars-Peter ClausenThe state of endpoint widgets is affected by that card's power state. Endpoint widgets that do no have the ignore_suspend flag set will be considered inactive during suspend. So they have to be re-checked and marked dirty after the card's power state changes. Currently the input and output widgets are marked dirty instead, this works most of the time since typically a path from one endpoint to another will go via a input or output widget. But marking the endpoints dirty is technically more correct and will also work for odd corner cases.
---
No changes since v1
--- include/sound/soc-dapm.h | 2 +- sound/soc/soc-core.c | 8 ++++---- sound/soc/soc-dapm.c | 15 ++++----------- 3 files changed, 9 insertions(+), 16 deletions(-)
include/sound/soc-dapm.h +1 -1
@@ -435,7 +435,7 @@ void snd_soc_dapm_auto_nc_pins(struct snd_soc_card *card);unsigned int dapm_kcontrol_get_value (const struct snd_kcontrol *kcontrol);/* Mostly internal - should not normally be used */ -void dapm_mark_io_dirty (struct snd_soc_dapm_context *dapm); +void dapm_mark_endpoints_dirty (struct snd_soc_card *card);/* dapm path query */ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
sound/soc/soc-core.c +4 -4
@@ -629,8 +629,8 @@ int snd_soc_suspend(struct device *dev) SND_SOC_DAPM_STREAM_SUSPEND); } -/* Recheck all analogue paths too */ -dapm_mark_io_dirty (&card->dapm); +/* Recheck all endpoints too, their state is affected by suspend */ +dapm_mark_endpoints_dirty (card);snd_soc_dapm_sync (&card->dapm);/* suspend all CODECs */
@@ -796,8 +796,8 @@ static void soc_resume_deferred(struct work_struct *work)/* userspace can access us now we are back as we were before */ snd_power_change_state (card->snd_card,SNDRV_CTL_POWER_D0 ); -/* Recheck all analogue paths too */ -dapm_mark_io_dirty (&card->dapm); +/* Recheck all endpoints too, their state is affected by suspend */ +dapm_mark_endpoints_dirty (card);snd_soc_dapm_sync (&card->dapm); }
sound/soc/soc-dapm.c +4 -11
@@ -159,27 +159,20 @@ static void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason) } } -void dapm_mark_io_dirty (struct snd_soc_dapm_context *dapm) +void dapm_mark_endpoints_dirty (struct snd_soc_card *card) { -struct snd_soc_card *card = dapm->card;struct snd_soc_dapm_widget *w;mutex_lock (&card->dapm_mutex);list_for_each_entry (w, &card->widgets, list) { -switch (w->id) { -case snd_soc_dapm_input: -case snd_soc_dapm_output: -dapm_mark_dirty (w,"Rechecking inputs and outputs" ); -break ; -default : -break ; - } +if (w->is_sink || w->is_source) +dapm_mark_dirty (w,"Rechecking endpoints" ); }mutex_unlock (&card->dapm_mutex); } -EXPORT_SYMBOL_GPL (dapm_mark_io_dirty); +EXPORT_SYMBOL_GPL (dapm_mark_endpoints_dirty);/* create a new dapm widget */ static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
Signature · 1 line
1.8.0
PATCH v2 7/8 ASoC: dapm: Add a few supply widget sanity checks
In reply to Lars-Peter ClausenSupply widgets are somewhat special and not all kinds of paths to or from supply widgets make sense. This patch adds a few sanity checks that errors out during the path instantiation for those invalid paths. This will prevent drivers to depend on weird behavior resulting from such paths as well as will allow the DAPM algorithms to assume that they never see such paths.
This patch adds checks for the following three invalid types of paths:
* A path with a non-supply widget as a source connected to a supply widget as a sink. Such a path has no effect on either of the two connected widgets.
* Paths with a connected() callback that have a non-supply widget as the source. The DAPM algorithm only uses the conneceted() callback for supply widget power checks. And since it prevents caching of the DAPM state there is no intention to make it more generic as it has negative performance implications.
* Paths which connect a supply to a mixer or mux via a control. Controls are only meant to affect the routing of audio data.
---
No changes since v1
--- sound/soc/soc-dapm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
sound/soc/soc-dapm.c +21 -0
@@ -2194,6 +2194,27 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,struct snd_soc_dapm_path *path;int ret; +if (wsink->is_supply && !wsource->is_supply) { +dev_err (dapm->dev, +"Connecting non-supply widget to supply widget is not supported (%s -> %s)\n" , + wsource->name, wsink->name); +return -EINVAL ; + } + +if (connected && !wsource->is_supply) { +dev_err (dapm->dev, +"connected() callback only supported for supply widgets (%s -> %s)\n" , + wsource->name, wsink->name); +return -EINVAL ; + } + +if (wsource->is_supply && control) { +dev_err (dapm->dev, +"Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n" , + wsource->name, control, wsink->name); +return -EINVAL ; + } + path =kzalloc (sizeof (struct snd_soc_dapm_path ),GFP_KERNEL );if (!path)return -ENOMEM ;
Signature · 1 line
1.8.0
PATCH v2 8/8 ASoC: dapm: Use more aggressive caching
In reply to Lars-Peter ClausenCurrently we cache the number of input and output paths going to/from a widget only within a power update sequence. But not in between power update sequences.
But we know how changes to the DAPM graph affect the number of input (form a source) and output (to a sink) paths of a widget and only need to recalculate them if a operation has been performed that might have changed them.
* Adding/removing or connecting/disconnecting a path means that the for the source of the path the number of output paths can change and for the sink the number of input paths can change.
* Connecting/disconnecting a widget has the same effect has connecting/ disconnecting all paths of the widget. So for the widget itself the number of inputs and outputs can change, for all sinks of the widget the number of inputs can change and for all sources of the widget the number of outputs can change.
* Activating/Deactivating a stream can either change the number of outputs on the sources of the widget associated with the stream or the number of inputs on the sinks.
Instead of always invalidating all cached numbers of input and output paths for each power up or down sequence this patch restructures the code to only invalidate the cached numbers when a operation that might change them has been performed. This can greatly reduce the number of DAPM power checks for some very common operations.
Since per DAPM operation typically only either change the number of inputs or outputs the number of path checks is reduced by at least 50%. The number of neighbor checks is also reduced about the same percentage, but since the number of neighbors encountered when walking from sink to source is not the same as when walking from source to sink the actual numbers will slightly vary from card to card (e.g. for a mixer we see 1 neighbor when walking from source to sink, but the number of inputs neighbors when walking from source to sink).
Bigger improvements can be observed for widgets with multiple connected inputs and output (e.g. mixers probably being the most widespread form of this). Previously we had to re-calculate the number of inputs and outputs on all input and output paths. With this change we only have to re-calculate the number of outputs on the input path that got changed and the number of inputs on the output paths.
E.g. imagine the following example:
A --> B ----. v M --> N --> Z <-- S <-- R | v X
Widget Z has multiple input paths, if any change was made that cause Z to be marked as dirty the power state of Z has to be re-computed. This requires to know the number of inputs and outputs of Z, which requires to know the number of inputs and outputs of all widgets on all paths from or to Z. Previously this meant re-computing all inputs and outputs of all the path going into or out of Z. With this patch in place only paths that actually have changed need to be re-computed.
If the system is idle (or the part of the system affected by the changed path) the number of path checks drops to either 0 or 1, regardless of how large or complex the DAPM context is. 0 if there is no connected sink and no connected source. 1 if there is either a connected source or sink, but not both. The number of neighbor checks again will scale accordingly and will be a constant number that is the number of inputs or outputs of the widget for which we did the path check.
When loading a state file or switching between different profiles typically multiple mixer and mux settings are changed, so we see the benefit of this patch multiplied for these kinds of operations.
Testing with the ADAU1761 shows the following changes in DAPM stats for changing a single Mixer switch for a Mixer with 5 inputs while the DAPM context is idle.
Power Path Neighbour Before: 2 12 30
After: 2 1 2
For the same switch, but with a active playback stream the stat changed are as follows.
Power Path Neighbour Before: 10 20 54 After: 10 7 21
Cumulative numbers for switching the audio profile which changes 7 controls while the system is idle:
Power Path Neighbour
Before: 16 80 170 After: 16 7 23
Cumulative numbers for switching the audio profile which changes 7 controls while playback is active:
Power Path Neighbour Before: 51 123 273 After: 51 29 109
Starting (or stopping) the playback stream:
Power Path Neighbour Before: 34 34 117 After: 34 17 69
---
Changes since v1:
* Add dapm_assert_locked(w->dapm) to dapm_widget_invalidate_{input,output}_paths.
* Only call dapm_path_invalidate() in snd_soc_dapm_add_path() if the card has already been instantiated.
* Change '/**' to '/*' for static function documentation to prevent it from showing up in the generated public API documentation
--- include/sound/soc-dapm.h | 1 + sound/soc/soc-dapm.c | 161 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 154 insertions(+), 8 deletions(-)
include/sound/soc-dapm.h +1 -0
@@ -569,6 +569,7 @@ struct snd_soc_dapm_widget {struct list_head sinks;/* used during DAPM updates */ +struct list_head work_list;struct list_head power_list;struct list_head dirty;int inputs;
sound/soc/soc-dapm.c +153 -8
234 lines not on this page · raw message
Signature · 1 line
1.8.0
Quoted 3 lines · Lars-Peter Clausen
Only as few minor cleanup changes since v1. No change in functionallity.
Original cover letter from v1:
Applied all, thanks.