From: Andre Noll Date: Sat, 13 Aug 2011 10:17:51 +0000 (+0200) Subject: Merge branch 't/timing_improvements' X-Git-Tag: v0.4.8~10 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=5ff2b0b3a6f9242033c436fb8272245f5594dd8c;hp=d49cd9a91015766cb19d7d43bb04048265925fe5 Merge branch 't/timing_improvements' --- diff --git a/NEWS b/NEWS index f76a6e97..49747ccb 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,7 @@ are the highlights of this release. - Compiles cleanly also with llvm/clang. - Corrupt mp3 files are handled more gracefully. - sched: Optimized zero timeouts. + - vss timeout cleanups. -------------------------------------- 0.4.7 (2011-06-01) "infinite rollback" diff --git a/alsa_write.c b/alsa_write.c index 6850221a..34a71f9b 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -150,10 +150,14 @@ static void alsa_write_pre_select(struct sched *s, struct task *t) if (ret == 0) return; - if (!pad) - return sched_min_delay(s); - if (ret < 0) - return sched_request_barrier_or_min_delay(&pad->drain_barrier, s); + if (!pad) { + sched_min_delay(s); + return; + } + if (ret < 0) { + sched_request_barrier_or_min_delay(&pad->drain_barrier, s); + return; + } /* * Data is available to be written to the alsa handle. Compute number * of milliseconds until next buffer underrun would occur. diff --git a/sched.c b/sched.c index ca365f17..385dde61 100644 --- a/sched.c +++ b/sched.c @@ -311,17 +311,19 @@ void sched_request_timeout_ms(long unsigned ms, struct sched *s) * \param barrier Absolute time before select() should return. * \param s Pointer to the scheduler struct. * - * If \a barrier is in the past, this function does nothing. + * \return If \a barrier is in the past, this function does nothing and returns + * zero. Otherwise it returns one. * * \sa sched_request_barrier_or_min_delay(). */ -void sched_request_barrier(struct timeval *barrier, struct sched *s) +int sched_request_barrier(struct timeval *barrier, struct sched *s) { struct timeval diff; if (tv_diff(now, barrier, &diff) > 0) - return; + return 0; sched_request_timeout(&diff, s); + return 1; } /** @@ -330,15 +332,19 @@ void sched_request_barrier(struct timeval *barrier, struct sched *s) * \param barrier Absolute time before select() should return. * \param s Pointer to the scheduler struct. * - * If \a barrier is in the past, this function requests a minimal timeout. + * If \a barrier is in the past, this function requests a minimal timeout and + * returns zero. Otherwise it returns one. * * \sa sched_min_delay(), sched_request_barrier(). */ -void sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s) +int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s) { struct timeval diff; - if (tv_diff(now, barrier, &diff) > 0) - return sched_min_delay(s); + if (tv_diff(now, barrier, &diff) > 0) { + sched_min_delay(s); + return 0; + } sched_request_timeout(&diff, s); + return 1; } diff --git a/sched.h b/sched.h index e018c2fe..ea9578f7 100644 --- a/sched.h +++ b/sched.h @@ -81,5 +81,5 @@ void sched_shutdown(void); void sched_min_delay(struct sched *s); void sched_request_timeout(struct timeval *to, struct sched *s); void sched_request_timeout_ms(long unsigned ms, struct sched *s); -void sched_request_barrier(struct timeval *barrier, struct sched *s); -void sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s); +int sched_request_barrier(struct timeval *barrier, struct sched *s); +int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s); diff --git a/vss.c b/vss.c index 2068563c..b9afc8ed 100644 --- a/vss.c +++ b/vss.c @@ -688,26 +688,6 @@ static int next_slice_is_due(struct fec_client *fc, struct timeval *diff) return ret < 0? 1 : 0; } -static void compute_slice_timeout(struct timeval *timeout) -{ - struct fec_client *fc; - - list_for_each_entry(fc, &fec_client_list, node) { - struct timeval diff; - - if (fc->state != FEC_STATE_READY_TO_RUN) - continue; - if (next_slice_is_due(fc, &diff)) { - timeout->tv_sec = 0; - timeout->tv_usec = 0; - return; - } - /* timeout = min(timeout, diff) */ - if (tv_diff(&diff, timeout, NULL) < 0) - *timeout = diff; - } -} - static void set_eof_barrier(struct vss_task *vsst) { struct fec_client *fc; @@ -798,42 +778,38 @@ static int chk_barrier(const char *bname, const struct timeval *barrier, return -1; } -/* - * != NULL: timeout for next chunk - * NULL: nothing to do - */ -static struct timeval *vss_compute_timeout(struct vss_task *vsst) +static void vss_compute_timeout(struct sched *s, struct vss_task *vsst) { - static struct timeval the_timeout; - struct timeval next_chunk; - - if (vss_next() && vsst->map) { - /* only sleep a bit, nec*/ - the_timeout.tv_sec = 0; - the_timeout.tv_usec = 100; - return &the_timeout; - } - if (chk_barrier("autoplay_delay", &vsst->autoplay_barrier, - &the_timeout, 1) < 0) - return &the_timeout; - if (chk_barrier("eof", &vsst->eof_barrier, &the_timeout, 1) < 0) - return &the_timeout; - if (chk_barrier("data send", &vsst->data_send_barrier, - &the_timeout, 1) < 0) - return &the_timeout; + struct timeval tv; + struct fec_client *fc; + if (!vss_playing() || !vsst->map) - return NULL; + return; + if (vss_next() && vsst->map) /* only sleep a bit, nec*/ + return sched_request_timeout_ms(100, s); + + /* Each of these barriers must have passed until we may proceed */ + if (sched_request_barrier(&vsst->autoplay_barrier, s) == 1) + return; + if (sched_request_barrier(&vsst->eof_barrier, s) == 1) + return; + if (sched_request_barrier(&vsst->data_send_barrier, s) == 1) + return; + /* + * Compute the select timeout as the minimal time until the next + * chunk/slice is due for any client. + */ compute_chunk_time(mmd->chunks_sent, &mmd->afd.afhi.chunk_tv, - &mmd->stream_start, &next_chunk); - if (chk_barrier("chunk", &next_chunk, &the_timeout, 0) >= 0) { - /* chunk is due or bof */ - the_timeout.tv_sec = 0; - the_timeout.tv_usec = 0; - return &the_timeout; + &mmd->stream_start, &tv); + if (sched_request_barrier_or_min_delay(&tv, s) == 0) + return; + list_for_each_entry(fc, &fec_client_list, node) { + if (fc->state != FEC_STATE_READY_TO_RUN) + continue; + if (next_slice_is_due(fc, &tv)) + return sched_min_delay(s); + sched_request_timeout(&tv, s); } - /* compute min of current timeout and next slice time */ - compute_slice_timeout(&the_timeout); - return &the_timeout; } static void vss_eof(struct vss_task *vsst) @@ -902,7 +878,6 @@ static void set_mmd_offset(void) static void vss_pre_select(struct sched *s, struct task *t) { int i; - struct timeval *tv; struct vss_task *vsst = container_of(t, struct vss_task, task); if (!vsst->map || vss_next() || vss_paused() || vss_repos()) { @@ -940,9 +915,7 @@ static void vss_pre_select(struct sched *s, struct task *t) continue; senders[i].pre_select(&s->max_fileno, &s->rfds, &s->wfds); } - tv = vss_compute_timeout(vsst); - if (tv) - sched_request_timeout(tv, s); + vss_compute_timeout(s, vsst); } static int recv_afs_msg(int afs_socket, int *fd, uint32_t *code, uint32_t *data)