Documentation
¶
Overview ¶
Package governor is the resource-governance policy engine (SPEC §4.1, §10). It consumes idle/power signals, enforces the operator's serve policy, and guarantees instant-yield: on operator activity, in-flight requests are drained-or-cancelled within the configured grace window and the node marks itself YIELDED.
Index ¶
- Variables
- type ErrNotServing
- type FakeIdleSource
- type FakePowerSource
- type Governor
- func (g *Governor) Admit(parent context.Context, id string) (context.Context, func(), error)
- func (g *Governor) Inflight() int
- func (g *Governor) Policy() Policy
- func (g *Governor) Power() PowerStatus
- func (g *Governor) Run(ctx context.Context)
- func (g *Governor) SetPolicy(p Policy)
- func (g *Governor) State() State
- func (g *Governor) Subscribe() <-chan State
- type IdleSource
- type Policy
- type PowerSource
- type PowerStatus
- type State
- type Window
Constants ¶
This section is empty.
Variables ¶
var ErrNoIdleSource = errors.New("governor: idle detection not implemented on this platform")
ErrNoIdleSource is returned by stub platform sources.
Functions ¶
This section is empty.
Types ¶
type ErrNotServing ¶
type ErrNotServing struct{ State State }
ErrNotServing is returned by Admit when the governor refuses work.
func (ErrNotServing) Error ¶
func (e ErrNotServing) Error() string
type FakeIdleSource ¶
type FakeIdleSource struct {
// contains filtered or unexported fields
}
FakeIdleSource / FakePowerSource are shared by tests here and in other packages (localapi, tunnel) that need a controllable governor.
func (*FakeIdleSource) Fail ¶
func (f *FakeIdleSource) Fail(err error)
func (*FakeIdleSource) Set ¶
func (f *FakeIdleSource) Set(d time.Duration)
type FakePowerSource ¶
type FakePowerSource struct {
// contains filtered or unexported fields
}
func (*FakePowerSource) Set ¶
func (f *FakePowerSource) Set(ps PowerStatus)
func (*FakePowerSource) Status ¶
func (f *FakePowerSource) Status(context.Context) (PowerStatus, error)
type Governor ¶
type Governor struct {
// contains filtered or unexported fields
}
Governor evaluates Policy against live signals.
func New ¶
func New(p Policy, idle IdleSource, power PowerSource, clk clock.Clock, log *slog.Logger) *Governor
New builds a Governor. clk may be nil (wall clock).
func (*Governor) Admit ¶
Admit gates one request. On success it returns a request context that the governor cancels if the yield grace expires, plus a release func the caller MUST invoke when the request finishes (success or not).
func (*Governor) Power ¶
func (g *Governor) Power() PowerStatus
Power returns the last observed power status (for heartbeats).
type IdleSource ¶
IdleSource reports how long user input has been quiet. Platform implementations live in idle_*.go; tests use FakeIdleSource.
func NewPlatformIdleSource ¶
func NewPlatformIdleSource() IdleSource
NewPlatformIdleSource returns the Linux idle source: systemd-logind's IdleHint / IdleSinceHint for the operator's seat session, read through `loginctl show-session`. The session is $XDG_SESSION_ID when the daemon runs inside a login session, else the first active seat session from `loginctl list-sessions` (a systemd --user service has no XDG_SESSION_ID). No logind, or no seat session at all (headless), is ErrNoIdleSource: the governor assumes idle with a one-time log line, which is the right default for servers.
Caveat: IdleHint is set by the desktop session (GNOME, KDE, sway with an idle daemon…); a bare X session without one leaves it at "no", so the node never counts as idle there — serve_policy = always or scheduled is the operator's answer.
type Policy ¶
type Policy struct {
Serve string // always|idle-only|scheduled
IdleAfter time.Duration
YieldGrace time.Duration // drain-or-cancel window, default 2s
PollInterval time.Duration
ServeOnBattery bool
MaxTempCelsius float64
Schedule []Window
}
Policy is the operator's resource-governance configuration.
type PowerSource ¶
type PowerSource interface {
Status(ctx context.Context) (PowerStatus, error)
}
PowerSource reports battery/thermal state.
func NewPlatformPowerSource ¶
func NewPlatformPowerSource() PowerSource
NewPlatformPowerSource reads /sys/class/power_supply and thermal zones.
type PowerStatus ¶
PowerStatus is a battery/thermal snapshot. TempCelsius == 0 means unknown.
type State ¶
type State int
State is the governor's serving decision.
const ( // StateServing: the node accepts and runs inference. StateServing State = iota // StateYielded: the operator is using the machine (idle-only policy). StateYielded // StatePausedBattery: on battery and serve_on_battery=false. StatePausedBattery // StatePausedThermal: above the temperature ceiling. StatePausedThermal // StateOutsideSchedule: serve_policy=scheduled and now is out of window. StateOutsideSchedule )
type Window ¶
Window is a daily serving window in local time. Overnight windows (start > end, e.g. 22:00-08:00) wrap across midnight.
func ParseWindows ¶
ParseWindows parses a config list like ["22:00-08:00", "12:00-13:00"].