$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
perf_mode.h File Reference

Runtime performance optimization module. More...

#include <sched.h>
Include dependency graph for perf_mode.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PerfModeContext
 State container for performance mode. More...
 

Enumerations

enum  PerfModeState {
  PERF_MODE_OFF = 0 , PERF_MODE_GAMEMODE , PERF_MODE_NATIVE_SCHED , PERF_MODE_NATIVE_NICE ,
  PERF_MODE_ERROR
}
 Current state of the performance mode subsystem. More...
 
enum  PerfModeBackend { PERF_BACKEND_NONE = 0 , PERF_BACKEND_GAMEMODE , PERF_BACKEND_NATIVE }
 Available performance optimization backends. More...
 

Functions

int perf_mode_init (PerfModeContext *ctx)
 Initialize the performance mode subsystem. More...
 
void perf_mode_cleanup (PerfModeContext *ctx)
 Clean up performance mode resources. More...
 
int perf_mode_request_start (PerfModeContext *ctx)
 Request activation of performance mode. More...
 
int perf_mode_request_end (PerfModeContext *ctx)
 Request deactivation of performance mode. More...
 
PerfModeState perf_mode_get_state (const PerfModeContext *ctx)
 Get the current performance mode state. More...
 
PerfModeBackend perf_mode_get_backend (const PerfModeContext *ctx)
 Get the detected backend type. More...
 
const char * perf_mode_get_state_string (const PerfModeContext *ctx)
 Get a human-readable string for the current state. More...
 
int perf_mode_is_active (const PerfModeContext *ctx)
 Check if performance mode is currently active. More...
 

Detailed Description

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

// Performance mode active
}
// ... run application ...
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

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ perf_mode_cleanup()

void perf_mode_cleanup ( PerfModeContext ctx)

Clean up performance mode resources.

Ensures any active optimizations are properly reverted. Should be called at application shutdown.

Parameters
ctxPointer to the context.
Here is the call graph for this function:

◆ perf_mode_get_backend()

PerfModeBackend perf_mode_get_backend ( const PerfModeContext ctx)

Get the detected backend type.

Parameters
ctxPointer to the context.
Returns
Detected PerfModeBackend value.

◆ perf_mode_get_state()

PerfModeState perf_mode_get_state ( const PerfModeContext ctx)

Get the current performance mode state.

Parameters
ctxPointer to the context.
Returns
Current PerfModeState value.

◆ perf_mode_get_state_string()

const char* perf_mode_get_state_string ( const PerfModeContext ctx)

Get a human-readable string for the current state.

Parameters
ctxPointer to the context.
Returns
Static string describing the current mode (e.g., "GameMode", "Native SCHED_FIFO", "Off").

◆ perf_mode_init()

int perf_mode_init ( PerfModeContext ctx)

Initialize the performance mode subsystem.

Detects available backends (GameMode daemon, native capabilities). Should be called once at application startup.

Parameters
ctxPointer to the context to initialize.
Returns
0 on success, -1 on failure.
Here is the call graph for this function:

◆ perf_mode_is_active()

int perf_mode_is_active ( const PerfModeContext ctx)

Check if performance mode is currently active.

Parameters
ctxPointer to the context.
Returns
1 if active, 0 if not.

◆ perf_mode_request_end()

int perf_mode_request_end ( PerfModeContext ctx)

Request deactivation of performance mode.

Reverts any system changes made by perf_mode_request_start().

Parameters
ctxPointer to the context.
Returns
0 on success, -1 on failure.
Here is the call graph for this function:

◆ perf_mode_request_start()

int perf_mode_request_start ( PerfModeContext ctx)

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
ctxPointer 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.
Here is the call graph for this function: