Skip to content

Port to C - #3

Merged
spoulson merged 44 commits into
mainfrom
spoulson/c
Sep 12, 2026
Merged

spoulson merged 44 commits into
mainfrom
spoulson/c

Conversation

@spoulson

Copy link
Copy Markdown
Owner

Switching from Golang to C builds a smaller executable and runs with much less memory utilization.

Stats on Ubuntu 24.04:

Golang version

  • Executable size: 18,782,431
  • RSS: 19440
  • Systemctl status memory: 7.2M

C version

  • Executable size: 60,344
  • RSS: 9076
  • Systemctl status memory: 2.8M

spoulson and others added 30 commits May 26, 2026 20:28
ReadFanSpeeds and SetSpeed previously created their own context.Background(),
making them unresponsive to cancellation. Now they accept and use the caller's
context so SIGINT/SIGTERM aborts in-flight IPMI calls immediately.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Decouples suggestion receipt from fan speed application. The apply
block only runs when a sensor has posted a new speed since the last set,
preventing redundant SetSpeed calls from the fan-log ticker or other
non-sensor select cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- TempReader now returns map[string]float64 (CPU uses IPMI sensor name,
  GPU uses gpu0/gpu1/... index keys); Poll returns the map alongside
  the rolling aggregate
- Log "sensor temperature" includes latest_temps map and aggregate_temp
- "current fan speed" reverts to one log line per fan (map format was
  unreadable); Percent field removed, RPM and delta remain

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- make install: skip copying frostd.yaml if /etc/frostd.yaml already exists
- make uninstall_clean: runs uninstall then removes /etc/frostd.yaml and
  the log file defined within it

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rotates /var/log/frostd/frostd.log daily, retains 7 days, uses
copytruncate since frostd holds the log file open without reload support.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- SensorMonitor.Poll now records the max temp across sensor IDs each
  iteration rather than the average
- Add log_format config field ("text" or "json", default "text");
  frostd.yaml sets json for production

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…g reference

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
spoulson and others added 14 commits May 27, 2026 20:46
- Rename frostd_device_* metrics to frostd_sensor_*
- Drop _celsius suffix from temperature metric names
- Rename frostd_actual_fan_speed_rpm to frostd_actual_fan_rpm
- Use "Temp" as GPU sensor key to match IPMI naming convention

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Each sensor ID now maintains its own rolling sample buffer instead of
a single buffer fed by the per-poll maximum. Suggested fan speed is
derived from the max aggregate across all IDs. The Prometheus
frostd_sensor_aggregate_temperature metric gains an "id" label to
expose the individual aggregates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- service.c: create the speed-bus condvar with CLOCK_MONOTONIC so
  pthread_cond_timedwait's deadline matches the clock used to compute
  it. Previously the default CLOCK_REALTIME wait clock combined with a
  CLOCK_MONOTONIC deadline made every wait return ETIMEDOUT instantly,
  spinning the fan-log loop with no delay.
- ipmi.c: fix the sensor iterator loop condition. ipmi_monitoring_sensor_iterator_next()
  returns 1 on successful advance (0 means end of list), not 0 on
  success as the header comment implies. The old `== 0` check ended
  iteration after the first sensor of any type, so only one CPU/fan
  sensor was ever seen regardless of how many were present.
- ipmi.c: fix real_raw_command() to prepend the command byte to the
  request buffer passed to ipmi_cmd_raw(), which expects it as the
  first byte of the request rather than as a separate parameter. The
  command byte was previously discarded, so Dell OEM raw commands
  (enable manual fan control, set fan speed) never reached the BMC
  correctly and fans stayed at automatic/idle speed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KxtPMuWLTmsYMMwwbtMtFi
SIGTERM/SIGINT is delivered to a single thread of the process, and
neither clock_nanosleep nor pthread_cond_timedwait wake up early on
signal delivery (per POSIX/NPTL semantics). Previously, whichever
thread didn't receive the signal kept blocking until its own next
natural wakeup (up to sample_interval or fan_log_interval away, and
compounding with real IPMI call latency when fan control is active)
before it rechecked g_shutdown, so Ctrl-C could take up to that long,
or longer, to actually stop the service.

Cap every wait to a short poll granularity (1s) so any thread notices
g_shutdown promptly regardless of which thread the signal landed on,
while still only firing sample/fan-log actions on their real
deadlines.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KxtPMuWLTmsYMMwwbtMtFi
The Requirements section still listed the Go build toolchain from
before the port to C. Replace it with the actual build requirements
(GCC, make, and the C dev libraries) matching CLAUDE.md's Developer
Prerequisites.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KxtPMuWLTmsYMMwwbtMtFi
@spoulson
spoulson merged commit d3d7ceb into main Sep 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant