[SLOF] [PATCH slof v3 5/5] fdt: Pass the resulting device tree to QEMU
Segher Boessenkool
segher at kernel.crashing.org
Thu Oct 5 03:40:48 AEDT 2017
On Tue, Oct 03, 2017 at 11:13:51PM +1100, Alexey Kardashevskiy wrote:
> > +: fdt-properties ( phandle -- )
> > + dup encode-int s" phandle" fdt-prop
> > + >r
> > + s" "
> > + BEGIN
> > + r@ next-property
> > + WHILE
> > + 2dup
> > + 2dup r@ get-property
> > + not IF
> > + 2swap fdt-prop
> > + THEN
> > + REPEAT
> > + r>
> > + drop
> > +;
>
>
> Doing as below still works but brings the time for the huge guest (256
> CPUs, 256 E1000) down to 366ms as it does not search for properties every
> time but just iterates through them, I picked this from ".properties". So
> we are back in business :) But I'd really love someone to explain me how
> that works as I am unable to parse this kind of internals myself... Segher,
> please.
I'll try.
: link>name cell+ ;
: name>string char+ count ;
A wordlist is a linked list, offset 0 of each record is a pointer to
the next. At offset 1 cell is the per-name data: a flags byte, a byte
that is the number of chars in the name, and the actual chars.
Well. The wordlists are themselves a linked list; offset 0 holds the
address of the next wordlist, and offset 1 cell holds the address of
the first name record. Like:
STRUCT
cell FIELD wid>next
cell FIELD wid>names \ the head of the list of name records
END-STRUCT
STRUCT
cell FIELD name>next
char FIELD name>flags
char FIELD name>count
0 FIELD name>chars
END-STRUCT
The default (find) implementation (from engine.in):
: ((find)) ( str len head -- 0 | link )
BEGIN dup WHILE
>r 2dup r@ link>name name>string string=ci IF \ if found the name:
2drop r> EXIT THEN \ return a pointer to this name record
r> @ \ follow the linked list
REPEAT
3drop false ; \ nope, not found
> : fdt-properties ( phandle -- )
> dup encode-int s" phandle" fdt-prop
>
> node>properties @ cell+ @
"properties" in a node struct is a wordlist, which is just a pointer
to the first name record in that wordlist.
> BEGIN
> dup
> WHILE
> dup
>
> link>
: link> link>name name> ;
where name> moves to after the name (cell-aligned):
: name> char+ dup c@ 1+ chars+ aligned ;
(skip the flags byte, get the char count byte, skip that many bytes
(and the count byte itself), align).
> dup >name name>string 2>r
> execute
> 2r>
> fdt-prop
>name tries to find the name, given an xt. You do not need it here.
>
> @
> REPEAT
>
> drop
> ;
So maybe more like
: fdt-property ( link -- )
dup link> execute rot link>name name>string fdt-prop ;
: fdt-properties ( phandle -- )
dup encode-int s" phandle" fdt-prop
node>properties @ cell+ @ BEGIN dup WHILE dup fdt-property @ REPEAT drop ;
(and maybe better names? Something that makes clear it is copying
properties to the flat tree).
Segher
More information about the SLOF
mailing list