Introduction to RTOS Part 11 - Priority Inversion | Digi-Key Electronics

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 มี.ค. 2021
  • Priority inversion is a nasty concurrency bug that occurs when a low priority thread prevents a high priority thread from running. In a sense, the priority structure has been “inverted,” as the low priority thread gets to run first.
    The code for the challenge, which starts with unbounded priority inversion, can be found here: github.com/ShawnHymel/introdu...
    The solution to the challenge can be found here: www.digikey.com/en/maker/proj...
    Code for this video series (including demonstrations, challenges, and solutions) can be found here: github.com/ShawnHymel/introdu...
    Bounded priority inversion happens in the simple case where a high priority task takes a lock (e.g. mutex or semaphore) and prevents a high priority task from running, as the high priority task is blocked waiting for the same lock. We consider this “bounded” because the blocking is bounded by the length of time the low priority task is executing inside the critical section (prior to returning the lock).
    Preventing bounded priority inversion requires careful thinking about how the threads interact and either limiting or avoiding critical sections. One possible solution is to create a task (or thread) that manages a shared resource. All other threads must use queues (or other synchronization techniques) to send and receive data from this task.
    Unbounded priority inversion occurs when a medium priority task preempts a low priority task that’s holding a lock needed by a high priority task. It’s “unbounded” because the amount of time that the high priority task is blocked is dependent on the time the medium task runs without yielding to the low priority task (which needs to release the lock).
    We can prevent unbounded priority inversion through the use of the priority ceiling protocol or priority inheritance, which we cover in the video. Both techniques require that the priorities of tasks can be dynamically changed at runtime. Note that both techniques do not prevent bounded priority inversion.
    Product Links:
    www.digikey.com/en/products/d...
    Related Videos:
    Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? - • Introduction to RTOS P... ​
    Introduction to RTOS Part 2 - Getting Started with FreeRTOS - • Introduction to RTOS P... ​
    Introduction to RTOS Part 3 - Task Scheduling - • Introduction to RTOS P... ​
    Introduction to RTOS Part 4 - Memory Management - • Introduction to RTOS P... ​
    Introduction to RTOS Part 5 - Queue - • Introduction to RTOS P... ​
    Introduction to RTOS Part 6 - Mutex - • Introduction to RTOS P... ​
    Introduction to RTOS Part 7 - • Introduction to RTOS P... ​
    Introduction to RTOS Part 8 - • Introduction to RTOS P...
    Introduction to RTOS Part 9 - • Introduction to RTOS P...
    Introduction to RTOS Part 10 - • Introduction to RTOS P...
    Introduction to RTOS Part 11 - • Introduction to RTOS P...
    Introduction to RTOS Part 12 - • Introduction to RTOS P...
    Related Project Links:
    www.digikey.com/en/maker/proj...
    Related Articles:
    www.digikey.com/en/maker/vide...
    Learn more:
    Maker.io - www.digikey.com/en/maker
    Digi-Key’s Blog - TheCircuit www.digikey.com/en/blog
    Connect with Digi-Key on Facebook / digikey.electronics
    And follow us on Twitter / digikey
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 32

  • @tehmudjinkhan2207
    @tehmudjinkhan2207 3 ปีที่แล้ว +11

    RTOS is perfect for my projects and this video series helps a lot

  • @mohamedhassanin6054
    @mohamedhassanin6054 2 ปีที่แล้ว +12

    0:00 Mars Rover Pathfinder
    1:14 bounded priority inversion
    2:47 bound task
    3:39 Mars rover bounded priority inversion
    6:03 bounded priority inversion demo
    7:59 priority ceiling protocol
    9:49 priority inheritance
    10:56 priority inheritance demo with FreeRTOS mutex
    11:20 challenge

  • @AlonchBreak
    @AlonchBreak 3 ปีที่แล้ว +13

    You did a great job at keeping sessions interesting with real-life examples!

  • @Clark-Mills
    @Clark-Mills 3 ปีที่แล้ว +8

    Great work, really appreciate the quality of your work.

  • @MrWATCHthisWAY
    @MrWATCHthisWAY 3 ปีที่แล้ว +4

    Darn Shawn no Happy Hacking at the end of your lesson this time? These lessons are all coming together for me now as you build on each segment. Thank you and DigiKey for these lessons because it helps out tremendously in understanding the of architecture & function of the programming.

    • @ShawnHymel
      @ShawnHymel 3 ปีที่แล้ว +2

      Happy hacking! ;) I'm glad to hear that you're finding them helpful!

    • @qcsupport2594
      @qcsupport2594 3 ปีที่แล้ว +4

      Your challenge for Part 11 is to build a rover, land it on Mars, detect any priority inversions, and fix them from Earth. Happy Hacking!

  • @AgainPsychoX
    @AgainPsychoX 3 ปีที่แล้ว +2

    I love the videos, interesting topic, and so good quality

  • @josephlai7737
    @josephlai7737 3 ปีที่แล้ว +3

    It seems to me it is better to disable preemption or interrupt altogether for any critical section, for two reasons.
    One: critical sections are short, they are non-blocking, so the protected resource will be available for the task with higher priority (be it the task that wants to preempt the current task, or an interrupt service routine) very soon.
    Two: this way, no priority inversion will happen, including the bounded type.
    Of course, the lower priority task should yield to higher priority task immediately after it releases the resource.
    What are the reasons for not disabling preemption/interrupt?
    # Edit: As the video continues, I realized what I was talking about are called critical markers and do exactly that.

    • @ShawnHymel
      @ShawnHymel 3 ปีที่แล้ว

      Good question! Disabling preemption and interrupts during critical sections does make it much easier to prevent priority inversion.
      You generally want preemption when you have high priority tasks that should stop another task from running to perform some task immediately (I.e it cannot wait for the low priority task to explicitly yield the processor with a vTaskDelay()).

  • @TS-kg4lf
    @TS-kg4lf 3 ปีที่แล้ว +3

    One way to check that is an integration test where you call all tasks to see if the hierarchy is respected

  • @tinashetanyaradzwamabika2422
    @tinashetanyaradzwamabika2422 ปีที่แล้ว

    thank you for the awesome content. referring to diagram on 2:44 , what if we have another task that keep tracks of the task holding the mutex so that when another task of high priority interrupts, it will call the task holding the mutex to release it so that it proceeds to do its work

  • @ethanzheng4673
    @ethanzheng4673 ปีที่แล้ว

    Great explanation!

  • @andrewabilevich7370
    @andrewabilevich7370 2 ปีที่แล้ว

    so touching for an excellent video

  • @tosemusername
    @tosemusername 3 ปีที่แล้ว

    @Digi-Key I don't get the 4:3-ish window size of the arduino IDE in the videos.

    • @YaroslaffFedin
      @YaroslaffFedin 2 ปีที่แล้ว

      Looks like the author puts two code editors side by side to copy code from one another, so he only records one of the windows. Still not great.

  • @chrisalfred5567
    @chrisalfred5567 ปีที่แล้ว

    At 3:16 You say that queue 2 can be replaced by "a global variable that Task A and B have read-only access to". Surely that will cause race conditions as The "Service Task" can not know when Task A or Task B are reading the variable to coordinate the write to the global variable; and conversely Task A and Task B can not know when the Service Task is about to write to the global variable to coordinate their reads.

  • @zee-lab-electronics
    @zee-lab-electronics 3 ปีที่แล้ว +3

    Awesome Shawn.
    It would be great if you start tinyML video series (on esp32-cam) , 🤗.
    Is it possible? 😊.

    • @ShawnHymel
      @ShawnHymel 3 ปีที่แล้ว +3

      I've got a few TinyML videos and a course out there, but nothing on vision. Good to know there's interest!

  • @narsino
    @narsino ปีที่แล้ว

    thank you!

  • @awesomdev
    @awesomdev ปีที่แล้ว

    Whats' the meaning of sw?

  • @gacherumburu9958
    @gacherumburu9958 3 ปีที่แล้ว +1

    👍

  • @Kravch96
    @Kravch96 2 ปีที่แล้ว

    He is too perfect

    • @digikey
      @digikey  2 ปีที่แล้ว +1

      We think so too. There's a conspiracy that he's a robot. ;)

  • @reginaldsykes
    @reginaldsykes ปีที่แล้ว

    I am somewhat confused by the explanation of what is happening to create the "priority inversion" issue that affected the Mars rover. I listened to the explanation several times but I feel that some part of the explanation is either missing or I am misunderstanding. From 4:21 to 4:56 ...
    you stated "Every now and then, the medium priority task would run while the low priority task was in the critical section. As you can see, task 'H' is still blocked and it will remain blocked so long as task 'L' has the mutex. And, task 'L' won't run to release the mutex as long as task 'M' is running."
    Here is where I am confused. If task 'L' has the mutex, and task 'H' is being blocked, that should mean that no task can work in the critical section until task 'L' releases the mutex. You stated that "task 'L' won't run to release the mutex as long as task 'M' is running. This is confusing to me. Can you explain why task 'M' is a factor if it doesn't have the mutex and is not holding a resource that task 'L' needs in order to complete task 'L's task? Why wouldn't task 'L' just complete its task, release the mutex, and task 'H' and task 'M' are free to take the mutex if they need to run in this critical section? I don't understand what task 'M' has to do with this if task 'M' is not using this critical section. I'm sure I missed something here. Please explain.

    • @seferideveloper6933
      @seferideveloper6933 ปีที่แล้ว

      I totally think the same thing! Have you been able to understand yet?

    • @mikoajchyczynski5707
      @mikoajchyczynski5707 ปีที่แล้ว +3

      What I understood: because task M has higher priority than task L, task L will be preempted and task M will run. Because taks M does not use use critical section it will not be stopped by it (like task H was stopped) and it will not let task L finish with critical section because it doesn't need the critical section and doesn't care about it. Task M can run for a long of time without interrupts (because is higher prio than L and because task H is not gonna to preempt it because it is blocked by critical section) and all of that time task L is holding critical section that task H wants to use. So finally medium priority task runs freely and high priority task is blocked (that's the inversion of priorities).
      For the Mars rover task M run and blocked tasks L & H for enough time to trigger watchdog.

  • @sankalpnegi7626
    @sankalpnegi7626 2 ปีที่แล้ว +1

    Hey, great job on the content, keep it up !
    However, I disagree on the concept "Bounded Priority Inversion", as I think its not a "Priority Inversion", at all !
    As we see in the video 2:17, in "Bounded Priority Inversion", the higher priority task is waiting on a lower priority task, but, due to a resource contention, and NOT because of any priority specific scheduling decision making.
    We need to understand that priority is NOT always the sole metric of scheduling !
    As we see in this case, the priority metric is shadowed by resource contention logic. Hence, by design, its completely intentional, and not an anomaly. The priority scheduling was never broken here (its just that it was not significant enough to be considered in this case).
    So, this may be termed as a type of "Priority Inversion", but only in a poetic sense, as it has no technical backing !
    Feel free to correct me, Thanks !

  • @nilton61
    @nilton61 2 ปีที่แล้ว

    Do not use delays of other blocking code

  • @devkumar9889
    @devkumar9889 6 หลายเดือนก่อน

    PCP info was not clear and wrong I guess

  • @intheshell35ify
    @intheshell35ify ปีที่แล้ว

    What are you talking about?!?! Bunch of cs dropouts.