History log of /sound/core/pcm_lib.c
Revision Date Author Comments
3345c36f951a36962493b1f59f23e47b5a94d8d2 15-Sep-2011 Arjan van de Ven <arjan@infradead.org> ALSA: pcm - fix race condition in wait_for_avail()

commit 763437a9e7737535b2fc72175ad4974048769be6 upstream.

wait_for_avail() in pcm_lib.c has a race in it (observed in practice by an
Intel validation group).

The function is supposed to return once space in the buffer has become
available, or if some timeout happens. The entity that creates space (irq
handler of sound driver and some such) will do a wake up on a waitqueue
that this function registers for.

However there are two races in the existing code

1) If space became available between the caller noticing there was no
space and this function actually sleeping, the wakeup is missed and the
timeout condition will happen instead

2) If a wakeup happened but not sufficient space became available, the
code will loop again and wait for more space. However, if the second
wake comes in prior to hitting the schedule_timeout_interruptible(), it
will be missed, and potentially you'll wait out until the timeout
happens.

The fix consists of using more careful setting of the current state (so
that if a wakeup happens in the main loop window, the schedule_timeout()
falls through) and by checking for available space prior to going into the
schedule_timeout() loop, but after being on the waitqueue and having the
state set to interruptible.

[tiwai: the following changes have been added to Arjan's original patch:
- merged akpm's fix for waitqueue adding order into a single patch
- reduction of duplicated code of avail check
]

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
f2b3614cefb61ee6046a0aaee503ee37f227d310 26-May-2011 Takashi Iwai <tiwai@suse.de> ALSA: PCM - Don't check DMA time-out too shortly

When the PCM period size is set larger than 10 seconds, currently the
PCM core may abort the operation with DMA-error due to the fixed timeout
for 10 seconds. A similar problem is seen in the drain operation that
has a fixed timeout of 10 seconds, too.

This patch fixes the timeout length depending on the period size and
rate, also including the consideration of no_period_wakeup flag.

Reported-by: Raymond Yau <superquad.vortex2@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
217658f46c2dbfe260f8f5976f2a201911a2f4c6 19-May-2011 Ben Gardiner <bengardiner@nanometrics.ca> ALSA: sound, core, pcm_lib: fix xrun_log

The xrun_log function was augmented with the in_interrupt parameter whereas the
empty macro definition used when xrun logging is disabled was not.

Add a third parameter to the empty macro definition so as to not cause compiler
errors when xrun logging (CONFIG_SND_PCM_XRUN_DEBUG) is disabled.

Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ec08b14483de0702ca43e3a8506e149486975f9b 18-May-2011 Ben Gardiner <bengardiner@nanometrics.ca> ALSA: sound, core, pcm_lib: xrun_log: log also in_interrupt

When debugging pcm drivers I found the "period" or "hw" prefix printed
by either XRUN_DEBUG_PERIODUPDATE or XRUN_DEBUG_PERIODUPDATE events,
respectively to be very useful is observing the interplay between
interrupt-context updates and syscall-context updates.

Similarly, when debugging overruns with XRUN_DEBUG_LOG it is useful to
see the context of the last 10 positions.

Add an in_interrupt member to hwptr_log_entry which stores the value of
the in_interrupt parameter of snd_pcm_update_hw_ptr0 when the log entry
is created. Print a "[Q]" prefix when dumping the log entries if
in_interrupt was true.

Signed-off-by: Ben Gardiner <bengardiner@nanometrics.ca>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
12ff414e2e4512f59fe191dc18e856e2939a1c79 01-Apr-2011 Kelly Anderson <kelly@silka.with-linux.com> ALSA: pcm: fix infinite loop in snd_pcm_update_hw_ptr0()

When period interrupts are disabled, snd_pcm_update_hw_ptr0() compares
the current time against the time estimated for the current hardware
pointer to detect xruns. The somewhat fuzzy threshold in the while loop
makes it possible that hdelta becomes negative; the comparison being
done with unsigned types then makes the loop go through the entire 263
negative range, and, depending on the value, never reach an unsigned
value that is small enough to stop the loop. Doing this with interrupts
disabled results in the machine locking up.

To prevent this, ensure that the loop condition uses signed types for
both operands so that the comparison is correctly done.

Many thanks to Kelly Anderson for debugging this.

Reported-by: Nix <nix@esperi.org.uk>
Reported-by: "Christopher K." <c.krooss@googlemail.com>
Reported-and-tested-by: Kelly Anderson <kelly@silka.with-linux.com>
Signed-off-by: Kelly Anderson <kelly@silka.with-linux.com>
[cl: remove unneeded casts; use a temp variable]
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Cc: 2.6.38 <stable@kernel.org>

