当前位置:网站首页>Px4 module design part 13: workqueue design
Px4 module design part 13: workqueue design
2022-07-27 22:52:00 【lida2003】
PX4 Module design 13 :WorkQueue Design
1. WorkQueue start-up
WorkQueue yes PX4 Flight control software Common( public ) Components , By function px4::WorkQueueManagerStart It started , Please refer to PX4 Module design ten :PX4 The boot process .
board_app_initialize
└──> px4_platform_init
└──> px4::WorkQueueManagerStart
notes 1:Nuttx The system is supported WorkQueue Of . however PX4 stay common( public ) The component layer implements a similar WorkQueue The function of , Instead of directly using Nuttx Systematic WorkQueue. It is preliminarily suspected that this result was caused by historical time .
notes 2:Nuttx The first version is in 2007 Released in , Start supporting 2-3 individual MCU((i.e. 8051 and ARM7);PX4-AutoPilot yes 2009 The project started in ,2013 year ETH Zurich ( Federal Polytechnic University of Zurich ) Computer vision and geometry Laboratory Lorenz Meier , Released the first generation of experimental version : Dual flight control processors PX4FMU/PX4IO Hardware .
So to sum up , For the following reasons
1) Its historical reasons ,PX4-AutoPilot Common components of WorkQueue Independent implementation ;
2) Flight control mode adopts C++ Class inheritance for development and management ;
3)uORB Message component adopts C++ Class to manage ;
4)HRT High precision timing acquisition trigger management ;
WorkQueue The overall management of the company combines the above historical reasons , take C/C++ Design , class , Inherit , And kernel mode / User mode . The overall feeling is extremely complex , This part of the content is really not flattering !!!(—AnyWay, Historical reasons !!!—)
2. WorkQueue Interface
2.1 Basic interface
The most basic WorkQueue The management interface is not responsible , Mainly Start/Stop/Status Three .
int WorkQueueManagerStart() //WorkQueue Manage startup tasks
int WorkQueueManagerStop() // As a basic component, it basically does not need Stop, At least there is no Stop The place of .
int WorkQueueManagerStatus() //WorkQueue State query
2.2 Auxiliary interface
const wq_config_t & device_bus_to_wq(uint32_t device_id_int) //device_bus turn wq To configure
const wq_config_t & serial_port_to_wq(const char *serial) //serial_port turn wq To configure
const wq_config_t & ins_instance_to_wq(uint8_t instance) //instance turn wq To configure
static WorkQueue * FindWorkQueueByName(const char *name) // Check by name WorkQueue
WorkQueue * WorkQueueFindOrCreate(const wq_config_t &new_wq) // Find or create WorkQueue
2.3 WorkQueue Task function
WorkQueue At present, it is in support of Flat and Protected Build Two compilation modes , The most significant difference between different compilation modes is Flat Build Use pthread_create Set up tasks , and Protected Build Use px4_task_spawn_cmd Set up tasks .
2.3.1 Flat Build
static void * WorkQueueRunner(void *context)
2.3.2 Protected Build
The internal implementation of this function will call again Flat Build Function of ( At this time, the running code space will be in kernel mode ).
inline static int WorkQueueRunner(int argc, char *argv[])
2.4 Key interface analysis
2.4.1 WorkQueueManagerStart
WorkQueueManagerStart
├──> <_wq_manager_should_exit.load() && (_wq_manager_create_queue == nullptr)>
│ ├──> _wq_manager_should_exit.store(false);
│ ├──> int task_id = px4_task_spawn_cmd("wq:manager",SCHED_DEFAULT,SCHED_PRIORITY_MAX,PX4_STACK_ADJUSTED(1280),(px4_main_t)&WorkQueueManagerRun,nullptr);
│ └──> <task_id < 0>
│ ├──> _wq_manager_should_exit.store(true);
│ ├──> PX4_ERR("task start failed (%i)", task_id);
│ └──> return -errno;
├──> else
│ ├──> PX4_WARN("already running");
│ └──> return PX4_ERROR;
└──> return PX4_OK;
2.4.2 WorkQueueManagerRun
WorkQueueManagerRun
├──> _wq_manager_wqs_list = new BlockingList<WorkQueue *>();
├──> _wq_manager_create_queue = new BlockingQueue<const wq_config_t *, 1>();
├──> <while (!_wq_manager_should_exit.load())>
│ ├──> const wq_config_t *wq = _wq_manager_create_queue->pop(); // When there is no work queue When , Management tasks are always blocked here .
│ └──> <wq != nullptr> // It should not be empty , Fault tolerance in case of segment errors , Inside is the establishment of new work queue
│ ├──> [stack, priority, etc] // A little ....
│ ├──> [Flat Build, pthread_create WorkQueueRunner]
│ ├──> [Protected Build, px4_task_spawn_cmd WorkQueueRunner]
│ ├──> <pid > 0>
│ │ └──> PX4_DEBUG("starting: %s, priority: %d, stack: %zu bytes", wq->name, sched_priority, stacksize);
│ └──> <else>
│ └──> PX4_ERR("failed to create thread for %s (%i): %s", wq->name, pid, strerror(pid));
└──> return 0;
2.4.3 WorkQueueRunner
WorkQueueRunner
├──> wq_config_t *config = static_cast<wq_config_t *>(context);
├──> WorkQueue wq(*config);
├──> _wq_manager_wqs_list->add(&wq); // add to work queue list
├──> wq.Run(); // Here is the
├──> _wq_manager_wqs_list->remove(&wq); // remove from work queue list
└──> return nullptr;
2.4.4 WorkQueue::Run
WorkQueue::Run
├──> <while (!should_exit())>
│ ├──> do {} while (px4_sem_wait(&_process_lock) != 0); // loop as the wait may be interrupted by a signal
│ ├──> work_lock();
│ └──> <while (!_q.empty())>
│ ├──> WorkItem *work = _q.pop();
│ ├──> work_unlock(); // unlock work queue to run (item may requeue itself)
│ ├──> work->RunPreamble();
│ ├──> work->Run(); // What really needs to be implemented Run function , It's usually inheritance WorkItem The object of
│ ├──> work_lock(); // re-lock
│ └──> work_unlock();
└──> PX4_DEBUG("%s: exiting", _config.name);
2.4.5 WorkQueueFindOrCreate
WorkQueueFindOrCreate
├──> <_wq_manager_create_queue == nullptr>
│ ├──> PX4_ERR("not running");
│ └──> return nullptr;
├──> WorkQueue *wq = FindWorkQueueByName(new_wq.name); // search list for existing work queue
├──> <wq == nullptr>
│ ├──> _wq_manager_create_queue->push(&new_wq); // It's important here , Only push 了 ,WorkQueueManagerRun It can only be carried out inside .
│ ├──> _uint64_t t = 0;
│ └──> _<while (wq == nullptr && t < 10_s)> // we wait until new wq is created, then return
│ ├──> t += 1_ms;
│ ├──> px4_usleep(1_ms);
│ ├──> wq = FindWorkQueueByName(new_wq.name);
│ └──> <wq == nullptr>
│ └──> PX4_ERR("failed to create %s", new_wq.name);
└──> return wq;
3. summary
Work queue , Actually, I'm not responsible . and PX4 Why does your work queue look complex , Mainly work queues and actual business coupling . Here we haven't put uORB Put your subscription content inside , If you combine this part , Plus the mutual switching of multiple inherited businesses , It seems more complicated .
So we especially emphasize that the design needs loose coupling , Try to be modular , Clear interface design , Define the frame design .
4. Reference material
【1】PX4 A brief introduction to the open source software framework
【2】Nuttx WorkQueue
边栏推荐
- Metersphere financial company landing experience sharing
- OPPO Find X2系列发布:3K+120Hz曲面屏,DXO评分第一,顶配版6999元!
- Shandong football match
- 技术生涯10年,那些让我心动的技术书
- Purple light FPGA solves the mask problem! Boost the overall speed-up of mask production
- Markdown extended syntax
- 2022/5/17考试总结
- Chrome realizes automated testing: recording and playback web page actions
- 七大排序之希尔排序
- It's time to say goodbye gracefully to nullpointexception
猜你喜欢

