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>
This commit is contained in:
Timo Teräs 2015-11-05 18:54:55 +01:00 committed by Denys Vlasenko
parent 34adecc2b0
commit 48dc80bbba
4 changed files with 113 additions and 120 deletions

View file

@ -16,6 +16,57 @@ extern int delete_module(const char *module, unsigned int flags);
# define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
#endif
static module_entry *helper_get_module(module_db *db, const char *module, int create)
{
char modname[MODULE_NAME_LEN];
struct module_entry *e;
unsigned i, hash;
filename2modname(module, modname);
hash = 0;
for (i = 0; modname[i]; i++)
hash = ((hash << 5) + hash) + modname[i];
hash %= MODULE_HASH_SIZE;
for (e = db->buckets[hash]; e; e = e->next)
if (strcmp(e->modname, modname) == 0)
return e;
if (!create)
return NULL;
e = xzalloc(sizeof(*e));
e->modname = xstrdup(modname);
e->next = db->buckets[hash];
db->buckets[hash] = e;
e->dnext = e->dprev = e;
return e;
}
module_entry* FAST_FUNC moddb_get(module_db *db, const char *module)
{
return helper_get_module(db, module, 0);
}
module_entry* FAST_FUNC moddb_get_or_create(module_db *db, const char *module)
{
return helper_get_module(db, module, 1);
}
void FAST_FUNC moddb_free(module_db *db)
{
module_entry *e, *n;
unsigned i;
for (i = 0; i < MODULE_HASH_SIZE; i++) {
for (e = db->buckets[i]; e; e = n) {
n = e->next;
free(e->name);
free(e->modname);
free(e);
}
}
}
void FAST_FUNC replace(char *s, char what, char with)
{
while (*s) {