diff options
author | Sam Hurst <shurst@google.com> | 2016-10-31 09:04:09 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-11-23 15:36:00 -0800 |
commit | c459c8278ed2dc84100693eab93389a0df9429bd (patch) | |
tree | f5196db2f5f97c98c1494ee6ab37535cb7286ed7 /common | |
parent | e4609af63c3b2884b4dd89e04175c7fbc2abab21 (diff) | |
download | chrome-ec-c459c8278ed2dc84100693eab93389a0df9429bd.tar.gz |
ec: Improve efficiency of host command dispatcher
Use binary search in host command lookup dispatcher
BUG=chrome-os-partner:570895
TEST=manual testing on kevin
- Kevin boots
- ectool hello
make buildall -j
Verify *.smap hcmds section is sorted:
100bca94 R __hcmds
100bca94 R __host_cmd_0x0000
100bcaa0 R __host_cmd_0x0001
100bcaac R __host_cmd_0x0002
100bcab8 R __host_cmd_0x0003
100bcac4 R __host_cmd_0x0004
100bcad0 R __host_cmd_0x0005
100bcadc R __host_cmd_0x0006
100bcae8 R __host_cmd_0x0007
100bcaf4 R __host_cmd_0x0008
100bcb00 R __host_cmd_0x0009
100bcb0c R __host_cmd_0x000a
100bcb18 R __host_cmd_0x000b
100bcb24 R __host_cmd_0x000d
100bcb30 R __host_cmd_0x0010
100bcb3c R __host_cmd_0x0011
100bcb48 R __host_cmd_0x0012
100bcb54 R __host_cmd_0x0013
100bcb60 R __host_cmd_0x0015
100bcb6c R __host_cmd_0x0016
100bcb78 R __host_cmd_0x0017
100bcb84 R __host_cmd_0x0025
100bcb90 R __host_cmd_0x0026
100bcb9c R __host_cmd_0x0029
100bcba8 R __host_cmd_0x002a
100bcbb4 R __host_cmd_0x002b
100bcbc0 R __host_cmd_0x002c
100bcbcc R __host_cmd_0x0044
100bcbd8 R __host_cmd_0x0045
100bcbe4 R __host_cmd_0x0046
100bcbf0 R __host_cmd_0x0047
100bcbfc R __host_cmd_0x0061
100bcc08 R __host_cmd_0x0062
100bcc14 R __host_cmd_0x0064
100bcc20 R __host_cmd_0x0065
100bcc2c R __host_cmd_0x0067
100bcc38 R __host_cmd_0x0087
100bcc44 R __host_cmd_0x008c
100bcc50 R __host_cmd_0x008d
100bcc5c R __host_cmd_0x008f
100bcc68 R __host_cmd_0x0092
100bcc74 R __host_cmd_0x0093
100bcc80 R __host_cmd_0x0096
100bcc8c R __host_cmd_0x0097
100bcc98 R __host_cmd_0x0098
100bcca4 R __host_cmd_0x0099
100bccb0 R __host_cmd_0x009e
100bccbc R __host_cmd_0x00a0
100bccc8 R __host_cmd_0x00a1
100bccd4 R __host_cmd_0x00a8
100bcce0 R __host_cmd_0x00a9
100bccec R __host_cmd_0x00b6
100bccf8 R __host_cmd_0x00b7
100bcd04 R __host_cmd_0x00d2
100bcd10 R __host_cmd_0x00d3
100bcd1c R __host_cmd_0x00db
100bcd28 R __host_cmd_0x0101
100bcd34 R __host_cmd_0x0102
100bcd40 R __host_cmd_0x0103
100bcd4c R __host_cmd_0x0104
100bcd58 R __host_cmd_0x0110
100bcd64 R __host_cmd_0x0111
100bcd70 R __host_cmd_0x0112
100bcd7c R __host_cmd_0x0113
100bcd88 R __host_cmd_0x0114
100bcd94 R __host_cmd_0x0115
100bcda0 R __host_cmd_0x0116
100bcdac R __host_cmd_0x0117
100bcdb8 R __host_cmd_0x0118
100bcdc4 R __host_cmd_0x011a
100bcdd0 R __evt_src_EC_MKBP_EVENT_KEY_MATRIX
100bcdd0 R __hcmds_end
BRANCH=none
Change-Id: Ideb9951b318763f71915e2c4e5052f4b4bfab173
Reviewed-on: https://chromium-review.googlesource.com/405528
Commit-Ready: Sam Hurst <shurst@google.com>
Tested-by: Sam Hurst <shurst@google.com>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/host_command.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/common/host_command.c b/common/host_command.c index 3034419503..6a4b491936 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -363,6 +363,30 @@ host_packet_bad: */ static const struct host_command *find_host_command(int command) { +#ifdef CONFIG_HOSTCMD_SECTION_SORTED + const struct host_command *l, *r, *m; + uint32_t num, hc_size; + +/* Use binary search to locate host command handler */ + l = __hcmds; + r = __hcmds_end; + hc_size = sizeof(struct host_command); + + while (1) { + if (l > r) + return NULL; + + num = ((intptr_t)r - (intptr_t)l) / hc_size; + m = l + (num / 2); + + if (m->command < command) + l = m + 1; + else if (m->command > command) + r = m - 1; + else + return m; + } +#else const struct host_command *cmd; for (cmd = __hcmds; cmd < __hcmds_end; cmd++) { @@ -371,6 +395,7 @@ static const struct host_command *find_host_command(int command) } return NULL; +#endif } static void host_command_init(void) |