ALSA: split params refinement to seperated file
RFC PATCH 1/1 ALSA: split params refinement to seperated file
ALSA parameter refinement takes up about 13kB of memory. The refinement is useful on the desktop but is not usually required for some bespoke applications typically found on small inexpensive devices with reduced memory. These bespoke applications will typically configure the audio configuration with the exact requirements that will not require any further refinement from the kernel.
The change moves refinement functions from original pcm_native.c and pcm_lib.c, to pcm_refine.c(similarly the declaration from pcm.h to pcm_refine.h), so it is not so big as it looks like.
Please be noticed that this change may block alsa-lib usage, user app such as aplay/arecord doesn't work when CONFIG_SND_PARAMS_REFINEMENT is unselected. But it may be still worthy, some small player(e.g. tinyplay) can work with fixed params passed in(some small changes for the player may be needed), at this case, the change here will save about 13KB footprint on x86_64 platform for those small inexpensive devices(e.g. IoT ones).
--- include/sound/pcm.h | 123 +--- include/sound/pcm_refine.h | 307 +++++++++ sound/core/Kconfig | 9 + sound/core/Makefile | 1 + sound/core/pcm_lib.c | 982 ---------------------------- sound/core/pcm_native.c | 505 --------------- sound/core/pcm_refine.c | 1519 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1837 insertions(+), 1609 deletions(-) create mode 100644 include/sound/pcm_refine.h create mode 100644 sound/core/pcm_refine.c
include/sound/pcm.h +1 -122
@@ -26,6 +26,7 @@#include <sound/asound.h> #include <sound/memalloc.h> #include <sound/minors.h> +#include <sound/pcm_refine.h> #include <linux/poll.h> #include <linux/mm.h> #include <linux/bitops.h>
@@ -213,34 +214,6 @@ struct snd_pcm_ops {#define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE#endif -struct snd_pcm_file { -struct snd_pcm_substream *substream; -int no_compat_mmap; -}; - -struct snd_pcm_hw_rule ; -typedef int (*snd_pcm_hw_rule_func_t )(struct snd_pcm_hw_params *params, -struct snd_pcm_hw_rule *rule); - -struct snd_pcm_hw_rule { -unsigned int cond; -int var; -int deps[4 ]; - -snd_pcm_hw_rule_func_t func; -void *private; -}; - -struct snd_pcm_hw_constraints { -struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK - -SNDRV_PCM_HW_PARAM_FIRST_MASK +1 ]; -struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - -SNDRV_PCM_HW_PARAM_FIRST_INTERVAL +1 ]; -unsigned int rules_num; -unsigned int rules_all; -struct snd_pcm_hw_rule *rules; -}; -static inline struct snd_mask *constrs_mask (struct snd_pcm_hw_constraints *constrs,snd_pcm_hw_param_t var) {
@@ -253,38 +226,6 @@ static inline struct snd_interval *constrs_interval(struct snd_pcm_hw_constraintreturn &constrs->intervals[var -SNDRV_PCM_HW_PARAM_FIRST_INTERVAL ]; } -struct snd_ratnum { -unsigned int num; -unsigned int den_min, den_max, den_step; -}; - -struct snd_ratden { -unsigned int num_min, num_max, num_step; -unsigned int den; -}; - -struct snd_pcm_hw_constraint_ratnums { -int nrats; -struct snd_ratnum *rats; -}; - -struct snd_pcm_hw_constraint_ratdens { -int nrats; -struct snd_ratden *rats; -}; - -struct snd_pcm_hw_constraint_list { -const unsigned int *list; -unsigned int count; -unsigned int mask; -}; - -struct snd_pcm_hw_constraint_ranges { -unsigned int count; -const struct snd_interval *ranges; -unsigned int mask; -}; -struct snd_pcm_hwptr_log ;/*
@@ -968,72 +909,10 @@ static inline unsigned int params_buffer_bytes(const struct snd_pcm_hw_params *preturn hw_param_interval_c (p,SNDRV_PCM_HW_PARAM_BUFFER_BYTES )->min; } -int snd_interval_refine (struct snd_interval *i,const struct snd_interval *v); -void snd_interval_mul (const struct snd_interval *a,const struct snd_interval *b,struct snd_interval *c); -void snd_interval_div (const struct snd_interval *a,const struct snd_interval *b,struct snd_interval *c); -void snd_interval_muldivk (const struct snd_interval *a,const struct snd_interval *b, -unsigned int k,struct snd_interval *c); -void snd_interval_mulkdiv (const struct snd_interval *a,unsigned int k, -const struct snd_interval *b,struct snd_interval *c); -int snd_interval_list (struct snd_interval *i,unsigned int count, -const unsigned int *list,unsigned int mask); -int snd_interval_ranges (struct snd_interval *i,unsigned int count, -const struct snd_interval *list,unsigned int mask); -int snd_interval_ratnum (struct snd_interval *i, -unsigned int rats_count,struct snd_ratnum *rats, -unsigned int *nump,unsigned int *denp); -void _snd_pcm_hw_params_any (struct snd_pcm_hw_params *params);void _snd_pcm_hw_param_setempty (struct snd_pcm_hw_params *params,snd_pcm_hw_param_t var);int snd_pcm_hw_params_choose (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params); -int snd_pcm_hw_refine (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params); - -int snd_pcm_hw_constraints_init (struct snd_pcm_substream *substream); -int snd_pcm_hw_constraints_complete (struct snd_pcm_substream *substream); - -int snd_pcm_hw_constraint_mask (struct snd_pcm_runtime *runtime,snd_pcm_hw_param_t var, -u_int32_t mask); -int snd_pcm_hw_constraint_mask64 (struct snd_pcm_runtime *runtime,snd_pcm_hw_param_t var, -u_int64_t mask); -int snd_pcm_hw_constraint_minmax (struct snd_pcm_runtime *runtime,snd_pcm_hw_param_t var, -unsigned int min,unsigned int max); -int snd_pcm_hw_constraint_integer (struct snd_pcm_runtime *runtime,snd_pcm_hw_param_t var); -int snd_pcm_hw_constraint_list (struct snd_pcm_runtime *runtime, -unsigned int cond, -snd_pcm_hw_param_t var, -const struct snd_pcm_hw_constraint_list *l); -int snd_pcm_hw_constraint_ranges (struct snd_pcm_runtime *runtime, -unsigned int cond, -snd_pcm_hw_param_t var, -const struct snd_pcm_hw_constraint_ranges *r); -int snd_pcm_hw_constraint_ratnums (struct snd_pcm_runtime *runtime, -unsigned int cond, -snd_pcm_hw_param_t var, -struct snd_pcm_hw_constraint_ratnums *r); -int snd_pcm_hw_constraint_ratdens (struct snd_pcm_runtime *runtime, -unsigned int cond, -snd_pcm_hw_param_t var, -struct snd_pcm_hw_constraint_ratdens *r); -int snd_pcm_hw_constraint_msbits (struct snd_pcm_runtime *runtime, -unsigned int cond, -unsigned int width, -unsigned int msbits); -int snd_pcm_hw_constraint_step (struct snd_pcm_runtime *runtime, -unsigned int cond, -snd_pcm_hw_param_t var, -unsigned long step); -int snd_pcm_hw_constraint_pow2 (struct snd_pcm_runtime *runtime, -unsigned int cond, -snd_pcm_hw_param_t var); -int snd_pcm_hw_rule_noresample (struct snd_pcm_runtime *runtime, -unsigned int base_rate); -int snd_pcm_hw_rule_add (struct snd_pcm_runtime *runtime, -unsigned int cond, -int var, -snd_pcm_hw_rule_func_t func,void *private, -int dep, ...); -int snd_pcm_format_signed (snd_pcm_format_t format);int snd_pcm_format_unsigned (snd_pcm_format_t format);int snd_pcm_format_linear (snd_pcm_format_t format);
include/sound/pcm_refine.h new file +307 -0
307 lines not on this page · raw message
sound/core/Kconfig +9 -0
@@ -191,6 +191,15 @@ config SND_PROC_FS 9KB on x86_64 platform. If unsure say Y. +config SND_PARAMS_REFINEMENT + bool "HW/SW Params Refinement Support" if EXPERT + default y + help + Say 'N' to disable the HW/SW Params Refinement feature, which may + save about 13KB code size on x86_64 object target. + Please be noted that enabling this may break alsa on the desktop, + only use it with tinyalsa/tinyplay for device such as IoT. + config SND_VERBOSE_PROCFS bool "Verbose procfs contents" depends on SND_PROC_FS
sound/core/Makefile +1 -0
@@ -18,6 +18,7 @@ snd-pcm-y := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \ snd-pcm-$(CONFIG_SND_DMA_SGBUF) += sgbuf.o snd-pcm-$(CONFIG_SND_PCM_ELD) += pcm_drm_eld.o snd-pcm-$(CONFIG_SND_PCM_IEC958) += pcm_iec958.o +snd-pcm-$(CONFIG_SND_PARAMS_REFINEMENT) += pcm_refine.o # for trace-points CFLAGS_pcm_lib.o := -I$(src)
sound/core/pcm_lib.c +0 -982
994 lines not on this page · raw message
sound/core/pcm_native.c +0 -505
529 lines not on this page · raw message
sound/core/pcm_refine.c new file +1519 -0
997 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.1
Part of the diff is not shown here. View the raw message.
Quoted 3 lines · Jie Yang
The change moves refinement functions from original
pcm_native.candpcm_lib.c, topcm_refine.c(similarly the declaration from pcm.h to pcm_refine.h), so it is not so big as it looks like.
I'd suggest that for review it'd be easier to have one patch for the move and another for the change in behaviour: it's a bit hard to find the actual change in what the kernel does in this diff and that's the bit that needs most careful consideration.
git format-patch -M may also help.
Quoted 14 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Friday, June 05, 2015 3:16 AM
To: Jie, Yang
Cc: [email protected]; [email protected]; Girdwood, Liam R; Zhang, Vivian
Subject: Re: [RFC PATCH] ALSA: split params refinement to seperated fileQuoted 3 lines · Jie Yang
The change moves refinement functions from original
pcm_native.candpcm_lib.c, topcm_refine.c(similarly the declaration from pcm.h to pcm_refine.h), so it is not so big as it looks like.
Quoted 6 lines
I'd suggest that for review it'd be easier to have one patch for the move and another for the change in behaviour: it's a bit hard to find the actual change in what the kernel does in this diff and that's the bit that needs most careful consideration.
git format-patch -M may also help.
Umm, Liam also suggested that, it's really hard for reviewing, but I found that "git format-patch -M" doesn't help for partially splitting/moving from a file to another/new file, I even tried '-M5%', but no luck. :(
I can't find good way to make it better, any suggestion?
~Keyon
At Mon, 8 Jun 2015 07:35:17 +0000,
Quoted 20 lines · Yang
Quoted 20 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Friday, June 05, 2015 3:16 AM
To: Jie, Yang
Cc: [email protected]; [email protected]; Girdwood, Liam R; Zhang, Vivian
Subject: Re: [RFC PATCH] ALSA: split params refinement to seperated fileQuoted 3 lines · Jie Yang
The change moves refinement functions from original
pcm_native.candpcm_lib.c, topcm_refine.c(similarly the declaration from pcm.h to pcm_refine.h), so it is not so big as it looks like.I'd suggest that for review it'd be easier to have one patch for the move and another for the change in behaviour: it's a bit hard to find the actual change in what the kernel does in this diff and that's the bit that needs most careful consideration.
Quoted 7 lines
Quoted 1 line
git format-patch -M may also help.
Umm, Liam also suggested that, it's really hard for reviewing, but I found that "git format-patch -M" doesn't help for partially splitting/moving from a file to another/new file, I even tried '-M5%', but no luck. :(
I can't find good way to make it better, any suggestion?
Just begin with adding ifdefs instead of reshuffling the code. This will make easier to understand what you're going to change. At least, it's good enough for RFC. After that, we can refactor the code.
But, before going further, I'd like to know the exact measurement you've done, the target and the goal. Measuring only the static code size doesn't help much from the whole system POV. Also, it's not clear which functionality has to be kept with which drivers and which configuration.
Removing the hw constraints refinement is rather a radical change. It's a part of the PCM core functionality, and removing it means that the driver has no ways to refuse the incompatible parameters even if it knows it's broken. So, IMO, this is the very last resort. We can start from ripping off lower hanging fruits.
thanks,
Takashi
Quoted 3 lines · Takashi Iwai
Just begin with adding ifdefs instead of reshuffling the code. This will make easier to understand what you're going to change. At least, it's good enough for RFC. After that, we can refactor the code.
Plus if the patches get applied it at least makes it easier for people who do decide to do such major surgery.
Quoted 5 lines
Removing the hw constraints refinement is rather a radical change. It's a part of the PCM core functionality, and removing it means that the driver has no ways to refuse the incompatible parameters even if it knows it's broken. So, IMO, this is the very last resort. We can start from ripping off lower hanging fruits.
Indeed, part of the reason I was asking about the split was to help me figure out what takes the place of constraints - sounds like nothing? I wonder if we could have cards support this by providing fixed configurations that we could check against using less code or something. But like you say, we *must* have some other room for improvement.
At Tue, 9 Jun 2015 18:57:11 +0100,
Quoted 16 lines · Mark Brown
Quoted 3 lines · Takashi Iwai
Just begin with adding ifdefs instead of reshuffling the code. This will make easier to understand what you're going to change. At least, it's good enough for RFC. After that, we can refactor the code.
Plus if the patches get applied it at least makes it easier for people who do decide to do such major surgery.
Quoted 5 lines
Removing the hw constraints refinement is rather a radical change. It's a part of the PCM core functionality, and removing it means that the driver has no ways to refuse the incompatible parameters even if it knows it's broken. So, IMO, this is the very last resort. We can start from ripping off lower hanging fruits.
Quoted 4 lines
Indeed, part of the reason I was asking about the split was to help me figure out what takes the place of constraints - sounds like nothing? I wonder if we could have cards support this by providing fixed configurations that we could check against using less code or something.
I think it's possible to reduce the hw refine part. But, the question is whether a kernel driver should trust user-space blindly. The removal of *full* hw constraints means that, and I'm worried by lack of safety.
Quoted 1 line
But like you say, we *must* have some other room for improvement.
Yes, let's see other things we can cut off. For example, the PCM timer is easy to trim. It's used by dmix, but most apps / backends don't need it at all. Then the whole ALSA timer component can be removed, too.
Takashi
Quoted 11 lines · Takashi Iwai
Quoted 4 lines · Mark Brown
Indeed, part of the reason I was asking about the split was to help me figure out what takes the place of constraints - sounds like nothing? I wonder if we could have cards support this by providing fixed configurations that we could check against using less code or something.
I think it's possible to reduce the hw refine part. But, the question is whether a kernel driver should trust user-space blindly. The removal of *full* hw constraints means that, and I'm worried by lack of safety.
Quite, I think you're right on the blind trust. It seems like too much potential for people to break their systems. The code reorganisation to make it easier to modify the kernel if you really know what you're doing seems much less worrying but that final step with no further safeguards is a bit too much.
Quoted 34 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, June 10, 2015 2:51 AM
To: Mark Brown
Cc: Jie, Yang; [email protected]; Girdwood, Liam R; Zhang, Vivian
Subject: Re: [RFC PATCH] ALSA: split params refinement to seperated fileAt Tue, 9 Jun 2015 18:57:11 +0100,
Quoted 16 lines · Mark Brown
Quoted 3 lines · Takashi Iwai
Just begin with adding ifdefs instead of reshuffling the code. This will make easier to understand what you're going to change. At least, it's good enough for RFC. After that, we can refactor the code.
Plus if the patches get applied it at least makes it easier for people who do decide to do such major surgery.
Quoted 5 lines
Removing the hw constraints refinement is rather a radical change. It's a part of the PCM core functionality, and removing it means that the driver has no ways to refuse the incompatible parameters even if it knows it's broken. So, IMO, this is the very last resort. We can start from ripping off lower hanging fruits.
Quoted 4 lines
Indeed, part of the reason I was asking about the split was to help me figure out what takes the place of constraints - sounds like nothing? I wonder if we could have cards support this by providing fixed configurations that we could check against using less code or something.
I think it's possible to reduce the hw refine part. But, the question is whether a kernel driver should trust user-space blindly. The removal of *full* hw constraints means that, and I'm worried by lack of safety.
Quoted 5 lines
Quoted 1 line
But like you say, we *must* have some other room for improvement.
Yes, let's see other things we can cut off. For example, the PCM timer is easy to trim. It's used by dmix, but most apps / backends don't need it at all. Then the whole ALSA timer component can be removed, too.
Thanks for pointing out that, we will investigate cutting off the PCM timer part.
~Keyon
Quoted 3 lines
Takashi
Quoted 38 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, June 08, 2015 5:21 PM
To: Jie, Yang
Cc: Mark Brown; [email protected]; Girdwood, Liam R; Zhang, Vivian
Subject: Re: [RFC PATCH] ALSA: split params refinement to seperated fileAt Mon, 8 Jun 2015 07:35:17 +0000,
Quoted 28 lines · Yang
Quoted 16 lines
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Friday, June 05, 2015 3:16 AM
To: Jie, Yang
Cc: [email protected]; [email protected]; Girdwood, Liam R; Zhang, Vivian
Subject: Re: [RFC PATCH] ALSA: split params refinement to seperated fileQuoted 3 lines · Jie Yang
The change moves refinement functions from original
pcm_native.candpcm_lib.c, topcm_refine.c(similarly the declaration from pcm.h to pcm_refine.h), so it is not so big as it looks like.Quoted 6 lines
I'd suggest that for review it'd be easier to have one patch for the move and another for the change in behaviour: it's a bit hard to find the actual change in what the kernel does in this diff and that's the bit that needs most careful consideration.
git format-patch -M may also help.
Umm, Liam also suggested that, it's really hard for reviewing, but I found that "git format-patch -M" doesn't help for partially splitting/moving from a file to another/new file, I even tried '-M5%', but no luck. :(
Quoted 5 lines
Quoted 1 line
I can't find good way to make it better, any suggestion?
Just begin with adding ifdefs instead of reshuffling the code. This will make easier to understand what you're going to change. At least, it's good enough for RFC. After that, we can refactor the code.
That make sense.
Quoted 3 lines
But, before going further, I'd like to know the exact measurement you've done, the target and the goal. Measuring only the static code size doesn't
Our target the minimum memory footprint usage for ALSA on small(e.g. IoT) devices, and using 'lsmod' to check the status(including memory footprint) of the modules.
Quoted 2 lines
help much from the whole system POV. Also, it's not clear which functionality has to be kept with which drivers and which configuration.
We suppose the bspoke application will pass down the specific params to ALSA on those small devices, then hw refinement may be not needed.
We also made adapted change in tinyplay, did some testing and verified it works in this case.
Quoted 4 lines
Removing the hw constraints refinement is rather a radical change. It's a part of the PCM core functionality, and removing it means that the driver has no ways to refuse the incompatible parameters even if it knows
Can we just return error and refuse doing stream playback/capture when we know it's broken?
Quoted 2 lines
it's broken. So, IMO, this is the very last resort. We can start from ripping off lower hanging fruits.
Agree that it is very last resort, I realized that it is a radical change and impact a lot before sending this RFC. :|
thanks,
~Keyon
Quoted 5 lines
thanks,
Takashi
Quoted 5 lines · Yang
Quoted 4 lines
I'd suggest that for review it'd be easier to have one patch for the move and another for the change in behaviour: it's a bit hard to find the actual change in what the kernel does in this diff and that's the bit that needs most careful consideration.
Quoted 7 lines
Quoted 1 line
git format-patch -M may also help.
Umm, Liam also suggested that, it's really hard for reviewing, but I found that "git format-patch -M" doesn't help for partially splitting/moving from a file to another/new file, I even tried '-M5%', but no luck. :(
I can't find good way to make it better, any suggestion?
I think the thing I suggested about having one patch that only moves code around and another that allows you to disable the constraining would also help - the first patch will be big but mechanical which helps.