diff options
author | Brian Behlendorf <[email protected]> | 2017-08-09 15:31:08 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2017-08-09 15:31:08 -0700 |
commit | 46364cb2f35545a7fc915df9593b719a94c43a83 (patch) | |
tree | 0fb11534892c2aaaa1c1bda3c10914e718827eb0 /lib/libzpool | |
parent | 5146d802b4e371cab1d6db79bea482c056be7bf2 (diff) |
Add libtpool (thread pools)
OpenZFS provides a library called tpool which implements thread
pools for user space applications. Porting this library means
the zpool utility no longer needs to borrow the kernel mutex and
taskq interfaces from libzpool. This code was updated to use
the tpool library which behaves in a very similar fashion.
Porting libtpool was relatively straight forward and minimal
modifications were needed. The core changes were:
* Fully convert the library to use pthreads.
* Updated signal handling.
* lmalloc/lfree converted to calloc/free
* Implemented portable pthread_attr_clone() function.
Finally, update the build system such that libzpool.so is no
longer linked in to zfs(8), zpool(8), etc. All that is required
is libzfs to which the zcommon soures were added (which is the way
it always should have been). Removing the libzpool dependency
resulted in several build issues which needed to be resolved.
* Moved zfeature support to module/zcommon/zfeature_common.c
* Moved ratelimiting to to module/zfs/zfs_ratelimit.c
* Moved get_system_hostid() to lib/libspl/gethostid.c
* Removed use of cmn_err() in zcommon source
* Removed dprintf_setup() call from zpool_main.c and zfs_main.c
* Removed highbit() and lowbit()
* Removed unnecessary library dependencies from Makefiles
* Removed fletcher-4 kstat in user space
* Added sha2 support explicitly to libzfs
* Added highbit64() and lowbit64() to zpool_util.c
Reviewed-by: Tony Hutter <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #6442
Diffstat (limited to 'lib/libzpool')
-rw-r--r-- | lib/libzpool/Makefile.am | 16 | ||||
-rw-r--r-- | lib/libzpool/kernel.c | 195 |
2 files changed, 18 insertions, 193 deletions
diff --git a/lib/libzpool/Makefile.am b/lib/libzpool/Makefile.am index a8c72c98d..aed8868ae 100644 --- a/lib/libzpool/Makefile.am +++ b/lib/libzpool/Makefile.am @@ -19,13 +19,14 @@ USER_C = \ util.c KERNEL_C = \ + zfeature_common.c \ zfs_comutil.c \ zfs_deleg.c \ zfs_fletcher.c \ + zfs_fletcher_aarch64_neon.c \ + zfs_fletcher_avx512.c \ zfs_fletcher_intel.c \ zfs_fletcher_sse.c \ - zfs_fletcher_avx512.c \ - zfs_fletcher_aarch64_neon.c \ zfs_fletcher_superscalar.c \ zfs_fletcher_superscalar4.c \ zfs_namecheck.c \ @@ -115,13 +116,13 @@ KERNEL_C = \ zap_leaf.c \ zap_micro.c \ zfeature.c \ - zfeature_common.c \ zfs_byteswap.c \ zfs_debug.c \ zfs_fm.c \ zfs_fuid.c \ zfs_sa.c \ zfs_znode.c \ + zfs_ratelimit.c \ zfs_rlock.c \ zil.c \ zio.c \ @@ -136,12 +137,13 @@ nodist_libzpool_la_SOURCES = \ $(KERNEL_C) libzpool_la_LIBADD = \ - $(top_builddir)/lib/libunicode/libunicode.la \ - $(top_builddir)/lib/libuutil/libuutil.la \ + $(top_builddir)/lib/libavl/libavl.la \ + $(top_builddir)/lib/libicp/libicp.la \ $(top_builddir)/lib/libnvpair/libnvpair.la \ - $(top_builddir)/lib/libicp/libicp.la + $(top_builddir)/lib/libspl/libspl.la \ + $(top_builddir)/lib/libunicode/libunicode.la libzpool_la_LIBADD += $(ZLIB) -ldl -libzpool_la_LDFLAGS = -version-info 2:0:0 +libzpool_la_LDFLAGS = -pthread -version-info 2:0:0 EXTRA_DIST = $(USER_C) diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index e67d13c92..3fc7337e8 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -71,7 +71,7 @@ pthread_mutex_t kthread_lock = PTHREAD_MUTEX_INITIALIZER; pthread_key_t kthread_key; int kthread_nr = 0; -void +static void thread_init(void) { kthread_t *kt; @@ -90,7 +90,7 @@ thread_init(void) kthread_nr = 1; } -void +static void thread_fini(void) { kthread_t *kt = curthread; @@ -1051,149 +1051,30 @@ delay(clock_t ticks) /* * Find highest one bit set. - * Returns bit number + 1 of highest bit that is set, otherwise returns 0. - * High order bit is 31 (or 63 in _LP64 kernel). + * Returns bit number + 1 of highest bit that is set, otherwise returns 0. + * The __builtin_clzll() function is supported by both GCC and Clang. */ int highbit64(uint64_t i) { - register int h = 1; - if (i == 0) - return (0); - if (i & 0xffffffff00000000ULL) { - h += 32; i >>= 32; - } - if (i & 0xffff0000) { - h += 16; i >>= 16; - } - if (i & 0xff00) { - h += 8; i >>= 8; - } - if (i & 0xf0) { - h += 4; i >>= 4; - } - if (i & 0xc) { - h += 2; i >>= 2; - } - if (i & 0x2) { - h += 1; - } - return (h); + return (0); + + return (NBBY * sizeof (uint64_t) - __builtin_clzll(i)); } /* * Find lowest one bit set. * Returns bit number + 1 of lowest bit that is set, otherwise returns 0. - * This is basically a reimplementation of ffsll(), which is GNU specific. + * The __builtin_ffsll() function is supported by both GCC and Clang. */ int lowbit64(uint64_t i) { - register int h = 64; if (i == 0) return (0); - if (i & 0x00000000ffffffffULL) - h -= 32; - else - i >>= 32; - - if (i & 0x0000ffff) - h -= 16; - else - i >>= 16; - - if (i & 0x00ff) - h -= 8; - else - i >>= 8; - - if (i & 0x0f) - h -= 4; - else - i >>= 4; - - if (i & 0x3) - h -= 2; - else - i >>= 2; - - if (i & 0x1) - h -= 1; - - return (h); -} - -/* - * Find highest one bit set. - * Returns bit number + 1 of highest bit that is set, otherwise returns 0. - * High order bit is 31 (or 63 in _LP64 kernel). - */ -int -highbit(ulong_t i) -{ -register int h = 1; - - if (i == 0) - return (0); -#ifdef _LP64 - if (i & 0xffffffff00000000ul) { - h += 32; i >>= 32; - } -#endif - if (i & 0xffff0000) { - h += 16; i >>= 16; - } - if (i & 0xff00) { - h += 8; i >>= 8; - } - if (i & 0xf0) { - h += 4; i >>= 4; - } - if (i & 0xc) { - h += 2; i >>= 2; - } - if (i & 0x2) { - h += 1; - } - return (h); -} - -/* - * Find lowest one bit set. - * Returns bit number + 1 of lowest bit that is set, otherwise returns 0. - * Low order bit is 0. - */ -int -lowbit(ulong_t i) -{ - register int h = 1; - - if (i == 0) - return (0); - -#ifdef _LP64 - if (!(i & 0xffffffff)) { - h += 32; i >>= 32; - } -#endif - if (!(i & 0xffff)) { - h += 16; i >>= 16; - } - if (!(i & 0xff)) { - h += 8; i >>= 8; - } - if (!(i & 0xf)) { - h += 4; i >>= 4; - } - if (!(i & 0x3)) { - h += 2; i >>= 2; - } - if (!(i & 0x1)) { - h += 1; - } - return (h); + return (__builtin_ffsll(i)); } static int random_fd = -1, urandom_fd = -1; @@ -1288,64 +1169,6 @@ umem_out_of_memory(void) return (0); } -#define HOSTID_MASK 0xffffffff - -static unsigned long -get_spl_hostid(void) -{ - FILE *f; - unsigned long hostid; - char *env; - - /* - * Allow the hostid to be subverted for testing. - */ - env = getenv("ZFS_HOSTID"); - if (env) { - hostid = strtoull(env, NULL, 0); - return (hostid & HOSTID_MASK); - } - - f = fopen("/sys/module/spl/parameters/spl_hostid", "r"); - if (!f) - return (0); - - if (fscanf(f, "%lu", &hostid) != 1) - hostid = 0; - - fclose(f); - - return (hostid & HOSTID_MASK); -} - -unsigned long -get_system_hostid(void) -{ - unsigned long system_hostid = get_spl_hostid(); - /* - * We do not use the library call gethostid() because - * it generates a hostid value that the kernel is - * unaware of, if the spl_hostid module parameter has not - * been set and there is no system hostid file (e.g. - * /etc/hostid). The kernel and userspace must agree. - * See comments above hostid_read() in the SPL. - */ - if (system_hostid == 0) { - int fd, rc; - unsigned long hostid; - int hostid_size = 4; /* 4 bytes regardless of arch */ - - fd = open("/etc/hostid", O_RDONLY); - if (fd >= 0) { - rc = read(fd, &hostid, hostid_size); - if (rc > 0) - system_hostid = (hostid & HOSTID_MASK); - close(fd); - } - } - return (system_hostid); -} - void kernel_init(int mode) { |