Signed-off-by: Takashi Iwai <tiwai@suse.de>
87a1c8aaa0bced8acf4cd64672362492460c31ae 21-Dec-2010 Jesper Juhl <jj@chaosbits.net> ALSA: pcm: remember to always call va_end() on stuff that we va_start()

The Coverity checker spotted that we do not always remember to call
va_end() on 'args' in failure paths in snd_pcm_hw_rule_add().
Here's a patch to fix that up (compile tested only) - it also removes
some annoying trailing whitespace that caught my eye while I was in the
area..

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
47228e48aecdbec423a1275a5e27697d47f1f912 18-Nov-2010 Clemens Ladisch <clemens@ladisch.de> ALSA: pcm: optimize xrun detection in no-period-wakeup mode

Add a lightweight condition on top of the xrun checking so that we can
avoid the division when the application is calling the update function
often enough.

Suggested-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
59ff878ffb26bc0be812ca8295799164f413ae88 18-Nov-2010 Clemens Ladisch <clemens@ladisch.de> ALSA: pcm: detect xruns in no-period-wakeup mode

When period wakeups are disabled, successive calls to the pointer update
function do not have a maximum allowed distance, so xruns cannot be
detected with the pointer value only.

To detect xruns, compare the actually elapsed time with the time that
should have theoretically elapsed since the last update. When the
hardware pointer has wrapped around due to an xrun, the actually elapsed
time will be too big by about hw_ptr_buffer_jiffies.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ab69a4904b5dd4d7cd6996587ba066bca8d13838 15-Nov-2010 Clemens Ladisch <clemens@ladisch.de> ALSA: pcm: support for period wakeup disabling

This patch allows to disable period interrupts which are
not needed when the application relies on a system timer
to wake-up and refill the ring buffer. The behavior of
the driver is left unchanged, and interrupts are only
disabled if the application requests this configuration.
The behavior in case of underruns is slightly different,
instead of being detected during the period interrupts the
underruns are detected when the application calls
snd_pcm_update_avail, which in turns forces a refresh of the
hw pointer and shows the buffer is empty.

More specifically this patch makes a lot of sense when
PulseAudio relies on timer-based scheduling to access audio
devices such as HDAudio or Intel SST. Disabling interrupts
removes two unwanted wake-ups due to period elapsed events
in low-power playback modes. It also simplifies PulseAudio
voice modules used for speech calls.

To quote Lennart "This patch looks very interesting and
desirable. This is something have long been waiting for."

Support for this in hardware drivers is optional.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@intel.com>
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
c80c1d542744dd7851cc8da748c6ada99680fb4d 15-Nov-2010 Joe Perches <joe@perches.com> ALSA: sound/core/pcm_lib.c: Remove unnecessary semicolons

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
d7d28bc29f4ea7c2d23ed002a9973c64a92bcdb8 18-Aug-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm midlevel code - add time check for double interrupt acknowledge

The current code in pcm_lib.c do all checks using only the position
in the ring buffer. Unfortunately, where the interrupts gets delayed or
merged into one, we need another timing source to check when the
buffer size boundary overlaps to avoid the wrong updating of the
ring buffer pointers.

This code uses jiffies to check the right time window without any
performance impact.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
bd76af0f87f7a1815b311bde269a3f18305b3169 18-Aug-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm midlevel code - add time check for double interrupt acknowledge

The current code in pcm_lib.c do all checks using only the position
in the ring buffer. Unfortunately, where the interrupts gets delayed or
merged into one, we need another timing source to check when the
buffer size boundary overlaps to avoid the wrong updating of the
ring buffer pointers.

This code uses jiffies to check the right time window without any
performance impact.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
9e216e8a40428cbf689222148c28d0256fbd0186 19-Jul-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm core - add a safe check to the silence filling function

In situation when appl_ptr is far greater then hw_ptr, the hw_avail value
can be greater than buffer_size. Check for this.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
5daeba34d2aab669aea07abee13d53cd116578fb 27-Jun-2010 David Dillow <dave@thedillows.org> ALSA: pcm_lib: avoid timing jitter in snd_pcm_read/write()

When using poll() to wait for the next period -- or avail_min samples --
one gets a consistent delay for each system call that is usually just a
little short of the selected period time. However, When using
snd_pcm_read/write(), one gets a jittery delay that alternates between
less than a millisecond and approximately two period times. This is
caused by snd_pcm_lib_{read,write}1() transferring any available samples
to the user's buffer and adjusting the application pointer prior to
sleeping to the end of the current period. When the next period
interrupt occurs, there is then less than avail_min samples remaining to
be transferred in the period, so we end up sleeping until a second
period occurs.

This is solved by using runtime->twake as the number of samples needed
for a wakeup in addition to selecting the proper wait queue to wake in
snd_pcm_update_state(). This requires twake to be non-zero when used
by snd_pcm_lib_{read,write}1() even if avail_min is zero.

