Skip to content

Commit

Permalink
Fix UPF legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
char-1ee committed Dec 11, 2023
1 parent 03f0a07 commit f7a6985
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ctriface/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type StartVMResponse struct {

const (
testImageName = "ghcr.io/ease-lab/helloworld:var_workload"
fileBackend = "File"

Check failure on line 67 in ctriface/iface.go

View workflow job for this annotation

GitHub Actions / Build and check code quality (1.18)

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 67 in ctriface/iface.go

View workflow job for this annotation

GitHub Actions / Build and check code quality (1.19)

File is not `gofmt`-ed with `-s` (gofmt)
uffdBackend = "Uffd"
)

// StartVM Boots a VM if it does not exist
Expand Down Expand Up @@ -104,7 +106,7 @@ func (o *Orchestrator) StartVMWithEnvironment(ctx context.Context, vmID, imageNa

tStart = time.Now()
conf := o.getVMConfig(vm)
_, err = o.fcClient.CreateVM(ctx, conf)
resp, err := o.fcClient.CreateVM(ctx, conf)
startVMMetric.MetricMap[metrics.FcCreateVM] = metrics.ToUS(time.Since(tStart))
if err != nil {
return nil, nil, errors.Wrap(err, "failed to create the microVM in firecracker-containerd")
Expand Down Expand Up @@ -214,7 +216,7 @@ func (o *Orchestrator) StartVMWithEnvironment(ctx context.Context, vmID, imageNa
VMMStatePath: o.getSnapshotFile(vmID),
WorkingSetPath: o.getWorkingSetFile(vmID),
// FIXME (gh-807)
//InstanceSockAddr: resp.UPFSockPath,
InstanceSockAddr: resp.GetSocketPath(),
}
if err := o.memoryManager.RegisterVM(stateCfg); err != nil {
return nil, nil, errors.Wrap(err, "failed to register VM with memory manager")
Expand Down Expand Up @@ -497,7 +499,19 @@ func (o *Orchestrator) LoadSnapshot(ctx context.Context, vmID string, snap *snap
conf.MemFilePath = snap.GetMemFilePath()
conf.ContainerSnapshotPath = containerSnap.GetDevicePath()

if conf.MemBackend == nil {
conf.MemBackend = &proto.MemoryBackend{}
}
conf.MemBackend.BackendType = fileBackend
conf.MemBackend.BackendPath = snap.GetMemFilePath()

if o.GetUPFEnabled() {
conf.MemBackend.BackendType = uffdBackend
conf.MemBackend.BackendPath, err = o.memoryManager.GetUPFSockPath(vmID)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to get UPF socket path for uffd backend")
}

if err := o.memoryManager.FetchState(vmID); err != nil {
return nil, nil, err
}
Expand Down
29 changes: 29 additions & 0 deletions memory/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,35 @@ func (m *MemoryManager) GetUPFLatencyStats(vmID string) ([]*metrics.Metric, erro
return state.latencyMetrics, nil
}

func (m *MemoryManager) GetUPFSockPath(vmID string) (string, error) {
logger := log.WithFields(log.Fields{"vmID": vmID})

logger.Debug("Get the path of firecracker unix domain socket")

m.Lock()

state, ok := m.instances[vmID]
if !ok {
m.Unlock()
logger.Error("VM not registered with the memory manager")
return "", errors.New("VM not registered with the memory manager")
}

m.Unlock()

if state.isActive {
logger.Error("Cannot get stats while VM is active")
return "", errors.New("Cannot get stats while VM is active")
}

if !m.MetricsModeOn || !state.metricsModeOn {
logger.Error("Metrics mode is not on")
return "", errors.New("Metrics mode is not on")
}

return m.instances[vmID].SnapshotStateCfg.InstanceSockAddr, nil
}

func getLazyHeaderStats(state *SnapshotState, functionName string) ([]string, []string) {
header := []string{
"FuncName",
Expand Down

0 comments on commit f7a6985

Please sign in to comment.