From 734397ff113b35973db7c9c458a9fba9d416bae9 Mon Sep 17 00:00:00 2001 From: Sudhar Krishnakumar Date: Mon, 29 Jul 2024 21:42:28 +0100 Subject: [PATCH 1/2] Added support for GetDevices, when invoked from host side, to return list of VFs. With this, GetDevices can get invoked when VSP runs in host and IPU. --- ipu-plugin/pkg/ipuplugin/deviceplugin.go | 25 ++++++++++++++++-------- ipu-plugin/pkg/ipuplugin/ipuplugin.go | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ipu-plugin/pkg/ipuplugin/deviceplugin.go b/ipu-plugin/pkg/ipuplugin/deviceplugin.go index 72bc3746..86d65612 100644 --- a/ipu-plugin/pkg/ipuplugin/deviceplugin.go +++ b/ipu-plugin/pkg/ipuplugin/deviceplugin.go @@ -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 } var ( exclude = []string{"enp0s1f0", "enp0s1f0d1", "enp0s1f0d2", "enp0s1f0d3"} sysClassNet = "/sys/class/net" deviceCode = "0x1452" + deviceCodeVf = "0x145c" ) -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 } @@ -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) @@ -59,9 +62,15 @@ 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} + } + } + } + if mode == types.HostMode { + if device_code == deviceCodeVf { devices[file.Name()] = &pb.Device{ID: file.Name(), Health: pluginapi.Healthy} } } diff --git a/ipu-plugin/pkg/ipuplugin/ipuplugin.go b/ipu-plugin/pkg/ipuplugin/ipuplugin.go index 3f05f182..11247243 100644 --- a/ipu-plugin/pkg/ipuplugin/ipuplugin.go +++ b/ipu-plugin/pkg/ipuplugin/ipuplugin.go @@ -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() { From 1ded4cfbc52c2a7fbdfec98ddc47b058393b8015 Mon Sep 17 00:00:00 2001 From: Sudhar Krishnakumar Date: Mon, 29 Jul 2024 23:08:45 +0100 Subject: [PATCH 2/2] addressed review comment. --- ipu-plugin/pkg/ipuplugin/deviceplugin.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ipu-plugin/pkg/ipuplugin/deviceplugin.go b/ipu-plugin/pkg/ipuplugin/deviceplugin.go index 86d65612..b3ba38f0 100644 --- a/ipu-plugin/pkg/ipuplugin/deviceplugin.go +++ b/ipu-plugin/pkg/ipuplugin/deviceplugin.go @@ -68,8 +68,7 @@ func discoverHostDevices(mode string) (map[string]*pb.Device, error) { devices[file.Name()] = &pb.Device{ID: file.Name(), Health: pluginapi.Healthy} } } - } - if mode == types.HostMode { + } else if mode == types.HostMode { if device_code == deviceCodeVf { devices[file.Name()] = &pb.Device{ID: file.Name(), Health: pluginapi.Healthy} }