Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce IntrusiveSortedList and use for uORB, WorkQueues, and WorkItems #14885

Merged
merged 1 commit into from
Aug 4, 2020

Conversation

dagar
Copy link
Member

@dagar dagar commented May 10, 2020

This is a new linked list container (c++ template) that sorts on insertion. It's primarily for convenience for inspecting things in the system like uORB or WorkQueues. These are lists of things that are effectively static for the duration of operation in any normal usage (once booted), so there's no issue with doing slightly more work on insertion.

Usage is nearly identical to the existing List container other than having to additionally implement operator<= in your IntrusiveSortedListNode.

update: 1s, num topics: 77
TOPIC NAME                     INST #SUB RATE #LOST #Q SIZE
actuator_armed                    0    4    1     0  1   24 
actuator_controls_0               0    6  800  2654  1   48 
actuator_outputs                  0    3   46    90  1   80 
adc_report                        0    1  100     0  1   96 
battery_status                    0    7  100   259  1  112 
battery_status                    1    6  100   209  1  112 
cpuload                           0    4    1     0  1   16 
ekf2_timestamps                   0    1  200     0  1   24 
estimator_innovation_test_ratios  0    1  100     0  1  144 
estimator_innovation_variances    0    1  100     0  1  144 
estimator_innovations             0    1  100     0  1  144 
estimator_sensor_bias             0    4  100    97  1   56 
estimator_status                  0    4  100   309  1  288 
multirotor_motor_limits           0    2   46     0  1   16 
rate_ctrl_status                  0    1  800     0  1   24 
safety                            0    2   46     0  1   16 
sensor_accel                      0    2  800     0  4   40 
sensor_accel                      1    1  799     0  4   40 
sensor_accel                      2    1  995     0  4   40 
sensor_accel_integrated           0    3  200   238  1   48 
sensor_accel_integrated           1    3  199   238  1   48 
sensor_accel_integrated           2    3  202   249  1   48 
sensor_accel_status               0    3   10     0  1   48 
sensor_accel_status               1    3   10     0  1   48 
sensor_accel_status               2    3   10     0  1   48 
sensor_baro                       0    2   74     0  1   32 
sensor_combined                   0    3  200   197  1   48 
sensor_gyro                       0    2  800     0  4   40 
sensor_gyro                       1    1  799     0  4   40 
sensor_gyro                       2    1 1250     0  4   40 
sensor_gyro_integrated            0    4  200   238  1   48 
sensor_gyro_integrated            1    4  199   238  1   48 
sensor_gyro_integrated            2    4  206   257  1   48 
sensor_gyro_status                0    3   10     0  1   56 
sensor_gyro_status                1    1   10     0  1   56 
sensor_gyro_status                2    1   10     0  1   56 
sensor_mag                        0    3   88   105  1   48 
sensor_preflight                  0    1  200     0  1   24 
system_power                      0    2  100     9  1   24 
telemetry_status                  0    2    2     0  3   48 
vehicle_acceleration              0    1  800   750  1   32 
vehicle_air_data                  0    8   74   364  1   40 
vehicle_angular_acceleration      0    1  800     0  1   32 
vehicle_angular_velocity          0    6  800  3132  1   32 
vehicle_attitude                  0    7  200   840  1   48 
vehicle_attitude_setpoint         0    4  200   448  1   64 
vehicle_control_mode              0    8    1     0  1   32 
vehicle_land_detected             0    9    1     0  1   24 
vehicle_local_position            0   11  100   784  1  152 
vehicle_magnetometer              0    3   89    86  1   24 
vehicle_odometry                  0    1  100    98  1  256 
vehicle_rates_setpoint            0    4  200   448  1   32 
vehicle_status                    0   16    1     0  1   56 
vehicle_status_flags              0    1    1     0  1   40 
nsh> work_queue status

