diff --git a/conf/airframes/AGGIEAIR/aggieair_ark_quad_lisa_mx.xml b/conf/airframes/AGGIEAIR/aggieair_ark_quad_lisa_mx.xml index 320c7eeb7c..3086b7767d 100644 --- a/conf/airframes/AGGIEAIR/aggieair_ark_quad_lisa_mx.xml +++ b/conf/airframes/AGGIEAIR/aggieair_ark_quad_lisa_mx.xml @@ -35,6 +35,7 @@ + diff --git a/conf/airframes/ENAC/fixed-wing/apogee.xml b/conf/airframes/ENAC/fixed-wing/apogee.xml index f3674c2d2f..b0548d6957 100644 --- a/conf/airframes/ENAC/fixed-wing/apogee.xml +++ b/conf/airframes/ENAC/fixed-wing/apogee.xml @@ -39,7 +39,7 @@ - + diff --git a/conf/airframes/ENAC/fixed-wing/jp.xml b/conf/airframes/ENAC/fixed-wing/jp.xml index 1d66ef5196..ca73462a39 100644 --- a/conf/airframes/ENAC/fixed-wing/jp.xml +++ b/conf/airframes/ENAC/fixed-wing/jp.xml @@ -69,7 +69,7 @@ - + diff --git a/conf/modules/rtos_mon.xml b/conf/modules/rtos_mon.xml deleted file mode 100644 index 15dd2d2780..0000000000 --- a/conf/modules/rtos_mon.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - RTOS monitoring tool - - Reports: - - CPU load - - core and heap free memory - - number of threads, their load and free stack. - - Can be used with ChibiOS implementation - - -
- -
- - - - - - -
- diff --git a/conf/modules/sys_mon.xml b/conf/modules/sys_mon.xml index 88964bba1c..14e96a3198 100644 --- a/conf/modules/sys_mon.xml +++ b/conf/modules/sys_mon.xml @@ -5,8 +5,9 @@ System monitor. The sys_mon module gives you some information about the timing of the periodic tasks and a rough estimate of cpu load (averaged over 1 sec). +For systems with RTOS it also gives you stats about threads and memory usage. -The SYS_MON message contains the following information (all times are given in microseconds): +For bare-metal systems, the SYS_MON message contains the following information (all times are given in microseconds): - @b periodic_time : time between two calls of the modules_periodic_task (averaged over 1s) - @b periodic_time_min : minimum time between two calls of the modules_periodic_task() during the last second - @b periodic_time_max : maximum time between two calls of the modules_periodic_task() during the last second @@ -15,15 +16,22 @@ The SYS_MON message contains the following information (all times are given in m - @b periodic_cycle_max : maximum time it took to execute the main periodic functions during the last second - @b event_number : number of times the event loop was called during the last second - @b cpu_load : rough estimate of cpu load (averaged over 1 sec) - +- @b cpu_time : time in seconds since start-up So your periodic_time should be 1/MODULES_FREQUENCY, which should be the same as 1/PERIODIC_FREQUENCY The periodic_cycle_max should not be over the periodic_time, otherwise in at least one cycle it took longer to calculate everything and the next one was slightly delayed. - - The sys_mon module has to run at the full main frequency! - So either don't specify a main_freq parameter for the modules node or set your actual main frequency + + +For systems with RTOS, RTOS_MON message is sent instead and the following information are shown: +- @b nb_thread : number of threads running +- @b cpu_load : rough estimate of cpu load (averaged over 1 sec) +- @b core_free : Core free memory (bytes) +- @b heap_free : Heap free memory (bytes) +- @b cpu_time : time in seconds since start-up + +Again, the sys_mon module has to run at the full main frequency (so the reports are generated at 1 second intervals).
@@ -33,8 +41,23 @@ So either don't specify a main_freq parameter for the modules node or set your a + - + + # for ChibiOS arch include rtos_mon.c and rtos_mon_arch.c + ifeq ($(ARCH), chibios) + $(TARGET).srcs += $(SRC_MODULES)/core/rtos_mon.c + $(TARGET).srcs += $(SRC_ARCH)/modules/core/rtos_mon_arch.c + else + # for all other architecture use existing sys_mon.c + $(TARGET).srcs += $(SRC_MODULES)/core/sys_mon.c + endif + + + + + + diff --git a/sw/airborne/arch/chibios/modules/core/rtos_mon_arch.c b/sw/airborne/arch/chibios/modules/core/rtos_mon_arch.c index 5fce7d0872..78894bac17 100644 --- a/sw/airborne/arch/chibios/modules/core/rtos_mon_arch.c +++ b/sw/airborne/arch/chibios/modules/core/rtos_mon_arch.c @@ -24,11 +24,8 @@ * ChibiOS implementation */ -#include "modules/core/rtos_mon.h" -#include "modules/core/rtos_mon_arch.h" -#include "subsystems/datalink/downlink.h" +#include "modules/core/sys_mon_rtos.h" #include -#include #if !CH_DBG_THREADS_PROFILING #error CH_DBG_THREADS_PROFILING should be defined to TRUE to use this monitoring tool @@ -91,11 +88,9 @@ void rtos_mon_periodic_arch(void) // assume we call the counter once a second // so the difference in seconds is always one - // NOTE: not perfectly precise - // FIXME: add finer resolution than seconds? + // NOTE: not perfectly precise, +-5% on average so take it into consideration rtos_mon.cpu_load = (1 - (float)(idle_counter - last_idle_counter) / CH_CFG_ST_FREQUENCY) * 100; last_idle_counter = idle_counter; - } static uint16_t get_stack_free(const thread_t *tp) diff --git a/sw/airborne/arch/chibios/modules/core/rtos_mon_arch.h b/sw/airborne/arch/sim/modules/core/rtos_mon_arch.c similarity index 52% rename from sw/airborne/arch/chibios/modules/core/rtos_mon_arch.h rename to sw/airborne/arch/sim/modules/core/rtos_mon_arch.c index 88b3e06832..eff5e5b407 100644 --- a/sw/airborne/arch/chibios/modules/core/rtos_mon_arch.h +++ b/sw/airborne/arch/sim/modules/core/rtos_mon_arch.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Gautier Hattenberger + * Copyright (C) 2016 Michal Podhradsky * * This file is part of paparazzi * @@ -18,19 +19,32 @@ * . */ /** - * @file "arch/chibios/modules/core/rtos_mon_arch.h" - * @author Gautier Hattenberger - * RTOS monitoring tool - * ChibiOS implementation + * @file "arch/sim/modules/core/rtos_mon_arch.c" + * @author Michal Podhradsky + * System monitoring tool + * SIM implementation */ -#ifndef RTOS_MON_ARCH_H -#define RTOS_MON_ARCH_H +#include "modules/core/sys_mon_rtos.h" +#include /* atof */ +#include /* printf, fgets */ +#include -// Init function -extern void rtos_mon_init_arch(void); -// Periodic report -extern void rtos_mon_periodic_arch(void); +void rtos_mon_init_arch(void) {} -#endif +// Ask for CPU usage of the process +void rtos_mon_periodic_arch(void) +{ + char line[20]; + FILE *cmd = popen("ps -C simsitl -o %CPU", "r"); + + char *ret; + ret = fgets(line, sizeof(line), cmd); + ret = fgets(line, sizeof(line), cmd); + if (ret != NULL) { + double cpu = atof(ret); + rtos_mon.cpu_load = (uint8_t)cpu; + } + pclose(cmd); +} diff --git a/sw/airborne/modules/core/rtos_mon.c b/sw/airborne/modules/core/rtos_mon.c index b4eecb0bb7..78ab63474e 100644 --- a/sw/airborne/modules/core/rtos_mon.c +++ b/sw/airborne/modules/core/rtos_mon.c @@ -23,14 +23,13 @@ * RTOS monitoring tool */ -#include "modules/core/rtos_mon.h" -#include "modules/core/rtos_mon_arch.h" +#include "modules/core/sys_mon.h" +#include "modules/core/sys_mon_rtos.h" #include "subsystems/datalink/downlink.h" -#include struct rtos_monitoring rtos_mon; -void rtos_mon_init(void) +void init_sysmon(void) { // zero structure memset(&rtos_mon, 0, sizeof(struct rtos_monitoring)); @@ -41,7 +40,7 @@ void rtos_mon_init(void) // Periodic report of RTOS parameters // This function is actually arch dependent -void rtos_mon_periodic(void) +void periodic_report_sysmon(void) { // update struct rtos_mon_periodic_arch(); @@ -59,4 +58,6 @@ void rtos_mon_periodic(void) } +void periodic_sysmon(void) {} +void event_sysmon(void) {} diff --git a/sw/airborne/modules/core/sys_mon.c b/sw/airborne/modules/core/sys_mon.c index 71ab734bc6..d3b70c4419 100644 --- a/sw/airborne/modules/core/sys_mon.c +++ b/sw/airborne/modules/core/sys_mon.c @@ -19,10 +19,20 @@ * Boston, MA 02111-1307, USA. * */ +/** \file sys_mon.c + * + * System monitoring for bare metal targets + * return cpu load, average exec time, ... + */ #include "core/sys_mon.h" +#include "core/sys_mon_bare_metal.h" #include "mcu_periph/sys_time.h" +#include "mcu_periph/uart.h" +#include "pprzlink/messages.h" +#include "subsystems/datalink/downlink.h" + /** Global system monitor data (averaged over 1 sec) */ struct SysMon sys_mon; @@ -60,10 +70,6 @@ void init_sysmon(void) periodic_timer = 0; } -#include "mcu_periph/uart.h" -#include "pprzlink/messages.h" -#include "subsystems/datalink/downlink.h" - void periodic_report_sysmon(void) { /** Report system status at low frequency */ diff --git a/sw/airborne/modules/core/sys_mon.h b/sw/airborne/modules/core/sys_mon.h index 4122c80c31..750ca87e04 100644 --- a/sw/airborne/modules/core/sys_mon.h +++ b/sw/airborne/modules/core/sys_mon.h @@ -22,7 +22,7 @@ /** \file sys_mon.h * - * System monitoring + * System monitoring common header * return cpu load, average exec time, ... */ @@ -31,20 +31,6 @@ #include "std.h" -struct SysMon { - uint8_t cpu_load; - uint16_t periodic_time; ///< in usec - uint16_t periodic_time_min; ///< in usec - uint16_t periodic_time_max; ///< in usec - uint16_t periodic_cycle; ///< in usec - uint16_t periodic_cycle_min; ///< in usec - uint16_t periodic_cycle_max; ///< in usec - uint16_t event_number; - float cpu_time; // in secs since startup -}; - -extern struct SysMon sys_mon; - /** Init system monitoring */ void init_sysmon(void); diff --git a/sw/airborne/modules/core/sys_mon_bare_metal.h b/sw/airborne/modules/core/sys_mon_bare_metal.h new file mode 100644 index 0000000000..858fba8e3b --- /dev/null +++ b/sw/airborne/modules/core/sys_mon_bare_metal.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016 Gautier Hattenberger + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +/** \file sys_mon.h + * + * System monitoring + * return cpu load, average exec time, ... + */ + +#ifndef SYS_MON_BARE_METAL_H +#define SYS_MON_BARE_METAL_H + +#include "core/sys_mon.h" + +struct SysMon { + uint8_t cpu_load; + uint16_t periodic_time; ///< in usec + uint16_t periodic_time_min; ///< in usec + uint16_t periodic_time_max; ///< in usec + uint16_t periodic_cycle; ///< in usec + uint16_t periodic_cycle_min; ///< in usec + uint16_t periodic_cycle_max; ///< in usec + uint16_t event_number; + float cpu_time; // in secs since startup +}; + +extern struct SysMon sys_mon; + +#endif /* SYS_MON_BARE_METAL_H */ diff --git a/sw/airborne/modules/core/rtos_mon.h b/sw/airborne/modules/core/sys_mon_rtos.h similarity index 79% rename from sw/airborne/modules/core/rtos_mon.h rename to sw/airborne/modules/core/sys_mon_rtos.h index 3a236248aa..20a404b80a 100644 --- a/sw/airborne/modules/core/rtos_mon.h +++ b/sw/airborne/modules/core/sys_mon_rtos.h @@ -1,7 +1,7 @@ /* * Copyright (C) 2016 Gautier Hattenberger * - * This file is part of paparazzi + * This file is part of paparazzi. * * paparazzi is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,19 +14,22 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with paparazzi; see the file COPYING. If not, see - * . - */ -/** - * @file "modules/core/rtos_mon.h" - * @author Gautier Hattenberger - * RTOS monitoring tool + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * */ -#ifndef RTOS_MON_H -#define RTOS_MON_H +/** \file sys_mon_rtos.h + * + * System monitoring for RTOS targets + * return cpu load, average exec time, ... + */ -#include "std.h" +#ifndef SYS_MON_RTOS_H +#define SYS_MON_RTOS_H + +#include "core/sys_mon.h" // Maximum number of threads // The limit is related to the max size of the report message @@ -55,9 +58,8 @@ struct rtos_monitoring { extern struct rtos_monitoring rtos_mon; // Init function -extern void rtos_mon_init(void); +extern void rtos_mon_init_arch(void); // Periodic report -extern void rtos_mon_periodic(void); - -#endif +extern void rtos_mon_periodic_arch(void); +#endif /* SYS_MON_RTOS_H */