3

I am working on a time-consuming computation algorithm and want to run it as fast as possible.

How much presence (running algorithm under it) of Operating System (Windows or Linux) slows the process?

Is there any example of "OS" specifically implemented to run predefined program?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Slaus
  • 2,086
  • 4
  • 26
  • 41
  • 'As fast as possible' is a non-requirement; set yourself a measurable goal (e.g. runs daily, so must be completed within 24 hours). The benefit of eliminating OS overhead is limited. Try to distribute your process across multiple cores, even multiple (hosted) machines; particularly important when processing time is proportional to the size of an ever-growing data set. Any other optimizations (less OS overhead, assembly code) might be surpassed by faster hardware ([Moore's law](http://en.wikipedia.org/wiki/Moore%27s_law)) by the time you completed your effort. – Ruud Helderman Aug 24 '14 at 11:27
  • That's a very good point. Extending the hardware; optimising the code; doing other real-life stuff (I'm serious as being a man is also a target) - in importance descending order. Some resources measure overhead to be 3-30%, for example: https://upcommons.upc.edu/e-prints/bitstream/2117/6579/1/Radojkovic.pdf - sadly it's processor specific but subject is too narrow to find at least anything about it. – Slaus Aug 24 '14 at 17:19
  • So, when you rent or manage supercomputer you gotta pay ~500 dollars per hour making it definitely a good deal trying to save it's ~20% power what is 360000 * 0.2 = 72000 dollars per month. Another positive side is that such task is pretty easily delegated. – Slaus Aug 24 '14 at 17:22
  • Btw, I do measure the "get rid of OS" task even less complicated than "rewrite everything to assembly" and do not expect any optimization from it, do you? – Slaus Aug 24 '14 at 17:25
  • 3
    if you really want to remove any possible overhead you can try: BaremetalOS http://www.returninfinity.com/baremetal.html – Nazar554 Aug 24 '14 at 18:48
  • @Nazar554 it's just a bull eye! The best I wanted to find out is a sample to ever implemented program which just runs on naked hardware but IT infrastructure continues to impress with it's high development stage. Thank you very much! – Slaus Aug 24 '14 at 18:56
  • Even it's name is cool: BareMetal :). I was trying to expose the task as "naked hardware" but it's better. – Slaus Aug 24 '14 at 18:59

3 Answers3

4

First of all I'd like to introduce that I am also working on a very similar topic time-consuming computation algorithm! So much common here OR maybe just a co-incidence...

Now,let's proceed to the answer section :-

Presence of the process(your algorithm which is running) in OS is affected by daemons and other available user programs waiting in the ready queue depending on the scheduling algorithm applied by your OS. Generally, daemons are always running and some of the system applications related process just preempts other low-priority processes(maybe like your's if your process has lower priority,generally system processes and daemons preempt all other processes). The very presence of OS(Windows Or Linux)---I am considering only their kernel here--- doesn't affect as the kernels are the manager of the OS and all process and tasks. So,they don't slow the process but daemons and system processes are heavy one and they do affect your program significantly. I also wish if we could just disable all the daemons but they are just for the efficient working of OS(like mouse control,power efficiency,etc) all in all...

Just for an example, on Linux and Unix based systems, top command provides an ongoing look at processor activity in real time. It displays a listing of the most CPU-intensive tasks on the system.

So, if you will execute this code on a Linux system,you'll get the result of all the heavy processes which are intensely consuming memory! here, you'll find that apart from your process which is heavily utilising memory there are several daemons like powerd, moused, etc., and other System processes like Xorg,kdeinit4,etc... which does affect the user processes !!!

But, one thing is clear that each process or daemons generally won't occupy more memory than your intense computation algorithm process! The ratio will be lesser instead may be one-eighth,one-fourth!!!

UPDATE BASED ON COMMENTS :-

If you're specifically looking for the process to be running on the native hardware without OS facilitation/installation---you have got two choices.

Either develop the code in machine-level language or assembly languages or other low-level languages which will directly run your process on the hardware without the need for OS to manage memory sections and all and other system processes and daemons!

Second solution is to develop/utilise a very minimal OS comprising of only those settings which are required for your algorithmic program/process! And,then this minimal OS won't be a complete OS---thereby lack of daemons,multiple system calls as in major OS' like Windows,Linux,Unix,etc.

One of the useful link which Nazar554 has provided in the comment section.I'll just quote him :-

if you really want to remove any possible overhead you can try: BareMetal OS

In your case,it seems you are preferring the first option more than the other. But,you can achieve your task in either way!

LATEST EDIT :-

It's just a feedback from myside as I couldn't get you more clearly! It would be better if you ask the same question on Operating Systems Beta as there are several experts sitting to answer all queries regarding OS development/functionality,etc! There you'll receive a more strong and positive response regarding every single tiny detail which is relevant to your topic that I might have missed.

Best wishes from myside...

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
  • For now, I'm getting values of 5-30%% of OS overhead, but when you talk about "half, one-fourth" - it's absolutely hilarious and worth rewriting. What about any samples of programs run on naked hardware? – Slaus Aug 19 '14 at 19:30
  • The first one was simply to demonstrate the general idea of ratio and also the maximum ratio range! Second--->`What about any samples of programs run on naked hardware?`---What??? – Am_I_Helpful Aug 19 '14 at 19:31
  • I suppose that last question is also answered within deleted comments? ;) – Slaus Aug 19 '14 at 21:44
  • I mean, we agreed to remove all the comments which we are clear on. Update your answer also please. – Slaus Aug 19 '14 at 21:46
  • @Slav-I have updated it.THANKS anyways for constructive criticism.Good question though, I've already upvoted it! – Am_I_Helpful Aug 19 '14 at 21:54
  • Thanks to you! Now I can expose my problem much better! – Slaus Aug 19 '14 at 22:01
  • Couldn't figure out why downvoted! – Am_I_Helpful Aug 20 '14 at 03:10
  • I'm sorry, but trying to give an advice within a very narrow subject having no understanding of how the things work is not a good mood - it just causes many misunderstandings what did for us. It's not a specific knowledge - it's just a common one within IT area. Your answer shows absence of knowledge within any of these subject: Von Neumann Architecture, ALU, memory addressing, "page", computer structure layering. I strongly recommend you [this book](http://www.amazon.com/Structured-Computer-Organization-5th-Edition/dp/0131485210). – Slaus Aug 24 '14 at 17:50
  • @Slav-No problem for downvoting but I must add that I already have the knowledge of computer organisation or architecture. Also, I can have another discussion on ALU,von-Neumann Architecture,Paging,Segmentation,even Harvard architecture and so on! Anyways ,as OP wishes I can't give my own mind over this!!! – Am_I_Helpful Aug 24 '14 at 17:53
  • I appreciate you answer my question, but letting question unanswered is better the confuse and it's better leave it unanswered since putting in a wrong direction can hurt even more. Btw, we agreed on remove our commends under this answer which was already answered. I suppose your top question was also answered and should be removed. – Slaus Aug 24 '14 at 17:53
  • Sorry, what is "OP"? – Slaus Aug 24 '14 at 17:54
  • OP is `you` being referred here---Original Poster of the question. Also,the second answer also uses the same guidelines like `Daemons`,`Interrupts/preemption` which I used. I really don't know what specific thing/detail do you want!Also, I must add that your process won't be that much atomic as you already mentioned that your process/application is intensive memory consuming! – Am_I_Helpful Aug 24 '14 at 17:57
  • It's me, thank you. Yeah, seems like I have problems exposing my problem since people answer the different way I expect. What do you mean under "not that much atomic"? Please clarify. – Slaus Aug 24 '14 at 18:02
  • An extensive memory consuming process is not to be considered atomic---the reason being as the process is consuming memory,so it can be break down into several parts(threads) which will run in parallel to achieve the task. But,it's not necessary that it'll be parallel process,it can be atomic(though with a minimal chance)---No one knows what other is interested in AS in our last discussion you dragged me up to the Assemby Programming as I was not getting over that topic! – Am_I_Helpful Aug 24 '14 at 18:06
  • 1
    Also,my friend,you have got a separate website to discuss that---`www.operatingsystems.stackexchange.com`---Please try on that! I feel you'd get a more deeper detail. I will be following your question over there as i am already a member of it! – Am_I_Helpful Aug 24 '14 at 18:09
  • That's HUGE! Thank you! I suppose that's an answer for stackoverflow side. Issue such one and I'll accept it and move to that site. Any clarification of my question would be also appreciated - since I have some problems with exposing it on my own ... – Slaus Aug 24 '14 at 18:25
  • I'd simply suggest you to simply provide more and every tiny detail you wanna know about! Like you didn't clarify here that you're ready to operate without OS/kernel! It came to me after our long discussion. Please add every detail so that you'd get each and every tny response. My best wishes for you. Hoping to follow that question very soon on `www.operatingsystems.stackexchange.com`! – Am_I_Helpful Aug 24 '14 at 18:28
  • OK, I understand - will point out the possible kernel absence. So, could you make an answer in a form of redirecting me to that side so I can authorize your proposition as an accepted one? – Slaus Aug 24 '14 at 18:32
  • @Slav-Check the `latest edit` section. THANKS FOR YOUR HUMBLE BEHAVIOUR! – Am_I_Helpful Aug 24 '14 at 18:39
  • The acceptance is applicable in 14 hours, oops :) Btw, I would like your answer to consist of only the "LATEST EDIT:-" part, but never mind. – Slaus Aug 24 '14 at 18:51
  • Oh, sorry, edit it please somehow (just a character) so I can upvote it - it's locked now. – Slaus Aug 24 '14 at 18:57
