352 Commits

Author SHA1 Message Date
Ehren Bendler
6e5c950141 fix clang-format error that is blocking CI 2025-05-01 15:35:50 +01:00
MithicSpirit
499af4c7bb Prevent platform profile error on unsupported systems
If a system does not support setting the platform profile (i.e., does
not have the file /sys/firmware/acpi/platform_profile), then everything
that interacts with it is skipped to prevent errors. This situation is
more common than I expected.[1]

[1] https://github.com/FeralInteractive/gamemode/issues/524
2025-04-30 19:12:51 +01:00
MithicSpirit
d84c5ded1c Extract split lock mitigation into common file
This reduces duplication of the split lock mitigation path.
Additionally, it allows extending the functionality of procsysctl into
also getting the split lock mitigation state.
2025-02-24 15:43:15 +00:00
MithicSpirit
2d71be6a94 Save all state before any of it is changed
The platform profile may restrict what values the governor can take, so
we need to save all state first to ensure the restored state is correct.
Then, the platform profile is the first thing we set (and restore) to
ensure all other changes are made to the best of our ability.
2025-02-24 15:43:15 +00:00
MithicSpirit
1e3e55c5d8 Add tests for platform profile
Note that the platform profile feature is considered required. Maybe
this shouldn't be the case, as I'm not sure how standard this feature is
yet.
2025-02-24 15:43:15 +00:00
MithicSpirit
e75f2c3942 Support setting the platform profile
The platform profile lives in /sys/firmware/acpi/platform_profile. The
desiredprof and defaultprof options correspond to the values for the
platform profile set when gamescope begins and ends, respectively.

HACK: The platform profile may restrict what values the governor can
take, so we choose to set the governor before the platform profile in
order to store the correct default governor, and restore the platform
profile before the governor. This is done to maximize correctness after
restoration, but it can cause issues if the previous platform profile
restricts the governor.

TODO: Save all the state we care about before any of it is changed. In
thsi case, we should set (and restore) the platform profile before the
governor.
2025-02-24 15:43:15 +00:00
Ahsan Fayaz
5b3b4ae638 Add "GameMode contributors" to copyright notice
Attribute the contributions made by members of the community, but avoid
unweildy and inconsistent copyright notices at the top of each file.

