Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 04, 2015, 01:52:21 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: DONE: Replacement Power Options applet  (Read 33693 times)

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
DONE: Replacement Power Options applet
« on: December 17, 2006, 12:02:15 PM »
Maybe not a snack but it would be useful.

Currently the Power Options in Control Panel work on the basis of keyboard and mouse activity.

I would like a replacement that works on a CPU threshold not being exceeded for a period (say 5%) - that way I could set Standby or Hibernate when the computer is truly idle - not just when I don't interact personally. That would allow extended processing applications (such as video recoding) to proceed without Power Options kicking in.

Anyone any ideas how to acheive this ?
« Last Edit: December 17, 2006, 12:23:48 PM by brotherS »

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #1 on: December 17, 2006, 05:37:09 PM »
 :) How about this one?

LowToSleep - Stop a PC from falling asleep until the CPU is inactive.

Features:
- Change CPU limit using Settings in the tray menu
- Shows CPU usage in the tray

You'll find the downloads and more info at 1 Hour Software by Skrommel.

It just checks the CPU, and if it is above the limit (5 % is default), it sends a keystroke to a hidden control.

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #2 on: December 17, 2006, 06:12:23 PM »
Hey great idea - thanks. Nice to see you back  :Thmbsup:

(some pennies on the way)

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #3 on: December 17, 2006, 06:31:02 PM »
Follow up:

I am getting an error at line 42 "Can't load icon" which appears repeatedly. See window ...

sc.png

The value of %icon% looks to be negative everytime and the numerical value doesn't seem to match the actual CPU usage (according to task manager)?

I can see that the INI file allows you to set the delay time in minutes but could it also allow the setting of the frequency of checking (in ms) and also the CPU threshold (as a %).
« Last Edit: December 17, 2006, 07:32:30 PM by Carol Haynes »

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #4 on: December 17, 2006, 07:30:50 PM »
 :) Man, you must really have a slow computer!

But seriously, what CPU is in there? I've never gotten any negative values, and they correspond very well with Task manager's tray icon. The code is lifted from the Autohotkey site, and noone has reported any anomalies...

I've just uploaded a new LowToSleep that checks if the icon exists, and I've changed the settings to show threshold in % and checking interval in seconds. Remember to delete your existing ini file!

Please keep me informed.

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
« Last Edit: January 12, 2007, 11:28:15 AM by skrommel »

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #5 on: December 17, 2006, 07:33:03 PM »
By duplicating the icons with a '-' in front of the number it works but I am getting odd CPU usage tooltips (like -88%) when I hover over the icon. The actual CPU usage is <10%. Could this be because I have a dual core processor?

I am using an AMD Athlon64 X2 4600+ ... so pretty slow ;)

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #6 on: December 20, 2006, 06:48:29 AM »
Anyone any further thoughts on this? Unfortunately Skrommel's idea doesn't seem to work for me (I get negative CPU usage and the apparent numerical value calculated int he script is always high - ignoring the sign).

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #7 on: December 20, 2006, 07:46:37 AM »
 :( I've posted the question on the AHK forum, but noone has answered...

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #8 on: December 26, 2006, 11:57:17 AM »
 :) Carol, try LowToSleep v1.0.

I've found typo in the settings file, causing the CPU load to be checked too fast.

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #9 on: December 26, 2006, 05:02:18 PM »
Strange - with <10% CPU activity LowToSleep is still reporting negative CPU activity (of the order of -80%) ???

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 8,858
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #10 on: December 26, 2006, 05:44:17 PM »
Hmm...

dunno if this is at all related, but for AMD dualcore CPUs, each core has it's own "Time Stamp Counter", and they don't update in parallel for a various number of reasons.

So, if an application queries the TSC (with assembly instruction RDTSC), store the number, thread gets scheduled to other CPU, RDTSC is done again and old value is subtracted (ie, timing is being done) you can end up with negative values.

This is why all Unreal Engine games crash on AMD64x2 boxes, unless they're launched with "affinity restriction".
- carpe noctem

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #11 on: December 27, 2006, 04:33:34 AM »
That sounds quite likely.

How do you launch a program with affinity restriction (I know how to change it once it is launched).


f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 8,858
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #12 on: December 27, 2006, 06:11:05 PM »
You need to find a launcher - I wrote a little hacky tool with no error checking, but you're probably better off googling for "win2000launcher" :)
- carpe noctem

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #13 on: December 27, 2006, 06:22:48 PM »
 :) Pocess from http://www.beyondlogic.org/solutions/processutil/processutil.htm can set the affinity of a process.

Skrommel

Quote
Change the affinity of processes . . .

The affinity is a mask which indicates on which processors (CPUs) a process can run. This is only useful on multiprocessor systems. When the -a option is used in conjunction with a process name or PID, the utility will show the System Affinity Mask and the Process Affinity Mask. The System Affinity Mask shows how many configured processors are currently available in a system. The Process Affinity Mask indicates on what processor(s) the specified process can run on.

C:\>process -a wordpad.exe

Command Line Process Viewer/Killer/Suspender for Windows NT/2000/XP V2.01
Copyright(C) 2002-2003 Craig.Peacock@beyondlogic.org
Getting Affinity Mask for PID 1084 'wordpad.exe'
System  : 0x0001 0b00000000000000000000000000000011  [2 Installed Processor(s)]
Process : 0x0001 0b00000000000000000000000000000011

 

To set the affinity mask, simply append the binary mask after the PID/Image Name. Any leading zeros are ignored, so there is no requirement to enter the full 32 bit mask.

C:\>process -a wordpad.exe 01

