Commit Graph

875 Commits

Author SHA1 Message Date
Lucas De Marchi 15fe2128f8 scripts: Plot hashfunc timings 2013-09-20 14:35:52 -05:00
Lucas De Marchi 7862f1158b scripts/parse-depmod: use anchored text 2013-09-20 14:35:52 -05:00
Lucas De Marchi 68882b4861 scripts: Add scripts to parse hashfunc timings 2013-09-20 14:35:52 -05:00
Lucas De Marchi 65fb2dc3f7 Benchmark hash timing per key len 2013-09-20 14:35:52 -05:00
Lucas De Marchi 228750032d scripts: Add benchmark scripts and distribution logs 2013-09-20 14:33:38 -05:00
Lucas De Marchi 0690b7aa49 fixup! Add hash functions for test 2013-09-20 14:33:38 -05:00
Lucas De Marchi 54ea7920b2 Dump hashes 2013-09-20 14:33:38 -05:00
Lucas De Marchi 05f7fdacf5 Add hash functions for test 2013-09-20 14:33:38 -05:00
Lucas De Marchi 8f67ab5340 NEWS: add entries 2013-09-20 01:50:40 -05:00
Lucas De Marchi 017893f244 rmmod: remove --wait option
Let libkmod enforce KMOD_REMOVE_NOWAIT.
2013-09-20 01:42:04 -05:00
Lucas De Marchi 7ab8804448 libkmod: always pass O_NONBLOCK to kernel
Not passsing O_NONBLOCK to delete_module() is deprecated since kmod 11
and is being removed from the kernel. Force this flag in libkmod.
2013-09-20 01:37:24 -05:00
Lucas De Marchi 82fc7d986c libkmod-hash: always align n_buckets to power of 2
By aligning n_buckets to power of 2 we can turn the "bucket = hashval %
n_buckets" into a less expensive bucket = hashval & (n_buckets - 1).
This removes the DIV instruction as shown below.

Before:
	xor    %edx,%edx
	divl   0x8(%rbx)
	mov    %edx,%eax
	add    $0x1,%rax
	shl    $0x4,%rax
	add    %rbx,%rax

After:
	lea    -0x1(%rdi),%edx
	and    %edx,%eax
	add    $0x1,%rax
	shl    $0x4,%rax
	add    %rbx,%rax

With a microbenchmark, measuring the time to locate the bucket (i.e.
time_to_calculate_hashval + time_to_calculate_bucket_position) we have
the results below (time in clock cycles):

	keylen      before   after
	2-10          79.0    61.9 (-21.65%)
	11-17         81.0    64.4 (-20.48%)
	18-25         90.0    73.2 (-18.69%)
	26-32        104.7    87.0 (-16.82%)
	33-40        108.4    89.6 (-17.37%)
	41-48        111.2    91.9 (-17.38%)
	49-55        120.1   102.1 (-15.04%)
	56-63        134.4   115.7 (-13.91%)

As expected the gain is constant, regardless of the key length.
The time to clculate the hashval varies with the key length, which
explains the bigger gains for short keys.
2013-09-20 01:10:37 -05:00
Lucas De Marchi 3ba7f59e84 util: Add ALIGN_POWER2
Add static inline function to align a value to it's next power of 2.
This is commonly done by a SWAR like the one in:

http://aggregate.org/MAGIC/#Next Largest Power of 2

However a microbench shows that the implementation herer is a faster.
It doesn't really impact the possible user of this function, but it's
interesting nonetheless.

Using a x86_64 i7 Ivy Bridge it shows a ~4% advantage by using clz
instead instead of the OR and SHL chain. And this is by using a BSR
since Ivy Bridge doesn't have LZCNT. New Haswell processors have the
LZCNT instruction which can make this even better. ARM also has a CLZ
instruction so it should be better, too.

Code used to test:

	...
	v = val[i];
	t1 = get_cycles(0);
	a = ALIGN_POWER2(v);
	t1 = get_cycles(t1);

	t2 = get_cycles(0);
	v = nlpo2(v);
	t2 = get_cycles(t2);

	printf("%u\t%llu\t%llu\t%d\n", v, t1, t2, v == a);
	...

In which val is an array of 20 random unsigned int, nlop2 is the SWAR
implementation and get_cycles uses RDTSC to measure the performance.

Averages:
	ALIGN_POWER2: 	30 cycles
	nlop2:		31.4 cycles
2013-09-20 01:08:46 -05:00
Tom Gundersen 6506ddf5a3 depmod: warn on invalid devname specification
During the last merge window (3.12) a couple of modules gained devname
aliases, but without the necessary major and minor information. These were
then silently ignored when generating modules.devname.

Complain loudly to avoid such errors sneaking in undetected in the future:

    depmod: ERROR: Module 'zram' has devname (zram) but lacks major and minor information. Ignoring.
    depmod: ERROR: Module 'uhid' has devname (uhid) but lacks major and minor information. Ignoring.

