1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
Copyright 2021 Intel Corporation
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.
*/
// This application demonstrates using the blockio API.
package main
import (
"flag"
"fmt"
"os"
"sort"
"strings"
"github.com/intel/goresctrl/pkg/rdt"
)
var (
// Global command line flags
groupPrefix string
)
type subCmd func([]string) error
var subCmds = map[string]subCmd{
"info": subCmdInfo,
"configure": subCmdConfigure,
}
func main() {
cmds := make([]string, 0, len(subCmds))
for c := range subCmds {
cmds = append(cmds, c)
}
sort.Strings(cmds)
allCmds := strings.Join(cmds, ", ")
if len(os.Args) < 2 {
exitError("missing sub-command, must be one of: %s\n", allCmds)
}
// Run sub-command
cmd, ok := subCmds[os.Args[1]]
if !ok {
exitError("unknown sub-command %q, must be of: %s\n", os.Args[1], allCmds)
}
if err := cmd(os.Args[2:]); err != nil {
exitError("sub-command %q failed: %v\n", os.Args[1], err)
}
}
func addGlobalFlags(flagset *flag.FlagSet) {
flagset.StringVar(&groupPrefix, "group-prefix", "", "prefix to use for resctrl groups")
}
func subCmdInfo(args []string) error {
// Parse command line args
flags := flag.NewFlagSet("info", flag.ExitOnError)
addGlobalFlags(flags)
if err := flags.Parse(args); err != nil {
return err
}
// Run sub-command
if err := rdt.Initialize(groupPrefix); err != nil {
fmt.Printf("RDT is not enabled: %v\n", err)
return nil
}
fmt.Printf("Monitoring supported: %v\n", rdt.MonSupported())
if rdt.MonSupported() {
mon := rdt.GetMonFeatures()
fmt.Println("Monitoring features:")
for r, f := range mon {
fmt.Printf(" - %s: %v\n", r, strings.Join(f, ", "))
}
}
fmt.Println("Classes:")
for _, cls := range rdt.GetClasses() {
fmt.Printf(" - %s\n", cls.Name())
mon := cls.GetMonGroups()
if len(mon) > 0 {
fmt.Println(" Monitoring groups:")
for _, grp := range mon {
fmt.Printf(" - %s\n", grp.Name())
}
}
}
return nil
}
func subCmdConfigure(args []string) error {
// Parse command line args
flags := flag.NewFlagSet("configure", flag.ExitOnError)
addGlobalFlags(flags)
configFile := flags.String("config-file", "", "path to rdt configuration file")
force := flags.Bool("force", false, "force configuration, delete non-empty resctrl groups")
if err := flags.Parse(args); err != nil {
return err
}
if *configFile == "" {
return fmt.Errorf("-config-file must be specified")
}
// Run sub-command
if err := rdt.Initialize(groupPrefix); err != nil {
return fmt.Errorf("RDT is not enabled: %v", err)
}
fmt.Println("Configuring resctrl filesystem...")
if err := rdt.SetConfigFromFile(*configFile, *force); err != nil {
return err
}
fmt.Println("Done!")
return nil
}
func exitError(format string, args ...interface{}) {
fmt.Printf("ERROR: "+format+"\n", args...)
os.Exit(1)
}
|