All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Gabbasov <andrew_gabbasov@mentor.com>
To: 'Takashi Iwai' <tiwai@suse.de>
Cc: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Timo Wischer <twischer@de.adit-jv.com>
Subject: RE: [PATCH v5 0/7] ALSA: aloop: Support sound timer as clock source instead of jiffies
Date: Fri, 22 Nov 2019 20:56:42 +0300	[thread overview]
Message-ID: <000001d5a15e$3dc81c20$b9585460$@mentor.com> (raw)
In-Reply-To: <s5hblt6v0x4.wl-tiwai@suse.de>

Hello Takashi,

> -----Original Message-----
> From: Takashi Iwai [mailto:tiwai@suse.de]
> Sent: Wednesday, November 20, 2019 9:49 PM
> To: Gabbasov, Andrew
> Cc: alsa-devel@alsa-project.org; linux-kernel@vger.kernel.org; Jaroslav
> Kysela; Takashi Iwai; Timo Wischer
> Subject: Re: [PATCH v5 0/7] ALSA: aloop: Support sound timer as clock
> source instead of jiffies
> 
> On Wed, 20 Nov 2019 18:49:48 +0100,
> Andrew Gabbasov wrote:
> >
> > This patch set is an updated version of patches by Timo Wischer:
> > https://mailman.alsa-project.org/pipermail/alsa-devel/2019-
> March/146871.html
> >
> > This patch set is required for forwarding audio data between a HW sound
> > card and an aloop device without the usage of an asynchronous sample
rate
> > converter.
> >
> > Most of sound and timers related code is kept the same as in previous
> set.
> > The code, related to snd_pcm_link() functionality and its using for
> > timer source setting, is removed (as rejected earlier). The changes in
> this
> > update are mainly related to the parameters handling and some cleanup.
> >
> > The timer source can be initially selected by "timer_source" kernel
> module
> > parameter. It is supposed to have the following format:
> >     [<pref>:](<card name>|<card idx>)[{.,}<dev idx>[{.,}<subdev idx>]]
> > For example: "hw:I82801AAICH.1.0", or "1.1", or just "I82801AAICH".
> > (Prefix is ignored, just allowed here to be able to use the strings,
> > the user got used to).
> > Although the parsing function recognizes both '.' and ',' as a
separator,
> > module parameters handling routines use ',' to separate parameters for
> > different module instances (array elements), so we have to use '.'
> > to separate device and subdevice numbers from the card name or number
> > in module parameters.
> > Empty string indicates using jiffies as a timer source.
> >
> > Besides "static" selection of timer source at module load time,
> > it is possible to dynamically change it via sound "info" interface
> > (using "/proc/asound/<card>/timer_source" file in read-write mode.
> > The contents of this file is used as a timer source string for
> > a particular loopback card, e.g. "hw:0,0,0" (and here ',' can be used
> > as a separator).
> >
> > The timer source string value can be changed at any time, but it is
> > latched by PCM substream open callback "loopback_open()" (the first
> > one for a particular cable). At this point it is actually used,
> > that is the string is parsed, and the timer is looked up and opened.
> > This seems to be a good trade-off between flexibility of updates and
> > synchronizations or racing complexity.
> >
> > The timer source is set for a loopback card (the same as initial setting
> > by module parameter), but every cable uses the value, current at the
> moment
> > of opening. Theoretically, it's possible to set the timer source for
each
> > cable independently (via separate files), but it would be inconsistent
> > with the initial setting via module parameters on a per-card basis.
> >
> > v2:
> > https://mailman.alsa-project.org/pipermail/alsa-devel/2019-
> November/157961.html
> >
> > v3:
> > https://mailman.alsa-project.org/pipermail/alsa-devel/2019-
> November/158312.html
> > - Change sound card lookup to use snd_card_ref() and avoid direct access
> >   to sound cards array
> > - Squash commits on returning error codes for timer start and stop
> > - Some locking related fixes
> > - Some code cleanup
> >
> > v4:
> > https://mailman.alsa-project.org/pipermail/alsa-devel/2019-
> November/158896.html
> > - Change to use updated API for snd_timer_open() (separate timer
> instance)
> > - Change to use snd_timer_close() returning void
> > - Some code cleanup
> >
> > v5:
> > - Change to initialize timer event tasklet before calling
> snd_timer_open()
> >
> >
> > Andrew Gabbasov (1):
> >   ALSA: aloop: Support runtime change of snd_timer via info interface
> >
> > Timo Wischer (6):
> >   ALSA: aloop: Describe units of variables
> >   ALSA: aloop: Support return of error code for timer start and stop
> >   ALSA: aloop: Use callback functions for timer specific implementations
> >   ALSA: aloop: Rename all jiffies timer specific functions
> >   ALSA: aloop: Move CABLE_VALID_BOTH to the top of file
> >   ALSA: aloop: Support selection of snd_timer instead of jiffies
> 
> Now applied all patches.  Thanks.

Thank you very much!

Unfortunately, I found some issue with locking in patch 6
(sorry for late finding):
loopback_parse_timer_id() uses snd_card_ref(), that can lock on mutex,
also snd_timer_instance_new() uses non-atomic allocation, that can sleep.
So, both functions can not be called from loopback_snd_timer_open()
with cable->lock spinlock locked.

Also, most part of loopback_snd_timer_open() function body works
when the opposite stream of the same cable does not yet exist, and
the current stream is not yet completely open and can't be running,
so existing locking of loopback->cable_lock mutex is enough to protect
from conflicts with simultaneous opening or closing.

So, it looks like locking of cable->lock spinlock is not needed
in loopback_snd_timer_open() at all
(similarly to loopback_snd_timer_close_cable()).

I'm sending a separate patch to fix this:
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/159087.h
tml

Also, when you requested to move tasklet_init() call to before
snd_timer_open() call, I should have guessed to look into the
reverse closing side too ;-)
Now, I have to add one more patch to move tasklet_kill() call
to after snd_timer_close().
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/159088.h
tml

