In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
What is the scheduling principle of RTOS? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Our series of Wechat tweets is just to help you quickly have a perceptual understanding of the operating system. Of course, to better remember one complex thing is to find another simple thing to explain it. However, the interpretation in this way is totally inconsistent with the rigorous logic that education should have. So let's take back this unscientific argument and use scientific methodology to express what we need to explain.
(1) write a scheduling algorithm by yourself
A long time ago, I probably remember that when I was a sophomore, I began to write a scheduling algorithm myself. The function of its implementation is very simple, which is to make the two "tasks" execute alternately in time-sharing, and use the timer to determine the running time of the two tasks. At that time, I was full of joy to tell the world that I had completed a "kernel" framework.
Now come to think of it, the above behavior is really ridiculous ignorance and satisfaction. Because the implementation of this algorithm is very simple. A brief description of its principle is to create two pointer variables that point to functions, then create two functions, and use the above two variables to point to them. The timer starts to be timed, assuming that the period is 10ms, so you only have to switch two variables every other 10ms. In this way, if you look at the macro, you can see that the two tasks are running at the same time.
To analyze the above things, it sounds very simple, but after careful consideration, they certainly do not conform to any of the characteristics of the operating system. First of all, if the execution time of each task is less than that of 10ms, in case you exceed its time-sharing running time (10ms) and use a timer to switch, then the currently unfinished data will be completely lost, and there is no room for salvation. Second, its tasks cannot be dynamically created and recycled. There are many, many shortcomings. This is something that suddenly dawned on me in my junior year. Therefore, up to now, I do not like to use the timer to generate the count value in the main function and switch the running function according to the count value. Why? Because when you are programming in bare metal, especially when there is a lot of communication waiting for operation in a function, you can't guarantee that the running time of each function is exactly less than the time you set. Therefore, there will always be the phenomenon that some tasks cannot be carried out at all.
But unfortunately, after working later, I found that many electronic engineers deal with the flow of his programs in this way.
(2) the principle of operating system scheduling algorithm
I began to study the operating system, and it was at that time that I confidently used my own "kernel" to do several projects, until once I did a long-distance Modbus high-speed communication, because there was a function in this function that failed to do CRC verification and waited for retransmission. Due to the selection of high-speed data stream and long distance, the distortion of high-frequency signal is more serious, resulting in high bit error rate. So this function is called frequently, but it turns out that it can hardly be run completely. After analyzing the reason for a long time, it was found that the execution time of this function far exceeded the running time I assigned to it, so my scheduling algorithm forced it to be interrupted before it was finished. And because there is no data preservation mechanism, the whole function can only be destroyed in half of the execution. Later, after working, I also encountered other engineers doing this and persuading them to modify it, but they still refused to listen, which eventually led to serious mistakes. Since then, I would rather while (1) to the end than use this way.
For a mature operating system kernel, its scheduling algorithm will save the data after interrupting the current task.
We call the currently running task "running", while the task that is not running is called "non-running". But with regard to "non-running state", this is just a general name, which contains a large number of sub-states. We will explain the specific breakdown of "non-running state" in detail later. Note here that in the logic of our course, all specific non-running states are aggregated in order to simplify the operating system model, which remains to be discussed in some advanced operating systems.
In the case of the most basic time-sharing operating system, it is assumed that all tasks have the same priority and will be automatically polled when the time is up. When the time comes, the operating system will have a mechanism to save the data for which the running task has not been executed, which can be pushed onto the stack. The specific operation process is to save the data in the register, which is somewhat similar to the call of the interrupt function. Then recycle the memory that can be recycled. Then, allocate memory for the next task that needs to be performed, and finally go to the next task that needs to be performed. When it is time for the first unfinished task, memory will be re-allocated, and then the previous data will be taken out and continue to execute. This is the whole general process.
The answer to the question about the scheduling principle of RTOS is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.