Skip to content

Commit 5e1b8a1

Browse files
committed
log: symbolic levels, H2K_LOG_NO_SPAM mode, and bitmask once_ht
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>
1 parent dd64d3e commit 5e1b8a1

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

kernel/util/log/log.spec

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!--
2+
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3+
* SPDX-License-Identifier: BSD-3-Clause-Clear
4+
-->
5+
6+
# H2K Logging Specification
7+
8+
## Build Configuration
9+
10+
### LOGBUF Syntax
11+
12+
```
13+
make LOGBUF=<target>[<level>]
14+
```
15+
16+
- `<target>`: `1` (all), `<module>` (dir), `<file>` (filename), or comma-separated list
17+
- `<level>`: `0`/`err`, `1`/`warn`, `2`/`info`, `3`/`dbg` (default: `3`)
18+
19+
Examples:
20+
```
21+
make LOGBUF=1[warn] # whole kernel, WARN+
22+
make LOGBUF=sched[info] # sched module, INFO+
23+
make LOGBUF=sched[warn],futex[err] # mixed levels
24+
```
25+
26+
### H2K_LOG_NO_SPAM
27+
28+
Disables spam-control macros (once/throttle) to eliminate static state:
29+
```
30+
make LOGBUF=1[warn] H2K_LOG_NO_SPAM=1
31+
```
32+
33+
When enabled, `H2K_log_once*()` and `H2K_log_throttle*()` become no-ops.
34+
35+
## API
36+
37+
### Base Logging
38+
```c
39+
H2K_log(fmt, ...) // DEBUG
40+
H2K_log_err(fmt, ...) // ERROR
41+
H2K_log_warn(fmt, ...) // WARN
42+
H2K_log_info(fmt, ...) // INFO
43+
H2K_log_dbg(fmt, ...) // DEBUG
44+
```
45+
46+
### Spam Control
47+
```c
48+
H2K_log_once*(fmt, ...) // emit once per callsite (4 bytes)
49+
H2K_log_once_ht*(fmt, ...) // emit once per HT (4 bytes, bitmask)
50+
H2K_log_throttle*(interval, ...) // rate-limited (8 bytes)
51+
H2K_log_throttle_ht*(interval, ...) // per-HT rate-limited (8×MAX_HTHREADS bytes)
52+
```
53+
54+
All combinations of severity (`_err`, `_warn`, `_info`, `_dbg`) available.
55+
56+
### String Variants
57+
```c
58+
H2K_log_string*(S) // pre-formatted string
59+
H2K_log_string_once*(S) // with spam control
60+
H2K_log_string_throttle*(interval, S)
61+
```
62+
63+
## Output Format
64+
65+
```
66+
[ht<id>][<LEVEL>][<pcycles>][<file>:<line>] message
67+
```
68+
69+
Example: `[ht0][WARN][12345678][sched.c:42] reschedule timeout`
70+
71+
## Memory
72+
73+
| Macro | Storage |
74+
|-------|---------|
75+
| `H2K_log_once()` | 4 bytes (u32 flag) |
76+
| `H2K_log_once_ht()` | 4 bytes (u32 bitmask, 1 bit per HT) |
77+
| `H2K_log_throttle()` | 8 bytes (u64 timestamp) |
78+
| `H2K_log_throttle_ht()` | 8 × MAX_HTHREADS bytes |
79+
80+
With `H2K_LOG_NO_SPAM=1`: no static state for spam-control macros.
81+
82+
## Implementation
83+
84+
- **H2K_LOGBUF**: lockless per-HT ring buffers, atomic setbit for once, spinlock for throttle
85+
- **H2K_LOG_PRINTF**: printf-based, static inline prefix helpers, same spam-control logic
86+
- **Silent**: all macros are no-ops (default when neither flag set)

0 commit comments

Comments
 (0)