Skip to content

Commit

Permalink
Merge pull request #273 from tbs60/dev_tming
Browse files Browse the repository at this point in the history
feat:support auto search toolchain, issue: #272
  • Loading branch information
tming authored Aug 7, 2024
2 parents a72c77a + 81e28e6 commit a555faf
Show file tree
Hide file tree
Showing 18 changed files with 540 additions and 44 deletions.
5 changes: 5 additions & 0 deletions src/backend/booster/bk_dist/booster/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
FlagOutputEnvSourceFile = "output_env_source_file"
FlagCommitSuicide = "commit_suicide"
FlagToolChainJSONFile = "tool_chain_json_file"
FlagSearchToolchain = "search_toolchain"
FlagBatchMode = "batch_mode"
FlagDirectives = "directives"
FlagGlobalSlots = "global_slots"
Expand Down Expand Up @@ -279,6 +280,10 @@ var (
Name: "tool_chain_json_file",
Usage: "json file to describe tool chain",
},
commandCli.BoolFlag{
Name: "search_toolchain",
Usage: "automatically search for toolchain based on command",
},
commandCli.BoolFlag{
Name: "batch_mode, bm",
Usage: "batch mode for booster, multi booster in the same projectID will use one same workID",
Expand Down
1 change: 1 addition & 0 deletions src/backend/booster/bk_dist/booster/command/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func newBooster(c *commandCli.Context) (*pkg.Booster, error) {
WriteMemroy: c.Bool(FlagWriteMemroMemroy),
IdleKeepSecs: c.Int(FlagIdleKeepSecs),
CleanTmpFilesDayAgo: cleanTmpFilesDayAgo,
SearchToolchain: c.Bool(FlagSearchToolchain),
},

Transport: dcType.BoosterTransport{
Expand Down
4 changes: 4 additions & 0 deletions src/backend/booster/bk_dist/booster/pkg/booster.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ func (b *Booster) getWorkersEnv() map[string]string {
requiredEnv[env.KeyExecutorIdleKeepSecs] = strconv.Itoa(b.config.Works.IdleKeepSecs)
}

if b.config.Works.SearchToolchain {
requiredEnv[env.KeyExecutorSearchToolchain] = envValueTrue
}

resultEnv := make(map[string]string, 10)
for k, v := range requiredEnv {
resultEnv[env.GetEnvKey(k)] = v
Expand Down
1 change: 1 addition & 0 deletions src/backend/booster/bk_dist/common/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
KeyExecutorTotalActionNum = "TOTAL_ACTION_NUM"
KeyExecutorUseWebSocket = "USE_WEBSOCKET"
KeyExecutorNewShader = "NEW_SHADER"
KeyExecutorSearchToolchain = "SEARCH_TOOLCHAIN"

KeyUserDefinedLogLevel = "USER_DEFINED_LOG_LEVEL"
KeyUserDefinedExecutorLogLevel = "USER_DEFINED_EXECUTOR_LOG_LEVEL"
Expand Down
4 changes: 4 additions & 0 deletions src/backend/booster/bk_dist/common/syscall/syscall_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,7 @@ func RedirectStderror(f string) error {

return nil
}

func NeedSearchToolchain(input *env.Sandbox) bool {
return false
}
8 changes: 8 additions & 0 deletions src/backend/booster/bk_dist/common/syscall/syscall_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,11 @@ func RedirectStderror(f string) error {

return nil
}

func NeedSearchToolchain(input *env.Sandbox) bool {
if input != nil {
return input.GetEnv(env.KeyExecutorSearchToolchain) != ""
}

return env.GetEnv(env.KeyExecutorSearchToolchain) != ""
}
4 changes: 4 additions & 0 deletions src/backend/booster/bk_dist/common/syscall/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,7 @@ func RedirectStderror(f string) error {

return nil
}

func NeedSearchToolchain(input *env.Sandbox) bool {
return false
}
2 changes: 2 additions & 0 deletions src/backend/booster/bk_dist/common/types/booster.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ type BoosterWorks struct {

EnableLink bool
EnableLib bool

SearchToolchain bool
}

// BoosterTransport describe the transport data to controller
Expand Down
40 changes: 33 additions & 7 deletions src/backend/booster/bk_dist/controller/pkg/manager/basic/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ func NewMgr(pCtx context.Context, work *types.Work) types.BasicMgr {
ctx, _ := context.WithCancel(pCtx)

return &Mgr{
ctx: ctx,
work: work,
settings: &types.WorkSettings{},
info: types.NewInitWorkInfo(work.ID()),
waitWorkReadyTick: 100 * time.Millisecond,
analysisStatus: types.NewWorkAnalysisStatus(),
toolchainMap: make(map[string]toolchainCache, 1),
ctx: ctx,
work: work,
settings: &types.WorkSettings{},
info: types.NewInitWorkInfo(work.ID()),
waitWorkReadyTick: 100 * time.Millisecond,
analysisStatus: types.NewWorkAnalysisStatus(),
toolchainMap: make(map[string]toolchainCache, 1),
searchToolChainCache: make(map[string]bool, 10),
}
}

Expand All @@ -70,9 +71,13 @@ type Mgr struct {
toolchainLock sync.RWMutex
toolchainMap map[string]toolchainCache

searchToolchainLock sync.RWMutex

aliveTask int64

registeredCounter int32

searchToolChainCache map[string]bool
}

// Alive return the current alive task number
Expand Down Expand Up @@ -516,3 +521,24 @@ func (m *Mgr) GetToolChainTimestamp(key string) (int64, error) {

return v.toolchain.Timestamp, nil
}

// SearchToolChain search toolchain files by cmd, ensure only execute once
func (m *Mgr) SearchToolChain(cmd string) error {
m.searchToolchainLock.Lock()
defer m.searchToolchainLock.Unlock()

if _, ok := m.searchToolChainCache[cmd]; ok {
blog.Infof("basic: toolchain with key:%s search before, do nothing", cmd)
return nil
}

m.searchToolChainCache[cmd] = true

// TODO : search toolchain with cmd now
toolchain, err := searchToolChain(cmd)
if err == nil && toolchain != nil {
m.SetToolChain(toolchain)
}

return nil
}
Loading

0 comments on commit a555faf

Please sign in to comment.