aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2018-01-11 22:01:17 +0200
committerMichael S. Tsirkin <mst@redhat.com>2018-01-11 22:03:50 +0200
commitacc95bc85036c443da8bf7159a77edf9f00dcd80 (patch)
tree21965c6e60a2e29664b7685e52feacdb6a86e0bd /util
parent880b1ffe6ec2f0ae25cc4175716227ad275e8b8a (diff)
parent997eba28a3ed5400a80f754bf3a1c8044b75b9ff (diff)
downloadqemu-acc95bc85036c443da8bf7159a77edf9f00dcd80.zip
qemu-acc95bc85036c443da8bf7159a77edf9f00dcd80.tar.gz
qemu-acc95bc85036c443da8bf7159a77edf9f00dcd80.tar.bz2
Merge remote-tracking branch 'origin/master' into HEAD
Resolve conflicts around apb. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/hbitmap.c39
-rw-r--r--util/memfd.c4
-rw-r--r--util/mmap-alloc.c8
-rw-r--r--util/qemu-coroutine-sleep.c4
-rw-r--r--util/qemu-option.c36
-rw-r--r--util/qemu-sockets.c32
-rw-r--r--util/qemu-thread-posix.c59
-rw-r--r--util/rcu.c6
-rw-r--r--util/uuid.c7
9 files changed, 110 insertions, 85 deletions
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 2f9d0fd..289778a 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -188,6 +188,45 @@ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap *hb, uint64_t first)
}
}
+int64_t hbitmap_next_zero(const HBitmap *hb, uint64_t start)
+{
+ size_t pos = (start >> hb->granularity) >> BITS_PER_LEVEL;
+ unsigned long *last_lev = hb->levels[HBITMAP_LEVELS - 1];
+ uint64_t sz = hb->sizes[HBITMAP_LEVELS - 1];
+ unsigned long cur = last_lev[pos];
+ unsigned start_bit_offset =
+ (start >> hb->granularity) & (BITS_PER_LONG - 1);
+ int64_t res;
+
+ cur |= (1UL << start_bit_offset) - 1;
+ assert((start >> hb->granularity) < hb->size);
+
+ if (cur == (unsigned long)-1) {
+ do {
+ pos++;
+ } while (pos < sz && last_lev[pos] == (unsigned long)-1);
+
+ if (pos >= sz) {
+ return -1;
+ }
+
+ cur = last_lev[pos];
+ }
+
+ res = (pos << BITS_PER_LEVEL) + ctol(cur);
+ if (res >= hb->size) {
+ return -1;
+ }
+
+ res = res << hb->granularity;
+ if (res < start) {
+ assert(((start - res) >> hb->granularity) == 0);
+ return start;
+ }
+
+ return res;
+}
+
bool hbitmap_empty(const HBitmap *hb)
{
return hb->count == 0;
diff --git a/util/memfd.c b/util/memfd.c
index 4571d1a..412e94a 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -31,9 +31,7 @@
#include "qemu/memfd.h"
-#ifdef CONFIG_MEMFD
-#include <sys/memfd.h>
-#elif defined CONFIG_LINUX
+#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
#include <sys/syscall.h>
#include <asm/unistd.h>
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 3ec029a..2fd8cbc 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -35,6 +35,10 @@ size_t qemu_fd_getpagesize(int fd)
return fs.f_bsize;
}
}
+#ifdef __sparc__
+ /* SPARC Linux needs greater alignment than the pagesize */
+ return QEMU_VMALLOC_ALIGN;
+#endif
#endif
return getpagesize();
@@ -60,6 +64,10 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
/* It's hugepage, return the huge page size */
return fs.f_bsize;
}
+#ifdef __sparc__
+ /* SPARC Linux needs greater alignment than the pagesize */
+ return QEMU_VMALLOC_ALIGN;
+#endif
#endif
return getpagesize();
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
index 254349c..afb678f 100644
--- a/util/qemu-coroutine-sleep.c
+++ b/util/qemu-coroutine-sleep.c
@@ -31,9 +31,9 @@ static void co_sleep_cb(void *opaque)
aio_co_wake(sleep_cb->co);
}
-void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,
- int64_t ns)
+void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
{
+ AioContext *ctx = qemu_get_current_aio_context();
CoSleepCB sleep_cb = {
.co = qemu_coroutine_self(),
};
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 9b1dc80..553d3dc 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -91,40 +91,6 @@ const char *get_opt_value(char *buf, int buf_size, const char *p)
return p;
}
-int get_next_param_value(char *buf, int buf_size,
- const char *tag, const char **pstr)
-{
- const char *p;
- char option[128];
-
- p = *pstr;
- for(;;) {
- p = get_opt_name(option, sizeof(option), p, '=');
- if (*p != '=')
- break;
- p++;
- if (!strcmp(tag, option)) {
- *pstr = get_opt_value(buf, buf_size, p);
- if (**pstr == ',') {
- (*pstr)++;
- }
- return strlen(buf);
- } else {
- p = get_opt_value(NULL, 0, p);
- }
- if (*p != ',')
- break;
- p++;
- }
- return 0;
-}
-
-int get_param_value(char *buf, int buf_size,
- const char *tag, const char *str)
-{
- return get_next_param_value(buf, buf_size, tag, &str);
-}
-
static void parse_option_bool(const char *name, const char *value, bool *ret,
Error **errp)
{
@@ -766,7 +732,7 @@ void qemu_opts_print(QemuOpts *opts, const char *separator)
}
for (; desc && desc->name; desc++) {
const char *value;
- QemuOpt *opt = qemu_opt_find(opts, desc->name);
+ opt = qemu_opt_find(opts, desc->name);
value = opt ? opt->str : desc->def_value_str;
if (!value) {
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index a1cf47e..d6a1e17 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -26,7 +26,6 @@
#include "qapi/error.h"
#include "qemu/sockets.h"
#include "qemu/main-loop.h"
-#include "qapi/clone-visitor.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/qobject-output-visitor.h"
#include "qapi-visit.h"
@@ -199,7 +198,6 @@ static int try_bind(int socket, InetSocketAddress *saddr, struct addrinfo *e)
static int inet_listen_saddr(InetSocketAddress *saddr,
int port_offset,
- bool update_addr,
Error **errp)
{
struct addrinfo ai,*res,*e;
@@ -327,15 +325,6 @@ listen_failed:
return -1;
listen_ok:
- if (update_addr) {
- g_free(saddr->host);
- saddr->host = g_strdup(uaddr);
- g_free(saddr->port);
- saddr->port = g_strdup_printf("%d",
- inet_getport(e) - port_offset);
- saddr->has_ipv6 = saddr->ipv6 = e->ai_family == PF_INET6;
- saddr->has_ipv4 = saddr->ipv4 = e->ai_family != PF_INET6;
- }
freeaddrinfo(res);
return slisten;
}
@@ -791,7 +780,6 @@ static int vsock_parse(VsockSocketAddress *addr, const char *str,
#ifndef _WIN32
static int unix_listen_saddr(UnixSocketAddress *saddr,
- bool update_addr,
Error **errp)
{
struct sockaddr_un un;
@@ -856,12 +844,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
goto err;
}
- if (update_addr && pathbuf) {
- g_free(saddr->path);
- saddr->path = pathbuf;
- } else {
- g_free(pathbuf);
- }
+ g_free(pathbuf);
return sock;
err:
@@ -921,7 +904,6 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
#else
static int unix_listen_saddr(UnixSocketAddress *saddr,
- bool update_addr,
Error **errp)
{
error_setg(errp, "unix sockets are not available on windows");
@@ -938,7 +920,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
#endif
/* compatibility wrapper */
-int unix_listen(const char *str, char *ostr, int olen, Error **errp)
+int unix_listen(const char *str, Error **errp)
{
char *path, *optstr;
int sock, len;
@@ -958,11 +940,7 @@ int unix_listen(const char *str, char *ostr, int olen, Error **errp)
saddr->path = g_strdup(str);
}
- sock = unix_listen_saddr(saddr, true, errp);
-
- if (sock != -1 && ostr) {
- snprintf(ostr, olen, "%s%s", saddr->path, optstr ? optstr : "");
- }
+ sock = unix_listen_saddr(saddr, errp);
qapi_free_UnixSocketAddress(saddr);
return sock;
@@ -1053,11 +1031,11 @@ int socket_listen(SocketAddress *addr, Error **errp)
switch (addr->type) {
case SOCKET_ADDRESS_TYPE_INET:
- fd = inet_listen_saddr(&addr->u.inet, 0, false, errp);
+ fd = inet_listen_saddr(&addr->u.inet, 0, errp);
break;
case SOCKET_ADDRESS_TYPE_UNIX:
- fd = unix_listen_saddr(&addr->u.q_unix, false, errp);
+ fd = unix_listen_saddr(&addr->u.q_unix, errp);
break;
case SOCKET_ADDRESS_TYPE_FD:
diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index 7306475..959a570 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -479,15 +479,29 @@ static void __attribute__((constructor)) qemu_thread_atexit_init(void)
}
-/* Attempt to set the threads name; note that this is for debug, so
- * we're not going to fail if we can't set it.
- */
-static void qemu_thread_set_name(QemuThread *thread, const char *name)
-{
#ifdef CONFIG_PTHREAD_SETNAME_NP
- pthread_setname_np(thread->thread, name);
-#endif
+typedef struct {
+ void *(*start_routine)(void *);
+ void *arg;
+ char *name;
+} QemuThreadArgs;
+
+static void *qemu_thread_start(void *args)
+{
+ QemuThreadArgs *qemu_thread_args = args;
+ void *(*start_routine)(void *) = qemu_thread_args->start_routine;
+ void *arg = qemu_thread_args->arg;
+
+ /* Attempt to set the threads name; note that this is for debug, so
+ * we're not going to fail if we can't set it.
+ */
+ pthread_setname_np(pthread_self(), qemu_thread_args->name);
+ g_free(qemu_thread_args->name);
+ g_free(qemu_thread_args);
+ return start_routine(arg);
}
+#endif
+
void qemu_thread_create(QemuThread *thread, const char *name,
void *(*start_routine)(void*),
@@ -502,23 +516,34 @@ void qemu_thread_create(QemuThread *thread, const char *name,
error_exit(err, __func__);
}
+ if (mode == QEMU_THREAD_DETACHED) {
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ }
+
/* Leave signal handling to the iothread. */
sigfillset(&set);
pthread_sigmask(SIG_SETMASK, &set, &oldset);
- err = pthread_create(&thread->thread, &attr, start_routine, arg);
- if (err)
- error_exit(err, __func__);
+#ifdef CONFIG_PTHREAD_SETNAME_NP
if (name_threads) {
- qemu_thread_set_name(thread, name);
+ QemuThreadArgs *qemu_thread_args;
+ qemu_thread_args = g_new0(QemuThreadArgs, 1);
+ qemu_thread_args->name = g_strdup(name);
+ qemu_thread_args->start_routine = start_routine;
+ qemu_thread_args->arg = arg;
+
+ err = pthread_create(&thread->thread, &attr,
+ qemu_thread_start, qemu_thread_args);
+ } else
+#endif
+ {
+ err = pthread_create(&thread->thread, &attr,
+ start_routine, arg);
}
- if (mode == QEMU_THREAD_DETACHED) {
- err = pthread_detach(thread->thread);
- if (err) {
- error_exit(err, __func__);
- }
- }
+ if (err)
+ error_exit(err, __func__);
+
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
pthread_attr_destroy(&attr);
diff --git a/util/rcu.c b/util/rcu.c
index ca5a63e..f4d09c8 100644
--- a/util/rcu.c
+++ b/util/rcu.c
@@ -32,6 +32,9 @@
#include "qemu/atomic.h"
#include "qemu/thread.h"
#include "qemu/main-loop.h"
+#if defined(CONFIG_MALLOC_TRIM)
+#include <malloc.h>
+#endif
/*
* Global grace period counter. Bit 0 is always one in rcu_gp_ctr.
@@ -246,6 +249,9 @@ static void *call_rcu_thread(void *opaque)
qemu_event_reset(&rcu_call_ready_event);
n = atomic_read(&rcu_call_count);
if (n == 0) {
+#if defined(CONFIG_MALLOC_TRIM)
+ malloc_trim(4 * 1024 * 1024);
+#endif
qemu_event_wait(&rcu_call_ready_event);
}
}
diff --git a/util/uuid.c b/util/uuid.c
index dd6b5fd..ebf06c0 100644
--- a/util/uuid.c
+++ b/util/uuid.c
@@ -41,7 +41,12 @@ void qemu_uuid_generate(QemuUUID *uuid)
int qemu_uuid_is_null(const QemuUUID *uu)
{
static QemuUUID null_uuid;
- return memcmp(uu, &null_uuid, sizeof(QemuUUID)) == 0;
+ return qemu_uuid_is_equal(uu, &null_uuid);
+}
+
+int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv)
+{
+ return memcmp(lhv, rhv, sizeof(QemuUUID)) == 0;
}
void qemu_uuid_unparse(const QemuUUID *uuid, char *out)