RDKEMW-14901: Add support for cgroup v2#447
Open
ks734 wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds cgroups v2 (unified hierarchy) awareness across Dobby’s environment API, stats collection, init OOM detection, and OCI template generation so the daemon/plugins can run on systems defaulting to cgroups v2.
Changes:
- Extend
IDobbyEnv/DobbyEnvwith cgroup version detection and v1/v2-aware mount path handling. - Update stats + OOM detection to use v2 file formats (
cpu.stat,memory.events,memory.max/current/peak) while keeping v1 behavior. - Gate OCI
swappinessemission behind a template section so it’s omitted on v2; remove CI template patching step.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/include/IDobbyEnv.h | Adds CgroupVersion and cgroupVersion() API for v1/v2 branching. |
| daemon/lib/source/include/DobbyEnv.h | Plumbs cgroup version + mount point discovery signature changes. |
| daemon/lib/source/DobbyEnv.cpp | Detects v1/v2 and scans /proc/mounts for cgroup vs cgroup2. |
| daemon/lib/source/include/DobbyStats.h | Adds readCgroupKeyValue() helper for v2 key/value files. |
| daemon/lib/source/DobbyStats.cpp | Switches stats collection to v1/v2-specific filenames and parsing. |
| daemon/init/source/InitMain.cpp | Updates OOM detection to read memory.events on v2. |
| rdkPlugins/OOMCrash/source/OOMCrashPlugin.cpp | Reads v1 memory.failcnt vs v2 memory.events oom_kill. |
| rdkPlugins/GPU/source/GpuPlugin.cpp | Detects v2 and returns empty mount (intended graceful degradation). |
| rdkPlugins/IONMemory/source/IonMemoryPlugin.cpp | Detects v2 and returns empty mount (intended graceful degradation). |
| bundle/lib/source/DobbyTemplate.cpp | Recognizes cgroup2 mounts for RT scheduling template values. |
| bundle/lib/source/DobbySpecConfig.cpp | Adds SWAPPINESS_ENABLED section gating based on v1/v2 detection. |
| bundle/lib/source/templates/OciConfigJson1.0.2-dobby.template | Conditionally emits swappiness. |
| bundle/lib/source/templates/OciConfigJsonVM1.0.2-dobby.template | Conditionally emits swappiness. |
| tests/L1_testing/mocks/DobbyEnv.h | Updates mock interface for new cgroupVersion(). |
| tests/L1_testing/mocks/DobbyEnvMock.h | Adds gmock method for cgroupVersion(). |
| tests/L1_testing/mocks/DobbyEnvMock.cpp | Adds delegation for cgroupVersion(). |
| openspec/specs/proposals/cgroupv2-support.md | Documents the implemented approach/changes. |
| .github/workflows/L2-tests.yml | Removes CI-time template patching for v2 swappiness. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+177
to
+184
| // On cgroups v2 there is no separate gpu cgroup controller | ||
| struct stat st; | ||
| if (stat("/sys/fs/cgroup/cgroup.controllers", &st) == 0) | ||
| { | ||
| AI_LOG_WARN("gpu cgroup controller not available on cgroups v2"); | ||
| AI_LOG_FN_EXIT(); | ||
| return std::string(); | ||
| } |
Comment on lines
+193
to
+200
| // On cgroups v2 there is no separate ion cgroup controller | ||
| struct stat st; | ||
| if (stat("/sys/fs/cgroup/cgroup.controllers", &st) == 0) | ||
| { | ||
| AI_LOG_WARN("ion cgroup controller not available on cgroups v2"); | ||
| AI_LOG_FN_EXIT(); | ||
| return std::string(); | ||
| } |
| fclose(fp); | ||
| AI_LOG_ERROR("failed to read cgroup file line (%d - %s)", errno, strerror(errno)); | ||
| return false; | ||
| return true; |
Comment on lines
+180
to
+186
| // cgroups v2 memory file names | ||
| stats["memory"]["user"]["limit"] = | ||
| readSingleCgroupValue(id, memCgroupPath, "memory.max"); | ||
| stats["memory"]["user"]["usage"] = | ||
| readSingleCgroupValue(id, memCgroupPath, "memory.current"); | ||
| stats["memory"]["user"]["max"] = | ||
| readSingleCgroupValue(id, memCgroupPath, "memory.peak"); |
Comment on lines
+643
to
+649
| // swappiness is not supported on cgroups v2, only show if on v1 | ||
| { | ||
| struct stat st; | ||
| if (stat("/sys/fs/cgroup/cgroup.controllers", &st) != 0) | ||
| { | ||
| dictionary->ShowSection(SWAPPINESS_ENABLED); | ||
| } |
Comment on lines
+477
to
+482
| // On cgroups v2, check for cpu.max under the unified mount | ||
| if (strcmp(mnt->mnt_type, "cgroup2") == 0) | ||
| { | ||
| // v2 doesn't expose per-group rt_runtime_us; RT scheduling is | ||
| // handled differently. Leave values as 0 → null in template. | ||
| break; |
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.
Description
Add cgroups v2 (unified hierarchy) support to Dobby plugins and daemon components. All hardcoded cgroups v1 paths are now guarded by proper version detection checks, allowing Dobby to run correctly on modern kernels that default to cgroups v2.
Test Procedure
Type of Change
Requires Bitbake Recipe changes?
meta-rdk-ext/recipes-containers/dobby/dobby.bb) must be modified to support the changes in this PR (beyond updatingSRC_REV)