[v5,6/6] RFC: fdt: Implement "fdt-fetch" method for client interface

Message ID 20171016051653.31014-7-aik@ozlabs.ru
State New
Headers show
Series
  • fdt: Pass the resulting device tree to QEMU + related fixes
Related show

Commit Message

Alexey Kardashevskiy Oct. 16, 2017, 5:16 a.m.
The guest kernel fetches the device tree via the client interface,
calling it for every node and property, and traversing the entire tree
twice - first to build strings blob, second - to build struct blob.

On top of that there is also not so efficient implementation of
the "getprop" method - it calls slow  "get-property" which does full
search for a property.

As the result, on a 256 CPU + 256 Intel E1000 virtual devices,
the guest's flatten_device_tree() takes roughly 8.5sec.

However now we have a FDT rendering helper in SLOF which takes about 350ms
to render the FDT. This implements a client interface call to allow
the guest to read it during early boot and save time.

The produced DTB is almost the same as the guest kernel would have
produced itself - the differences are:
1. SLOF creates an empty reserved map; the guest can easily fix
it up later;
2. SLOF only reuses 40 most popular strings; the guest reuses everything
it can - on a 256CPU + 256 PCI devices guest, the difference is about
20KB for 350KB FDT blob.

Note, that the guest also ditches the "name" property just like SLOF
does:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/kernel/prom_init.c?h=v4.13#n2302

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---

If the guest tries "fdt-fetch" and SLOF does not have it, than SLOF
prints an error:

Patch

===
copying OF device tree...

fdt-fetch NOT FOUNDBuilding dt strings...
Building dt structure...
===

and the guest continues with the old method. We could suppress SLOF error
for such unlikely situation though.
---
 slof/fs/client.fs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/slof/fs/client.fs b/slof/fs/client.fs
index 7d537a6..8a7f6ac 100644
--- a/slof/fs/client.fs
+++ b/slof/fs/client.fs
@@ -308,4 +308,20 @@  ALSO client-voc DEFINITIONS
 : set-callback ( newfunc -- oldfunc )
   client-callback @ swap client-callback ! ;
 
+\ Custom method to get FDT blob
+: fdt-fetch ( buf len -- ret )
+    fdt-flatten-tree    ( buf len dtb )
+    dup >r
+    >fdth_tsize l@      ( buf len size r: dtb )
+    2dup < IF
+        ." ERROR: need " .d ." bytes, the buffer is " .d ." bytes only" cr
+        drop
+        -1
+    ELSE
+        nip r@ -rot move
+        0
+    THEN
+    r> fdt-flatten-tree-free
+;
+
 PREVIOUS DEFINITIONS