Extending Logging Interface#75
Open
zbelinsk wants to merge 4 commits into
Open
Conversation
Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
Expands the logging system from a simple H2K_log() macro into a complete structured logging API with severity levels, spam control, and build-time filtering. ## New API (all three build modes: LOGBUF, LOG_PRINTF, silent) Severity variants: H2K_log_err/warn/info/dbg(fmt, ...) H2K_log_string_at(level, S), H2K_log_string_err/warn/info/dbg(S) Spam control — log once per callsite: H2K_log_once[_err/warn/info/dbg](...) H2K_log_once_ht[_err/warn/info/dbg](...) per hardware thread Spam control — rate limited by PCycle interval: H2K_log_throttle[_err/warn/info/dbg](interval, ...) H2K_log_throttle_ht[_err/warn/info/dbg](interval, ...) per hardware thread All string variants (_string_once, _string_throttle, _ht) follow the same pattern, giving a full NxM matrix of combinations. ## Log prefix format (same in both LOGBUF and LOG_PRINTF) [ht<id>][LEVEL][<pcycles>][<file>:<line>] message ## Build-time level filtering make LOGBUF=1[2] whole kernel, INFO and above only make LOGBUF=sched[1] sched directory, WARN and above make LOGBUF=dosched.ref.c[0] single file, ERROR only make LOGBUF=sched,futex[2] mixed, no level = default (DBG) The [level] syntax works for both kernel (LOGBUF) and standalone test (LOG_PRINTF) builds via Makefile.inc.test. ## Implementation notes - LOGBUF: lockless per-htid ring buffer; spinlock only for Angel flush. Formatting (emit_prefix + format parse) happens outside the lock. H2K_log_once uses H2K_atomic_setbit; H2K_log_throttle uses logbuf_lock. H2K_log_throttle_ht / H2K_log_once_ht are lockless (per-slot ownership). - LOG_PRINTF: static inline helpers (H2K_printf_now via H2K_get_pcycle_reg, H2K_printf_basename via strrchr) give full prefix with zero link deps. H2K_printf_log_once (atomic) and H2K_printf_log_throttle (spinlock) live in log.ref.c under #ifdef H2K_LOG_PRINTF. - H2K_log_string now has identical semantics in both modes (full prefix + level check), replacing the previous puts() shortcut in LOG_PRINTF. Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
5e1b8a1 to
0654e7c
Compare
Three improvements to the logging system:
1. Accept symbolic level names in LOGBUF syntax (err, warn, info, dbg) in
addition to numeric values (0, 1, 2, 3):
make LOGBUF=1[warn] whole kernel, WARN and above
make LOGBUF=sched[info] sched directory, INFO and above
make LOGBUF=futex[err],sched[dbg] mixed symbolic and numeric
2. Add H2K_LOG_NO_SPAM mode to strip spam-control macros (once/throttle) and
make them no-ops. Eliminates static state bloat:
make LOGBUF=1[warn] H2K_LOG_NO_SPAM=1
In this mode, H2K_log_once/throttle macros become empty (no-op), while
base H2K_log/err/warn/info/dbg macros still emit normally.
3. Optimize H2K_log_once_ht to use a single u32 bitmask instead of an array.
Each hardware thread's once-flag is now a single bit in a shared u32,
reducing per-callsite memory from MAX_HTHREADS*4 bytes to 4 bytes.
Uses H2K_atomic_setbit for race-free per-bit access. Works in both
H2K_LOGBUF and H2K_LOG_PRINTF modes.
Implemented via Makefile function for level mapping, conditional macro
redefinition in log.h, and bitmask logic in log.ref.c. Works in both kernel
(LOGBUF) and standalone test (LOG_PRINTF) builds.
Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
0654e7c to
5f0098b
Compare
Signed-off-by: Zeev Belinsky <zbelinsk@qti.qualcomm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Logging system improvements: symbolic level names, spam-control opt-out, and memory optimization.
err,warn,info,dbg) inLOGBUFsyntax alongside numeric valuesH2K_LOG_NO_SPAMmode to disable spam-control macros (once/throttle), making them no-opsH2K_log_once_ht()to use a single u32 bitmask instead of an array (4 bytes vs. 4×MAX_HTHREADS bytes per callsite)Examples
Details
Symbolic Levels
err→ 0 (ERROR)warn→ 1 (WARN)info→ 2 (INFO)dbg→ 3 (DEBUG)H2K_LOG_NO_SPAM Mode
When enabled,
H2K_log_once*()andH2K_log_throttle*()macros become empty (no-op). Eliminates static state bloat:H2K_log_once()allocates a u32 flag per callsite (tracks if already logged)H2K_log_throttle()allocates a u64 timestamp per callsite (tracks last emit time)H2K_log_throttle_ht()allocates u64[MAX_HTHREADS] per callsite (per-HT timestamps)H2K_log_once_ht()uses a single u32 bitmask per callsite. Each hardware thread's once-flag is one bit, accessed atomically viaH2K_atomic_setbit().With the flag, these allocations are skipped entirely.