Commit Graph

885 Commits

Author SHA1 Message Date
Lucas De Marchi a4578669ca libkmod-module: mangle the section header, not the section
When we are told to remove the "__versions" section we were mangling
that section instead of tweaking the SHF_ALLOC flag in its header.
2012-11-21 20:23:02 -02:00
Lucas De Marchi d196b8d99f libkmod-module: Remove key+value vermagic from .modinfo section
When told to force load a module, we were removing only the value of
vermagic instead of the complete entry.

Philippe De Swert (philippe.deswert@jollamobile.com) sent a patch that
was additionally mangling also the last two chars of the key
("vermagic="). Instead of creating an invalid entry in .modinfo section
like this, this patch removes the complete entry, key + value, by
zeroing the entire string.

Much thanks to Philippe who found the issue and pointed to the fix.
2012-11-21 20:22:56 -02:00
Lucas De Marchi 02c64df3c2 depmod: fix asserting mod->kmod == NULL
If we are replacing a lower priority module (due to its location), we
already created a kmod_module, but didn't open the file for reading its
symbols. This means mod->kmod won't be NULL, and this is just ok. Since
all the functions freeing stuff below the previous assert already takes
NULL into consideration, it's safe to just unref mod->kmod and let the
right thing happens.
2012-11-16 12:05:42 -02:00
Lucas De Marchi 06294621a9 depmod: fix hash lookup by relpath instead of uncrelpath
We index modules in depmod by it's uncompressed relative path, not
relative path. We didn't notice this bug before since this function is
only triggered if we release a module to be replaced by one of higher
priority.

Also fix a leftover log message referring to relpath instead of
uncrelpath.
2012-11-16 11:39:41 -02:00
Lucas De Marchi c599606f75 kmod 11 2012-11-08 02:30:21 -02:00
Lucas De Marchi 6c29e5c670 TODO: remove completed action 2012-11-08 02:01:59 -02:00
Lucas De Marchi 7c04aeee40 tools: use program_invocation_short_name provided by libc
Thanks to Dave Reisner for pointing this out.
2012-11-06 19:30:16 -02:00
Lucas De Marchi c841273721 tools: staticize functions that are now only used in log.c 2012-11-06 19:06:11 -02:00
Lucas De Marchi fcb0ce9475 tools: share function for logging 2012-11-06 19:02:23 -02:00
Lucas De Marchi 52a50fe2e5 tools: share setting up libkmod log
This also fixes a bug in "e6996c5 rmmod: route all messages to syslog if
told to" in which "+ verbose" was removed. Instead of letting verbose
add to kmod_get_log_priority(), let it be similar to the other programs
instead.
2012-11-06 18:52:09 -02:00
Lucas De Marchi 92aad74925 tools: use a single function for logging libkmod output 2012-11-06 18:35:17 -02:00
Lucas De Marchi 34e06bfb54 tools: make usage() messages go to stdout rather than stderr
When user supplied --help/-h, program should output to stdout the usage,
not to stderr. It's the expected behavior, what the user asked for,
not something to log or an error.
2012-11-06 17:32:41 -02:00
Lucas De Marchi 84341fbe01 tools: share function to convert prio to string
No change is expected in the final binary since right now only an inline
function is shared. Later we expect to share more code.
2012-11-06 17:10:57 -02:00
Lucas De Marchi 4a2e20dfb3 tools: share getting program name from argv for all tools 2012-11-06 16:55:00 -02:00
Lucas De Marchi e6996c5c30 rmmod: route all messages to syslog if told to 2012-11-05 18:32:05 -02:00
Lucas De Marchi 04c26d28be rmmod: prefer ERR over plain fprintf 2012-11-05 18:31:19 -02:00
Lucas De Marchi 9382dbf7aa modinfo: prefer ERR over plain fprintf 2012-11-05 18:31:19 -02:00
Lucas De Marchi e2f9478faf insmod: prefer ERR over plain fprintf 2012-11-05 17:59:23 -02:00
Lucas De Marchi 96b50d3623 depmod: add depmod prefix to log messages 2012-11-05 02:08:16 -02:00
Lucas De Marchi a3f16ff704 depmod: remove inline from _log 2012-11-05 02:08:16 -02:00
Lucas De Marchi 8836ff24b4 TODO: update file with tasks 2012-11-05 02:04:44 -02:00
Lucas De Marchi 61c48db360 depmod: prefer ERR and WRN over plain fprintf 2012-11-05 02:01:06 -02:00
Lucas De Marchi d9a2e15504 modprobe: use ERR() instead of fprintf(stderr, ...) 2012-11-01 13:03:02 -02:00
Lucas De Marchi d96ae03bd9 modprobe: prefix log messages to stderr with modprobe 2012-11-01 12:46:12 -02:00
Lucas De Marchi 07df56eb24 modprobe: move log function 2012-11-01 12:46:12 -02:00
Lucas De Marchi 86cc1f2328 modprobe: prefix libkmod messages to stderr with modprobe:
When we are logging to stderr we are previously relying on libkmod
sending it to the default location in case we are not asked to log to
syslog. The problem is that modprobe may be used in scripts that don't
want to log to syslog (since they are not daemons, like scripts to
generate initrd) and then it's difficult to know where the message comes
from.

