Looking for a comparison of different scheduling algorithms for a Finite State Machine

后端 未结 2 1796
攒了一身酷
攒了一身酷 2021-01-06 21:14

Are there any good resources (books, websites) that give very good comparison of different scheduling algorithms for a Finite State Machine (FSM) in an embedded system witho

相关标签:
2条回答
  • 2021-01-06 21:40

    You state: "I mean for example scheduling condion in like ,if two task arrived at the same time which task need to be prioritized and simillar other situations in embedded webserver."

    Which I interpret as: "What is the set of rules used to determine which task gets executed first (scheduled) when multiple tasks arrive at the same time."

    I used your terminology, "task" to illustrate the similarity. But Clifford is correct. The proper term should be "event" or "message".

    And when you say "scheduling condition" I think you mean "set of rules that determines a schedule of events".

    The definition of algorithm is: A process or set of rules to be followed in calculations or other problem-solving operations, esp. by a computer.

    From a paper entitled Scheduling Algorithms:

    Consider the central processing unit of a computer that must process a sequence of jobs that arrive over time. In what order should the jobs be processed in order to minimize, on average, the time that a job is in the system from arrival to completion?

    Which again, sounds like what you're calling "scheduling conditions".

    I bring this up because using the right words to describe what you are looking for will help us (the SO community) give you better answers. And will help you as you research further on your own.

    If my interpretation of your question still isn't what you have in mind, please let me know what, in particular, I've said is wrong and I will try again. Maybe some more examples would help me better understand.

    Some further reading on scheduling (which is what you asked for):

    1. A good starting point of course is the Wikipedia article on Scheduling Disciplines
    2. A bit lower level than you are looking for but still full of detailed information on scheduling is Scheduling Algorithms for High-Level Synthesis (NOTE: for whatever reason the PDF has the pages in reverse order, so start at the bottom)

    An example of a priority interrupt scheduler:

    Take an architecture where Priority Level 0 is the highest. Two events come in simultaneously. One with Priority 2 and another with Priority 3. The scheduling algorithm starts processing the one with Priority 2 because it has a higher priority.

    While the event with Priority 2 is being processed, another event with Priority 0 comes in. The scheduler interrupts the event with Priority 2 and processes the event with Priority 0.

    When it's finished processing the Priority 0 event, it returns to processing the Priority 2 event. When it's finished processing the Priority 2 event, it processes the Priority 3 event.

    Finally, when it's done with processing all of the priority interrupts, it returns control to the main processing task which handles events where priority doesn't matter.

    An illustration:

    priority interrupt timing

    In the above image, the "task" is the super loop which DipSwitch mentioned or the infinite loop in main() that occurs in a cyclic executive which you mentioned. The "events" are the various routines that are run in the super loop or interrupts as seen above if they require prioritization.

    Terms to search for are Priority Interrupt and Control Flow. Some good reading material is the Toppers Kernel Spec (where I got the image from), the ARM Interrupt Architecture, and a paper on the 80196 Interrupt Architecture.

    I mention the Toppers Kernel Spec just because that's where I got the image from. But at the heart of any real-time OS is it's scheduling algorithm and interrupt architecture.

    The "on event" processing you ask about would be handled by the microprocessor/microcontroller interrupt subsystem. How you structure the priority levels and how you handle non-priority events is what makes up the totality of your scheduling algorithm.

    An example of a cooperative scheduler:

    typedef struct {
        void   (*task)(void); // Pointer to the task function.
        uint32_t period;      // Period to execute with.
        uint32_t delay;       // Delay before first call.
    } task_type;
    
    volatile uint32_t elapsed_ticks = 0;
    task_type tasks[NUM_TASKS];
    
    void Dispatch_Tasks(void)
    {
        Disable_Interrupts();
        while (elapsed_ticks > 0) { // TRUE only if the ISR ran.
            for (uint32_t i = 0; i < NUM_TASKS; i++) {
                if (--tasks[i].delay == 0) {
                    tasks[i].delay = tasks[i].period;
    
                    Enable_Interrupts();
                    tasks[i].task(); // Execute the task!
                    Disable_Interrupts();
                }
            }
            --elapsed_ticks;
        }
        Enable_Interrupts();
    }
    
    // Count the number of ticks yet to be processed.
    void Timer_ISR(void)
    {
        ++elapsed_ticks;
    }
    

    The above example was take from a blog post entitled "Simple Co-Operative Scheduling".

    A cooperative scheduler is a combination of a super loop and a timer interrupt. From Section 2.4 in NON-BLOCKING HARDWARE CODING FOR EMBEDDED SYSTEMS:

    A Cooperative scheduler is essentially a combination of the two previously discussed schedulers. One timer is set to interrupt at a regular interval, which will be the minimum time resolution for the different tasks. Each task is then assigned a period that is a multiple of the minimum resolution of the interrupt interval. A function is then constantly called to update the interrupt count for each task and run tasks that have reached their interrupt period. This results in a scheduler that has the scalability of the Superloop with the timing reliability of the Time Triggered scheduler. This is a commonly used scheduler for sensor systems. However, this type of scheduler is not without its limitations. It is still important that the task calls in a cooperative scheduler are short. If one task blocks longer than one timer interrupt period, a time-critical task might be missed.

    And for a more in depth analysis, here is a paper from the International Journal of Electrical & Computer Sciences.

    Preemptive versus Cooperative:

    A cooperative scheduler cannot handle asynchronous events without some sort of a preemption algorithm running on top of it. An example of this would be a multilevel queue architecture. Some discussion on this can be found in this paper on CPU Scheduling. There are, of course, pros and cons to each. A few of which are described in this short article on the RTKernel-32.

    As for "any specific type preemptive scheduling scheduling process that can satisfy priority based task scheduling (like in the graph)", any priority based interrupt controller is inherently preemptive. If you schedule one task per interrupt, it will execute as shown in the graph.

    0 讨论(0)
  • 2021-01-06 21:42

    If I knew what the question meant the answer would still probably be Miro Samek's Practical UML Statecharts in C/C++, Second Edition: Event-Driven Programming for Embedded Systems

    0 讨论(0)
提交回复
热议问题