[PATCH 0/9] dm: core: Support collecting and reporting stats

Simon Glass sjg at chromium.org
Sun May 8 12:39:18 CEST 2022


Driver model can use a lot of memory, as it is the core of all drivers
and devices in U-Boot. Add a command to show how much is in use, along
with the sizes of various data structures.

This patch can be used to analyse the impact of various potential changes
to driver model for SPL, none of which has been implemented. Most involve
shrinking the size of struct udevice, which is a particular problem on
64-bit machines since their pointers are so unnecessarily large in SPL.

To try this out, enable SPL_DM_STATS and then build and run on your
board. You should see output for SPL and U-Boot proper, like this:

   Struct sizes: udevice 90, driver 78, uclass 30, uc_driver 78
   Memory: device 11:990, device names 111, uclass a:1e0

   Attached type    Count   Size    Cur   Tags   Save
   ---------------  -----  -----  -----  -----  -----
   plat                 3     e0    990    914     7c (124)
   parent_plat          2     40    990    910     80 (128)
   uclass_plat          1     10    990    90c     84 (132)
   priv                 6    13d    990    920     70 (112)
   parent_priv          0      0    990    908     88 (136)
   uclass_priv          3     38    990    914     7c (124)
   driver_data          0      0    990    908     88 (136)
   uclass               0      0
   Attached total       f    2a5                   37c (892)
   tags                 0      0

   Total size: e15 (3605)

   With tags:       a99 (2713)
   - singly-linked: 901 (2305)
   - driver index:  88a (2186)
   - uclass index:  813 (2067)
   Drop device name (not SRAM): 111 (273)


Simon Glass (9):
  dm: core: Rename dm_dump_all()
  dm: core: Sort dm subcommands
  dm: core: Fix addresses in the dm static command
  dm: core: Add documentation for the dm command
  dm: core: Switch the testbus driver to use a new struct
  dm: core: Support accessing core tags
  dm: core: Add a way to collect memory usage
  dm: core: Add a command to show driver model statistics
  dm: spl: Allow SPL to show memory usage

 cmd/dm.c                |  69 ++++--
 common/spl/spl.c        |   9 +
 doc/usage/cmd/dm.rst    | 487 ++++++++++++++++++++++++++++++++++++++++
 doc/usage/index.rst     |   1 +
 drivers/core/Kconfig    |  21 ++
 drivers/core/device.c   |  65 ++++++
 drivers/core/dump.c     |  79 ++++++-
 drivers/core/root.c     |  53 +++++
 drivers/core/tag.c      |  29 +++
 drivers/misc/test_drv.c |   6 +-
 include/dm/device.h     |  25 +++
 include/dm/root.h       |  45 ++++
 include/dm/tag.h        |  32 ++-
 include/dm/test.h       |   7 +
 include/dm/util.h       |  11 +-
 test/dm/core.c          |  91 ++++++++
 tools/dtoc/test_dtoc.py |   6 +-
 17 files changed, 1004 insertions(+), 32 deletions(-)
 create mode 100644 doc/usage/cmd/dm.rst

-- 
2.36.0.512.ge40c2bad7a-goog



More information about the U-Boot mailing list