Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for GetDevices, when invoked from host side, to return list of VFs. #218

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions ipu-plugin/pkg/ipuplugin/deviceplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ import (
"slices"
"strings"

"github.com/intel/ipu-opi-plugins/ipu-plugin/pkg/types"
pb "github.com/openshift/dpu-operator/dpu-api/gen"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)

type DevicePluginService struct {
pb.UnimplementedDeviceServiceServer
mode string
sudhar-krishnakumar marked this conversation as resolved.
Show resolved Hide resolved
sudhar-krishnakumar marked this conversation as resolved.
Show resolved Hide resolved
}

var (
exclude = []string{"enp0s1f0", "enp0s1f0d1", "enp0s1f0d2", "enp0s1f0d3"}
sysClassNet = "/sys/class/net"
deviceCode = "0x1452"
deviceCodeVf = "0x145c"
sudhar-krishnakumar marked this conversation as resolved.
Show resolved Hide resolved
)

func NewDevicePluginService() *DevicePluginService {
return &DevicePluginService{}
func NewDevicePluginService(mode string) *DevicePluginService {
return &DevicePluginService{mode: mode}
}

func (*DevicePluginService) GetDevices(context.Context, *pb.Empty) (*pb.DeviceListResponse, error) {
func (s *DevicePluginService) GetDevices(context.Context, *pb.Empty) (*pb.DeviceListResponse, error) {

devices, err := discoverHostDevices()
devices, err := discoverHostDevices(s.mode)
if err != nil {
return &pb.DeviceListResponse{}, err
}
Expand All @@ -41,7 +44,7 @@ func (*DevicePluginService) GetDevices(context.Context, *pb.Empty) (*pb.DeviceLi
return response, nil
}

func discoverHostDevices() (map[string]*pb.Device, error) {
func discoverHostDevices(mode string) (map[string]*pb.Device, error) {

devices := make(map[string]*pb.Device)

Expand All @@ -59,9 +62,14 @@ func discoverHostDevices() (map[string]*pb.Device, error) {
}

device_code := strings.TrimSpace(string(deviceCodeByte))

if device_code == deviceCode {
if !slices.Contains(exclude, file.Name()) {
if mode == types.IpuMode {
if device_code == deviceCode {
if !slices.Contains(exclude, file.Name()) {
devices[file.Name()] = &pb.Device{ID: file.Name(), Health: pluginapi.Healthy}
}
}
} else if mode == types.HostMode {
if device_code == deviceCodeVf {
devices[file.Name()] = &pb.Device{ID: file.Name(), Health: pluginapi.Healthy}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ipu-plugin/pkg/ipuplugin/ipuplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func (s *server) Run() error {
pb2.RegisterLifeCycleServiceServer(s.grpcSrvr, NewLifeCycleService(s.daemonHostIp, s.daemonIpuIp, s.daemonPort, s.mode, s.p4rtbin))
if s.mode == types.IpuMode {
pb.RegisterBridgePortServiceServer(s.grpcSrvr, s)
pb2.RegisterDeviceServiceServer(s.grpcSrvr, NewDevicePluginService())
pb2.RegisterNetworkFunctionServiceServer(s.grpcSrvr, NewNetworkFunctionService(s.p4rtbin))
}
pb2.RegisterDeviceServiceServer(s.grpcSrvr, NewDevicePluginService(s.mode))

s.log.WithField("addr", listen.Addr().String()).Info("IPU plugin server listening on at:")
go func() {
Expand Down
Loading