Skip to content

Commit b2224f0

Browse files
committed
add CMA (Contiguous Memory Allocator) enablement test script
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>
1 parent d37dcc2 commit b2224f0

3 files changed

Lines changed: 401 additions & 0 deletions

File tree

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# CMA (Contiguous Memory Allocator) Enablement Test
2+
3+
## Overview
4+
5+
This test validates CMA (Contiguous Memory Allocator) enablement, configuration, and functionality on Qualcomm platforms. CMA is essential for allocating large contiguous memory blocks required by multimedia devices like cameras, displays, and video encoders.
6+
7+
## What is CMA?
8+
9+
CMA (Contiguous Memory Allocator) is a Linux kernel framework that:
10+
- Reserves a pool of physically contiguous memory at boot time
11+
- Allows normal page allocations from this pool when not in use
12+
- Provides large contiguous allocations when needed by devices
13+
- Critical for DMA operations requiring physically contiguous buffers
14+
15+
## Test Coverage
16+
17+
### 1. CMA Kernel Configuration
18+
- **CONFIG_CMA** - Core CMA support (mandatory)
19+
- **CONFIG_DMA_CMA** - Core CMA support (mandatory)
20+
- **CONFIG_CMA_DEBUG** - Core CMA support (mandatory)
21+
- **CONFIG_CMA_DEBUGFS** - Core CMA support (mandatory)
22+
- **CONFIG_CMA_SIZE_MBYTES** - Default CMA size configuration
23+
- **CONFIG_CMA_SIZE_SEL_MBYTES** - CMA size selection method
24+
- **CONFIG_CMA_AREAS** - Maximum number of CMA areas
25+
26+
### 2. CMA Memory Statistics
27+
- Total CMA memory available
28+
- Free CMA memory
29+
- Used CMA memory
30+
- Usage percentage calculation
31+
- Size validation (minimum 1MB)
32+
33+
### 3. CMA Device Tree Configuration
34+
- CMA size from device tree
35+
- CMA alignment properties
36+
- Reserved memory region enumeration
37+
38+
### 4. CMA Initialization and Runtime
39+
- CMA reservation messages in kernel logs
40+
- CMA allocation/release activity
41+
- Error and warning detection
42+
- Runtime behavior validation
43+
44+
### 5. CMA Sysfs/Debugfs Interface
45+
- CMA debugfs (`/sys/kernel/debug/cma`)
46+
- CMA area enumeration
47+
- Per-area allocation statistics
48+
- CMA statistics in `/proc/vmstat`
49+
50+
## Usage
51+
52+
### Run directly:
53+
```bash
54+
cd /path/to/Runner/suites/Kernel/Baseport/cma
55+
./run.sh
56+
```
57+
58+
### Run via test runner:
59+
```bash
60+
cd /path/to/Runner
61+
./run-test.sh cma
62+
```
63+
64+
## Test Results
65+
66+
Generates:
67+
- `cma.res` - Final result (PASS/FAIL)
68+
- Console output with detailed CMA information
69+
70+
## Prerequisites
71+
72+
### Required:
73+
- `CONFIG_DMA_CMA=y` `CONFIG_CMA=y` `CONFIG_CMA_DEBUG=y` `CONFIG_CMA_DEBUGFS=y` in kernel configuration
74+
- CMA memory reserved (via device tree or kernel command line)
75+
76+
### Optional:
77+
- Debugfs mounted at `/sys/kernel/debug` (for detailed statistics)
78+
- Root or appropriate permissions
79+
80+
## Expected Output
81+
82+
```
83+
[INFO] 1980-01-06 00:18:47 - ================================================================================
84+
[INFO] 1980-01-06 00:18:47 - ============ Starting cma Testcase =======================================
85+
[INFO] 1980-01-06 00:18:47 - ================================================================================
86+
[INFO] 1980-01-06 00:18:47 - === CMA Kernel Configuration Validation ===
87+
[PASS] 1980-01-06 00:18:47 - Kernel config CONFIG_CMA is enabled
88+
[PASS] 1980-01-06 00:18:47 - Kernel config CONFIG_DMA_CMA is enabled
89+
[PASS] 1980-01-06 00:18:47 - Kernel config CONFIG_CMA_DEBUG is enabled
90+
[PASS] 1980-01-06 00:18:47 - Kernel config CONFIG_CMA_DEBUGFS is enabled
91+
[PASS] 1980-01-06 00:18:47 - CMA kernel configuration validated
92+
[INFO] 1980-01-06 00:18:47 - Checking optional CMA configurations...
93+
[FAIL] 1980-01-06 00:18:47 - Kernel config CONFIG_CMA_SIZE_MBYTES is missing or not enabled
94+
[INFO] 1980-01-06 00:18:47 - CONFIG_CMA_SIZE_MBYTES: not set (optional)
95+
[PASS] 1980-01-06 00:18:47 - Kernel config CONFIG_CMA_SIZE_SEL_MBYTES is enabled
96+
[INFO] 1980-01-06 00:18:47 - CONFIG_CMA_SIZE_SEL_MBYTES:
97+
[FAIL] 1980-01-06 00:18:48 - Kernel config CONFIG_CMA_AREAS is missing or not enabled
98+
[INFO] 1980-01-06 00:18:48 - CONFIG_CMA_AREAS: not set (optional)
99+
[INFO] 1980-01-06 00:18:48 - === CMA Memory Statistics ===
100+
[INFO] 1980-01-06 00:18:48 - CMA Memory Statistics:
101+
[INFO] 1980-01-06 00:18:48 - Total: 172 MB (176128 kB)
102+
[INFO] 1980-01-06 00:18:48 - Free: 119 MB (122548 kB)
103+
[INFO] 1980-01-06 00:18:48 - Used: 52 MB (53580 kB)
104+
[INFO] 1980-01-06 00:18:48 - Usage: 30%
105+
[PASS] 1980-01-06 00:18:48 - CMA memory statistics validated
106+
[INFO] 1980-01-06 00:18:48 - Total reserved memory regions: 32
107+
[INFO] 1980-01-06 00:18:48 - === CMA Initialization and Runtime ===
108+
[PASS] 1980-01-06 00:18:48 - CMA initialization messages found in dmesg:
109+
[INFO] 1980-01-06 00:18:48 - [ 17.510276] cma: cma_alloc(cma ffffffc0823f1b38, name: reserved, count 2, align 1)
110+
[INFO] 1980-01-06 00:18:48 - [ 17.924390] cma: cma_alloc(cma ffffffc0823f1b38, name: reserved, count 32, align 5)
111+
[INFO] 1980-01-06 00:18:48 - [ 17.935579] cma: cma_alloc(cma ffffffc0823f1b38, name: reserved, count 128, align 7)
112+
[INFO] 1980-01-06 00:18:48 - [ 18.501219] cma: cma_alloc(cma ffffffc0823f1b38, name: reserved, count 2, align 1)
113+
[INFO] 1980-01-06 00:18:48 - CMA allocation/release activity detected
114+
[INFO] 1980-01-06 00:18:48 - Allocations: 42
115+
[INFO] 1980-01-06 00:18:48 - Releases: 8
116+
[INFO] 1980-01-06 00:18:48 - === CMA Sysfs/Debugfs Interface ===
117+
[INFO] 1980-01-06 00:18:48 - Found CMA debugfs: /sys/kernel/debug/cma
118+
[INFO] 1980-01-06 00:18:48 - CMA area: reserved
119+
[INFO] 1980-01-06 00:18:48 - Total CMA areas: 1
120+
[PASS] 1980-01-06 00:18:48 - CMA statistics in /proc/vmstat:
121+
[INFO] 1980-01-06 00:18:48 - nr_free_cma 30637
122+
[INFO] 1980-01-06 00:18:48 - cma_alloc_success 21
123+
[INFO] 1980-01-06 00:18:48 - cma_alloc_fail 0
124+
[INFO] 1980-01-06 00:18:48 - ================================================================================
125+
[PASS] 1980-01-06 00:18:48 - cma : Test Passed
126+
```
127+
128+
## CMA Configuration Methods
129+
130+
### 1. Device Tree Configuration (Recommended)
131+
```dts
132+
reserved-memory {
133+
#address-cells = <2>;
134+
#size-cells = <2>;
135+
ranges;
136+
137+
linux,cma {
138+
compatible = "shared-dma-pool";
139+
reusable;
140+
size = <0x0 0x20000000>; /* 512 MB */
141+
alignment = <0x0 0x00400000>; /* 4 MB */
142+
linux,cma-default;
143+
};
144+
};
145+
```
146+
147+
### 2. Kernel Command Line
148+
```bash
149+
cma=512M
150+
```
151+
152+
### 3. Kernel Config Default
153+
```
154+
CONFIG_CMA_SIZE_MBYTES=512
155+
```
156+
157+
158+
159+
## License
160+
161+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
162+
SPDX-License-Identifier: BSD-3-Clause
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
metadata:
2+
format: Lava-Test Test Definition 1.0
3+
name: cma
4+
description: "CMA (Contiguous Memory Allocator) enablement and functionality validation"
5+
maintainer:
6+
- vnarapar@qti.qualcomm.com
7+
os:
8+
- openembedded
9+
scope:
10+
- functional
11+
devices:
12+
- rb3gen2
13+
- qcs6490
14+
- qcs8300
15+
- qcs9100
16+
- sa8775p
17+
18+
run:
19+
steps:
20+
- REPO_PATH=$PWD
21+
- cd Runner/suites/Kernel/Baseport/cma
22+
- ./run.sh
23+
- $REPO_PATH/Runner/utils/send-to-lava.sh cma.res

0 commit comments

Comments
 (0)