Commit 64355e7
committed
lib: utils/fdt: Cache CPU intc phandle->hartid lookups
CLINT/PLIC/PLMT/PLICSW probing walks `interrupts-extended` and for each
entry resolves the CPU intc phandle to a hartid via
`fdt_node_offset_by_phandle()` + `fdt_parent_offset()` + `fdt_parse_hart_id()`.
Both libfdt helpers are O(FDT_size) linear scans of the structure block,
so on an N-hart system each driver pays O(N * FDT_size), and the same
handful of intc phandles is re-resolved across multiple drivers
(PLIC + MSWI + MTIMER + ...).
Build a small cache by walking `/cpus` once: for each cpu node, record
its child intc node's phandle paired with the parsed hartid. Subsequent
lookups become an O(harts) linear scan over the cache instead of two
full FDT walks per entry. The cache is keyed on the FDT pointer so a
new fdt invalidates it implicitly.
Also move the hwirq filter ahead of the phandle resolution at each
callsite so non-matching `interrupts-extended` entries skip the lookup
entirely.
Measured on 8-hart system (release build, mtime @ 25MHz,
1M ticks = 40 ms):
sbi_irqchip_init: 15.08M -> 3.64M (~4.15x; 603 -> 146 ms)
sbi_ipi_init: 14.75M -> 2.82M (~5.23x; 590 -> 113 ms)
sbi_timer_init: 14.86M -> 2.94M (~5.06x; 594 -> 118 ms)
combined: 44.69M -> 9.39M (~4.76x; 1788 -> 376 ms)
Signed-off-by: Chen Pei <cp0613@linux.alibaba.com>1 parent 1cdfbc6 commit 64355e7
3 files changed
Lines changed: 91 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
249 | 322 | | |
250 | 323 | | |
251 | 324 | | |
| |||
968 | 1041 | | |
969 | 1042 | | |
970 | 1043 | | |
971 | | - | |
| 1044 | + | |
972 | 1045 | | |
973 | 1046 | | |
974 | 1047 | | |
| |||
1003 | 1076 | | |
1004 | 1077 | | |
1005 | 1078 | | |
1006 | | - | |
1007 | | - | |
| 1079 | + | |
1008 | 1080 | | |
1009 | 1081 | | |
1010 | | - | |
1011 | | - | |
| 1082 | + | |
1012 | 1083 | | |
1013 | 1084 | | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1024 | 1089 | | |
1025 | 1090 | | |
1026 | 1091 | | |
| |||
1056 | 1121 | | |
1057 | 1122 | | |
1058 | 1123 | | |
1059 | | - | |
1060 | | - | |
1061 | 1124 | | |
1062 | 1125 | | |
1063 | 1126 | | |
1064 | | - | |
1065 | | - | |
| 1127 | + | |
1066 | 1128 | | |
1067 | 1129 | | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
| 1130 | + | |
1075 | 1131 | | |
1076 | 1132 | | |
1077 | 1133 | | |
1078 | 1134 | | |
1079 | 1135 | | |
1080 | | - | |
1081 | | - | |
| 1136 | + | |
1082 | 1137 | | |
1083 | 1138 | | |
1084 | 1139 | | |
| |||
1112 | 1167 | | |
1113 | 1168 | | |
1114 | 1169 | | |
1115 | | - | |
1116 | | - | |
1117 | 1170 | | |
1118 | 1171 | | |
1119 | 1172 | | |
1120 | | - | |
1121 | | - | |
1122 | | - | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
| 1173 | + | |
1126 | 1174 | | |
1127 | 1175 | | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
| 1176 | + | |
1131 | 1177 | | |
1132 | 1178 | | |
1133 | 1179 | | |
1134 | 1180 | | |
1135 | 1181 | | |
1136 | | - | |
1137 | | - | |
| 1182 | + | |
1138 | 1183 | | |
1139 | 1184 | | |
1140 | 1185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 39 | + | |
46 | 40 | | |
47 | 41 | | |
48 | 42 | | |
| |||
0 commit comments