From 8f62c98f904833033bd4684fa3ae6b516470da75 Mon Sep 17 00:00:00 2001 From: paulo Date: Mon, 18 Jan 2010 18:00:34 +0000 Subject: Nexus to handle old threads and process the bgp local events. Deals with having 1 or multiple nexus (and pthreads). --- lib/thread.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'lib/thread.c') diff --git a/lib/thread.c b/lib/thread.c index 773e9338..62f9669f 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1028,6 +1028,61 @@ thread_fetch (struct thread_master *m, struct thread *fetch) } } + +/* Fetch next ready thread. Events and timeouts only. No I/O. + * If nothing to do returns NULL and sets event_wait to recommended time + * to be called again. */ +struct thread * +thread_fetch_event (struct thread_master *m, struct thread *fetch, + qtime_mono_t *event_wait) +{ + struct thread *thread; + struct timeval timer_val; + struct timeval timer_val_bg; + struct timeval *timer_wait; + struct timeval *timer_wait_bg; + + /* Normal event are the next highest priority. */ + if ((thread = thread_trim_head (&m->event)) != NULL) + return thread_run (m, thread, fetch); + + /* If there are any ready threads from previous scheduler runs, + * process top of them. + */ + if ((thread = thread_trim_head (&m->ready)) != NULL) + return thread_run (m, thread, fetch); + + /* Calculate select wait timer if nothing else to do */ + quagga_get_relative (NULL); + timer_wait = thread_timer_wait (&m->timer, &timer_val); + timer_wait_bg = thread_timer_wait (&m->background, &timer_val_bg); + + if (timer_wait_bg && + (!timer_wait || (timeval_cmp (*timer_wait, *timer_wait_bg) > 0))) + timer_wait = timer_wait_bg; + + /* When is the next timer due ? */ + if (timer_wait) + { + *event_wait = timeval2qtime(timer_wait); + return NULL; + } + + /* Check foreground timers. Historically, they have had higher + priority than I/O threads, so let's push them onto the ready + list in front of the I/O threads. */ + quagga_get_relative (NULL); + thread_timer_process (&m->timer, &relative_time); + + /* Background timer/events, lowest priority */ + thread_timer_process (&m->background, &relative_time); + + if ((thread = thread_trim_head (&m->ready)) != NULL) + return thread_run (m, thread, fetch); + + return NULL; +} + unsigned long thread_consumed_time (RUSAGE_T *now, RUSAGE_T *start, unsigned long *cputime) { -- cgit v1.2.3 From e0f9836737c9e91b8fa4c72b45d1fdc286e2d811 Mon Sep 17 00:00:00 2001 From: paulo Date: Mon, 18 Jan 2010 18:29:24 +0000 Subject: Merged with GMCH changes --- lib/thread.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'lib/thread.c') diff --git a/lib/thread.c b/lib/thread.c index 62f9669f..09a082cf 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1052,22 +1052,6 @@ thread_fetch_event (struct thread_master *m, struct thread *fetch, if ((thread = thread_trim_head (&m->ready)) != NULL) return thread_run (m, thread, fetch); - /* Calculate select wait timer if nothing else to do */ - quagga_get_relative (NULL); - timer_wait = thread_timer_wait (&m->timer, &timer_val); - timer_wait_bg = thread_timer_wait (&m->background, &timer_val_bg); - - if (timer_wait_bg && - (!timer_wait || (timeval_cmp (*timer_wait, *timer_wait_bg) > 0))) - timer_wait = timer_wait_bg; - - /* When is the next timer due ? */ - if (timer_wait) - { - *event_wait = timeval2qtime(timer_wait); - return NULL; - } - /* Check foreground timers. Historically, they have had higher priority than I/O threads, so let's push them onto the ready list in front of the I/O threads. */ @@ -1080,6 +1064,19 @@ thread_fetch_event (struct thread_master *m, struct thread *fetch, if ((thread = thread_trim_head (&m->ready)) != NULL) return thread_run (m, thread, fetch); + /* Calculate select wait timer if nothing else to do */ + timer_wait = thread_timer_wait (&m->timer, &timer_val); + timer_wait_bg = thread_timer_wait (&m->background, &timer_val_bg); + + if (timer_wait_bg && + (!timer_wait || (timeval_cmp (*timer_wait, *timer_wait_bg) > 0))) + timer_wait = timer_wait_bg; + + /* When is the next timer due ? */ + *event_wait = (timer_wait != NULL) + ? timeval2qtime(timer_wait) + : 0; + return NULL; } -- cgit v1.2.3