Find the answer to your Linux question:
Results 1 to 6 of 6
If I had two CPU intensive programs or threads running in a single CPU Linux system, two infinite "while(true) i++;" loops for example, both with SCHED_RR (round-robin) attributes will both ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    12

    Question about scheduling in single CPU systems


    If I had two CPU intensive programs or threads running in a single CPU Linux system, two infinite "while(true) i++;" loops for example, both with SCHED_RR (round-robin) attributes will both processes progress or only one?
    I suppose, both would run because they are RR.

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    586
    Linux only gives processes "time slices" and as such it lets all processes to get a "time slice". It does not matter if it is the active window, etc. You can also "renice" processes to change it "priority" (not it is in the form of making this process more nice use less resources and longer run times for number ordering by allowing long jobs to not consume the resources when the completion is not needed right away (hence being "nice" to the other processes (or users) on the machine).

  3. #3
    Just Joined!
    Join Date
    Dec 2011
    Posts
    12
    Yes i know that.So ,do both processes run simultaneusly or not?.I understand yes...

  4. #4
    Just Joined!
    Join Date
    Dec 2011
    Posts
    12
    I will reply myself after my tests in a single 2.6.18 Linux system.Maybe this will help someone.
    Yes, if you had two procesess (Simple C binaries doing a while(1)i++ loop) and after launching them with nohup binary& they will fight for CPU resources,as you can easyly see with a top. Now, you can use chrt to increase its priority and set them round robin SCHED_RR.to do so,you must alsso increase your shell priority above that of yor two running processes.(or yor ssh session by increasing ssh priority then opening a new session)
    If they and your shell are the highest real time processes (rtprio=-40,for example) BUT below the priority of your kernel processes (rtprio=-51 for example) all runs fine. ping to machine works.
    If you set ALL machine processes to SCHED_RR they run for a few minutes,but sooner or later the whole machine blocks,and ping stops responding.I think the reason is there are some kernel real time processes handling interrupts that canīt be preempted and must work SCHED_FIFO.
    In other test,if you set ONLY ONE of those loop processes to SCHED_FIFO without touching piority yo can see in top (higher priority) that only one is running,because he does not yield CPU to other processes below its priority and the other process (RR) its never scheduled.
    Last test: if you have only one RR process in a loop, and other processes in the machine are lower priority, all get collapsed.

    p_j_r_m
    Last edited by lunix; 09-26-2013 at 09:58 PM.

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,175
    Quote Originally Posted by lunix View Post
    Yes i know that.So ,do both processes run simultaneusly or not?.I understand yes...
    On a single core system, only one runs at any time. This is why the scheduler is important. I used to (back in the dark ages of the 80's and 90's - before multi-core systems) write real-time software and the scheduler was critical to proper operation. Read up on RMA (Rate Monotonic Analysis) for more information about dealing with such systems. If your scheduler is not deterministic (the standard Linux scheduler is not such), then you cannot be assured that any thread/application will not starve another of processor cycles. FWIW, your example code of "while(1)++ loop) is good for exposing this...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    586
    Yes, to a human they appear to be running simultaneously due to the smallness of the time-slice. But only one is running at any moment of time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •