[PATCH v3 0/7] Cache CPU information from the DT

Samuel Holland samuel.holland at sifive.com
Wed Oct 14 04:30:17 PDT 2026


It turns out that OpenSBI spends a lot of time repeatedly parsing the
FDT to get information about the CPUs and local interrupt controllers.
Caching this information can significantly speed up cold boot. For
example, on the HiFive Premier P550 board (4 cores, PLIC, CLINT),
applying this series decreased boot time by a third, from 6.35 ms to
4.23 ms (with SBI_SCRATCH_NO_BOOT_PRINTS set). The impact would be even
larger on systems with more cores.

The cache cannot be used everywhere:
 - fw_platform_init() or other functions called before fdt_cpu_init()
 - fixup functions or other functions called after fdt_get_address_rw()
but it covers all drivers that previously called fdt_parse_hart_id().

Changes in v3:
 - Uninline fdt_get_address() so sbi_domain.h is not included everywhere
 - Add a helper to indicate when cached FDT blob offsets are invalidated
 - Check fdt_cached_offsets_valid() before returning cached FDT offsets
 - Document that fdt_cpu_hartindex_to_offset() cannot be used in fixups
 - Move fdt_cpu_init() call to generic_extensions_init()
 - Do not use cached offsets in fdt_domain_fixup()
 - Also use the cache in CMO library and TMC0 driver
 - Also use the cache in irqchip_aplic_update_idc_map()
 - Also update platform/generic/openhwgroup/ariane.c

Changes in v2:
 - Rename for_each_hartindex() to sbi_for_each_hartindex()
 - Add missing include of fdt_cpu.h in fdt_helper.c

Samuel Holland (7):
  lib utils/fdt: Drop fdt_parse_max_enabled_hart_id()
  lib: utils: Include more headers directly
  lib: utils/fdt: Indicate when cached FDT blob offsets are valid
  lib: utils/fdt: Cache CPU information from the DT
  lib: utils/fdt: Used cached CPU DT information
  lib: utils: Use fdt_cpu_intc_phandle_to_hartindex()
  lib: utils: Use fdt_cpu_get_timebase_frequency()

 include/sbi_utils/fdt/fdt_cpu.h               |  60 +++++++
 include/sbi_utils/fdt/fdt_helper.h            |  35 ++--
 include/sbi_utils/irqchip/imsic.h             |   2 +-
 include/sbi_utils/serial/uart8250.h           |   1 +
 lib/utils/cache/fdt_cmo_helper.c              |  22 +--
 lib/utils/cache/fdt_sifive_ec.c               |   1 +
 lib/utils/cache/fdt_sifive_pl2.c              |   1 +
 lib/utils/cppc/fdt_cppc_rpmi.c                |   1 +
 lib/utils/fdt/fdt_cpu.c                       | 118 ++++++++++++++
 lib/utils/fdt/fdt_domain.c                    |  41 ++---
 lib/utils/fdt/fdt_helper.c                    | 151 +++++-------------
 lib/utils/fdt/objects.mk                      |   1 +
 lib/utils/hsm/fdt_hsm_andes_atcsmu.c          |   1 +
 lib/utils/hsm/fdt_hsm_sifive_tmc0.c           |  24 +--
 lib/utils/i2c/fdt_i2c_spacemit.c              |   1 +
 lib/utils/irqchip/fdt_irqchip_aplic.c         |  21 +--
 lib/utils/irqchip/fdt_irqchip_imsic.c         |  19 +--
 lib/utils/irqchip/fdt_irqchip_plic.c          |  21 +--
 lib/utils/irqchip/imsic.c                     |   6 +-
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c    |   1 +
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c           |   1 +
 lib/utils/mpxy/fdt_mpxy_rpmi_mm.c             |   1 +
 lib/utils/regmap/fdt_regmap_syscon.c          |   1 +
 lib/utils/reset/fdt_reset_atcwdt200.c         |   1 +
 lib/utils/timer/fdt_timer_mtimer.c            |   7 +-
 lib/utils/timer/fdt_timer_plmt.c              |   8 +-
 platform/generic/eswin/eic770x.c              |   9 +-
 platform/generic/openhwgroup/ariane.c         |   7 +-
 platform/generic/openhwgroup/openpiton.c      |   7 +-
 platform/generic/platform.c                   |  10 +-
 platform/generic/sifive/sifive_dev_platform.c |   1 +
 31 files changed, 327 insertions(+), 254 deletions(-)
 create mode 100644 include/sbi_utils/fdt/fdt_cpu.h
 create mode 100644 lib/utils/fdt/fdt_cpu.c

-- 
2.52.0

base-commit: 6ad246a1494807ee91e36ffcf60e4c30bb309d45
branch: up/fdt-cpu



More information about the opensbi mailing list