add CMA (Contiguous Memory Allocator) enablement test script#298
add CMA (Contiguous Memory Allocator) enablement test script#298vnarapar wants to merge 1 commit intoqualcomm-linux:mainfrom
Conversation
Introduce a CMA enablement/validation script that verifies configuration, initialization, runtime behavior, and statistics on Qualcomm platforms. Key capabilities: - Kernel config validation: CONFIG_CMA, CONFIG_DMA_CMA, CONFIG_CMA_DEBUG, CONFIG_CMA_DEBUGFS (mandatory), plus optional CMA sizing and areas. - Memory stats collection: total, free, used, and usage% with size sanity checks (≥ 1 MB). - DT configuration checks: CMA size/alignment and reserved-memory regions. - Runtime verification: dmesg for CMA reservation/alloc/release messages, error/warning detection, and activity counts. - Sysfs/Debugfs interfaces: enumerate `/sys/kernel/debug/cma` areas and report per-area stats; include relevant `/proc/vmstat` counters. - Result artifacts: writes `cma.res` (PASS/FAIL) and logs detailed output to the console. Signed-off-by: Vamsee Narapareddi <vnarapar@qti.qualcomm.com>
smuppand
left a comment
There was a problem hiding this comment.
Right now the test is mostly presence + observation. To validate CMA “functionality”, add one or more active functional checks:
A) Validate CMA is actually being used by at least one subsystem (non-invasive)
Check for common multimedia allocations that use CMA:
ION / dma-buf heaps (depending on kernel/userspace)
camera/video drivers that allocate contiguous buffers
Practical checks:
Look for dma_alloc_from_contiguous users in dmesg? (rare)
Check for increases in CmaFree drop after starting a known multimedia test (optional integration)
Extension idea: If media-ctl/camera nodes exist, do a short yavta capture (or your existing camera smoke test) and re-read /proc/meminfo before/after:
If CMA total is non-zero and capture runs, expect CmaFree to fluctuate at least once.
Don’t hard-fail if it doesn’t (drivers may use other paths), but log as INFO.
B) Validate reserved-memory DT looks correct (stronger DT parsing)
Current DT check only counts regions. You can improve by:
Identify nodes with compatible = "shared-dma-pool" and/or linux,cma-default
Report their size, alignment, reusable
Verify at least one CMA pool exists in DT when kernel cmdline doesn’t specify cma=
Implementation detail:
Read /proc/device-tree/reserved-memory/*/compatible, /linux,cma-default, /size, /alignment.
Size properties are binary cells; needs hexdump parsing (doable with od -An -t u4 etc).
C) Validate kernel cmdline CMA overrides
Check /proc/cmdline for:
cma= or cma_pernuma= etc (if relevant)
If present, compare configured size against /proc/meminfo CmaTotal with tolerance.
D) Validate CMA areas and per-area stats from debugfs (more than listing names)
In debugfs CMA directories, there are often files like:
count, pages, used, maxchunk etc (varies by kernel) Your script only lists area names. Enhance to dump key files if present:
total pages
free pages
used pages
alloc failures counters
Make it resilient: “if file exists, print it”.
E) Proactively detect CMA allocation failures in logs (more accurate)
Instead of generic error|fail|warn, look for common CMA failure strings:
cma_alloc: alloc failed
Failed to allocate contiguous memory
dma_alloc_from_contiguous: ... failed
cma: ... allocation failed
This reduces false positives from generic “warn”.
F) Add “pressure” functional test (optional, gated)
If you want a true kernel functional test without requiring multimedia:
Use cma_test module if present (some trees have it)
Or allocate contiguous memory via a small C helper using dma_heap (but that’s userspace and device-dependent)
Or run a workload that triggers hugepage / buddy allocator fragmentation and see if CMA still allocates (hard to do reliably)
| log_info "Checking optional CMA configurations..." | ||
| for cfg in $OPTIONAL_CMA_CONFIGS; do | ||
| if check_kernel_config "$cfg" 2>/dev/null; then | ||
| value=$(grep "^$cfg=" /proc/config.gz 2>/dev/null | cut -d'=' -f2 || echo "enabled") |
There was a problem hiding this comment.
But /proc/config.gz is gzipped, grep won’t work unless you use zcat. Also check_kernel_config likely already knows how to read config from /proc/config.gz using zgrep/zcat. So the “value=…” printout is wrong on many targets.
Use get_kernel_config_value "$cfg" helper if you have it (or add one).
Or: zcat /proc/config.gz | grep "^$cfg=".
| log_info "=== CMA Initialization and Runtime ===" | ||
|
|
||
| # Check dmesg for CMA initialization | ||
| if dmesg | grep -i -q "cma.*reserved"; then |
There was a problem hiding this comment.
This is okay if you’re only logging, but be careful if later you want to update pass=false inside that loop — it won’t work due to subshell. Right now you set pass=false before the pipe in the warning case, so you’re safe, but keep it in mind.
Use scan_dmesg_errors prefer capturing into a variable/file and then iterating without a pipe if you ever need state changes.
| log_info "=== CMA Kernel Configuration Validation ===" | ||
|
|
||
| # Core CMA configs | ||
| CORE_CMA_CONFIGS="CONFIG_CMA CONFIG_DMA_CMA CONFIG_CMA_DEBUG CONFIG_CMA_DEBUGFS" |
There was a problem hiding this comment.
Right now you warn only. But you also fail earlier if CONFIG_CMA_DEBUGFS is missing. That’s okay for “enablement” coverage, but you should also emit a clear reason:
If config says enabled but path missing -> likely debugfs not mounted or permission issue -> WARN + remediation
If config not enabled -> FAIL (enablement missing)
Extension (recommended):
call a helper like ensure_debugfs_mounted (if you have one), or implement minimal:
check mountpoint, try mount if root.
| log_info "=== CMA Initialization and Runtime ===" | ||
|
|
||
| # Check dmesg for CMA initialization | ||
| if dmesg | grep -i -q "cma.*reserved"; then |
There was a problem hiding this comment.
Many kernels print CMA reservation messages in different forms (examples):
cma: Reserved 256 MiB at ...
Reserved memory: created CMA memory pool at ...
OF: reserved mem: initialized node linux,cma...
broaden patterns and be explicit:
cma:.*Reserved
CMA:.*reserved (some arch)
reserved mem.*CMA
linux,cma
| else | ||
| log_fail "$TESTNAME : Test Failed" | ||
| echo "$TESTNAME FAIL" > "$res_file" | ||
| exit 1 |
There was a problem hiding this comment.
I’d recommend exit 0 always (and rely on .res)
| - sa8775p | ||
|
|
||
| run: | ||
| steps: |
There was a problem hiding this comment.
Check for repo path before entering into the cma directory. Should be something like
- REPO_PATH="$PWD"
- cd "$REPO_PATH/Runner/suites/Kernel/Baseport/cma"
- ./run.sh
- "$REPO_PATH/Runner/utils/send-to-lava.sh" cma.res
Introduce a CMA enablement/validation script that verifies configuration, initialization, runtime behavior, and statistics on Qualcomm platforms.
Key capabilities:
/sys/kernel/debug/cmaareas and report per-area stats; include relevant/proc/vmstatcounters.cma.res(PASS/FAIL) and logs detailed output to the console.