Thread: How can i determine the length of a quantum

  1. #1
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71

    Question 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.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    And your question would be?

  3. #3
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    how can be this program in c?can you give me some examples?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    1
    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...

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    So you may know that the overhead of running two applications is 1.52 seconds. But if the OS task switched once, 100 times or 10000 times will not be something you know. And you also do not know how much overhead EACH task switch takes. That would vary depending on lots of things - try writing a program that sums all numbers 0..1000000 [to make sure it doesn't overflow, make the result a double] a few hundred times (enough to take 20 seconds, say). Then do the same task again, but instead of using a simple counter, fill a 1 million entry array [make the array a global variable] with with the values 0..1000000 in the array, and calculate the sum by reading the array instead of just adding a loop variable to the sum. This will use 4MB of memory instead of a few dozen bytes for each complete loop. Run both once and then two copies. I think you'll find that the overhead in the array case will be MUCH larger (as a proportion of the time taken).

    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    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.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Aga^^ View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    &#37;d is not what you meant to use, read the doc...

  10. #10
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    thanks for your helps
    for 2 years i have not used c so i forgot some things
    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. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    hmm you are right. but a little part of the code about measuring the quantum is enough for me

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Aga^^ View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    double needs &#37;f format in printf, %lf format is for scanf
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  15. #15
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    i tried it and both &#37;f and %lf gives the same result. (i looked it from an document)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  3. How to determine length of pointer array
    By Dr.Zoidburg in forum C Programming
    Replies: 12
    Last Post: 02-16-2009, 06:52 PM
  4. Determine length of an array
    By ulillillia in forum C Programming
    Replies: 7
    Last Post: 04-21-2007, 08:32 PM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM