public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Qais Yousef <qais.yousef@imgtec.com>
To: Mark Brown <broonie@kernel.org>
Cc: <alsa-devel@alsa-project.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 05/10] ALSA: axd: add buffers manipulation files
Date: Tue, 1 Sep 2015 11:00:42 +0100	[thread overview]
Message-ID: <55E5774A.8070808@imgtec.com> (raw)
In-Reply-To: <20150829094711.GZ12027@sirena.org.uk>

On 08/29/2015 10:47 AM, Mark Brown wrote:
> On Thu, Aug 27, 2015 at 03:21:17PM +0100, Qais Yousef wrote:
>> On 08/26/2015 07:43 PM, Mark Brown wrote:
>>> On Mon, Aug 24, 2015 at 01:39:14PM +0100, Qais Yousef wrote:
>>>> +	/*
>>>> +	 * must ensure we have one access at a time to the queue and rd_idx
>>>> +	 * to be preemption and SMP safe
>>>> +	 * Sempahores will ensure that we will only read after a complete write
>>>> +	 * has finished, so we will never read and write from the same location.
>>>> +	 */
>>> In what way will sempahores ensure that we will only read after a
>>> complete write?
>> This comment needs fixing. What it is trying to say is that if we reached
>> this point of the code then we're certainly allowed to modify the buffer
>> queue and {rd, wr}_idx because the semaphore would have gone to sleep
>> otherwise if the queue is full/empty.
>> Should I just remove the reference to Semaphores from the comment or worth
>> rephrasing it?
> Any comments need to be comprehensible.
>
>> Would it be better to rename {rd, wr}_{idx, sem} to {take, put}_{idx, sem}?
> I'm not sure that helps to be honest, the main issue is that the scheme
> is fairly complex and unexplained.
>
>>>> +	buf = bufferq->queue[bufferq->rd_idx];
>>> So buffers are always retired in the same order that they are acquired?
>> I don't think I get you here. axd_bufferq_take() and axd_bufferq_put() could
>> be called in any order.
> Retiring buffers in the order they are acquired means that buffers are
> always freed in the same order they are acquired, you can't free one
> buffer before another that was acquired first.
>> What this code is trying to do is make a contiguous memory area behave as a
>> ring buffer. Then this ring buffer behave as a queue. We use semaphore
>> counts to control how many are available to take/put. rd_idx and wr_idx
>> should always point at the next location to take/put from/to.
>> Does this help answering your question?
> No.  Why are we doing this?  Essentially all ALSA buffers are ring
> buffers handled in blocks, why does this one need this complex locking
> scheme?

There are 2 sides to this. The ALSA/driver iface and the driver/firmware 
one. The ALSA/driver iface is called from ALSA ops but the 
driver/firmware is handled by the interrupt and workqueues. The code is 
trying to deal with this concurrency. Also once AXD consumed a buffer it 
sends back an interrupt to the driver that it can reuse it, there's no 
guarantee that this returned buffer is in the same order it was sent.

I hear you though. Let me see how I can simplify this :-)

>>>> +void axd_bufferq_abort_put(struct axd_bufferq *bufferq)
>>>> +{
>>>> +	if (axd_bufferq_is_full(bufferq)) {
>>>> +		bufferq->abort_put = 1;
>>>> +		up(&bufferq->wr_sem);
>>>> +	}
>>>> +}
>>> These look *incredibly* racy.  Why are they here and why are they safe?
>> If we want to restart the firmware we will need to abort any blocking reads
>> or writes for the user space to react. I also needed that to implement
> I'm not questioning what the functionns are doing, I'm questioning their
> implementation - it doesn't look like they are safe or reliable.  They
> just set a flag, relying on something else to notice that the flag has
> been set and act appropriately before it goes on and corrupts data.
> That just screams concurrency issues.

OK. I'll see how I can rework the code to address all of your comments.

Thanks,
Qais

