49 Commits

Author SHA1 Message Date
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
peelz
c854772369 Fix idle inhibitor closing bus connection too early 2024-03-27 16:44:45 +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
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
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
Christian Kellner
cfe0fb4f17 daemon: add requester to GameModeClient
Record the requester process id in the GameModeClient struct and
add a getter for it.
2019-07-16 19:00:33 +01:00
Christian Kellner
52367772c8 daemon: add creation timestamp to GameModeClient
Record the time a client was created, i.e. registered, in the
GameModeClient struct and add a getter for it.

(Alex Smith: Fixed up function documentation comments)
2019-07-16 18:59:01 +01:00
Christian Kellner
f9827edfb6 daemon: emit client count change automatically
Every time a game is (un)-registered and we emit the corresponding
signal, also emit the properties change signal for ClientCount.
2019-07-04 16:04:35 +02:00
Christian Kellner
d2bab2962d daemon: export game objects on the bus
For each registered game, export an object on the bus under the
path "/com/feralinteractive/GameMode/Games/<pid>" with an dbus
interface of ""com.feralinteractive.GameMode.Game". The interface
currently provides to properties, ProcessId and Executable.
Additionally add the ListGames method and the GameRegistered,
GameUnregistered signals to the com.feralinteractive.GameMode
interface.
2019-07-04 16:04:35 +02:00
Christian Kellner
5949a988ea daemon: add game_mode_context_lookup_client method
Like game_mode_context_has_client, but will add a reference to
the client, if a match was found.
2019-07-02 17:47:05 +02:00
Christian Kellner
208f37b7d1 daemon: method to list all registered clients
Return an array of pid_t elements containing the process ids of
all registered clients. Memory ownership is transferred to the
client and must be freed.
2019-07-02 17:47:05 +02:00
Christian Kellner
455ea0c72e daemon: getters for properties of GameModeClient
Add getters for all two properties of GameModeCLient: the process
id and the executable path.
2019-07-02 17:46:52 +02:00
Christian Kellner
d99af40795 daemon: add game_mode_client_ref
Now that GameModeClient is reference counted, the counterpart to
game_mode_client_unref is also needed.
2019-07-02 17:46:31 +02:00
Christian Kellner
7e10cc3a0b daemon: make game_mode_client_unref public
So it can be used outside ouf gamemode-context.c.
2019-07-02 17:46:24 +02:00
Christian Kellner
2027e981e6 daemon: expose GameModeClient as opaque struct
First step to making GameModeClient useful outside of gamemode-
context.c.
2019-07-02 17:45:55 +02:00
Marc Di Luzio
c5c966ad54 Add back needed include 2019-06-01 10:57:27 +01:00
Marc Di Luzio
2e67906402 Remove unneeded includes 2019-06-01 10:57:27 +01:00
Marc Di Luzio
98e656f9ec Clean up self explanatory comments 2019-06-01 10:54:22 +01:00
Marc Di Luzio
1b78d0dcf7 Restructure files and libraries
Rename a bunch of files to make the consistent
	Create two new subdirectories for common code, and utilities
2019-06-01 10:54:22 +01:00
Marc Di Luzio
41988b7f1c Move code only used for Wine detection into wine file 2019-06-01 10:54:22 +01:00
Marc Di Luzio
1df1852c76 Move most Wine could out to Wine file 2019-06-01 10:54:22 +01:00
Marc Di Luzio
ec55bda3b2 Implement inotify check on the reaper thread for config changes 2019-05-19 11:15:47 +01:00
Marc Di Luzio
ceb1808c95 Initial implementation of a RefreshConfig dbus interface 2019-05-19 11:15:47 +01:00
Marc Di Luzio
2249a71355 Get ready for re-setting ioprio value on un-register
Implements tests for feature

	Fixes CLAMP macro
2019-05-11 12:08:29 +01:00
Marc Di Luzio
09d63ae4f5 Set up for resetting niceness value
Add tests to check this feature
	Apply config validation in config for simplicity

	Note: if anything messes with the niceness (ie. it starts non-zero, or it's not the expected value during setup, we'll bail out)
