From eae14688c6734007bab068cbef0cb625d0c1e9de Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Thu, 8 Apr 2021 13:24:45 +0300 Subject: [PATCH] tasks: add Linux rdt support Add support for configuring the Linux resctrl pseudo-filesystem with goresctrl library. The functionality is integrated in the "io.containerd.service.v1.tasks-service" plugin. Signed-off-by: Markus Lehtonen --- docs/man/containerd-config.toml.5.md | 8 +++++ services/tasks/local.go | 13 ++++++++ services/tasks/rdt_default.go | 24 +++++++++++++ services/tasks/rdt_linux.go | 50 ++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 services/tasks/rdt_default.go create mode 100644 services/tasks/rdt_linux.go diff --git a/docs/man/containerd-config.toml.5.md b/docs/man/containerd-config.toml.5.md index 50f14d3ea..e727c7c1a 100644 --- a/docs/man/containerd-config.toml.5.md +++ b/docs/man/containerd-config.toml.5.md @@ -104,6 +104,12 @@ documentation. - **sched_core** Core scheduling is a feature that allows only trusted tasks to run concurrently on cpus sharing compute resources (eg: hyperthreads on a core). (Default: **false**) +- **[plugins."io.containerd.service.v1.tasks-service"]** has one option: + - **rdt_config_file** (Linux only) specifies path to a configuration used for + configuring RDT (Default: **""**). Enables support for Intel RDT, a + technology for cache and memory bandwidth management. + See https://github.com/intel/goresctrl/blob/v0.2.0/doc/rdt.md#configuration + for details of the configuration file format. **oom_score** : The out of memory (OOM) score applied to the containerd daemon process (Default: 0) @@ -193,6 +199,8 @@ imports = ["/etc/containerd/runtime_*.toml", "./debug.toml"] [plugins."io.containerd.runtime-shim.v2.shim"] platforms = ["linux/amd64"] sched_core = true + [plugins."io.containerd.service.v1.tasks-service"] + rdt_config_file = "/etc/rdt-config.yaml" ``` ## BUGS diff --git a/services/tasks/local.go b/services/tasks/local.go index 9a2b33c24..8d327356c 100644 --- a/services/tasks/local.go +++ b/services/tasks/local.go @@ -63,11 +63,18 @@ const ( stateTimeout = "io.containerd.timeout.task.state" ) +// Config for the tasks service plugin +type Config struct { + // RdtConfigFile specifies the path to RDT configuration file + RdtConfigFile string `toml:"rdt_config_file" json:"rdtConfigFile"` +} + func init() { plugin.Register(&plugin.Registration{ Type: plugin.ServicePlugin, ID: services.TasksService, Requires: tasksServiceRequires, + Config: &Config{}, InitFn: initFunc, }) @@ -75,6 +82,7 @@ func init() { } func initFunc(ic *plugin.InitContext) (interface{}, error) { + config := ic.Config.(*Config) runtimes, err := loadV1Runtimes(ic) if err != nil { return nil, err @@ -128,6 +136,11 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) { for _, t := range v2Tasks { l.monitor.Monitor(t, nil) } + + if err := initRdt(config.RdtConfigFile); err != nil { + log.G(ic.Context).WithError(err).Errorf("RDT initialization failed") + } + return l, nil } diff --git a/services/tasks/rdt_default.go b/services/tasks/rdt_default.go new file mode 100644 index 000000000..05007dc77 --- /dev/null +++ b/services/tasks/rdt_default.go @@ -0,0 +1,24 @@ +//go:build !linux || no_rdt +// +build !linux no_rdt + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package tasks + +func RdtEnabled() bool { return false } + +func initRdt(configFilePath string) error { return nil } diff --git a/services/tasks/rdt_linux.go b/services/tasks/rdt_linux.go new file mode 100644 index 000000000..e70d280c0 --- /dev/null +++ b/services/tasks/rdt_linux.go @@ -0,0 +1,50 @@ +//go:build linux && !no_rdt +// +build linux,!no_rdt + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package tasks + +import ( + "github.com/containerd/containerd/log" + + "github.com/intel/goresctrl/pkg/rdt" + "github.com/pkg/errors" +) + +const ( + // ResctrlPrefix is the prefix used for class/closid directories under the resctrl filesystem + ResctrlPrefix = "" +) + +func initRdt(configFilePath string) error { + if configFilePath == "" { + log.L.Debug("No RDT config file specified, RDT not configured") + return nil + } + + if err := rdt.Initialize(ResctrlPrefix); err != nil { + return errors.Wrap(err, "RDT not enabled") + } + + if err := rdt.SetConfigFromFile(configFilePath, true); err != nil { + return err + } + + return nil + +}