{"action":"created","issue":{"url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2366","repository_url":"https://api.github.com/repos/cleanflight/cleanflight","labels_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2366/labels{/name}","comments_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2366/comments","events_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2366/events","html_url":"https://github.com/cleanflight/cleanflight/pull/2366","id":172497654,"number":2366,"title":"Scheduler rewrite, improvements, debugging, and tests","user":{"login":"QuinnDamerell","id":7854873,"avatar_url":"https://avatars.githubusercontent.com/u/7854873?v=3","gravatar_id":"","url":"https://api.github.com/users/QuinnDamerell","html_url":"https://github.com/QuinnDamerell","followers_url":"https://api.github.com/users/QuinnDamerell/followers","following_url":"https://api.github.com/users/QuinnDamerell/following{/other_user}","gists_url":"https://api.github.com/users/QuinnDamerell/gists{/gist_id}","starred_url":"https://api.github.com/users/QuinnDamerell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuinnDamerell/subscriptions","organizations_url":"https://api.github.com/users/QuinnDamerell/orgs","repos_url":"https://api.github.com/users/QuinnDamerell/repos","events_url":"https://api.github.com/users/QuinnDamerell/events{/privacy}","received_events_url":"https://api.github.com/users/QuinnDamerell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":20,"created_at":"2016-08-22T16:34:19Z","updated_at":"2016-08-23T18:59:31Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/cleanflight/cleanflight/pulls/2366","html_url":"https://github.com/cleanflight/cleanflight/pull/2366","diff_url":"https://github.com/cleanflight/cleanflight/pull/2366.diff","patch_url":"https://github.com/cleanflight/cleanflight/pull/2366.patch"},"body":"I wanted to get involved with the project so I pulled the code and found the scheduler as a good starting point. As I looked at the code I realized it was quite over complicated and there seemed to be two different concepts going on in the code. There is a static array of tasks that can be ran that is compiled into the code and there was also a queue of tasks, but the tasks were only added to the queue on boot and never changed.\r\n\r\nI simplified the logic to only use the task list, which makes the code much easier to maintain but remove the possibility of queuing random task at any given time. That can still be added later down the road, but it didn’t seem like it was really a feature that would be needed in the system.\r\nI also made some improvements, the scheduler had the concept of a realtime guard (tasks would not be scheduled if they would run past the time when a realtime task needed to be scheduled) but the logic had a bug that would only make it apply if the realtime events were first in the queue. It also only considered the highest running time of all of the tasks, so if there was one task that was super long it wouldn’t let any tasks queue in the time slot. I changed the logic to work for all realtime tasks, and to also consider each task length individually so if one will fit it will run.\r\n\r\nI also improved the timing period for time based tasks, so if a task should run every 100ms the period between runs should be much closer to 100ms. The old code would reschedule the task to run 100ms from when it was executed, which means if the task was executed at 112 it would be queued to run at 212 next. A better way of doing this is to always schedule to the time it should have ran, so if it executed at 112 it would be scheduled to run at 200 next. The result is the time tasks are much more consistent. \r\n\r\nAnd finally, I added a ton of unit tests. There were unit tests for the queue in the scheduler, but none for any of the scheduling logic. I added unit test for just about everything, including all of the realtime guard and priority features."},"comment":{"url":"https://api.github.com/repos/cleanflight/cleanflight/issues/comments/241840506","html_url":"https://github.com/cleanflight/cleanflight/pull/2366#issuecomment-241840506","issue_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/2366","id":241840506,"user":{"login":"martinbudden","id":194586,"avatar_url":"https://avatars.githubusercontent.com/u/194586?v=3","gravatar_id":"","url":"https://api.github.com/users/martinbudden","html_url":"https://github.com/martinbudden","followers_url":"https://api.github.com/users/martinbudden/followers","following_url":"https://api.github.com/users/martinbudden/following{/other_user}","gists_url":"https://api.github.com/users/martinbudden/gists{/gist_id}","starred_url":"https://api.github.com/users/martinbudden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martinbudden/subscriptions","organizations_url":"https://api.github.com/users/martinbudden/orgs","repos_url":"https://api.github.com/users/martinbudden/repos","events_url":"https://api.github.com/users/martinbudden/events{/privacy}","received_events_url":"https://api.github.com/users/martinbudden/received_events","type":"User","site_admin":false},"created_at":"2016-08-23T18:59:31Z","updated_at":"2016-08-23T18:59:31Z","body":"@ledvinap , yes a linked list of tasks is another possibility. And RTOS is a whole other discussion...\r\n\r\nBut I'm generally not in favour of making changes in this area, especially just before a release:\r\n1. The existing code works and is performant\r\n2. Any bugs in the scheduler code are pretty sure to impact the user\r\n3. Any work on the scheduler is an opportunity cost, when there are quite a few more important and urgent things to do. Migration to the new IO, for example. "}}
{"actor":{"display_login":"martinbudden"}}