Cc: Kay Sievers <kay@vrfy.org>
Cc: Lucas De Marchi <lucas.demarchi@profusion.mobi>
2013-09-10 00:49:41 -03:00
Lucas De Marchi 4c2dc16a2e build: remove check for typeof
It's used in so many places without checking, that's really pointless to
check for it in macro.h.

Also remove AC_C_TYPEOF from configure.ac since we don't use -ansi.
2013-09-06 11:31:35 -03:00
Thomas Petazzoni dc8ed09f8f Add configure check for _Static_assert()
Commit 8efede20ef ("Use _Static_assert") introduced the usage of
_Static_assert(). However, _Static_assert() is a fairly new thing,
since it was introduced only in gcc 4.6. In order to support older
compilers, this patch adds a configure.in test that checks whether
_Static_assert() is usable or not, and adjust the behavior of the
assert_cc() macro accordingly.
2013-09-06 11:06:19 -03:00
Lucas De Marchi 7e0385c47a Fix usage of readdir_r()
With readdir_r() we should be providing enough space to store the dir
name. This could be accomplished by define an union like systemd does:

	union dirent_storage {
		struct dirent de;
		uint8_t storage[offsetof(struct dirent, d_name) +
				((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))];
	};

However in all places that we use readdir_r() we have no concerns about
reentrance nor we have problems with threads. Thus use the simpler
readdir() instead.

We also remove the error logging here (that could be added back by
checking errno), but it was not adding much value so it's gone.
2013-08-29 01:33:51 -03:00
John Spencer bd4e7340bc testsuite: fix usage of reserved names
stdout and stderr are names reserved for the implementation
and musl uses them rightfully as macro - and the expansion
causes (of course) unexpected results.

rename the struct members stdout to out and stderr
to err, to be 1) compliant 2) cause compilation to
succeed.

fixes build with musl libc.
2013-08-29 01:22:20 -03:00
Lucas De Marchi 18811d22e9 kmod 15 2013-08-22 10:44:08 -03:00
Lucas De Marchi 493dc650d6 libkmod: Fix getting param with no value from kcmdline 2013-08-13 22:04:46 -03:00
Lucas De Marchi ea225b982c testsuite: Add test for parameter with no value in kcmdline
Currently we fail to add the module option if the parameter doesn't have
a value.
2013-08-13 22:03:26 -03:00
Jan Engelhardt c1170883b4 depmod: add missing "else" clause
It occurred to an openSUSE user that our mkinitrd would throw a
warning when used with kmod:

libkmod: conf_files_list: unsupported file mode /dev/null: 0x21b6

Grepping for the error message revealed that there might be a missing
"else" keyword here, since it is unusual to put an "if" directly after
closing brace.
2013-08-09 12:01:10 -03:00
Lucas De Marchi 48a4096441 shell-completion: Make options accept '=' as last char 2013-08-02 12:07:39 -03:00
Lucas De Marchi 80cf2c8f05 build: Install bash completion data 2013-07-30 14:45:21 -03:00
Lucas De Marchi ec6d026f26 shell-completion: Add kmod static-nodes 2013-07-30 14:45:21 -03:00
Lucas De Marchi ac6573aab4 shell-completion: Add initial completion for kmod
Based on journalctl and udevadm from systemd and adapted to kmod needs.
2013-07-30 14:45:18 -03:00
Lucas De Marchi b3e19ce92e NEWS: Add entries 2013-07-17 02:31:50 -03:00
Lucas De Marchi cd923111c6 README: Move items from TODO
Put the differences between kmod and module-init-tools in the README
file so it's more visible.
2013-07-17 02:31:27 -03:00
Tom Gundersen 232bf4d863 static-nodes: create parent directories of output file
Allows us to drop call to "mkdir -p" from the systemd service file.
2013-07-15 12:46:12 -03:00
Lucas De Marchi fa6fc9f0b8 util: Add mkdir_parents()
Like mkdir_p, but discards the leaf, creating the parent directories.
2013-07-15 12:45:35 -03:00
Lucas De Marchi c493b93750 util: Add len arg to mkdir_p() 2013-07-15 12:44:33 -03:00
Tom Gundersen ae17710117 static-nodes: don't fail if modules.devname not found
In containers/VM's/initrd one might not have installed any modules and
accompanying modules.devname Don't fail if this is the case, just warn.

When used in systemd this means we don't get a failing unit on booting
containers.
2013-07-15 12:44:33 -03:00
Lucas De Marchi 85d02ebea3 util: Add mkdir_p implementation from testsuite 2013-07-15 12:44:33 -03:00
Lucas De Marchi 7980eaf0ec testsuite: Fix mkdir_p corner cases
- Fix infinite loop when path is relative
 - Fix not considering EEXIST as a success
 - General refactor to mkdir_p so it never calls mkdir for an existing
   dir (given no one creates it from outside)
