X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/045c1d602dcba57868845ba3270510593c39480f..27e47c72a25846e107b6e450c3a1480a2742382e:/src/tests/rtstutter.c diff --git a/src/tests/rtstutter.c b/src/tests/rtstutter.c index 39dfc5d3..739683d5 100644 --- a/src/tests/rtstutter.c +++ b/src/tests/rtstutter.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -7,7 +5,7 @@ PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2 of the + published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. PulseAudio is distributed in the hope that it will be useful, but @@ -28,69 +26,70 @@ #include #include #include -#include #include -#include + +#ifdef HAVE_PTHREAD #include +#endif +#include #include #include #include #include +#include +#include +#include static int msec_lower, msec_upper; -static void* work(void *p) PA_GCC_NORETURN; +static void work(void *p) PA_GCC_NORETURN; -static void* work(void *p) { - cpu_set_t mask; - struct sched_param param; +static void work(void *p) { + + pa_log_notice("CPU%i: Created thread.", PA_PTR_TO_UINT(p)); - pa_log_notice("CPU%i: Created thread.", PA_PTR_TO_INT(p)); + pa_make_realtime(12); - memset(¶m, 0, sizeof(param)); - param.sched_priority = 12; - pa_assert_se(pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) == 0); +#ifdef HAVE_PTHREAD_SETAFFINITY_NP +{ + cpu_set_t mask; CPU_ZERO(&mask); - CPU_SET(PA_PTR_TO_INT(p), &mask); + CPU_SET((size_t) PA_PTR_TO_UINT(p), &mask); pa_assert_se(pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) == 0); +} +#endif for (;;) { - struct timespec now, end; - uint64_t nsec; - - pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_INT(p)); - sleep(1); + struct timeval now, end; + uint64_t usec; - pa_assert_se(clock_gettime(CLOCK_REALTIME, &end) == 0); + pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_UINT(p)); + pa_msleep(1000); - nsec = - (uint64_t) ((((double) rand())*(msec_upper-msec_lower)*PA_NSEC_PER_MSEC)/RAND_MAX) + - (uint64_t) (msec_lower*PA_NSEC_PER_MSEC); + usec = + (uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_USEC_PER_MSEC)/RAND_MAX) + + (uint64_t) ((uint64_t) msec_lower*PA_USEC_PER_MSEC); - pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_INT(p), (int) (nsec/PA_NSEC_PER_MSEC)); + pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (usec/PA_USEC_PER_MSEC)); - end.tv_sec += nsec / PA_NSEC_PER_SEC; - end.tv_nsec += nsec % PA_NSEC_PER_SEC; - - while (end.tv_nsec > PA_NSEC_PER_SEC) { - end.tv_sec++; - end.tv_nsec -= PA_NSEC_PER_SEC; - } + pa_rtclock_get(&end); + pa_timeval_add(&end, usec); do { - pa_assert_se(clock_gettime(CLOCK_REALTIME, &now) == 0); - } while (now.tv_sec < end.tv_sec || - (now.tv_sec == end.tv_sec && now.tv_nsec < end.tv_nsec)); + pa_rtclock_get(&now); + } while (pa_timeval_cmp(&now, &end) < 0); } } int main(int argc, char*argv[]) { - int n; + unsigned n; + + pa_log_set_level(PA_LOG_INFO); - srand(time(NULL)); + srand((unsigned) time(NULL)); if (argc >= 3) { msec_lower = atoi(argv[1]); @@ -106,11 +105,10 @@ int main(int argc, char*argv[]) { pa_assert(msec_upper > 0); pa_assert(msec_upper >= msec_lower); - pa_log_notice("Creating random latencies in the range of %ims to %ims.", msec_lower, msec_upper); + pa_log_notice("Creating random latencies in the range of %ims to %ims.", msec_lower, msec_upper); - for (n = 1; n < sysconf(_SC_NPROCESSORS_CONF); n++) { - pthread_t t; - pa_assert_se(pthread_create(&t, NULL, work, PA_INT_TO_PTR(n)) == 0); + for (n = 1; n < pa_ncpus(); n++) { + pa_assert_se(pa_thread_new("rtstutter", work, PA_UINT_TO_PTR(n))); } work(PA_INT_TO_PTR(0));