This patch treats only the messages coming from libkmod.
2012-11-01 12:46:03 -02:00
Lucas De Marchi 1e947e3c87 modprobe: use prio_to_str() helper 2012-10-31 22:00:40 -02:00
Lucas De Marchi 4434d8ba36 modprobe: exit in one place 2012-10-31 21:29:54 -02:00
Lucas De Marchi e4a7352ad3 depmod: unref kmod_module once we don't need it anymore
Once we read all we need from a module, unref it so any resource taken
by it (including the mmap to access the file in libkmod) will be
dropped. This drastically reduces the number of open file descriptors
and also the memory needed, with no performance penalties. Rather,
there's a small speedup of ~2.6%.

Running depmod in a laptop with 2973 modules and comparing the number of
open file descriptors for kmod-10, before and after the last patches to
depmod (caaf438cb6 and HEAD) we have:

	Before:		2980 simultaneously open fds
	After:		7    simultaneously open fds
	kmod-10:	7    simultaneously open fds

So now we have the speedup of caching the file in kmod_module without
the drawback of increasing the number of open file descriptors.
2012-10-30 04:56:59 -02:00
Lucas De Marchi 447eed8c48 depmod: use our copy of modname instead of calling libkmod
In depmod_module_add() we already called kmod_module_get_name() and
copied the string to our struct. Use it instead of calling again and
again the libkmod function.
2012-10-30 04:11:24 -02:00
Lucas De Marchi ec587f298c depmod: cache dependency_symbol list in struct mod
The overall goal is to coalesce the accesses to a file that is the
backend of a module. This commit addresses the calls to
kmod_module_get_get_dependency_symbols(). Calling it earlier, while we
are iterating the modules allows us to free the struct kmod of each
module much sooner. We are still not freeing it since there are other
places that must be refactored first.

There's a performance penalty of ~2.5% from previous commit.
2012-10-30 04:05:53 -02:00
Lucas De Marchi 7062eca38b depmod: cache info_list in struct mod
The overall goal is to coalesce the accesses to a file that is the
backend of a module. This commit addresses the calls to
kmod_module_get_info(). Calling it earlier, while we are iterating the
modules allows us to free the struct kmod of each module much sooner. We
are still not freeing it since there are other places that must be
refactored first.

A nice side effect is that this commit reduces in ~33% the calls to
malloc(), giving a speedup of ~6% for cold caches (reproduced on only 1
laptop).
2012-10-30 03:24:25 -02:00
Lucas De Marchi b51ac407c2 depmod: do not create a hole in struct depmod 2012-10-30 02:33:14 -02:00
Lucas De Marchi caaf438cb6 build-sys: use AS_IF autoconf macro
Just for consistency with the rest.
2012-10-23 10:45:10 -02:00
Sami Kerola 5c61b1491e build-sys: require xsltproc when manpages are enabled
Before this commit the build system failed at late state with
non-helpful message when xsltproc was not available.

Making all in man
  GEN      depmod.d.5
/bin/sh: --nonet: command not found
make[2]: *** [depmod.d.5] Error 127
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
2012-10-22 16:06:04 -02:00
Lucas De Marchi 1eff942e37 libkmod: cache open file for later access
If we are accessing several times the modules and reading some sections
by sucessive calls to the functions below, we are incurring in a penalty
of having to open, parse the header and close the file. For each
function.

	- kmod_module_get_info()
	- kmod_module_get_versions()
	- kmod_module_get_symbols()
	- kmod_module_get_dependency_symbols()

These functions are particularly important to depmod. It calls all of
them, for each module. Moreover there's a huge bottleneck in the open
operation if we are using compression. Every time we open the module we
need to uncompress the file and after getting the information we need we
discard the result. This is clearly shown by profiling depmod with perf
(record + report), using compressed modules:

 64.07%  depmod  libz.so.1.2.7       [.] 0x00000000000074b8                                            ◆
 18.18%  depmod  libz.so.1.2.7       [.] crc32                                                         ▒
  2.42%  depmod  libz.so.1.2.7       [.] inflate                                                       ▒
  1.17%  depmod  libc-2.16.so        [.] __memcpy_ssse3_back                                           ▒
  0.96%  depmod  [kernel.kallsyms]   [k] copy_user_generic_string                                      ▒
  0.89%  depmod  libc-2.16.so        [.] __strcmp_sse42                                                ▒
  0.82%  depmod  [kernel.kallsyms]   [k] hrtimer_interrupt                                             ▒
  0.77%  depmod  libc-2.16.so        [.] _int_malloc                                                   ▒
  0.44%  depmod  kmod-nolib          [.] kmod_elf_get_strings                                          ▒
  0.41%  depmod  kmod-nolib          [.] kmod_elf_get_dependency_symbols                               ▒
  0.37%  depmod  kmod-nolib          [.] kmod_elf_get_section                                          ▒
  0.36%  depmod  kmod-nolib          [.] kmod_elf_get_symbols
  ...

