Commit b5c4140a authored by Jordan Yates's avatar Jordan Yates Committed by Anas Nashif
Browse files

device: optimize handles array



Optimize the handles array by making the following observations:
 * The devicetree ordinal at index 0 in pass1 is discarded by
   gen_handles.py, and therefore does not appear in the pass2 array.
 * gen_handles.py does not need `DEVICE_HANDLE_ENDS` to determine the
   end of the handle array, as that information is present in the .elf.

Therefore, instead of replacing the devicetree ordinal with an
additional `DEVICE_HANDLE_ENDS` at the end (to preserve lengths), we
can simply move the ordinal to the end and have it be the original
`DEVICE_HANDLE_ENDS` symbol. This reduces the size of the array by
one handle per device (2 bytes).

Signed-off-by: default avatarJordan Yates <jordan.yates@data61.csiro.au>
parent 1660386f
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -702,7 +702,6 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
		))							\
			DEVICE_HANDLE_SEP,				\
			Z_DEVICE_EXTRA_HANDLES(__VA_ARGS__)		\
			DEVICE_HANDLE_ENDS,				\
		};

#define Z_DEVICE_DEFINE_INIT(node_id, dev_name, pm_control_fn)		\
+5 −3
Original line number Diff line number Diff line
@@ -241,7 +241,7 @@ def main():
        handle.dev_deps = []
        handle.ext_deps = []
        deps = handle.dev_deps
        while True:
        while hvi < len(hv):
            h = hv[hvi]
            if h == DEVICE_HANDLE_ENDS:
                break
@@ -303,7 +303,9 @@ def main():
            # When CONFIG_USERSPACE is enabled the pre-built elf is
            # also used to get hashes that identify kernel objects by
            # address. We can't allow the size of any object in the
            # final elf to change.
            # final elf to change. We also must make sure at least one
            # DEVICE_HANDLE_ENDS is inserted.
            assert len(hdls) < len(hs.handles), "%s no DEVICE_HANDLE_ENDS inserted" % (dev.sym.name,)
            while len(hdls) < len(hs.handles):
                hdls.append(DEVICE_HANDLE_ENDS)
            assert len(hdls) == len(hs.handles), "%s handle overflow" % (dev.sym.name,)