Work Queue: 8 threads                      RATE        INTERVAL
|__ 1) wq:rate_ctrl    
|   |__ 1) mc_rate_control             800.2 Hz       1249.6 us
|   \__ 2) vehicle_angular_velocity    800.1 Hz       1249.9 us
|__ 2) wq:SPI1         
|   |__ 1) bmi055                     1250.0 Hz        800.0 us (800 us)
|   |__ 2) bmi055                     1249.9 Hz        800.1 us (800 us)
|   |__ 3) icm20602                    800.1 Hz       1249.9 us
|   \__ 4) icm20689                    799.1 Hz       1251.4 us
|__ 3) wq:SPI4         
|   \__ 1) ms5611                       99.4 Hz      10056.4 us
|__ 4) wq:I2C3         
|   \__ 1) ist8310                      88.9 Hz      11250.2 us
|__ 5) wq:attitude_ctrl
|   \__ 1) mc_att_control              166.1 Hz       6021.7 us
|__ 6) wq:navigation_and_controllers
|   |__ 1) ekf2                        200.0 Hz       4999.0 us
|   |__ 2) land_detector                50.0 Hz      19991.3 us (20000 us)
|   |__ 3) mc_pos_control               41.5 Hz      24076.6 us
|   |__ 4) sensors                     200.0 Hz       4999.7 us
|   |__ 5) vehicle_acceleration        800.0 Hz       1249.9 us
|   |__ 6) vehicle_air_data             74.5 Hz      13418.3 us
|   |__ 7) vehicle_imu                 370.2 Hz       2701.2 us
|   |__ 8) vehicle_imu                 199.8 Hz       5004.0 us
|   \__ 9) vehicle_imu                 200.1 Hz       4998.2 us
|__ 7) wq:hp_default   
|   |__ 1) adc                         100.0 Hz       9997.0 us (10000 us)
|   |__ 2) battery_status              100.0 Hz       9997.4 us (10000 us)
|   |__ 3) pwm_out                       0.1 Hz   14890350.0 us
|   |__ 4) rc_update                     0.0 Hz          0.0 us
|   |__ 5) safety_button                30.3 Hz      32968.6 us (33000 us)
|   \__ 6) tone_alarm                    9.5 Hz     105043.7 us
\__ 8) wq:lp_default   
    |__ 1) load_mon                      1.0 Hz     972547.1 us (1000000 us)
    |__ 2) mc_hover_thrust_estimator      0.0 Hz          0.0 us
    |__ 3) rgbled_pwm                   39.7 Hz      25182.2 us
    \__ 4) send_event                   30.0 Hz      33306.7 us (33333 us)

@dagar dagar force-pushed the pr-sorted_list branch from 11e2ea8 to 6ccfef7 Compare July 2, 2020 01:18
@dagar dagar marked this pull request as ready for review July 2, 2020 01:18
@dagar dagar requested a review from julianoes July 2, 2020 01:19
@dagar
Copy link
Member Author

dagar commented Aug 3, 2020

update: 1s, num topics: 64
TOPIC NAME                     INST #SUB RATE #LOST #Q SIZE
actuator_armed                    0    6    1     0  1   24 
actuator_controls_0               0    6  998  2793  1   48 
actuator_outputs                  0    3  800  1914  1   80 
adc_report                        0    1  100     0  1   96 
battery_status                    0    6  100   247  1  112 
battery_status                    1    6  100   247  1  112 
commander_state                   0    1    1     0  1   16 
cpuload                           0    4    2     1  1   16 
estimator_innovation_test_ratios  0    1  100     0  1  144 
estimator_innovation_variances    0    1  100     0  1  144 
estimator_innovations             0    1  100     0  1  144 
estimator_sensor_bias             0    4  100    93  1   56 
estimator_status                  0    4  100   367  1  288 
multirotor_motor_limits           0    2  800     0  1   16 
rate_ctrl_status                  0    1  998     0  1   24 
safety                            0    2    1     0  1   16 
sensor_accel                      0    4  803     0  8   48 
sensor_accel                      1    3  750     0  8   48 
sensor_baro                       0    2   73     0  1   32 
sensor_baro                       1    2   73    14  1   32 
sensor_combined                   0    3  200   189  1   48 
sensor_gyro                       0    4  998     0  8   40 
sensor_gyro                       1    3  750     0  8   40 
sensor_mag                        0    3   98    92  1   48 
sensor_preflight                  0    1  200     0  1   24 
system_power                      0    2  100     9  1   24 
telemetry_status                  0    2    2     0  3   48 
vehicle_acceleration              0    1  201   101  1   32 
vehicle_air_data                  0    8   18    90  1   40 
vehicle_angular_acceleration      0    1  998     0  1   32 
vehicle_angular_velocity          0    5  998  2889  1   32 
vehicle_attitude                  0    7  200   821  1   48 
vehicle_attitude_setpoint         0    4  200   476  1   64 
vehicle_control_mode              0    8    1     0  1   32 
vehicle_imu                       0    3  200   191  1   56 
vehicle_imu                       1    3  188   179  1   56 
vehicle_imu_status                0    4   10     0  1   56 
vehicle_imu_status                1    4   10     0  1   56 
vehicle_land_detected             0    9    1     5  1   24 
vehicle_local_position            0   11  100   820  1  152 
vehicle_magnetometer              0    3   97    91  1   24 
vehicle_odometry                  0    1  100   118  1  256 
vehicle_rates_setpoint            0    4  200   476  1   32 
vehicle_status                    0   17    1     5  1   56 
vehicle_status_flags              0    1    1     0  1   40 
nsh> work_queue status

Work Queue: 9 threads                        RATE        INTERVAL
|__ 1) wq:rate_ctrl    
|   |__ 1) mc_rate_control               997.8 Hz         1002 us
|   |__ 2) pwm_out                       799.6 Hz         1251 us
|   \__ 3) vehicle_angular_velocity      997.8 Hz         1002 us
|__ 2) wq:SPI2         
|   \__ 1) rm3100                         97.3 Hz        10282 us
|__ 3) wq:SPI4         
|   |__ 1) bmi088                        997.2 Hz         1003 us
|   |__ 2) bmi088                        803.0 Hz         1245 us
|   \__ 3) ms5611                         97.3 Hz        10280 us
|__ 4) wq:SPI6         
|   |__ 1) icm20649                      747.4 Hz         1338 us (1333 us)
|   \__ 2) ms5611                         97.3 Hz        10281 us
|__ 5) wq:attitude_ctrl
|   \__ 1) mc_att_control                199.6 Hz         5011 us
|__ 6) wq:nav_and_controllers
|   |__ 1) ekf2                          199.6 Hz         5011 us
|   |__ 2) land_detector                  86.3 Hz        11587 us
|   |__ 3) mc_pos_control                 50.0 Hz        19991 us
|   |__ 4) sensors                       199.4 Hz         5015 us
|   |__ 5) vehicle_acceleration          215.3 Hz         4645 us
|   |__ 6) vehicle_air_data               72.8 Hz        13731 us
|   |__ 7) vehicle_imu                   187.6 Hz         5332 us
|   \__ 8) vehicle_imu                   199.8 Hz         5005 us
|__ 7) wq:hp_default   
|   |__ 1) adc                           100.0 Hz         9999 us (10000 us)
|   |__ 2) battery_status                100.0 Hz         9998 us (10000 us)
|   |__ 3) rc_update                       0.0 Hz            0 us
|   |__ 4) safety_button                  30.3 Hz        32982 us (33000 us)
|   \__ 5) tone_alarm                     10.3 Hz        96623 us
|__ 8) wq:UART5        
|   \__ 1) rc_input                      250.0 Hz         4000 us (4000 us)
\__ 9) wq:lp_default   
    |__ 1) load_mon                        2.0 Hz       499053 us (500000 us)
    |__ 2) mc_hover_thrust_estimator       0.0 Hz            0 us
    |__ 3) rgbled_pwm                     39.2 Hz        25491 us
    \__ 4) send_event                     30.0 Hz        33329 us (33333 us)

@@ -57,6 +60,9 @@ class WorkItem : public ListNode<WorkItem *>, public IntrusiveQueueNode<WorkItem
WorkItem(WorkItem &&) = delete;
WorkItem &operator=(WorkItem &&) = delete;

// WorkItems sorted by name
bool operator<=(const WorkItem &rhs) const { return (strcmp(ItemName(), rhs.ItemName()) <= 0); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have an upper bound for safety, so with strncmp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose, although in a lot of these cases for us I think we'd want to go back to the source to get a reasonable answer in place for the max length.

In this case the WorkItem name is set in the constructor and I believe we're currently always setting it to MODULE_NAME or <single_shot>. MODULE_NAME doesn't really have any constraints, although in the past we've trimmed them to fit within the NuttX task CONFIG_TASK_NAME_SIZE.

I'm not sure if we need to worry about about it unless there's the possibility of involving a non-NULL terminated character array.

@dagar dagar merged commit b6a17a6 into master Aug 4, 2020
@dagar dagar deleted the pr-sorted_list branch August 4, 2020 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants