Saturday, April 20, 2024
20
rated 0 times [  20] [ 0]  / answers: 1 / hits: 2602  / 2 Years ago, sat, september 17, 2022, 11:10:35

My desktop stays on all the time. It acts as a server and also performs other semi-essential household tasks. During the day it uses the OnDemand CPU setting. This essentially just scales the CPU frequency as it needs it and this works really well for me.



At night time, it flits around. Of course most of the time it's idling along at a low power but occasionally, it'll ramp up to do something. I would rather it stayed on PowerSave and tasks were just forced to take a little longer to complete.



Additionally, I have a Nvidia card (GTX 580) which can consume about the same amount of power as a small African village uses in a year when it wants to (glares at Minecraft). For unknown reasons (undoubtedly something happening on the desktop), this ramps up, the fans sound like they're charging up to fire lasers into space. At night time, I'd like to underclock the card as far as it'll go.



I've considered a simple root-run cron script to push these through but my working hours are variable. Last week I had a near-70 hour working week so I was up very early and still up very late, every day. If the system was honking along at super-underclock mode, I would have been furious. Is there something I could do to say, "Underclock if:




  • It's between 10pm and 9am

  • There hasn't been any mouse/keyboard activity for 10 minutes

  • There isn't a movie playing



If one of those conditions isn't true, the underclock needs to revert instantly. I don't want to wait for a cron-script to come along to wake the computer up from its slumber. Similarly, as soon as all of those do become true, it should go back to sleep.



What are my options?


More From » power-management

 Answers
4

Here's a program that does what you want:



#!/usr/bin/env python
# coding: utf8

import time
import sys
import commands


USER = commands.getoutput("cat /var/log/auth.log | grep " +
sys.argv[0]).split("sudo:")[1].split()[0].strip()


def is_idle():
return int(commands.getoutput("xprintidle")) >= 10 * 60 * 1000

def is_night():
return time.localtime().tm_hour in (22, 23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

def is_stumm():
return "RUNNING" not in commands.getoutput(("sudo -u %s pacmd " +
"list-sinks | grep RUNNING") % USER)


def main():
powersave = False
while 1:
if is_idle() and is_night() and is_stumm():
if not powersave:
print "going into powersave mode"
commands.getoutput("echo powersave > " +
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor")
powersave = True
else:
if powersave:
print "going into ondemand mode"
commands.getoutput("echo ondemand > " +
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor")
powersave = False
time.sleep(0.5)

if __name__ == '__main__':
assert commands.getstatusoutput("xprintidle")[0] == 0, (
"you need to `sudo apt-get install xprintidle`")
assert commands.getoutput("whoami") == "root", (
"you need to be root to run this program")
main()


Note your preferences:




  • ... >= 10 * 60 * 1000

  • ... tm_hour in (22, 23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
    and

  • "RUNNING" not in ...



I'm using pulseaudio to find out if a movie is playing. This also affect music.


[#44786] Sunday, September 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ateact

Total Points: 176
Total Questions: 130
Total Answers: 122

Location: Egypt
Member since Sun, Apr 23, 2023
1 Year ago
ateact questions
;