src/Pure/Tools/build_schedule.scala
changeset 79102 4d5f878665a3
parent 79101 4e47b34fbb8e
child 79103 883f61f0beda
equal deleted inserted replaced
79101:4e47b34fbb8e 79102:4d5f878665a3
   465   trait Scheduler {
   465   trait Scheduler {
   466     def next(state: Build_Process.State): List[Config]
   466     def next(state: Build_Process.State): List[Config]
   467     def build_schedule(build_state: Build_Process.State): Schedule
   467     def build_schedule(build_state: Build_Process.State): Schedule
   468   }
   468   }
   469 
   469 
   470   abstract class Heuristic(timing_data: Timing_Data, max_threads_limit: Int) extends Scheduler {
   470   abstract class Heuristic(timing_data: Timing_Data) extends Scheduler {
   471     val host_infos = timing_data.host_infos
   471     val host_infos = timing_data.host_infos
   472     val ordered_hosts = host_infos.hosts.sorted(host_infos.host_speeds)
   472     val ordered_hosts = host_infos.hosts.sorted(host_infos.host_speeds)
   473     val max_threads = host_infos.hosts.map(_.info.num_cpus).max min max_threads_limit
       
   474 
       
   475     def best_time(job_name: String): Time = {
       
   476       val host = ordered_hosts.last
       
   477       val threads = timing_data.best_threads(job_name, max_threads) min host.info.num_cpus
       
   478       timing_data.estimate(job_name, host.info.hostname, threads)
       
   479     }
       
   480 
   473 
   481     def build_schedule(build_state: Build_Process.State): Schedule = {
   474     def build_schedule(build_state: Build_Process.State): Schedule = {
   482       @tailrec
   475       @tailrec
   483       def simulate(state: State): State =
   476       def simulate(state: State): State =
   484         if (state.is_finished) state
   477         if (state.is_finished) state
   511 
   504 
   512   abstract class Path_Heuristic(
   505   abstract class Path_Heuristic(
   513     timing_data: Timing_Data,
   506     timing_data: Timing_Data,
   514     sessions_structure: Sessions.Structure,
   507     sessions_structure: Sessions.Structure,
   515     max_threads_limit: Int
   508     max_threads_limit: Int
   516   ) extends Heuristic(timing_data, max_threads_limit) {
   509   ) extends Heuristic(timing_data) {
   517     /* pre-computed properties for efficient heuristic */
   510     /* pre-computed properties for efficient heuristic */
   518 
   511 
       
   512     val max_threads = host_infos.hosts.map(_.info.num_cpus).max min max_threads_limit
       
   513 
   519     type Node = String
   514     type Node = String
   520 
       
   521     val build_graph = sessions_structure.build_graph
   515     val build_graph = sessions_structure.build_graph
   522 
   516 
   523     val minimals = build_graph.minimals
   517     val minimals = build_graph.minimals
   524     val maximals = build_graph.maximals
   518     val maximals = build_graph.maximals
   525 
   519 
   526     def all_preds(node: Node): Set[Node] = build_graph.all_preds(List(node)).toSet
   520     def all_preds(node: Node): Set[Node] = build_graph.all_preds(List(node)).toSet
   527     val maximals_all_preds = maximals.map(node => node -> all_preds(node)).toMap
   521     val maximals_all_preds = maximals.map(node => node -> all_preds(node)).toMap
   528 
   522 
       
   523     def best_time(node: Node): Time = {
       
   524       val host = ordered_hosts.last
       
   525       val threads = timing_data.best_threads(node, max_threads) min host.info.num_cpus
       
   526       timing_data.estimate(node, host.info.hostname, threads)
       
   527     }
   529     val best_times = build_graph.keys.map(node => node -> best_time(node)).toMap
   528     val best_times = build_graph.keys.map(node => node -> best_time(node)).toMap
   530 
   529 
   531     val succs_max_time_ms = build_graph.node_height(best_times(_).ms)
   530     val succs_max_time_ms = build_graph.node_height(best_times(_).ms)
   532     def max_time(node: Node): Time = Time.ms(succs_max_time_ms(node)) + best_times(node)
   531     def max_time(node: Node): Time = Time.ms(succs_max_time_ms(node)) + best_times(node)
   533     def max_time(task: Build_Process.Task): Time = max_time(task.name)
   532     def max_time(task: Build_Process.Task): Time = max_time(task.name)