Skip to content

Conversation

@NeroBurner
Copy link
Contributor

No need to implement SystemMonitor<FreeRtosMonitor> if the variable
configUSE_TRACE_FACILITY is set to 1. Otherwise implement the
DummyMonitor class.

@JF002
Copy link
Collaborator

JF002 commented Feb 19, 2022

The definition of the template SystemMonitor<FreeRtosMonitor> should not cause any issue if it's not instantiated by the code that is being built. Did you get any error while building the simulator?

@JF002 JF002 added this to the 1.9.0 milestone Feb 19, 2022
@NeroBurner
Copy link
Contributor Author

yes, without the commit I'd have to implement/stub xPortGetFreeHeapSize() for a logger, that isn't used in the simulator

[build] /usr/bin/c++ -DLV_CONF_INCLUDE_SIMPLE -I/home/nero/repos/pinetime/InfiniSim/sim -I/home/nero/repos/pinetime/InfiniSim/sim/libraries/log -I/home/nero/repos/pinetime/InfiniSim/sim/libraries/timer -I/home/nero/repos/pinetime/InfiniSim/sim/nrfx -I/home/nero/repos/pinetime/InfiniSim/sim/nrfx/hal -I/home/nero/repos/pinetime/InfiniSim -I/home/nero/repos/pinetime/InfiniSim/InfiniTime/src/libs -I/home/nero/repos/pinetime/InfiniSim/lv_drivers -I/home/nero/repos/pinetime/InfiniSim/InfiniTime/src -I/home/nero/repos/pinetime/InfiniSim/build -isystem /home/nero/repos/pinetime/InfiniSim/InfiniTime/src/libs/date/includes -isystem /usr/include/SDL2 -g -std=c++17 -MD -MT CMakeFiles/infinisim.dir/sim/components/battery/BatteryController.cpp.o -MF CMakeFiles/infinisim.dir/sim/components/battery/BatteryController.cpp.o.d -o CMakeFiles/infinisim.dir/sim/components/battery/BatteryController.cpp.o -c /home/nero/repos/pinetime/InfiniSim/sim/components/battery/BatteryController.cpp
[build] In file included from /home/nero/repos/pinetime/InfiniSim/InfiniTime/src/systemtask/SystemMonitor.h:4,
[build]                  from /home/nero/repos/pinetime/InfiniSim/InfiniTime/src/systemtask/SystemTask.h:15,
[build]                  from /home/nero/repos/pinetime/InfiniSim/sim/components/battery/BatteryController.h:3,
[build]                  from /home/nero/repos/pinetime/InfiniSim/sim/components/battery/BatteryController.cpp:1:
[build] /home/nero/repos/pinetime/InfiniSim/InfiniTime/src/systemtask/SystemMonitor.h: In member function ‘void Pinetime::System::SystemMonitor<Pinetime::System::FreeRtosMonitor>::Process() const’:
[build] /home/nero/repos/pinetime/InfiniSim/InfiniTime/src/systemtask/SystemMonitor.h:26:83: error: ‘xPortGetFreeHeapSize’ was not declared in this scope
[build]    26 |           NRF_LOG_INFO("---------------------------------------\nFree heap : %d", xPortGetFreeHeapSize());
[build]       |                                                                                   ^~~~~~~~~~~~~~~~~~~~
[build] /home/nero/repos/pinetime/InfiniSim/sim/libraries/log/nrf_log.h:56:66: note: in definition of macro ‘NRF_LOG_INFO’
[build]    56 | #define NRF_LOG_INFO(...)         do {printf("info:  "); printf( __VA_ARGS__ ); printf("\n"); } while(false);
[build]       |                                                                  ^~~~~~~~~~~

The only place where this logger is instantiated is in SystemTask.h with the following statement:

#if configUSE_TRACE_FACILITY == 1
      SystemMonitor<FreeRtosMonitor> monitor;
#else
      SystemMonitor<DummyMonitor> monitor;
#endif

One thing I just noticed is that we could get rid of the templated System-Monitor class and use just a SystemMonitor monitor; in SystemTask.h if we use the configUSE_TRACE_FACILITY macro to decide the implementation of the monitor.

