Skip to content

Commit b5c4140

Browse files
Jordan Yatesnashif
authored andcommitted
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: Jordan Yates <[email protected]>
1 parent 1660386 commit b5c4140

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

include/device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,6 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
702702
)) \
703703
DEVICE_HANDLE_SEP, \
704704
Z_DEVICE_EXTRA_HANDLES(__VA_ARGS__) \
705-
DEVICE_HANDLE_ENDS, \
706705
};
707706

708707
#define Z_DEVICE_DEFINE_INIT(node_id, dev_name, pm_control_fn) \

scripts/gen_handles.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def main():
241241
handle.dev_deps = []
242242
handle.ext_deps = []
243243
deps = handle.dev_deps
244-
while True:
244+
while hvi < len(hv):
245245
h = hv[hvi]
246246
if h == DEVICE_HANDLE_ENDS:
247247
break
@@ -302,8 +302,10 @@ def main():
302302

303303
# When CONFIG_USERSPACE is enabled the pre-built elf is
304304
# also used to get hashes that identify kernel objects by
305-
# address. We can't allow the size of any object in the
306-
# final elf to change.
305+
# address. We can't allow the size of any object in the
306+
# final elf to change. We also must make sure at least one
307+
# DEVICE_HANDLE_ENDS is inserted.
308+
assert len(hdls) < len(hs.handles), "%s no DEVICE_HANDLE_ENDS inserted" % (dev.sym.name,)
307309
while len(hdls) < len(hs.handles):
308310
hdls.append(DEVICE_HANDLE_ENDS)
309311
assert len(hdls) == len(hs.handles), "%s handle overflow" % (dev.sym.name,)

0 commit comments

Comments
 (0)