mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	alsa-sink/source: Warn for scheduling delays
Sometimes the kernel does not schedule us in due time, thus causing an underrun. Adding a detection and a debug message will be a helpful step in determining the cause of an underrun. Signed-off-by: David Henningsson <david.henningsson@canonical.com>
This commit is contained in:
		
							parent
							
								
									2219a775c4
								
							
						
					
					
						commit
						3bb0b88beb
					
				
					 2 changed files with 32 additions and 4 deletions
				
			
		| 
						 | 
					@ -1685,7 +1685,7 @@ static void thread_func(void *userdata) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (;;) {
 | 
					    for (;;) {
 | 
				
			||||||
        int ret;
 | 
					        int ret;
 | 
				
			||||||
        pa_usec_t rtpoll_sleep = 0;
 | 
					        pa_usec_t rtpoll_sleep = 0, real_sleep;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef DEBUG_TIMING
 | 
					#ifdef DEBUG_TIMING
 | 
				
			||||||
        pa_log_debug("Loop");
 | 
					        pa_log_debug("Loop");
 | 
				
			||||||
| 
						 | 
					@ -1776,8 +1776,10 @@ static void thread_func(void *userdata) {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (rtpoll_sleep > 0)
 | 
					        if (rtpoll_sleep > 0) {
 | 
				
			||||||
            pa_rtpoll_set_timer_relative(u->rtpoll, rtpoll_sleep);
 | 
					            pa_rtpoll_set_timer_relative(u->rtpoll, rtpoll_sleep);
 | 
				
			||||||
 | 
					            real_sleep = pa_rtclock_now();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            pa_rtpoll_set_timer_disabled(u->rtpoll);
 | 
					            pa_rtpoll_set_timer_disabled(u->rtpoll);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1785,6 +1787,18 @@ static void thread_func(void *userdata) {
 | 
				
			||||||
        if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
 | 
					        if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
 | 
				
			||||||
            goto fail;
 | 
					            goto fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (rtpoll_sleep > 0) {
 | 
				
			||||||
 | 
					            real_sleep = pa_rtclock_now() - real_sleep;
 | 
				
			||||||
 | 
					#ifdef DEBUG_TIMING
 | 
				
			||||||
 | 
					            pa_log_debug("Expected sleep: %0.2fms, real sleep: %0.2fms (diff %0.2f ms)",
 | 
				
			||||||
 | 
					                (double) rtpoll_sleep / PA_USEC_PER_MSEC, (double) real_sleep / PA_USEC_PER_MSEC,
 | 
				
			||||||
 | 
					                (double) ((int64_t) real_sleep - (int64_t) rtpoll_sleep) / PA_USEC_PER_MSEC);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					            if (u->use_tsched && real_sleep > rtpoll_sleep + u->tsched_watermark)
 | 
				
			||||||
 | 
					                pa_log_info("Scheduling delay of %0.2fms, you might want to investigate this to improve latency...",
 | 
				
			||||||
 | 
					                    (double) (real_sleep - rtpoll_sleep) / PA_USEC_PER_MSEC);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (u->sink->flags & PA_SINK_DEFERRED_VOLUME)
 | 
					        if (u->sink->flags & PA_SINK_DEFERRED_VOLUME)
 | 
				
			||||||
            pa_sink_volume_change_apply(u->sink, NULL);
 | 
					            pa_sink_volume_change_apply(u->sink, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1451,7 +1451,7 @@ static void thread_func(void *userdata) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (;;) {
 | 
					    for (;;) {
 | 
				
			||||||
        int ret;
 | 
					        int ret;
 | 
				
			||||||
        pa_usec_t rtpoll_sleep = 0;
 | 
					        pa_usec_t rtpoll_sleep = 0, real_sleep;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef DEBUG_TIMING
 | 
					#ifdef DEBUG_TIMING
 | 
				
			||||||
        pa_log_debug("Loop");
 | 
					        pa_log_debug("Loop");
 | 
				
			||||||
| 
						 | 
					@ -1515,8 +1515,10 @@ static void thread_func(void *userdata) {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (rtpoll_sleep > 0)
 | 
					        if (rtpoll_sleep > 0) {
 | 
				
			||||||
            pa_rtpoll_set_timer_relative(u->rtpoll, rtpoll_sleep);
 | 
					            pa_rtpoll_set_timer_relative(u->rtpoll, rtpoll_sleep);
 | 
				
			||||||
 | 
					            real_sleep = pa_rtclock_now();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            pa_rtpoll_set_timer_disabled(u->rtpoll);
 | 
					            pa_rtpoll_set_timer_disabled(u->rtpoll);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1524,6 +1526,18 @@ static void thread_func(void *userdata) {
 | 
				
			||||||
        if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
 | 
					        if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
 | 
				
			||||||
            goto fail;
 | 
					            goto fail;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (rtpoll_sleep > 0) {
 | 
				
			||||||
 | 
					            real_sleep = pa_rtclock_now() - real_sleep;
 | 
				
			||||||
 | 
					#ifdef DEBUG_TIMING
 | 
				
			||||||
 | 
					            pa_log_debug("Expected sleep: %0.2fms, real sleep: %0.2fms (diff %0.2f ms)",
 | 
				
			||||||
 | 
					                (double) rtpoll_sleep / PA_USEC_PER_MSEC, (double) real_sleep / PA_USEC_PER_MSEC,
 | 
				
			||||||
 | 
					                (double) ((int64_t) real_sleep - (int64_t) rtpoll_sleep) / PA_USEC_PER_MSEC);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					            if (u->use_tsched && real_sleep > rtpoll_sleep + u->tsched_watermark)
 | 
				
			||||||
 | 
					                pa_log_info("Scheduling delay of %0.2fms, you might want to investigate this to improve latency...",
 | 
				
			||||||
 | 
					                    (double) (real_sleep - rtpoll_sleep) / PA_USEC_PER_MSEC);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (u->source->flags & PA_SOURCE_DEFERRED_VOLUME)
 | 
					        if (u->source->flags & PA_SOURCE_DEFERRED_VOLUME)
 | 
				
			||||||
            pa_source_volume_change_apply(u->source, NULL);
 | 
					            pa_source_volume_change_apply(u->source, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue