Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Huamin Chen <[email protected]>
  • Loading branch information
rootfs committed Jun 14, 2023
1 parent e91541d commit 4b3ccee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
4 changes: 3 additions & 1 deletion cmd/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ func main() {
config.SetEnabledHardwareCounterMetrics(*exposeHardwareCounterMetrics)
config.SetEnabledGPU(*enableGPU)
config.EnabledMSR = *enabledMSR
config.SetKernelSourceDir(*kernelSourceDirPath)
if err := config.SetKernelSourceDir(*kernelSourceDirPath); err != nil {
klog.Warningf("failed to set kernel source dir to %q: %v", *kernelSourceDirPath, err)
}

// the ebpf batch deletion operation was introduced in linux kernel 5.6, which provides better performance to delete keys.
// but the user can enable it if the kernel has backported this functionality.
Expand Down
2 changes: 1 addition & 1 deletion pkg/bpfassets/attacher/bcc_attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func AttachBPFAssets() (*BpfModuleTables, error) {
m, err := loadModule(objProg, options)
if err != nil {
klog.Infof("failed to attach perf module with options %v: %v, from default kernel source.\n", options, err)
dirs := config.GetKernelSourceDir()
dirs := config.GetKernelSourceDirs()
for _, dir := range dirs {
klog.Infof("trying to load eBPF module with kernel source dir %s", dir)
os.Setenv("BCC_KERNEL_SOURCE", dir)
Expand Down
45 changes: 20 additions & 25 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var (
configPath = "/etc/kepler/kepler.config"

// dir of kernel sources for bcc
kernelSourceDir = []string{}
kernelSourceDirs = []string{}

////////////////////////////////////
ModelServerEnable = getBoolConfig("MODEL_SERVER_ENABLE", false)
Expand Down Expand Up @@ -153,35 +153,30 @@ func getConfig(configKey, defaultValue string) (result string) {

// SetKernelSourceDir sets the directory for all kernel source. This is used for bcc. Only the top level directory is needed.
func SetKernelSourceDir(dir string) error {
fileInfo, err := os.Stat(dir)
if err != nil {
return err
}

fileInfo, err := os.Stat(path)
if err != nil {
return err
}

if !fileInfo.IsDir() {
return fmt.Errorf("expected kernel root path %s to be a directory", dir)
}
// read all the kernel source directories
if dir != "" {
// list all the directories under `dir` and store in kernelSourceDir
klog.V(4).Infoln("kernel source dir is set to", dir)
files, err := os.ReadDir(dir)
if err != nil {
klog.Warning("failed to read kernel source dir", err)
}
kernelVers := fmt.Sprintf("%v", getKernelVersion(c))
for _, file := range files {
// only store directories and the directory name should contain the kernel version
if strings.Contains(file.Name(), kernelVers) && file.IsDir() {
kernelSourceDir = append(kernelSourceDir, filepath.Join(dir, file.Name()))
}
if !fileInfo.IsDir() {
return fmt.Errorf("expected kernel root path %s to be a directory", dir)
}
// list all the directories under dir and store in kernelSourceDir
klog.Infoln("kernel source dir is set to", dir)
files, err := os.ReadDir(dir)
if err != nil {
klog.Warning("failed to read kernel source dir", err)
}
for _, file := range files {
if file.IsDir() {
kernelSourceDirs = append(kernelSourceDirs, filepath.Join(dir, file.Name()))
}
}
return nil
}

func GetKernelSourceDir() []string {
return kernelSourceDir
func GetKernelSourceDirs() []string {
return kernelSourceDirs
}

func SetModelServerReqEndpoint() (modelServerReqEndpoint string) {
Expand Down

0 comments on commit 4b3ccee

Please sign in to comment.