Commit Graph

40 Commits

Author SHA1 Message Date
Ville Juven d83b9f3c38 WorkItemSingleShot: Disable priority inheritance for signaling semaphore
WorkItemSingleShot::_sem is a signaling semaphore, disable PI for it.

Set CONFIG_DEBUG_ASSERTIONS=y and the kernel panics due to the semaphore
having no holder, disabling PI fixes this.
2023-10-17 10:08:25 -04:00
Beat Küng e65a0a01d6 fix WorkQueueManager: wait until running to prevent race conditions 2023-05-31 07:45:20 +02:00
Eric Katzfey 9b3feee6ee
worker and HRT threads for Qurt platform (#20739)
* Getting work manager and hrt threads ready for Qurt platform
2022-12-12 14:25:28 -05:00
Ville Juven 59e86c490d Remove include <log.h> from defines.h
The reason for this is that log.h includes drv_hrt.h which sucks in
half the project's include files with it, which causes strange build
issues
2022-09-29 07:56:24 +02:00
Jukka Laitinen 7bb33e65ae Remove px4_work_queue linking to px4_platform
Remove linking to px4_plaform in here; this breaks linking for nuttx protected build

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2022-01-27 12:42:40 -05:00
Daniel Agar 8067207ea6 px4_work_queue: rename serial port WQs 2022-01-18 14:56:15 -05:00
Beat Küng fe1b726b62 ScheduledWorkItem: do not call ScheduleClear() if not init in destructor
This avoids that unit tests trying to access a wq hang.
It still fails with an error currently.
2021-12-24 20:06:13 -05:00
Beat Küng e29759d877 WorkQueueManager: explicitly convert PTHREAD_STACK_MIN to int
fixes a compiler error on GCC 11.2.1:
error: no matching function for call to ‘max(long int, int)’
2021-12-22 08:47:33 -05:00
Jukka Laitinen 77af102cab px4_work_queue: Use px4_task_spawn_cmd for WorkQueueRunner in NuttX protected
In NuttX protected build there are separate work queues in kernel and user sides.

pthreads are only available in user side, so use tasks and kthreads for
memory protected builds.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2021-12-09 20:42:28 -05:00
Daniel Agar beb358a344 px4_work_queue: adjust status formatting to accommodate longer names (eg mc_autotune_attitude_control) 2021-10-05 18:09:00 -04:00
Jukka Laitinen c3c30e5d4f Fix memory corruption when work queue is being deleted
When the last WorkItem is deleted, it is removed from a work queue and the
queue is being stopped. But, the queue itself might get deleted in the middle,
in a higher priority thread than where the WorkItem deletion was performed from

If the WorkQueue::Detach accesses the member variables after this, there is memory
corruption

This happens in particular when launching i2c or spi devices in
I2CSPIDriverBase::module_start:

- The "initializer" is deleted when the instance is not found and the iterator
  while loop continues.
- The workqueue is deleted in the middle of "initializer" deletion when the
  WorkQueueRunner returns.

This prevents deletion of the WorkQueue before the Detach has been finished,
in the specific case that the ::Detach triggers the deletion

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2021-08-27 10:43:45 +02:00
Jukka Laitinen 523578d2ce Increase stack size of wq:manager and worker threads for 64 bit targets
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2021-08-24 10:16:27 -04:00
Daniel Agar 65745a3676 purge broken qurt support and atlflight boards 2021-07-16 08:53:36 -04:00
Daniel Agar 98cff94702 px4_work_queue: directly support SITL lockstep
- the purpose is to ensure that every WorkItem (and WorkItems scheduled
by WorkItems) is allowed to run to completion every step
 - per workqueue register a lockstep component whenever a work item is
added (if not already registered)
 - once the work queue is empty unregister component
2021-01-04 09:38:05 +01:00
Daniel Agar 0f411d6820
Multi-EKF support (ekf2)
- ekf2 can now run in multi-instance mode (currently up to 9 instances)
    - in multi mode all estimates are published to alternate topics (eg estimator_attitude instead of vehicle_attitude)
 - new ekf2 selector runs in multi-instance mode to monitor and compare all instances, selecting a primary (eg N x estimator_attitude => vehicle_attitude)
 - sensors module accel & gyro inconsistency checks are now relative to the mean of all instances, rather than the current primary (when active ekf2 selector is responsible for choosing primary accel & gyro)
 - existing consumers of estimator_status must check estimator_selector_status to select current primary instance status
 - ekf2 single instance mode is still fully supported and the default

Co-authored-by: Paul Riseborough <gncsolns@gmail.com>
2020-10-27 10:56:11 -04:00
Daniel Agar 08bf71b73d
drivers/tone_alarm and tune_control small improvements/cleanup
- drivers/tone_alarm: move to ModuleBase and purge CDev (/dev/tone_alarm0)
 - drivers/tone_alarm: only run on tune_control publication (or scheduled note) rather than continuously
 - drivers/tone_alarm: use HRT to schedule tone stop (prevents potential disruption)
 - msg/tune_control: add tune_id numbering
 - systemcmds/tune_control: add "error" special case tune_id
 - move all tune_control publication to new uORB::PublicationQueued<>
 - start tone_alarm immediately after board defaults are loaded to fix potential startup issues
 - for SITL (or other boards with no TONE output) print common messages (startup, error, etc)
2020-10-05 21:39:26 -04:00
Daniel Agar 668c16da83 px4_work_queue: reset statistics after each status print 2020-09-02 10:09:13 -04:00
Daniel Agar 31fe7af454 selectively increase optimization -Os -> -O2
- targetted at modules/libraries that benefit without drastically
increasing flash usage
 - ignored on boards with CONSTRAINED_FLASH set
2020-06-04 20:59:52 -04:00
Daniel Agar 8ee0a5d328 px4_work_queue: minor status changes
- only record start time on first run rather than init
 - increase name length
 - round average interval to nearest microsecond
 - basic formatting consistency (google style guide)
2020-05-23 11:51:23 -04:00
Daniel Agar 1d164c0dbd px4_work_queue: sem_wait add loop as the wait may be interrupted by a signal 2020-04-06 10:30:35 +02:00
Beat Küng 8c41025565 px4_work_queue: add WorkItemSingleShot
To run a specific method on a work queue and wait for it to return.
2020-03-17 23:31:17 -04:00
Beat Küng 18bc6cf872 ScheduledWorkItem::ScheduleClear: remove item from runnable queue
The existing behavior is unexpected: if the work item is already on the
runnable queue, it will still be triggered after a call to ScheduleClear().
This can lead to race conditions.
2020-03-09 08:06:00 -04:00
SalimTerryLi e0abe7090e
SBUS on Linux: replace termios with termios2 and add UNKNOWN UART WQ 2020-02-02 14:06:27 -05:00
Julian Oes 30188d2884 Revert "Simulation: Set scheduling policy RR for lockstep"
This reverts commit 742b1839d5.
2020-01-24 12:04:47 +01:00
Daniel Agar 21a8d7db7f WorkItem modules: Run() shouldn't be public 2020-01-22 12:03:03 -05:00
Daniel Agar dc05ceaad2
create temperature_compensation module
- this is a new module for temperature compensation that consolidates the functionality previously handled in the sensors module (calculating runtime thermal corrections) and the events module (online thermal calibration)
 - by collecting this functionality into a single module we can optionally disable it on systems where it's not used and save some flash (if disabled at build time) or memory (disabled at run time)
2020-01-20 21:42:42 -05:00
Daniel Agar bd111c9f42
px4_work_queue: revert inherited sched attr and run wq:manager and max priority
Setting PTHREAD_EXPLICIT_SCHED was necessary on linux to create WQ threads with priorities relative to max, but unfortunately we can't rely pthread_attr_setinheritsched as it's dependent on system ulimit configuration or running privileged. Instead we can create the wq:manager at the maximum desired priority and allow each WQ thread to have a relative priority.
2020-01-10 17:57:51 -05:00
Daniel Agar a08b54b8e1
px4_work_queue: don't inherit pthread attributes from creating thread
- this is necessary on linux so that the WQ threads priorities are set relative to max, and not relative to the wq:manager thread
2020-01-10 11:02:49 -05:00
Lorenz Meier 742b1839d5 Simulation: Set scheduling policy RR for lockstep
This should ensure that all processes do still run at full load.
2019-12-26 10:16:58 +01:00
Daniel Agar 071f159794 PX4 work queue: extend to UARTs 2019-11-27 20:44:32 -05:00
Daniel Agar c5520cbaca mpu9250: start building "NuttX" driver for Linux and QuRT 2019-11-13 09:21:02 -05:00
Beat Küng a203475489 BlockingList: fix unsafe getLockGuard() API
getLockGuard relies on copy elision to work correctly, which the compiler
is not required to do (only with C++17).
If no copy elision happens, the mutex ends up being unlocked twice, and the
CS is executed with the mutex unlocked.

The patch also ensures that the same pattern cannot be used again.
2019-11-05 12:14:20 +01:00
FlavioTonelli 7984c0c910 px4_work_queue: stack size rounded to page size on posix 2019-11-03 09:04:04 -05:00
Beat Küng 3198610f85 src/platforms: move all headers to platforms/common/include/px4_platform_common
and remove the px4_ prefix, except for px4_config.h.

command to update includes:
for k in app.h atomic.h cli.h console_buffer.h defines.h getopt.h i2c.h init.h log.h micro_hal.h module.h module_params.h param.h param_macros.h posix.h sem.h sem.hpp shmem.h shutdown.h tasks.h time.h workqueue.h; do for i in $(grep -rl 'include <px4_'$k src platforms boards); do sed -i 's/#include <px4_'$k'/#include <px4_platform_common\/'$k/ $i; done; done
for in $(grep -rl 'include <px4_config.h' src platforms boards); do sed -i 's/#include <px4_config.h/#include <px4_platform_common\/px4_config.h'/ $i; done

Transitional headers for submodules are added (px4_{defines,log,time}.h)
2019-10-30 11:48:47 +01:00
Daniel Agar 4192414576 clang-tidy: partially fix cppcoreguidelines-pro-type-reinterpret-cast 2019-10-28 10:50:31 -04:00
Beat Küng 25aded36ec WorkQueue: avoid potential semaphore counter overflow
This could happen in the following cases:
- IRQ/publisher rate is faster than the processing rate, and therefore
  WorkQueue::Add is called at a higher rate
- a long-running or stuck task that blocks the work queue a long time

Both cases are not expected to happen under 'normal' circumstances (if the
system runs as expected).
2019-10-16 18:29:26 +02:00
Daniel Agar 26364d44c9
px4_work_queue: command line status output and shutdown empty queues
* adds a work_queue systemcmd that will bring a tree view of all active work queues and work items
 * WorkQueues now track attached WorkItems and will shutdown when the last WorkItem is detached
2019-10-02 12:23:17 -04:00
Julian Oes 78d3986013 platforms: fix main function signature 2019-09-03 11:52:54 -05:00
Beat Küng 43fdcd7876 px4_middleware: remove that header and move px4::init to px4_init.h
delete include:
for i in $(grep -rl 'px4_middleware.h' src platforms); do sed -i '/#include <px4_middleware.h/d' $i; done
2019-08-30 07:59:44 +02:00
Beat Küng f8e0441e7b src/platforms/common: move to platforms/common
Script to update include paths:
for i in $(grep -rl 'include <px4_work_queue' src platforms); do sed -i 's/#include <px4_work_queue/#include <px4_platform_common\/px4_work_queue/' $i; done
2019-08-30 07:59:44 +02:00