How mchehab/rasdaemon works
Project Type and Purpose
• This is a userspace daemon (rasdaemon) intended to collect and correlate hardware RAS (Reliability, Availability, Serviceability) events emitted by the Linux kernel (EDAC, MCE, PCIe AER, APEI, etc.). It reads kernel tracepoints via debugfs, dispatches events to specialized handlers, logs them (syslog/journald), and can optionally persist them in a SQLite database for later analysis.
File‐Structure Analysis
• Top level: build/configuration files (configure.ac, Makefile.am, m4/, .github/, scripts/, man/).
• Core code:
• rasdaemon.c – main daemon loop, trace event subscription, dispatch logic
• ras-*.c / ras-*.h – one handler pair per event type (ras-mce-handler.c, ras-aer-handler.c, ras-arm-handler.c, etc.)
• util/ras-mc-ctl.in – auxiliary CLI tool to query or inject events
• bitfield.c/h, queue.c/h, rbtree.c/h – internal data‐structure libraries
• trigger.c/h – logic for threshold‐based actions
• contrib/: test and injection scripts (edac-fake-inject, AER/MCE injectors)
• misc/: init scripts and systemd unit templates
• No GUI or web frontend—pure daemon + CLI tools.
README Insights
• Describes concepts: tracepoint-based event collection, user‐space policy engine, optional SQLite storage, syslog/journal integration, and how to compile/install/run.
• Mentions optional features (--enable-sqlite3, --enable-aer, --enable-mce) toggling backends and event types.
Main Components
a. Kernel Event Sources
• EDAC drivers, Machine Check (MCE) driver, PCIe AER, APEI—each exposing tracepoints under debugfs.
b. libtraceevent Layer
• Subscribes to kernel tracepoints, parses raw events into in‐memory structures.
c. rasdaemon Core
• Central event loop (rasdaemon.c) that:
• Reads events from trace pipe
• Dispatches to the correct handler module based on event type
• Maintains internal state (queues, rbtrees) for deduplication, correlation
• Applies trigger logic (thresholds, burst detection) via trigger.c
d. Handler Modules
• One per event family (ras-mce-handler, ras-aer-handler, ras-devlink-handler, etc.)
• Convert generic trace data into a unified RAS event representation
e. Output Backends
• Syslog/journald logger (built‐in)
• SQLite3 storage (if enabled): schema defined in code, persistent DB file
f. Auxiliary Tools and Scripts
• ras-mc-ctl: CLI front end for ad-hoc queries or error decoding
• contrib scripts: event injectors for testing
• systemd unit / init scripts for service management
Relationships and Data Flows
• Kernel → debugfs tracepoint files → libtraceevent → rasdaemon core → handler modules → output backends → syslog/journal or SQLite.
• Auxiliary CLI (ras-mc-ctl) ↔ SQLite DB or live daemon via IPC (if implemented).
• contrib scripts → kernel injection modules → test events into the same pipeline.
Architectural Patterns and Design Principles
• Modular handler pattern: new event types simply add new ras-*-handler modules.
• Single-threaded event loop for simplicity and ordering guarantees.
• Pluggable backends (logging vs. database) toggled at compile time.
• Lightweight data structures (queues, rbtree) for in-memory state and event correlation.