From d32b0bbf2f8cfe548553c4012e2c0f79040d999f Mon Sep 17 00:00:00 2001 From: Andrew Donnellan Date: Tue, 29 Sep 2020 21:30:58 +1000 Subject: syz-ci: make polling times configurable Some users may wish to reduce the frequency at which syz-ci polls for jobs. Add two new optional settings, job_poll_period and commit_poll_period, that allow the administrator to set how often syz-ci polls for jobs and commits. Keep the existing defaults of 10 seconds and 1 hour respectively. Signed-off-by: Andrew Donnellan --- syz-ci/jobs.go | 19 +++++++------------ syz-ci/syz-ci.go | 14 ++++++++++---- syz-ci/testdata/example.cfg | 2 ++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/syz-ci/jobs.go b/syz-ci/jobs.go index 862d79d62..79d0fd8be 100644 --- a/syz-ci/jobs.go +++ b/syz-ci/jobs.go @@ -25,10 +25,6 @@ import ( "github.com/google/syzkaller/vm" ) -const ( - commitPollPeriod = time.Hour -) - type JobProcessor struct { cfg *Config name string @@ -56,9 +52,10 @@ func newJobProcessor(cfg *Config, managers []*Manager, stop, shutdownPending cha } func (jp *JobProcessor) loop() { - ticker := time.NewTicker(10 * time.Second) - defer ticker.Stop() - var lastCommitPoll time.Time + jobTicker := time.NewTicker(time.Duration(jp.cfg.JobPollPeriod) * time.Second) + commitTicker := time.NewTicker(time.Duration(jp.cfg.CommitPollPeriod) * time.Second) + defer jobTicker.Stop() + defer commitTicker.Stop() loop: for { // Check jp.stop separately first, otherwise if stop signal arrives during a job execution, @@ -69,17 +66,15 @@ loop: default: } select { - case <-ticker.C: + case <-jobTicker.C: if len(kernelBuildSem) != 0 { // If normal kernel build is in progress (usually on start), don't query jobs. // Otherwise we claim a job, but can't start it for a while. continue loop } jp.pollJobs() - if time.Since(lastCommitPoll) > commitPollPeriod { - jp.pollCommits() - lastCommitPoll = time.Now() - } + case <-commitTicker.C: + jp.pollCommits() case <-jp.stop: break loop } diff --git a/syz-ci/syz-ci.go b/syz-ci/syz-ci.go index 28ab11ef8..0467449ee 100644 --- a/syz-ci/syz-ci.go +++ b/syz-ci/syz-ci.go @@ -96,6 +96,10 @@ type Config struct { BisectBinDir string `json:"bisect_bin_dir"` Ccache string `json:"ccache"` Managers []*ManagerConfig `json:"managers"` + // Poll period for jobs in seconds (optional, defaults to 10 seconds) + JobPollPeriod int `json:"job_poll_period"` + // Poll period for commits in seconds (optional, defaults to 3600 seconds) + CommitPollPeriod int `json:"commit_poll_period"` } type ManagerConfig struct { @@ -237,10 +241,12 @@ func serveHTTP(cfg *Config) { func loadConfig(filename string) (*Config, error) { cfg := &Config{ - SyzkallerRepo: "https://github.com/google/syzkaller.git", - SyzkallerBranch: "master", - ManagerPort: 10000, - Goroot: os.Getenv("GOROOT"), + SyzkallerRepo: "https://github.com/google/syzkaller.git", + SyzkallerBranch: "master", + ManagerPort: 10000, + Goroot: os.Getenv("GOROOT"), + JobPollPeriod: 10, + CommitPollPeriod: 3600, } if err := config.LoadFile(filename, cfg); err != nil { return nil, err diff --git a/syz-ci/testdata/example.cfg b/syz-ci/testdata/example.cfg index b9ff45cfd..1f8a410c2 100644 --- a/syz-ci/testdata/example.cfg +++ b/syz-ci/testdata/example.cfg @@ -5,6 +5,8 @@ "hub_addr": "2.3.4.5:2345", "hub_key": "222", "goroot": "/syzkaller/goroot", + "job_poll_period": 20, + "commit_poll_period": 1800, "managers": [ { "name": "upstream-kasan", -- cgit mrf-deployment