ASoC: dapm: Introduce toplevel widget categories
DAPM 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.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
2 files changed