Please, take a look at the patches.

Thanks!

Best regards,
Andrew


WARNING: multiple messages have this Message-ID (diff)
From: Andrew Gabbasov <andrew_gabbasov@mentor.com>
To: 'Takashi Iwai' <tiwai@suse.de>
Cc: Timo Wischer <twischer@de.adit-jv.com>,
	alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [alsa-devel] [PATCH v5 0/7] ALSA: aloop: Support sound timer as clock source instead of jiffies
Date: Fri, 22 Nov 2019 20:56:42 +0300	[thread overview]
Message-ID: <000001d5a15e$3dc81c20$b9585460$@mentor.com> (raw)
In-Reply-To: <s5hblt6v0x4.wl-tiwai@suse.de>

Hello Takashi,

> -----Original Message-----
> From: Takashi Iwai [mailto:tiwai@suse.de]
> Sent: Wednesday, November 20, 2019 9:49 PM
> To: Gabbasov, Andrew
> Cc: alsa-devel@alsa-project.org; linux-kernel@vger.kernel.org; Jaroslav
> Kysela; Takashi Iwai; Timo Wischer
> Subject: Re: [PATCH v5 0/7] ALSA: aloop: Support sound timer as clock
> source instead of jiffies
> 
> On Wed, 20 Nov 2019 18:49:48 +0100,
> Andrew Gabbasov wrote:
> >
> > This patch set is an updated version of patches by Timo Wischer:
> > https://mailman.alsa-project.org/pipermail/alsa-devel/2019-
> March/146871.html
> >
> > This patch set is required for forwarding audio data between a HW sound
> > card and an aloop device without the usage of an asynchronous sample
rate
> > converter.
> >
> > Most of sound and timers related code is kept the same as in previous
> set.
> > The code, related to snd_pcm_link() functionality and its using for
> > timer source setting, is removed (as rejected earlier). The changes in
> this
> > update are mainly related to the parameters handling and some cleanup.
> >
> > The timer source can be initially selected by "timer_source" kernel
> module
> > parameter. It is supposed to have the following format:
> >     [<pref>:](<card name>|<card idx>)[{.,}<dev idx>[{.,}<subdev idx>]]
> > For example: "hw:I82801AAICH.1.0", or "1.1", or just "I82801AAICH".
> > (Prefix is ignored, just allowed here to be able to use the strings,
> > the user got used to).
> > Although the parsing function recognizes both '.' and ',' as a
separator,
> > module parameters handling routines use ',' to separate parameters for
> > different module instances (array elements), so we have to use '.'
> > to separate device and subdevice numbers from the card name or number
> > in module parameters.
> > Empty string indicates using jiffies as a timer source.
> >
> > Besides "static" selection of timer source at module load time,
> > it is possible to dynamically change it via sound "info" interface
> > (using "/proc/asound/<card>/timer_source" file in read-write mode.
> > The contents of this file is used as a timer source string for
> > a particular loopback card, e.g. "hw:0,0,0" (and here ',' can be used
> > as a separator).
> >
> > The timer source string value can be changed at any time, but it is
> > latched by PCM substream open callback "loopback_open()" (the first
> > one for a particular cable). At this point it is actually used,
> > that is the string is parsed, and the timer is looked up and opened.
> > This seems to be a good trade-off between flexibility of updates and
> > synchronizations or racing complexity.
> >
> > The timer source is set for a loopback card (the same as initial setting
> > by module parameter), but every cable uses the value, current at the
> moment
> > of opening. Theoretically, it's possible to set the timer source for
each
> > cable independently (via separate files), but it would be inconsistent
> > with the initial setting via module parameters on a per-card basis.
> >
> > v2:
> > https://mailman.alsa-project.org/pipermail/alsa-devel/2019-
> November/157961.html
> >
> > v3:
> > https://mailman.alsa-project.org/pipermail/alsa-devel/2019-
> November/158312.html
> > - Change sound card lookup to use snd_card_ref() and avoid direct access
> >   to sound cards array
> > - Squash commits on returning error codes for timer start and stop
> > - Some locking related fixes
> > - Some code cleanup
> >
> > v4:
> > https://mailman.alsa-project.org/pipermail/alsa-devel/2019-
> November/158896.html
> > - Change to use updated API for snd_timer_open() (separate timer
> instance)
> > - Change to use snd_timer_close() returning void
> > - Some code cleanup
> >
> > v5:
> > - Change to initialize timer event tasklet before calling
> snd_timer_open()
> >
> >
> > Andrew Gabbasov (1):
> >   ALSA: aloop: Support runtime change of snd_timer via info interface
> >
> > Timo Wischer (6):
> >   ALSA: aloop: Describe units of variables
> >   ALSA: aloop: Support return of error code for timer start and stop
> >   ALSA: aloop: Use callback functions for timer specific implementations
> >   ALSA: aloop: Rename all jiffies timer specific functions
> >   ALSA: aloop: Move CABLE_VALID_BOTH to the top of file
> >   ALSA: aloop: Support selection of snd_timer instead of jiffies
> 
> Now applied all patches.  Thanks.

Thank you very much!

Unfortunately, I found some issue with locking in patch 6
(sorry for late finding):
loopback_parse_timer_id() uses snd_card_ref(), that can lock on mutex,
also snd_timer_instance_new() uses non-atomic allocation, that can sleep.
So, both functions can not be called from loopback_snd_timer_open()
with cable->lock spinlock locked.

Also, most part of loopback_snd_timer_open() function body works
when the opposite stream of the same cable does not yet exist, and
the current stream is not yet completely open and can't be running,
so existing locking of loopback->cable_lock mutex is enough to protect
from conflicts with simultaneous opening or closing.

So, it looks like locking of cable->lock spinlock is not needed
in loopback_snd_timer_open() at all
(similarly to loopback_snd_timer_close_cable()).

I'm sending a separate patch to fix this:
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/159087.h
tml

Also, when you requested to move tasklet_init() call to before
snd_timer_open() call, I should have guessed to look into the
reverse closing side too ;-)
Now, I have to add one more patch to move tasklet_kill() call
to after snd_timer_close().
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/159088.h
tml

Please, take a look at the patches.

Thanks!

Best regards,
Andrew

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2019-11-22 17:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 17:49 [PATCH v5 0/7] ALSA: aloop: Support sound timer as clock source instead of jiffies Andrew Gabbasov
2019-11-20 17:49 ` [alsa-devel] " Andrew Gabbasov
2019-11-20 17:49 ` [PATCH v5 1/7] ALSA: aloop: Describe units of variables Andrew Gabbasov
2019-11-20 17:49   ` [alsa-devel] " Andrew Gabbasov
2019-11-20 17:49   ` [PATCH v5 2/7] ALSA: aloop: Support return of error code for timer start and stop Andrew Gabbasov
2019-11-20 17:49     ` [alsa-devel] " Andrew Gabbasov
2019-11-20 17:49     ` [PATCH v5 3/7] ALSA: aloop: Use callback functions for timer specific implementations Andrew Gabbasov
2019-11-20 17:49       ` [alsa-devel] " Andrew Gabbasov
2019-11-20 17:49       ` [PATCH v5 4/7] ALSA: aloop: Rename all jiffies timer specific functions Andrew Gabbasov
2019-11-20 17:49         ` [alsa-devel] " Andrew Gabbasov
2019-11-20 17:49         ` [PATCH v5 5/7] ALSA: aloop: Move CABLE_VALID_BOTH to the top of file Andrew Gabbasov
2019-11-20 17:49           ` [alsa-devel] " Andrew Gabbasov
2019-11-20 17:49           ` [PATCH v5 6/7] ALSA: aloop: Support selection of snd_timer instead of jiffies Andrew Gabbasov
2019-11-20 17:49             ` [alsa-devel] " Andrew Gabbasov
2019-11-20 17:49             ` [PATCH v5 7/7] ALSA: aloop: Support runtime change of snd_timer via info interface Andrew Gabbasov
2019-11-20 17:49               ` [alsa-devel] " Andrew Gabbasov
2019-11-20 18:48 ` [PATCH v5 0/7] ALSA: aloop: Support sound timer as clock source instead of jiffies Takashi Iwai
2019-11-22 17:56   ` Andrew Gabbasov [this message]
2019-11-22 17:56     ` [alsa-devel] " Andrew Gabbasov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000001d5a15e$3dc81c20$b9585460$@mentor.com' \
    --to=andrew_gabbasov@mentor.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    --cc=twischer@de.adit-jv.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.