If this restructure isn't wanted I'll have to stub the xPortGetFreeHeapSize() in InfiniSim. Your choice, we got all the freedom to choose :)

@JF002
Copy link
Collaborator

JF002 commented Feb 20, 2022

Ok, I understand :) The goal with the template class was to avoid using #ifdef : both versions exist in the code but only 1 will be linked in the final binary. Well I failed at that goal as the #ifdef is still needed in systemtask.h any way...

On the long term, I would like to find a better design to handle multiple platforms but for now, I think your first solution will be the best :

One thing I just noticed is that we could get rid of the templated System-Monitor class and use just a SystemMonitor monitor; in SystemTask.h if we use the configUSE_TRACE_FACILITY macro to decide the implementation of the monitor.

@NeroBurner NeroBurner force-pushed the SystemMonitor_conditional_compile branch from 9dd6da2 to c4981b0 Compare February 20, 2022 13:55
@NeroBurner
Copy link
Contributor Author

NeroBurner commented Feb 20, 2022

With the restructure of SystemMonitor.h some missing nrf_log.h includes were detected which I've fixed in Add missing nrf_log.h includes shadowed by SystemMonitor.h

Some components were missing a nrf_log.h include. This missing
include was accidentally provided by the SystemMonitor.h header, which
was included by Systemtask.h

Should I create a separate PR for these nrf_log.h fixes?

And I've split the SystemMonitor into a h and cpp pair, as the implementation of a non-template function shouldn't be in the header. As this could cause errors with the one-definition rule (not here, but generally)

Furthermore I've changed the Process() function to be a non-const function, as it modifies a member-variable, and thus shouldn't be marked as const

@NeroBurner NeroBurner force-pushed the SystemMonitor_conditional_compile branch from c4981b0 to feeca6b Compare February 24, 2022 17:45
@NeroBurner
Copy link
Contributor Author

rebased on current develop branch 0e2b27d

NeroBurner added a commit to InfiniTimeOrg/InfiniSim that referenced this pull request Feb 27, 2022
InfiniTimeOrg/InfiniTime#967 splits
SystemMonitor.h into a h and cpp file. Add the cpp file to the infinisim
target.
NeroBurner added a commit to InfiniTimeOrg/InfiniSim that referenced this pull request Mar 2, 2022
InfiniTimeOrg/InfiniTime#967 splits
SystemMonitor.h into a h and cpp file. Add the cpp file to the infinisim
target.
Some components were missing a `nrf_log.h` include. This missing
include was accidentally provided by the SystemMonitor.h header, which
was included by Systemtask.h
Split SystemMonitor into h and cpp file and move the logging code of the
`Process` function into the cpp file.

Depending of the `configUSE_TRACE_FACILITY` define from
`src/FreeRTOSConfig.h` create either a "FreeRtosMonitor" or a
"DummyMonitor".

Make the `Process()` function non-const, as the FreeRtosMonitor changes
the member variable `lastTick`.

In `SystemTask.h` we then only need to use `SystemMonitor`, without
knowledge of the `configUSE_TRACE_FACILITY` define.
@NeroBurner NeroBurner force-pushed the SystemMonitor_conditional_compile branch from feeca6b to 9131722 Compare March 7, 2022 20:37
NeroBurner added a commit to InfiniTimeOrg/InfiniSim that referenced this pull request Mar 7, 2022
InfiniTimeOrg/InfiniTime#967 splits
SystemMonitor.h into a h and cpp file. Add the cpp file to the infinisim
target.
NeroBurner added a commit to InfiniTimeOrg/InfiniSim that referenced this pull request Mar 7, 2022
InfiniTimeOrg/InfiniTime#967 splits
SystemMonitor.h into a h and cpp file. Add the cpp file to the infinisim
target.
@JF002 JF002 merged commit 187d99c into InfiniTimeOrg:develop Mar 8, 2022
@NeroBurner NeroBurner deleted the SystemMonitor_conditional_compile branch March 8, 2022 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants