How to we assign deadline in QNX?

Ok, I am new to real-time programming and QNX. I have a question that I guess is too basic to ask but I really need to figure it out!

We know that a real-time OS can gurantee that if a task is supposed to finish at a given deanline, it will! But my question is that how do we assign such dealline for such thread?
I mean say, we have a periodic task that is supposed to run every 3ms and it is hard realtime. How do I setup such a thread in QNX? One method that I could think of is to set a timer that send a message to my thread every 3ms and activate it but this is not assigning deadline to this thread. what if something unpredictable happend and the OS take care of that and my task lose its HRAD real time features? In other word, how to I do strictly make qnx to run a thread every say 3ms and make it to arrange everything in such a way that no matter what, the task runs every 3ms. back to my question, how do we assign deadline for a task in QNX?

Thanks for your help in advance.
Mike

What you can do is setup a thread and create a timer which will fire a pulse every 3ms. Assign the pulse the highest priority possible and make sure that thread only deal with that pulse (not other messages). The only thing that will disrupt that thread are hardware interrupt or other hardware related issue.

You could also do the work in an interrupt routine but I’d stay away from that ;-)

The concept of deadline is more then an OS issue, it’s a design issue. If you need to do something that last 2.99 ms every 3ms that won’t work ;) You cannot specify when an operation must be completed (deadline) you can only control when it starts and who can or cannot disrupt it.

Thanks a lot mario! But, I still have this question that what if a thread that we had expected to finish in that say 3ms, couldn’t complete its task because of some unpredictable events that the designer couldn’t think of? Porbably, the answer is we have to know how much time that thread needs to complete its job but i guess this is not 100% possible. First of all what happens in such a case ? Secondly, is there any way to prevent this?

Plus, as a new real-time programmer, I have learned all the basic of real-time OS but I still cann’t find a good source that could teach me how to use these basics and design a real-time software!!! I know all about mutex, synchronization, message passing, timers,… but I can’t find a good source that I could learn how to efficiently use these tools and desing a real-time software. I have the QNX cookbook but it’s kinda vague for me. I need something that step by step show me the desing of a real-time software using the above tools in any similar OS. Do you know any source?
Plus, do we have any good CASE tool for real-time softwate desing proper for QNX ?

Thanks a lot for your help in advance!

I thought you are not suppose to have “unpredictable events” in a real-time OS ?

As xtang said, if your system has “unpredictable events” then it becomes unpretictable in nature. You have to know your hardware and understand how it behaves.

If the job that needs to be perform every 3ms usually takes 2 ms but then because of extra calculation it takes 3.3ms, then you are screw. Solution are to get a faster processor, rework you algorithm or abort the calculation.

If the process takes 3.3 ms because of external source like a higher priority process grabbing the CPU then you need to make you process high priority then the process/thread that is stealing CPU time.

If interrupt is stealing CPU time then you need to be higher priority then the interrupt or disable the priority or remove the cause of the interrupt.

I’ll try to use an analogy. You have a car, top speed is 100km. You have to drive from A to b (distance 100km) in 59 minutes. When all is well you can make the trip back and forth without any problem and have a minute to spare. But one day you get a flat tire and it takes 2 minutes to fix it, you will be late. There is no way you can enforce arrival time ( deadline ). There is no law of physic that can guaranty you will make it in less then 60 minutes, you can only plan for all potentiel delay and get preparre to deal with them; only solution is to get a faster car to account for possible delay, turn around and give up or get a car with steel wheels ;-)

Try reading the following introduction to RMA.

It demonstrates how deadlines can be met (and proven to
have a feasible schedule) from the rates of periodic execution
and the priorities assigned to different tasks of different rates.
The deadline is implicit from the period. The analysis proves (based
on “cost” of execution) whether the deadline will always be met (or not).

netrino.com/Publications/Glossary/RMA.html

Longer (aperiodic) deadlines are also possible, but the analysis is
trickier, involving partitioning the problem into quanta and using
something like Sporadic Server Scheduling to ensure that it only
runs above higher priority periodic tasks within its quanta.

Replying to my own message.

A key thing missing from that article is the calculation of processor
utilization (Cost, C, is in wall clock time):

Sum[i=1->n](Ci/Ti) 

Giving the schedulability invariant:

Sumi=1-.N <= Wn

It also avoids the second order analysis that looks at how long
each task may be blocked waiting for a resource (e.g. mutex)
shared with a higher priority task: you add the blocking “factor”
to the cost for each task. N.B. Since the higher priority task
always has a shorter period, the blocking factor must also be shorter.