ASoC: dapm: dapm_dai_get_connected_widgets: Fix missing mutex unlock
PATCH v2 1/3 ASoC: dapm: dapm_dai_get_connected_widgets: Fix missing mutex unlock
Make sure to unlock the DAPM mutex when dapm_widget_list_create() fails.
This means the function will now generate a trace_snd_soc_dapm_connected event, even if the creation of the list fails. But that was the behavior before the patch that introduced the unlock issue, so that should be fine.
---
New in v2
--- sound/soc/soc-dapm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/soc-dapm.c +1 -1
@@ -1191,7 +1191,7 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, ret =dapm_widget_list_create (list, &widgets);if (ret) -return ret; + paths = ret;trace_snd_soc_dapm_connected (paths, stream);mutex_unlock (&card->dapm_mutex);
Signature · 1 line
2.1.4
PATCH v2 2/3 ASoC: dapm: Consolidate input and output path handling
After the recent cleanups and generalizations of the DAPM algorithm the handling of input and output paths is now fully symmetric. This means by making some slight changes to the data structure and using arrays with one entry for each direction, rather than separate fields, it is possible to create a generic implementation that is capable of handling both input and output paths.
Unfortunately this generalization significantly increases the code size on the hot path of is_connected_{input,output}_ep() and dapm_widget_invalidate_{input,output}_paths(), which has a negative impact on the overall performance. The inner loops of those functions are quite small and the generic implementation adds extra pointer arithmetic in a few places.
Testing on ARM shows that the combined code size of the specialized functions is about 50% larger than the generalized function in relative numbers. But in absolute numbers its less than 200 bytes, which is still quite small. On the other hand the generalized function increases the execution time of dapm_power_one_widget() by 30%. Given that this function is one of the most often called functions of the DAPM framework the trade-off of getting better performance at expense of generating slightly larger code at seems to be worth it.
To avoid this still keep two versions of these functions around, one for input and one for output. But have a generic implementation of the algorithm which gets inlined by those two versions. And then let the compiler take care of optimizing it and removing he extra instructions.
This still reduces the source code size as well as the makes making changes to the implementation more straight forward since the same change does no longer need to be done in two separate places. Also on the slow paths we can use a generic implementations that handle both input and output paths.
---
Changes since v1:
* Use snd_soc_dapm prefix everywhere (instead of sometimes just dapm)
* Move snd_soc_dapm_for_each_path_safe to the header next to snd_soc_dapm_for_each_path
--- include/sound/soc-dapm.h | 69 ++++++++-- sound/soc/soc-dapm.c | 350 +++++++++++++++++++++++------------------------ 2 files changed, 227 insertions(+), 192 deletions(-)
include/sound/soc-dapm.h +55 -14
@@ -512,9 +512,18 @@ struct snd_soc_dapm_route {struct snd_soc_dapm_path {const char *name; -/* source (input) and sink (output) widgets */ -struct snd_soc_dapm_widget *source; -struct snd_soc_dapm_widget *sink; +/* +* source (input) and sink (output) widgets +* The union is for convience, since it is a lot nicer to type +* p->source, rather than p->node[SND_SOC_DAPM_DIR_IN] +*/ +union { +struct { +struct snd_soc_dapm_widget *source; +struct snd_soc_dapm_widget *sink; + }; +struct snd_soc_dapm_widget *node[2 ]; + };/* status */ u32 connect:1 ;/* source and sink widgets are connected */
@@ -525,8 +534,7 @@ struct snd_soc_dapm_path {int (*connected)(struct snd_soc_dapm_widget *source,struct snd_soc_dapm_widget *sink); -struct list_head list_source; -struct list_head list_sink; +struct list_head list_node[2 ];struct list_head list_kcontrol;struct list_head list; };
@@ -560,8 +568,7 @@ struct snd_soc_dapm_widget { 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 */ + unsigned char is_ep:2; /* Widget is a endpoint type widget */int subseq;/* sort within widget type */ int (*power_check)(struct snd_soc_dapm_widget *w);
@@ -576,16 +583,14 @@ struct snd_soc_dapm_widget {struct snd_kcontrol **kcontrols;struct snd_soc_dobj dobj; -/* widget input and outputs */ -struct list_head sources; -struct list_head sinks; +/* widget input and output edges */ +struct list_head edges[2 ];/* used during DAPM updates */ struct list_head work_list;struct list_head power_list;struct list_head dirty; -int inputs; -int outputs; +int endpoints[2 ];struct clk *clk; };
@@ -673,6 +678,42 @@ static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(return dapm->bias_level; } +enum snd_soc_dapm_direction { +SND_SOC_DAPM_DIR_IN , +SND_SOC_DAPM_DIR_OUT +}; + +#define SND_SOC_DAPM_DIR_TO_EP (x) BIT(x) + +#define SND_SOC_DAPM_EP_SOURCE SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_IN) +#define SND_SOC_DAPM_EP_SINK SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_OUT) + +/** +* snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths in the +* specified direction of a widget +* @w: The widget +* @dir: Whether to iterate over the paths where the specified widget is the +* incoming or outgoing widgets +* @p: The path iterator variable +*/ +#define snd_soc_dapm_widget_for_each_path (w, dir, p) \ + list_for_each_entry(p, &w->edges[dir], list_node[dir]) + +/** +* snd_soc_dapm_widget_for_each_sink_path_safe - Iterates over all paths in the +* specified direction of a widget +* @w: The widget +* @dir: Whether to iterate over the paths where the specified widget is the +* incoming or outgoing widgets +* @p: The path iterator variable +* @next_p: Temporary storage for the next path +* +* This function works like snd_soc_dapm_widget_for_each_sink_path, expect that +* it is safe to remove the current path from the list while iterating +*/ +#define snd_soc_dapm_widget_for_each_path_safe (w, dir, p, next_p) \ + list_for_each_entry_safe(p, next_p, &w->edges[dir], list_node[dir]) +/** * snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths leaving a * widget
@@ -680,7 +721,7 @@ static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(* @p: The path iterator variable */ #define snd_soc_dapm_widget_for_each_sink_path (w, p) \ - list_for_each_entry(p, &w->sinks, list_source) + snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_IN, p)/** * snd_soc_dapm_widget_for_each_source_path - Iterates over all paths leading to
@@ -689,6 +730,6 @@ static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(* @p: The path iterator variable */ #define snd_soc_dapm_widget_for_each_source_path (w, p) \ - list_for_each_entry(p, &w->sources, list_sink) + snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_OUT, p)#endif
sound/soc/soc-dapm.c +172 -178
643 lines not on this page · raw message
Signature · 1 line
2.1.4
Mark Brown
maintainerApplied "ASoC: dapm: Consolidate input and output path handling" to the asoc tree
The patch
ASoC: dapm: Consolidate input and output path handling
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
a3423b02cf745c1418f1f199646c450d6fc9ca4eMon Sep 17 00:00:00 2001
From: Lars-Peter Clausen <[email protected]>
Date: Tue, 11 Aug 2015 21:38:00 +0200
Subject: [PATCH] ASoC: dapm: Consolidate input and output path handling
After the recent cleanups and generalizations of the DAPM algorithm the handling of input and output paths is now fully symmetric. This means by making some slight changes to the data structure and using arrays with one entry for each direction, rather than separate fields, it is possible to create a generic implementation that is capable of handling both input and output paths.
Unfortunately this generalization significantly increases the code size on the hot path of is_connected_{input,output}_ep() and dapm_widget_invalidate_{input,output}_paths(), which has a negative impact on the overall performance. The inner loops of those functions are quite small and the generic implementation adds extra pointer arithmetic in a few places.
Testing on ARM shows that the combined code size of the specialized functions is about 50% larger than the generalized function in relative numbers. But in absolute numbers its less than 200 bytes, which is still quite small. On the other hand the generalized function increases the execution time of dapm_power_one_widget() by 30%. Given that this function is one of the most often called functions of the DAPM framework the trade-off of getting better performance at expense of generating slightly larger code at seems to be worth it.
To avoid this still keep two versions of these functions around, one for input and one for output. But have a generic implementation of the algorithm which gets inlined by those two versions. And then let the compiler take care of optimizing it and removing he extra instructions.
This still reduces the source code size as well as the makes making changes to the implementation more straight forward since the same change does no longer need to be done in two separate places. Also on the slow paths we can use a generic implementations that handle both input and output paths.
--- include/sound/soc-dapm.h | 69 ++++++++-- sound/soc/soc-dapm.c | 350 +++++++++++++++++++++++------------------------ 2 files changed, 227 insertions(+), 192 deletions(-)
include/sound/soc-dapm.h +55 -14
@@ -512,9 +512,18 @@ struct snd_soc_dapm_route {struct snd_soc_dapm_path {const char *name; -/* source (input) and sink (output) widgets */ -struct snd_soc_dapm_widget *source; -struct snd_soc_dapm_widget *sink; +/* +* source (input) and sink (output) widgets +* The union is for convience, since it is a lot nicer to type +* p->source, rather than p->node[SND_SOC_DAPM_DIR_IN] +*/ +union { +struct { +struct snd_soc_dapm_widget *source; +struct snd_soc_dapm_widget *sink; + }; +struct snd_soc_dapm_widget *node[2 ]; + };/* status */ u32 connect:1 ;/* source and sink widgets are connected */
@@ -525,8 +534,7 @@ struct snd_soc_dapm_path {int (*connected)(struct snd_soc_dapm_widget *source,struct snd_soc_dapm_widget *sink); -struct list_head list_source; -struct list_head list_sink; +struct list_head list_node[2 ];struct list_head list_kcontrol;struct list_head list; };
@@ -560,8 +568,7 @@ struct snd_soc_dapm_widget { 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 */ + unsigned char is_ep:2; /* Widget is a endpoint type widget */int subseq;/* sort within widget type */ int (*power_check)(struct snd_soc_dapm_widget *w);
@@ -576,16 +583,14 @@ struct snd_soc_dapm_widget {struct snd_kcontrol **kcontrols;struct snd_soc_dobj dobj; -/* widget input and outputs */ -struct list_head sources; -struct list_head sinks; +/* widget input and output edges */ +struct list_head edges[2 ];/* used during DAPM updates */ struct list_head work_list;struct list_head power_list;struct list_head dirty; -int inputs; -int outputs; +int endpoints[2 ];struct clk *clk; };
@@ -673,6 +678,42 @@ static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(return dapm->bias_level; } +enum snd_soc_dapm_direction { +SND_SOC_DAPM_DIR_IN , +SND_SOC_DAPM_DIR_OUT +}; + +#define SND_SOC_DAPM_DIR_TO_EP (x) BIT(x) + +#define SND_SOC_DAPM_EP_SOURCE SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_IN) +#define SND_SOC_DAPM_EP_SINK SND_SOC_DAPM_DIR_TO_EP(SND_SOC_DAPM_DIR_OUT) + +/** +* snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths in the +* specified direction of a widget +* @w: The widget +* @dir: Whether to iterate over the paths where the specified widget is the +* incoming or outgoing widgets +* @p: The path iterator variable +*/ +#define snd_soc_dapm_widget_for_each_path (w, dir, p) \ + list_for_each_entry(p, &w->edges[dir], list_node[dir]) + +/** +* snd_soc_dapm_widget_for_each_sink_path_safe - Iterates over all paths in the +* specified direction of a widget +* @w: The widget +* @dir: Whether to iterate over the paths where the specified widget is the +* incoming or outgoing widgets +* @p: The path iterator variable +* @next_p: Temporary storage for the next path +* +* This function works like snd_soc_dapm_widget_for_each_sink_path, expect that +* it is safe to remove the current path from the list while iterating +*/ +#define snd_soc_dapm_widget_for_each_path_safe (w, dir, p, next_p) \ + list_for_each_entry_safe(p, next_p, &w->edges[dir], list_node[dir]) +/** * snd_soc_dapm_widget_for_each_sink_path - Iterates over all paths leaving a * widget
@@ -680,7 +721,7 @@ static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(* @p: The path iterator variable */ #define snd_soc_dapm_widget_for_each_sink_path (w, p) \ - list_for_each_entry(p, &w->sinks, list_source) + snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_IN, p)/** * snd_soc_dapm_widget_for_each_source_path - Iterates over all paths leading to
@@ -689,6 +730,6 @@ static inline enum snd_soc_bias_level snd_soc_dapm_get_bias_level(* @p: The path iterator variable */ #define snd_soc_dapm_widget_for_each_source_path (w, p) \ - list_for_each_entry(p, &w->sources, list_sink) + snd_soc_dapm_widget_for_each_path(w, SND_SOC_DAPM_DIR_OUT, p)#endif
sound/soc/soc-dapm.c +172 -178
643 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 3/3 ASoC: dapm: Consolidate path trace events
In reply to Lars-Peter ClausenThe snd_soc_dapm_input_path and snd_soc_dapm_output_path trace events are identical except for the direction. Instead of having two events have a single one that has a field that contains the direction.
---
No changes since v1
--- include/trace/events/asoc.h | 53 +++++++++++++-------------------------------- sound/soc/soc-dapm.c | 9 -------- 2 files changed, 15 insertions(+), 47 deletions(-)
include/trace/events/asoc.h +15 -38
@@ -8,6 +8,7 @@#include <linux/tracepoint.h> #define DAPM_DIRECT "(direct)" +#define DAPM_ARROW (dir) (((dir) == SND_SOC_DAPM_DIR_OUT) ? "->" : "<-")struct snd_soc_jack ;struct snd_soc_codec ;
@@ -152,62 +153,38 @@ TRACE_EVENT(snd_soc_dapm_walk_done, (int)__entry->path_checks, (int)__entry->neighbour_checks) ); -TRACE_EVENT (snd_soc_dapm_output_path, +TRACE_EVENT (snd_soc_dapm_path, TP_PROTO(struct snd_soc_dapm_widget *widget, + enum snd_soc_dapm_direction dir, struct snd_soc_dapm_path *path), -TP_ARGS (widget, path), +TP_ARGS (widget, dir, path),TP_STRUCT__entry ( __string( wname, widget->name ) __string( pname, path->name ? path->name : DAPM_DIRECT) - __string( psname, path->sink->name ) - __field( int, path_sink ) + __string( pnname, path->node[dir]->name ) + __field( int, path_node ) __field( int, path_connect ) +__field ( int, path_dir ) ),TP_fast_assign ( __assign_str(wname, widget->name); __assign_str(pname, path->name ? path->name : DAPM_DIRECT); - __assign_str(psname, path->sink->name); + __assign_str(pnname, path->node[dir]->name); __entry->path_connect = path->connect; - __entry->path_sink = (long)path->sink; + __entry->path_node = (long)path->node[dir]; + __entry->path_dir = dir; ), -TP_printk ("%c%s -> %s -> %s" , - (int ) __entry->path_sink && +TP_printk ("%c%s %s %s %s %s" , + (int ) __entry->path_node && (int ) __entry->path_connect ?'*' :' ' , -__get_str (wname),__get_str (pname),__get_str (psname)) -); - -TRACE_EVENT (snd_soc_dapm_input_path, - - TP_PROTO(struct snd_soc_dapm_widget *widget, - struct snd_soc_dapm_path *path), - -TP_ARGS (widget, path), - -TP_STRUCT__entry ( - __string( wname, widget->name ) - __string( pname, path->name ? path->name : DAPM_DIRECT) - __string( psname, path->source->name ) - __field( int, path_source ) -__field ( int, path_connect ) - ), - -TP_fast_assign ( - __assign_str(wname, widget->name); - __assign_str(pname, path->name ? path->name : DAPM_DIRECT); - __assign_str(psname, path->source->name); - __entry->path_connect = path->connect; - __entry->path_source = (long)path->source; - ), - -TP_printk ("%c%s <- %s <- %s" , - (int ) __entry->path_source && - (int ) __entry->path_connect ?'*' :' ' , -__get_str (wname),__get_str (pname),__get_str (psname)) +__get_str (wname),DAPM_ARROW (__entry->path_dir), +__get_str (pname),DAPM_ARROW (__entry->path_dir), +__get_str (pnname)) ); TRACE_EVENT(snd_soc_dapm_connected,
sound/soc/soc-dapm.c +0 -9
@@ -1047,15 +1047,6 @@ static int dapm_widget_list_create(struct snd_soc_dapm_widget_list **list,return 0 ; } -static void trace_snd_soc_dapm_path (struct snd_soc_dapm_widget *w, -enum snd_soc_dapm_direction dir,struct snd_soc_dapm_path *p) -{ -if (dir ==SND_SOC_DAPM_DIR_IN ) -trace_snd_soc_dapm_input_path (w, p); -else -trace_snd_soc_dapm_output_path (w, p); -} -/* * Common implementation for is_connected_output_ep() and * is_connected_input_ep(). The function is inlined since the combined size of
Signature · 1 line
2.1.4
Mark Brown
maintainerApplied "ASoC: dapm: dapm_dai_get_connected_widgets: Fix missing mutex unlock" to the asoc tree
In reply to Lars-Peter ClausenThe patch
ASoC: dapm: dapm_dai_get_connected_widgets: Fix missing mutex unlock
has been applied to the asoc tree at
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
30abbe7727b23c6661daeea5d36be36ed7a41665Mon Sep 17 00:00:00 2001
From: Lars-Peter Clausen <[email protected]>
Date: Tue, 11 Aug 2015 21:37:59 +0200
Subject: [PATCH] ASoC: dapm: dapm_dai_get_connected_widgets: Fix missing mutex
unlock
Make sure to unlock the DAPM mutex when dapm_widget_list_create() fails.
This means the function will now generate a trace_snd_soc_dapm_connected event, even if the creation of the list fails. But that was the behavior before the patch that introduced the unlock issue, so that should be fine.
--- sound/soc/soc-dapm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/soc-dapm.c +1 -1
@@ -1191,7 +1191,7 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, ret =dapm_widget_list_create (list, &widgets);if (ret) -return ret; + paths = ret;trace_snd_soc_dapm_connected (paths, stream);mutex_unlock (&card->dapm_mutex);
Signature · 1 line
2.5.0