Runtime performance optimization module.
More...
#include <sched.h>
Go to the source code of this file.
Runtime performance optimization module.
Provides a unified interface for activating system-level performance optimizations similar to Windows "Game Mode". Uses libgamemode when available, with native Linux scheduler fallback.
Usage
}
int perf_mode_init(PerfModeContext *ctx)
Initialize the performance mode subsystem.
Definition: perf_mode.c:89
int perf_mode_request_start(PerfModeContext *ctx)
Request activation of performance mode.
Definition: perf_mode.c:277
int perf_mode_request_end(PerfModeContext *ctx)
Request deactivation of performance mode.
Definition: perf_mode.c:318
void perf_mode_cleanup(PerfModeContext *ctx)
Clean up performance mode resources.
Definition: perf_mode.c:350
◆ PerfModeBackend
Available performance optimization backends.
| Enumerator |
|---|
| PERF_BACKEND_NONE | No backend available.
|
| PERF_BACKEND_GAMEMODE | libgamemode detected.
|
| PERF_BACKEND_NATIVE | Native Linux syscalls.
|
◆ PerfModeState
Current state of the performance mode subsystem.
| Enumerator |
|---|
| PERF_MODE_OFF | No optimizations active.
|
| PERF_MODE_GAMEMODE | Using libgamemode/gamemoded.
|
| PERF_MODE_NATIVE_SCHED | Using native sched_setscheduler.
|
| PERF_MODE_NATIVE_NICE | Using native nice priority.
|
| PERF_MODE_ERROR | Activation failed.
|
◆ perf_mode_cleanup()
Clean up performance mode resources.
Ensures any active optimizations are properly reverted. Should be called at application shutdown.
- Parameters
-
| ctx | Pointer to the context. |
◆ perf_mode_get_backend()
Get the detected backend type.
- Parameters
-
| ctx | Pointer to the context. |
- Returns
- Detected PerfModeBackend value.
◆ perf_mode_get_state()
Get the current performance mode state.
- Parameters
-
| ctx | Pointer to the context. |
- Returns
- Current PerfModeState value.
◆ perf_mode_get_state_string()
Get a human-readable string for the current state.
- Parameters
-
| ctx | Pointer to the context. |
- Returns
- Static string describing the current mode (e.g., "GameMode", "Native SCHED_FIFO", "Off").
◆ perf_mode_init()
Initialize the performance mode subsystem.
Detects available backends (GameMode daemon, native capabilities). Should be called once at application startup.
- Parameters
-
| ctx | Pointer to the context to initialize. |
- Returns
- 0 on success, -1 on failure.
◆ perf_mode_is_active()
Check if performance mode is currently active.
- Parameters
-
| ctx | Pointer to the context. |
- Returns
- 1 if active, 0 if not.
◆ perf_mode_request_end()
Request deactivation of performance mode.
Reverts any system changes made by perf_mode_request_start().
- Parameters
-
| ctx | Pointer to the context. |
- Returns
- 0 on success, -1 on failure.
◆ perf_mode_request_start()
Request activation of performance mode.
Attempts to activate performance optimizations using the best available backend. Effects may include:
- CPU governor set to "performance"
- GPU performance mode enabled
- Process scheduling priority elevated
- Background services deprioritized
- Parameters
-
| ctx | Pointer to the context. |
- Returns
- 0 on success, -1 on failure.
- Note
- For native SCHED_FIFO, requires CAP_SYS_NICE or root. GameMode handles permissions via polkit.