Average of running depmod 5 times, dropping caches between them, in a
slow spinning disk:

Before:   12.25 +- 0.20
After:     8.20 +- 0.21
m-i-t:     9.62 +- 0.27

So this patch leads to an improvement of ~33% over unpatched version,
ending up with 15% speedup over module-init-tools.
2012-10-18 02:09:55 -03:00
Lucas De Marchi cc833644b2 rmmod: Deprecate --wait option
Remove --wait from usage() and give a message + sleep(10) if user is in
fact using it.
2012-10-17 18:43:17 -03:00
Leandro Pereira 1faec2c134 libkmod-hash: Plug possible memory leak when free_value is defined
Although the hash table implementation allows passing a callback function
to free a value when it is removed from the hash table, hash_del() wasn't
freeing it if it was provided. Now it does.

As a bonus, it now checks if the callback is set in hash_add() as well.
2012-10-12 12:34:27 -03:00
Lucas De Marchi 66f3228d17 libkmod: Add support for '.' in module parameter on kcmdline
Otherwise we fail to parse arguments in kernel command line like
testmodule.testparam=1.5G

Suggested-by: Selim T. Erdogan <selim@alumni.cs.utexas.edu>
2012-10-09 09:56:50 -03:00
Lucas De Marchi b0c9fc85a2 testsuite: add depmod test for modules.alias
Check if modules.alias is correctly generated from modules.order if we
have compressed modules.
2012-10-04 01:08:13 -03:00
Lucas De Marchi 3e451bfefb testsuite: allow to check generated files
This gives the test cases the ability to supply files that must be
checked after the test is run, rather than just checking stdout/stderr.

This is intended to be used with tools that generate files, like depmod.
It includes a poor's man implementation of a "check for differences in
files". Not really optimized, but it's simple enough and does what it
proposes to.
2012-10-04 01:04:52 -03:00
Lucas De Marchi 88c247f7f1 depmod: fix parsing of modules.order with compressed modules
We now index the modules by uncompressed-relative-path instead of
relative-path. This is because the file modules.order, coming from
kernel, always comes with uncompressed paths. This fixes the issue of
not sorting the aliases correctly due to paths not matching when using
compressed modules.
2012-10-03 16:29:36 -03:00
Dave Reisner c5b37dba89 build-sys: Remove --with-rootprefix option
This is a broken option that only leads to misery and incompatabilities
with other systems. Kbuild doesn't come close to supporting directories
other than /lib/modules with several targets simply failing without
hacky fixes. Simply remove the option and all traces of it, as it
doesn't make sense in today's world.
2012-10-02 00:27:31 -03:00
Lucas De Marchi 7812d88c95 build-sys: Append -Werror when testing flags
Clang doesn't treat unknown warnings flags as an error, but rather as a
warning. The result is that the detection for whic CFLAGS are supported
by this compiler will not work, since the compilation will succeed.

With this patch we now successfully detect clang doesn't support
-Wlogical-op, as opposed to previous behavior:

	checking if clang supports flag -Wlogical-op in envvar CFLAGS... no

We use this macro only for LDFLAGS and CFLAGS, so it's safe to stash
-Werror there.
2012-09-14 11:37:29 -03:00
Jan Engelhardt a7fbae0315 NEWS: language corrections 2012-09-13 21:07:13 -03:00
Dave Reisner 1a3fa1a1a5 modinfo: clarify verbiage for field shortcuts
Cleanup the punctuation and grammar in this blurb, specifically pointing
out what these are shortcuts for.
2012-09-08 14:40:37 -04:00
Dave Reisner 86bbd05319 Makefile: remove redundant flags to $(RM)
$(RM) will always expand to 'rm -f' which means we don't need to ignore
errors or pass this flag again.
2012-09-08 14:40:37 -04:00
Dave Reisner cf814054dd Define rootfs as dependency of check-am
This should actually fix the problem of ensuring that the rootfs is
created every time that 'make check' is run.
2012-09-08 14:40:37 -04:00
Dave Reisner 84afccb91d Revert "build-sys: disable jobserver for rootfs target"
This is bogus and does not work.

This reverts commit 4e7f0f204b.
2012-09-08 14:09:58 -04:00
Lucas De Marchi d642341777 testsuite: Fix double definition of 64-bits variant
If _FILE_OFFSET_BITS is defined we should not be wrapping these 64
variants, since they are macros in libc.
2012-09-07 15:12:12 -03:00