diff options
| -rw-r--r-- | pkg/bisect/bisect.go | 4 | ||||
| -rw-r--r-- | pkg/instance/instance.go | 40 | ||||
| -rw-r--r-- | pkg/osutil/semaphore.go | 42 | ||||
| -rw-r--r-- | pkg/updater/updater.go | 2 | ||||
| -rw-r--r-- | syz-ci/manager.go | 4 |
5 files changed, 50 insertions, 42 deletions
diff --git a/pkg/bisect/bisect.go b/pkg/bisect/bisect.go index 55a5d44f7..a37436495 100644 --- a/pkg/bisect/bisect.go +++ b/pkg/bisect/bisect.go @@ -36,8 +36,8 @@ type Config struct { Syzkaller SyzkallerConfig Repro ReproConfig Manager *mgrconfig.Config - BuildSemaphore *instance.Semaphore - TestSemaphore *instance.Semaphore + BuildSemaphore *osutil.Semaphore + TestSemaphore *osutil.Semaphore BuildCPUs int // CrossTree specifies whether a cross tree bisection is to take place, i.e. // Kernel.Commit is not reachable from Kernel.Branch. diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index b4460e3ab..df0d74b98 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -40,8 +40,8 @@ type Env interface { type env struct { cfg *mgrconfig.Config optionalFlags bool - buildSem *Semaphore - testSem *Semaphore + buildSem *osutil.Semaphore + testSem *osutil.Semaphore } type BuildKernelConfig struct { @@ -56,7 +56,7 @@ type BuildKernelConfig struct { BuildCPUs int } -func NewEnv(cfg *mgrconfig.Config, buildSem, testSem *Semaphore) (Env, error) { +func NewEnv(cfg *mgrconfig.Config, buildSem, testSem *osutil.Semaphore) (Env, error) { if !vm.AllowsOvercommit(cfg.Type) { return nil, fmt.Errorf("test instances are not supported for %v VMs", cfg.Type) } @@ -508,40 +508,6 @@ func RunnerCmd(prog, fwdAddr, os, arch string, poolIdx, vmIdx int, threaded, new "-threaded=%t -new-env=%t", prog, fwdAddr, os, arch, poolIdx, vmIdx, threaded, newEnv) } -type Semaphore struct { - ch chan struct{} -} - -func NewSemaphore(count int) *Semaphore { - s := &Semaphore{ - ch: make(chan struct{}, count), - } - for i := 0; i < count; i++ { - s.Signal() - } - return s -} - -func (s *Semaphore) Wait() { - <-s.ch -} - -func (s *Semaphore) WaitC() <-chan struct{} { - return s.ch -} - -func (s *Semaphore) Available() int { - return len(s.ch) -} - -func (s *Semaphore) Signal() { - if av := s.Available(); av == cap(s.ch) { - // Not super reliable, but let it be here just in case. - panic(fmt.Sprintf("semaphore capacity (%d) is exceeded (%d)", cap(s.ch), av)) - } - s.ch <- struct{}{} -} - // RunSmokeTest executes syz-manager in the smoke test mode and returns two values: // The crash report, if the testing failed. // An error if there was a problem not related to testing the kernel. diff --git a/pkg/osutil/semaphore.go b/pkg/osutil/semaphore.go new file mode 100644 index 000000000..83d251ce0 --- /dev/null +++ b/pkg/osutil/semaphore.go @@ -0,0 +1,42 @@ +// Copyright 2025 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package osutil + +import ( + "fmt" +) + +type Semaphore struct { + ch chan struct{} +} + +func NewSemaphore(count int) *Semaphore { + s := &Semaphore{ + ch: make(chan struct{}, count), + } + for i := 0; i < count; i++ { + s.Signal() + } + return s +} + +func (s *Semaphore) Wait() { + <-s.ch +} + +func (s *Semaphore) WaitC() <-chan struct{} { + return s.ch +} + +func (s *Semaphore) Available() int { + return len(s.ch) +} + +func (s *Semaphore) Signal() { + if av := s.Available(); av == cap(s.ch) { + // Not super reliable, but let it be here just in case. + panic(fmt.Sprintf("semaphore capacity (%v) is exceeded (%v)", cap(s.ch), av)) + } + s.ch <- struct{}{} +} diff --git a/pkg/updater/updater.go b/pkg/updater/updater.go index dd62a061a..00181f732 100644 --- a/pkg/updater/updater.go +++ b/pkg/updater/updater.go @@ -49,7 +49,7 @@ type Updater struct { type Config struct { // If set, exit on updates instead of restarting the current binary. ExitOnUpdate bool - BuildSem *instance.Semaphore + BuildSem *osutil.Semaphore ReportBuildError func(commit *vcs.Commit, compilerID string, buildErr error) SyzkallerRepo string SyzkallerBranch string diff --git a/syz-ci/manager.go b/syz-ci/manager.go index 204bba875..116b605f0 100644 --- a/syz-ci/manager.go +++ b/syz-ci/manager.go @@ -170,12 +170,12 @@ func createManager(cfg *Config, mgrcfg *ManagerConfig, debug bool) (*Manager, er // Gates kernel builds, syzkaller builds and coverage report generation. // Kernel builds take whole machine, so we don't run more than one at a time. // Also current image build script uses some global resources (/dev/nbd0) and can't run in parallel. -var buildSem = instance.NewSemaphore(1) +var buildSem = osutil.NewSemaphore(1) // Gates tests that require extra VMs. // Currently we overcommit instances in such cases, so we'd like to minimize the number of // simultaneous env.Test calls. -var testSem = instance.NewSemaphore(1) +var testSem = osutil.NewSemaphore(1) const fuzzingMinutesBeforeCover = 360 const benchUploadPeriod = 30 * time.Minute |
