# How can i determine the length of a quantum

Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last
• 11-23-2008
Aga^^
How can i determine the length of a quantum
the topic is writing a program that determines the length of a quantum in the OS loaded in the computer.

I think, program is a simple program doing nothing but integer operations for a long time, say for 20secs. Let us run this program twice unless our computer is not dual core system the processes normally will run in 41 says.The one second delay is due to switching. From here, we may calculate how many quanta are used per process; then, we may calculate the duration of a quantum. Our program should measure the time in milliseconds for accuracy.
• 11-23-2008
whiteflags
• 11-23-2008
Aga^^
how can be this program in c?can you give me some examples?
• 11-23-2008
matsp
I don't think the description of the problem is accurate in the first post. You want to measure the amount of time of the overhead of running two processes instead of one, and from that determine the quanta? In my (computer) vocabulary, quanta means the amount of time a process may run continously before another runnable process gets switched in.

Now, lets say that we have a 20 second runtime, and we run the process twice at the same time, and it now take 41 seconds to complete. What does that tell us? Nothing. Because we do not know HOW LONG it takes to switch from one task to another, and we do not know how many times those two tasks switched.

It gets even worse if we have a modern processor, as modern processors are rather complex and not entirely predictable when it comes to cache-hitrate and other complicated matters that affect the overall time the application runs.

There may well be ways to determine how long the quanta is, but I doubt that it's as simple as what you describe.

--
Mats
• 11-24-2008
Feline
i am asked to determine the length of a quantum in the operating system and writing a set of comp. progs in a high level of language C. One of the progs is a simple prog doing nothing but integer operations for a long time, say for 20secs. Let us run this program twice ( you may want to have another program to run it twice with the least possible delay) Unless your system is a dual core system, the two processes will run slightly longer than twice as they would normally run, say 41 secs. The one second delay is due to switching. From here we may calculate how many quanta are used per process, then we may calculate the duration of quantum. The program should measure the time in milliseconds for accuracy. You may have other ideas such as running more than two copies of program in parallel...
• 11-24-2008
matsp
Feline, are you the same person as Aga, or just in the same class? Is there some part of my answer in post 3 that you do not understand the concept of.

Running two instances of the application will tell you the overhead of running two applications at once, but it will NOT tell you the scheduling quantum parameter - because you do not know either of how many task switches there are, or the amount of time that a schedule another task in itself takes. These values in themselves vary a bit depending on cache-hit-rate in the scheduler just to mention ONE of many parameters.

There is probably a way to determine the scheduling of the processor (at least get some reasonable measure of the apparent values), such as reading a high precision timer in a tight loop in two different processes, and seeing if there are "gaps" in the time. If there is a gap, that's the amount of time another process ran for.

Of course, the next problem is that other processes than yours WILL run on a system - so you may receive a network package that requires the computer to do some sort of work, and that interferes with your current task. That's part of the overhead of a computer.

--
Mats
• 11-24-2008
Aga^^
Code:

```#include <stdio.h> int main() {         double a=0;         double i;         double total;         for(i=0;i<1000000;i++)         {                 a=a+i;         }                 total=a;         printf("Sum of numbers %d :",total);         return 0; }```
the output of this code is -1179123712 how can be this i can not understand. :(
• 11-24-2008
matsp
Quote:

Originally Posted by Aga^^
Code:

`        printf("Sum of numbers %d :",total);`
the output of this code is -1179123712 how can be this i can not understand. :(

Because you are printing a double as a integer value.

--
Mats
• 11-24-2008
root4
&#37;d is not what you meant to use, read the doc...
• 11-24-2008
Aga^^
for 2 years i have not used c so i forgot some things :confused:
Code:

```#include <stdio.h> int main() {         double a=0;         double i;         double total;         for(i=0;i<1000000;i++)         {                 a=a+i;         }                 total=a;         printf("Sum of numbers %lf :",total);         return 0; }```
now how can i measure the length of a quantum?
• 11-24-2008
matsp
Like I said earlier, you can't with that type of code (unless I've been working with operating systems and task switching code for 15+ years and not understood how they work...)

--
Mats
• 11-24-2008
Aga^^
hmm you are right. but a little part of the code about measuring the quantum is enough for me
• 11-24-2008
matsp
Quote:

Originally Posted by Aga^^
hmm you are right. but a little part of the code about measuring the quantum is enough for me

Like I said, measure time with reasonably high precision (QueryPerfomanceCounter on Windows, gettimeofday in Linux) in a tight loop, and see if there are "gaps". Run two of those processes at the same time, and the "gaps" should correspond to the quantum.

--
Mats
• 11-25-2008
vart
double needs &#37;f format in printf, %lf format is for scanf
• 11-25-2008
Aga^^
i tried it and both &#37;f and %lf gives the same result. (i looked it from an document)
Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last