Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting max CPU consumption #24

Open
sc0ttj opened this issue Nov 19, 2020 · 3 comments
Open

Setting max CPU consumption #24

sc0ttj opened this issue Nov 19, 2020 · 3 comments

Comments

@sc0ttj
Copy link

sc0ttj commented Nov 19, 2020

# 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

Given the default max consumption is 100%, does giving a value of 3 mean the program will use max 75% CPU, or max 25% CPU?

I would like to limit my browser to a max of 80% CPU consumption (on whatever core its grinding away on...)

@kernc
Copy link
Owner

kernc commented Nov 19, 2020

It's decrease, 75% decrease. Based on this code:

#define FAST_INTERVAL_MSEC 100

xsuspender/src/events.c

Lines 286 to 287 in b73f837

g_timeout_add_full (
G_PRIORITY_HIGH_IDLE, FAST_INTERVAL_MSEC, on_downclock_slice, NULL, NULL);

xsuspender/src/events.c

Lines 346 to 353 in b73f837

// Suspend the process
kill (pid, SIGSTOP);
// Signal to raise after so-many time slices
pair->counter = downclock_slice_counter + entry->rule->downclock_on_battery;
// Put in "suspended" queue
downclock_suspended = g_list_prepend (downclock_suspended, pair);

It's a 100ms-sliced timer and a rule of = n means "sleep n cycles for every one work cycle", making 50% the least possible decrease, unfortunately.

@sc0ttj
Copy link
Author

sc0ttj commented Nov 20, 2020

Gotcha. Thanks. Close if you like 👍

@kernc kernc added the question label Nov 20, 2020
@kernc
Copy link
Owner

kernc commented Nov 20, 2020

For a finer grained slice control (e.g. percent), tho alternatives are, on Linux, cgroups, or running a while (true) loop like cpulimit does in a separate thread. PR welcome. 👍

@kernc kernc changed the title [Question] Setting a max CPU consumption Setting max CPU consumption Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants