Skip to content

RDKEMW-14901: Add support for cgroup v2#447

Open
ks734 wants to merge 2 commits into
developfrom
topic/RDKEMW-14901
Open

RDKEMW-14901: Add support for cgroup v2#447
ks734 wants to merge 2 commits into
developfrom
topic/RDKEMW-14901

Conversation

@ks734
Copy link
Copy Markdown
Contributor

@ks734 ks734 commented May 22, 2026

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

  • On cgroup v1 device: verify containers start/stop normally, GPU/ION limits apply, OOM detection works via memory.failcnt, swappiness appears in generated OCI config
  • On cgroup v2 system: verify containers start/stop normally, GPU/ION plugins log warnings and degrade gracefully, OOM detection works via memory.events oom_kill field, swappiness is absent from OCI config
  • Ensure whether both L1 and L2 tests pass

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other (doesn't fit into the above categories - e.g. documentation updates)

Requires Bitbake Recipe changes?

  • The base Bitbake recipe (meta-rdk-ext/recipes-containers/dobby/dobby.bb) must be modified to support the changes in this PR (beyond updating SRC_REV)

@ks734 ks734 marked this pull request as ready for review May 25, 2026 12:29
Copilot AI review requested due to automatic review settings May 25, 2026 12:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / DobbyEnv with 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 swappiness emission 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants