From 686041f8e7490e2caa0582d9fa3d79d2ff07ab2a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Jan 2017 07:12:22 -0600 Subject: [PATCH] CPU load: Correct computation of the nominal period to use when the source is a oneshot timer. --- sched/Kconfig | 4 ++-- sched/sched/sched_cpuload_oneshot.c | 30 +++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/sched/Kconfig b/sched/Kconfig index 0c966337ba..1053722e90 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -654,8 +654,8 @@ config CPULOAD_ONESHOT_ENTROPY Where - CPULOAD_ONESHOT_NOMINAL is CONFIG_SCHED_CPULOAD_TICKSPERSEC in - units of microseconds. + CPULOAD_ONESHOT_NOMINAL is the nominal sample internval implied + by CONFIG_SCHED_CPULOAD_TICKSPERSEC in units of microseconds. CPULOAD_ONESHOT_ENTROPY is (1 << CONFIG_CPULOAD_ONESHOT_ENTROPY), and 'error' is an error value that is retained from interval to diff --git a/sched/sched/sched_cpuload_oneshot.c b/sched/sched/sched_cpuload_oneshot.c index b11193b242..e3076bbfb6 100644 --- a/sched/sched/sched_cpuload_oneshot.c +++ b/sched/sched/sched_cpuload_oneshot.c @@ -1,7 +1,7 @@ /**************************************************************************** * sched/sched/sched_cpuload_oneshot.c * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -56,25 +56,43 @@ * Pre-processor Definitions ****************************************************************************/ +/* Configuration ************************************************************/ + #if !defined(CONFIG_SCHED_CPULOAD) || !defined(CONFIG_SCHED_CPULOAD_EXTCLK) # error CONFIG_SCHED_CPULOAD and CONFIG_SCHED_CPULOAD_EXTCLK must be defined #endif +/* CONFIG_SCHED_CPULOAD_TICKSPERSEC is the frequency of the external clock + * source. + */ + #ifndef CONFIG_SCHED_CPULOAD_TICKSPERSEC # error CONFIG_SCHED_CPULOAD_TICKSPERSEC not defined #endif -#define CPULOAD_ONESHOT_NOMINAL (CONFIG_SCHED_CPULOAD_TICKSPERSEC * 1000) - -#if CPULOAD_ONESHOT_NOMINAL < 1 || CPULOAD_ONESHOT_NOMINAL > 0x7fffffff -# error CPULOAD_ONESHOT_NOMINAL is out of range -#endif +/* CONFIG_CPULOAD_ONESHOT_ENTROPY determines that amount of random "jitter" + * that will be added to the nominal sample interval. Specified as a number + * bits. + */ #ifndef CONFIG_CPULOAD_ONESHOT_ENTROPY # warning CONFIG_CPULOAD_ONESHOT_ENTROPY not defined # define CONFIG_CPULOAD_ONESHOT_ENTROPY 0 #endif +/* Calculate the nomimal sample interval in microseconds: + * + * nominal = (1,000,000 usec/sec) / Frequency cycles/sec) = Period usec/cycle + */ + +#define CPULOAD_ONESHOT_NOMINAL (1000000 / CONFIG_SCHED_CPULOAD_TICKSPERSEC) + +#if CPULOAD_ONESHOT_NOMINAL < 1 || CPULOAD_ONESHOT_NOMINAL > 0x7fffffff +# error CPULOAD_ONESHOT_NOMINAL is out of range +#endif + +/* Convert the entropy from number of bits to a numeric value */ + #define CPULOAD_ONESHOT_ENTROPY (1 << CONFIG_CPULOAD_ONESHOT_ENTROPY) #if CPULOAD_ONESHOT_NOMINAL < CPULOAD_ONESHOT_ENTROPY