Skip to contentSkip to conversation

patch] Real-Time Preemption, plist fixes

PATCH Thomas Gleixner 4 participants 30 messages Jun 5, 2005 – Jun 6, 2005 Library code

lore
Share & tools
lore
#0 lore raw

The patch fixes a couple of really annoying issues in the PI code of the Real-Time-Preemption patch

1. Fix the insertion order according to the specified intentions

The desired action was inserting in descending priority and FIFO mode for matching priority. The resulting action of the code was inserting in descending priority and inverse FIFO mode for matching priority.

2. Add the proper list_head initializer in the replacement path.

3. Remove the bogus checks in the delete function for A. !list_empty(&pl->sp_node)
B. else if (pl->prio == pl_new->prio)

Those checks just covered the dumbest implementation detail of plist at all. See 4.)

4. Make plist_entry() work as expected by anybody who ever used list_entry(). Add a plist_first_entry macro for those places where the provided functionality was accidentaly correct.

Application example:

plist_for_each_safe(curr1, next1, &old_owner->pi_waiters) {
	w = plist_entry(curr1, struct rt_mutex_waiter, pi_list);
	.....
}

A moderate experienced Linux programmer would expect, that plist_entry(curr1,...) returns the first entry of the list &old_owner->pi_waiters. Looking into the plist_entry macro after spending hours of witchcrafting reviels that the result is the next entry of the first entry of the list.

#define plist_entry(ptr, type, member) \
container_of(plist_first(ptr), type, member)

No further comment necessary.

5. Modify the comments in the header file to explain the real intention of the implemenation.

Changing fundamental implemtation details and keeping the original comments is just provoking false assumptions. I apologize hereby for all maledictions I addressed to the original author.

Index linux/lib/plist.c
===================================================================

lib/plist.c +18 -16
@@ -9,6 +9,10 @@
  * 2001-2005 (c) MontaVista Software, Inc.
  * Daniel Walker <[email protected]>
  *
+ * (C) 2005 Thomas Gleixner <[email protected]>
+ * Tested and made it functional. I'm still pondering if it is
+ * worth the trouble.
+ *
  * Licensed under the FSF's GNU Public License v2 or later.
  *
  * Based on simple lists (include/linux/list.h).
@@ -17,6 +21,7 @@
 #include <linux/sched.h>
 #include <linux/rt_lock.h>
 
+
 /* Initialize a pl */
 void plist_init(struct plist *pl, int prio)
 {
@@ -63,7 +68,6 @@
 	struct list_head *itr;
 	struct plist *itr_pl, *itr_pl2;
 
-
 	if (pl->prio < INT_MAX) {
 		list_for_each(itr, &plist->dp_node) {
 			itr_pl = list_entry(itr, struct plist, dp_node);
@@ -82,13 +86,12 @@
 	itr_pl = plist;
 
 new_sp_head:
-	itr_pl2 = container_of(itr_pl->dp_node.prev, struct plist, dp_node);
 	list_add_tail(&pl->dp_node, &itr_pl->dp_node);
-	list_add(&pl->sp_node, &itr_pl2->sp_node);
+	list_add_tail(&pl->sp_node, &itr_pl->sp_node);
 	return;
 existing_sp_head:
-	itr_pl2 = container_of(itr_pl->dp_node.prev, struct plist, dp_node);
-	list_add(&pl->sp_node, &itr_pl2->sp_node);
+	itr_pl2 = container_of(itr_pl->dp_node.next, struct plist, dp_node);
+	list_add_tail(&pl->sp_node, &itr_pl2->sp_node);
 	return;
 }
 
@@ -107,22 +110,21 @@
 	return 0;
 }
 
-
 /* Grunt to do the real removal work of @pl from the plist. */
 static inline
-void __plist_del(struct plist *pl)
+void  __plist_del(struct plist *pl)
 {
-	if (!list_empty(&pl->sp_node) && !list_empty(&pl->dp_node)) {
-		/* SP list head, not empty */
-		struct plist *pl_new = container_of(pl->sp_node.prev,
-							struct plist, sp_node);
-
-		if (pl->dp_node.prev == &pl_new->dp_node) {
+	if (!list_empty(&pl->dp_node)) {
+		struct plist *pl_new = container_of(pl->sp_node.next,
+						    struct plist, sp_node);
+	
+		if (pl->dp_node.next == &pl_new->dp_node) {
 			/* end of this priorities list */
 			list_del_init(&pl->dp_node);
-		} else if (pl->prio == pl_new->prio) {
+		} else {
 			list_replace_rcu(&pl->dp_node, &pl_new->dp_node);
-		} 
+			INIT_LIST_HEAD(&pl->dp_node);
+		}
 	}
 	list_del_init(&pl->sp_node);
 }
@@ -162,7 +164,7 @@
  */
 unsigned plist_chprio(struct plist *plist, struct plist *pl, int new_prio)
 {
-	if (new_prio == plist->prio)
+	if (new_prio == pl->prio)
 		return 0;
 
 	__plist_chprio(pl, new_prio);

Index linux/include/linux/plist.h
===================================================================

include/linux/plist.h +50 -20

98 lines not on this page · raw message

Index linux/kernel/rt.c
===================================================================

kernel/rt.c +2 -2
@@ -773,7 +773,7 @@
 	 *
 	 * (same-prio RT tasks go FIFO)
 	 */
-	waiter = plist_entry(&lock->wait_list, struct rt_mutex_waiter, list);
+	waiter = plist_first_entry(&lock->wait_list, struct rt_mutex_waiter, list);
 
 	trace_special_pid(waiter->task->pid, waiter->task->prio, 0);
 
@@ -1351,7 +1351,7 @@
 	 */
 	prio = mutex_getprio(old_owner);
 	if (!plist_empty(&old_owner->pi_waiters)) {
-		w = plist_entry(&old_owner->pi_waiters, struct rt_mutex_waiter, pi_list);
+		w = plist_first_entry(&old_owner->pi_waiters, struct rt_mutex_waiter, pi_list);
 		if (w->task->prio < prio)
 			prio = w->task->prio;
 	}
#1 lore raw
Quoted 2 lines · Thomas Gleixner

The patch fixes a couple of really annoying issues in the PI code of the Real-Time-Preemption patch

You mean really annoying in the plist code?

Quoted 5 lines

1. Fix the insertion order according to the specified intentions

The desired action was inserting in descending priority and FIFO mode for matching priority. The resulting action of the code was inserting in descending priority and inverse FIFO mode for matching priority.

This is good.

Quoted 1 line

2. Add the proper list_head initializer in the replacement path.

Not sure what you mean here.

Quoted 24 lines

3. Remove the bogus checks in the delete function for A. !list_empty(&pl->sp_node)
B. else if (pl->prio == pl_new->prio)

Those checks just covered the dumbest implementation detail of plist at all. See 4.)

4. Make plist_entry() work as expected by anybody who ever used list_entry(). Add a plist_first_entry macro for those places where the provided functionality was accidentaly correct.

Application example:

plist_for_each_safe(curr1, next1, &old_owner->pi_waiters) {
	w = plist_entry(curr1, struct rt_mutex_waiter, pi_list);
	.....
}

A moderate experienced Linux programmer would expect, that plist_entry(curr1,...) returns the first entry of the list &old_owner->pi_waiters. Looking into the plist_entry macro after spending hours of witchcrafting reviels that the result is the next entry of the first entry of the list.

Quoted 4 lines

#define plist_entry(ptr, type, member) \
container_of(plist_first(ptr), type, member)

No further comment necessary.

I already released a patch to fix this.

Quoted 6 lines

5. Modify the comments in the header file to explain the real intention of the implemenation.

Changing fundamental implemtation details and keeping the original comments is just provoking false assumptions. I apologize hereby for all maledictions I addressed to the original author.

You should wait till it's stable before you finalize the documentation.

Quoted 4 lines

+ * (C) 2005 Thomas Gleixner <[email protected]>
+ * Tested and made it functional. I'm still pondering if it is
+ * worth the trouble.
+ *

Gimme a break Thomas..

Daniel

#2 lore raw

Plist cleanup on RT

This includes a change from Thomas Gleixner to make the sp_nodes
FIFO ordered, plus some other small code changes and some small documentation cleanup.

I fixed plist_entry() to work more like list_entry() , and made
the proper update to kernel/rt.c .

Oleg, do you have any correctness concerns with this patch?

Daniel

include/linux/plist.h +10 -5
Index: linux-2.6.11/include/linux/plist.h
===================================================================
@@ -7,6 +7,8 @@
  * 2001-2005 (c) MontaVista Software, Inc.
  * Daniel Walker <[email protected]>
  *
+ * (C) 2005 Thomas Gleixner <[email protected]>
+ *
  * Licensed under the FSF's GNU Public License v2 or later.
  *
  * Based on simple lists (include/linux/list.h).
@@ -28,11 +30,14 @@
  *
  *  - The tier 1 list is the dp list (Different Priority)
  *
- *  - The tier 2 list is the sp list (Same Priority)
+ *  - The tier 2 list is the sp list (Serialized Priority)
+ *
+ * The nodes on the sp list are ordered by priority and can contain
+ * entries which have the same priority. Those entries are ordered
+ * FIFO.
  *
- * All the nodes in a SP list have the same priority, and all the DP
- * lists have different priorities (and are sorted by priority, of
- * course).
+ * The DP lists have different priorities (and are sorted by priority, 
+ * of course).
  *
  * Addition means: look for the DP node in the DP list for the
  * priority of the node and append to the SP list corresponding to
@@ -83,7 +88,7 @@ struct plist {
  * @member:     the name of the list_struct within the struct.
  */
 #define plist_entry(ptr, type, member) \
-        container_of(plist_first(ptr), type, member)
+        container_of(ptr, type, member)
 /**
  * plist_for_each  -       iterate over the plist
  * @pos1:        the type * to use as a loop counter.
kernel/rt.c +2 -2
Index: linux-2.6.11/kernel/rt.c
===================================================================
@@ -773,7 +773,7 @@ static inline struct task_struct * pick_
 	 *
 	 * (same-prio RT tasks go FIFO)
 	 */
-	waiter = plist_entry(&lock->wait_list, struct rt_mutex_waiter, list);
+	waiter = plist_entry(plist_first(&lock->wait_list), struct rt_mutex_waiter, list);
 
 	trace_special_pid(waiter->task->pid, waiter->task->prio, 0);
 
@@ -1351,7 +1351,7 @@ static void __up_mutex(struct rt_mutex *
 	 */
 	prio = mutex_getprio(old_owner);
 	if (!plist_empty(&old_owner->pi_waiters)) {
-		w = plist_entry(&old_owner->pi_waiters, struct rt_mutex_waiter, pi_list);
+		w = plist_entry(plist_first(&old_owner->pi_waiters), struct rt_mutex_waiter, pi_list);
 		if (w->task->prio < prio)
 			prio = w->task->prio;
 	}
lib/plist.c +11 -9
Index: linux-2.6.11/lib/plist.c
===================================================================
@@ -9,6 +9,8 @@
  * 2001-2005 (c) MontaVista Software, Inc.
  * Daniel Walker <[email protected]>
  *
+ * (C) 2005 Thomas Gleixner <[email protected]>
+ *
  * Licensed under the FSF's GNU Public License v2 or later.
  *
  * Based on simple lists (include/linux/list.h).
@@ -80,13 +82,12 @@ static inline void __plist_add_sorted(st
 	itr_pl = plist;
 
 new_sp_head:
-	itr_pl2 = container_of(itr_pl->dp_node.prev, struct plist, dp_node);
 	list_add_tail(&pl->dp_node, &itr_pl->dp_node);
-	list_add(&pl->sp_node, &itr_pl2->sp_node);
+	list_add_tail(&pl->sp_node, &itr_pl->sp_node);
 	return;
 existing_sp_head:
-	itr_pl2 = container_of(itr_pl->dp_node.prev, struct plist, dp_node);
-	list_add(&pl->sp_node, &itr_pl2->sp_node);
+	itr_pl2 = container_of(itr_pl->dp_node.next, struct plist, dp_node);
+	list_add_tail(&pl->sp_node, &itr_pl2->sp_node);
 	return;
 }
 
@@ -110,16 +111,17 @@ unsigned plist_add(struct plist *pl, str
 static inline
 void __plist_del(struct plist *pl)
 {
-	if (!list_empty(&pl->sp_node) && !list_empty(&pl->dp_node)) {
+	if (!list_empty(&pl->sp_node)) {
 		/* SP list head, not empty */
-		struct plist *pl_new = container_of(pl->sp_node.prev,
+		struct plist *pl_new = container_of(pl->sp_node.next,
 							struct plist, sp_node);
 
-		if (pl->dp_node.prev == &pl_new->dp_node) {
+		if (pl->dp_node.next == &pl_new->dp_node) {
 			/* end of this priorities list */
 			list_del_init(&pl->dp_node);
-		} else if (pl->prio == pl_new->prio) {
+		} else {
 			list_replace_rcu(&pl->dp_node, &pl_new->dp_node);
+			INIT_LIST_HEAD(&pl->dp_node);
 		} 
 	}
 	list_del_init(&pl->sp_node);
@@ -160,7 +162,7 @@ void __plist_chprio(struct plist *pl, in
  */
 unsigned plist_chprio(struct plist *plist, struct plist *pl, int new_prio)
 {
-	if (new_prio == plist->prio)
+	if (new_prio == pl->prio)
 		return 0;
 
 	__plist_chprio(pl, new_prio);
#3 lore raw
In reply to Daniel Walker
Quoted 1 line · Daniel Walker

You mean really annoying in the plist code?

Usually I mean what I write.

Quoted 3 lines
Quoted 1 line

2. Add the proper list_head initializer in the replacement path.

Not sure what you mean here.

      list_replace_rcu(&pl->dp_node, &pl_new->dp_node);

+ INIT_LIST_HEAD(&pl->dp_node);

Quoted 5 lines
Quoted 4 lines

4. Make plist_entry() work as expected by anybody who ever used list_entry(). Add a plist_first_entry macro for those places where the provided functionality was accidentaly correct.

I already released a patch to fix this.

Nice to know. Where ?

Quoted 4 lines
Quoted 2 lines

5. Modify the comments in the header file to explain the real intention of the implemenation.

You should wait till it's stable before you finalize the documentation.

Thats plain wrong. Having explanations in place which do not match the code is worse than no explanation at all.

tglx

#4 lore raw
Quoted 6 lines · Thomas Gleixner
Quoted 2 lines · Daniel Walker
Quoted 1 line

I already released a patch to fix this.

Nice to know. Where ?

Ingo pointed me at the patch.

Sorry, but I really don't see the release there.

Quoted 4 lines

The first time I saw these latencies I has the PI abstraction applied, and the most recent time I had the attached patch applied only. This patch is small so I'm not sure if it could have that type of effect on task latency.

It fixes a problem and uncovers others, but your comment is more a question than an explanation for the urgency of the fix. In fact the original implementation leads to solid deadlocks in plist_for_each_safe() loops.

I really can't blame Ingo for ignoring this.

tglx

#5 lore raw
In reply to Thomas Gleixner
Quoted 6 lines · Thomas Gleixner

[...]
*
* Based on simple lists (include/linux/list.h).

include/linux/plist.h +0 -0
@@ -17,35 +22,50 @@
  * a priority too (the highest of all the nodes), stored in the head
  * of the list (that is a node itself).

include/linux/plist.h line 26

Quoted 10 lines
include/linux/plist.h +2 -6
  *
- * Addition is O(1), removal is O(1), change of priority of a node is
- * O(1).
+ * Addition is O(N), removal is O(1), change of priority of a node is
+ * O(N).
  *
- * Addition and change of priority's order is really O(K), where K is
- * a constant being the maximum number of different priorities you
- * will store in the list. Being a constant, it means it is O(1).
- *

What is N? The number of nodes in the list or the number of different priorities? If it is the number of nodes in total this exercise is
worthless: You could just as well have a sorted list.

But I hope and also think that the original explanation was correct.

Esben

#6 lore raw
Quoted 23 lines · Esben Nielsen
Quoted 6 lines · Thomas Gleixner

[...]
*
* Based on simple lists (include/linux/list.h).

include/linux/plist.h +0 -0
@@ -17,35 +22,50 @@
  * a priority too (the highest of all the nodes), stored in the head
  * of the list (that is a node itself).

include/linux/plist.h line 26

Quoted 10 lines
include/linux/plist.h +2 -6
  *
- * Addition is O(1), removal is O(1), change of priority of a node is
- * O(1).
+ * Addition is O(N), removal is O(1), change of priority of a node is
+ * O(N).
  *
- * Addition and change of priority's order is really O(K), where K is
- * a constant being the maximum number of different priorities you
- * will store in the list. Being a constant, it means it is O(1).
- *

What is N? The number of nodes in the list or the number of different priorities? If it is the number of nodes in total this exercise is
worthless: You could just as well have a sorted list.

Quoted 1 line

But I hope and also think that the original explanation was correct.

Sorry, I meant K the number of different priorities.

I just find it completely bogus, that O(K) == O(1) for any K != 1.

tglx

#7 lore raw
Quoted 24 lines · Thomas Gleixner
Quoted 23 lines · Esben Nielsen
Quoted 6 lines · Thomas Gleixner

[...]
*
* Based on simple lists (include/linux/list.h).

include/linux/plist.h +0 -0
@@ -17,35 +22,50 @@
  * a priority too (the highest of all the nodes), stored in the head
  * of the list (that is a node itself).

include/linux/plist.h line 26

Quoted 10 lines
include/linux/plist.h +2 -6
  *
- * Addition is O(1), removal is O(1), change of priority of a node is
- * O(1).
+ * Addition is O(N), removal is O(1), change of priority of a node is
+ * O(N).
  *
- * Addition and change of priority's order is really O(K), where K is
- * a constant being the maximum number of different priorities you
- * will store in the list. Being a constant, it means it is O(1).
- *

What is N? The number of nodes in the list or the number of different priorities? If it is the number of nodes in total this exercise is
worthless: You could just as well have a sorted list.

Quoted 8 lines
Quoted 1 line

But I hope and also think that the original explanation was correct.

Sorry, I meant K the number of different priorities.

I just find it completely bogus, that O(K) == O(1) for any K != 1.

tglx

When K is a constant or bounded by a constant (140 in this application) any function which is O(K) is O(1) per definition of O!

Esben

#8 lore raw
Quoted 2 lines · Esben Nielsen

When K is a constant or bounded by a constant (140 in this application) any function which is O(K) is O(1) per definition of O!

technically you are right. But the question is - while K is considered a constant, and N (nr_running_RT_tasks) is technically not bounded - in practice N is bounded just as much. Have you ever seen any hard-RT application that has more than 140 threads _running at the same time_ on a single CPU? You can even enforce it to be theoretically bounded, via ulimits.

in fact, K and N should be pretty close to each other for most applications. I'd be interested in real application scenarios where N is much (== more than 10 times) larger than K and plists really matter.

Ingo

#9 lore raw
Quoted 13 lines · Ingo Molnar
Quoted 2 lines · Esben Nielsen

When K is a constant or bounded by a constant (140 in this application) any function which is O(K) is O(1) per definition of O!

technically you are right. But the question is - while K is considered a constant, and N (nr_running_RT_tasks) is technically not bounded - in practice N is bounded just as much. Have you ever seen any hard-RT application that has more than 140 threads _running at the same time_ on a single CPU? You can even enforce it to be theoretically bounded, via ulimits.

Quoted 4 lines

in fact, K and N should be pretty close to each other for most applications. I'd be interested in real application scenarios where N is much (== more than 10 times) larger than K and plists really matter.

I think that would only be the case when an application has an error. The problem now is: Say you have two RT applications running, one living in priority 0-49 and one in 50-99. Let us say the second has such an error, like keep spawning threads whichs blocks on a mutex owned by a task which is blocked forever. Without plists such an error will kill the high priority RT task. With plists it will only see a _limited_ effect on it's latency.

You can say plists is better at isolating applications wrt. timing than ordinary sorted lists.

Quoted 2 lines

Ingo

#10 lore raw
In reply to Thomas Gleixner
Quoted 1 line · Thomas Gleixner

5. [...]

#6 looks pretty significant too:

lib/plist.c line 168

Quoted 5 lines

unsigned plist_chprio(struct plist *plist, struct plist *pl, int new_prio) {

lib/plist.c +1 -1
-	if (new_prio == plist->prio)
+	if (new_prio == pl->prio)
 		return 0;

right?

Ingo

#11 lore raw
Quoted 6 lines · Ingo Molnar
Quoted 1 line · Thomas Gleixner

5. [...]

#6 looks pretty significant too:

Quoted 8 lines

lib/plist.c line 168

Quoted 5 lines

unsigned plist_chprio(struct plist *plist, struct plist *pl, int new_prio) {

lib/plist.c +1 -1
-	if (new_prio == plist->prio)
+	if (new_prio == pl->prio)
 		return 0;

right?

Yes, forgot to rant about that :)

tglx

#12 lore raw

Re: [patch] Real-Time Preemption, plist fixes

In reply to Thomas Gleixner
Quoted 3 lines · Thomas Gleixner

+ * (C) 2005 Thomas Gleixner <[email protected]>
+ * Tested and made it functional. I'm still pondering if it is
+ * worth the trouble.

you had a long Saturday night debugging session i guess:

Quoted 1 line

Date: Sun, 05 Jun 2005 02:17:12 +0200

but i think the fundamental question remains even on Sunday mornings - is the plist overhead worth it? Compared to the simple sorted list we exchange O(nr_RT_tasks_running) for O(nr_RT_levels_used) [which is in the 1-100 range], is that a significant practical improvement? By overhead i dont just mean cycle cost, but also architectural flexibility and maintainability.

in any case, i've added most of your fixes and cleanups (changed the O(N) to O(K) and explained K) and have released the -47-17 patch. Daniel, do agree with these changes (in particular the __plist_del() changes?) and is there anything else missing? It looks like we might be near the end of the tunnel and plists are really stabilizing.

Ingo

#13 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 1 line · Ingo Molnar
Quoted 1 line

Date: Sun, 05 Jun 2005 02:17:12 +0200

:)

Quoted 6 lines

but i think the fundamental question remains even on Sunday mornings - is the plist overhead worth it? Compared to the simple sorted list we exchange O(nr_RT_tasks_running) for O(nr_RT_levels_used) [which is in the 1-100 range], is that a significant practical improvement? By overhead i dont just mean cycle cost, but also architectural flexibility and maintainability.

That was my question too.

tglx

#14 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 8 lines · Thomas Gleixner
Quoted 6 lines

but i think the fundamental question remains even on Sunday mornings - is the plist overhead worth it? Compared to the simple sorted list we exchange O(nr_RT_tasks_running) for O(nr_RT_levels_used) [which is in the 1-100 range], is that a significant practical improvement? By overhead i dont just mean cycle cost, but also architectural flexibility and maintainability.

That was my question too.

i think it would be handy to resurrect ALL_TASKS_PI. It was one of the things that stabilized the sorted list approach so quickly. Nothing beats the coverage of running a full graphical desktop with all the PI code active :-)

Ingo

#15 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 4 lines · Ingo Molnar

i think it would be handy to resurrect ALL_TASKS_PI. It was one of the things that stabilized the sorted list approach so quickly. Nothing beats the coverage of running a full graphical desktop with all the PI code active :-)

I keep wondering why I'm dragging ALL_TASKS_PI around in all my patches, since it doesn't work. Why not have it on all the time?

Daniel

#16 lore raw

Re: [patch] Real-Time Preemption, plist fixes

In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 3 lines · Thomas Gleixner

+ * (C) 2005 Thomas Gleixner <[email protected]>
+ * Tested and made it functional. I'm still pondering if it is
+ * worth the trouble.

you had a long Saturday night debugging session i guess:

Quoted 9 lines
Quoted 1 line

Date: Sun, 05 Jun 2005 02:17:12 +0200

but i think the fundamental question remains even on Sunday mornings - is the plist overhead worth it? Compared to the simple sorted list we exchange O(nr_RT_tasks_running) for O(nr_RT_levels_used) [which is in the 1-100 range], is that a significant practical improvement? By overhead i dont just mean cycle cost, but also architectural flexibility and maintainability.

Sorted lists works deterministicly O(1) on UP if no owner of the lock blocks while having the lock. On SMP or worse if an owner blocks in the lock, the wait list can grow very long. Thus insertion of new elements takes a long time - with preemption disabled :-(

If this is supposed to be used for user-space PI as well I would say it would have to be completely bounded, i.e. plists are certainly needed. If it is in the kernel only, you might argue that the code is under control and thus not make very long wait-lists. Therefore it is not worth the extra CPU cycles to use them. However, there is no way to know for sure. In extreme load situations we could end up with a lot of waiters on mmap_sem forinstance.

Esben

#17 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 2 lines · Esben Nielsen

[...] In extreme load situations we could end up with a lot of waiters on mmap_sem forinstance.

what do you mean by extreme load. Extreme number of RT tasks, or extreme number of tasks altogether? The sorted-list implementation i had in -RT had all non-RT tasks handled in an O(1) way - the O(N) component was for adding RT tasks (removal was O(1)).

so the question is - can we have an extreme (larger than 140) number of RT tasks? If yes, why are they all RT - they can have no expectation of good latencies with a possible load factor of 140!

Ingo

#18 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 6 lines · Ingo Molnar
Quoted 2 lines · Esben Nielsen

[...] In extreme load situations we could end up with a lot of waiters on mmap_sem forinstance.

Quoted 8 lines

what do you mean by extreme load. Extreme number of RT tasks, or extreme number of tasks altogether? The sorted-list implementation i had in -RT had all non-RT tasks handled in an O(1) way - the O(N) component was for adding RT tasks (removal was O(1)).

so the question is - can we have an extreme (larger than 140) number of RT tasks? If yes, why are they all RT - they can have no expectation of good latencies with a possible load factor of 140!

I can't really imagine a properly working application having more than 140 RT tasks pounding on the same lock - except maybe if someone tries to run an RT application on one of those Altrix thingies (#CPUS>140 :-).

But as I said I could imagine a situation where you have some really important RT tasks you would like to survive even if your low priority RT tasks does something bad - like keep spawning RT tasks which all waits on the same lock.

Actually this test would make the difference:

thread1:
lock(&badlock);
block_on_some_event_which_might_never_arrive();
unlock(&badlock);

func:
lock(&badlock);
unlock(&badlock);
done=1;

thread2:
while(!done) {
create_thread(func,RTprio=50);
create_thread(func,RTprio=51);
if(done) break;
sleep(1);
}

If you have enough memory for all the tasks, this kind of code would not be a problem with plists - it will only take a lot of memory. On the other hand with sorted lists each thread will take longer time inside raw spinlocks. At some point it will take the whole 1 sec and basicly nothing else can run.

Ofcourse you can prevent this with ulimits...

What I would do in this discussion is to abstract the interface:
The rt_mutex code should not care if plists, sorted lists or what ever are used. It should just have a prio_queue structure and prio_queue_add(), prio_queue_first(), a prio_queue_for_each macro etc. Then Daniel can play along with his plists and have it as a config-option for now. Someone who doesn't care about the memory consumption, could even choose to use the prio_array from the scheduler!

Quoted 2 lines

Ingo

Esben

#19 lore raw

Re: [patch] Real-Time Preemption, plist fixes

In reply to Esben Nielsen
Quoted 4 lines · Esben Nielsen

Sorted lists works deterministicly O(1) on UP if no owner of the lock blocks while having the lock. On SMP or worse if an owner blocks in the lock, the wait list can grow very long. Thus insertion of new elements takes a long time - with preemption disabled :-(

the wait list can grow only as long as the max # of RT tasks is. Sorted lists become 'O(1)' if we added some code that globally limits the number of RT tasks to say 50. E.g. /proc/sys/kernel/max_nr_RT_tasks. A user can override it if he needs more RT tasks. There can be an arbitrary number of SCHED_OTHER tasks.

(note that on Linux there is a RAM-dependent 'max # of tasks' ulimit which is never 'infinity', so theoretically the sorted lists are "O(1)" too. But this is nitpicking.)

Quoted 3 lines

If this is supposed to be used for user-space PI as well I would say it would have to be completely bounded, i.e. plists are certainly needed. [...]

yes, it's supposed to be used for user-space PI too. What do you mean by 'completely bounded'. Do you consider the current worst-case O(100) property of plists a 'completely bounded' solution?

i dont think fusyn's should be made available to non-RT tasks. If this restriction is preserved then fusyn's would become O(max_nr_RT_tasks) too.

Ingo

#20 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 22 lines · Ingo Molnar
Quoted 4 lines · Esben Nielsen

Sorted lists works deterministicly O(1) on UP if no owner of the lock blocks while having the lock. On SMP or worse if an owner blocks in the lock, the wait list can grow very long. Thus insertion of new elements takes a long time - with preemption disabled :-(

the wait list can grow only as long as the max # of RT tasks is. Sorted lists become 'O(1)' if we added some code that globally limits the number of RT tasks to say 50. E.g. /proc/sys/kernel/max_nr_RT_tasks. A user can override it if he needs more RT tasks. There can be an arbitrary number of SCHED_OTHER tasks.

(note that on Linux there is a RAM-dependent 'max # of tasks' ulimit which is never 'infinity', so theoretically the sorted lists are "O(1)" too. But this is nitpicking.)

Quoted 3 lines

If this is supposed to be used for user-space PI as well I would say it would have to be completely bounded, i.e. plists are certainly needed. [...]

Quoted 8 lines

yes, it's supposed to be used for user-space PI too. What do you mean by 'completely bounded'. Do you consider the current worst-case O(100) property of plists a 'completely bounded' solution?

i dont think fusyn's should be made available to non-RT tasks. If this restriction is preserved then fusyn's would become O(max_nr_RT_tasks) too.

My pragmatic side agrees with you. My sense of beauty does not. I think you make 2 small hacks here:
1) Adding a limit like above smells wrong.
2) Making PI only apply to RT tasks isn't beautifull either.

On the other hand the plists are "beautifull". It would sadden me if they are thrown away.

As I said in an earlier mail, I think you should agree on an interface between the rt_mutex code and list structure. Then Daniel can implement and test his plist in user space, somebody else can implement and test the sorted list in userspace and the transition can happen with a switch of a macro and a recompilation.

I hope I will get some time to help out from next weekend. I am taking exams right now.

Quoted 2 lines

Ingo

Esben

#21 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 9 lines · Esben Nielsen
Quoted 3 lines

i dont think fusyn's should be made available to non-RT tasks. If this restriction is preserved then fusyn's would become O(max_nr_RT_tasks) too.

My pragmatic side agrees with you. My sense of beauty does not. I think you make 2 small hacks here:

1) Adding a limit like above smells wrong.
2) Making PI only apply to RT tasks isn't beautifull either.

Enabling PI for all tasks would certainly make plists the only viable choice. To achieve that we'd have to do quite careful coding, as the priorities of SCHED_OTHER tasks can change quite frequently, and the PI code doesnt follow priority changes that well currently.

Ingo

#22 lore raw

Re: [patch] Real-Time Preemption, plist fixes

In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar

yes, it's supposed to be used for user-space PI too. What do you mean by 'completely bounded'. Do you consider the current worst-case O(100) property of plists a 'completely bounded' solution?

i dont think fusyn's should be made available to non-RT tasks. If this restriction is preserved then fusyn's would become O(max_nr_RT_tasks) too.

I think making fusyn RT tasks only would be asking a lot. Fusyn
replaces Futex, and they are both used in pthreads. So non-RT tasks wouldn't be able to use pthreads in userspace, or a big chunk of pthread ..

Daniel

#23 lore raw

Re: [patch] Real-Time Preemption, plist fixes

In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar

in any case, i've added most of your fixes and cleanups (changed the O(N) to O(K) and explained K) and have released the -47-17 patch. Daniel, do agree with these changes (in particular the __plist_del() changes?) and is there anything else missing? It looks like we might be near the end of the tunnel and plists are really stabilizing.

__plist_del was a good fix. I attached a patch on "Plist cleanup on RT" to lkml with what was acceptable to me. A good 60% of Thomas's changes are unacceptable to me.

Daniel

#24 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 3 lines · Daniel Walker

__plist_del was a good fix. I attached a patch on "Plist cleanup on RT" to lkml with what was acceptable to me. A good 60% of Thomas's changes are unacceptable to me.

Would you be so kind to explain that a bit ? Your patch contains _all_ my proposed changes except the additional plist_first_entry macro and the comment cleanup.

So what are the 60% which are unacceptable. Comments ? I'm amused.

tglx

#25 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 11 lines · Thomas Gleixner
Quoted 3 lines · Daniel Walker

__plist_del was a good fix. I attached a patch on "Plist cleanup on RT" to lkml with what was acceptable to me. A good 60% of Thomas's changes are unacceptable to me.

Would you be so kind to explain that a bit ? Your patch contains _all_ my proposed changes except the additional plist_first_entry macro and the comment cleanup.

So what are the 60% which are unacceptable. Comments ? I'm amused.

Whatever was missing was unacceptable.

Daniel

#26 lore raw

Re: [patch] Real-Time Preemption, plist fixes

In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar

but i think the fundamental question remains even on Sunday mornings - is the plist overhead worth it? Compared to the simple sorted list we exchange O(nr_RT_tasks_running) for O(nr_RT_levels_used) [which is in the 1-100 range], is that a significant practical improvement? By overhead i dont just mean cycle cost, but also architectural flexibility and maintainability.

We use it for all tasks . So for instance all priority levels get sorted , not just RT tasks. Most systems aren't going to have many RT tasks, just interrupts and they don't share many locks. However, there are tons of userspace tasks that do get sorted.

I think using plist on the wait_list is worth it. Since there aren't many RT tasks usually . It may be a waste to use it on the pi_waiters.

Daniel

#27 lore raw

Re: [patch] Real-Time Preemption, plist fixes

In reply to Ingo Molnar
Quoted 7 lines · Ingo Molnar

but i think the fundamental question remains even on Sunday mornings - is the plist overhead worth it? Compared to the simple sorted list we exchange O(nr_RT_tasks_running) for O(nr_RT_levels_used) [which is in the 1-100 range], is that a significant practical improvement? By overhead i dont just mean cycle cost, but also architectural flexibility and maintainability.

You'll have to explain the "architectural flexibility and
maintainability" costs . Questioning if plist works correctly isn't a long term maintainability problem, in my mind. I don't see any architectural costs considering the plist API, which is why I saw a clear path to integrate plist in the first place.

For me it's strictly a speed question. I was reviewing V0.7.40-04
and it looks like apples and oranges to me. It's more a question of where do you perfer the latency , in up() or in down() .. plist is slower for non-RT tasks, but non-RT tasks also get the benefit of priority ordering.

Daniel

#28 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 5 lines · Daniel Walker

For me it's strictly a speed question. I was reviewing
V0.7.40-04 and it looks like apples and oranges to me. It's more a question of where do you perfer the latency , in up() or in down() .. plist is slower for non-RT tasks, but non-RT tasks also get the benefit of priority ordering.

what benefit do non-RT tasks get from plists, compared to the ordered list? Non-RT tasks are not PI handled in any way.

Ingo

#29 lore raw

Re: [patch] Real-Time Preemption, plist fixes

Quoted 11 lines · Ingo Molnar
Quoted 5 lines · Daniel Walker

For me it's strictly a speed question. I was reviewing
V0.7.40-04 and it looks like apples and oranges to me. It's more a question of where do you perfer the latency , in up() or in down() .. plist is slower for non-RT tasks, but non-RT tasks also get the benefit of priority ordering.

what benefit do non-RT tasks get from plists, compared to the ordered list? Non-RT tasks are not PI handled in any way.

The original wait list was partial ordered, wasn't it? RT tasks on the front, non-RT at the back. Now the whole list is sorted (including non RT tasks) . So non-RT task will get the lock in priority sorted order, as opposed to just random. Like you said, there is no PI done.

Daniel