68 Commits

Author SHA1 Message Date
Marc Di Luzio
1665447350 Use run_external_process for the script execution
This protects the main process against script exection and allows more detailed error handling
2019-03-07 17:51:57 +00:00
Marc Di Luzio
5facf2bba5 Refactor out script execution 2019-03-07 17:51:57 +00:00
Marc Di Luzio
024acddf90 Run the custom start scripts to after the other optimisations
This ensures the other featues are applied first, and the scripts can react if needed to those settings
2019-03-07 17:51:57 +00:00
Marc Di Luzio
7f6f32d284 Actually reject requests if require_supervisor is hit 2019-02-22 15:58:46 +00:00
Marc Di Luzio
b28efdb555 Correct the names and return 0 for success 2019-02-21 17:34:20 +00:00
Marc Di Luzio
602afdcbb7 Add check against require_supervisor variable 2019-02-21 17:34:20 +00:00
Marc Di Luzio
1d40c0cc1b Refactor to use single internal functions for register, unregister and query 2019-02-21 17:34:20 +00:00
Marc Di Luzio
d4fdd9e3b4 Correct internal name for query_status_for 2019-02-21 17:34:20 +00:00
Marc Di Luzio
de1049f070 Fix comments 2019-02-21 17:34:20 +00:00
Marc Di Luzio
c2f7e971c6 Implement game_mode_query_status_for as well 2019-02-21 17:34:20 +00:00
Marc Di Luzio
1430c0b831 Implement supervisor features using new config variables
This allows direct control over who can make requests on behalf of other processes

	require_supervisor can also be used to allow a supervisor to take direct control of gamemode on the system (perhaps a GUI, or game launcher)
2019-02-21 17:34:20 +00:00
Marc Di Luzio
c5f58c56d0 Hook up interfaces for functions to register another process 2019-02-21 17:34:20 +00:00
Marc Di Luzio
d5ffdcffdb Fix reaper_frequency naming 2019-02-19 17:40:50 +00:00
Marc Di Luzio
b7dff4265c Refactor config functions that can return their full value to do so
This pattern got a little out of hand, and was only meant for variable length values like strings
2019-02-19 17:40:50 +00:00
Marc Di Luzio
a395caeb48 Refactor the governor request into an external process helper function 2019-02-12 08:55:23 +00:00
Marc Di Luzio
b1bf33d386 Add config parameters for GPU clocking 2019-02-12 08:55:23 +00:00
Marc Di Luzio
aeaef7377d Preliminary (empty) implementation of GPU optimisations 2019-02-12 08:55:23 +00:00
Marc Di Luzio
ba49055519 Set up inhibit_screensaver config option to disable the feature 2019-02-03 15:45:11 +00:00
Marc Di Luzio
e342b6e394 Remove SCHED_ISO from gamemode.c
As per request, no longer needed
2019-01-29 16:38:25 +00:00
Marc Di Luzio
42dd7e6ea8 Add initial screensaver inhibiting code 2019-01-28 16:36:56 +00:00
Kai Krakow
5396370e5d refactor: Simplify the log hinter
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-09 00:33:46 +02:00
Kai Krakow
f4cd01f989 refactor: Break wine API functions out of the main daemon source
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-09 00:33:46 +02:00
Kai Krakow
403ce122f6 refactor: Break ioprio API functions out of the main daemon source
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-09 00:33:46 +02:00
Kai Krakow
edf9257de4 refactor: Break sched API functions out of the main daemon source
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-09 00:33:46 +02:00
Kai Krakow
b9c9a5f120 refactor: Avoid exposing various internal types
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-09 00:33:46 +02:00
Kai Krakow
92967b135b refactor: Break env API functions out of the main daemon source
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-09 00:33:46 +02:00
Kai Krakow
748808be7e refactor: Break proc API functions out of the main daemon source
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-09 00:33:46 +02:00
Kai Krakow
c4ff3d7250 refactor: Break helpers out of the main daemon source
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-08 20:53:04 +02:00
Alex Smith
9bbcc03c50 Merge pull request #84 from kakra/improve-scheduler-logging
gamemode-scheduler: Improve logging
2018-10-08 17:30:06 +01:00
Kai Krakow
29f8f0883c gamemode: Explain the concerning logs a little better
Testing showed that wine processes may provoke some concerning logs
multiple times. Let's explain this a little more so no questions from
worried users show up.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 20:03:17 +02:00
Kai Krakow
fd4166279b gamemode: Convert game_mode_context_has_client() to return the client
Returning a bool is not useful if we want to create some log information
from this. It now returns NULL or a client pointer which is compatible
with all of the current users.