Existing contributor copyright notices have been left as-is.
2025-02-24 15:14:21 +00:00
Henrik Holst
1d9c1e6a72
Use better kernel api for P/E-cores (#515)
There's a proper kernel way to check for the presence of P- and E-cores so we don't have to check the frequency differences.

Kept the frequency check in case the kernel way does not exist on the users kernel but upped the fail-safe to 10% from 5% to close #498
2025-01-27 08:25:32 +00:00
Andrew Koroluk
2f69f7c023 Add suggestion message to failed CPU governernor test 2024-11-04 11:04:05 +00:00
peelz
c854772369 Fix idle inhibitor closing bus connection too early 2024-03-27 16:44:45 +00:00
Daniel Martinez
1c293d7818 use posix basename to fix build on musl
glibc provides a nonstandard basename implementation,
this can be overriden and posix basename can be used
by includeing libgen.h, however musl only has posix
basename, and must always include libgen.h

In this particular case, it doesn't appear that using
the posix version of basename will cause any issues,
as it is simply being used to match a hardcoded config
file name.
2024-03-27 10:17:17 +00:00
patatahooligan
8cea4c2418 Fix hybrid CPU core pinning
Previously the condition would always evaluate to `false`. With the fix
any core with >=95% of `max_freq` will be added to the set of cores to
keep.
2024-01-03 11:09:13 +00:00
Henrik Holst
41191dc607 Update gamemode-context.c
check format wined again, looks like I'm really bad at this
2023-12-05 11:31:16 +00:00
Henrik Holst
22001c56b1 Update gamemode-config.c
fixed format to match the proper codingstyle
2023-12-05 11:31:16 +00:00
Henrik Holst
088639e8b2 Update gamemode-context.c
fixed format to match the proper codingstyle
2023-12-05 11:31:16 +00:00
Henrik Holst
9e21ac3924 Update gamemode-context.c
fixed format to match the proper codingstyle
2023-12-05 11:31:16 +00:00
Henrik Holst
e2e8e981a2 Update gamemode-config.c
fixed format to match the proper codingstyle
2023-12-05 11:31:16 +00:00
Henrik Holst
9a7ee00bbf Update gamemode-context.c
added support for disabling the kernel split lock mitigation when entering game mode
2023-12-05 11:31:16 +00:00
Henrik Holst
b2bd7e5919 Update gamemode-config.h
added config values for disabling split lock mitigation
2023-12-05 11:31:16 +00:00
Henrik Holst
97cee92d94 Update gamemode-config.c
added config value for disabling split lock mitigation
2023-12-05 11:31:16 +00:00
Ahsan Fayaz
6c197f9b70 Apply clang-format with the new include order 2023-12-04 17:00:20 +00:00
Ahsan Fayaz
fad889db45 Apply clang-format to CPU pinning and parking code
The original PR #416 failed the format check, but this wasn't apparent
until after merging.
2023-12-04 15:33:15 +00:00
Hugo Locurcio
138ad384e3 Set the default GPU device ID to 0
This avoids confusion with the default configuration value being
`gpu_device=0` (as commented out in the `gamemode.ini` example),
but the actual default value being `-1`.

The alternative is to document this behavior and set the commented
out value to `-1`, but this makes the setup procedure more complex.
The new default behavior suits the 90% use case where there's
only one dedicated GPU available.
2023-12-04 14:21:32 +00:00
Henrik Holst
9614ceca9b pin every thread of the process
walk through /proc/pid/task to make sure that we set the thread affinity for every single thread in the process
2023-12-04 14:18:38 +00:00
Henrik Holst
865ffb2588 reapply the core pinning from the reaper thread
Reapply the core pinning from the reaper thread to catch cases where the game launches threads after initial start
2023-12-04 14:18:38 +00:00
Henrik Holst
b83fb8f83e made pinning optionally silent
made core pinning optionally silent, used for when the reaper thread calls us repeatable so we don't create tons of unnecessary logs
2023-12-04 14:18:38 +00:00
Henrik Holst
e882505881 properly support config reloading 2023-12-04 14:18:38 +00:00
Henrik Holst
88a15aba86 properly support config reloading 2023-12-04 14:18:38 +00:00
Henrik Holst
9cb119be62 properly support config reloading 2023-12-04 14:18:38 +00:00
Henrik Holst
91eb57574c fixed double free on exit from non use
if cpu core parking/pinning was disabled by the logic then there would be a double free at exit
2023-12-04 14:18:38 +00:00
Henrik Holst
25a99af4a1 use define instead of value
use a define instead of values for the park_or_pin variable
2023-12-04 14:18:38 +00:00
Henrik Holst
81dc3f95e5 fixed more coding style errors 2023-12-04 14:18:38 +00:00
Henrik Holst
912d4bdc19 fixed more coding style errors 2023-12-04 14:18:38 +00:00
Henrik Holst
2e26331d97 fix to match clang-format 2023-12-04 14:18:38 +00:00
Henrik Holst
51ee251efb Added detection for big.LITTLE
Added detection for big.LITTLE aka cpu:s where not all cores have the same frequency like on Intel Alder Lake and newer. The current logic allows a 5% difference in the max frequency due to some reports that those cpu:s doesn't always give back the exact same value (possible due to boosting capability).
2023-12-04 14:18:38 +00:00
Henrik Holst
4997adef8d build gamemode-cpu
Added build info for gamemade-cpu.c to meson
2023-12-04 14:18:38 +00:00
Henrik Holst
1b10b679cd added the cpu core parking/pinning definitions
added the cpu core parking/pinning definitions to gamemode.h
2023-12-04 14:18:38 +00:00
Henrik Holst
495a659895 Added gamemode-cpu.c
Added gamemode-cpu.c which contains the functions for cpu core parking and pinning
2023-12-04 14:18:38 +00:00
Henrik Holst
2dbd565340 call the cpu core parking/pinning from context
call the cpu core parking/pinning from gamemode-context.c
2023-12-04 14:18:38 +00:00
Henrik Holst
01024927d2 added cpu core parking/pinning settings
added cpu core parking/pinning settings to gamemode-config.h
2023-12-04 14:18:38 +00:00
Henrik Holst
32a0b5b636 added the cpu core parking/pinning settings
added the cpu core parking/pinning settings to gamemode-config.c
2023-12-04 14:18:38 +00:00
Alfred Persson Forsberg
f50e7fffe7 Fix build on musl libc
This simple patch includes signal.h in daemon/gamemode-context.c to fix building gamemode on musl
libc.

This has been tested Gentoo musl and Alpine (also Gentoo glibc to
ensure no multiple defined symbols/other errors for glibc).

> ../daemon/gamemode-context.c: In function 'game_mode_context_auto_expire':
> ../daemon/gamemode-context.c:421:29: error: implicit declaration of function 'kill' [-Werror=implicit-function-declaration]
>   421 |                         if (kill(client->pid, 0) != 0) {
>       |                             ^~~~
> ../daemon/gamemode-context.c:421:29: warning: nested extern declaration of 'kill' [-Wnested-externs]

Signed-off-by: Alfred Persson Forsberg <cat@catcream.org>
2022-07-15 14:14:16 +01:00
Sam Gleske
23493e5cc3 Fix GitHub Actions Format Check
This change fixes the format check in GitHub actions ran by `clang-format`.

Dockerfile

```dockerfile
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN set -ex; \
apt-get update; \
apt-get install -y build-essential meson appstream clang clang-format clang-tools libdbus-1-dev libinih-dev libsystemd-dev git

RUN set -ex; \
yes | adduser ci-user

USER ci-user
```

Environment setup

```bash
sudo su -g docker $USER
docker build -t ci .
```

clang-format fix

```bash
docker run -e CI=true --rm -v "$PWD:$PWD" -w "$PWD" --init ci ./scripts/format-check.sh
```
2022-02-21 09:51:59 +00:00
Stephan Lachnit
6c60565f33 Format files according to clang-format
Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
2022-02-03 16:40:02 +00:00
Kira Bruneau
5e366bd55d Fix loading shipped config when using a prefix other than /usr
Also remove recommendation to modify `/usr/share/gamemode/gamemode.ini`.
`/usr/share` is intended to contain read-only data files.

See https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s11.html.
2022-02-03 16:02:18 +00:00
Kira Bruneau
126e67fb6b Run executables from PATH instead of /usr/bin
Not all distributions install non-system binaries into /usr/bin. For
example, NixOS installs packages to /nix/store using a unique hash
generated from the inputs used to build it:

/nix/store/jld7jh3ilvbg91zvn1bdyawfc55b9jk8-polkit-0.118-bin/bin/pkexec
2022-02-03 15:42:22 +00:00
Ahsan Fayaz
510a0a6ae2 Fix issues found by Coverity, closes #206. 2020-07-17 18:55:00 +01:00
Stephan Lachnit
d8337aeb05 various variable naming improvements
This makes it more clear that libgamemode and libgamemodeauto are indeed libraries. Also, the misleading name `libgamemode_dep` has been renamed to `gamemode_dep`, which now also includes the dependency on libdl. The misleading `libgamemode_includes` variable name has also been changed.

Signed-off-by: Stephan Lachnit <stephanlachnit@protonmail.com>
2020-06-23 09:18:14 +01:00
Stephan Lachnit
ce6485ef97 combine no-daemon, elogind and systemd option
Signed-off-by: Stephan Lachnit <stephanlachnit@protonmail.com>
2020-05-19 16:27:51 +01:00
Stephan Lachnit
953792b4a5 Add option to use elogind
Signed-off-by: Stephan Lachnit <stephanlachnit@protonmail.com>
2020-05-19 16:27:51 +01:00