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>
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>
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>
Fix what was reported by valgrind:
```
==8458==
==8458== HEAP SUMMARY:
==8458== in use at exit: 11,677 bytes in 27 blocks
==8458== total heap usage: 768 allocs, 741 frees, 397,008 bytes
allocated
==8458==
==8458== Searching for pointers to 27 not-freed blocks
==8458== Checked 206,624 bytes
==8458==
==8458== LEAK SUMMARY:
==8458== definitely lost: 0 bytes in 0 blocks
==8458== indirectly lost: 0 bytes in 0 blocks
==8458== possibly lost: 0 bytes in 0 blocks
==8458== still reachable: 11,677 bytes in 27 blocks
==8458== suppressed: 0 bytes in 0 blocks
==8458== Reachable blocks (those to which a pointer was found) are not
shown.
==8458== To see them, rerun with: --leak-check=full
--show-leak-kinds=all
==8458==
==8458== Use --track-origins=yes to see where uninitialised values come
from
==8458== ERROR SUMMARY: 200 errors from 10 contexts (suppressed: 0 from
0)
==8458==
==8458== 20 errors in context 1 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x10BD18: game_mode_apply_scheduler (gamemode.c:237)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 2 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x4A0C4DC: strcmp (vg_replace_strmem.c:846)
==8458== by 0x10BD15: game_mode_apply_scheduler (gamemode.c:237)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 3 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x10BCDB: game_mode_apply_scheduler (gamemode.c:232)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 4 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x4A0C4DC: strcmp (vg_replace_strmem.c:846)
==8458== by 0x10BCD8: game_mode_apply_scheduler (gamemode.c:232)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 5 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x53AB44C: vfprintf (vfprintf.c:1642)
==8458== by 0x53B2C5D: printf (printf.c:33)
==8458== by 0x10BBA2: game_mode_apply_scheduler (gamemode.c:201)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 6 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x53AA9DA: vfprintf (vfprintf.c:1642)
==8458== by 0x53B2C5D: printf (printf.c:33)
==8458== by 0x10BBA2: game_mode_apply_scheduler (gamemode.c:201)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 7 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x53A6FF5: _itoa_word (_itoa.c:179)
==8458== by 0x53AA922: vfprintf (vfprintf.c:1642)
==8458== by 0x53B2C5D: printf (printf.c:33)
==8458== by 0x10BBA2: game_mode_apply_scheduler (gamemode.c:201)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 8 of 10:
==8458== Use of uninitialised value of size 8
==8458== at 0x53A6FE8: _itoa_word (_itoa.c:179)
==8458== by 0x53AA922: vfprintf (vfprintf.c:1642)
==8458== by 0x53B2C5D: printf (printf.c:33)
==8458== by 0x10BBA2: game_mode_apply_scheduler (gamemode.c:201)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 9 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x53AB20A: vfprintf (vfprintf.c:1642)
==8458== by 0x53B2C5D: printf (printf.c:33)
==8458== by 0x10BBA2: game_mode_apply_scheduler (gamemode.c:201)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458==
==8458== 20 errors in context 10 of 10:
==8458== Conditional jump or move depends on uninitialised value(s)
==8458== at 0x10BB44: game_mode_apply_scheduler (gamemode.c:200)
==8458== by 0x10C7D7: game_mode_context_register (gamemode.c:445)
==8458== by 0x10D4E6: method_register_game (dbus_messaging.c:79)
==8458== by 0x4CB795B: method_callbacks_run (bus-objects.c:404)
==8458== by 0x4CB795B: object_find_and_run (bus-objects.c:1262)
==8458== by 0x4CB8D38: bus_process_object (bus-objects.c:1378)
==8458== by 0x4CC9251: process_message (sd-bus.c:2663)
==8458== by 0x4CC9251: process_running (sd-bus.c:2705)
==8458== by 0x4CC9251: bus_process_internal (sd-bus.c:2924)
==8458== by 0x10D8B9: game_mode_context_loop (dbus_messaging.c:173)
==8458== by 0x10B7C4: main (main.c:186)
==8458==
==8458== ERROR SUMMARY: 200 errors from 10 contexts (suppressed: 0 from
0)
```
Signed-off-by: Kai Krakow <kai@kaishome.de>
This adds support for a switch `--pre-commit` to work in
pre-commit-mode. It downloads the file and runs the real pre-commit-hook
then.
Signed-off-by: Kai Krakow <kai@kaishome.de>
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>
This commit silences the standard output of wget to generate less noise
when using `format-check.sh` as a pre-commit hook.
It also doesn't redownload the file over and over again but only when
changes were detected. Previous behavior was wget creating numbered
versions by multiple downloads, thus it always used the first version
which was download. That is obviously wrong.
It errors out nicely now when the download failed.
Signed-off-by: Kai Krakow <kai@kaishome.de>
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.
When there are not valid standard file descriptors then strange things
can happen. When new file descriptors are opened, they will take the
place of the former standard file descriptors and when e.g. somebody
calls printf() they will write to some file descriptor that is not
prepared for it. This would already happen during PLOG_MSG() in
gamemoded.
Actually this also causes a SIGABRT when calling gamemoded like this:
```bash
gamemoded -d
```
This is due to a bug [1] in systemd that causes an assertion to be
triggered. This shows that file descriptor zero is in this case being
replaced by a UNIX domain socket representing the connection to the
D-Bus session bus.
Therefore instead of just closing the standard file descriptors, replace
them by appropriate file descriptors refering to /dev/null.
[1]: https://github.com/systemd/systemd/issues/8080
The reason for setting umask in a daemon is to get a defined umask value
instead of whatever the calling user had configured. A umask of zero is
dangerous, however, because it can easily cause world-readable and
world-writeable files when oblivious code is involved that specified
0777 during open() calls, wanting to grant the user full control of the
resulting file mode.
Currently the daemon shouldn't be creating any new files so this is not
a matter. This could change in the future, however.
Games built against a new gamemode_client.h will fail to work with older
GameMode installations without this change. There are no ABI changes right
now so just attempt to load the old unversioned path if loading the
versioned one fails.
In order to be safe for future ABI changes and to fulfill packaging
requirements for e.g. Fedora, provide libtool like versioning for
both libraries, i.e. libgamemode and libgamemodeauto.
To ease development, create a gamemode.pc and a gamemode-auto.pc
file, that other projects can use integrate with gamemode. The
former if they want to integrate at the source level and the latter
if the automatic integration is preferred.
Always install the dbus service file and specify the systemd
unit file in it. This makes the service dbus-activatable and
thus we don't need to explicitly enable it (also we have one
less daemon running, if it is not needed).
Warn the user about adjusting `SCHED_ISO` to too high CPU usage values
as it may render the OS unresponsive.
Signed-off-by: Kai Krakow <kai@kaishome.de>
Depending on the local system architecture and the game architecture,
changes to the scheduling may result in priority inversion which has
counter-intuitive effects on performance. Let's document these to give
the user a chance to detect and fix this problem.
Signed-off-by: Kai Krakow <kai@kaishome.de>
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>