diff options
author | Timo Teräs <timo.teras@iki.fi> | 2015-11-05 18:54:55 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-11-05 18:54:55 +0100 |
commit | 48dc80bbba994eee24ed94ae4532a1cce76d7cb7 (patch) | |
tree | 051e7aacf5538ffc07310bb4261a693a047311d2 /modutils/modutils.c | |
parent | 34adecc2b049f6941c5e075ffb58fe2183823da3 (diff) | |
download | busybox-w32-48dc80bbba994eee24ed94ae4532a1cce76d7cb7.tar.gz busybox-w32-48dc80bbba994eee24ed94ae4532a1cce76d7cb7.tar.bz2 busybox-w32-48dc80bbba994eee24ed94ae4532a1cce76d7cb7.zip |
modutils: merge module_entry and module_info to common
This merges the in-memory module info structures of modprobe
and depmod. This allows sharing hashing by modulename code
improving depmod runtime with almost factor of 2x.
function old new delta
get_or_add_modentry - 17 +17
do_modprobe 590 601 +11
moddb_get_or_create - 10 +10
load_modules_dep 195 205 +10
moddb_get - 7 +7
add_probe 81 78 -3
modprobe_main 721 714 -7
depmod_main 553 543 -10
config_file_action 434 421 -13
helper_get_module 160 144 -16
parse_module 343 320 -23
order_dep_list 105 82 -23
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/7 up/down: 55/-95) Total: -40 bytes
Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'modutils/modutils.c')
-rw-r--r-- | modutils/modutils.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/modutils/modutils.c b/modutils/modutils.c index ef4134af5..8e9eef72d 100644 --- a/modutils/modutils.c +++ b/modutils/modutils.c | |||
@@ -16,6 +16,57 @@ extern int delete_module(const char *module, unsigned int flags); | |||
16 | # define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) | 16 | # define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags) |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | static module_entry *helper_get_module(module_db *db, const char *module, int create) | ||
20 | { | ||
21 | char modname[MODULE_NAME_LEN]; | ||
22 | struct module_entry *e; | ||
23 | unsigned i, hash; | ||
24 | |||
25 | filename2modname(module, modname); | ||
26 | |||
27 | hash = 0; | ||
28 | for (i = 0; modname[i]; i++) | ||
29 | hash = ((hash << 5) + hash) + modname[i]; | ||
30 | hash %= MODULE_HASH_SIZE; | ||
31 | |||
32 | for (e = db->buckets[hash]; e; e = e->next) | ||
33 | if (strcmp(e->modname, modname) == 0) | ||
34 | return e; | ||
35 | if (!create) | ||
36 | return NULL; | ||
37 | |||
38 | e = xzalloc(sizeof(*e)); | ||
39 | e->modname = xstrdup(modname); | ||
40 | e->next = db->buckets[hash]; | ||
41 | db->buckets[hash] = e; | ||
42 | e->dnext = e->dprev = e; | ||
43 | |||
44 | return e; | ||
45 | } | ||
46 | module_entry* FAST_FUNC moddb_get(module_db *db, const char *module) | ||
47 | { | ||
48 | return helper_get_module(db, module, 0); | ||
49 | } | ||
50 | module_entry* FAST_FUNC moddb_get_or_create(module_db *db, const char *module) | ||
51 | { | ||
52 | return helper_get_module(db, module, 1); | ||
53 | } | ||
54 | |||
55 | void FAST_FUNC moddb_free(module_db *db) | ||
56 | { | ||
57 | module_entry *e, *n; | ||
58 | unsigned i; | ||
59 | |||
60 | for (i = 0; i < MODULE_HASH_SIZE; i++) { | ||
61 | for (e = db->buckets[i]; e; e = n) { | ||
62 | n = e->next; | ||
63 | free(e->name); | ||
64 | free(e->modname); | ||
65 | free(e); | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | |||
19 | void FAST_FUNC replace(char *s, char what, char with) | 70 | void FAST_FUNC replace(char *s, char what, char with) |
20 | { | 71 | { |
21 | while (*s) { | 72 | while (*s) { |