Command Line Process Viewer/Killer/Suspender for Windows NT/2000/XP V2.01
Copyright(C) 2002-2003 Craig.Peacock@beyondlogic.org
Setting Affinity Mask for PID 1084 'wordpad.exe'
Affinity Mask Successfully Set to 00000000000000000000000000000001
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #14 on: January 11, 2007, 05:18:17 PM »
 :) Try LowToSleep v1.1!

I've added affinity to show the correct cpu usage on mutliple core/cpu systems. But I haven't got one, so please telle me if it works!

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #15 on: January 12, 2007, 12:09:57 PM »
I still get large negative usage values (eg. -80% even when CPU usage is under 10%)

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #16 on: January 17, 2007, 06:45:44 PM »
 :tellme: How about LowToSleep v1.2?

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 8,858
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #17 on: January 17, 2007, 09:00:08 PM »
Hm, some things... unless I pass parameters for all three variables to GetSystemTimes, it doesn't return anything - the following code would simply print fluff! with SysInternals' dbgview. Adding "dummy1" and "dummy2", I get some garbage output, indicating that there's output.
Code: [Select]
lala = %idleticks% + "fluff!"
DllCall("kernel32.dll\OutputDebugString", "uint", &lala)
(christ, AutoHotKey is a weird language).

I still get -100% usage, though - and I'm pretty sure affinity isn't the problem, GetSystemTimes shouldn't be affected by that (rdtsc, GetTickCount() and QueryPerformanceCounter() are, though - I originally thought you were using one of those).

What the heck is going on in the loop in GETCPULOAD?

EDIT: oh, A_TickCount probably translates to a call to GetTickCount(), so affinity might be necessary after all. And the Loop seems to be necessary because of AHK's weird "everything is a string, but we don't translate API output" philosophy. Hm.

EDIT2: I've modified the GETCPULOAD() function somewhat...
Code: [Select]
GETCPULOAD() ;originally made by shimanov
{
  Global
  idletime0 = %idletime% ; Save previous values
  tick0 = %tick%

  DllCall("Kernel32.dll\GetSystemTimes", "*UInt64", idletime, "*Uint64", dummy1, "*Uint64", dummy2)

  tick := A_TickCount
  dIdle := (idletime - idletime0)
  dTick := (tick - tick0)

  load := 100 - 0.01 * dIdle/dTick

  outstr = Spent time: %dIdle%/%dTick%
  DllCall("kernel32.dll\OutputDebugString", "str", outstr)

  Return,load
}
With dbgview, I get values like...
Code: [Select]
Spent time: 20000000/1000
Spent time: 20000000/1000
Spent time: 19843750/1000
Spent time: 20000000/1000
Spent time: 19843750/1000
Spent time: 20000000/1000
Spent time: 19687500/1000

EDIT 3: Okay, I should have seen this earlier. Quoting MSDN for GetSystemTimes, emphasis is mine: "Retrieves system timing information. On a multiprocessor system, the values returned are the sum of the designated times across all processors.".

So, for NT systems, add a EnvGet, NumCpu, NUMBER_OF_PROCESSORS near the top of the script, and do dIdle := (idletime - idletime0) / NumCpu. Feels somewhat hacky, but works. Probably better using GetSystemInfo() and checking the dwNumberOfProcessors field, but I dunno how AHK handles structs. If you do the environment thing, check for 9x and assign 1 to NumCpu.
- carpe noctem
« Last Edit: January 17, 2007, 09:31:14 PM by f0dder »

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #18 on: January 18, 2007, 03:29:18 AM »
Sounds like progress - but I don't pretend I have followed the argument  :-[

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,032
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #19 on: January 18, 2007, 04:26:01 AM »
I'll take a shot at it.  I think what is going on is to use the internal "clock" counts to a certain quantity defined by... I'm not sure, but the countdown/up is what triggers the event.  Clear as mud, right?
« Last Edit: December 08, 2009, 06:59:50 PM by CodeTRUCKER »

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #20 on: January 18, 2007, 06:41:29 AM »
Scratches head .... yes I think I understand that ...  :tellme:

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 8,858
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #21 on: January 18, 2007, 10:16:04 AM »
Okay, let me try... you were in the right direction, Farmsteader :)

the code runs once every second, and measures:

1) how many miliseconds elapsed since it last run (tick-tick0). This might seem superfluous, but it CAN vary a bit, since the code runs at normal priority.

2) how much time the CPU was idle (the value from GetSystemTimes) (again, a relative timing, idletime-idletime0).

Thing is, GetSystemTimes returns totals for all CPUs - so on a 2-core system, although only one second has elapsed, 2 "cpu-seconds" could be spent idle, and this is why we have to divide by NUMBER_OF_PROCESSORS.

The affinity thing is anyother problem, and I'm not sure it applies here (can't remember if it affects GetTickCount(), or only the RDTSC CPU instruction and the win32 api QueryPerformanceCounter()). But that problem happens on AMD dualcore CPUs, because their internal time-stamp counters aren't synchronized (while on intel dualcores it seems like either there's a single TSC, or the TSCs are synchronized).
- carpe noctem

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #22 on: January 18, 2007, 10:47:39 AM »
 :tellme: Anyone care to test LowToSleep v1.3?

- 20070118 - v1.3: Retrieves the number of processors for correct calculations on multi core systems.

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,969
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #23 on: January 18, 2007, 11:18:47 AM »
Ah ! Now that seems to work for me (at least for reporting CPU usage). Thanks that's great.

I'll try it out now for allowing sleeping on sustained low CPU usage.

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: Replacement Power Options applet
« Reply #24 on: January 18, 2007, 11:47:05 AM »
 :D Great!

Thanks for finding the solution, f0dder!

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.