Skip to content

Commit

Permalink
After enabling VFs on host, changed the way to verify, (#238)
Browse files Browse the repository at this point in the history
After enabling VFs on host, changed the way to verify, if those VFs came up fine. Previous way of ssh from host to IMC,
to run cli_client is not reliable, since customer config may not support
host to IMC connection.
  • Loading branch information
sudhar-krishnakumar authored Oct 24, 2024
1 parent 1738639 commit d81d578
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 35 deletions.
60 changes: 51 additions & 9 deletions ipu-plugin/pkg/ipuplugin/deviceplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/intel/ipu-opi-plugins/ipu-plugin/pkg/types"
"github.com/intel/ipu-opi-plugins/ipu-plugin/pkg/utils"
log "github.com/sirupsen/logrus"

pb "github.com/openshift/dpu-operator/dpu-api/gen"
Expand All @@ -30,7 +29,6 @@ var (
deviceCode = "0x1452"
deviceCodeVf = "0x145c"
intelVendor = "0x8086"
configNumVfs = 8
maxVfsSupported = 64
)

Expand All @@ -53,16 +51,62 @@ func (s *DevicePluginService) GetDevices(context.Context, *pb.Empty) (*pb.Device
return response, nil
}

// Note: This function below was taken from open-source sriov plugin, which
// is also under the same apache license, with few additional changes.
// Returns a List containing PCI addr for all VF discovered in a given PF
func GetVFList(pf string) (vfList []string, err error) {
vfList = make([]string, 0)
pfDir := filepath.Join(sysBusPciDevices, pf)
_, err = os.Lstat(pfDir)
if err != nil {
log.Errorf("error. Could not get PF directory information for device: %s, Err: %v", pf, err)
err = fmt.Errorf("error. Could not get PF directory information for device: %s, Err: %v", pf, err)
return
}

vfDirs, err := filepath.Glob(filepath.Join(pfDir, "virtfn*"))

if err != nil {
log.Errorf("error reading VF directories %v", err)
err = fmt.Errorf("error reading VF directories %v", err)
return
}

// Read all VF directory and get add VF PCI addr to the vfList
for _, dir := range vfDirs {
dirInfo, err := os.Lstat(dir)
if err == nil && (dirInfo.Mode()&os.ModeSymlink != 0) {
linkName, err := filepath.EvalSymlinks(dir)
if err == nil {
vfLink := filepath.Base(linkName)
vfList = append(vfList, vfLink)
}
}
}
return
}

func GetVfDeviceCount(pciAddr string) (int, error) {
vfList, err := GetVFList(pciAddr)
if err != nil {
log.Errorf("Error->%v, from GetVFList", err)
return 0, fmt.Errorf("Error->%v, from GetVFList", err)
}
length := len(vfList)
log.Infof("GetVFList count->%v", length)
return length, nil
}

// Recommended to wait upto 2 seconds, for the max VFs(64) currently supported.
func pollToCheckVfDevices(mode string, count int) error {
func pollToCheckVfDevices(pciAddr string, count int) error {
var err error
cnt := 0
ticker := time.NewTicker(time.Second / 3)
done := make(chan bool, 1)

go func() {
for _ = range ticker.C {
cnt, err = utils.GetVfDeviceCount(mode)
cnt, err = GetVfDeviceCount(pciAddr)
if cnt == count && err == nil {
ticker.Stop()
break
Expand Down Expand Up @@ -104,7 +148,7 @@ func SetNumSriovVfs(mode string, pciAddr string, vfCnt int32) error {
return fmt.Errorf("SetNumSriovVfs(): reset fail %s: %v", pathToNumVfsFile, err)
}
zeroVfs := 0
err = pollToCheckVfDevices(mode, zeroVfs)
err = pollToCheckVfDevices(pciAddr, zeroVfs)
if err != nil {
return fmt.Errorf("cli-client query failed count->%v, err->%v\n", zeroVfs, err)
}
Expand All @@ -115,7 +159,7 @@ func SetNumSriovVfs(mode string, pciAddr string, vfCnt int32) error {
return fmt.Errorf("SetNumSriovVfs():error in updating %s: %v", pathToNumVfsFile, err)
}

err = pollToCheckVfDevices(mode, int(vfCnt))
err = pollToCheckVfDevices(pciAddr, int(vfCnt))
if err != nil {
return fmt.Errorf("cli-client query failed count->%v, err->%v\n", vfCnt, err)
}
Expand All @@ -132,9 +176,7 @@ func SetNumVfs(mode string, numVfs int32) (int32, error) {
return 0, fmt.Errorf("setNumVfs(): only supported on host: mode %s\n", mode)
}

//Note: Per internal discussion, for now setting VFs to hardcoded value.
log.Debugf("setNumVfs(): requested VFs->%v, will allocate VFs->%v\n", numVfs, configNumVfs)
numVfs = int32(configNumVfs)
log.Debugf("setNumVfs(): requested num of VFs->%v\n", numVfs)

files, err := os.ReadDir(sysBusPciDevices)
if err != nil {
Expand Down
26 changes: 0 additions & 26 deletions ipu-plugin/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,6 @@ func ImcQueryfindVsiGivenMacAddr(mode string, mac string) (string, error) {
return output, nil
}

func GetVfDeviceCount(mode string) (int, error) {
var ipAddr string
if mode == types.HostMode {
ipAddr = hostToImcIpAddr
} else if mode == types.IpuMode {
ipAddr = accToImcIpAddr
}

runCommand := fmt.Sprintf(`ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@"%s" "/usr/bin/cli_client -cq" \
| awk '{if(($4 == "0x0") && ($6 == "yes")) {print $17}}'`, ipAddr)

// reach out to the IMC to get the mac addresses of the VFs
output, err := ExecuteScript(runCommand)

if err != nil {
return 0, fmt.Errorf("unable to reach the IMC %v", err)
}

vfMacList := strings.Split(strings.TrimSpace(output), "\n")
length := len(vfMacList)
if len(vfMacList) == 1 && vfMacList[0] == "" {
length = length - 1
}
return length, nil
}

func GetVfMacList() ([]string, error) {
// reach out to the IMC to get the mac addresses of the VFs
output, err := ExecuteScript(`ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 [email protected] "/usr/bin/cli_client -cq" \
Expand Down

0 comments on commit d81d578

Please sign in to comment.