* [PATCH] ALSA: pcmtest: Extend error injection, decrease buffer filling overhead
@ 2023-07-12 19:13 Ivan Orlov
2023-07-13 6:03 ` Takashi Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Ivan Orlov @ 2023-07-12 19:13 UTC (permalink / raw)
To: perex, tiwai; +Cc: Ivan Orlov, alsa-devel, linux-kernel
Extend 'pcmtest' virtual driver with 'open' callback error injection
functionality, as it already can inject errors into other PCM callbacks.
Fix the driver to use already defined variables where it is possible.
Additionally, decrease the buffer filling overhead with conditional
reminder calculation in the 'inc_buf_pos' inline function.
Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
---
sound/drivers/pcmtest.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c
index 291e7fe47893..08e14b5eb772 100644
--- a/sound/drivers/pcmtest.c
+++ b/sound/drivers/pcmtest.c
@@ -65,6 +65,7 @@ static int inject_delay;
static bool inject_hwpars_err;
static bool inject_prepare_err;
static bool inject_trigger_err;
+static bool inject_open_err;
static short fill_mode = FILL_MODE_PAT;
@@ -88,6 +89,9 @@ module_param(inject_prepare_err, bool, 0600);
MODULE_PARM_DESC(inject_prepare_err, "Inject EINVAL error in the 'prepare' callback");
module_param(inject_trigger_err, bool, 0600);
MODULE_PARM_DESC(inject_trigger_err, "Inject EINVAL error in the 'trigger' callback");
+module_param(inject_open_err, bool, 0600);
+MODULE_PARM_DESC(inject_open_err, "Inject EBUSY error in the 'open' callback");
+
struct pcmtst {
struct snd_pcm *pcm;
@@ -140,7 +144,8 @@ static inline void inc_buf_pos(struct pcmtst_buf_iter *v_iter, size_t by, size_t
{
v_iter->total_bytes += by;
v_iter->buf_pos += by;
- v_iter->buf_pos %= bytes;
+ if (v_iter->buf_pos >= bytes)
+ v_iter->buf_pos %= bytes;
}
/*
@@ -196,10 +201,10 @@ static void check_buf_block_ni(struct pcmtst_buf_iter *v_iter, struct snd_pcm_ru
u8 current_byte;
for (i = 0; i < v_iter->b_rw; i++) {
- current_byte = runtime->dma_area[buf_pos_n(v_iter, channels, i % channels)];
+ ch_num = i % channels;
+ current_byte = runtime->dma_area[buf_pos_n(v_iter, channels, ch_num)];
if (!current_byte)
break;
- ch_num = i % channels;
if (current_byte != patt_bufs[ch_num].buf[(v_iter->total_bytes / channels)
% patt_bufs[ch_num].len]) {
v_iter->is_buf_corrupted = true;
@@ -239,7 +244,7 @@ static void fill_block_pattern_n(struct pcmtst_buf_iter *v_iter, struct snd_pcm_
for (i = 0; i < v_iter->b_rw; i++) {
ch_num = i % channels;
- runtime->dma_area[buf_pos_n(v_iter, channels, i % channels)] =
+ runtime->dma_area[buf_pos_n(v_iter, channels, ch_num)] =
patt_bufs[ch_num].buf[(v_iter->total_bytes / channels)
% patt_bufs[ch_num].len];
inc_buf_pos(v_iter, 1, runtime->dma_bytes);
@@ -364,6 +369,9 @@ static int snd_pcmtst_pcm_open(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime = substream->runtime;
struct pcmtst_buf_iter *v_iter;
+ if (inject_open_err)
+ return -EBUSY;
+
v_iter = kzalloc(sizeof(*v_iter), GFP_KERNEL);
if (!v_iter)
return -ENOMEM;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: pcmtest: Extend error injection, decrease buffer filling overhead
2023-07-12 19:13 [PATCH] ALSA: pcmtest: Extend error injection, decrease buffer filling overhead Ivan Orlov
@ 2023-07-13 6:03 ` Takashi Iwai
2023-07-13 7:48 ` Ivan Orlov
0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2023-07-13 6:03 UTC (permalink / raw)
To: Ivan Orlov; +Cc: perex, tiwai, alsa-devel, linux-kernel
On Wed, 12 Jul 2023 21:13:25 +0200,
Ivan Orlov wrote:
>
> Extend 'pcmtest' virtual driver with 'open' callback error injection
> functionality, as it already can inject errors into other PCM callbacks.
>
> Fix the driver to use already defined variables where it is possible.
>
> Additionally, decrease the buffer filling overhead with conditional
> reminder calculation in the 'inc_buf_pos' inline function.
>
> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Please avoid mixing different changes in a single patch.
This patch does three completely different things, and they should be
split.
- New inject_open_err parameter
- Optimization of inc_buf_pos()
- Optimization of check_buf_block_ni() and fill_block_pattern_n()
The latter two could be put in a single patch as minor optimizations,
but the introduction of a new option doesn't fit with the rest.
thanks,
Takashi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ALSA: pcmtest: Extend error injection, decrease buffer filling overhead
2023-07-13 6:03 ` Takashi Iwai
@ 2023-07-13 7:48 ` Ivan Orlov
0 siblings, 0 replies; 3+ messages in thread
From: Ivan Orlov @ 2023-07-13 7:48 UTC (permalink / raw)
To: Takashi Iwai; +Cc: perex, tiwai, alsa-devel, linux-kernel
On 7/13/23 10:03, Takashi Iwai wrote:
> On Wed, 12 Jul 2023 21:13:25 +0200,
> Ivan Orlov wrote:
>>
>> Extend 'pcmtest' virtual driver with 'open' callback error injection
>> functionality, as it already can inject errors into other PCM callbacks.
>>
>> Fix the driver to use already defined variables where it is possible.
>>
>> Additionally, decrease the buffer filling overhead with conditional
>> reminder calculation in the 'inc_buf_pos' inline function.
>>
>> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
>
> Please avoid mixing different changes in a single patch.
>
> This patch does three completely different things, and they should be
> split.
>
> - New inject_open_err parameter
> - Optimization of inc_buf_pos()
> - Optimization of check_buf_block_ni() and fill_block_pattern_n()
>
> The latter two could be put in a single patch as minor optimizations,
> but the introduction of a new option doesn't fit with the rest.
>
>
> thanks,
>
> Takashi
Hi Takashi,
Thank you for the review. I'll split the patch and send the changes again.
Kind regards,
Ivan Orlov
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-13 7:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-12 19:13 [PATCH] ALSA: pcmtest: Extend error injection, decrease buffer filling overhead Ivan Orlov
2023-07-13 6:03 ` Takashi Iwai
2023-07-13 7:48 ` Ivan Orlov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®