Skip to contentSkip to conversation

Scatter Gather

DISCUSSION Manuel Jander 5 participants 6 messages Feb 27, 2004 – Mar 2, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

AFAIK, it seems that when using a scatter gather buffer, not every period is located inside of a page. If for example i use a period size of 3000 bytes and a Scatter Gather buffer, i would have this:

pages : page0, page1, page2 ...
periods: p0, p1, p2, p3, p4 ...

|...page0...||...page1...||...page3...|
|...p0...||...p1...||...p2...||...p3...|

The problem is that a DMA transfer can not go accross 2 different pages. On Aureal hardware, even on contiguous buffers this causes all sort of odd problems. Each DMA chunk must be on the same page.

So i would have to do this:

d0, d1, d2, d3 : DMA chunks programmed in hardware. There are 4 for each DMA channel.

|...page0...||...page1...||...page3...|
|...p0...||..|.p1...||...p2...||...p3...|
|...d0...||d1||.d2..||d3||.d0.||..d1..|

That means that i would have to split each period that crosses a page boundary into 2 DMA chunks, with all the complications involved because of irregular sizes, offsets... ARghhh!

I could just leave the period size as a power of 2, on that way, a period would never cross any page boundary, but most ALSA programs are too picky to accept that kind of restrictions in most cases.

----------------------------------------------
Regarding the "Writing a ALSA driver" Docbook:

Regarding the Non contiguous buffers, that the sgbuf struct can be derived as:

snd_pcm_sgbuf_t *sgbuf = (snd_pcm_sgbuf_t*)substream->dma_private;

But there is a problem: The substream->dma_private is only valid after snd_pcm_lib_malloc_pages() has been called. Maybe it would be nice to hint about this small detail in the document.

Best Regards

Manuel

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

#1 lore raw
Quoted 9 lines · Manuel Jander

AFAIK, it seems that when using a scatter gather buffer, not every period is located inside of a page. ...
The problem is that a DMA transfer can not go accross 2 different pages. On Aureal hardware, even on contiguous buffers this causes all sort of odd problems. Each DMA chunk must be on the same page.
...
That means that i would have to split each period that crosses a page boundary into 2 DMA chunks, with all the complications involved because of irregular sizes, offsets... ARghhh!

Yes. Every driver using SG must do this. Look into bt87x.c or via82xx.c for examples.

Quoted 3 lines

I could just leave the period size as a power of 2, on that way, a period would never cross any page boundary, but most ALSA programs are too picky to accept that kind of restrictions in most cases.

Devices like usb and ymfpci have a fixed period size, but their drivers emulate arbitrary period sizes.

Regards,
Clemens

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

#2 lore raw

Hi,

Quoted 11 lines · Clemens Ladisch
Quoted 9 lines · Manuel Jander

AFAIK, it seems that when using a scatter gather buffer, not every period is located inside of a page. ...
The problem is that a DMA transfer can not go accross 2 different pages. On Aureal hardware, even on contiguous buffers this causes all sort of odd problems. Each DMA chunk must be on the same page.
...
That means that i would have to split each period that crosses a page boundary into 2 DMA chunks, with all the complications involved because of irregular sizes, offsets... ARghhh!

Quoted 2 lines

Yes. Every driver using SG must do this. Look into bt87x.c or via82xx.c for examples.

Well, i guess in that case the period size loses any relevance in terms of efficiency. Is there any gain if DMA chunks and period sizes are related in any way ?

Quoted 6 lines
Quoted 3 lines

I could just leave the period size as a power of 2, on that way, a period would never cross any page boundary, but most ALSA programs are too picky to accept that kind of restrictions in most cases.

Devices like usb and ymfpci have a fixed period size, but their drivers emulate arbitrary period sizes.

That means that those hwparam restrictions "should not be used" ?? After realizing that 99% of ALSA apps don't work when using them, renders them quiet useless.

By the way, is it really really necesary that "snd_pcm_period_elapsed()" is called exactly when one period has been playback ? Must that callback be called for every period ?
After looking at the bt87x driver it seems that it doesn't matter after all (is that right ?). I was thinking in calling snd_pcm_period_elapsed() just after each page crossing, instead of period crossing, for simplicity.

Any comments ?

Best Regards

Manuel

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

#3 lore raw
Quoted 7 lines · Manuel Jander

By the way, is it really really necesary that "snd_pcm_period_elapsed()" is called exactly when one period has been playback ? Must that callback be called for every period ?
After looking at the bt87x driver it seems that it doesn't matter after all (is that right ?). I was thinking in calling snd_pcm_period_elapsed() just after each page crossing, instead of period crossing, for simplicity.

It will create extra latency, because application will be woken up later than expected. The driver should try to call this ack immediately when the period transfer is finished.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

#4 lore raw
In reply to Manuel Jander
Quoted 5 lines · On 02-Mar-2004 Manuel Jander wrote:
Quoted 2 lines

Yes. Every driver using SG must do this. Look into bt87x.c or via82xx.c for examples.

Well, i guess in that case the period size loses any relevance in terms of efficiency.

Efficiency about what ? If the hardware can be programmed to use any period size, then the application is free to choose the size it prefers. It's not a bad thing. NB: the interrupt should be generated at the end of the period, not at the end of each block, eg. when it crosses the page boundary.

Quoted 2 lines

Is there any gain if DMA chunks and period sizes are related in any way ?

No, unless the hardware benefits from it.

--
Giuliano.

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

#5 lore raw

At Tue, 02 Mar 2004 11:16:33 +0100 (CET),

Quoted 7 lines · Giuliano Pochini
Quoted 3 lines · On 02-Mar-2004 Manuel Jander wrote:
Quoted 2 lines

Yes. Every driver using SG must do this. Look into bt87x.c or via82xx.c for examples.

Quoted 8 lines
Quoted 2 lines

Well, i guess in that case the period size loses any relevance in terms of efficiency.

Efficiency about what ? If the hardware can be programmed to use any period size, then the application is free to choose the size it prefers. It's not a bad thing. NB: the interrupt should be generated at the end of the period, not at the end of each block, eg. when it crosses the page boundary.

well, it's ok to generate irqs at each page boundary, too, as long as the driver processes it properly, i.e. calling snd_pcm_period_elapsed() only at the irq of the end of period. of course, less irqs are better from the performance viewpoint.

Takashi

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click