How does a computer sleep/wait without using all of its processing power?












3















Something I've never quite understood is how a computer can operate without using all of its processing power. (Likely this confusion stems from a dreadful OS class in college.)



As far as I know, a thread (such as the OS's scheduler) has to be doing something at any given point in time. If there's nothing to do, it just loops until there is something to do. A loop of this nature, I would think, would always run as fast as it can, which would eat up all of a processor's computing power.



I'm guessing my misunderstanding is a wrong assumption that "if there's nothing to do, it just loops". I don't know what else it could do, however.










share|improve this question























  • Well, first correction: In Windows at least, the OS's scheduler isn't a thread. As for "what else it could do" if there's nothing to do, read up on the HLT (halt) instruction. Read also about CPU power-saving states.

    – Jamie Hanrahan
    Jan 11 at 20:17


















3















Something I've never quite understood is how a computer can operate without using all of its processing power. (Likely this confusion stems from a dreadful OS class in college.)



As far as I know, a thread (such as the OS's scheduler) has to be doing something at any given point in time. If there's nothing to do, it just loops until there is something to do. A loop of this nature, I would think, would always run as fast as it can, which would eat up all of a processor's computing power.



I'm guessing my misunderstanding is a wrong assumption that "if there's nothing to do, it just loops". I don't know what else it could do, however.










share|improve this question























  • Well, first correction: In Windows at least, the OS's scheduler isn't a thread. As for "what else it could do" if there's nothing to do, read up on the HLT (halt) instruction. Read also about CPU power-saving states.

    – Jamie Hanrahan
    Jan 11 at 20:17
















3












3








3








Something I've never quite understood is how a computer can operate without using all of its processing power. (Likely this confusion stems from a dreadful OS class in college.)



As far as I know, a thread (such as the OS's scheduler) has to be doing something at any given point in time. If there's nothing to do, it just loops until there is something to do. A loop of this nature, I would think, would always run as fast as it can, which would eat up all of a processor's computing power.



I'm guessing my misunderstanding is a wrong assumption that "if there's nothing to do, it just loops". I don't know what else it could do, however.










share|improve this question














Something I've never quite understood is how a computer can operate without using all of its processing power. (Likely this confusion stems from a dreadful OS class in college.)



As far as I know, a thread (such as the OS's scheduler) has to be doing something at any given point in time. If there's nothing to do, it just loops until there is something to do. A loop of this nature, I would think, would always run as fast as it can, which would eat up all of a processor's computing power.



I'm guessing my misunderstanding is a wrong assumption that "if there's nothing to do, it just loops". I don't know what else it could do, however.







operating-systems task-scheduler parallel-processing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 9 at 19:42









dx_over_dtdx_over_dt

14610




14610













  • Well, first correction: In Windows at least, the OS's scheduler isn't a thread. As for "what else it could do" if there's nothing to do, read up on the HLT (halt) instruction. Read also about CPU power-saving states.

    – Jamie Hanrahan
    Jan 11 at 20:17





















  • Well, first correction: In Windows at least, the OS's scheduler isn't a thread. As for "what else it could do" if there's nothing to do, read up on the HLT (halt) instruction. Read also about CPU power-saving states.

    – Jamie Hanrahan
    Jan 11 at 20:17



















Well, first correction: In Windows at least, the OS's scheduler isn't a thread. As for "what else it could do" if there's nothing to do, read up on the HLT (halt) instruction. Read also about CPU power-saving states.

– Jamie Hanrahan
Jan 11 at 20:17







Well, first correction: In Windows at least, the OS's scheduler isn't a thread. As for "what else it could do" if there's nothing to do, read up on the HLT (halt) instruction. Read also about CPU power-saving states.

– Jamie Hanrahan
Jan 11 at 20:17












2 Answers
2






active

oldest

votes


















5














Computers have hardware timers that can be used to signal the processor when a particular length of time has passed. One such item is the High Precision Event Timer (HPET), and back in the history of things even the RTC could fulfil a similar purpose.



The CPU also has the ability to halt execution units using the HLT instruction and effectively put itself to sleep. No loops run and for all intents and purposes the CPU is dead except for hardware that waits for interrupt lines to be asserted.



Rather than spin-waiting through a loop the processor simply tells the hardware to alert it when a particular time has passed and then puts the core execution units to sleep. Once the time has passed the timer asserts an interrupt, which in turn wakes the CPU and execution starts again.



Low precision timers such as the RTC would work in a similar way, for every number of ticks you check the count on each tick and sleep until the next one comes along. It's a relatively low cost (processor power wise) way to implement wait states.






share|improve this answer


























  • Hah, I've lived so long in the upper layers of software, where code just uses hardware for its own purposes, that it didn't even occur to me that hardware could be the one to signal the software. That embarrassing.

    – dx_over_dt
    Jan 9 at 20:19






  • 1





    @dx_over_dt in all fairness as far as the actual software is concerned it does just look like the CPU runs all the time, it's just that the CPU likes to take lots of naps and has a very loud, very accurate alarm clock and the OS scheduler spends a lot of time wandering around blearily saying "there's nothing to do here so let's have another 5 microsecond nap" or "jeez Program, are you still running? I haven't had a nap in ages so could you just ask for something from the disk so we can both go to sleep?"

    – Mokubai
    Jan 9 at 22:31





















1














Mokubai gives the correct answer for how sleep generally works. But even if the computer were spin-looping, it could still use less power than normal. Different instructions use different amounts of power, depending on what they do. Reading from RAM will use more power than reading from the CPU cache, and while it's in a tiny spin loop it should just use cache. While it's looping the parts of the CPU that perform arithmetic or interact with external devices are inactive, so they don't use any power. If it's a laptop, the screen will be shut down, and that should be a huge power saving.



This all isn't as good as going almost totally dead except for the event timer. But I think some operating systems have "low power mode" that's in between normal running and sleeping, which may incorporate some of this.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1392423%2fhow-does-a-computer-sleep-wait-without-using-all-of-its-processing-power%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    Computers have hardware timers that can be used to signal the processor when a particular length of time has passed. One such item is the High Precision Event Timer (HPET), and back in the history of things even the RTC could fulfil a similar purpose.



    The CPU also has the ability to halt execution units using the HLT instruction and effectively put itself to sleep. No loops run and for all intents and purposes the CPU is dead except for hardware that waits for interrupt lines to be asserted.



    Rather than spin-waiting through a loop the processor simply tells the hardware to alert it when a particular time has passed and then puts the core execution units to sleep. Once the time has passed the timer asserts an interrupt, which in turn wakes the CPU and execution starts again.



    Low precision timers such as the RTC would work in a similar way, for every number of ticks you check the count on each tick and sleep until the next one comes along. It's a relatively low cost (processor power wise) way to implement wait states.






    share|improve this answer


























    • Hah, I've lived so long in the upper layers of software, where code just uses hardware for its own purposes, that it didn't even occur to me that hardware could be the one to signal the software. That embarrassing.

      – dx_over_dt
      Jan 9 at 20:19






    • 1





      @dx_over_dt in all fairness as far as the actual software is concerned it does just look like the CPU runs all the time, it's just that the CPU likes to take lots of naps and has a very loud, very accurate alarm clock and the OS scheduler spends a lot of time wandering around blearily saying "there's nothing to do here so let's have another 5 microsecond nap" or "jeez Program, are you still running? I haven't had a nap in ages so could you just ask for something from the disk so we can both go to sleep?"

      – Mokubai
      Jan 9 at 22:31


















    5














    Computers have hardware timers that can be used to signal the processor when a particular length of time has passed. One such item is the High Precision Event Timer (HPET), and back in the history of things even the RTC could fulfil a similar purpose.



    The CPU also has the ability to halt execution units using the HLT instruction and effectively put itself to sleep. No loops run and for all intents and purposes the CPU is dead except for hardware that waits for interrupt lines to be asserted.



    Rather than spin-waiting through a loop the processor simply tells the hardware to alert it when a particular time has passed and then puts the core execution units to sleep. Once the time has passed the timer asserts an interrupt, which in turn wakes the CPU and execution starts again.



    Low precision timers such as the RTC would work in a similar way, for every number of ticks you check the count on each tick and sleep until the next one comes along. It's a relatively low cost (processor power wise) way to implement wait states.






    share|improve this answer


























    • Hah, I've lived so long in the upper layers of software, where code just uses hardware for its own purposes, that it didn't even occur to me that hardware could be the one to signal the software. That embarrassing.

      – dx_over_dt
      Jan 9 at 20:19






    • 1





      @dx_over_dt in all fairness as far as the actual software is concerned it does just look like the CPU runs all the time, it's just that the CPU likes to take lots of naps and has a very loud, very accurate alarm clock and the OS scheduler spends a lot of time wandering around blearily saying "there's nothing to do here so let's have another 5 microsecond nap" or "jeez Program, are you still running? I haven't had a nap in ages so could you just ask for something from the disk so we can both go to sleep?"

      – Mokubai
      Jan 9 at 22:31
















    5












    5








    5







    Computers have hardware timers that can be used to signal the processor when a particular length of time has passed. One such item is the High Precision Event Timer (HPET), and back in the history of things even the RTC could fulfil a similar purpose.



    The CPU also has the ability to halt execution units using the HLT instruction and effectively put itself to sleep. No loops run and for all intents and purposes the CPU is dead except for hardware that waits for interrupt lines to be asserted.



    Rather than spin-waiting through a loop the processor simply tells the hardware to alert it when a particular time has passed and then puts the core execution units to sleep. Once the time has passed the timer asserts an interrupt, which in turn wakes the CPU and execution starts again.



    Low precision timers such as the RTC would work in a similar way, for every number of ticks you check the count on each tick and sleep until the next one comes along. It's a relatively low cost (processor power wise) way to implement wait states.






    share|improve this answer















    Computers have hardware timers that can be used to signal the processor when a particular length of time has passed. One such item is the High Precision Event Timer (HPET), and back in the history of things even the RTC could fulfil a similar purpose.



    The CPU also has the ability to halt execution units using the HLT instruction and effectively put itself to sleep. No loops run and for all intents and purposes the CPU is dead except for hardware that waits for interrupt lines to be asserted.



    Rather than spin-waiting through a loop the processor simply tells the hardware to alert it when a particular time has passed and then puts the core execution units to sleep. Once the time has passed the timer asserts an interrupt, which in turn wakes the CPU and execution starts again.



    Low precision timers such as the RTC would work in a similar way, for every number of ticks you check the count on each tick and sleep until the next one comes along. It's a relatively low cost (processor power wise) way to implement wait states.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 9 at 19:57

























    answered Jan 9 at 19:51









    MokubaiMokubai

    57.7k16138156




    57.7k16138156













    • Hah, I've lived so long in the upper layers of software, where code just uses hardware for its own purposes, that it didn't even occur to me that hardware could be the one to signal the software. That embarrassing.

      – dx_over_dt
      Jan 9 at 20:19






    • 1





      @dx_over_dt in all fairness as far as the actual software is concerned it does just look like the CPU runs all the time, it's just that the CPU likes to take lots of naps and has a very loud, very accurate alarm clock and the OS scheduler spends a lot of time wandering around blearily saying "there's nothing to do here so let's have another 5 microsecond nap" or "jeez Program, are you still running? I haven't had a nap in ages so could you just ask for something from the disk so we can both go to sleep?"

      – Mokubai
      Jan 9 at 22:31





















    • Hah, I've lived so long in the upper layers of software, where code just uses hardware for its own purposes, that it didn't even occur to me that hardware could be the one to signal the software. That embarrassing.

      – dx_over_dt
      Jan 9 at 20:19






    • 1





      @dx_over_dt in all fairness as far as the actual software is concerned it does just look like the CPU runs all the time, it's just that the CPU likes to take lots of naps and has a very loud, very accurate alarm clock and the OS scheduler spends a lot of time wandering around blearily saying "there's nothing to do here so let's have another 5 microsecond nap" or "jeez Program, are you still running? I haven't had a nap in ages so could you just ask for something from the disk so we can both go to sleep?"

      – Mokubai
      Jan 9 at 22:31



















    Hah, I've lived so long in the upper layers of software, where code just uses hardware for its own purposes, that it didn't even occur to me that hardware could be the one to signal the software. That embarrassing.

    – dx_over_dt
    Jan 9 at 20:19





    Hah, I've lived so long in the upper layers of software, where code just uses hardware for its own purposes, that it didn't even occur to me that hardware could be the one to signal the software. That embarrassing.

    – dx_over_dt
    Jan 9 at 20:19




    1




    1





    @dx_over_dt in all fairness as far as the actual software is concerned it does just look like the CPU runs all the time, it's just that the CPU likes to take lots of naps and has a very loud, very accurate alarm clock and the OS scheduler spends a lot of time wandering around blearily saying "there's nothing to do here so let's have another 5 microsecond nap" or "jeez Program, are you still running? I haven't had a nap in ages so could you just ask for something from the disk so we can both go to sleep?"

    – Mokubai
    Jan 9 at 22:31







    @dx_over_dt in all fairness as far as the actual software is concerned it does just look like the CPU runs all the time, it's just that the CPU likes to take lots of naps and has a very loud, very accurate alarm clock and the OS scheduler spends a lot of time wandering around blearily saying "there's nothing to do here so let's have another 5 microsecond nap" or "jeez Program, are you still running? I haven't had a nap in ages so could you just ask for something from the disk so we can both go to sleep?"

    – Mokubai
    Jan 9 at 22:31















    1














    Mokubai gives the correct answer for how sleep generally works. But even if the computer were spin-looping, it could still use less power than normal. Different instructions use different amounts of power, depending on what they do. Reading from RAM will use more power than reading from the CPU cache, and while it's in a tiny spin loop it should just use cache. While it's looping the parts of the CPU that perform arithmetic or interact with external devices are inactive, so they don't use any power. If it's a laptop, the screen will be shut down, and that should be a huge power saving.



    This all isn't as good as going almost totally dead except for the event timer. But I think some operating systems have "low power mode" that's in between normal running and sleeping, which may incorporate some of this.






    share|improve this answer




























      1














      Mokubai gives the correct answer for how sleep generally works. But even if the computer were spin-looping, it could still use less power than normal. Different instructions use different amounts of power, depending on what they do. Reading from RAM will use more power than reading from the CPU cache, and while it's in a tiny spin loop it should just use cache. While it's looping the parts of the CPU that perform arithmetic or interact with external devices are inactive, so they don't use any power. If it's a laptop, the screen will be shut down, and that should be a huge power saving.



      This all isn't as good as going almost totally dead except for the event timer. But I think some operating systems have "low power mode" that's in between normal running and sleeping, which may incorporate some of this.






      share|improve this answer


























        1












        1








        1







        Mokubai gives the correct answer for how sleep generally works. But even if the computer were spin-looping, it could still use less power than normal. Different instructions use different amounts of power, depending on what they do. Reading from RAM will use more power than reading from the CPU cache, and while it's in a tiny spin loop it should just use cache. While it's looping the parts of the CPU that perform arithmetic or interact with external devices are inactive, so they don't use any power. If it's a laptop, the screen will be shut down, and that should be a huge power saving.



        This all isn't as good as going almost totally dead except for the event timer. But I think some operating systems have "low power mode" that's in between normal running and sleeping, which may incorporate some of this.






        share|improve this answer













        Mokubai gives the correct answer for how sleep generally works. But even if the computer were spin-looping, it could still use less power than normal. Different instructions use different amounts of power, depending on what they do. Reading from RAM will use more power than reading from the CPU cache, and while it's in a tiny spin loop it should just use cache. While it's looping the parts of the CPU that perform arithmetic or interact with external devices are inactive, so they don't use any power. If it's a laptop, the screen will be shut down, and that should be a huge power saving.



        This all isn't as good as going almost totally dead except for the event timer. But I think some operating systems have "low power mode" that's in between normal running and sleeping, which may incorporate some of this.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 11 at 19:24









        BarmarBarmar

        1,629815




        1,629815






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1392423%2fhow-does-a-computer-sleep-wait-without-using-all-of-its-processing-power%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]