All of lore.kernel.org
 help / color / mirror / Atom feed
* Upgrade driver to 1.0.6, memory allocation?
@ 2004-08-19  2:57 Eliot Blennerhassett
  0 siblings, 0 replies; 6+ messages in thread
From: Eliot Blennerhassett @ 2004-08-19  2:57 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux

[-- Attachment #1: Type: text/plain, Size: 2056 bytes --]

Hello all,

with the upgrade to 1.0.6, my alsa driver broke. (asihpi)
Now I'm trying to put it together again, and could do with some tips...
Mostly it still contained lots of easy to fix snd_magic_cast() but
Can anybody confirm that the following update is the 'correct' thing to
do?

(My) old code:
call snd_malloc_pages_fallback in the open callback.

New code:
call snd_pcm_lib_malloc_pages() in the hw_params callback

and call snd_pcm_lib_preallocate_pages_for_all() in the sound card pcm
init function (in my case snd_card_asihpi_pcm()
================================
By default according to pcm_memory.c, only a maximum of 4 substreams are
allowed.
My cards have up to 16 substreams.

Chapter 10 of "Writing an alsa driver" says
"snd_pcm_lib_malloc_pages(substream, size);
Note that you have to pre-allocate to use this function. "

Does this only mean that you have to preallocate at least one buffer to
use the function?

If I read it correctly, snd_pcm_lib_malloc_pages will still try to
allocate some memory for substreams> 4, this just becomes less likely as
the system mem becomes fragmented.

Is there a rationale for making the substreams limit 4 as opposed to any
other number?
I guess I can change the max_substreams by providing a module parameter
to snd-pcm module.
============================
snd_pcm_lib_preallocate_pages1()
...
if (size> 0 && preallocate_dma && substream->number <maximum_substreams)
preallocate_pcm_pages(substream, size);
...
Maybe I'm missing something, but it seems the possible error return
value from preallocate_pcm_pages is ignored - is this intentional?
===========================
TIA for any enligtenment about the above.

-- Eliot



<P><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">ICQ - You get the message, anywhere!<br>Get it @ <a href="http://www.icq.com" target=new>http://www.icq.com</a></font><br><br>&nbsp;</font></font>

[-- Attachment #2: Type: text/html, Size: 2249 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Upgrade driver to 1.0.6, memory allocation?
@ 2004-08-19  2:57 Eliot Blennerhassett
  2004-08-19  9:53 ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Eliot Blennerhassett @ 2004-08-19  2:57 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux

[-- Attachment #1: Type: text/plain, Size: 2056 bytes --]

Hello all,

with the upgrade to 1.0.6, my alsa driver broke. (asihpi)
Now I'm trying to put it together again, and could do with some tips...
Mostly it still contained lots of easy to fix snd_magic_cast() but
Can anybody confirm that the following update is the 'correct' thing to
do?

(My) old code:
call snd_malloc_pages_fallback in the open callback.

New code:
call snd_pcm_lib_malloc_pages() in the hw_params callback

and call snd_pcm_lib_preallocate_pages_for_all() in the sound card pcm
init function (in my case snd_card_asihpi_pcm()
================================
By default according to pcm_memory.c, only a maximum of 4 substreams are
allowed.
My cards have up to 16 substreams.

Chapter 10 of "Writing an alsa driver" says
"snd_pcm_lib_malloc_pages(substream, size);
Note that you have to pre-allocate to use this function. "

Does this only mean that you have to preallocate at least one buffer to
use the function?

If I read it correctly, snd_pcm_lib_malloc_pages will still try to
allocate some memory for substreams> 4, this just becomes less likely as
the system mem becomes fragmented.

Is there a rationale for making the substreams limit 4 as opposed to any
other number?
I guess I can change the max_substreams by providing a module parameter
to snd-pcm module.
============================
snd_pcm_lib_preallocate_pages1()
...
if (size> 0 && preallocate_dma && substream->number <maximum_substreams)
preallocate_pcm_pages(substream, size);
...
Maybe I'm missing something, but it seems the possible error return
value from preallocate_pcm_pages is ignored - is this intentional?
===========================
TIA for any enligtenment about the above.

-- Eliot



<P><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">ICQ - You get the message, anywhere!<br>Get it @ <a href="http://www.icq.com" target=new>http://www.icq.com</a></font><br><br>&nbsp;</font></font>

[-- Attachment #2: Type: text/html, Size: 2249 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Upgrade driver to 1.0.6, memory allocation?
@ 2004-08-19  2:57 Eliot Blennerhassett
  2004-08-19  7:49 ` Giuliano Pochini
  2004-08-19 13:01 ` Fred Gleason
  0 siblings, 2 replies; 6+ messages in thread
From: Eliot Blennerhassett @ 2004-08-19  2:57 UTC (permalink / raw)
  To: alsa-devel; +Cc: linux

[-- Attachment #1: Type: text/plain, Size: 2056 bytes --]

Hello all,

with the upgrade to 1.0.6, my alsa driver broke. (asihpi)
Now I'm trying to put it together again, and could do with some tips...
Mostly it still contained lots of easy to fix snd_magic_cast() but
Can anybody confirm that the following update is the 'correct' thing to
do?

(My) old code:
call snd_malloc_pages_fallback in the open callback.

New code:
call snd_pcm_lib_malloc_pages() in the hw_params callback

and call snd_pcm_lib_preallocate_pages_for_all() in the sound card pcm
init function (in my case snd_card_asihpi_pcm()
================================
By default according to pcm_memory.c, only a maximum of 4 substreams are
allowed.
My cards have up to 16 substreams.

Chapter 10 of "Writing an alsa driver" says
"snd_pcm_lib_malloc_pages(substream, size);
Note that you have to pre-allocate to use this function. "

Does this only mean that you have to preallocate at least one buffer to
use the function?

If I read it correctly, snd_pcm_lib_malloc_pages will still try to
allocate some memory for substreams> 4, this just becomes less likely as
the system mem becomes fragmented.

Is there a rationale for making the substreams limit 4 as opposed to any
other number?
I guess I can change the max_substreams by providing a module parameter
to snd-pcm module.
============================
snd_pcm_lib_preallocate_pages1()
...
if (size> 0 && preallocate_dma && substream->number <maximum_substreams)
preallocate_pcm_pages(substream, size);
...
Maybe I'm missing something, but it seems the possible error return
value from preallocate_pcm_pages is ignored - is this intentional?
===========================
TIA for any enligtenment about the above.

-- Eliot



<P><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">ICQ - You get the message, anywhere!<br>Get it @ <a href="http://www.icq.com" target=new>http://www.icq.com</a></font><br><br>&nbsp;</font></font>

[-- Attachment #2: Type: text/html, Size: 2249 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Upgrade driver to 1.0.6, memory allocation?
  2004-08-19  2:57 Upgrade driver to 1.0.6, memory allocation? Eliot Blennerhassett
@ 2004-08-19  7:49 ` Giuliano Pochini
  2004-08-19 13:01 ` Fred Gleason
  1 sibling, 0 replies; 6+ messages in thread
From: Giuliano Pochini @ 2004-08-19  7:49 UTC (permalink / raw)
  To: Eliot Blennerhassett; +Cc: linux, alsa-devel


On 19-Aug-2004 Eliot Blennerhassett wrote:

> with the upgrade to 1.0.6, my alsa driver broke. (asihpi)
> Now I'm trying to put it together again, and could do with some tips...
> Mostly it still contained lots of easy to fix snd_magic_cast() but
> Can anybody confirm that the following update is the 'correct' thing to
> do?
> 
> (My) old code:
> call snd_malloc_pages_fallback in the open callback.
> 
> New code:
> call snd_pcm_lib_malloc_pages() in the hw_params callback
> 
> and call snd_pcm_lib_preallocate_pages_for_all() in the sound card pcm
> init function (in my case snd_card_asihpi_pcm()
> ================================
> By default according to pcm_memory.c, only a maximum of 4 substreams are
> allowed.

By default it preallocates memory for the first 4
substreams only. _malloc_pages() will allocate memory on
demand for the other substreams. You can do your own
preallocation routine if you think this default is not good.
If you want to "prepare" the substrem for use with
snd_pcm_lib_malloc_pages() without actually allocating
memory call _preallocate_pages() with size==0.
You can change the size of preallocated memory from
userspace via /proc interface.

Btw I would move the check for (substream->number < 4)
from snd_pcm_lib_preallocate_pages1() to
snd_pcm_lib_preallocate_pages_for_all() in order to allow
the driver to preallocate memory for any ss it wishes.


--
Giuliano.


-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Upgrade driver to 1.0.6, memory allocation?
  2004-08-19  2:57 Eliot Blennerhassett
@ 2004-08-19  9:53 ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2004-08-19  9:53 UTC (permalink / raw)
  To: Eliot Blennerhassett; +Cc: alsa-devel, linux

At Wed, 18 Aug 2004 19:57:23 -0700,
Eliot Blennerhassett wrote:
> 
> Hello all,
> 
> with the upgrade to 1.0.6, my alsa driver broke. (asihpi)
> Now I'm trying to put it together again, and could do with some tips...
> Mostly it still contained lots of easy to fix snd_magic_cast() but
> Can anybody confirm that the following update is the 'correct' thing to do?
> 
> (My) old code:
> call snd_malloc_pages_fallback in the open callback.

Oh sorry, my last clean-up hits you...

> 
> New code:
> call snd_pcm_lib_malloc_pages() in the hw_params callback
> 
> and call snd_pcm_lib_preallocate_pages_for_all() in the sound card pcm init function
> (in my case snd_card_asihpi_pcm()
> ================================
> By default according to pcm_memory.c, only a maximum of 4 substreams are allowed.
> My cards have up to 16 substreams.
> 
> Chapter 10 of "Writing an alsa driver" says "snd_pcm_lib_malloc_pages(substream,
> size);
> Note that you have to pre-allocate to use this function. "
> 
> Does this only mean that you have to preallocate at least one buffer to use the
> function?

This doesn't matter.  snd_pcm_lib_malloc_pages() allocates the pages
automatically when no preallocated buffer exists or the request buffer
size exceeds the preallocated buffer.

Just call snd_pcm_preallocate_pages_for_all() for the all pcm
instances to use snd_pcm_lib_malloc_pages().


> If I read it correctly, snd_pcm_lib_malloc_pages will still try to allocate some
> memory for substreams> 4, this just becomes less likely as the system mem becomes
> fragmented.

Well but in your old code you allocated pages in the open callback,
right?  So it shouldn't be different.  The buffer allocation in
hw_params callback is usually also done only once per open.


> Is there a rationale for making the substreams limit 4 as opposed to any other number?
> I guess I can change the max_substreams by providing a module parameter to snd-pcm
> module.
> ============================
> snd_pcm_lib_preallocate_pages1()
> ...
> if (size> 0 && preallocate_dma && substream->number <maximum_substreams)
> preallocate_pcm_pages(substream, size);
> ...
> Maybe I'm missing something, but it seems the possible error return value from
> preallocate_pcm_pages is ignored - is this intentional?

Yes.  The error in preallocation isn't critical since
snd_pcm_lib_malloc_pages() itself allocates the buffer, too.


Takashi


-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Upgrade driver to 1.0.6, memory allocation?
  2004-08-19  2:57 Upgrade driver to 1.0.6, memory allocation? Eliot Blennerhassett
  2004-08-19  7:49 ` Giuliano Pochini
@ 2004-08-19 13:01 ` Fred Gleason
  1 sibling, 0 replies; 6+ messages in thread
From: Fred Gleason @ 2004-08-19 13:01 UTC (permalink / raw)
  To: Eliot Blennerhassett, alsa-devel; +Cc: linux

On Wednesday 18 August 2004 22:57, Eliot Blennerhassett wrote:

> Is there a rationale for making the substreams limit 4 as opposed to any
> other number?

I take it these streams map one-to-one with HPI stream resources?  If four is 
the limit, what happens if there are already four or more streams open via 
HPI?  Would snd_pcm_open() fail, or could the driver 'redirect' in some way 
to an unused stream?

Cheers!


|-------------------------------------------------------------------------|
| Frederick F. Gleason, Jr. | Director of Broadcast Software Development  |
|                           |             Salem Radio Labs                |
|-------------------------------------------------------------------------|
|  Some people say a front-engine car handles best.  Some people say a    |
|  rear-engine car handles best.  I say a rented car handles best.        |
|                                          --P.J. O'Rourke                |
|-------------------------------------------------------------------------|



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-08-19 13:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-19  2:57 Upgrade driver to 1.0.6, memory allocation? Eliot Blennerhassett
2004-08-19  7:49 ` Giuliano Pochini
2004-08-19 13:01 ` Fred Gleason
  -- strict thread matches above, loose matches on Subject: below --
2004-08-19  2:57 Eliot Blennerhassett
2004-08-19  9:53 ` Takashi Iwai
2004-08-19  2:57 Eliot Blennerhassett

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.