Signed-off-by: Dave Dillow <dave@thedillows.org>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
b406e6103baa3da85950f22d3d46d21a8da654c5 25-May-2010 Clemens Ladisch <clemens@ladisch.de> ALSA: pcm: fix delta calculation at boundary wraparound

In the cleanup of the hw_ptr update functions in 2.6.33, the calculation
of the delta value was changed to use the modulo operator to protect
against a negative difference due to the pointer wrapping around at the
boundary.

However, the ptr variables are unsigned, so a negative difference would
result in the two complement's value which has no relation to the actual
difference relative to the boundary; the result is typically some value
near LONG_MAX-boundary. Furthermore, even if the modulo operation would
be done with signed types, the result of a negative dividend could be
negative.

The invalid delta value is then caught by the following checks, but this
means that the pointer update is ignored.

To fix this, use a range check as in the other pointer calculations.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Cc: <stable@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
ead4046b2fdfd69acc4272e693afd249ad3eb689 21-May-2010 Clemens Ladisch <clemens@ladisch.de> ALSA: pcm: fix the fix of the runtime->boundary calculation

Commit 7910b4a1db63fefc3d291853d33c34c5b6352e8e in 2.6.34 changed the
runtime->boundary calculation to make this value a multiple of both the
buffer_size and the period_size, because the latter is assumed by the
runtime->hw_ptr_interrupt calculation.

However, due to the lack of a ioctl that could read the software
parameters before they are set, the kernel requires that alsa-lib
calculates the boundary value, too. The changed algorithm leads to
a different boundary value used by alsa-lib, which makes, e.g., mplayer
fail to play a 44.1 kHz file because the silence_size parameter is now
invalid; bug report:
<https://bugtrack.alsa-project.org/alsa-bug/view.php?id=5015>.

This patch reverts the change to the boundary calculation, and instead
fixes the hw_ptr_interrupt calculation to be period-aligned regardless
of the boundary value.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Cc: <stable@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
0f17014b340b98465fcf0de4c0d6c84a002ec53b 26-Mar-2010 Jarkko Nikula <jhnikula@gmail.com> ALSA: pcm_lib - fix xrun functionality

The commit 4d96eb255c53ab5e39b37fd4d484ea3dc39ab456 broke the interrupt
time xrun functionality (stream stop etc.) if the CONFIG_SND_PCM_XRUN_DEBUG
is not set. This is because the xrun() is null defined without it.

Fix this by letting the function xrun() to be always defined as it was
before.

Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Cc: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
e7636925789b042ff9d98c51d48392e8c5549480 26-Jan-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm_lib - return back hw_ptr_interrupt

Clemens Ladisch noted for hw_ptr_removal in "cleanup & merge hw_ptr
update functions" commit:

"It is possible for the status/delay ioctls to be called when the sound
card's pointer register alreay shows a position at the beginning of the
new period, but immediately before the interrupt is actually executed.
(This happens regularly on a SMP machine with mplayer.) When that
happens, the code thinks that the position must be at least one period
ahead of the current position and drops an entire buffer of data."

Return back the hw_ptr_interrupt variable. The last interrupt pointer
is always computed from the latest hw_ptr instead of tracking it
separately (in this case all hw_ptr checks and modifications might
influence also hw_ptr_interrupt and it is difficult to keep it
consistent).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
c91a988dc6551c66418690e36b2a23cdb0255da8 21-Jan-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm_core: Fix wake_up() optimization

This change fixes the "ALSA: pcm_lib - optimize wake_up() calls for PCM I/O"
commit. New sleeping queue is introduced to separate user space and kernel
space wake_ups. runtime->nowake is renamed to twake (transfer wake).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
ed69c6a8eef679f2783848ed624897a937a434ac 13-Jan-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm_lib - fix wrong delta print for jiffies check

The previous jiffies delta was 0 in all cases. Use hw_ptr variable to
store and print original value.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
7b3a177b0d4f92b3431b8dca777313a07533a710 08-Jan-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm_lib: fix "something must be really wrong" condition

When runtime->periods == 1 or when pointer crosses end of ring buffer,
the delta might be greater than buffer_size.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
1250932e48d3b698415b1f04775433cf1da688d6 07-Jan-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm_lib - optimize wake_up() calls for PCM I/O

As noted by pl bossart <bossart.nospam@gmail.com>, the PCM I/O routines
(snd_pcm_lib_write1, snd_pcm_lib_read1) should block wake_up() calls
until all samples are not processed.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
f240406babfe1526998e10583ea5eccc2676a433 05-Jan-2010 Jaroslav Kysela <perex@perex.cz> ALSA: pcm_lib - cleanup & merge hw_ptr update functions

