Commit 31e8960b35975ed235d283d6fb95d0e28dffded0

Authored by Takashi Iwai
Committed by Jaroslav Kysela
1 parent 130755108b

[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>

Showing 5 changed files with 3 additions and 159 deletions Side-by-side Diff

... ... @@ -274,7 +274,6 @@
274 274 snd_pcm_uframes_t period_size; /* period size */
275 275 unsigned int periods; /* periods */
276 276 snd_pcm_uframes_t buffer_size; /* buffer size */
277   - unsigned int tick_time; /* tick time */
278 277 snd_pcm_uframes_t min_align; /* Min alignment for the format */
279 278 size_t byte_align;
280 279 unsigned int frame_bits;
... ... @@ -286,7 +285,6 @@
286 285 /* -- SW params -- */
287 286 int tstamp_mode; /* mmap timestamp is updated */
288 287 unsigned int period_step;
289   - unsigned int sleep_min; /* min ticks to sleep */
290 288 snd_pcm_uframes_t start_threshold;
291 289 snd_pcm_uframes_t stop_threshold;
292 290 snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
... ... @@ -305,7 +303,6 @@
305 303  
306 304 /* -- locking / scheduling -- */
307 305 wait_queue_head_t sleep;
308   - struct timer_list tick_timer;
309 306 struct fasync_struct *fasync;
310 307  
311 308 /* -- private section -- */
... ... @@ -810,7 +807,6 @@
810 807 #define params_periods(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIODS)->min
811 808 #define params_buffer_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min
812 809 #define params_buffer_bytes(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min
813   -#define params_tick_time(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_TICK_TIME)->min
814 810  
815 811  
816 812 int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
... ... @@ -908,9 +904,6 @@
908 904 int snd_pcm_playback_xrun_asap(struct snd_pcm_substream *substream);
909 905 int snd_pcm_capture_xrun_asap(struct snd_pcm_substream *substream);
910 906 void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr);
911   -void snd_pcm_tick_prepare(struct snd_pcm_substream *substream);
912   -void snd_pcm_tick_set(struct snd_pcm_substream *substream, unsigned long ticks);
913   -void snd_pcm_tick_elapsed(struct snd_pcm_substream *substream);
914 907 void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
915 908 snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
916 909 const void __user *buf,
sound/core/oss/pcm_oss.c
... ... @@ -985,7 +985,6 @@
985 985 sw_params->stop_threshold = runtime->buffer_size;
986 986 sw_params->tstamp_mode = SNDRV_PCM_TSTAMP_NONE;
987 987 sw_params->period_step = 1;
988   - sw_params->sleep_min = 0;
989 988 sw_params->avail_min = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
990 989 1 : runtime->period_size;
991 990 if (atomic_read(&substream->mmap_count) ||
... ... @@ -359,7 +359,6 @@
359 359 snd_iprintf(buffer, "rate: %u (%u/%u)\n", runtime->rate, runtime->rate_num, runtime->rate_den);
360 360 snd_iprintf(buffer, "period_size: %lu\n", runtime->period_size);
361 361 snd_iprintf(buffer, "buffer_size: %lu\n", runtime->buffer_size);
362   - snd_iprintf(buffer, "tick_time: %u\n", runtime->tick_time);
363 362 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
364 363 if (substream->oss.oss) {
365 364 snd_iprintf(buffer, "OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.format));
... ... @@ -387,7 +386,6 @@
387 386 }
388 387 snd_iprintf(buffer, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(runtime->tstamp_mode));
389 388 snd_iprintf(buffer, "period_step: %u\n", runtime->period_step);
390   - snd_iprintf(buffer, "sleep_min: %u\n", runtime->sleep_min);
391 389 snd_iprintf(buffer, "avail_min: %lu\n", runtime->control->avail_min);
392 390 snd_iprintf(buffer, "start_threshold: %lu\n", runtime->start_threshold);
393 391 snd_iprintf(buffer, "stop_threshold: %lu\n", runtime->stop_threshold);
... ... @@ -764,12 +762,6 @@
764 762 return snd_pcm_free(pcm);
765 763 }
766 764  
767   -static void snd_pcm_tick_timer_func(unsigned long data)
768   -{
769   - struct snd_pcm_substream *substream = (struct snd_pcm_substream *) data;
770   - snd_pcm_tick_elapsed(substream);
771   -}
772   -
773 765 int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
774 766 struct file *file,
775 767 struct snd_pcm_substream **rsubstream)
... ... @@ -876,9 +868,6 @@
876 868 memset((void*)runtime->control, 0, size);
877 869  
878 870 init_waitqueue_head(&runtime->sleep);
879   - init_timer(&runtime->tick_timer);
880   - runtime->tick_timer.function = snd_pcm_tick_timer_func;
881   - runtime->tick_timer.data = (unsigned long) substream;
882 871  
883 872 runtime->status->state = SNDRV_PCM_STATE_OPEN;
884 873  
sound/core/pcm_lib.c
... ... @@ -1451,112 +1451,13 @@
1451 1451  
1452 1452 EXPORT_SYMBOL(snd_pcm_lib_ioctl);
1453 1453  
1454   -/*
1455   - * Conditions
1456   - */
1457   -
1458   -static void snd_pcm_system_tick_set(struct snd_pcm_substream *substream,
1459   - unsigned long ticks)
1460   -{
1461   - struct snd_pcm_runtime *runtime = substream->runtime;
1462   - if (ticks == 0)
1463   - del_timer(&runtime->tick_timer);
1464   - else {
1465   - ticks += (1000000 / HZ) - 1;
1466   - ticks /= (1000000 / HZ);
1467   - mod_timer(&runtime->tick_timer, jiffies + ticks);
1468   - }
1469   -}
1470   -
1471   -/* Temporary alias */
1472   -void snd_pcm_tick_set(struct snd_pcm_substream *substream, unsigned long ticks)
1473   -{
1474   - snd_pcm_system_tick_set(substream, ticks);
1475   -}
1476   -
1477   -void snd_pcm_tick_prepare(struct snd_pcm_substream *substream)
1478   -{
1479   - struct snd_pcm_runtime *runtime = substream->runtime;
1480   - snd_pcm_uframes_t frames = ULONG_MAX;
1481   - snd_pcm_uframes_t avail, dist;
1482   - unsigned int ticks;
1483   - u_int64_t n;
1484   - u_int32_t r;
1485   - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1486   - if (runtime->silence_size >= runtime->boundary) {
1487   - frames = 1;
1488   - } else if (runtime->silence_size > 0 &&
1489   - runtime->silence_filled < runtime->buffer_size) {
1490   - snd_pcm_sframes_t noise_dist;
1491   - noise_dist = snd_pcm_playback_hw_avail(runtime) + runtime->silence_filled;
1492   - if (noise_dist > (snd_pcm_sframes_t)runtime->silence_threshold)
1493   - frames = noise_dist - runtime->silence_threshold;
1494   - }
1495   - avail = snd_pcm_playback_avail(runtime);
1496   - } else {
1497   - avail = snd_pcm_capture_avail(runtime);
1498   - }
1499   - if (avail < runtime->control->avail_min) {
1500   - snd_pcm_sframes_t to_avail_min =
1501   - runtime->control->avail_min - avail;
1502   - if (to_avail_min > 0 &&
1503   - frames > (snd_pcm_uframes_t)to_avail_min)
1504   - frames = to_avail_min;
1505   - }
1506   - if (avail < runtime->buffer_size) {
1507   - snd_pcm_sframes_t to_buffer_size =
1508   - runtime->buffer_size - avail;
1509   - if (to_buffer_size > 0 &&
1510   - frames > (snd_pcm_uframes_t)to_buffer_size)
1511   - frames = to_buffer_size;
1512   - }
1513   - if (frames == ULONG_MAX) {
1514   - snd_pcm_tick_set(substream, 0);
1515   - return;
1516   - }
1517   - dist = runtime->status->hw_ptr - runtime->hw_ptr_base;
1518   - /* Distance to next interrupt */
1519   - dist = runtime->period_size - dist % runtime->period_size;
1520   - if (dist <= frames) {
1521   - snd_pcm_tick_set(substream, 0);
1522   - return;
1523   - }
1524   - /* the base time is us */
1525   - n = frames;
1526   - n *= 1000000;
1527   - div64_32(&n, runtime->tick_time * runtime->rate, &r);
1528   - ticks = n + (r > 0 ? 1 : 0);
1529   - if (ticks < runtime->sleep_min)
1530   - ticks = runtime->sleep_min;
1531   - snd_pcm_tick_set(substream, (unsigned long) ticks);
1532   -}
1533   -
1534   -void snd_pcm_tick_elapsed(struct snd_pcm_substream *substream)
1535   -{
1536   - struct snd_pcm_runtime *runtime;
1537   - unsigned long flags;
1538   -
1539   - snd_assert(substream != NULL, return);
1540   - runtime = substream->runtime;
1541   - snd_assert(runtime != NULL, return);
1542   -
1543   - snd_pcm_stream_lock_irqsave(substream, flags);
1544   - if (!snd_pcm_running(substream) ||
1545   - snd_pcm_update_hw_ptr(substream) < 0)
1546   - goto _end;
1547   - if (runtime->sleep_min)
1548   - snd_pcm_tick_prepare(substream);
1549   - _end:
1550   - snd_pcm_stream_unlock_irqrestore(substream, flags);
1551   -}
1552   -
1553 1454 /**
1554 1455 * snd_pcm_period_elapsed - update the pcm status for the next period
1555 1456 * @substream: the pcm substream instance
1556 1457 *
1557 1458 * This function is called from the interrupt handler when the
1558 1459 * PCM has processed the period size. It will update the current
1559   - * pointer, set up the tick, wake up sleepers, etc.
  1460 + * pointer, wake up sleepers, etc.
1560 1461 *
1561 1462 * Even if more than one periods have elapsed since the last call, you
1562 1463 * have to call this only once.
... ... @@ -1580,8 +1481,6 @@
1580 1481  
1581 1482 if (substream->timer_running)
1582 1483 snd_timer_interrupt(substream->timer, 1);
1583   - if (runtime->sleep_min)
1584   - snd_pcm_tick_prepare(substream);
1585 1484 _end:
1586 1485 snd_pcm_stream_unlock_irqrestore(substream, flags);
1587 1486 if (runtime->transfer_ack_end)
... ... @@ -1715,7 +1614,7 @@
1715 1614 snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
1716 1615 snd_pcm_uframes_t avail;
1717 1616 snd_pcm_uframes_t cont;
1718   - if (runtime->sleep_min == 0 && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
  1617 + if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
1719 1618 snd_pcm_update_hw_ptr(substream);
1720 1619 avail = snd_pcm_playback_avail(runtime);
1721 1620 if (!avail) {
... ... @@ -1764,9 +1663,6 @@
1764 1663 if (err < 0)
1765 1664 goto _end_unlock;
1766 1665 }
1767   - if (runtime->sleep_min &&
1768   - runtime->status->state == SNDRV_PCM_STATE_RUNNING)
1769   - snd_pcm_tick_prepare(substream);
1770 1666 }
1771 1667 _end_unlock:
1772 1668 snd_pcm_stream_unlock_irq(substream);
... ... @@ -1923,7 +1819,7 @@
1923 1819 snd_pcm_uframes_t frames, appl_ptr, appl_ofs;
1924 1820 snd_pcm_uframes_t avail;
1925 1821 snd_pcm_uframes_t cont;
1926   - if (runtime->sleep_min == 0 && runtime->status->state == SNDRV_PCM_STATE_RUNNING)
  1822 + if (runtime->status->state == SNDRV_PCM_STATE_RUNNING)
1927 1823 snd_pcm_update_hw_ptr(substream);
1928 1824 avail = snd_pcm_capture_avail(runtime);
1929 1825 if (!avail) {
... ... @@ -1973,9 +1869,6 @@
1973 1869 offset += frames;
1974 1870 size -= frames;
1975 1871 xfer += frames;
1976   - if (runtime->sleep_min &&
1977   - runtime->status->state == SNDRV_PCM_STATE_RUNNING)
1978   - snd_pcm_tick_prepare(substream);
1979 1872 }
1980 1873 _end_unlock:
1981 1874 snd_pcm_stream_unlock_irq(substream);
sound/core/pcm_native.c
... ... @@ -413,7 +413,6 @@
413 413 runtime->period_size = params_period_size(params);
414 414 runtime->periods = params_periods(params);
415 415 runtime->buffer_size = params_buffer_size(params);
416   - runtime->tick_time = params_tick_time(params);
417 416 runtime->info = params->info;
418 417 runtime->rate_num = params->rate_num;
419 418 runtime->rate_den = params->rate_den;
... ... @@ -433,7 +432,6 @@
433 432 /* Default sw params */
434 433 runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE;
435 434 runtime->period_step = 1;
436   - runtime->sleep_min = 0;
437 435 runtime->control->avail_min = runtime->period_size;
438 436 runtime->start_threshold = 1;
439 437 runtime->stop_threshold = runtime->buffer_size;
... ... @@ -542,7 +540,6 @@
542 540 }
543 541 snd_pcm_stream_lock_irq(substream);
544 542 runtime->tstamp_mode = params->tstamp_mode;
545   - runtime->sleep_min = params->sleep_min;
546 543 runtime->period_step = params->period_step;
547 544 runtime->control->avail_min = params->avail_min;
548 545 runtime->start_threshold = params->start_threshold;
... ... @@ -551,10 +548,6 @@
551 548 runtime->silence_size = params->silence_size;
552 549 params->boundary = runtime->boundary;
553 550 if (snd_pcm_running(substream)) {
554   - if (runtime->sleep_min)
555   - snd_pcm_tick_prepare(substream);
556   - else
557   - snd_pcm_tick_set(substream, 0);
558 551 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
559 552 runtime->silence_size > 0)
560 553 snd_pcm_playback_silence(substream, ULONG_MAX);
... ... @@ -865,8 +858,6 @@
865 858 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
866 859 runtime->silence_size > 0)
867 860 snd_pcm_playback_silence(substream, ULONG_MAX);
868   - if (runtime->sleep_min)
869   - snd_pcm_tick_prepare(substream);
870 861 if (substream->timer)
871 862 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSTART,
872 863 &runtime->trigger_tstamp);
... ... @@ -920,7 +911,6 @@
920 911 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSTOP,
921 912 &runtime->trigger_tstamp);
922 913 runtime->status->state = state;
923   - snd_pcm_tick_set(substream, 0);
924 914 }
925 915 wake_up(&runtime->sleep);
926 916 }
927 917  
... ... @@ -1004,12 +994,9 @@
1004 994 snd_timer_notify(substream->timer,
1005 995 SNDRV_TIMER_EVENT_MPAUSE,
1006 996 &runtime->trigger_tstamp);
1007   - snd_pcm_tick_set(substream, 0);
1008 997 wake_up(&runtime->sleep);
1009 998 } else {
1010 999 runtime->status->state = SNDRV_PCM_STATE_RUNNING;
1011   - if (runtime->sleep_min)
1012   - snd_pcm_tick_prepare(substream);
1013 1000 if (substream->timer)
1014 1001 snd_timer_notify(substream->timer,
1015 1002 SNDRV_TIMER_EVENT_MCONTINUE,
... ... @@ -1064,7 +1051,6 @@
1064 1051 &runtime->trigger_tstamp);
1065 1052 runtime->status->suspended_state = runtime->status->state;
1066 1053 runtime->status->state = SNDRV_PCM_STATE_SUSPENDED;
1067   - snd_pcm_tick_set(substream, 0);
1068 1054 wake_up(&runtime->sleep);
1069 1055 }
1070 1056  
... ... @@ -1167,8 +1153,6 @@
1167 1153 snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MRESUME,
1168 1154 &runtime->trigger_tstamp);
1169 1155 runtime->status->state = runtime->status->suspended_state;
1170   - if (runtime->sleep_min)
1171   - snd_pcm_tick_prepare(substream);
1172 1156 }
1173 1157  
1174 1158 static struct action_ops snd_pcm_action_resume = {
... ... @@ -1997,8 +1981,6 @@
1997 1981 }
1998 1982  
1999 1983 /* FIXME: this belong to lowlevel */
2000   - snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_TICK_TIME,
2001   - 1000000 / HZ, 1000000 / HZ);
2002 1984 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
2003 1985  
2004 1986 return 0;
... ... @@ -2238,9 +2220,6 @@
2238 2220 if (appl_ptr < 0)
2239 2221 appl_ptr += runtime->boundary;
2240 2222 runtime->control->appl_ptr = appl_ptr;
2241   - if (runtime->status->state == SNDRV_PCM_STATE_RUNNING &&
2242   - runtime->sleep_min)
2243   - snd_pcm_tick_prepare(substream);
2244 2223 ret = frames;
2245 2224 __end:
2246 2225 snd_pcm_stream_unlock_irq(substream);
... ... @@ -2286,9 +2265,6 @@
2286 2265 if (appl_ptr < 0)
2287 2266 appl_ptr += runtime->boundary;
2288 2267 runtime->control->appl_ptr = appl_ptr;
2289   - if (runtime->status->state == SNDRV_PCM_STATE_RUNNING &&
2290   - runtime->sleep_min)
2291   - snd_pcm_tick_prepare(substream);
2292 2268 ret = frames;
2293 2269 __end:
2294 2270 snd_pcm_stream_unlock_irq(substream);
... ... @@ -2335,9 +2311,6 @@
2335 2311 if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary)
2336 2312 appl_ptr -= runtime->boundary;
2337 2313 runtime->control->appl_ptr = appl_ptr;
2338   - if (runtime->status->state == SNDRV_PCM_STATE_RUNNING &&
2339   - runtime->sleep_min)
2340   - snd_pcm_tick_prepare(substream);
2341 2314 ret = frames;
2342 2315 __end:
2343 2316 snd_pcm_stream_unlock_irq(substream);
... ... @@ -2384,9 +2357,6 @@
2384 2357 if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary)
2385 2358 appl_ptr -= runtime->boundary;
2386 2359 runtime->control->appl_ptr = appl_ptr;
2387   - if (runtime->status->state == SNDRV_PCM_STATE_RUNNING &&
2388   - runtime->sleep_min)
2389   - snd_pcm_tick_prepare(substream);
2390 2360 ret = frames;
2391 2361 __end:
2392 2362 snd_pcm_stream_unlock_irq(substream);