load_mon move from NuttX LPWORK to PX4 work queue lp_default

This commit is contained in:
Daniel Agar 2019-05-28 09:40:36 -04:00 committed by GitHub
parent 5d6cc7d033
commit 6627c60e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 25 deletions

View File

@ -38,5 +38,6 @@ px4_add_module(
SRCS SRCS
load_mon.cpp load_mon.cpp
DEPENDS DEPENDS
px4_work_queue
) )

View File

@ -45,7 +45,7 @@
#include <px4_defines.h> #include <px4_defines.h>
#include <px4_module.h> #include <px4_module.h>
#include <px4_module_params.h> #include <px4_module_params.h>
#include <px4_workqueue.h> #include <px4_work_queue/ScheduledWorkItem.hpp>
#include <systemlib/cpuload.h> #include <systemlib/cpuload.h>
#include <uORB/topics/cpuload.h> #include <uORB/topics/cpuload.h>
#include <uORB/topics/task_stack_info.h> #include <uORB/topics/task_stack_info.h>
@ -68,7 +68,7 @@ extern "C" __EXPORT int load_mon_main(int argc, char *argv[]);
// Run it at 1 Hz. // Run it at 1 Hz.
const unsigned LOAD_MON_INTERVAL_US = 1000000; const unsigned LOAD_MON_INTERVAL_US = 1000000;
class LoadMon : public ModuleBase<LoadMon>, public ModuleParams class LoadMon : public ModuleBase<LoadMon>, public ModuleParams, public px4::ScheduledWorkItem
{ {
public: public:
LoadMon(); LoadMon();
@ -88,12 +88,11 @@ public:
/** @see ModuleBase::print_status() */ /** @see ModuleBase::print_status() */
int print_status() override; int print_status() override;
/** Trampoline for the work queue. */ void start();
static void cycle_trampoline(void *arg);
private: private:
/** Do a compute and schedule the next cycle. */ /** Do a compute and schedule the next cycle. */
void _cycle(); void Run() override;
/** Do a calculation of the CPU load and publish it. */ /** Do a calculation of the CPU load and publish it. */
void _cpuload(); void _cpuload();
@ -113,8 +112,6 @@ private:
(ParamBool<px4::params::SYS_STCK_EN>) _param_sys_stck_en (ParamBool<px4::params::SYS_STCK_EN>) _param_sys_stck_en
) )
work_s _work{};
orb_advert_t _cpuload_pub{nullptr}; orb_advert_t _cpuload_pub{nullptr};
hrt_abstime _last_idle_time{0}; hrt_abstime _last_idle_time{0};
@ -125,12 +122,15 @@ private:
LoadMon::LoadMon() : LoadMon::LoadMon() :
ModuleParams(nullptr), ModuleParams(nullptr),
ScheduledWorkItem(px4::wq_configurations::lp_default),
_stack_perf(perf_alloc(PC_ELAPSED, "stack_check")) _stack_perf(perf_alloc(PC_ELAPSED, "stack_check"))
{ {
} }
LoadMon::~LoadMon() LoadMon::~LoadMon()
{ {
ScheduleClear();
perf_free(_stack_perf); perf_free(_stack_perf);
} }
@ -143,28 +143,22 @@ int LoadMon::task_spawn(int argc, char *argv[])
return -1; return -1;
} }
/* Schedule a cycle to start things. */
int ret = work_queue(LPWORK, &obj->_work, (worker_t)&LoadMon::cycle_trampoline, obj, 0);
if (ret < 0) {
delete obj;
return ret;
}
_object.store(obj); _object.store(obj);
_task_id = task_id_is_work_queue; _task_id = task_id_is_work_queue;
/* Schedule a cycle to start things. */
obj->start();
return 0; return 0;
} }
void void
LoadMon::cycle_trampoline(void *arg) LoadMon::start()
{ {
LoadMon *dev = reinterpret_cast<LoadMon *>(arg); ScheduleOnInterval(LOAD_MON_INTERVAL_US);
dev->_cycle();
} }
void LoadMon::_cycle() void LoadMon::Run()
{ {
_cpuload(); _cpuload();
@ -176,11 +170,8 @@ void LoadMon::_cycle()
#endif #endif
if (!should_exit()) { if (should_exit()) {
work_queue(LPWORK, &_work, (worker_t)&LoadMon::cycle_trampoline, this, ScheduleClear();
USEC2TICK(LOAD_MON_INTERVAL_US));
} else {
exit_and_cleanup(); exit_and_cleanup();
} }
} }