From: Ingo Molnar oops, the plist debugging changes were missing from the delta. Signed-off-by: Ingo Molnar Signed-off-by: Andrew Morton --- include/asm-generic/bug.h | 6 ++++ include/linux/plist.h | 29 ++++++++++++++++++++--- lib/plist.c | 45 ++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) diff -puN include/asm-generic/bug.h~pi-futex-patchset-v4-update include/asm-generic/bug.h --- devel/include/asm-generic/bug.h~pi-futex-patchset-v4-update 2006-04-01 16:26:33.000000000 -0800 +++ devel-akpm/include/asm-generic/bug.h 2006-04-01 16:26:33.000000000 -0800 @@ -39,4 +39,10 @@ #endif #endif +#ifdef CONFIG_SMP +# define WARN_ON_SMP(x) WARN_ON(x) +#else +# define WARN_ON_SMP(x) do { } while (0) +#endif + #endif diff -puN include/linux/plist.h~pi-futex-patchset-v4-update include/linux/plist.h --- devel/include/linux/plist.h~pi-futex-patchset-v4-update 2006-04-01 16:26:33.000000000 -0800 +++ devel-akpm/include/linux/plist.h 2006-04-01 16:26:33.000000000 -0800 @@ -79,6 +79,9 @@ struct plist_head { struct list_head prio_list; struct list_head node_list; +#ifdef CONFIG_DEBUG_PI_LIST + spinlock_t *lock; +#endif }; struct plist_node { @@ -86,15 +89,22 @@ struct plist_node { struct plist_head plist; }; +#ifdef CONFIG_DEBUG_PI_LIST +# define PLIST_HEAD_LOCK_INIT(_lock) .lock = _lock +#else +# define PLIST_HEAD_LOCK_INIT(_lock) +#endif + /** * #PLIST_HEAD_INIT - static struct plist_head initializer * * @head: struct plist_head variable name */ -#define PLIST_HEAD_INIT(head) \ +#define PLIST_HEAD_INIT(head, _lock) \ { \ .prio_list = LIST_HEAD_INIT((head).prio_list), \ .node_list = LIST_HEAD_INIT((head).node_list), \ + PLIST_HEAD_LOCK_INIT(&(_lock)) \ } /** @@ -115,10 +125,13 @@ struct plist_node { * @head: &struct plist_head pointer */ static inline void -plist_head_init(struct plist_head *head) +plist_head_init(struct plist_head *head, spinlock_t *lock) { INIT_LIST_HEAD(&head->prio_list); INIT_LIST_HEAD(&head->node_list); +#ifdef CONFIG_DEBUG_PI_LIST + head->lock = lock; +#endif } /** @@ -130,7 +143,7 @@ plist_head_init(struct plist_head *head) static inline void plist_node_init(struct plist_node *node, int prio) { node->prio = prio; - plist_head_init(&node->plist); + plist_head_init(&node->plist, NULL); } extern void plist_add(struct plist_node *node, struct plist_head *head); @@ -207,8 +220,16 @@ static inline int plist_node_empty(const * @type: the type of the struct this is embedded in. * @member: the name of the list_struct within the struct. */ -#define plist_first_entry(head, type, member) \ +#ifdef CONFIG_DEBUG_PI_LIST +# define plist_first_entry(head, type, member) \ +({ \ + WARN_ON(plist_head_empty(head)); \ + container_of(plist_first(head), type, member); \ +}) +#else +# define plist_first_entry(head, type, member) \ container_of(plist_first(head), type, member) +#endif /** * plist_first - return the first node (and thus, highest priority) diff -puN lib/plist.c~pi-futex-patchset-v4-update lib/plist.c --- devel/lib/plist.c~pi-futex-patchset-v4-update 2006-04-01 16:26:33.000000000 -0800 +++ devel-akpm/lib/plist.c 2006-04-01 16:26:33.000000000 -0800 @@ -26,6 +26,44 @@ #include #include +#ifdef CONFIG_DEBUG_PI_LIST + +static void plist_check_prev_next(struct list_head *t, struct list_head *p, + struct list_head *n) +{ + if (n->prev != p || p->next != n) { + printk("top: %p, n: %p, p: %p\n", t, t->next, t->prev); + printk("prev: %p, n: %p, p: %p\n", p, p->next, p->prev); + printk("next: %p, n: %p, p: %p\n", n, n->next, n->prev); + WARN_ON(1); + } +} + +static void plist_check_list(struct list_head *top) +{ + struct list_head *prev = top, *next = top->next; + + plist_check_prev_next(top, prev, next); + while (next != top) { + prev = next; + next = prev->next; + plist_check_prev_next(top, prev, next); + } +} + +static void plist_check_head(struct plist_head *head) +{ + WARN_ON(!head->lock); + if (head->lock) + WARN_ON_SMP(!spin_is_locked(head->lock)); + plist_check_list(&head->prio_list); + plist_check_list(&head->node_list); +} + +#else +# define plist_check_head(h) do { } while (0) +#endif + /** * plist_add - add @node to @head * @@ -36,6 +74,7 @@ void plist_add(struct plist_node *node, { struct plist_node *iter; + plist_check_head(head); WARN_ON(!plist_node_empty(node)); list_for_each_entry(iter, &head->prio_list, plist.prio_list) { @@ -52,6 +91,8 @@ lt_prio: list_add_tail(&node->plist.prio_list, &iter->plist.prio_list); eq_prio: list_add_tail(&node->plist.node_list, &iter->plist.node_list); + + plist_check_head(head); } /** @@ -62,6 +103,8 @@ eq_prio: */ void plist_del(struct plist_node *node, struct plist_head *head) { + plist_check_head(head); + if (!list_empty(&node->plist.prio_list)) { struct plist_node *next = plist_first(&node->plist); @@ -70,4 +113,6 @@ void plist_del(struct plist_node *node, } list_del_init(&node->plist.node_list); + + plist_check_head(head); } _