Skip to content

Commit

Permalink
new tool: irqcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Oct 6, 2020
1 parent 52d6463 commit 3dc83b8
Show file tree
Hide file tree
Showing 63 changed files with 6,495 additions and 894 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ outdir:
dist: binaries

.PHONY: binaries
binaries: numalign sriovscan lsnt splitcpulist sriovctl
binaries: numalign sriovscan lsnt splitcpulist sriovctl irqcheck

numalign: outdir
$(BUILDFLAGS) go build -v -o _output/numalign ./cmd/numalign
Expand All @@ -31,6 +31,9 @@ splitcpulist: outdir
sriovctl: outdir
$(BUILDFLAGS) go build -v -o _output/sriovctl ./cmd/sriovctl

irqcheck: outdir
$(BUILDFLAGS) go build -v -o _output/irqcheck ./cmd/irqcheck

clean:
rm -rf _output

Expand Down
86 changes: 86 additions & 0 deletions cmd/irqcheck/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.
*
* Copyright 2020 Red Hat, Inc.
*/

package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"

flag "github.com/spf13/pflag"

"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
)

func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] cpulist\n", filepath.Base(os.Args[0]))
flag.PrintDefaults()
}
var procfsRoot = flag.StringP("procfs", "P", "/proc", "procfs mount point to use.")
flag.Parse()

args := flag.Args()
if len(args) != 1 {
flag.Usage()
os.Exit(1)
}

isolCpus, err := cpuset.Parse(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing %q: %v", args[0], err)
os.Exit(1)
}

irqRoot := filepath.Join(*procfsRoot, "irq")
var irqViolations []int

err = filepath.Walk(irqRoot, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
_, file := filepath.Split(path)
irq, convErr := strconv.Atoi(file)
if convErr != nil {
return nil // just skip not-irq-looking dirs
}

irqCpuList, readErr := ioutil.ReadFile(filepath.Join(path, "smp_affinity_list"))
if readErr != nil {
fmt.Fprintf(os.Stderr, "error reading smp_affinity_list for IRQ %d: %v\n", irq, readErr)
return nil // keep running
}

irqCpus, parseErr := cpuset.Parse(strings.TrimSpace(string(irqCpuList)))

if parseErr != nil {
fmt.Fprintf(os.Stderr, "error parsing smp_affinity_list for IRQ %d: %v\n", irq, parseErr)
return nil // keep running
}

cpus := irqCpus.Intersection(isolCpus)
if cpus.Size() != 0 {
fmt.Printf("IRQ %3d: can run on %v\n", irq, cpus.ToSlice())
irqViolations = append(irqViolations, irq)
}

return nil
})
}
32 changes: 30 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,35 @@ go 1.13
require (
github.com/disiqueira/gotree v1.0.0
github.com/fromanirh/cpuset v0.0.0-20200530094055-76ce61745438
github.com/google/go-cmp v0.2.0
github.com/google/go-cmp v0.3.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.3
github.com/spf13/pflag v1.0.5
k8s.io/kubernetes v0.0.0-00010101000000-000000000000
)

// Pinned to kubernetes-1.18.3
replace (
k8s.io/api => k8s.io/api v0.18.3
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.18.3
k8s.io/apimachinery => k8s.io/apimachinery v0.18.3
k8s.io/apiserver => k8s.io/apiserver v0.18.3
k8s.io/cli-runtime => k8s.io/cli-runtime v0.18.3
k8s.io/client-go => k8s.io/client-go v0.18.3
k8s.io/cloud-provider => k8s.io/cloud-provider v0.18.3
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.18.3
k8s.io/code-generator => k8s.io/code-generator v0.18.3
k8s.io/component-base => k8s.io/component-base v0.18.3
k8s.io/cri-api => k8s.io/cri-api v0.18.3
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.18.3
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.18.3
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.18.3
k8s.io/kube-proxy => k8s.io/kube-proxy v0.18.3
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.18.3
k8s.io/kubectl => k8s.io/kubectl v0.18.3
k8s.io/kubelet => k8s.io/kubelet v0.18.3
k8s.io/kubernetes => k8s.io/kubernetes v1.18.3
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.18.3
k8s.io/metrics => k8s.io/metrics v0.18.3
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.18.3
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.6.0
)
593 changes: 593 additions & 0 deletions go.sum

Large diffs are not rendered by default.

Loading

0 comments on commit 3dc83b8

Please sign in to comment.