From dcae71faa813249ef652afcf1d35f2d7a0ca821e Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Mon, 29 Sep 2014 23:11:36 +0100 Subject: [PATCH] Move CPU instrumentation up into the main loop. --- dump1090.c | 15 +++++++++++++++ mode_s.c | 14 -------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/dump1090.c b/dump1090.c index 39898e3..0fb1fa6 100644 --- a/dump1090.c +++ b/dump1090.c @@ -888,6 +888,7 @@ int main(int argc, char **argv) { pthread_mutex_lock(&Modes.data_mutex); while (Modes.exit == 0) { + struct timespec cpu_start_time, cpu_end_time; if (Modes.iDataReady == 0) { pthread_cond_wait(&Modes.data_cond,&Modes.data_mutex); // This unlocks Modes.data_mutex, and waits for Modes.data_cond @@ -922,11 +923,25 @@ int main(int argc, char **argv) { // Process data after releasing the lock, so that the capturing // thread can read data while we perform computationally expensive // stuff at the same time. + + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_start_time); + if (Modes.oversample) detectModeS_oversample(Modes.magnitude, MODES_ASYNC_BUF_SAMPLES); else detectModeS(Modes.magnitude, MODES_ASYNC_BUF_SAMPLES); + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_end_time); + Modes.stat_cputime.tv_sec += (cpu_end_time.tv_sec - cpu_start_time.tv_sec); + Modes.stat_cputime.tv_nsec += (cpu_end_time.tv_nsec - cpu_start_time.tv_nsec); + if (Modes.stat_cputime.tv_nsec < 0) { + Modes.stat_cputime.tv_nsec += 1000000000L; + Modes.stat_cputime.tv_sec--; + } else if (Modes.stat_cputime.tv_nsec > 1000000000L) { + Modes.stat_cputime.tv_nsec -= 1000000000L; + Modes.stat_cputime.tv_sec++; + } + // Update the timestamp ready for the next block if (Modes.oversample) Modes.timestampBlk += (MODES_ASYNC_BUF_SAMPLES*5); diff --git a/mode_s.c b/mode_s.c index 9dcd7a2..20428b6 100644 --- a/mode_s.c +++ b/mode_s.c @@ -2082,9 +2082,6 @@ void detectModeS_oversample(uint16_t *m, uint32_t mlen) { unsigned char msg[MODES_LONG_MSG_BYTES], *pMsg; uint32_t j; - struct timespec cpu_start_time, cpu_end_time; - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_start_time); - memset(&mm, 0, sizeof(mm)); for (j = 0; j < mlen; j++) { @@ -2415,17 +2412,6 @@ void detectModeS_oversample(uint16_t *m, uint32_t mlen) { } } - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_end_time); - Modes.stat_cputime.tv_sec += (cpu_end_time.tv_sec - cpu_start_time.tv_sec); - Modes.stat_cputime.tv_nsec += (cpu_end_time.tv_nsec - cpu_start_time.tv_nsec); - if (Modes.stat_cputime.tv_nsec < 0) { - Modes.stat_cputime.tv_nsec += 1000000000L; - Modes.stat_cputime.tv_sec--; - } else if (Modes.stat_cputime.tv_nsec > 1000000000L) { - Modes.stat_cputime.tv_nsec -= 1000000000L; - Modes.stat_cputime.tv_sec++; - } - //Send any remaining partial raw buffers now if (Modes.rawOutUsed || Modes.beastOutUsed) {