3

OSのない組み込みシステムの有限状態マシン(FSM)のさまざまなスケジューリングアルゴリズムを非常によく比較できる優れたリソース(書籍、Webサイト)はありますか?

OSのないシンプルな組み込みWebサーバーを設計しています。システムで発生するさまざまなイベントの処理をスケジュールするために使用されるさまざまな方法を知りたいです。

たとえば、2つのイベントが同時に到着した場合、イベントはどのように優先されますか?イベントに異なる優先度を割り当てる場合、優先度の高いイベントが最初に処理されるようにするにはどうすればよいですか?イベントの処理中にさらに優先度の高いイベントが発生した場合、そのイベントがすぐに処理されることをどのように確認できますか?

FSMを使用して、イベントの到着時にさまざまな条件を確認し、イベントを適切に処理するようにスケジュールすることを計画しています。組み込みWebサーバーにはOSがないため、循環的なエグゼクティブアプローチの使用を検討しています。しかし、このアプローチで使用できるさまざまなアルゴリズムの長所と短所の比較を見てみたいと思います。

4

2 に答える 2

8

質問の意味を知っていれば、答えはおそらくMiroSamekのC/ C ++の実用的なUMLステートチャート、第2版:組み込みシステムのイベント駆動型プログラミングでしょう。

于 2012-08-14T15:15:50.147 に答える
7

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.

于 2012-08-14T17:35:26.147 に答える