ARM-software / lisa

Linux Integrated System Analysis
Apache License 2.0
203 stars 119 forks source link

cgroups V2: support available? #2172

Closed Ablu closed 9 months ago

Ablu commented 10 months ago

Hi!

Systemd is quite ubiquitous nowadays. However, it looks like the cgroups module is not loaded under systemd due to incompatibilities. Now, I see that devlib has a cgroups2 module where the module documentation reads^1 like it may work with systemd.

Is there any way to use this with lisa? There does not seem to be much of documentation on how to use cgroups2 and the code structure looks quite different. So I am not really sure where to get started on integrating it with lisa.

douglas-raillard-arm commented 10 months ago

Hi there,

So the current state of affairs is:

There is a basic example in the module-level docstring: https://github.com/ARM-software/devlib/blob/e012b175c672df84cabf5cc22510b2848b91b399/devlib/module/cgroups2.py#L16

The general idea is that you specify how your hierarchy should look like and what controller you want to enable along with their settings, and then you use the setup_hierarchy() method as a context manager to make it happen.

Note that due to how cgroups work (unrelated to devlib or LISA), you basically need a single owner of the hierarchy. If you use systemd, then that is systemd. However, systemd can give you a subtree in which you are free to do what you want, and that is what the cgroups2 devlib module does. The main implication of that is that the cgroups2 API can never guarantee you that the root of your request is the actual root group (also you could run in e.g. a container anyway, so it can never be really guaranteed).

Since that module hasn't been used extensively since it was contributed, let me know if you find any problem with it.

Ablu commented 10 months ago

There is a basic example in the module-level docstring: https://github.com/ARM-software/devlib/blob/e012b175c672df84cabf5cc22510b2848b91b399/devlib/module/cgroups2.py#L16

Hm. I failed to match that to what happened in /home/ablu/projects/lisa/ipynb/deprecated/energy/EnergyModel_ClusterEnergy.ipynb (which I was trying to resurrect). But I will try again tomorrow just using it as drop-in for cgroups[1]. I will probably need to have a second pass on how these module loading magic works :).

Freeze would be nice, but I can just call systemctl freeze if something annoys me for now :).

Thanks a lot!

douglas-raillard-arm commented 10 months ago

Hm. I failed to match that to what happened in /home/ablu/projects/lisa/ipynb/deprecated/energy/EnergyModel_ClusterEnergy.ipynb (which I was trying to resurrect).

I see, quite the archeological adventure you have there. The API of cgroups and cgroups2 is quite different and cgroups2 is not a drop-in replacement (otherwise we would just have updated the existing cgroups module). Let me know if you face further difficulties.

I will probably need to have a second pass on how these module loading magic works :).

Basically devlib has some classes that are instantiated and stored as Target attributes. In LISA, we make that process lazy so accessing the attribute triggers the instantiation to avoid initializing modules that won't be used.

douglas-raillard-arm commented 10 months ago

You might want to have a look at that, as this notebook dates from the before the deep rework of most LISA APIs: https://lisa-linux-integrated-system-analysis.readthedocs.io/en/latest/changes.html#transitioning-from-lisa-legacy

douglas-raillard-arm commented 9 months ago

Closing as we are migrating the repo to GitLab. New messages on this conversation should be posted at https://gitlab.arm.com/tooling/lisa/-/issues/2172

Note that you can login with your GitHub account on gitlab.arm.com so it should be painless.