Do general cleanup in snd_pcm_update_hw_ptr*() routines and merge them.
The main change is hw_ptr_interrupt variable removal to simplify code
logic. This variable can be computed directly from hw_ptr.

Ensure that updated hw_ptr is not lower than previous one (it was possible
with old code in some obscure situations when interrupt was delayed or
the lowlevel driver returns wrong ring buffer position value).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
4d96eb255c53ab5e39b37fd4d484ea3dc39ab456 20-Dec-2009 Jaroslav Kysela <perex@perex.cz> ALSA: pcm_lib - add possibility to log last 10 DMA ring buffer positions

In some debug cases, it might be usefull to see previous ring buffer
positions to determine position problems from the lowlevel drivers.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
741b20cfb9109760937f403d18d731bfde31f56f 17-Dec-2009 Jaroslav Kysela <perex@perex.cz> ALSA: pcm_lib.c - convert second xrun_debug() parameter to use defines

To increase code readability, convert send xrun_debug() argument to
use defines.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
8374e24c23448cabf6e78db2c83841c56c5df1e1 21-Dec-2009 Krzysztof Helt <krzysztof.h1@wp.pl> ALSA: refine rate selection in snd_interval_ratnum()

Refine the rate selection by choosing the rate
closer to the requested one in case of selecting
single frequency. Previously, the higher rate was
always selected.

Also, fix problem with the best_diff unsigned int
value wrapping (turning negative).

Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
40962d7c741de1c21b6ce8516c1d9f8836fb383e 19-Dec-2009 Krzysztof Helt <krzysztof.h1@wp.pl> ALSA: fix incorrect rounding direction in snd_interval_ratnum()

The direction of rounding is incorrect in the snd_interval_ratnum()
It was detected with following parameters (sb8 driver playing
8kHz stereo file):
- num is always 1000000
- requested frequency rate is from 7999 to 7999 (single frequency)

The first loop calculates div_down(num, freq->min) which is 125.
Thus, a frequency range's minimum value is 1000000 / 125 = 8000 Hz.
The second loop calculates div_up(num, freq->max) which is 126
The frequency range's maximum value is 1000000 / 126 = 7936 Hz.
The range maximum is lower than the range minimum so the function
fails due to empty result range.

Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
b1ddaf681e362ed453182ddee1699d7487069a16 25-Aug-2009 Clemens Ladisch <clemens@ladisch.de> sound: pcm_lib: fix unsorted list constraint handling

snd_interval_list() expected a sorted list but did not document this, so
there are drivers that give it an unsorted list. To fix this, change
the algorithm to work with any list.

This fixes the "Slave PCM not usable" error with USB devices that have
multiple alternate settings with sample rates in decreasing order, such
as the Philips Askey VC010 WebCam.

http://bugzilla.kernel.org/show_bug.cgi?id=14028

Reported-and-tested-by: Andrzej <adkadk@gmail.com>
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Cc: <stable@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
4cdc115fd38b54642e8536a5c2389483bcb9b2e9 20-Aug-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Fix drain behavior in non-blocking mode

The current PCM core has the following problems regarding PCM draining
in non-blocking mode:

- the current f_flags isn't checked in snd_pcm_drain(), thus changing
the mode dynamically via snd_pcm_nonblock() after open doesn't work.
- calling drain in non-blocking mode just return -EAGAIN error, but
doesn't provide any way to sync with draining.

This patch fixes these issues.
- check file->f_flags in snd_pcm_drain() properly
- when O_NONBLOCK is set, PCM core sets the stream(s) to DRAIN state
but quits ioctl immediately without waiting the whole drain; the
caller can sync the drain manually via poll()

Signed-off-by: Takashi Iwai <tiwai@suse.de>
947ca210f1df7656e19890832cb71fc3bdd88707 23-Jul-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Fix hwptr buffer-size overlap bug

The fix 79452f0a28aa5a40522c487b42a5fc423647ad98 introduced another
bug due to the missing offset for the overlapped hwptr.
When the hwptr goes back to zero, the delta value has to be corrected
with the buffer size. Otherwise this causes looping sounds.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
89350640439e0160056de26995d52deb18202b3e 23-Jul-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Fix warnings in debug loggings

Add proper cast.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
cedb8118e8cef21a2b73fd9cb70660ac19124c16 23-Jul-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Add logging of hwptr updates and interrupt updates

Added the logging functionality to xrun_debug to record the hwptr
updates via snd_pcm_update_hw_ptr() and snd_pcm_update_hwptr_interrupt(),
corresponding to 16 and 8, respectively.

For example,
# echo 9 > /proc/asound/card0/pcm0p/xrun_debug
will record the position and other parameters at each period interrupt
together with the normal XRUN debugging.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
79452f0a28aa5a40522c487b42a5fc423647ad98 22-Jul-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Fix regressions with VMware

