#include <common.h>
#include <command.h>
+#include <dm/root.h>
#include <dm/util.h>
static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc,
return 0;
}
+#if CONFIG_IS_ENABLED(DM_STATS)
+static int do_dm_dump_mem(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct dm_stats mem;
+
+ dm_get_mem(&mem);
+ dm_dump_mem(&mem);
+
+ return 0;
+}
+#endif /* DM_STATS */
+
static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag,
int argc, char * const argv[])
{
return 0;
}
+#if CONFIG_IS_ENABLED(DM_STATS)
+#define DM_MEM_HELP "dm mem Provide a summary of memory usage\n"
+#define DM_MEM U_BOOT_SUBCMD_MKENT(mem, 1, 1, do_dm_dump_mem),
+#else
+#define DM_MEM_HELP
+#define DM_MEM
+#endif
+
#if CONFIG_IS_ENABLED(SYS_LONGHELP)
static char dm_help_text[] =
"compat Dump list of drivers with compatibility strings\n"
"dm devres Dump list of device resources for each device\n"
"dm drivers Dump list of drivers with uclass and instances\n"
+ DM_MEM_HELP
"dm static Dump list of drivers with static platform data\n"
"dn tree Dump tree of driver model devices ('*' = activated)\n"
"dm uclass Dump list of instances for each uclass"
U_BOOT_SUBCMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat),
U_BOOT_SUBCMD_MKENT(devres, 1, 1, do_dm_dump_devres),
U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_dm_dump_drivers),
+ DM_MEM
U_BOOT_SUBCMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info),
U_BOOT_SUBCMD_MKENT(tree, 1, 1, do_dm_dump_tree),
U_BOOT_SUBCMD_MKENT(uclass, 1, 1, do_dm_dump_uclass));
for (entry = drv; entry != drv + n_ents; entry++)
printf("%-25.25s %p\n", entry->name, entry->plat);
}
+
+void dm_dump_mem(struct dm_stats *stats)
+{
+ int total, total_delta;
+ int i;
+
+ /* Support SPL printf() */
+ printf("Struct sizes: udevice %x, driver %x, uclass %x, uc_driver %x\n",
+ (int)sizeof(struct udevice), (int)sizeof(struct driver),
+ (int)sizeof(struct uclass), (int)sizeof(struct uclass_driver));
+ printf("Memory: device %x:%x, device names %x, uclass %x:%x\n",
+ stats->dev_count, stats->dev_size, stats->dev_name_size,
+ stats->uc_count, stats->uc_size);
+ printf("\n");
+ printf("%-15s %5s %5s %5s %5s %5s\n", "Attached type", "Count",
+ "Size", "Cur", "Tags", "Save");
+ printf("%-15s %5s %5s %5s %5s %5s\n", "---------------", "-----",
+ "-----", "-----", "-----", "-----");
+ total_delta = 0;
+ for (i = 0; i < DM_TAG_ATTACH_COUNT; i++) {
+ int cur_size, new_size, delta;
+
+ cur_size = stats->dev_count * sizeof(struct udevice);
+ new_size = stats->dev_count * (sizeof(struct udevice) -
+ sizeof(void *));
+ /*
+ * Let's assume we can fit each dmtag_node into 32 bits. We can
+ * limit the 'tiny tags' feature to SPL with
+ * CONFIG_SPL_SYS_MALLOC_F_LEN <= 64KB, so needing 14 bits to
+ * point to anything in that region (with 4-byte alignment).
+ * So:
+ * 4 bits for tag
+ * 14 bits for offset of dev
+ * 14 bits for offset of data
+ */
+ new_size += stats->attach_count[i] * sizeof(u32);
+ delta = cur_size - new_size;
+ total_delta += delta;
+ printf("%-16s %5x %6x %6x %6x %6x (%d)\n", tag_get_name(i),
+ stats->attach_count[i], stats->attach_size[i],
+ cur_size, new_size, delta > 0 ? delta : 0, delta);
+ }
+ printf("%-16s %5x %6x\n", "uclass", stats->uc_attach_count,
+ stats->uc_attach_size);
+ printf("%-16s %5x %6x %5s %5s %6x (%d)\n", "Attached total",
+ stats->attach_count_total + stats->uc_attach_count,
+ stats->attach_size_total + stats->uc_attach_size, "", "",
+ total_delta > 0 ? total_delta : 0, total_delta);
+ printf("%-16s %5x %6x\n", "tags", stats->tag_count, stats->tag_size);
+ printf("\n");
+ printf("Total size: %x (%d)\n", stats->total_size, stats->total_size);
+ printf("\n");
+
+ total = stats->total_size;
+ total -= total_delta;
+ printf("With tags: %x (%d)\n", total, total);
+
+ /* Use singly linked lists in struct udevice (3 nodes in each) */
+ total -= sizeof(void *) * 3 * stats->dev_count;
+ printf("- singly-linked: %x (%d)\n", total, total);
+
+ /* Use an index into the struct_driver list instead of a pointer */
+ total = total + stats->dev_count * (1 - sizeof(void *));
+ printf("- driver index: %x (%d)\n", total, total);
+
+ /* Same with the uclass */
+ total = total + stats->dev_count * (1 - sizeof(void *));
+ printf("- uclass index: %x (%d)\n", total, total);
+
+ /* Drop the device name */
+ printf("Drop device name (not SRAM): %x (%d)\n", stats->dev_name_size,
+ stats->dev_name_size);
+}