aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Campbell <Ian.Campbell@citrix.com>2012-01-31 16:06:14 +0000
committerIan Campbell <Ian.Campbell@citrix.com>2012-01-31 16:06:14 +0000
commit1a4af67d32b1c39b73e09346203f3e12c00b9e41 (patch)
treeee7058fc62cdec6fe3f3582a63f99f90bd05bb24
parentf17888fc962b5249f9b6b34f28a61998c3092018 (diff)
downloadxen-1a4af67d32b1c39b73e09346203f3e12c00b9e41.tar.gz
xen-1a4af67d32b1c39b73e09346203f3e12c00b9e41.tar.bz2
xen-1a4af67d32b1c39b73e09346203f3e12c00b9e41.zip
mini-os: use BSD sys/queue.h instead of Linux list.h
The latter is GPL which makes the whole of mini-os GPL rather than BSD as intended. In tree users are all GPL or GPL-compatible but we should fix this so that mini-os is BSD. Do so by using the same BSD sys/queue.h as we use in libxl. Tested with the builtin mini-os test app and qemu stubdomain, both of which appear to still function as expected. Move tools/libxl/external and the associated sed script to tools/include/xen-external to allow more sensible access from mini-os. Also add s/NULL/0/ in the sed script due to NULL not always being defined in stubdom code when mini-os/wait.h is included. As well as the obvious ABI changes there are a few API updates associated with the change: - struct rw_semaphore.wait_list is unused - remove_waiter needs to take the wait_queue_head The latter requires a qemu update, so there is also a QEMU_TAG update in this changeset. I sprinkled some extra-emacs local variables around the files I edited which didn't have them. I think this should be backported to the stable branches since external users of mini-os may have been mislead into thinking they could safely link mini-os against GPL-incompatible code. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
-rw-r--r--.hgignore1
-rw-r--r--Config.mk6
-rw-r--r--extras/mini-os/Makefile9
-rw-r--r--extras/mini-os/blkfront.c6
-rw-r--r--extras/mini-os/fbfront.c2
-rw-r--r--extras/mini-os/include/list.h190
-rw-r--r--extras/mini-os/include/sched.h2
-rw-r--r--extras/mini-os/include/semaphore.h1
-rw-r--r--extras/mini-os/include/wait.h56
-rw-r--r--extras/mini-os/include/waittypes.h26
-rw-r--r--extras/mini-os/lib/sys.c38
-rw-r--r--extras/mini-os/lib/xmalloc.c43
-rw-r--r--extras/mini-os/sched.c48
-rw-r--r--extras/mini-os/xenbus/xenbus.c4
-rw-r--r--tools/include/xen-external/README (renamed from tools/libxl/external/README)14
-rw-r--r--tools/include/xen-external/bsd-COPYRIGHT (renamed from tools/libxl/external/bsd-COPYRIGHT)0
-rw-r--r--tools/include/xen-external/bsd-queue.3 (renamed from tools/libxl/external/bsd-queue.3)0
-rwxr-xr-xtools/include/xen-external/bsd-sys-queue-h-seddery (renamed from tools/libxl/bsd-sys-queue-h-seddery)2
-rw-r--r--tools/include/xen-external/bsd-sys-queue.h (renamed from tools/libxl/external/bsd-sys-queue.h)0
-rw-r--r--tools/libxl/Makefile4
20 files changed, 148 insertions, 304 deletions
diff --git a/.hgignore b/.hgignore
index fd6cfaade0..2b5cfe576d 100644
--- a/.hgignore
+++ b/.hgignore
@@ -62,6 +62,7 @@
^docs/xen-api/xenapi-datamodel-graph.eps$
^docs/xen-api/xenapi.out$
^extras/mini-os/arch/ia64/gen_off.s$
+^extras/mini-os/include/list\.h$
^extras/mini-os/include/mini-os$
^extras/mini-os/include/ia64/mini-os$
^extras/mini-os/include/ia64/offsets.h$
diff --git a/Config.mk b/Config.mk
index 6d5b0c94b2..90a77286a1 100644
--- a/Config.mk
+++ b/Config.mk
@@ -222,9 +222,9 @@ SEABIOS_UPSTREAM_TAG ?= rel-1.6.3.1
# CONFIG_QEMU ?= `pwd`/$(XEN_ROOT)/../qemu-xen.git
CONFIG_QEMU ?= $(QEMU_REMOTE)
-QEMU_TAG ?= bb36d632e4cabf47882adff07a45c6702c4a5b30
-# Thu Jan 5 17:16:46 2012 +0000
-# qemu-xen: adjust MSI-X related log messages
+QEMU_TAG ?= de05447400930da4be216e4fb0fe52b8be81490e
+# Tue Jan 31 15:42:38 2012 +0000
+# block-vbd: update to new mini-os wait queue API (new linked list API)
# Short answer -- do not enable this unless you know what you are
# doing and are prepared for some pain.
diff --git a/extras/mini-os/Makefile b/extras/mini-os/Makefile
index c2ee062266..c4d26f0213 100644
--- a/extras/mini-os/Makefile
+++ b/extras/mini-os/Makefile
@@ -52,8 +52,12 @@ $(ARCH_LINKS):
$(arch_links)
endif
+include/list.h: $(XEN_ROOT)/tools/include/xen-external/bsd-sys-queue-h-seddery $(XEN_ROOT)/tools/include/xen-external/bsd-sys-queue.h
+ perl $^ --prefix=minios >$@.new
+ $(call move-if-changed,$@.new,$@)
+
.PHONY: links
-links: $(ARCH_LINKS)
+links: include/list.h $(ARCH_LINKS)
[ -e include/xen ] || ln -sf ../../../xen/include/public include/xen
[ -e include/mini-os ] || ln -sf . include/mini-os
[ -e include/$(TARGET_ARCH_FAM)/mini-os ] || ln -sf . include/$(TARGET_ARCH_FAM)/mini-os
@@ -97,7 +101,7 @@ ifneq ($(APP_OBJS),)
APP_O=$(OBJ_DIR)/$(TARGET)_app.o
endif
-$(OBJ_DIR)/$(TARGET): links $(OBJS) $(APP_O) arch_lib
+$(OBJ_DIR)/$(TARGET): links include/list.h $(OBJS) $(APP_O) arch_lib
$(LD) -r $(LDFLAGS) $(HEAD_OBJ) $(APP_O) $(OBJS) $(LDARCHLIB) $(LDLIBS) -o $@.o
$(OBJCOPY) -w -G $(GLOBAL_PREFIX)* -G _start $@.o $@.o
$(LD) $(LDFLAGS) $(LDFLAGS_FINAL) $@.o $(EXTRA_OBJS) -o $@
@@ -112,6 +116,7 @@ clean: arch_clean
for dir in $(addprefix $(OBJ_DIR)/,$(SUBDIRS)); do \
rm -f $$dir/*.o; \
done
+ rm -f include/list.h
rm -f $(OBJ_DIR)/*.o *~ $(OBJ_DIR)/core $(OBJ_DIR)/$(TARGET).elf $(OBJ_DIR)/$(TARGET).raw $(OBJ_DIR)/$(TARGET) $(OBJ_DIR)/$(TARGET).gz
find . $(OBJ_DIR) -type l | xargs rm -f
$(RM) $(OBJ_DIR)/lwip.a $(LWO)
diff --git a/extras/mini-os/blkfront.c b/extras/mini-os/blkfront.c
index 695d8e65ee..bb3d91ebd8 100644
--- a/extras/mini-os/blkfront.c
+++ b/extras/mini-os/blkfront.c
@@ -323,7 +323,7 @@ static void blkfront_wait_slot(struct blkfront_dev *dev)
schedule();
local_irq_save(flags);
}
- remove_waiter(w);
+ remove_waiter(w, blkfront_queue);
local_irq_restore(flags);
}
}
@@ -414,7 +414,7 @@ void blkfront_io(struct blkfront_aiocb *aiocbp, int write)
schedule();
local_irq_save(flags);
}
- remove_waiter(w);
+ remove_waiter(w, blkfront_queue);
local_irq_restore(flags);
}
@@ -470,7 +470,7 @@ void blkfront_sync(struct blkfront_dev *dev)
schedule();
local_irq_save(flags);
}
- remove_waiter(w);
+ remove_waiter(w, blkfront_queue);
local_irq_restore(flags);
}
diff --git a/extras/mini-os/fbfront.c b/extras/mini-os/fbfront.c
index 8d03e5be5a..9889376408 100644
--- a/extras/mini-os/fbfront.c
+++ b/extras/mini-os/fbfront.c
@@ -569,7 +569,7 @@ static void fbfront_out_event(struct fbfront_dev *dev, union xenfb_out_event *ev
add_waiter(w, fbfront_queue);
while (page->out_prod - page->out_cons == XENFB_OUT_RING_LEN)
schedule();
- remove_waiter(w);
+ remove_waiter(w, fbfront_queue);
prod = page->out_prod;
mb(); /* ensure ring space available */
diff --git a/extras/mini-os/include/list.h b/extras/mini-os/include/list.h
deleted file mode 100644
index a60ae23431..0000000000
--- a/extras/mini-os/include/list.h
+++ /dev/null
@@ -1,190 +0,0 @@
-#ifndef _LINUX_LIST_H
-#define _LINUX_LIST_H
-
-/*
- * Simple doubly linked list implementation.
- *
- * Some of the internal functions ("__xxx") are useful when
- * manipulating whole lists rather than single entries, as
- * sometimes we already know the next/prev entries and we can
- * generate better code by using them directly rather than
- * using the generic single-entry routines.
- */
-
-struct minios_list_head {
- struct minios_list_head *next, *prev;
-};
-
-#define MINIOS_LIST_HEAD_INIT(name) { &(name), &(name) }
-
-#define MINIOS_LIST_HEAD(name) \
- struct minios_list_head name = MINIOS_LIST_HEAD_INIT(name)
-
-#define MINIOS_INIT_LIST_HEAD(ptr) do { \
- (ptr)->next = (ptr); (ptr)->prev = (ptr); \
-} while (0)
-
-#define minios_list_top(head, type, member) \
-({ \
- struct minios_list_head *_head = (head); \
- minios_list_empty(_head) ? NULL : minios_list_entry(_head->next, type, member); \
-})
-
-/*
- * Insert a new entry between two known consecutive entries.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static __inline__ void __minios_list_add(struct minios_list_head * new,
- struct minios_list_head * prev,
- struct minios_list_head * next)
-{
- next->prev = new;
- new->next = next;
- new->prev = prev;
- prev->next = new;
-}
-
-/**
- * minios_list_add - add a new entry
- * @new: new entry to be added
- * @head: list head to add it after
- *
- * Insert a new entry after the specified head.
- * This is good for implementing stacks.
- */
-static __inline__ void minios_list_add(struct minios_list_head *new, struct minios_list_head *head)
-{
- __minios_list_add(new, head, head->next);
-}
-
-/**
- * minios_list_add_tail - add a new entry
- * @new: new entry to be added
- * @head: list head to add it before
- *
- * Insert a new entry before the specified head.
- * This is useful for implementing queues.
- */
-static __inline__ void minios_list_add_tail(struct minios_list_head *new, struct minios_list_head *head)
-{
- __minios_list_add(new, head->prev, head);
-}
-
-/*
- * Delete a list entry by making the prev/next entries
- * point to each other.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static __inline__ void __minios_list_del(struct minios_list_head * prev,
- struct minios_list_head * next)
-{
- next->prev = prev;
- prev->next = next;
-}
-
-/**
- * minios_list_del - deletes entry from list.
- * @entry: the element to delete from the list.
- * Note: minios_list_empty on entry does not return true after this, the entry is in an undefined state.
- */
-static __inline__ void minios_list_del(struct minios_list_head *entry)
-{
- __minios_list_del(entry->prev, entry->next);
-}
-
-/**
- * minios_list_del_init - deletes entry from list and reinitialize it.
- * @entry: the element to delete from the list.
- */
-static __inline__ void minios_list_del_init(struct minios_list_head *entry)
-{
- __minios_list_del(entry->prev, entry->next);
- MINIOS_INIT_LIST_HEAD(entry);
-}
-
-/**
- * minios_list_empty - tests whether a list is empty
- * @head: the list to test.
- */
-static __inline__ int minios_list_empty(struct minios_list_head *head)
-{
- return head->next == head;
-}
-
-/**
- * minios_list_splice - join two lists
- * @list: the new list to add.
- * @head: the place to add it in the first list.
- */
-static __inline__ void minios_list_splice(struct minios_list_head *list, struct minios_list_head *head)
-{
- struct minios_list_head *first = list->next;
-
- if (first != list) {
- struct minios_list_head *last = list->prev;
- struct minios_list_head *at = head->next;
-
- first->prev = head;
- head->next = first;
-
- last->next = at;
- at->prev = last;
- }
-}
-
-/**
- * minios_list_entry - get the struct for this entry
- * @ptr: the &struct minios_list_head pointer.
- * @type: the type of the struct this is embedded in.
- * @member: the name of the minios_list_struct within the struct.
- */
-#define minios_list_entry(ptr, type, member) \
- ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
-
-/**
- * minios_list_for_each - iterate over a list
- * @pos: the &struct minios_list_head to use as a loop counter.
- * @head: the head for your list.
- */
-#define minios_list_for_each(pos, head) \
- for (pos = (head)->next; pos != (head); pos = pos->next)
-
-/**
- * minios_list_for_each_safe - iterate over a list safe against removal of list entry
- * @pos: the &struct minios_list_head to use as a loop counter.
- * @n: another &struct minios_list_head to use as temporary storage
- * @head: the head for your list.
- */
-#define minios_list_for_each_safe(pos, n, head) \
- for (pos = (head)->next, n = pos->next; pos != (head); \
- pos = n, n = pos->next)
-
-/**
- * minios_list_for_each_entry - iterate over list of given type
- * @pos: the type * to use as a loop counter.
- * @head: the head for your list.
- * @member: the name of the minios_list_struct within the struct.
- */
-#define minios_list_for_each_entry(pos, head, member) \
- for (pos = minios_list_entry((head)->next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = minios_list_entry(pos->member.next, typeof(*pos), member))
-
-/**
- * minios_list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
- * @pos: the type * to use as a loop counter.
- * @n: another type * to use as temporary storage
- * @head: the head for your list.
- * @member: the name of the minios_list_struct within the struct.
- */
-#define minios_list_for_each_entry_safe(pos, n, head, member) \
- for (pos = minios_list_entry((head)->next, typeof(*pos), member), \
- n = minios_list_entry(pos->member.next, typeof(*pos), member); \
- &pos->member != (head); \
- pos = n, n = minios_list_entry(n->member.next, typeof(*n), member))
-#endif /* _LINUX_LIST_H */
-
diff --git a/extras/mini-os/include/sched.h b/extras/mini-os/include/sched.h
index 538bed5b8d..ea3239d602 100644
--- a/extras/mini-os/include/sched.h
+++ b/extras/mini-os/include/sched.h
@@ -19,7 +19,7 @@ struct thread
#else /* !defined(__ia64__) */
thread_regs_t regs;
#endif /* !defined(__ia64__) */
- struct minios_list_head thread_list;
+ MINIOS_TAILQ_ENTRY(struct thread) thread_list;
uint32_t flags;
s_time_t wakeup_time;
#ifdef HAVE_LIBC
diff --git a/extras/mini-os/include/semaphore.h b/extras/mini-os/include/semaphore.h
index 8236046714..47470c511a 100644
--- a/extras/mini-os/include/semaphore.h
+++ b/extras/mini-os/include/semaphore.h
@@ -21,7 +21,6 @@ struct semaphore
struct rw_semaphore {
signed long count;
spinlock_t wait_lock;
- struct minios_list_head wait_list;
int debug;
};
diff --git a/extras/mini-os/include/wait.h b/extras/mini-os/include/wait.h
index 10b9f29b07..bffa3c444c 100644
--- a/extras/mini-os/include/wait.h
+++ b/extras/mini-os/include/wait.h
@@ -5,47 +5,47 @@
#include <mini-os/os.h>
#include <mini-os/waittypes.h>
-#define DEFINE_WAIT(name) \
-struct wait_queue name = { \
- .thread = get_current(), \
- .thread_list = MINIOS_LIST_HEAD_INIT((name).thread_list), \
+#define DEFINE_WAIT(name) \
+struct wait_queue name = { \
+ .thread = get_current(), \
+ .waiting = 0, \
}
static inline void init_waitqueue_head(struct wait_queue_head *h)
{
- MINIOS_INIT_LIST_HEAD(&h->thread_list);
+ MINIOS_STAILQ_INIT(h);
}
static inline void init_waitqueue_entry(struct wait_queue *q, struct thread *thread)
{
q->thread = thread;
- MINIOS_INIT_LIST_HEAD(&q->thread_list);
+ q->waiting = 0;
}
-
static inline void add_wait_queue(struct wait_queue_head *h, struct wait_queue *q)
{
- if (minios_list_empty(&q->thread_list))
- minios_list_add(&q->thread_list, &h->thread_list);
+ if (!q->waiting) {
+ MINIOS_STAILQ_INSERT_HEAD(h, q, thread_list);
+ q->waiting = 1;
+ }
}
-static inline void remove_wait_queue(struct wait_queue *q)
+static inline void remove_wait_queue(struct wait_queue_head *h, struct wait_queue *q)
{
- minios_list_del(&q->thread_list);
+ if (q->waiting) {
+ MINIOS_STAILQ_REMOVE(h, q, struct wait_queue, thread_list);
+ q->waiting = 0;
+ }
}
static inline void wake_up(struct wait_queue_head *head)
{
unsigned long flags;
- struct minios_list_head *tmp, *next;
+ struct wait_queue *curr, *tmp;
local_irq_save(flags);
- minios_list_for_each_safe(tmp, next, &head->thread_list)
- {
- struct wait_queue *curr;
- curr = minios_list_entry(tmp, struct wait_queue, thread_list);
+ MINIOS_STAILQ_FOREACH_SAFE(curr, head, thread_list, tmp)
wake(curr->thread);
- }
local_irq_restore(flags);
}
@@ -57,11 +57,11 @@ static inline void wake_up(struct wait_queue_head *head)
local_irq_restore(flags); \
} while (0)
-#define remove_waiter(w) do { \
- unsigned long flags; \
- local_irq_save(flags); \
- remove_wait_queue(&w); \
- local_irq_restore(flags); \
+#define remove_waiter(w, wq) do { \
+ unsigned long flags; \
+ local_irq_save(flags); \
+ remove_wait_queue(&wq, &w); \
+ local_irq_restore(flags); \
} while (0)
#define wait_event_deadline(wq, condition, deadline) do { \
@@ -84,7 +84,7 @@ static inline void wake_up(struct wait_queue_head *head)
local_irq_save(flags); \
/* need to wake up */ \
wake(get_current()); \
- remove_wait_queue(&__wait); \
+ remove_wait_queue(&wq, &__wait); \
local_irq_restore(flags); \
} while(0)
@@ -93,3 +93,13 @@ static inline void wake_up(struct wait_queue_head *head)
#endif /* __WAIT_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/extras/mini-os/include/waittypes.h b/extras/mini-os/include/waittypes.h
index 1215ffe0be..78d91c1542 100644
--- a/extras/mini-os/include/waittypes.h
+++ b/extras/mini-os/include/waittypes.h
@@ -6,21 +6,27 @@
struct thread;
struct wait_queue
{
+ int waiting;
struct thread *thread;
- struct minios_list_head thread_list;
+ MINIOS_STAILQ_ENTRY(struct wait_queue) thread_list;
};
-struct wait_queue_head
-{
- /* TODO - lock required? */
- struct minios_list_head thread_list;
-};
+/* TODO - lock required? */
+MINIOS_STAILQ_HEAD(wait_queue_head, struct wait_queue);
#define DECLARE_WAIT_QUEUE_HEAD(name) \
- struct wait_queue_head name = \
- { .thread_list = { &(name).thread_list, &(name).thread_list} }
+ struct wait_queue_head name = MINIOS_STAILQ_HEAD_INITIALIZER(name)
-#define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
- .thread_list = { &(name).thread_list, &(name).thread_list } }
+#define __WAIT_QUEUE_HEAD_INITIALIZER(name) MINIOS_STAILQ_HEAD_INITIALIZER(name)
#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/extras/mini-os/lib/sys.c b/extras/mini-os/lib/sys.c
index b7b3aff50a..2329a78c21 100644
--- a/extras/mini-os/lib/sys.c
+++ b/extras/mini-os/lib/sys.c
@@ -234,7 +234,7 @@ int read(int fd, void *buf, size_t nbytes)
break;
schedule();
}
- remove_waiter(w);
+ remove_waiter(w, console_queue);
return ret;
}
#ifdef HAVE_LWIP
@@ -705,12 +705,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
fd_set myread, mywrite, myexcept;
struct thread *thread = get_current();
s_time_t start = NOW(), stop;
- DEFINE_WAIT(w1);
- DEFINE_WAIT(w2);
- DEFINE_WAIT(w3);
- DEFINE_WAIT(w4);
- DEFINE_WAIT(w5);
- DEFINE_WAIT(w6);
+ DEFINE_WAIT(netfront_w);
+ DEFINE_WAIT(event_w);
+ DEFINE_WAIT(blkfront_w);
+ DEFINE_WAIT(xenbus_watch_w);
+ DEFINE_WAIT(kbdfront_w);
+ DEFINE_WAIT(console_w);
assert(thread == main_thread);
@@ -727,12 +727,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
/* Tell people we're going to sleep before looking at what they are
* saying, hence letting them wake us if events happen between here and
* schedule() */
- add_waiter(w1, netfront_queue);
- add_waiter(w2, event_queue);
- add_waiter(w3, blkfront_queue);
- add_waiter(w4, xenbus_watch_queue);
- add_waiter(w5, kbdfront_queue);
- add_waiter(w6, console_queue);
+ add_waiter(netfront_w, netfront_queue);
+ add_waiter(event_w, event_queue);
+ add_waiter(blkfront_w, blkfront_queue);
+ add_waiter(xenbus_watch_w, xenbus_watch_queue);
+ add_waiter(kbdfront_w, kbdfront_queue);
+ add_waiter(console_w, console_queue);
if (readfds)
myread = *readfds;
@@ -814,12 +814,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
ret = -1;
out:
- remove_waiter(w1);
- remove_waiter(w2);
- remove_waiter(w3);
- remove_waiter(w4);
- remove_waiter(w5);
- remove_waiter(w6);
+ remove_waiter(netfront_w, netfront_queue);
+ remove_waiter(event_w, event_queue);
+ remove_waiter(blkfront_w, blkfront_queue);
+ remove_waiter(xenbus_watch_w, xenbus_watch_queue);
+ remove_waiter(kbdfront_w, kbdfront_queue);
+ remove_waiter(console_w, console_queue);
return ret;
}
diff --git a/extras/mini-os/lib/xmalloc.c b/extras/mini-os/lib/xmalloc.c
index c7d3fc1b30..015cd31bb9 100644
--- a/extras/mini-os/lib/xmalloc.c
+++ b/extras/mini-os/lib/xmalloc.c
@@ -44,16 +44,18 @@
#include <mini-os/xmalloc.h>
#ifndef HAVE_LIBC
-static MINIOS_LIST_HEAD(freelist);
/* static spinlock_t freelist_lock = SPIN_LOCK_UNLOCKED; */
struct xmalloc_hdr
{
/* Total including this hdr, unused padding and second hdr. */
size_t size;
- struct minios_list_head freelist;
+ MINIOS_TAILQ_ENTRY(struct xmalloc_hdr) freelist;
} __cacheline_aligned;
+static MINIOS_TAILQ_HEAD(,struct xmalloc_hdr) freelist =
+ MINIOS_TAILQ_HEAD_INITIALIZER(freelist);
+
/* Unused padding data between the two hdrs. */
struct xmalloc_pad
@@ -82,7 +84,7 @@ static void maybe_split(struct xmalloc_hdr *hdr, size_t size, size_t block)
extra = (struct xmalloc_hdr *)((unsigned long)hdr + size);
extra->size = leftover;
/* spin_lock_irqsave(&freelist_lock, flags); */
- minios_list_add(&extra->freelist, &freelist);
+ MINIOS_TAILQ_INSERT_HEAD(&freelist, extra, freelist);
/* spin_unlock_irqrestore(&freelist_lock, flags); */
}
else
@@ -91,8 +93,6 @@ static void maybe_split(struct xmalloc_hdr *hdr, size_t size, size_t block)
}
hdr->size = size;
- /* Debugging aid. */
- hdr->freelist.next = hdr->freelist.prev = NULL;
}
static struct xmalloc_hdr *xmalloc_new_page(size_t size)
@@ -128,8 +128,6 @@ static void *xmalloc_whole_pages(size_t size, size_t align)
return NULL;
hdr->size = (1UL << (pageorder + PAGE_SHIFT));
- /* Debugging aid. */
- hdr->freelist.next = hdr->freelist.prev = NULL;
ret = (char*)hdr + hdr_size;
pad = (struct xmalloc_pad *) ret - 1;
@@ -155,14 +153,14 @@ void *_xmalloc(size_t size, size_t align)
/* Search free list. */
/* spin_lock_irqsave(&freelist_lock, flags); */
- minios_list_for_each_entry_safe( i, tmp, &freelist, freelist )
+ MINIOS_TAILQ_FOREACH_SAFE(i, &freelist, freelist, tmp)
{
data_begin = align_up((uintptr_t)i + hdr_size, align);
if ( data_begin + size > (uintptr_t)i + i->size )
continue;
- minios_list_del(&i->freelist);
+ MINIOS_TAILQ_REMOVE(&freelist, i, freelist);
/* spin_unlock_irqrestore(&freelist_lock, flags); */
uintptr_t size_before = (data_begin - hdr_size) - (uintptr_t)i;
@@ -173,7 +171,7 @@ void *_xmalloc(size_t size, size_t align)
new_i->size = i->size - size_before;
i->size = size_before;
/* spin_lock_irqsave(&freelist_lock, flags); */
- minios_list_add(&i->freelist, &freelist);
+ MINIOS_TAILQ_INSERT_HEAD(&freelist, i, freelist);
/* spin_unlock_irqrestore(&freelist_lock, flags); */
i = new_i;
}
@@ -224,16 +222,9 @@ void xfree(const void *p)
*(int*)0=0;
}
- /* Not previously freed. */
- if(hdr->freelist.next || hdr->freelist.prev)
- {
- printk("Should not be previously freed\n");
- *(int*)0=0;
- }
-
/* Merge with other free block, or put in list. */
/* spin_lock_irqsave(&freelist_lock, flags); */
- minios_list_for_each_entry_safe( i, tmp, &freelist, freelist )
+ MINIOS_TAILQ_FOREACH_SAFE(i, &freelist, freelist, tmp)
{
unsigned long _i = (unsigned long)i;
unsigned long _hdr = (unsigned long)hdr;
@@ -245,7 +236,7 @@ void xfree(const void *p)
/* We follow this block? Swallow it. */
if ( (_i + i->size) == _hdr )
{
- minios_list_del(&i->freelist);
+ MINIOS_TAILQ_REMOVE(&freelist, i, freelist);
i->size += hdr->size;
hdr = i;
}
@@ -253,7 +244,7 @@ void xfree(const void *p)
/* We precede this block? Swallow it. */
if ( (_hdr + hdr->size) == _i )
{
- minios_list_del(&i->freelist);
+ MINIOS_TAILQ_REMOVE(&freelist, i, freelist);
hdr->size += i->size;
}
}
@@ -270,7 +261,7 @@ void xfree(const void *p)
}
else
{
- minios_list_add(&hdr->freelist, &freelist);
+ MINIOS_TAILQ_INSERT_HEAD(&freelist, hdr, freelist);
}
/* spin_unlock_irqrestore(&freelist_lock, flags); */
@@ -306,3 +297,13 @@ void *_realloc(void *ptr, size_t size)
return new;
}
#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/extras/mini-os/sched.c b/extras/mini-os/sched.c
index c0229c5687..2d27bfaa97 100644
--- a/extras/mini-os/sched.c
+++ b/extras/mini-os/sched.c
@@ -54,19 +54,20 @@
#define DEBUG(_f, _a...) ((void)0)
#endif
+MINIOS_TAILQ_HEAD(thread_list, struct thread);
+
struct thread *idle_thread = NULL;
-MINIOS_LIST_HEAD(exited_threads);
+static struct thread_list exited_threads = MINIOS_TAILQ_HEAD_INITIALIZER(exited_threads);
+static struct thread_list thread_list = MINIOS_TAILQ_HEAD_INITIALIZER(thread_list);
static int threads_started;
struct thread *main_thread;
void inline print_runqueue(void)
{
- struct minios_list_head *it;
struct thread *th;
- minios_list_for_each(it, &idle_thread->thread_list)
+ MINIOS_TAILQ_FOREACH(th, &thread_list, thread_list)
{
- th = minios_list_entry(it, struct thread, thread_list);
printk(" Thread \"%s\", runnable=%d\n", th->name, is_runnable(th));
}
printk("\n");
@@ -74,8 +75,7 @@ void inline print_runqueue(void)
void schedule(void)
{
- struct thread *prev, *next, *thread;
- struct minios_list_head *iterator, *next_iterator;
+ struct thread *prev, *next, *thread, *tmp;
unsigned long flags;
prev = current;
@@ -96,10 +96,9 @@ void schedule(void)
time when the next timeout expires, else use 10 seconds. */
s_time_t now = NOW();
s_time_t min_wakeup_time = now + SECONDS(10);
- next = NULL;
- minios_list_for_each_safe(iterator, next_iterator, &idle_thread->thread_list)
+ next = NULL;
+ MINIOS_TAILQ_FOREACH_SAFE(thread, &thread_list, thread_list, tmp)
{
- thread = minios_list_entry(iterator, struct thread, thread_list);
if (!is_runnable(thread) && thread->wakeup_time != 0LL)
{
if (thread->wakeup_time <= now)
@@ -111,8 +110,8 @@ void schedule(void)
{
next = thread;
/* Put this thread on the end of the list */
- minios_list_del(&thread->thread_list);
- minios_list_add_tail(&thread->thread_list, &idle_thread->thread_list);
+ MINIOS_TAILQ_REMOVE(&thread_list, thread, thread_list);
+ MINIOS_TAILQ_INSERT_TAIL(&thread_list, thread, thread_list);
break;
}
}
@@ -128,12 +127,11 @@ void schedule(void)
inturrupted at the return instruction. And therefore at safe point. */
if(prev != next) switch_threads(prev, next);
- minios_list_for_each_safe(iterator, next_iterator, &exited_threads)
+ MINIOS_TAILQ_FOREACH_SAFE(thread, &exited_threads, thread_list, tmp)
{
- thread = minios_list_entry(iterator, struct thread, thread_list);
if(thread != prev)
{
- minios_list_del(&thread->thread_list);
+ MINIOS_TAILQ_REMOVE(&exited_threads, thread, thread_list);
free_pages(thread->stack, STACK_SIZE_PAGE_ORDER);
xfree(thread);
}
@@ -154,13 +152,7 @@ struct thread* create_thread(char *name, void (*function)(void *), void *data)
#endif
set_runnable(thread);
local_irq_save(flags);
- if(idle_thread != NULL) {
- minios_list_add_tail(&thread->thread_list, &idle_thread->thread_list);
- } else if(function != idle_thread_fn)
- {
- printk("BUG: Not allowed to create thread before initialising scheduler.\n");
- BUG();
- }
+ MINIOS_TAILQ_INSERT_TAIL(&thread_list, thread, thread_list);
local_irq_restore(flags);
return thread;
}
@@ -208,10 +200,10 @@ void exit_thread(void)
printk("Thread \"%s\" exited.\n", thread->name);
local_irq_save(flags);
/* Remove from the thread list */
- minios_list_del(&thread->thread_list);
+ MINIOS_TAILQ_REMOVE(&thread_list, thread, thread_list);
clear_runnable(thread);
/* Put onto exited list */
- minios_list_add(&thread->thread_list, &exited_threads);
+ MINIOS_TAILQ_INSERT_HEAD(&exited_threads, thread, thread_list);
local_irq_restore(flags);
/* Schedule will free the resources */
while(1)
@@ -296,6 +288,14 @@ void init_sched(void)
_REENT_INIT_PTR((&callback_reent))
#endif
idle_thread = create_thread("Idle", idle_thread_fn, NULL);
- MINIOS_INIT_LIST_HEAD(&idle_thread->thread_list);
}
+/*
+ * Local variables:
+ * mode: C
+ * c-set-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/extras/mini-os/xenbus/xenbus.c b/extras/mini-os/xenbus/xenbus.c
index a8081fd943..f404eff338 100644
--- a/extras/mini-os/xenbus/xenbus.c
+++ b/extras/mini-os/xenbus/xenbus.c
@@ -85,7 +85,7 @@ char **xenbus_wait_for_watch_return(xenbus_event_queue *queue)
add_waiter(w, xenbus_watch_queue);
schedule();
}
- remove_waiter(w);
+ remove_waiter(w, xenbus_watch_queue);
*queue = event->next;
return &event->path;
}
@@ -441,7 +441,7 @@ xenbus_msg_reply(int type,
xb_write(type, id, trans, io, nr_reqs);
schedule();
- remove_waiter(w);
+ remove_waiter(w, req_info[id].waitq);
wake(current);
rep = req_info[id].reply;
diff --git a/tools/libxl/external/README b/tools/include/xen-external/README
index 8c8beea3f9..93c2bc9cd8 100644
--- a/tools/libxl/external/README
+++ b/tools/include/xen-external/README
@@ -1,5 +1,5 @@
-WARNING - DO NOT EDIT THINGS IN THIS DIRECTORY (apart from this README)
------------------------------------------------------------------------
+WARNING - DO NOT EDIT THINGS IN THIS DIRECTORY
+----------------------------------------------
These files were obtained elsewhere and should only be updated by
copying new versions from the source location, as documented below:
@@ -12,3 +12,13 @@ bsd-queue.3
svn co -r 221843 svn://svn.freebsd.org/base/head/sys/sys/
svn co -r 221843 svn://svn.freebsd.org/base/head/share/man/man3
svn cat -r 221843 http://svn.freebsd.org/base/head/COPYRIGHT >tools/libxl/external/bsd-COPYRIGHT
+
+Exceptions:
+
+README
+
+ This file
+
+bsd-sys-queue-h-seddery
+
+ Script to transform the above into a new namespace.
diff --git a/tools/libxl/external/bsd-COPYRIGHT b/tools/include/xen-external/bsd-COPYRIGHT
index 6dc5d16b46..6dc5d16b46 100644
--- a/tools/libxl/external/bsd-COPYRIGHT
+++ b/tools/include/xen-external/bsd-COPYRIGHT
diff --git a/tools/libxl/external/bsd-queue.3 b/tools/include/xen-external/bsd-queue.3
index 007ca5c629..007ca5c629 100644
--- a/tools/libxl/external/bsd-queue.3
+++ b/tools/include/xen-external/bsd-queue.3
diff --git a/tools/libxl/bsd-sys-queue-h-seddery b/tools/include/xen-external/bsd-sys-queue-h-seddery
index c0aa079cbe..7a957e3a10 100755
--- a/tools/libxl/bsd-sys-queue-h-seddery
+++ b/tools/include/xen-external/bsd-sys-queue-h-seddery
@@ -68,3 +68,5 @@ s/\b(
s/\b struct \s+ type \b/type/xg;
s,^\#include.*sys/cdefs.*,/* $& */,xg;
+
+s/\b( NULL )/0/xg;
diff --git a/tools/libxl/external/bsd-sys-queue.h b/tools/include/xen-external/bsd-sys-queue.h
index 274e636c53..274e636c53 100644
--- a/tools/libxl/external/bsd-sys-queue.h
+++ b/tools/include/xen-external/bsd-sys-queue.h
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index b58c43ecb7..d0b6fda277 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -93,8 +93,8 @@ _libxl_paths.h: genpath
rm -f $@.tmp
$(call move-if-changed,$@.2.tmp,$@)
-_libxl_list.h: bsd-sys-queue-h-seddery external/bsd-sys-queue.h
- perl ./$^ --prefix=libxl >$@.new
+_libxl_list.h: $(XEN_INCLUDE)/xen-external/bsd-sys-queue-h-seddery $(XEN_INCLUDE)/xen-external/bsd-sys-queue.h
+ perl $^ --prefix=libxl >$@.new
$(call move-if-changed,$@.new,$@)
libxl_paths.c: _libxl_paths.h