Parallelize finding board settings

This reduces the _elapsed_ time running the script from ~90s to ~15s
on my AMD Ryzen 7 5700U. The CPU time is still around 2 minutes.
This commit is contained in:
Jeff Epler 2022-10-14 11:07:46 -05:00
parent 25164030e2
commit ad130e87f0
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE

View File

@ -20,6 +20,7 @@ import sys
import json import json
import yaml import yaml
import pathlib import pathlib
from concurrent.futures import ThreadPoolExecutor
tools_dir = pathlib.Path(__file__).resolve().parent tools_dir = pathlib.Path(__file__).resolve().parent
top_dir = tools_dir.parent top_dir = tools_dir.parent
@ -28,7 +29,11 @@ sys.path.insert(0, str(tools_dir / "adabot"))
sys.path.insert(0, str(top_dir / "docs")) sys.path.insert(0, str(top_dir / "docs"))
import build_board_info import build_board_info
from shared_bindings_matrix import get_settings_from_makefile from shared_bindings_matrix import (
get_settings_from_makefile,
SUPPORTED_PORTS,
all_ports_all_boards,
)
PORT_TO_ARCH = { PORT_TO_ARCH = {
"atmel-samd": "arm", "atmel-samd": "arm",
@ -86,6 +91,20 @@ def set_boards_to_build(build_all):
port_to_boards[port].add(board_id) port_to_boards[port].add(board_id)
board_to_port[board_id] = port board_to_port[board_id] = port
def compute_board_settings():
if board_settings:
return
def get_settings(arg):
board = arg[1].name
return (
board,
get_settings_from_makefile(str(top_dir / "ports" / board_to_port[board]), board),
)
with ThreadPoolExecutor(max_workers=os.cpu_count()) as ex:
board_settings.update(ex.map(get_settings, all_ports_all_boards()))
boards_to_build = all_board_ids boards_to_build = all_board_ids
if not build_all: if not build_all:
@ -123,11 +142,8 @@ def set_boards_to_build(build_all):
# As a (nearly) last resort, for some certain files, we compute the settings from the # As a (nearly) last resort, for some certain files, we compute the settings from the
# makefile for each board and determine whether to build them that way. # makefile for each board and determine whether to build them that way.
if p.startswith("frozen") or p.startswith("supervisor") or module_matches: if p.startswith("frozen") or p.startswith("supervisor") or module_matches:
compute_board_settings()
for board in all_board_ids: for board in all_board_ids:
if board not in board_settings:
board_settings[board] = get_settings_from_makefile(
str(top_dir / "ports" / board_to_port[board]), board
)
settings = board_settings[board] settings = board_settings[board]
# Check frozen files to see if they are in each board. # Check frozen files to see if they are in each board.