diff options
| author | Jafar Al-Gharaibeh <jafar@atcorp.com> | 2022-03-01 12:48:47 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-01 12:48:47 -0600 |
| commit | ec616c97bab6a549bec36f6bb295ae214dc69a44 (patch) | |
| tree | e83ac2f3745cc84b831ca30e7065f155dc97e628 /lib/thread.c | |
| parent | 33fec964f724ea14b9e2136d98dafb77283ef5b2 (diff) | |
| parent | 4e2839de649c7981d3ee742a0b5520ea96ffa872 (diff) | |
Merge pull request #10697 from donaldsharp/free_bsd_clock_gettime
lib: Fix FreeBSD clock_gettime(CLOCK_THREAD_CPUTIME_ID,..) going backā¦
Diffstat (limited to 'lib/thread.c')
| -rw-r--r-- | lib/thread.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/thread.c b/lib/thread.c index 6d91ca497b..90074b3d89 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1884,6 +1884,27 @@ unsigned long thread_consumed_time(RUSAGE_T *now, RUSAGE_T *start, unsigned long *cputime) { #ifdef HAVE_CLOCK_THREAD_CPUTIME_ID + +#ifdef __FreeBSD__ + /* + * FreeBSD appears to have an issue when calling clock_gettime + * with CLOCK_THREAD_CPUTIME_ID really close to each other + * occassionally the now time will be before the start time. + * This is not good and FRR is ending up with CPU HOG's + * when the subtraction wraps to very large numbers + * + * What we are going to do here is cheat a little bit + * and notice that this is a problem and just correct + * it so that it is impossible to happen + */ + if (start->cpu.tv_sec == now->cpu.tv_sec && + start->cpu.tv_nsec > now->cpu.tv_nsec) + now->cpu.tv_nsec = start->cpu.tv_nsec + 1; + else if (start->cpu.tv_sec > now->cpu.tv_sec) { + now->cpu.tv_sec = start->cpu.tv_sec; + now->cpu.tv_nsec = start->cpu.tv_nsec + 1; + } +#endif *cputime = (now->cpu.tv_sec - start->cpu.tv_sec) * TIMER_SECOND_MICRO + (now->cpu.tv_nsec - start->cpu.tv_nsec) / 1000; #else |
