MCPcopy
hub / github.com/google/gvisor / Init

Method Init

pkg/sentry/kernel/kernel.go:501–638  ·  view source on GitHub ↗

Init initialize the Kernel with no tasks. Callers must manually set Kernel.Platform and call Kernel.SetMemoryFile before calling Init.

(args InitKernelArgs)

Source from the content-addressed store, hash-verified

499// Callers must manually set Kernel.Platform and call Kernel.SetMemoryFile
500// before calling Init.
501func (k *Kernel) Init(args InitKernelArgs) error {
502 if args.Timekeeper == nil {
503 return fmt.Errorf("args.Timekeeper is nil")
504 }
505 if args.Timekeeper.clocks == nil {
506 return fmt.Errorf("must call Timekeeper.SetClocks() before Kernel.Init()")
507 }
508 if args.RootUserNamespace == nil {
509 return fmt.Errorf("args.RootUserNamespace is nil")
510 }
511 if args.ApplicationCores == 0 {
512 return fmt.Errorf("args.ApplicationCores is 0")
513 }
514
515 k.featureSet = args.FeatureSet
516 k.timekeeper = args.Timekeeper
517 k.tasks = newTaskSet(args.RootPIDNamespace)
518 k.rootUserNamespace = args.RootUserNamespace
519 k.rootUTSNamespace = args.RootUTSNamespace
520 k.rootIPCNamespace = args.RootIPCNamespace
521 k.rootNetworkNamespace = args.RootNetworkNamespace
522 if k.rootNetworkNamespace == nil {
523 k.rootNetworkNamespace = inet.NewRootNamespace(nil, nil, args.RootUserNamespace)
524 }
525 k.runningTasksCond.L = &k.runningTasksMu
526 k.cpuClockTickerWakeCh = make(chan struct{}, 1)
527 k.cpuClockTickerStopCond.L = &k.runningTasksMu
528 k.taskActivityCh = make(chan struct{})
529 k.applicationCores = args.ApplicationCores
530 if args.UseHostCores && k.HasCPUNumbers() {
531 args.UseHostCores = false
532 log.Infof("UseHostCores enabled but the platform implements HasCPUNumbers(): setting UseHostCores to false")
533 }
534
535 if args.UseHostCores {
536 k.useHostCores = true
537 maxCPU, err := hostcpu.MaxPossibleCPU()
538 if err != nil {
539 return fmt.Errorf("failed to get maximum CPU number: %v", err)
540 }
541 minAppCores := uint(maxCPU) + 1
542 if k.applicationCores < minAppCores {
543 log.Infof("UseHostCores enabled: increasing ApplicationCores from %d to %d", k.applicationCores, minAppCores)
544 k.applicationCores = minAppCores
545 }
546 }
547
548 if k.HasCPUNumbers() {
549 numCPUs := uint(k.NumCPUs())
550 if k.applicationCores < numCPUs {
551 log.Infof("ApplicationCores is less than NumCPUs: %d < %d", k.applicationCores, numCPUs)
552 log.Infof("Setting applicationCores to NumCPUs: %d", numCPUs)
553 k.applicationCores = numCPUs
554 }
555 }
556
557 k.extraAuxv = args.ExtraAuxv
558 k.vdso = args.Vdso

Callers 1

BootFunction · 0.95

Calls 15

SupervisorContextMethod · 0.95
DecRefMethod · 0.95
NewRootNamespaceFunction · 0.92
InfofFunction · 0.92
MaxPossibleCPUFunction · 0.92
NewManagerFunction · 0.92
NewFunction · 0.92
FromInt32Function · 0.92
CredentialsFromContextFunction · 0.92
NewFilesystemFunction · 0.92
NewFilesystemFunction · 0.92
NewInodeFunction · 0.92

Tested by

no test coverage detected