Make BottomUpMutators parallel

Append .Parallel() to all of the RegisterBottomUpMutator calls to tell
Blueprint it can run them in parallel.

Test: identical build.ninja, passes race detector
Change-Id: I969a0689522d4cba7c8ff51e2aa00fe2fd338a89
This commit is contained in:
Colin Cross
2016-08-07 21:17:54 -07:00
parent 1317701114
commit e8a67a7c58
7 changed files with 38 additions and 19 deletions

View File

@@ -25,10 +25,10 @@ import (
) )
func init() { func init() {
RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator) RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator).Parallel()
RegisterTopDownMutator("defaults", defaultsMutator) RegisterTopDownMutator("defaults", defaultsMutator)
RegisterBottomUpMutator("arch", ArchMutator) RegisterBottomUpMutator("arch", ArchMutator).Parallel()
} }
var ( var (

View File

@@ -44,8 +44,8 @@ type androidBottomUpMutatorContext struct {
androidBaseContextImpl androidBaseContextImpl
} }
func RegisterBottomUpMutator(name string, mutator AndroidBottomUpMutator) { func RegisterBottomUpMutator(name string, mutator AndroidBottomUpMutator) soong.BottomUpMutatorHandle {
soong.RegisterBottomUpMutator(name, func(ctx blueprint.BottomUpMutatorContext) { return soong.RegisterBottomUpMutator(name, func(ctx blueprint.BottomUpMutatorContext) {
if a, ok := ctx.Module().(Module); ok { if a, ok := ctx.Module().(Module); ok {
actx := &androidBottomUpMutatorContext{ actx := &androidBottomUpMutatorContext{
BottomUpMutatorContext: ctx, BottomUpMutatorContext: ctx,

View File

@@ -24,7 +24,7 @@ import (
) )
func init() { func init() {
RegisterBottomUpMutator("variable", variableMutator) RegisterBottomUpMutator("variable", variableMutator).Parallel()
} }
type variableProperties struct { type variableProperties struct {

View File

@@ -38,17 +38,17 @@ func init() {
// LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by // LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by
// the Go initialization order because this package depends on common, so common's init // the Go initialization order because this package depends on common, so common's init
// functions will run first. // functions will run first.
android.RegisterBottomUpMutator("link", linkageMutator) android.RegisterBottomUpMutator("link", linkageMutator).Parallel()
android.RegisterBottomUpMutator("ndk_api", ndkApiMutator) android.RegisterBottomUpMutator("ndk_api", ndkApiMutator).Parallel()
android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator) android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator).Parallel()
android.RegisterBottomUpMutator("begin", beginMutator) android.RegisterBottomUpMutator("begin", beginMutator).Parallel()
android.RegisterBottomUpMutator("deps", depsMutator) android.RegisterBottomUpMutator("deps", depsMutator).Parallel()
android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan)) android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan))
android.RegisterBottomUpMutator("asan", sanitizerMutator(asan)) android.RegisterBottomUpMutator("asan", sanitizerMutator(asan)).Parallel()
android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan)) android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan))
android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan)) android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan)).Parallel()
pctx.Import("android/soong/cc/config") pctx.Import("android/soong/cc/config")
} }

View File

@@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"sync"
"github.com/google/blueprint" "github.com/google/blueprint"
@@ -59,6 +60,7 @@ var (
// These libraries have migrated over to the new ndk_library, which is added // These libraries have migrated over to the new ndk_library, which is added
// as a variation dependency via depsMutator. // as a variation dependency via depsMutator.
ndkMigratedLibs = []string{} ndkMigratedLibs = []string{}
ndkMigratedLibsLock sync.Mutex // protects ndkMigratedLibs writes during parallel beginMutator
) )
// Creates a stub shared library based on the provided version file. // Creates a stub shared library based on the provided version file.
@@ -177,6 +179,8 @@ func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
c.baseCompiler.compilerInit(ctx) c.baseCompiler.compilerInit(ctx)
name := strings.TrimSuffix(ctx.ModuleName(), ".ndk") name := strings.TrimSuffix(ctx.ModuleName(), ".ndk")
ndkMigratedLibsLock.Lock()
defer ndkMigratedLibsLock.Unlock()
for _, lib := range ndkMigratedLibs { for _, lib := range ndkMigratedLibs {
if lib == name { if lib == name {
return return

View File

@@ -25,7 +25,7 @@ func init() {
soong.RegisterModuleType("gensrcs", GenSrcsFactory) soong.RegisterModuleType("gensrcs", GenSrcsFactory)
soong.RegisterModuleType("genrule", GenRuleFactory) soong.RegisterModuleType("genrule", GenRuleFactory)
android.RegisterBottomUpMutator("genrule_deps", genruleDepsMutator) android.RegisterBottomUpMutator("genrule_deps", genruleDepsMutator).Parallel()
} }
var ( var (

View File

@@ -34,9 +34,10 @@ type mutator struct {
name string name string
bottomUpMutator blueprint.BottomUpMutator bottomUpMutator blueprint.BottomUpMutator
topDownMutator blueprint.TopDownMutator topDownMutator blueprint.TopDownMutator
parallel bool
} }
var mutators []mutator var mutators []*mutator
func RegisterModuleType(name string, factory blueprint.ModuleFactory) { func RegisterModuleType(name string, factory blueprint.ModuleFactory) {
moduleTypes = append(moduleTypes, moduleType{name, factory}) moduleTypes = append(moduleTypes, moduleType{name, factory})
@@ -46,12 +47,23 @@ func RegisterSingletonType(name string, factory blueprint.SingletonFactory) {
singletons = append(singletons, singleton{name, factory}) singletons = append(singletons, singleton{name, factory})
} }
func RegisterBottomUpMutator(name string, m blueprint.BottomUpMutator) { func RegisterBottomUpMutator(name string, m blueprint.BottomUpMutator) BottomUpMutatorHandle {
mutators = append(mutators, mutator{name: name, bottomUpMutator: m}) mutator := &mutator{name: name, bottomUpMutator: m}
mutators = append(mutators, mutator)
return mutator
} }
func RegisterTopDownMutator(name string, m blueprint.TopDownMutator) { func RegisterTopDownMutator(name string, m blueprint.TopDownMutator) {
mutators = append(mutators, mutator{name: name, topDownMutator: m}) mutators = append(mutators, &mutator{name: name, topDownMutator: m})
}
type BottomUpMutatorHandle interface {
Parallel() BottomUpMutatorHandle
}
func (mutator *mutator) Parallel() BottomUpMutatorHandle {
mutator.parallel = true
return mutator
} }
func NewContext() *blueprint.Context { func NewContext() *blueprint.Context {
@@ -67,7 +79,10 @@ func NewContext() *blueprint.Context {
for _, t := range mutators { for _, t := range mutators {
if t.bottomUpMutator != nil { if t.bottomUpMutator != nil {
ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator) handle := ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator)
if t.parallel {
handle.Parallel()
}
} }
if t.topDownMutator != nil { if t.topDownMutator != nil {
ctx.RegisterTopDownMutator(t.name, t.topDownMutator) ctx.RegisterTopDownMutator(t.name, t.topDownMutator)