Jumpserver learning

一篇搞定Redis中的BigKey问题

An article to solve the bigkey problem in redis

In depth analysis - file operation
C语言详解系列——函数的认识(5)函数递归与迭代

Setcontentview details

浅析云原生应用安全组织架构

Data warehouse project is never a technical project

解决ip地址访问末位奇数通偶数不通,或者偶数通奇数不通的问题(云加密机连接云服务器时遇到的问题,全程记录,希望能给大佬们灵感)

Video human behavior detection
随机推荐
细胞CLE19多肽荧光成像牛血清白蛋白荧光猝灭量子点的制备
2022/5/13 考试总结
初中三年回忆录
catch all in one draft! Introduction to 10 data visualization software
Window localStorage 属性和Location 对象
US officials suggested trump prevent Infineon from acquiring cypress
三星存储工厂又发生火灾!
Leetcode-470. implement rand10() with rand7()
2022/3/11 exam summary
MediaTek and Samsung launched the world's first 8K TV that supports Wi Fi 6
Maximum sum of jz42 continuous subarray (force buckle) (GIF diagram)
In depth understanding of redis master-slave principle
物联网架构完全指南
jvm组成及内存模型
2021 Fujian Vocational College skills competition (secondary vocational group) network security competition assignment
对象创建过程及对象布局
10 years of technical career, those technical books that make me excited
Project management tool Zen
云计算服务主要安全风险及应对措施
CMOS switch (II)_ Parameter extraction