mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 05:53:39 +00:00
main: add -p flag to set parallelism
This is very useful for debugging.
This commit is contained in:
committed by
Ron Evans
parent
79bdd3f79a
commit
c638f03b3c
+2
-2
@@ -462,7 +462,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
||||
outext := filepath.Ext(outpath)
|
||||
if outext == ".o" || outext == ".bc" || outext == ".ll" {
|
||||
// Run jobs to produce the LLVM module.
|
||||
err := runJobs(programJob)
|
||||
err := runJobs(programJob, config.Options.Parallelism)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -686,7 +686,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
||||
// Run all jobs to compile and link the program.
|
||||
// Do this now (instead of after elf-to-hex and similar conversions) as it
|
||||
// is simpler and cannot be parallelized.
|
||||
err = runJobs(linkJob)
|
||||
err = runJobs(linkJob, config.Options.Parallelism)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+12
-3
@@ -71,7 +71,16 @@ func (job *compileJob) readyToRun() bool {
|
||||
// It runs all jobs in the order of the dependencies slice, depth-first.
|
||||
// Therefore, if some jobs are preferred to run before others, they should be
|
||||
// ordered as such in the job dependencies.
|
||||
func runJobs(job *compileJob) error {
|
||||
func runJobs(job *compileJob, parallelism int) error {
|
||||
if parallelism == 0 {
|
||||
// Have a default, if the parallelism isn't set. This is useful for
|
||||
// tests.
|
||||
parallelism = runtime.NumCPU()
|
||||
}
|
||||
if parallelism < 1 {
|
||||
return fmt.Errorf("-p flag must be at least 1, provided -p=%d", parallelism)
|
||||
}
|
||||
|
||||
// Create a slice of jobs to run, where all dependencies are run in order.
|
||||
jobs := []*compileJob{}
|
||||
addedJobs := map[*compileJob]struct{}{}
|
||||
@@ -94,7 +103,7 @@ func runJobs(job *compileJob) error {
|
||||
defer close(workerChan)
|
||||
|
||||
// Start a number of workers.
|
||||
for i := 0; i < runtime.NumCPU(); i++ {
|
||||
for i := 0; i < parallelism; i++ {
|
||||
if jobRunnerDebug {
|
||||
fmt.Println("## starting worker", i)
|
||||
}
|
||||
@@ -109,7 +118,7 @@ func runJobs(job *compileJob) error {
|
||||
for {
|
||||
// If there are free workers, try starting a new job (if one is
|
||||
// available). If it succeeds, try again to fill the entire worker pool.
|
||||
if numRunningJobs < runtime.NumCPU() {
|
||||
if numRunningJobs < parallelism {
|
||||
jobToRun := nextJob(jobs)
|
||||
if jobToRun != nil {
|
||||
// Start job.
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ func (l *Library) Load(config *compileopts.Config, tmpdir string) (dir string, e
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = runJobs(job)
|
||||
err = runJobs(job, config.Options.Parallelism)
|
||||
return filepath.Dir(job.result), err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user