Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Preemptive multitasking

Status
Not open for further replies.

Kittu20

Member level 2
Joined
Oct 18, 2022
Messages
52
Helped
1
Reputation
2
Reaction score
0
Trophy points
6
Activity points
427
I'm trying to understand the basics fundamental of preemptive multitasking.
I found multitasking is a method that allows multiple Tasks to share (CPU time).


Let's say we have a Tasks like this

Task 1 - Middle Priority
Task 2 - Lower Priority
Task 3 - High Priority

A single core CPU can execute only one task at a time. Hence CPU will always execute Task 3 as it is higher priority task.

I do not understand that if Task 3 will always be executed then when will the rest of the Task get CPU time.
 

I'm trying to understand the basics fundamental of preemptive multitasking.
I found multitasking is a method that allows multiple Tasks to share (CPU time).


Let's say we have a Tasks like this

Task 1 - Middle Priority
Task 2 - Lower Priority
Task 3 - High Priority

A single core CPU can execute only one task at a time. Hence CPU will always execute Task 3 as it is higher priority task.

I do not understand that if Task 3 will always be executed then when will the rest of the Task get CPU time.

Priority is not the only factor, although it could be.

Some priorities could be total hog of cpu, like life saving events, or
chemical processes that could create huge explosions, damage to
plant and capital equipment, etc..

One can assign both priority and a limit to hog time via time slice settings.

1673717538292.png



You are in control of these settings. So you can set some tasks that never get processed,
mistake obviously, or ones with low priority but a minimal non zero time slice.

There is no limit to how CPU is allocated if you write your own RTOS, as conceptually they
are fairly simple, or modify an open source RTOS. You could assign cpu time with a 100 variable
determined assignment algorithm. The sky is the limit.

So in the time slice and priority scheme, one keeps feeding the priority while also monitoring
who has had no time over some interval, and when that min is not met that low priority
task gets its minimal time slice of execution, then back to feeding the high priority tasks.

YouTube has lots of vid on RTOS fundamentals.

If I am not mistaken YouTube has some vid on DIY RTOS, certainly the web has as well.


Regards, Dana.
 
Last edited:
Hi,

I guess I have a different way to solve problems. Thus I'm not much of help anymore.

Klaus

@KlausST

I don't understand how you solve that problem which is related to task state model of RTOS. I gave a reference link only definition is written, there is no real world example. that's why i didn't understand them.

if you explain in a bit more detail, I'm willing to spend my time and research on this.
 

Hi,
if you explain in a bit more detail, I'm willing to spend my time and research on this.
Do I get this right?
First I have to do something for you...then you are willing to spend your time.

Thank you for your offer, but I'm fine if you don't spend time for me.

Klaus
 

Hi,

Do I get this right?
First I have to do something for you...then you are willing to spend your time.

Thank you for your offer, but I'm fine if you don't spend time for me.

Klaus
I had spent more time and researched on this before but still I do not understand. I would like to do more research if you help me to understand those definition with real world example.
 

I had spent more time and researched on this before but still I do not understand. I would like to do more research if you help me to understand those definition with real world example.
Have you gone over to YouTube ? There are quite a few videos on this
topic, maybe one will give you insight.

Quite a few hits oif you google "real world example rtos".......


Regards, Dana.
 

I would like to do more research if you help me to understand those definition with real world example.
Plenty of tips for free on this thread, provided by reputable and patient mebers - two of them giving it up - for whose you urge for help with an unusual conduct, demanding answers formatted as per your requisites. Since tutorials apparently did not meet your need, and considering that your application seem not so demanding for a multithread OS, I would recommend to adopt a baremetal programming approach, interrupt driven for critical tasks...or try to comprehend how to make effective searches on the Web for general and illustrated information; thereafter, feel free to make specific questions.
 
Hi,


The problem with your examples is that you just give half of the information.
You need to consider
* how often the task is called
* how long each task takes
Klaus

@KlausST

Does it makes any sense to you?

Task 1 runs twenty times for 10 ms in every 1000 ms
Task 2 runs twice for 250 ms in every 1000 ms
Task 3 runs once for 10ms in every 1000 ms

1) Task 1 - 20 time for 200 ms.
2) Task 2 - 2 times for 500 ms
3) Task 3 - 1 time for 100 ms

1) Task 1 - 10 ms.
2) Task 2 - 250 ms
3) Task 3 - 100 ms
 

Hi,

makes sense now.

A diagram can now show:
* when each task is requested
* when each task is performed
* which task has higher / lower priority.

Task 1: 20x 10ms every 1000ms (every 50ms) = 20% processing power
Task 2: 2x 250ms every 1000ms (every 500ms) = 50% processing power
Task 3: 1x 100ms every 1000ms (every 1000ms) = 10% processing power

So you need to give Task1 a higher priority than Task2 .. because every task needs to be finished (in some cases: at least started) before it gets requested again.

I couldn´t do without a drawing. But I won´t do the drawing for you.

Klaus
 
Hi,

I couldn´t do without a drawing. But I won´t do the drawing for you.

Klaus
I have no idea what kind of timing diagram you want me to draw or what kind of timing diagram you draw for RTOS. if you explain it a bit i can try to make it.


1675195333553.png


There is a kind of diagram which shows the task state for freeRTOS but it is not a timing diagram.
 

Hi,

Nowadays it's really hard to find informations.
When I was younger we at least had libraries ... and a bicycle to ride to the next town.

Klaus
 
Timing diagram.

At the most basic level I assume you know how much time you need for each
task, that you have timed that process with a simple test, like set a pin, invoke task, reset
pin, and time between pin edges is time to execute task. If task timing has dependencies,
then set up with worst case time gobbling parameters / values before you run the test.
This, couple with how often the task has to run to meet some real time constraint allows
you to move to the next step. Even allows you to catagorize MIPS needed and then by
totaling all of them making a finding if your machine has enough MIPS to accomplish the
tasks.

Once you know this you can then move on to setting up scheduler and test, with pins again.
Even use a scope to trigger off a task that does not occur often enough, and or takes too long
to execute. Detective work.

You are trading off absolute determinacy of complex system with ease of overall process
management. In fact you are increasing determinacy of asynchronous processes in one
sense. In effect this is creating a factory where you, as designer, have tons of processes,
some random, some determinant, to make the factory run smoothly.

https://www.design news.com/do-you-need-rtos-yes-and-here-are-7-reasons-why



Regards, Dana.
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top