Skip to content
Permalink
Browse files

Add option to downclock (cpulimit) processes

  • Loading branch information...
kernc committed Jan 10, 2018
1 parent 594cb81 commit 201717faabafde720fd2d054c5cd009c4e3839db
Showing with 252 additions and 14 deletions.
  1. +10 −0 data/xsuspender.conf
  2. +18 −0 doc/xsuspender.1
  3. +7 −0 src/config.c
  4. +2 −0 src/config.h
  5. +204 −13 src/events.c
  6. +5 −1 src/events.h
  7. +1 −0 src/macros.h
  8. +2 −0 src/rule.h
  9. +3 −0 src/xsuspender.c
@@ -41,6 +41,10 @@
# # power even if the window(s) didn't just lose focus.
# auto_suspend_on_battery = true
#
# # Limit CPU consumption for this factor when on battery power.
# # Value 1 means 50% decrease, 2 means 66%, 3 75% etc.
# downclock_on_battery = 0
#
#
# Values set in the Default section are inherited and overridden
# by other sections below.
@@ -52,22 +56,26 @@ resume_for = 5
send_signals = true
only_on_battery = true
auto_suspend_on_battery = true
downclock_on_battery = 0

# Preset configuration for some common software.

[Chromium]
suspend_delay = 10
match_wm_class_contains = chromium
suspend_subtree_pattern = chromium
downclock_on_battery = 1

[Firefox]
suspend_delay = 10
match_wm_class_contains = Navigator
match_wm_class_group_contains = Firefox
suspend_subtree_pattern = \/(firefox|plugin-container)
downclock_on_battery = 1

[JetBrains IDEs]
match_wm_class_group_contains = jetbrains-
downclock_on_battery = 1

[VirtualBox]
match_wm_class_contains = VirtualBox
@@ -77,6 +85,7 @@ exec_resume = VBoxManage controlvm "$(ps -o args= -q $PID | sed -E 's/.*--start
send_signals = false
resume_every = 0
only_on_battery = false
downclock_on_battery = 1

[qBittorrent]
match_wm_class_contains = qbittorrent
@@ -97,3 +106,4 @@ suspend_delay = 60
#send_signals = true
#only_on_battery = true
#auto_suspend_on_battery = true
#downclock_on_battery = 0
@@ -234,6 +234,24 @@ your
and
.B exec_resume
scripts to do the work.
.TP
.BR downclock_on_battery \ =\ 0
Set to greater than zero to decrease the CPU time allotted to the matching
process when running on battery power.
For every one time slice running, the process sleeps for this many slices.
Thus, a value
.I 1
decreases the CPU consumption of the process by 50%,
a value of
.I 2
by 66%, a value of
.I N
by \fIN/(N+1)\fR%, and so on. A value of
.I 0
disables downclocking.
.IP
This is a separate, stand-alone mechanism that limits consumption of,
also and in particular, focused windows.
.SH BUGS
The following limitations and quirks are known:
.IP \[bu] 2
@@ -128,6 +128,9 @@ read_section (GKeyFile *file,
val = g_key_file_get_integer (file, section, CONFIG_KEY_RESUME_FOR, &err);
if (! is_error (&err)) rule->resume_for = (guint16) CLAMP (val, 1, G_MAXUINT16);

val = g_key_file_get_integer (file, section, CONFIG_KEY_DOWNCLOCK_ON_BATTERY, &err);
if (! is_error (&err)) rule->downclock_on_battery = (guint8) CLAMP (val, 0, 9);

char *str;

str = g_key_file_get_value (file, section, CONFIG_KEY_WM_CLASS_CONTAINS, &err);
@@ -187,6 +190,7 @@ debug_print_rule (Rule *rule)
"only_on_battery = %d\n"
"send_signals = %d\n"
"subtree_pattern = %s\n"
"downclock_on_battery = %d\n"
"exec_suspend = %s\n"
"exec_resume = %s\n",
rule->needle_wm_class,
@@ -198,6 +202,7 @@ debug_print_rule (Rule *rule)
rule->only_on_battery,
rule->send_signals,
rule->subtree_pattern,
rule->downclock_on_battery,
(rule->exec_suspend ? rule->exec_suspend[2] : NULL),
(rule->exec_resume ? rule->exec_resume[2] : NULL)
);
@@ -217,6 +222,8 @@ parse_config ()

.subtree_pattern = NULL,

.downclock_on_battery = 0,

.delay = 10,
.resume_every = 50,
.resume_for = 5,
@@ -17,6 +17,7 @@
#define CONFIG_KEY_AUTO_ON_BATTERY "auto_suspend_on_battery"
#define CONFIG_KEY_SEND_SIGNALS "send_signals"
#define CONFIG_KEY_SUBTREE_PATTERN "suspend_subtree_pattern"
#define CONFIG_KEY_DOWNCLOCK_ON_BATTERY "downclock_on_battery"
#define CONFIG_KEY_WM_NAME_CONTAINS "match_wm_name_contains"
#define CONFIG_KEY_WM_CLASS_CONTAINS "match_wm_class_contains"
#define CONFIG_KEY_WM_CLASS_GROUP_CONTAINS "match_wm_class_group_contains"
@@ -25,6 +26,7 @@
CONFIG_KEY_AUTO_ON_BATTERY, \
CONFIG_KEY_SEND_SIGNALS, \
CONFIG_KEY_SUBTREE_PATTERN, \
CONFIG_KEY_DOWNCLOCK_ON_BATTERY, \
CONFIG_KEY_SUSPEND_DELAY, \
CONFIG_KEY_RESUME_EVERY, \
CONFIG_KEY_RESUME_FOR, \
Oops, something went wrong.

0 comments on commit 201717f

Please sign in to comment.
You can’t perform that action at this time.