2013-07-15 12:44:26 -03:00
Lucas De Marchi 83b855a6ed Use "-internal" suffix instead of "-private" 2013-07-04 16:13:11 -03:00
Lucas De Marchi b6adccd6ff tools: Do not link dynamically with libkmod
Instead of linking dynamically with libkmod, use libkmod-private.la. We
disallow creating a static libkmod because we can't hide symbols there
and it cause problems with external programs. However this should not
prevent users that are only interested in the tools we provide not being
able to ship only them keeping the library alone.

Other projects also do this to allow our tools to use certain functions
that should not be used outside of the project.
2013-07-04 16:08:10 -03:00
Lucas De Marchi 3b38c7fcb5 kmod 14 2013-07-03 12:42:04 -03:00
Lucas De Marchi 9de9e07da6 tools: Use test/kmod instead of kmod-nolib
The reason to have a kmod-nolib binary is that we need to call kmod on
test cases (or a symlink to it) and for testing things in tree. Since
we are using libtool if we are dinamically linking to libkmod what we
end up having is a shell script that (depending on the version *)
changes argv[0] to contain an "lt-" prefix. Since this screws with our
compat stuff, we had a kmod-nolib that links statically.

This all workaround works fine iff we are using one of the compat
commands, i.e. we are using the symlinks insmod, rmmod, modprobe, etc.
However if we are actually trying the kmod binary, this doesn't work
because we can't create a kmod symlink since there's already a kmod
binary.

So, completely give up on libtool fixing their mess. Now we create a
tool/test/ directory and the symlinks and kmod is put there.

* http://lists.gnu.org/archive/html/bug-libtool/2011-12/msg00023.html
2013-07-02 21:15:54 -03:00
Lucas De Marchi a5cbde4bce static-nodes: Better -f option description 2013-07-01 23:02:08 -03:00
Lucas De Marchi b7016153ec build-sys: do not allow --enable static
Do the same as done in systemd by Cristian Rodríguez
<crrodriguez@opensuse.org>. We use private symbols, not namespaced. So
don't pretend we support static linking.
2013-06-06 11:48:38 -03:00
Lucas De Marchi 4b9cab2872 Add travis-ci config file
Experiment with a build bot.
2013-05-11 01:32:31 -03:00
Jan Luebbe 5eac795b8b libkmod: Avoid calling syscall() with -1
At least in qemu 1.4.1 for vexpress/arm-cortexa9, this resulted in an
illegal instruction error. Solve that by returning an error when
__NR_finit_module is -1.
2013-05-11 00:54:15 -03:00
Lucas De Marchi 03f7dfb868 Revert "missing: Don't call syscall() with syscallno == -1"
This reverts commit 38829712e5.  It fixes
the problem, but it breaks the testsuite for those who don't have
__NR_finit_module. The testsuite would have to make the same check.

Instead, I'm reverting this change and I'm going to apply another patch
from Jan Luebbe who got this right from the beginning.
2013-05-11 00:50:32 -03:00
Chengwei Yang d7152f6282 Add document for exported enums
There are several exported enums by libkmod without document, this patch
mainly added documentation for below enums like the way kmod_resources
be documented in.
* kmod_index
* kmod_remove
* kmod_insert
* kmod_probe
* kmod_filter
* kmod_module_initstate

This is not the best way to document these exported enums, however, it's
the simple way due to gtkdoc limits. It doesn't support export plain
enum like below: see https://bugzilla.gnome.org/show_bug.cgi?id=657444
---------8<-------head.h--------------8<-----------
...
enum foo {
    ...
};
...
---------8<-------end of head.h-------8<-----------
---------8<-------source.c------------8<-----------
...
/**
 * document for foo here
 */
...
typedef enum foo foo;
...
---------8<-------end of source.c-----8<----------
2013-05-04 18:57:43 -03:00
Chengwei Yang 491c490204 Several minor fixes for documentation 2013-05-04 10:42:56 -03:00
Johannes Berg c010f02030 modprobe: don't check refcount with remove command
The modprobe.d (5) documentation for the "install" command
states that you could specify

install fred /sbin/modprobe barney; /sbin/modprobe --ignore-install fred

This makes some sense, but then the loading of "barney" is
hidden from the user who did only "modprobe fred". Thus,
it seems it should be possible to be able to unload the
"fred" module with "modprobe -r fred" by configuring the
"barney" module to also be removed:

remove fred /sbin/rmmod barney fred

(or similar.)

Make this possible by not checking the refcount when an
unload command was configured.

Reported-by: David Spinadel <david.spinadel@intel.com>
2013-05-02 23:30:44 -03:00
Lucas De Marchi 38829712e5 missing: Don't call syscall() with syscallno == -1
Reported-by: Jean-Francis Roy <jeanfrancis@funtoo.org>
Reported-by: Jan Luebbe <jlu@pengutronix.de>
2013-05-02 17:02:52 -03:00
Lucas De Marchi 1114e781ad Fix coding style
Either with space or without, not a mix of both.
2013-04-30 12:37:43 -03:00
Lucas De Marchi e975fd3115 TODO: Add some entries 2013-04-30 12:37:43 -03:00
Lucas De Marchi 681bf89afd libkmod-index: Return early if readroot failed 2013-04-23 21:26:09 -03:00