VMware tends to report PCM positions and period updates at utterly
wrong timing. This screws up the recent PCM core code that tries
to correct the position based on the irq timing.

Now, when a backward irq position is detected, skip the update
instead of rebasing. (This is almost the old behavior before
2.6.30.)

Signed-off-by: Takashi Iwai <tiwai@suse.de>
c00701101b82f2bc61dfc259748ec6e5288af6a9 08-Jun-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - A helper function to compose PCM stream name for debug prints

Use a common helper function for the PCM stream name displayed in
XRUN and buffer-pointer debug prints.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ab1863fc9bc18c806338564124b1e5e7e3ef53d1 07-Jun-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Fix update of runtime->hw_ptr_interrupt

The commit 13f040f9e55d41e92e485389123654971e03b819 made another
regression, the missing update of runtime->hw_ptr_interrupt.
Since this field is only checked in snd_pcmupdate__hw_ptr_interrupt(),
not in snd_pcm_update_hw_ptr(), it must be updated before the hw_ptr
change check.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
d86bf92313bfd47885a92c7de63bde392d585f95 06-Jun-2009 Jaroslav Kysela <perex@perex.cz> ALSA: pcm - Fix a typo in hw_ptr update check

Fix a typo in the commit 13f040f9e55d41e92e485389123654971e03b819
ALSA: PCM midlevel: Do not update hw_ptr_jiffies when hw_ptr is not changed
which causes obvious problems with PA.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
3f7440a6b771169e1f11fa582e53a4259b682809 05-Jun-2009 Takashi Iwai <tiwai@suse.de> ALSA: Clean up 64bit division functions

Replace the house-made div64_32() with the standard div_u64*() functions.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
a4444da31ec92f89cd6923579c20a9c240439cfc 28-May-2009 Jaroslav Kysela <perex@perex.cz> ALSA: PCM midlevel: lower jiffies check margin using runtime->delay value

When hardware has large FIFO, it is necessary to lower jiffies margin
by count of queued samples.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
13f040f9e55d41e92e485389123654971e03b819 28-May-2009 Jaroslav Kysela <perex@perex.cz> ALSA: PCM midlevel: Do not update hw_ptr_jiffies when hw_ptr is not changed

Some hardware might have bigger FIFOs and DMA pointer value will be updated
in large chunks. Do not update hw_ptr_jiffies and position timestamp when
hw_ptr value was not changed.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
c62a01ad6e746fae9c93f51ea67e0abfd8d94b58 28-May-2009 Jaroslav Kysela <perex@perex.cz> ALSA: PCM midlevel: introduce mask for xrun_debug() macro

For debugging purposes, it is better to separate actions.

Bit-values:

1: show bad PCM ring buffer pointer
2: show also stack (to debug kernel latency issues)
4: check pointer against system jiffies

Example:

5: show bad PCM ring buffer pointer and do jiffies check

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
8bea869c5e56234990e6bad92a543437115bfc18 27-Apr-2009 Jaroslav Kysela <perex@perex.cz> ALSA: PCM midlevel: improve fifo_size handling

Move the fifo_size assignment to hw->ioctl callback to allow lowlevel
drivers overwrite the default behaviour.

fifo_size is in frames not bytes as specified in asound.h and alsa-lib's
documentation, but most hardware have fixed byte based FIFOs. Introduce
internal SNDRV_PCM_INFO_FIFO_IN_FRAMES.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
c87d9732004b3f8fd82d729f12ccfb96c0df279e 27-May-2009 Takashi Iwai <tiwai@suse.de> ALSA: Enable PCM hw_ptr_jiffies check only in xrun_debug mode

The PCM hw_ptr jiffies check results sometimes in problems when a
hardware doesn't give smooth hw_ptr updates. So far, au88x0 and some
other drivers appear not working due to this strict check.
However, this check is a nice debug tool, and the capability should be
still kept.

Hence, we disable this check now as default unless the user enables it
by setting the xrun_debug mode to the specific stream via a proc file.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
6af3fb72d2437239e5eb13a59e95dc43ccab3e8f 27-May-2009 Takashi Iwai <tiwai@suse.de> ALSA: Fix invalid jiffies check after pause

The hw_ptr_jiffies has to be reset properly to avoid the invalid
check of jiffies delta in snd_pcm_update_hw_ptr*() functions.
Especailly this patch fixes the bogus jiffies check after the puase
and resume.

This patch is a modified version of the original patch by Jaroslav.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
3e5b50165fd0be080044586f43fcdd460ed27610 28-Apr-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm core - Avoid jiffies check for devices with BATCH flag

