mbox series

[v1,0/8] Cleanup the LMB subsystem

Message ID 20241211105504.453234-1-ilias.apalodimas@linaro.org
Headers show
Series Cleanup the LMB subsystem | expand

Message

Ilias Apalodimas Dec. 11, 2024, 10:54 a.m. UTC
Hi all,

This is v1 of the rfc [0]

The LMB subsystem was used opportunistically for a number of years.
A while back Sughosh merged it with the EFI subsystem in order to have a
common allocator and avoid subsystems overwriting memory they shouldn't.

This is an initial cleanup of all the crud we gathered over the years.
There's no functional change expected from the patches as they just cleanup
some abstraction functions and rename a few variables to make more
sense.

I plan to make even bigger changes -- e.g I don't see the point of
having *_alloc() and *_reserve() versions of the functions since they mostly
do the same thing and just cause confusion. lmb_alloc_addr_flags()
returning the base address on success makes little sense since we
already *request* the address on the function arguments, etc.
Since this patchset grew enough already, I'd like to get it in
before more refactoring happens.

It's worth noting that although some patches slightly increase the code
size due to an extra flags argument being carried around, the final
result is eventually smaller.

# qemu_arm64_lwip_defconfig (version string adds another 20b)
add/remove: 0/5 grow/shrink: 15/1 up/down: 568/-628 (-60)
Function                                     old     new   delta
lmb_alloc_base                                80     324    +244
lmb_alloc_addr                                 8     144    +136
lmb_reserve                                    8      96     +88
version_string                                50      70     +20
boot_relocate_fdt                            488     508     +20
boot_ramdisk_high                            268     284     +16
lmb_add_region_flags                         696     704      +8
boot_fdt_reserve_region                      100     108      +8
load_serial                                  548     552      +4
lmb_alloc                                      8      12      +4
image_setup_libfdt                           368     372      +4
do_load                                      728     732      +4
do_bootz                                     332     336      +4
do_booti                                     520     524      +4
bootm_run_states                            2176    2180      +4
lmb_alloc_addr_flags                           4       -      -4
boot_fdt_add_mem_rsv_regions                 284     280      -4
lmb_alloc_base_flags                          76       -     -76
lmb_reserve_flags                             96       -     -96
_lmb_alloc_addr                              144       -    -144
_lmb_alloc_base                              304       -    -304
Total: Before=1020102, After=1020042, chg -0.01%

# sandbox_defconfig (version string adds another 20b)
add/remove: 0/3 grow/shrink: 24/3 up/down: 523/-501 (22)
Function                                     old     new   delta
lmb_alloc_base                                48     299    +251
lmb_alloc_addr                                 4      92     +88
lmb_reserve                                    4      58     +54
test_alloc_addr                             2933    2963     +30
version_string                                50      70     +20
lib_test_lmb_overlapping_reserve            1018    1030     +12
lmb_add_region_flags                         600     610     +10
test_multi_alloc.constprop                  3034    3042      +8
test_get_unreserved_size                    1032    1038      +6
boot_relocate_fdt                            599     605      +6
boot_fdt_reserve_region                       67      73      +6
lmb_alloc                                      4       9      +5
lmb_free_flags                               190     194      +4
wget_handler                                1530    1533      +3
tftp_handler                                1190    1192      +2
test_noreserved                             1207    1209      +2
test_bigblock                                911     913      +2
load_serial                                  946     948      +2
lib_test_lmb_flags                          2101    2103      +2
do_spi_flash                                3150    3152      +2
do_bootz                                     526     528      +2
do_bootm_linux                              2067    2069      +2
bootm_run_states                            5275    5277      +2
_fs_read.lto_priv                            331     333      +2
lmb_dump_region.lto_priv                     356     353      -3
lmb_add                                       59      52      -7
efi_allocate_pages.part                      303     249     -54
lmb_reserve_flags                             65       -     -65
_lmb_alloc_addr.lto_priv                      92       -     -92
_lmb_alloc_base.lto_priv                     280       -    -280
Total: Before=2492722, After=2492744, chg +0.00%

[0] https://lore.kernel.org/u-boot/20241208105223.2821049-1-ilias.apalodimas@linaro.org/T/#m43927af3f758f8d0be897a8a6c77b4325546afd5

Changes since v1:
- Rebased on top of
  https://lore.kernel.org/u-boot/20241211021703.2333-1-semen.protsenko@linaro.org/
  https://lore.kernel.org/u-boot/20241211022550.2995-1-semen.protsenko@linaro.org/
- Converted enum lmb_flags to a u32
- Removed the _flags from all the functions
- Added a patch that removes lmb_align_down()
- Picked up r-b tags. Tom I kept your on patch #3 since I only changed the name
  of the function and assumed you are ok with it.

Ilias Apalodimas (8):
  lmb: Remove lmb_align_down()
  lmb: Move enum lmb_flags to a u32
  lmb: Remove lmb_reserve_flags()
  lmb: Rename free_mem to available_mem
  lmb: Remove lmb_add_region()
  lmb: Remove lmb_alloc_addr_flags()
  lmb: Remove lmb_alloc_base_flags()
  lmb: Rename _lmb_alloc_addr() to lmb_alloc_addr_flags()

 arch/powerpc/cpu/mpc85xx/mp.c |   2 +-
 arch/powerpc/lib/misc.c       |   2 +-
 boot/bootm.c                  |   3 +-
 boot/image-board.c            |  20 +++--
 boot/image-fdt.c              |  15 ++--
 cmd/booti.c                   |   2 +-
 cmd/bootz.c                   |   2 +-
 cmd/load.c                    |   2 +-
 fs/fs.c                       |   2 +-
 include/lmb.h                 |  58 ++++++---------
 lib/efi_loader/efi_memory.c   |   6 +-
 lib/lmb.c                     | 136 +++++++++++-----------------------
 test/cmd/bdinfo.c             |   4 +-
 test/lib/lmb.c                |  92 +++++++++++------------
 14 files changed, 145 insertions(+), 201 deletions(-)

--
2.45.2