core: get rid of rt sig/timer handling since modern Linux' ppooll() is finally fixed for granularity

This commit is contained in:
Lennart Poettering 2009-06-19 21:00:06 +02:00
parent a62db279b7
commit 32e2cd6d32
21 changed files with 4 additions and 372 deletions

View file

@ -811,7 +811,6 @@ libpulsecore_@PA_MAJORMINORMICRO@_la_SOURCES = \
pulsecore/play-memchunk.c pulsecore/play-memchunk.h \
pulsecore/resampler.c pulsecore/resampler.h \
pulsecore/rtpoll.c pulsecore/rtpoll.h \
pulsecore/rtsig.c pulsecore/rtsig.h \
pulsecore/sample-util.c pulsecore/sample-util.h \
pulsecore/sconv-s16be.c pulsecore/sconv-s16be.h \
pulsecore/sconv-s16le.c pulsecore/sconv-s16le.h \

View file

@ -84,7 +84,6 @@
#include <pulsecore/pid.h>
#include <pulsecore/namereg.h>
#include <pulsecore/random.h>
#include <pulsecore/rtsig.h>
#include <pulsecore/rtclock.h>
#include <pulsecore/macro.h>
#include <pulsecore/mutex.h>
@ -797,11 +796,6 @@ int main(int argc, char *argv[]) {
else
pa_log_info(_("Dude, your kernel stinks! The chef's recommendation today is Linux with high-resolution timers enabled!"));
#ifdef SIGRTMIN
/* Valgrind uses SIGRTMAX. To easy debugging we don't use it here */
pa_rtsig_configure(SIGRTMIN, SIGRTMAX-1);
#endif
if (conf->lock_memory) {
#ifdef HAVE_SYS_MMAN_H
if (mlockall(MCL_FUTURE) < 0)

View file

@ -1212,7 +1212,6 @@ static void thread_func(void *userdata) {
pa_make_realtime(u->core->realtime_priority);
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
int ret;

View file

@ -1094,7 +1094,6 @@ static void thread_func(void *userdata) {
pa_make_realtime(u->core->realtime_priority);
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
int ret;

View file

@ -1265,7 +1265,6 @@ static void thread_func(void *userdata) {
goto fail;
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
struct pollfd *pollfd;

View file

@ -225,7 +225,6 @@ static void thread_func(void *userdata) {
pa_make_realtime(u->core->realtime_priority);
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
int ret;

View file

@ -196,7 +196,6 @@ static void thread_func(void *userdata) {
pa_make_realtime(u->core->realtime_priority);
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
int ret;

View file

@ -280,7 +280,6 @@ static void thread_func(void *userdata) {
pa_make_realtime(u->core->realtime_priority+1);
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
u->thread_info.timestamp = pa_rtclock_usec();
u->thread_info.in_null_mode = FALSE;

View file

@ -200,7 +200,6 @@ static void thread_func(void *userdata) {
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
pa_smoother_set_time_offset(u->smoother, pa_rtclock_usec());

View file

@ -208,7 +208,6 @@ static void thread_func(void *userdata) {
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
u->timestamp = pa_rtclock_usec();

View file

@ -170,7 +170,6 @@ static void thread_func(void *userdata) {
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
struct pollfd *pollfd;

View file

@ -129,7 +129,6 @@ static void thread_func(void *userdata) {
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
int ret;

View file

@ -166,7 +166,6 @@ static void thread_func(void *userdata) {
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
u->timestamp = pa_rtclock_usec();

View file

@ -683,7 +683,6 @@ static void thread_func(void *userdata) {
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
int ret;

View file

@ -889,7 +889,6 @@ static void thread_func(void *userdata) {
pa_make_realtime(u->core->realtime_priority);
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
for (;;) {
int ret;

View file

@ -323,7 +323,6 @@ static void thread_func(void *userdata) {
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
pa_smoother_set_time_offset(u->smoother, pa_rtclock_usec());

View file

@ -30,10 +30,6 @@
#include <string.h>
#include <errno.h>
#ifdef __linux__
#include <sys/utsname.h>
#endif
#ifdef HAVE_POLL_H
#include <poll.h>
#else
@ -47,7 +43,6 @@
#include <pulsecore/rtclock.h>
#include <pulsecore/macro.h>
#include <pulsecore/llist.h>
#include <pulsecore/rtsig.h>
#include <pulsecore/flist.h>
#include <pulsecore/core-util.h>
#include <pulsecore/winsock.h>
@ -66,20 +61,9 @@ struct pa_rtpoll {
pa_bool_t scan_for_dead:1;
pa_bool_t running:1;
pa_bool_t installed:1;
pa_bool_t rebuild_needed:1;
pa_bool_t quit:1;
#ifdef HAVE_PPOLL
pa_bool_t timer_armed:1;
#ifdef __linux__
pa_bool_t dont_use_ppoll:1;
#endif
int rtsig;
sigset_t sigset_unblocked;
timer_t timer;
#endif
#ifdef DEBUG_TIMING
pa_usec_t timestamp;
pa_usec_t slept, awake;
@ -107,52 +91,20 @@ struct pa_rtpoll_item {
PA_STATIC_FLIST_DECLARE(items, 0, pa_xfree);
static void signal_handler_noop(int s) { /* write(2, "signal\n", 7); */ }
pa_rtpoll *pa_rtpoll_new(void) {
pa_rtpoll *p;
p = pa_xnew(pa_rtpoll, 1);
#ifdef HAVE_PPOLL
#ifdef __linux__
/* ppoll is broken on Linux < 2.6.16 */
p->dont_use_ppoll = FALSE;
{
struct utsname u;
unsigned major, minor, micro;
pa_assert_se(uname(&u) == 0);
if (sscanf(u.release, "%u.%u.%u", &major, &minor, &micro) != 3 ||
(major < 2) ||
(major == 2 && minor < 6) ||
(major == 2 && minor == 6 && micro < 16))
p->dont_use_ppoll = TRUE;
}
#endif
p->rtsig = -1;
sigemptyset(&p->sigset_unblocked);
p->timer = (timer_t) -1;
p->timer_armed = FALSE;
#endif
p->n_pollfd_alloc = 32;
p->pollfd = pa_xnew(struct pollfd, p->n_pollfd_alloc);
p->pollfd2 = pa_xnew(struct pollfd, p->n_pollfd_alloc);
p->n_pollfd_used = 0;
memset(&p->next_elapse, 0, sizeof(p->next_elapse));
pa_zero(p->next_elapse);
p->timer_enabled = FALSE;
p->running = FALSE;
p->installed = FALSE;
p->scan_for_dead = FALSE;
p->rebuild_needed = FALSE;
p->quit = FALSE;
@ -167,46 +119,6 @@ pa_rtpoll *pa_rtpoll_new(void) {
return p;
}
void pa_rtpoll_install(pa_rtpoll *p) {
pa_assert(p);
pa_assert(!p->installed);
p->installed = TRUE;
#ifdef HAVE_PPOLL
# ifdef __linux__
if (p->dont_use_ppoll)
return;
# endif
if ((p->rtsig = pa_rtsig_get_for_thread()) < 0) {
pa_log_warn("Failed to reserve POSIX realtime signal.");
return;
}
pa_log_debug("Acquired POSIX realtime signal %s", pa_sig2str(p->rtsig));
{
sigset_t ss;
struct sigaction sa;
pa_assert_se(sigemptyset(&ss) == 0);
pa_assert_se(sigaddset(&ss, p->rtsig) == 0);
pa_assert_se(pthread_sigmask(SIG_BLOCK, &ss, &p->sigset_unblocked) == 0);
pa_assert_se(sigdelset(&p->sigset_unblocked, p->rtsig) == 0);
memset(&sa, 0, sizeof(sa));
sa.sa_handler = signal_handler_noop;
pa_assert_se(sigemptyset(&sa.sa_mask) == 0);
pa_assert_se(sigaction(p->rtsig, &sa, NULL) == 0);
/* We never reset the signal handler. Why should we? */
}
#endif
}
static void rtpoll_rebuild(pa_rtpoll *p) {
struct pollfd *e, *t;
@ -250,7 +162,6 @@ static void rtpoll_rebuild(pa_rtpoll *p) {
if (ra)
p->pollfd2 = pa_xrealloc(p->pollfd2, p->n_pollfd_alloc * sizeof(struct pollfd));
}
static void rtpoll_item_destroy(pa_rtpoll_item *i) {
@ -279,11 +190,6 @@ void pa_rtpoll_free(pa_rtpoll *p) {
pa_xfree(p->pollfd);
pa_xfree(p->pollfd2);
#ifdef HAVE_PPOLL
if (p->timer != (timer_t) -1)
timer_delete(p->timer);
#endif
pa_xfree(p);
}
@ -321,7 +227,6 @@ int pa_rtpoll_run(pa_rtpoll *p, pa_bool_t wait) {
pa_assert(p);
pa_assert(!p->running);
pa_assert(p->installed);
p->running = TRUE;
@ -402,22 +307,15 @@ int pa_rtpoll_run(pa_rtpoll *p, pa_bool_t wait) {
/* OK, now let's sleep */
#ifdef HAVE_PPOLL
#ifdef __linux__
if (!p->dont_use_ppoll)
#endif
{
struct timespec ts;
ts.tv_sec = timeout.tv_sec;
ts.tv_nsec = timeout.tv_usec * 1000;
r = ppoll(p->pollfd, p->n_pollfd_used, (!wait || p->quit || p->timer_enabled) ? &ts : NULL, p->rtsig < 0 ? NULL : &p->sigset_unblocked);
r = ppoll(p->pollfd, p->n_pollfd_used, (!wait || p->quit || p->timer_enabled) ? &ts : NULL, NULL);
}
#ifdef __linux__
else
#endif
#endif
#else
r = poll(p->pollfd, p->n_pollfd_used, (!wait || p->quit || p->timer_enabled) ? (int) ((timeout.tv_sec*1000) + (timeout.tv_usec / 1000)) : -1);
#endif
#ifdef DEBUG_TIMING
{
@ -472,73 +370,11 @@ finish:
return r < 0 ? r : !p->quit;
}
static void update_timer(pa_rtpoll *p) {
pa_assert(p);
#ifdef HAVE_PPOLL
#ifdef __linux__
if (p->dont_use_ppoll)
return;
#endif
if (p->timer == (timer_t) -1) {
struct sigevent se;
memset(&se, 0, sizeof(se));
se.sigev_notify = SIGEV_SIGNAL;
se.sigev_signo = p->rtsig;
if (timer_create(CLOCK_MONOTONIC, &se, &p->timer) < 0)
if (timer_create(CLOCK_REALTIME, &se, &p->timer) < 0) {
pa_log_warn("Failed to allocate POSIX timer: %s", pa_cstrerror(errno));
p->timer = (timer_t) -1;
}
}
if (p->timer != (timer_t) -1) {
struct itimerspec its;
struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 };
sigset_t ss;
if (p->timer_armed) {
/* First disarm timer */
memset(&its, 0, sizeof(its));
pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
/* Remove a signal that might be waiting in the signal q */
pa_assert_se(sigemptyset(&ss) == 0);
pa_assert_se(sigaddset(&ss, p->rtsig) == 0);
sigtimedwait(&ss, NULL, &ts);
}
/* And install the new timer */
if (p->timer_enabled) {
memset(&its, 0, sizeof(its));
its.it_value.tv_sec = p->next_elapse.tv_sec;
its.it_value.tv_nsec = p->next_elapse.tv_usec*1000;
/* Make sure that 0,0 is not understood as
* "disarming" */
if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0)
its.it_value.tv_nsec = 1;
pa_assert_se(timer_settime(p->timer, TIMER_ABSTIME, &its, NULL) == 0);
}
p->timer_armed = p->timer_enabled;
}
#endif
}
void pa_rtpoll_set_timer_absolute(pa_rtpoll *p, pa_usec_t usec) {
pa_assert(p);
pa_timeval_store(&p->next_elapse, usec);
p->timer_enabled = TRUE;
update_timer(p);
}
void pa_rtpoll_set_timer_relative(pa_rtpoll *p, pa_usec_t usec) {
@ -550,8 +386,6 @@ void pa_rtpoll_set_timer_relative(pa_rtpoll *p, pa_usec_t usec) {
pa_rtclock_get(&p->next_elapse);
pa_timeval_add(&p->next_elapse, usec);
p->timer_enabled = TRUE;
update_timer(p);
}
void pa_rtpoll_set_timer_disabled(pa_rtpoll *p) {
@ -559,8 +393,6 @@ void pa_rtpoll_set_timer_disabled(pa_rtpoll *p) {
memset(&p->next_elapse, 0, sizeof(p->next_elapse));
p->timer_enabled = FALSE;
update_timer(p);
}
pa_rtpoll_item *pa_rtpoll_item_new(pa_rtpoll *p, pa_rtpoll_priority_t prio, unsigned n_fds) {

View file

@ -62,9 +62,6 @@ typedef enum pa_rtpoll_priority {
pa_rtpoll *pa_rtpoll_new(void);
void pa_rtpoll_free(pa_rtpoll *p);
/* Install the rtpoll in the current thread */
void pa_rtpoll_install(pa_rtpoll *p);
/* Sleep on the rtpoll until the time event, or any of the fd events
* is triggered. If "wait" is 0 we don't sleep but only update the
* struct pollfd. Returns negative on error, positive if the loop

View file

@ -1,131 +0,0 @@
/***
This file is part of PulseAudio.
Copyright 2004-2006 Lennart Poettering
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
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.1 of the
License, or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <signal.h>
#include <pulsecore/macro.h>
#include <pulsecore/flist.h>
#include <pulsecore/once.h>
#include <pulsecore/thread.h>
#include <pulsecore/core-util.h>
#include "rtsig.h"
#ifdef SIGRTMIN
static void _free_rtsig(void *p) {
pa_rtsig_put(PA_PTR_TO_INT(p));
}
PA_STATIC_FLIST_DECLARE(rtsig_flist, pa_make_power_of_two((unsigned) (SIGRTMAX-SIGRTMIN+1)), NULL);
PA_STATIC_TLS_DECLARE(rtsig_tls, _free_rtsig);
static pa_atomic_t rtsig_current = PA_ATOMIC_INIT(-1);
static int rtsig_start = -1, rtsig_end = -1;
int pa_rtsig_get(void) {
void *p;
int sig;
if ((p = pa_flist_pop(PA_STATIC_FLIST_GET(rtsig_flist))))
return PA_PTR_TO_INT(p);
sig = pa_atomic_dec(&rtsig_current);
pa_assert(sig <= SIGRTMAX);
pa_assert(sig <= rtsig_end);
if (sig < rtsig_start) {
pa_atomic_inc(&rtsig_current);
return -1;
}
return sig;
}
int pa_rtsig_get_for_thread(void) {
int sig;
void *p;
if ((p = PA_STATIC_TLS_GET(rtsig_tls)))
return PA_PTR_TO_INT(p);
if ((sig = pa_rtsig_get()) < 0)
return -1;
PA_STATIC_TLS_SET(rtsig_tls, PA_INT_TO_PTR(sig));
return sig;
}
void pa_rtsig_put(int sig) {
pa_assert(sig >= rtsig_start);
pa_assert(sig <= rtsig_end);
pa_assert_se(pa_flist_push(PA_STATIC_FLIST_GET(rtsig_flist), PA_INT_TO_PTR(sig)) >= 0);
}
void pa_rtsig_configure(int start, int end) {
int s;
sigset_t ss;
pa_assert(pa_atomic_load(&rtsig_current) == -1);
pa_assert(SIGRTMIN <= start);
pa_assert(start <= end);
pa_assert(end <= SIGRTMAX);
rtsig_start = start;
rtsig_end = end;
sigemptyset(&ss);
for (s = rtsig_start; s <= rtsig_end; s++)
pa_assert_se(sigaddset(&ss, s) == 0);
pa_assert(pthread_sigmask(SIG_BLOCK, &ss, NULL) == 0);
/* We allocate starting from the end */
pa_atomic_store(&rtsig_current, rtsig_end);
}
#else /* SIGRTMIN */
int pa_rtsig_get(void) {
return -1;
}
int pa_rtsig_get_for_thread(void) {
return -1;
}
void pa_rtsig_put(int sig) {
}
void pa_rtsig_configure(int start, int end) {
}
#endif /* SIGRTMIN */

View file

@ -1,39 +0,0 @@
#ifndef foopulsertsighfoo
#define foopulsertsighfoo
/***
This file is part of PulseAudio.
Copyright 2004-2006 Lennart Poettering
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.1 of the
License, or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
/* Return the next unused POSIX Realtime signals */
int pa_rtsig_get(void);
/* If not called before in the current thread, return the next unused
* rtsig, and install it in a TLS region and give it up automatically
* when the thread shuts down */
int pa_rtsig_get_for_thread(void);
/* Give an rtsig back. */
void pa_rtsig_put(int sig);
/* Block all RT signals */
void pa_rtsig_configure(int start, int end);
#endif

View file

@ -26,7 +26,6 @@
#include <pulsecore/log.h>
#include <pulsecore/rtpoll.h>
#include <pulsecore/rtsig.h>
static int before(pa_rtpoll_item *i) {
pa_log("before");
@ -47,10 +46,6 @@ int main(int argc, char *argv[]) {
pa_rtpoll_item *i, *w;
struct pollfd *pollfd;
#ifdef SIGRTMIN
pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX);
#endif
p = pa_rtpoll_new();
i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
@ -64,7 +59,6 @@ int main(int argc, char *argv[]) {
w = pa_rtpoll_item_new(p, PA_RTPOLL_NORMAL, 0);
pa_rtpoll_item_set_before_callback(w, worker);
pa_rtpoll_install(p);
pa_rtpoll_set_timer_relative(p, 10000000); /* 10 s */
pa_rtpoll_run(p, 1);