The hardware devices with SNDRV_PCM_INFO_BATCH flag can't give the
precise current position. And such hardwares have often big FIFO
in addition to the ring buffer, and it screws up the jiffies check
in pcm_lib.c.

This patch adds a simple check of info flag so that the driver skips
the jiffies check in snd_pcm_period_elapsed() when BATCH flag is set.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
bbf6ad1399e9516b0a95de3ad58ffbaed670e4cc 10-Apr-2009 Jaroslav Kysela <perex@perex.cz> [ALSA] pcm-midlevel: Add more strict buffer position checks based on jiffies

Some drivers like Intel8x0 or Intel HDA are broken for some hardware variants.
This patch adds more strict buffer position checks based on jiffies when
internal hw_ptr is updated. Enable xrun_debug to see mangling of wrong
positions.

As a side effect, the hw_ptr interrupt update routine might do slightly better
job when many interrupts are lost.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
8b22d943c34b616eefbd6d2f8f197a53b1f29fd0 20-Mar-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Safer boundary checks

Make the boundary checks a bit safer.
These caese are rare or theoretically won't happen, but nothing
bad to keep the checks safer...

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ded652f7024bc2d7b6118b561a44187af30841b0 19-Mar-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Fix delta calculation at boundary overlap

When the hw_ptr_interrupt reaches the boundary, it must check whether
the hw_base was already lapped and corret the delta value appropriately.

Also, rebasing the hw_ptr needs a correction because buffer_size isn't
always aligned to period_size.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
5f513e1197f27e9a0bcfec0feaac59f976f4a37e 19-Mar-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Reset invalid position even without debug option

Always reset the invalind hw_ptr position returned by the pointer
callback. The behavior should be consitent independently from the
debug option.

Also, add the printk_ratelimit() check to avoid flooding debug
prints.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
98204646f2b15d368701265e4194b773a6f94600 19-Mar-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - avoid unnecessary inline

Remove unnecessary explicit inlininig of internal functions.
Let compiler optimize.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
cad377acf3d6af6279622048e96680e79e352183 19-Mar-2009 Takashi Iwai <tiwai@suse.de> ALSA: pcm - Fix a typo in error messages

Fix a typo in error messages; forgotten after a copy&paste error.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
ed3da3d9a0ef13c6fe1414ec73c9c1be12747b62 03-Mar-2009 Takashi Iwai <tiwai@suse.de> ALSA: Rewrite hw_ptr updaters

Clean up and improve snd_pcm_update_hw_ptr*() functions.

snd_pcm_update_hw_ptr() tries to detect the unexpected hwptr jumps
more strictly to avoid the position mess-up, which often results in
the bad quality I/O with pulseaudio.

The hw-ptr skip error messages are printed when xrun proc is set to
non-zero.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
1c85cc64456c97f3b265788abafec5c482c6a908 15-Oct-2008 Randy Dunlap <randy.dunlap@oracle.com> ALSA: kernel docs: fix sound/core/ kernel-doc

Add kernel-doc function short descriptions to sound/core functions that
are missing this short description. Mostly this involves moving some of
the function description onto the @funcname line.