When dereferencing the returned pointer, a read lock must be acquired
around using the returned result as the client may be deallocated from
heap otherwise.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 20:03:17 +02:00
Kai Krakow
d023495a5d gamemode: Add a tiny buffered snprintf helper
Be careful using this as it may introduce some non-obvious pitfalls.
This saves us from a heap allocation in some code locations.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 20:03:17 +02:00
Kai Krakow
4fd93ee30a gamemode: Map wine preloaders to original exe
This commit hooks game_mode_resolve_wine_preloader() into the function
to lookup the exe from a PID.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:54:40 +02:00
Kai Krakow
ba80a6cc3d gamemode: Add function to resolve the wine preloader executable
This commit adds a function to resolve a wine preloader binary into its
original windows binary.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:54:40 +02:00
Kai Krakow
373fe5a8af gamemode: Add a helper to compare string tails
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:54:40 +02:00
Kai Krakow
c2344f4387 gamemode: Add function to search environment of a PID
This function can look up arbitrary environment variables from a running
PID (given we have access permissions which should be usually true).

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:54:40 +02:00
Kai Krakow
47ea4514cd gamemode: Add function to lookup user home directory
We first try to use `$HOME`, and only then fall back to passwd lookup.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:54:40 +02:00
Kai Krakow
3a6d258eae gamemode: Make game_mode_context_find_exe() thread-safe
Let's use our new safe_snprintf() helper. It's designed to make
thread-safe usage easy and will also be used by the next commits.

Reported-by: Alex Smith <alex@alex-smith.me.uk>
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:54:40 +02:00
Kai Krakow
81a52ddc4d gamemode: Add a tiny safe snprintf helper
Give it a buffer, it returns an allocated string respecting the buffer
size.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:54:23 +02:00
Kai Krakow
bd811c6646 gamemode: Add executable to initializer
This allows to initialize the GameModeClient later and cleans up the
error path.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:45:31 +02:00
Kai Krakow
8214f93630 gamemode: Optimize detection of dupe registers
GameMode can do a pretty expensive lookup function now for the exe.
Let's spare some CPU cycles by detecting a duplicate PID early. Nothing
makes use of the exe path at this stage.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:45:31 +02:00
Kai Krakow
2a0c6e7098 gamemode: Never add NULL to the client list
When running wine games, there's good chance the executable is already
gone when GameMode decided to add it to the list. Let's silently bail
out here. It probably grabs a non-matching PID anyway in this moment.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:45:31 +02:00
Kai Krakow
8a618a29fa gamemode-scheduler: Improve logging
During finding the cause of an issue, we discovered bad interactions
with other resource management daemon that may be running at the same
time and may interfere with GameMode's ability to properly set
scheduling parameters of the process. Usually, this results in EPERM
(instead of EINVAL for lacking kernel support). It also means that the
other daemon is leaking wrong scheduling settings into the games with
negative performance impacts (quite the opposite of what the user wanted
to achieve). So we should give some valuable hints.

This commit improves logging by detecting the error situation and giving
context-based hints on what to do next. To keep logging verbosity low,
the hint is only logged once per error code.

Closes: https://github.com/FeralInteractive/gamemode/issues/68
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-05 19:44:58 +02:00
Kai Krakow
62865b1e32 gamemode: Apply io priority to clients
This commit allows changing the io priority of the client to a value
specified in the configuration file. That can possibly reduce lags or
latency when a game has to load assets on demand and you have background
IO activity running (or other concurrent IO).

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-10-03 04:24:56 +02:00
Kai Krakow
a91a2e7739 gamemode: Add a value clamping helper
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-09-30 17:36:34 +02:00
Kai Krakow
5e4d5fb2e7 gamemode: Don't leak SCHED_ISO into children
We should not leak `SCHED_ISO` into children processes. This is obviously
a no-op if launchers use the `LD_PRELOAD` method because every child would
also preload the gamemode library (except they patch the environment
before forking).

But for games supporting gamemode natively, this prevents leaking the
scheduler settings into child processes which is important because it
children may create high CPU usage which counterfeits the original idea
of this.

Apparently, this won't work for the nice value except we would intercept
the libc forking functions (which would be possible but not very
transparent and prone to compatibility problems). However, if we
implemented it, it shouldn't be part of this commit anyway.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-09-24 20:31:17 +02:00
Alex Smith
22a90a73ef Fix formatting 2018-08-04 11:05:33 +01:00
Alex Smith
442475a78b Make error messages for failure to change scheduling policies more descriptive
Out of the box on most distros, both of these steps will fail (renicing
requires permission which may need adjustment to limits.conf, and the
upstream kernel does not support SCHED_ISO).

Explicitly state this in the error messages to hopefully reduce user
confusion as to why these might be failing.
2018-08-04 10:54:59 +01:00
Matthias Gerstner
39d7b95a26 game_mode_context_register: fix memory leak on error conditions
Clients can reach this memory leak by trying to unregister non-existing
clients via D-Bus.
2018-07-30 17:29:55 +02:00
Kai Krakow
6f93020d0b scheduler: Apply renice configuration to clients
This commit applies the configured nice value to the client. It accepts
values from 1 to 20, the negated value is applied as a nice value.
Negation was chosen due to limits of the configuration parser. Since low
priority values (0 to 19) make no sense in the scope of GameMode, this
is a safe approach.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-06-10 09:36:21 +02:00