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>
diff --git a/modutils/modutils.h b/modutils/modutils.h
index 5f059c7..2cbd144 100644
--- a/modutils/modutils.h
+++ b/modutils/modutils.h
@@ -16,6 +16,36 @@
/* linux/include/linux/module.h has 64, but this is also used
* internally for the maximum alias name length, which can be quite long */
#define MODULE_NAME_LEN 256
+#define MODULE_HASH_SIZE 256
+
+typedef struct module_entry {
+ struct module_entry *next;
+ char *name, *modname;
+ llist_t *deps;
+ IF_MODPROBE(
+ llist_t *realnames;
+ unsigned flags;
+ const char *probed_name; /* verbatim as seen on cmdline */
+ char *options; /* options from config files */
+ )
+ IF_DEPMOD(
+ llist_t *aliases;
+ llist_t *symbols;
+ struct module_entry *dnext, *dprev;
+ )
+} module_entry;
+
+typedef struct module_db {
+ module_entry *buckets[MODULE_HASH_SIZE];
+} module_db;
+
+#define moddb_foreach_module(db, module, index) \
+ for ((index) = 0; (index) < MODULE_HASH_SIZE; (index)++) \
+ for (module = (db)->buckets[index]; module; module = module->next)
+
+module_entry *moddb_get(module_db *db, const char *s) FAST_FUNC;
+module_entry *moddb_get_or_create(module_db *db, const char *s) FAST_FUNC;
+void moddb_free(module_db *db) FAST_FUNC;
void replace(char *s, char what, char with) FAST_FUNC;
char *replace_underscores(char *s) FAST_FUNC;