Also correct a few variable names and fix other kernel-doc notation.

Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
7eaa943c8ed8e91e05d0f5d0dc7a18e3319b45cf 08-Aug-2008 Takashi Iwai <tiwai@suse.de> ALSA: Kill snd_assert() in sound/core/*

Kill snd_assert() in sound/core/*, either removed or replaced with
if () with snd_BUG_ON().

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
8c12158687fc78091730d5456336b7efbf6f2250 11-Jan-2008 Jaroslav Kysela <perex@perex.cz> [ALSA] PCM interface - rename SNDRV_PCM_TSTAMP_MMAP to SNDRV_PCM_TSTAMP_ENABLE

Change semantics for SNDRV_PCM_TSTAMP_MMAP. Doing timestamping only in
the interrupt handler might cause that hw_ptr is not related to actual
timestamp. With this change, grab timestamp at every hw_ptr update to
have always valid timestamp + ring buffer position pair.
With this change, SNDRV_PCM_TSTAMP_MMAP was renamed to
SNDRV_PCM_TSTAMP_ENABLE. It's no regression (I think).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
9004acc70e8c49c50c4c7b652f906f1e0ed5709d 08-Jan-2008 Takashi Iwai <tiwai@suse.de> [ALSA] Remove sound/driver.h

This header file exists only for some hacks to adapt alsa-driver
tree. It's useless for building in the kernel. Let's move a few
lines in it to sound/core.h and remove it.
With this patch, sound/driver.h isn't removed but has just a single
compile warning to include it. This should be really killed in
future.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
31e8960b35975ed235d283d6fb95d0e28dffded0 08-Jan-2008 Takashi Iwai <tiwai@suse.de> [ALSA] Remove PCM sleep_min and tick

The 'tick' in PCM is set (again) via sw_params. And, nobody uses
this feature at all except for a command line option of aplay.
(This is literally 'nobody', as I checked alsa-lib API calls in all
programs in major distros.)
Above all, if we need finer wake-ups for the position update, it's
basically an issue that the driver should solve, not tuned by each
application.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
130755108ba03461f69da990e54e02a254accd23 08-Jan-2008 Takashi Iwai <tiwai@suse.de> [ALSA] PCM - clean up snd_pcm_lib_read/write

Introduce a common helper function for snd_pcm_lib_read and snd_pcm_lib_write
for cleaning up the code.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
d948035a928400ae127c873fbf771389bee18949 08-Jan-2008 Takashi Iwai <tiwai@suse.de> [ALSA] Remove PCM xfer_align sw params

The xfer_align sw_params parameter has never been used in a sane manner,
and no one understands what this does exactly. The current
implementation looks also buggy because it allows write of shorter size
than xfer_align. So, if you do partial writes, the write isn't actually
aligned at all.
Removing this parameter will make some pcm_lib_* code more readable
(and less buggy).

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
fa5717f2099aadb2083d5df4d19af8f9685fa03e 08-Jan-2008 Takashi Iwai <tiwai@suse.de> [ALSA] Fix PCM write blocking

The snd_pcm_lib_write1() may block in some weird condition:
- the stream isn't started
- avail_min is big (e.g. period size)
- partial write up to buffer_size - avail_min
The patch fixes this invalid blocking problem.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
67c393172c00a710121d61bb7aff31b1e4f44b8d 14-Dec-2007 Marcin Ślusarz <marcin.slusarz@gmail.com> [ALSA] pcm_lib: fix sparse warning about different signedness

pcm_lib: fix sparse warning about different signedness

Signed-off-by: Marcin Ślusarz <marcin.slusarz@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
be3e0115e3732d77d357724a394ee465e5d0b872 14-Dec-2007 Marcin Ślusarz <marcin.slusarz@gmail.com> [ALSA] pcm_lib: fix sparse warning about shadowing 'n' symbol

pcm_lib: fix sparse warning about shadowing 'n' symbol

Signed-off-by: Marcin Ślusarz <marcin.slusarz@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
b751eef1fdffca5532344285f2fad0c60d2f0158 13-Dec-2007 Jaroslav Kysela <perex@perex.cz> [ALSA] Use posix clock monotonic for PCM and timer timestamps

We need an accurate and continuous (monotonic) time sources to do
accurate synchronization among more timing sources. This patch allows
to enable monotonic timestamps for ALSA PCM devices and enables monotonic
timestamps for ALSA timer devices.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
7c7fc2d44b7a660846115e65b67772b6742a14d8 23-Nov-2007 Takashi Iwai <tiwai@suse.de> [ALSA] Fix PCM MMAP time-stamp mode

When MMAP time-stamp mode is given, it's supposed to update the time-stamp
only at period boundary. However, it currently updates at each status call
so this is just useless. The patch fixes this misbehavior.
Also it fixes the wrong check of tstamp_mode (don't use bit-and for enum).

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
c1017a4cdb68ae5368fbc9ee42c77f1f5dca8916 15-Oct-2007 Jaroslav Kysela <perex@perex.cz> [ALSA] Changed Jaroslav Kysela's e-mail from perex@suse.cz to perex@perex.cz


Signed-off-by: Jaroslav Kysela <perex@perex.cz>
0981a260a1fe4a3f22cc70ef01ce38a73f548745 01-Feb-2007 Takashi Iwai <tiwai@suse.de> [ALSA] Fix possible invalid memory access in PCM core

snd_internval_list() may access invalid memory in the case count = 0
is given. It shouldn't be passed, but it'd better to make the code
a bit more robust.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
9a826ddba6e087b1be24dd78cd0eac42f7eb7e97 23-Oct-2006 Clemens Ladisch <clemens@ladisch.de> [ALSA] pcm core: fix silence_start calculations

The case where silence_size < boundary was broken because different
parts of the snd_pcm_playback_silence() function disagreed about whether
silence_start should point to the start or to the end of the buffer part
to be silenced.
This patch changes the code to always use to the start, which also
simplifies several calculations.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
0df63e44c3e315ec0fe427ae62558231864108bd 28-Apr-2006 Takashi Iwai <tiwai@suse.de> [ALSA] Add O_APPEND flag support to PCM

Added O_APPEND flag support to PCM to enable shared substreams
among multiple processes. This mechanism is used by dmix and
dsnoop plugins.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2f4ca8e5c7cf6a6f7935483d8ee4aa8b039bdd7d 28-Apr-2006 Takashi Iwai <tiwai@suse.de> [ALSA] Clean up ugly hacks in pcm_lib.c

Clean up ugly hacks for sync with alsa-lib code in pcm_lib.c.
Also, optimize snd_pcm_hw_params_choose() with a loop.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
e88e8ae639a4908b903d9406c54e99a729b01a28 28-Apr-2006 Takashi Iwai <tiwai@suse.de> [ALSA] Move OSS-specific hw_params helper to snd-pcm-oss module

Move EXPORT_SYMBOL()s to places adjacent to functions/variables.
Also move OSS-specific hw_params helper functions to pcm_oss.c.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
61fb63c096a2e88b87742eaecfe88912b89f57cf 24-Apr-2006 Jaroslav Kysela <perex@suse.cz> [ALSA] PCM core - introduce CONFIG_SND_PCM_XRUN_DEBUG

This patch makes the XRUN (overrun/underrun) notification code optional.

Signed-off-by: Jaroslav Kysela <perex@suse.cz>
3bf75f9b90c981f18f27a0d35a44f488ab68c8ea 27-Mar-2006 Takashi Iwai <tiwai@suse.de> [ALSA] Clean up PCM codes (take 2)

- Clean up initialization and destruction of substream instance
Now snd_pcm_open_substream() alone does most initialization jobs.
Add pcm_release callback for cleaning up at snd_pcm_release_substream()
- Tidy up PCM oss code

Signed-off-by: Takashi Iwai <tiwai@suse.de>
235475cb7715852c42118fd8d8ec67b534ab6e8b 07-Dec-2005 Takashi Iwai <tiwai@suse.de> [ALSA] pcm - Fix wrong asserts

Modules: PCM Midlevel

Fixed wrong or supreflous snd_assert()'s.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
877211f5e1b1196179ba1290e8e1a3dc00427c55 17-Nov-2005 Takashi Iwai <tiwai@suse.de> [ALSA] Remove xxx_t typedefs: PCM

Modules: PCM Midlevel

Remove xxx_t typedefs from the core PCM codes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
07799e756c76ecd52cb01a812ba48b7d8ac67633 10-Oct-2005 Takashi Iwai <tiwai@suse.de> [ALSA] Use getnstimeofday()

Modules: Documentation,PCM Midlevel,Timer Midlevel,ALSA Core

Use the standard getnstimeofday() function instead of ALSA's own one.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
7c22f1aaa23370bf9ba2dd3abbccbed70dced216 10-Oct-2005 Takashi Iwai <tiwai@suse.de> [ALSA] Remove snd_runtime_check() macro

Remove snd_runtime_check() macro.
This macro worsens the readability of codes. They should be either
normal if() or removable asserts.

Also, the assert displays stack-dump, instead of only the last caller
pointer.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
df8db936e5e829ab3ff66346dbdf4033fa3ce588 07-Sep-2005 Takashi Iwai <tiwai@suse.de> [ALSA] Fix DocBook warnings

PCM Midlevel,RawMidi Midlevel
Fix DocBook warnings.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
a53fc188ec6fc406276799da465fe789c40d96b2 11-Aug-2005 Clemens Ladisch <clemens@ladisch.de> [ALSA] make local objects static

Memalloc module,PCM Midlevel,Timer Midlevel,GUS Library,AC97 Codec
ALI5451 driver,RME9652 driver
Make some functions/variables that are used in only one file static.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
443feb882679e21ba5d1e0ff9eff067ac26d9461 10-Aug-2005 Karsten Wiese <annabellesgarden@yahoo.de> [ALSA] ALSA's struct _snd_pcm_substream: Obsolete open_flag

PCM Midlevel,ALSA<-OSS emulation,USB USX2Y
This patch removes open_flag from struct _snd_pcm_substream.
All of its uses are substituted by querying struct _snd_pcm_substream's
member ffile instead.

Signed-off-by: Karsten Wiese <annabellesgarden@yahoo.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
62144100471e940468d7a0f2d989df193afe870c 24-May-2005 Takashi Iwai <tiwai@suse.de> [ALSA] Make docproc happy

PCM Midlevel
Make docproc happy by moving '#if 0' before comments.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
123992f728785e05f385d23893bd5ec69871aeb4 18-May-2005 Adrian Bunk <bunk@stusta.de> [ALSA] sound/core/: possible cleanups

PCM Midlevel,ALSA Core,Timer Midlevel,ALSA sequencer,Virtual Midi
This patch contains the following possible cleanups:
- make needlessly global code static
- #if 0 the following unused global functions
- remove the following unneeded EXPORT_SYMBOL's

Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 17-Apr-2005 Linus Torvalds <torvalds@ppc970.osdl.org> Linux-2.6.12-rc2

Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.

Let it rip!