0

The main idea in giving processor to a task is same among all major operating systems. I've provided a diagram demonstrating it. First let me describe this diagram then I'll answer your question.

enter image description here

Diagram Description

When a operating system wants to execute some tasks simultaneously, it can not give processor to all of them at once. Because processor can process a single operation at a time and it can't do more that one tasks processing at the same time. Because of it OS shares it among all tasks in a time-slot by time-slot manner. In other words each task is allowed to use the processor just in its own time slot and it should give the processor back to the OS once its time slot finished.

Operating systems uses a dispatcher component to select and dispatch a pending task to give the processor to it. What is different among operating systems is how the dispatcher works, What does a typical dispatcher do? in simple words :

Answer to your question

How much presence (running algorithm under it) of Operating System (Windows or Linux) slows the process?

It depends on:

  1. Dispatcher algorithm (i.e. which OS do you use)
  2. Current loads on the system (i.e. how much applications and daemons is running now)
  3. How much priority have your process task (i.e. real-time priority, UI priority, regular priority, low ,...)
  4. How much I/O stuff is going to be done by your task (Because I/O requesting tasks usually are scheduled in a separate queue)

Excuse me for my English issues, because English isn't my native language
Hope it helps you

Community
  • 1
  • 1
frogatto
  • 28,539
  • 11
  • 83
  • 129
  • 1
    I do know how OS works, I didn't asked to explain me about it. "Dispatcher algorithm (i.e. which OS do you use)" - I can use any of Windows or Linux. "Current loads on the system" presence of side processes do not slow any of them since they just share the processor, no computation power loss. "How much priority have your process task" - OS doesn't idle when it has nothing to do regardless the priority of processes. "How much I/O stuff is going to be done by your task" - also, it's just another specific process - OS doesn't suspends it or idles around it where there is anything present to do. – Slaus Aug 24 '14 at 17:36
0

Try booting in single-user mode.

From debian-administration.org and debianadmin.com:

Run Level 1 is known as 'single user' mode. A more apt description would be 'rescue', or 'trouble-shooting' mode. In run level 1, no daemons (services) are started. Hopefully single user mode will allow you to fix whatever made the transition to rescue mode necessary.

I guess "no daemons" is not entirely true, with wiki.debian.org claiming:

For example, a daemon can be configured to run only when the computer is in single-user mode (runlevel 1) or, more commonly, when in multi-user mode (runlevels 2-5).

But I suppose single-user mode will surely kill most of your daemons.

It's a bit of a hack, but it may just do the job for you.

Ruud Helderman
  • 10,563
  • 1
  • 26
  • 45
  • 1
    Sorry, the question was is "how much presence of OS slows the process" and "is there any existing solution of a program to run on naked hardware"? I didn't asked how to speed up Linux or Windows. :( – Slaus Aug 24 '14 at 17:31
  • You very clearly expressed the desire to "run it as fast as possible." Single-user mode eliminates a lot of processes that might otherwise share the CPU with your process. When in single-user mode, do some performance profiling (e.g. with [time](http://linux.die.net/man/1/time)) to determine how much OS overhead is left. If your process would still be allotted well below 100% of the CPU, then indeed, you might be better off without an OS. Though you may have some trouble getting the output of your process to the outside world without one... – Ruud Helderman Aug 24 '14 at 18:43
  • Basic output can be done pretty easily with BIOS. time() displays the percentage of resources usage already UNDER the OS, but it won't display the OS itself overhead. Even if it will say "100% of processor is used by your process" it doesn't mean that complete OS remove won't increase productivity by, say, 1000%. – Slaus Aug 24 '14 at 19:18
  • "one thousand" is because we don't know the OS overhead that's why I took some great value out of my mind. That was the question: "how much presence of OS slows the process" and "1000%" is still a possible answer. – Slaus Aug 24 '14 at 19:20
  • 1
    The overhead you seek is `Real` minus `User+Sys` (assuming the process runs on a single core); see http://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1 But feel free to use a different profiler if you feel more confident with that. – Ruud Helderman Aug 24 '14 at 19:43