2019-05-11 12:08:29 +01:00
Christian Kellner
6d921617f9 daemon: make context_num_clients a public method
So it can be used from outside daemon/gamemode.c, to e.g. implement
an ClientCount property.
2019-04-10 23:57:00 +02:00
Alex Smith
10a31f8dec Update copyright years to 2019 2019-03-14 16:59:30 +00:00
Marc Di Luzio
9ade4481c3 Change AMD overclocking to simply be setting the power_dpm_force_performance_level file for now
This covers the MVP for now, and simply allows pinning the power level to "high"

	Full overclocking set up is somewhat more complicated, and it'll be better to implement that at the same time as the same for Nvidia, where we're currently only really setting the top end power level
2019-03-10 10:32:08 +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
c2f7e971c6 Implement game_mode_query_status_for as well 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
20a4862888 Add functionality to get the current GPU information in the daemon 2019-02-20 17:53:13 +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
0b4e86651e Add a preliminary client test suite
This simply tests the current functionality of the gamemode_client tools by calling each function in turn and checking the values return correctly.

	Requires the gamemode service to currently be running and installed on the system.
2019-01-28 16:36:08 +00:00
Marc Di Luzio
94cfa2de54 Add game_mode_run_tests function to trigger tests 2019-01-28 16:36:08 +00: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
Marc Di Luzio
4f3bc2c9a2 Add gamemode_query_status and teach gamemoded '-s'
This allows the client to query the daemon about the status of gamemode.

	Returns the following:
		 0 if gamemode is inactive
		 1 if gamemode is active
		 2 if gamemode is active and this client is registered
		-1 if the query failed

	Passing -s to gamemoded will simply query and print the current status.

	Allows for more comprehensive testing when using 'gamemoded -r' as well as more reactionary program behaviour
2018-04-25 14:51:38 +01:00
Ikey Doherty
69db9c2a61 Conformance: Update copyright range to include 2018
Signed-off-by: Ikey Doherty <ikey@solus-project.com>
2018-04-10 13:23:38 +01:00
Ikey Doherty
68e326de60 Transform into a full D-BUS service with Polkit support
Primarily we convert the service into a thread safe one that isn't reliant
on signaling for control flow, eliminating data race conditions. We also
enable interleaving by separating game mode pivoting from explicit client
registration.

The static pid list is now converted into a dynamic list that is OOM safe
to store all registered clients (with a reasonable upper limit of 256 clients)
to better handle cases where LD_PRELOAD is used for a large process group.
Additionally we begin storing some metadata on the connected clients such
as their executable path, which will enable us to perform some basic
whitelisting in future.

The cpugovctl binary is now moved into the libexecdir as an explicit helper
of the D-BUS service, using the shared library to merge some code back into
the daemon. This saves having to execute a process to query the state of the
governors, as we don't need a privileged client to do this.

In order to sanely set the governors, we require that the binary is running
as euid 0, and execute this using `pkexec`. A PolKit policy definition is
provided which allows active/logged in users to execute this helper through
a path whitelist. As such we can convert the daemon into user-mode only, with
the privileged helper being dispatched exclusively via polkit. This removes
the need for a setuid helper or having a system mode daemon.

Lastly we clean up the codebase a bit to be consistent with modern C code
conventions, using pragmas where available. The library component still uses
the older ifdef approach to support older compilers, but the daemon portion
uses the directive to simplify intent and speed up compilation. Additionally
we move all comments to C style comments for consistency, instead of mixing
in C++ style single line comments, in order to establish a formal coding
style.

The net result is a more robust service which can be D-BUS activated when
clients need it, that can perform scaling automatically without harassing
the user with authentication popups.

Signed-off-by: Ikey Doherty <ikey@solus-project.com>
2018-03-05 17:32:25 +00:00
Marc Di Luzio
2bbaab129b Apply clang format to files
Also add brackets for all scopes at the same time
2018-03-05 17:32:01 +00:00
Marc Di Luzio
c459c05076 Initial 0.1 commit
This is a small daemon/libary to enable games to request a
performance "game mode" from the system.

Currently only implemented to upgrade the CPU governor and
automatically downgrade it once done.

A game only needs to load libgamemodeauto to activate the request.
Which means an LD_PRELOAD can be applied to any game to activate
the mode as needed.

However gamemode_client.h can be used to manually activate/deactivate
the mode as needed, and also perform error checking.

The libs are miminal loaders to call into an installed libgamemode
which, if the daemon is installed and running, will send through
the equivelant game mode request, and magic will happen.

See the README.md for more details.

Currently licensed under the BSD 3 clause license.
2018-03-05 17:32:01 +00:00