Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Project-HAMi/HAMi
Browse files Browse the repository at this point in the history
  • Loading branch information
archlitchi committed Feb 4, 2024
2 parents 72dd610 + c1d8616 commit d37e81f
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 21 deletions.
3 changes: 1 addition & 2 deletions cmd/device-plugin/nvidia/vgpucfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -80,7 +79,7 @@ func updateFromCLIFlag[T any](pflag **T, c *cli.Context, flagName string) {
}

func readFromConfigFile() error {
jsonbyte, err := ioutil.ReadFile("/config/config.json")
jsonbyte, err := os.ReadFile("/config/config.json")
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/vGPUmonitor/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -34,7 +33,7 @@ func init() {

func setcGgroupDriver() int {
// 1 for cgroupfs 2 for systemd
kubeletconfig, err := ioutil.ReadFile("/hostvar/lib/kubelet/config.yaml")
kubeletconfig, err := os.ReadFile("/hostvar/lib/kubelet/config.yaml")
if err != nil {
return 0
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/vGPUmonitor/pathmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -38,7 +37,7 @@ func init() {

func checkfiles(fpath string) (*sharedRegionT, error) {
klog.Infof("Checking path %s", fpath)
files, err := ioutil.ReadDir(fpath)
files, err := os.ReadDir(fpath)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -83,7 +82,7 @@ func isVaildPod(name string, pods *v1.PodList) bool {
func monitorpath(podmap map[string]podusage) error {
lock.Lock()
defer lock.Unlock()
files, err := ioutil.ReadDir(containerPath)
files, err := os.ReadDir(containerPath)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/device-plugin/hygon/dcu/amdgpu/amdgpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"bufio"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -100,7 +99,7 @@ func GetAMDGPUs() map[string]map[string]int {
// AMDGPU check if a particular card is an AMD GPU by checking the device's vendor ID
func AMDGPU(cardName string) bool {
sysfsVendorPath := "/sys/class/drm/" + cardName + "/device/vendor"
b, err := ioutil.ReadFile(sysfsVendorPath)
b, err := os.ReadFile(sysfsVendorPath)
if err == nil {
vid := strings.TrimSpace(string(b))

Expand Down
10 changes: 8 additions & 2 deletions pkg/device-plugin/hygon/dcu/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,14 @@ func (p *Plugin) createvdevFile(current *v1.Pod, ctr *v1.Container, req util.Con
s = s + fmt.Sprintln("enable: 1")
}
cacheFileHostDirectory := "/usr/local/vgpu/dcu/" + string(current.UID) + "_" + ctr.Name + "_" + fmt.Sprint(devidx) + "_" + fmt.Sprint(pipeid) + "_" + fmt.Sprint(vdevidx) + "_" + coremsk
os.MkdirAll(cacheFileHostDirectory, 0777)
os.Chmod(cacheFileHostDirectory, 0777)
err := os.MkdirAll(cacheFileHostDirectory, 0777)
if err != nil {
return "", err
}
err = os.Chmod(cacheFileHostDirectory, 0777)
if err != nil {
return "", err
}
os.WriteFile(cacheFileHostDirectory+"/vdev0.conf", []byte(s), os.ModePerm)
return cacheFileHostDirectory, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/device-plugin/mlu/cndev/cndev.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strconv"
"strings"
Expand Down Expand Up @@ -132,7 +132,7 @@ func (d *Device) ValidateSriovNum(num int) error {
}

func getNumFromFile(path string) (int, error) {
output, err := ioutil.ReadFile(path)
output, err := os.ReadFile(path)
if err != nil {
return 0, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/device-plugin/mlu/cntopo/cntopo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package cntopo

import (
"encoding/json"
"io/ioutil"
"os"
"os/exec"
"sync"
)
Expand Down Expand Up @@ -70,15 +70,15 @@ func (c *cntopo) GetRings(available []uint, size int) ([]Ring, error) {
}
c.Lock()
defer c.Unlock()
err = ioutil.WriteFile("/tmp/cntopo_input.json", b, 0666)
err = os.WriteFile("/tmp/cntopo_input.json", b, 0666)
if err != nil {
return nil, err
}
err = exec.Command("sh", "-c", "cntopo find -I /tmp/cntopo_input.json -O /tmp/cntopo_output.json -R 1000000 -C").Run()
if err != nil {
return nil, err
}
j, err := ioutil.ReadFile("/tmp/cntopo_output.json")
j, err := os.ReadFile("/tmp/cntopo_output.json")
if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/scheduler/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type NodeUsage struct {

type nodeManager struct {
nodes map[string]*NodeInfo
mutex sync.Mutex
mutex sync.RWMutex
}

func (m *nodeManager) init() {
Expand Down Expand Up @@ -101,14 +101,16 @@ func (m *nodeManager) rmNodeDevice(nodeID string, nodeInfo *NodeInfo) {
}

func (m *nodeManager) GetNode(nodeID string) (*NodeInfo, error) {
m.mutex.Lock()
defer m.mutex.Unlock()
m.mutex.RLock()
defer m.mutex.RUnlock()
if n, ok := m.nodes[nodeID]; ok {
return n, nil
}
return &NodeInfo{}, fmt.Errorf("node %v not found", nodeID)
}

func (m *nodeManager) ListNodes() (map[string]*NodeInfo, error) {
m.mutex.RLock()
defer m.mutex.RUnlock()
return m.nodes, nil
}
4 changes: 3 additions & 1 deletion pkg/scheduler/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type podInfo struct {

type podManager struct {
pods map[k8stypes.UID]*podInfo
mutex sync.Mutex
mutex sync.RWMutex
}

func (m *podManager) init() {
Expand Down Expand Up @@ -65,6 +65,8 @@ func (m *podManager) delPod(pod *corev1.Pod) {
}

func (m *podManager) GetScheduledPods() (map[k8stypes.UID]*podInfo, error) {
m.mutex.RLock()
defer m.mutex.RUnlock()
klog.Infof("Getting all scheduled pods with %d nums", len(m.pods))
return m.pods, nil
}
2 changes: 1 addition & 1 deletion pkg/scheduler/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func fitInCertainDevice(node *NodeUsage, request util.ContainerDeviceRequest, an
originReq := k.Nums
prevnuma := -1
klog.InfoS("Allocating device for container request", "pod", klog.KObj(pod), "card request", k)
tmpDevs := []util.ContainerDevice{}
var tmpDevs []util.ContainerDevice
for i := len(node.Devices) - 1; i >= 0; i-- {
klog.InfoS("scoring pod", "pod", klog.KObj(pod), "Memreq", k.Memreq, "MemPercentagereq", k.MemPercentagereq, "Coresreq", k.Coresreq, "Nums", k.Nums, "device index", i, "device", node.Devices[i].Id)
found, numa := checkType(annos, *node.Devices[i], k)
Expand Down

0 comments on commit d37e81f

Please sign in to comment.