Skip to content

Commit c59492b

Browse files
committed
Fix UPF legacy
1 parent bd34c62 commit c59492b

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

ctriface/iface.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ type StartVMResponse struct {
6464

6565
const (
6666
testImageName = "ghcr.io/ease-lab/helloworld:var_workload"
67+
fileBackend = "File"
68+
uffdBackend = "Uffd"
6769
)
6870

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

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

502+
if conf.MemBackend == nil {
503+
conf.MemBackend = &proto.MemoryBackend{}
504+
}
505+
conf.MemBackend.BackendType = fileBackend
506+
conf.MemBackend.BackendPath = snap.GetMemFilePath()
507+
500508
if o.GetUPFEnabled() {
509+
conf.MemBackend.BackendType = uffdBackend
510+
conf.MemBackend.BackendPath, err = o.memoryManager.GetUPFSockPath(vmID)
511+
if err != nil {
512+
return nil, nil, errors.Wrapf(err, "failed to get UPF socket path for uffd backend")
513+
}
514+
501515
if err := o.memoryManager.FetchState(vmID); err != nil {
502516
return nil, nil, err
503517
}

memory/manager/manager.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,35 @@ func (m *MemoryManager) GetUPFLatencyStats(vmID string) ([]*metrics.Metric, erro
351351
return state.latencyMetrics, nil
352352
}
353353

354+
func (m *MemoryManager) GetUPFSockPath(vmID string) (string, error) {
355+
logger := log.WithFields(log.Fields{"vmID": vmID})
356+
357+
logger.Debug("Get the path of firecracker unix domain socket")
358+
359+
m.Lock()
360+
361+
state, ok := m.instances[vmID]
362+
if !ok {
363+
m.Unlock()
364+
logger.Error("VM not registered with the memory manager")
365+
return "", errors.New("VM not registered with the memory manager")
366+
}
367+
368+
m.Unlock()
369+
370+
if state.isActive {
371+
logger.Error("Cannot get stats while VM is active")
372+
return "", errors.New("Cannot get stats while VM is active")
373+
}
374+
375+
if !m.MetricsModeOn || !state.metricsModeOn {
376+
logger.Error("Metrics mode is not on")
377+
return "", errors.New("Metrics mode is not on")
378+
}
379+
380+
return m.instances[vmID].SnapshotStateCfg.InstanceSockAddr, nil
381+
}
382+
354383
func getLazyHeaderStats(state *SnapshotState, functionName string) ([]string, []string) {
355384
header := []string{
356385
"FuncName",

0 commit comments

Comments
 (0)