>> nonblocking access in user space when this was a sysfs based driver. It was
>> important then to implement omx IL component correctly.
> Nobody cares about OMX ILs in mainline or sysfs based interfaces.
>
>> Do I need to support nonblock reads and writes in ALSA? If I use SIGKILL as
>> you suggested in the other email when restarting and nonblock is not
>> important then I can remove this.
> It would be better to support non blocking access.


  reply	other threads:[~2015-09-01 10:01 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-24 12:39 [PATCH 00/10] Add support for img AXD audio hardware decoder Qais Yousef
2015-08-24 12:39 ` [PATCH 01/10] irqchip: irq-mips-gic: export gic_send_ipi Qais Yousef
2015-08-24 12:49   ` Thomas Gleixner
2015-08-24 13:02     ` Qais Yousef
2015-08-24 13:32       ` Marc Zyngier
2015-08-24 14:27         ` Qais Yousef
2015-08-24 15:07           ` Thomas Gleixner
2015-08-24 16:39             ` Qais Yousef
2015-08-24 17:17               ` Marc Zyngier
2015-08-26 11:23                 ` Qais Yousef
2015-08-26 13:19                   ` Thomas Gleixner
2015-08-26 14:57                     ` Qais Yousef
2015-08-26 15:08                       ` Thomas Gleixner
2015-08-26 15:41                         ` Qais Yousef
2015-08-26 21:40                           ` Thomas Gleixner
2015-08-27  2:22                             ` Jiang Liu
2015-08-28 10:38                             ` Qais Yousef
2015-08-28 14:22                               ` Thomas Gleixner
2015-08-28 15:12                                 ` Qais Yousef
2015-09-02  9:33                                 ` Qais Yousef
2015-09-02  9:55                                   ` Marc Zyngier
2015-09-02 10:48                                     ` Qais Yousef
2015-09-02 11:53                                       ` Marc Zyngier
2015-09-02 13:25                                         ` Qais Yousef
2015-09-02 14:14                                           ` Marc Zyngier
2015-09-02 12:12                                     ` Jason Cooper
2015-08-24 14:55       ` Thomas Gleixner
2015-08-24 15:11         ` Qais Yousef
2015-08-24 12:39 ` [PATCH 02/10] dt: add img,axd.txt device tree binding document Qais Yousef
2015-08-24 13:26   ` Mark Rutland
2015-08-24 13:49     ` Qais Yousef
2015-08-24 12:39 ` [PATCH 03/10] ALSA: add AXD Audio Processing IP alsa driver Qais Yousef
2015-08-26 18:37   ` Mark Brown
2015-08-27 12:15     ` Qais Yousef
2015-08-27 15:32       ` Mark Brown
2015-08-28  9:22         ` Qais Yousef
2015-09-03 12:46           ` Mark Brown
2015-08-24 12:39 ` [PATCH 04/10] ALSA: axd: add fw binary header manipulation files Qais Yousef
2015-08-24 12:39 ` [PATCH 05/10] ALSA: axd: add buffers " Qais Yousef
2015-08-26 18:43   ` Mark Brown
2015-08-27 14:21     ` Qais Yousef
2015-08-29  9:47       ` Mark Brown
2015-09-01 10:00         ` Qais Yousef [this message]
2015-09-03 12:32           ` Mark Brown
2015-09-14  9:11             ` Qais Yousef
2015-09-14 18:50               ` Mark Brown
2015-08-24 12:39 ` [PATCH 06/10] ALSA: axd: add basic files for sending/receiving axd cmds Qais Yousef
2015-08-26 19:16   ` Mark Brown
2015-08-27 15:40     ` Qais Yousef
2015-08-29 10:18       ` Mark Brown
2015-09-01 10:46         ` Qais Yousef
2015-09-03 12:40           ` Mark Brown
2015-08-24 12:39 ` [PATCH 07/10] ALSA: axd: add cmd interface helper functions Qais Yousef
2015-08-24 12:39 ` [PATCH 08/10] ALSA: axd: add low level AXD platform setup files Qais Yousef
2015-08-24 12:39 ` [PATCH 09/10] ALSA: axd: add alsa compress offload operations Qais Yousef
2015-08-24 12:39 ` [PATCH 10/10] ALSA: axd: add Makefile Qais Yousef
2015-08-26 18:04 ` [PATCH 00/10] Add support for img AXD audio hardware decoder Mark Brown
2015-08-27  9:07   ` Qais Yousef

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=55E5774A.8070808@imgtec.com \
    --to=qais.yousef@imgtec.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox