From 500a464b228f6f59fa2d03c437cfa823cc85af39 Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Sat, 25 Mar 2023 18:48:18 +0000 Subject: [PATCH] Cache mig profiles in devicelib, not just each device Signed-off-by: Kevin Klues --- pkg/nvlib/device/api.go | 1 + pkg/nvlib/device/device.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/pkg/nvlib/device/api.go b/pkg/nvlib/device/api.go index c6605fc..9886d7b 100644 --- a/pkg/nvlib/device/api.go +++ b/pkg/nvlib/device/api.go @@ -40,6 +40,7 @@ type devicelib struct { nvml nvml.Interface skippedDevices map[string]struct{} verifySymbols *bool + migProfiles []MigProfile } var _ Interface = &devicelib{} diff --git a/pkg/nvlib/device/device.go b/pkg/nvlib/device/device.go index 40325dc..4136527 100644 --- a/pkg/nvlib/device/device.go +++ b/pkg/nvlib/device/device.go @@ -385,6 +385,12 @@ func (d *devicelib) GetMigDevices() ([]MigDevice, error) { // GetMigProfiles gets the set of unique MIG profiles across all top-level devices func (d *devicelib) GetMigProfiles() ([]MigProfile, error) { + // Return the cached list if available + if d.migProfiles != nil { + return d.migProfiles, nil + } + + // Otherwise generate it... var profiles []MigProfile err := d.VisitMigProfiles(func(p MigProfile) error { profiles = append(profiles, p) @@ -393,6 +399,9 @@ func (d *devicelib) GetMigProfiles() ([]MigProfile, error) { if err != nil { return nil, err } + + // And cache it before returning + d.migProfiles = profiles return profiles, nil }