diff options
author | Paul Hsia <paulhsia@google.com> | 2018-07-24 09:16:18 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-07 01:50:08 -0700 |
commit | 1ef46ee06cc610e139d834445837626686b41df4 (patch) | |
tree | cf03e3d0dd7c36611d92cf745c4d6903dd8dd8ee /cras/src/server/audio_thread.c | |
parent | 62f13cff586f323f1116c81f1be3842b57e961cb (diff) | |
download | adhd-1ef46ee06cc610e139d834445837626686b41df4.tar.gz |
CRAS: Add busyloop event detection in audio_thread
Initialize audio thread monitor in cras_server.
Create a method - check_busyloop for detecting busyloop in audio thread
and take a snapshot for audio thread when busyloop occurs.
BUG=chromium:866240
TEST=audio_thread_unittest
Change-Id: Iab6a05e16e4b17d1b6740e43562bfe8c5d193ec8
Reviewed-on: https://chromium-review.googlesource.com/1148087
Commit-Ready: Chih-Yang Hsia <paulhsia@chromium.org>
Tested-by: Chih-Yang Hsia <paulhsia@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'cras/src/server/audio_thread.c')
-rw-r--r-- | cras/src/server/audio_thread.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/cras/src/server/audio_thread.c b/cras/src/server/audio_thread.c index 290bbff2..27f99275 100644 --- a/cras/src/server/audio_thread.c +++ b/cras/src/server/audio_thread.c @@ -14,6 +14,7 @@ #include <syslog.h> #include "audio_thread_log.h" +#include "cras_audio_thread_monitor.h" #include "cras_config.h" #include "cras_fmt_conv.h" #include "cras_iodev.h" @@ -28,6 +29,10 @@ #define MIN_PROCESS_TIME_US 500 /* 0.5ms - min amount of time to mix/src. */ #define SLEEP_FUZZ_FRAMES 10 /* # to consider "close enough" to sleep frames. */ #define MIN_READ_WAIT_US 2000 /* 2ms */ +/* + * # to check whether a busyloop event happens + */ +#define MAX_CONTINUOUS_ZERO_SLEEP_COUNT 2 /* Messages that can be sent from the main context to the audio thread. */ enum AUDIO_THREAD_COMMAND { @@ -861,6 +866,22 @@ static struct pollfd *add_pollfd(struct audio_thread *thread, return &thread->pollfds[thread->num_pollfds - 1]; } +static int continuous_zero_sleep_count = 0; +static void check_busyloop(struct timespec* wait_ts) +{ + if(wait_ts->tv_sec == 0 && wait_ts->tv_nsec == 0) + { + continuous_zero_sleep_count ++; + if(continuous_zero_sleep_count == + MAX_CONTINUOUS_ZERO_SLEEP_COUNT) + cras_audio_thread_busyloop(); + } + else + { + continuous_zero_sleep_count = 0; + } +} + /* For playback, fill the audio buffer when needed, for capture, pull out * samples when they are ready. * This thread will attempt to run at a high priority to allow for low latency @@ -947,6 +968,8 @@ restart_poll_loop: ATLOG(atlog, AUDIO_THREAD_SLEEP, wait_ts ? wait_ts->tv_sec : 0, wait_ts ? wait_ts->tv_nsec : 0, longest_wake.tv_nsec); + if(wait_ts) + check_busyloop(wait_ts); rc = ppoll(thread->pollfds, thread->num_pollfds, wait_ts, NULL); clock_gettime(CLOCK_MONOTONIC_RAW, &last_wake); ATLOG(atlog, AUDIO_THREAD_WAKE, rc, 0, 0); |