CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: idle process

  1. #1
    Join Date
    Jul 2015
    Posts
    2

    idle process

    I couldn't find anywhere any information on how to run a process or thread in the idle (power saving) processor speed. Maybe someone here knows how-to or at least some keywords?

    The basic idea is:
    Imagin your laptop runs on batteries and you have sometimes tasks to execute. These tasks are not time critical, but needs to be done at some point (e.g. auto-save). The CPU is running all the time anyway, maybe just spinning in the idle 'process'. I'd like to somehow run a thread or process without bumping up the CPU state or even trigger some turbo/overclocking.

    I know I can run low priority threads that will be executed if there is no any higher priority thread running, but this causes my CPU to still run at full speed. I know I can "Sleep" to drop into power saving if I don't need the thread, but I actually need the thread to run, I just don't care how slow it runs.

    I've found WinAPIs to set a thread state to disable power saving (e.g. display always on) and I've found some APIs to enforce some a power saving scheme that you usually setup by hand (e.g. balances, maximize performance, maximize power saving), but those affect the whole system and I really don't want to enforce a change in the settings.


    hopefully I could express what I'm aiming for, I'm sure I'm not the first that wants this, but I just cannot find a solution in google nor here in forum (after crawling through some pages of the search result).

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: idle process

    Out of curiosity, why does it matter what the cpu does if it can execute your low priority threads? Also what are you doinf in these threads to put the cpu at 100%?

  3. #3
    Join Date
    Jul 2015
    Posts
    2

    Re: idle process

    Quote Originally Posted by Arjay View Post
    Out of curiosity, why does it matter what the cpu does if it can execute your low priority threads?
    you mean, in what power state it is?
    well, because it drains battery and also triggers the fan.
    This is useful if you need responsiveness. My laptop peaks at 4GHz when I scroll this forum page.
    Tho, this is not needed when I execute something in background that does not make an impact on the user interaction. If some background work takes 2.5s in power saving state (800MHz in my laptop) instead of 0.5s it's completely fine. It would utilize the cpu that otherwise spins doing nothing.

    Quote Originally Posted by Arjay View Post
    Also what are you doinf in these threads to put the cpu at 100%?
    There is always something, depends on the application. Take for example the auto-save of my drawing program. it periodically compresses the image (not really just the image, it saves the undo-redo list which is accomplished with delta-frames), the compression time depends strongly on the image size and how much the user changes and runs in the task system of my drawing program. A task is always executed by all cores your CPU has to offer, because it makes no sense to have just one core run at 4GHz while the others idle, as windows re-schedules the threads randomly and thus lifts up all cores to high frequencies.
    For the drawing, it's nice to have all CPU power for some ms and then switch back to power saving, but for auto-save, I really don't care how long it takes. The low priority threads are anyway interrupted by normal threads if the user decides to draw a line while auto-save is in progress (wouldn't make that much sense to have a background auto-save if it would lock-up the application).


    that all is nothing I would consider critical, it works and it's ok already. But all those tiny improvements accumulate in making the user happy. An auto-save (or other tasks) that do not trigger your laptop fan and run with barely any extra power usage "Why wouldn't anyone do it another way"

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: idle process

    It seems like it is very hardware dependent as the fan on my HP laptop rarely kicks in - even when compiling.

    At any rate, I'm not sure this is the kind of thing users would know or care about.

    Sorry for not being any help whatsoever.

  5. #5
    Join Date
    Nov 2003
    Posts
    1,902

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: idle process

    This is an advanced power management topic.
    Why do you think you can better manage system resources that Windows?
    Could it be that setting your thread's priority to idle will ensure that the processor will not get "overworked" it that was the ONLY running thread?
    At least, I would first do some measurements to see how the processor's speed behaves while your idle thread is working.
    If you *DO* decide to manage power yourself, you would need to determine if yours is the only running thread and lower system-wide power consumption until another process demands some CPU time.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: idle process

    Quote Originally Posted by stoikov View Post
    I know I can run low priority threads that will be executed if there is no any higher priority thread running, but this causes my CPU to still run at full speed. I know I can "Sleep" to drop into power saving if I don't need the thread, but I actually need the thread to run, I just don't care how slow it runs.
    The best thing you can do is to not interfere into power settings chosen by user, and just do what you can to minimize CPU clocks consumption done by your threads. Which just means a reasonable combination of the two "you know you can" things.

    The lower thread priority hints Windows to adjust all system threads scheduling and possibly may break your tasks regularity. The sleeping may be done in waitable manner, i.e. waking up on a set of events, regular or irregular. The sleep thing can be improved by breaking the whole tasks into smaller chunks, if possible of course, and more "sparsed" execution. Which of course is going to complicate the solution itself.

    You should remember as well that having some third party software involved, like libs or dlls, may result in creation of worker threads other than yours. This is typical thing for multimedia stuff like image or video processing. And those thread schemes being out of your control may totally waste all your efforts in implementing surrogate power saving.
    Last edited by Igor Vartanov; July 21st, 2015 at 02:21 AM.
    Best regards,
    Igor

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured