Skip to contentSkip to conversation

fix loop with disabled tasklets

PATCH Momchil Velikov 4 participants 7 messages Nov 11, 2001 – Nov 12, 2001

lore
Share & tools
lore
#0 lore raw

Mathijs,

You may want to have a look at the following patches (tested by visual inspection):

softirq.c renamed from softirq.c.orig +12 -22
@@ -188,22 +188,17 @@ static void tasklet_action(struct softir
 
 		list = list->next;
 
+		if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
+			BUG();
+
 		if (tasklet_trylock(t)) {
-			if (!atomic_read(&t->count)) {
-				if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
-					BUG();
+			if (!atomic_read(&t->count))
 				t->func(t->data);
-				tasklet_unlock(t);
-				continue;
-			}
 			tasklet_unlock(t);
+			continue;
 		}
 
-		local_irq_disable();
-		t->next = tasklet_vec[cpu].list;
-		tasklet_vec[cpu].list = t;
-		__cpu_raise_softirq(cpu, TASKLET_SOFTIRQ);
-		local_irq_enable();
+		tasklet_schedule(t);
 	}
 }
 
@@ -222,22 +217,17 @@ static void tasklet_hi_action(struct sof
 
 		list = list->next;
 
+		if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
+			BUG();
+
 		if (tasklet_trylock(t)) {
-			if (!atomic_read(&t->count)) {
-				if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
-					BUG();
+			if (!atomic_read(&t->count))
 				t->func(t->data);
-				tasklet_unlock(t);
-				continue;
-			}
 			tasklet_unlock(t);
+			continue;
 		}
 
-		local_irq_disable();
-		t->next = tasklet_hi_vec[cpu].list;
-		tasklet_hi_vec[cpu].list = t;
-		__cpu_raise_softirq(cpu, HI_SOFTIRQ);
-		local_irq_enable();
+		tasklet_hi_schedule(t);
 	}
 }
 
interrupt.h renamed from interrupt.h.orig +4 -2
@@ -185,13 +185,15 @@ static inline void tasklet_disable(struc
 static inline void tasklet_enable(struct tasklet_struct *t)
 {
 	smp_mb__before_atomic_dec();
-	atomic_dec(&t->count);
+	if (atomic_dec_and_test(&t->count))
+		tasklet_schedule(t);
 }
 
 static inline void tasklet_hi_enable(struct tasklet_struct *t)
 {
 	smp_mb__before_atomic_dec();
-	atomic_dec(&t->count);
+	if (atomic_dec_and_test(&t->count))
+		tasklet_hi_schedule(t);
 }
 
 extern void tasklet_kill(struct tasklet_struct *t);

Regards,
-velco

#1 lore raw
Quoted 2 lines · Momchil Velikov

You may want to have a look at the following patches (tested by visual inspection):

I like this one. I think it is what Andrea was going for, without the changes to interrupt.h. If we are going for thisone we should add some comments to interrupt.h warning about deadlocks etc.

still working on a patch that adds a cpu field to the tasklet_struct. Looking for races takes me a long time :).

me

#2 lore raw

From: Mathijs Mohlmann <[email protected]>
Date: Mon, 12 Nov 2001 08:46:08 +0100 (CET)

Quoted 2 lines · Momchil Velikov

You may want to have a look at the following patches (tested by visual inspection):

I like this one.

I don't like these changes, just make DECLARE_TASKLET_DISABLED and long-term tasklet_disable()'s be illegal.

There is only one abuser of this (keyboard), and it is easily cured.

Franks a lot,
David S. Miller
[email protected]

#3 lore raw
In reply to Mathijs Mohlmann
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Mathijs" == Mathijs Mohlmann <[email protected]> writes:

Quoted 2 lines · Momchil Velikov
Quoted 2 lines

You may want to have a look at the following patches (tested by visual inspection):

Mathijs> I like this one. I think it is what Andrea was going for, Mathijs> without the changes to interrupt.h. If we are going for

In this patch, the first thing is to deschedule the tasklet. So, the changes to interrupt.h are needed in order to put back the tasklet in the queue.

Mathijs> thisone we should add some comments to interrupt.h warning Mathijs> about deadlocks etc.

What deadlocks ? ;)

Mathijs> still working on a patch that adds a cpu field to the Mathijs> tasklet_struct. Looking for races takes me a long time :).

I think we can ignore the cpu whenever a tasklet is scheduled and disabled, treating it as not scheduled at all.

Regards,
-velco

#4 lore raw
Quoted 3 lines · On 12-Nov-2001 Momchil Velikov wrote:

In this patch, the first thing is to deschedule the tasklet. So, the changes to interrupt.h are needed in order to put back the tasklet in the queue.

I know, but Andrea suggested not to allow scheduling of disabled tasklets Also, enableing the tasklet will result in a scheduled tasklet, regardless whether it was scheduled. Plus, we are not sure if it is scheduled on the same cpu that did the tasklet_schedule (but i might be the only one who cares about this ;)

Quoted 3 lines

Mathijs> thisone we should add some comments to interrupt.h warning Mathijs> about deadlocks etc.
What deadlocks ? ;)

well, loops. Dont use tasklet_kill on disabled tasklet or on not scheduled tasklets.

me

Signature · 1 line
        me
#5 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Mathijs" == Mathijs Mohlmann <[email protected]> writes:

Quoted 3 lines · Mathijs> On 12-Nov-2001 Momchil Velikov wrote:
Quoted 3 lines

In this patch, the first thing is to deschedule the tasklet. So, the changes to interrupt.h are needed in order to put back the tasklet in the queue.

Mathijs> I know, but Andrea suggested not to allow scheduling of Mathijs> disabled tasklets Also, enableing the tasklet will result in

Disabled tasklets are not scheduled by enable_tasklet (). A disabled tasklet may temporarily appear in the queue, but nevertheless tasklet_action will remove it. It seems gross to traverse the list in order to remove a tasklet at the first disable.

Mathijs> a scheduled tasklet, regardless whether it was Mathijs> scheduled.

Hmm, if it isn't scheduled, there is not much sense in disabling it at all.

Mathijs> Plus, we are not sure if it is scheduled on the Mathijs> same cpu that did the tasklet_schedule (but i might be the Mathijs> only one who cares about this ;)

Mathijs> thisone we should add some comments to interrupt.h warning Mathijs> about deadlocks etc.

Quoted 1 line
Quoted 1 line

What deadlocks ? ;)

Mathijs> well, loops. Dont use tasklet_kill on disabled tasklet or on Mathijs> not scheduled tasklets.

Hmm, if TASKLET_STATE_SCHED is not set tasklet_kill will not deadlock. And tasklet_kill yields (?). Doesn't that mean that tasklet_action will be called eventually ?

Regards,
-velco

#6 lore raw
Quoted 2 lines · On 12-Nov-2001 Momchil Velikov wrote:

Hmm, if it isn't scheduled, there is not much sense in disabling it at all.

DECLARE_TASKLET_DISABLED
tasklet_enable

Quoted 3 lines

Hmm, if TASKLET_STATE_SCHED is not set tasklet_kill will not deadlock. And tasklet_kill yields (?). Doesn't that mean that tasklet_action will be called eventually ?

oops, i misread tasklet_unlock_wait. So sorry.

me

Signature · 1 line
        me