Skip to contentSkip to conversation

Kernel Janitor's TODO list

ANNOUNCE Manfred Spraul 15 participants 27 messages Jan 28, 2001 – Feb 16, 2001

lore
Share & tools
lore
#0 lore raw
Quoted 4 lines

Anything which uses sleep_on() has a 90% chance of being broken. Fix them all, because we want to remove sleep_on() and friends in 2.5.

Then you can add 'calling schedule() with disabled local interrupts()' to your list.

--
Manfred
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw

Em Sun, Jan 28, 2001 at 05:14:37PM +0100, Manfred Spraul escreveu:

Quoted 7 lines
Quoted 4 lines

Anything which uses sleep_on() has a 90% chance of being broken. Fix them all, because we want to remove sleep_on() and friends in 2.5.

Then you can add 'calling schedule() with disabled local interrupts()' to your list.

any example of code doing this now? That way we can at least point it to interested people and say "look at driver foobar in kernel x.y.z and see how its wrong"

- Arnaldo
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw
In reply to Manfred Spraul
Quoted 7 lines · Arnaldo Carvalho de Melo

Em Sun, Jan 28, 2001 at 05:14:37PM +0100, Manfred Spraul escreveu:

Quoted 5 lines
Quoted 4 lines

Anything which uses sleep_on() has a 90% chance of being broken. Fix them all, because we want to remove sleep_on() and friends in 2.5.

Quoted 7 lines
Quoted 2 lines

Then you can add 'calling schedule() with disabled local interrupts()' to your list.

any example of code doing this now? That way we can at least point it to interested people and say "look at driver foobar in kernel x.y.z and see how its wrong"

It isn't wrong to call schedule() with disabled interrupts - it's a feature ;-)
Those 10% sleep_on() users that aren't broken use it:

 for(;;) {
	cli();
	if(condition)
		break;
	sleep_on(&my_wait_queue);
	sti();

}

E.g. TIOCMIWAIT in drivers/char/serial.c - a nearly correct sleep_on() user.

But I doubt that 10% of the sleep_on() users are non-broken...

If you remove sleep_on(), then you can disallow calling schedule() with disabled local interrupts.

--
Manfred
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#3 lore raw
Quoted 11 lines · Manfred Spraul

It isn't wrong to call schedule() with disabled interrupts - it's a feature ;-)
Those 10% sleep_on() users that aren't broken use it:

 for(;;) {
	cli();
	if(condition)
		break;
	sleep_on(&my_wait_queue);
	sti();

}

That's valid iff the wake_up() can only happen from an ISR.

Quoted 2 lines

E.g. TIOCMIWAIT in drivers/char/serial.c - a nearly correct sleep_on() user.

TIOCMIWAIT does restore_flags() before interruptible_sleep_on(). It's broken too.

Anyway, if you're feeling pedantic, consider what happens if shutdown() is called from rs_close() just before sleep_on() is called. Regardless of whether interrupts are disabled.

Quoted 1 line

But I doubt that 10% of the sleep_on() users are non-broken...

There are cases where you don't care if you miss a wakeup because you have a timeout. So it's only suboptimal rather than broken. I did produce a patch to BUG() in sleep_on if the BKL isn't held, at one point. It was quite interesting.

Quoted 2 lines

If you remove sleep_on(), then you can disallow calling schedule() with disabled local interrupts.

The remaining valid users of sleep_on are mainly filesystems - much fs code gets called with the BKL held. I expect that to change during 2.5, at which point sleep_on can be terminated with extreme prejudice.

Signature · 7 lines
dwmw2


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#4 lore raw
Quoted 4 lines · David Woodhouse

TIOCMIWAIT does restore_flags() before interruptible_sleep_on(). It's broken too.

Yes, and I found a second bug: it doesn't sti() immediately after interruptible_sleep_on(), thus cli() doesn't reacquire the global irq lock --> the atomic copy won't be atomic on SMP.

And one more point for the Janitor's list:
Get rid of superflous irqsave()/irqrestore()'s - in 90% of the cases either spin_lock_irq() or spin_lock() is sufficient. That's both faster and better readable.

spin_lock_irq(): you know that the function is called with enabled interrupts.
spin_lock(): can be used in hardware interrupt handlers when only one hardware interrupt uses that spinlocks (most hardware drivers), or when all hardware interrupt handler set the SA_INTERRUPT flag (e.g. rtc and timer interrupt)

There is one more rule when you can use spin_lock_irq():
if you know that the function might sleep. E.g. compare make_request from 2.2.18 and __make_request() from 2.4.
Since __get_request_wait() can sleep, the callers of make_request() cannot rely on disabled interrupts, thus spin_lock_irq instead of spin_lock_irqsave().

--
Manfred
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw

Hi,

Quoted 11 lines · Manfred Spraul

And one more point for the Janitor's list:
Get rid of superflous irqsave()/irqrestore()'s - in 90% of the cases either spin_lock_irq() or spin_lock() is sufficient. That's both faster and better readable.

spin_lock_irq(): you know that the function is called with enabled interrupts.
spin_lock(): can be used in hardware interrupt handlers when only one hardware interrupt uses that spinlocks (most hardware drivers), or when all hardware interrupt handler set the SA_INTERRUPT flag (e.g. rtc and timer interrupt)

This is not a bug and only helps to make drivers nonportable. Please, don't do this.

bye, Roman

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#6 lore raw

This is driving me crazy! There is absolutely no documentation anywhere that tells you when to use or not use sleep_on or spin_lock_whatever or any of these calls. How is anyone supposed to know how to use these functions?! The post I quoted below just proves that a lot of people think they know but apparently don't! In fact, I predict that an argument between the two posters and a few others will soon ensue over who is right.

What makes it more frustrating is that some people on this list talk as if things things are common knowledge. I've been following this mailing list for months, and until today I had no idea sleep_on was bad. All the documentation I've read to date freely uses sleep_on in the sample code. In fact, I still don't even know WHY it's bad. Not only that, but what am I supposed to use instead?

This is what I find most frustrating about Linux. If I were a Windows driver programmer, I could walk into any bookstore and pick up any of a dozen books that explains everything, leaving no room for doubt.

** Reply to message from Roman Zippel <[email protected]> on Sun, 28 Jan 2001 19:51:57 +0100 (MET)

Quoted 25 lines

Hi,

Quoted 11 lines · Manfred Spraul

And one more point for the Janitor's list:
Get rid of superflous irqsave()/irqrestore()'s - in 90% of the cases either spin_lock_irq() or spin_lock() is sufficient. That's both faster and better readable.

spin_lock_irq(): you know that the function is called with enabled interrupts.
spin_lock(): can be used in hardware interrupt handlers when only one hardware interrupt uses that spinlocks (most hardware drivers), or when all hardware interrupt handler set the SA_INTERRUPT flag (e.g. rtc and timer interrupt)

This is not a bug and only helps to make drivers nonportable. Please, don't do this.

bye, Roman

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

Signature · 9 lines
Timur Tabi - [email protected]
Interactive Silicon - http://www.interactivesi.com

When replying to a mailing-list message, please direct the reply to the mailing list only.  Don't send another copy to me.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#7 lore raw
Quoted 3 lines · Timur Tabi

This is driving me crazy! There is absolutely no documentation anywhere that tells you when to use or not use sleep_on or spin_lock_whatever or any of these calls.

huh ?

http://www.kernelnewbies.org/books.php3

/usr/src/linux-2.4/Documentation/DocBook

/usr/src/linux/*

try the last one on Windows. Please get your facts at least remotely near the truth before you rant on linux-kernel again

john

Signature · 7 lines
"To be fair i do look quite like a monkey ..."
	- Peter Reid

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#8 lore raw
Quoted 4 lines · John Levon

huh ?

http://www.kernelnewbies.org/books.php3

Quoted 10 lines

/usr/src/linux-2.4/Documentation/DocBook

/usr/src/linux/*

try the last one on Windows. Please get your facts at least remotely near the truth before you rant on linux-kernel again

john

Umm, john.. He IS right. I've been following the linux kernel list for QUITE some time, though actively asking questions on it for the last 2 months. I've read through the docs in /usr/src/linux/Documentation/* and i hear one more person tell me to "read the source" I'll go nuts.

SOURCE CODE ONLY MAKES SENSE TO THOSE THAT EITHER WROTE IT OR WORK WITH IT EVERYDAY!

And don't tell me "Well, then you shouldn't be touching the kernel if you're not a developer" because that's crap too.

Simply put, with all bitterness and finger pointing aside, WHERE do we find information on various kernel functions, their general usage (as in the WHY, not only the HOW) and reasonings on why not to use some vs. others.

Remember, most of you guys have been coding for years, or working on the kernel for years. Some of us don't have that level of expertise, are trying to get it, and feel like we're being told that information is a private domain we aren't allowed in to.

Me personally, I'd be happy with a list of all the finctions in the linux kernel, a brief description of their usage and a singl elink on where to find more info about that particular function.

Just my 2 cents worth.

David D.W. Downey

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#9 lore raw
Quoted 4 lines · David D.W. Downey

Simply put, with all bitterness and finger pointing aside, WHERE do we find information on various kernel functions, their general usage (as in the WHY, not only the HOW) and reasonings on why not to use some vs. others.

/usr/src/linux/Documentation

Quoted 3 lines

Me personally, I'd be happy with a list of all the finctions in the linux kernel, a brief description of their usage and a singl elink on where to find more info about that particular function.

make pdfdocs
acroread Documentation/DocBook/kernel-api.pdf

(Check out the other .pdf's in that dir too)

You may also make sgmldocs/psdocs/htmldocs

regards,

Davej.

Signature · 7 lines
| Dave Jones.        http://www.suse.de/~davej
| SuSE Labs

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#10 lore raw

** Reply to message from [email protected] on Mon, 29 Jan 2001 20:44:55 +0000 (GMT)

Quoted 1 line

make pdfdocs

[ttabi@one DocBook]$ make pdfdocs Makefile:140: /Rules.make: No such file or directory

There's no Rules.make anywhere on my hard drive.

Signature · 9 lines
Timur Tabi - [email protected]
Interactive Silicon - http://www.interactivesi.com

When replying to a mailing-list message, please direct the reply to the mailing list only.  Don't send another copy to me.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#11 lore raw
In reply to David D.W. Downey
Quoted 7 lines · Timur Tabi

** Reply to message from [email protected] on Mon, 29 Jan 2001 20:44:55 +0000 (GMT)

Quoted 1 line

make pdfdocs

[ttabi@one DocBook]$ make pdfdocs Makefile:140: /Rules.make: No such file or directory

You have to be in the top level directory, not the DocBook one.

Quoted 2 lines

There's no Rules.make anywhere on my hard drive.

Made by 'make config'?

Signature · 9 lines
Regards,
        Rasmus([email protected])

"God prevent we should ever be twenty years without a revolution." 
  -- Thomas Jefferson
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#12 lore raw
In reply to David D.W. Downey

[Timur Tabi]

Quoted 4 lines

[ttabi@one DocBook]$ make pdfdocs Makefile:140: /Rules.make: No such file or directory

There's no Rules.make anywhere on my hard drive.

There had better be one in '../..'. Do the 'make pdfdocs' from the top level of the kernel source tree.

Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#13 lore raw
In reply to David D.W. Downey
Quoted 4 lines · [email protected] said:

Remember, most of you guys have been coding for years, or working on
the kernel for years. Some of us don't have that level of expertise, are trying to get it, and feel like we're being told that information is a private domain we aren't allowed in to.

Note that this is _precisely_ the reason I'm advocating the removal of sleep_on(). When I was young and stupid (ok, "younger and stupider") I used sleep_on() in my code. I pondered briefly the fact that I really couldn't convince myself that it was safe, but because it was used in so many other places, I decided I had to be missing something, and used it anyway.

I was wrong. I was copying broken code. And now I want to remove all those bad examples - for the benefit of those who are looking at them now and are tempted to copy them.

--
dwmw2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#14 lore raw

** Reply to message from David Woodhouse <[email protected]> on Tue, 30 Jan 2001 11:11:27 +0000

Quoted 9 lines

Note that this is _precisely_ the reason I'm advocating the removal of sleep_on(). When I was young and stupid (ok, "younger and stupider") I used sleep_on() in my code. I pondered briefly the fact that I really couldn't convince myself that it was safe, but because it was used in so many other places, I decided I had to be missing something, and used it anyway.

I was wrong. I was copying broken code. And now I want to remove all those bad examples - for the benefit of those who are looking at them now and are tempted to copy them.

What is wrong with sleep_on()?

Signature · 9 lines
Timur Tabi - [email protected]
Interactive Silicon - http://www.interactivesi.com

When replying to a mailing-list message, please direct the reply to the mailing list only.  Don't send another copy to me.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#15 lore raw
Quoted 1 line · [email protected] said:

What is wrong with sleep_on()?

Are you asking me? If so, why did I not receive a copy in my inbox? If I want to filter duplicates locally, I can. I don't.

It's almost impossible to use it safely, and the few ways you _can_ use it safely are frowned upon, because they mostly involve using the BKL, usage of which is slowly being phased out in favour of finer-grained locking.

This kind of code is far too common:

 if (!event) {
	/* BUT WHAT IF THE EVENT ARRIVES _NOW_? */

sleep_on(&event_wait);
}

--
dwmw2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#16 lore raw
In reply to David D.W. Downey
Quoted 9 lines · Timur Tabi

** Reply to message from David Woodhouse

Quoted 6 lines

Note that this is _precisely_ the reason I'm advocating the removal of sleep_on(). When I was young and stupid (ok, "younger and stupider") I used sleep_on() in my code. I pondered briefly the fact that I really couldn't convince myself that it was safe, but because it was used in so many other places, I decided I had to be missing something, and used it anyway.

Quoted 5 lines
Quoted 3 lines

I was wrong. I was copying broken code. And now I want to remove all those bad examples - for the benefit of those who are looking at them now and are tempted to copy them.

What is wrong with sleep_on()?

If you have a task that looks like:

loop:
<do something important>
sleep_on(q)

And you do wakeup(q) hoping to get something important done, then if the task isn't sleeping at the time of the wakeup it will ignore the wakeup and go to sleep, which imay not be what you wanted.

--
Daniel
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#17 lore raw

** Reply to message from Daniel Phillips <[email protected]> on Wed, 31 Jan 2001 01:06:08 +0100

Quoted 11 lines
Quoted 1 line

What is wrong with sleep_on()?

If you have a task that looks like:

loop:
<do something important>
sleep_on(q)

And you do wakeup(q) hoping to get something important done, then if the task isn't sleeping at the time of the wakeup it will ignore the wakeup and go to sleep, which imay not be what you wanted.

Ok, so how should this code have been written?

Signature · 9 lines
Timur Tabi - [email protected]
Interactive Silicon - http://www.interactivesi.com

When replying to a mailing-list message, please direct the reply to the mailing list only.  Don't send another copy to me.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#18 lore raw
Quoted 11 lines · Timur Tabi
Quoted 9 lines

If you have a task that looks like:

loop:
<do something important>
sleep_on(q)

And you do wakeup(q) hoping to get something important done, then if the task isn't sleeping at the time of the wakeup it will ignore the wakeup and go to sleep, which imay not be what you wanted.

Ok, so how should this code have been written?

DECLARE_WAIT_QUEUE(wait, current);

while(1) {
	do_something_important()

	set_current_state(TASK_INTERRUPTIBLE);
	add_wait_queue(&q, &wait);

	/* Now if something arrives, we'll be 'woken' immediately -
	   - that is; our state will be set to TASK_RUNNING */

	if (!stuff_to_do()) {
		/* If the 'stuff' arrives here, we get woken anyway,
			so the schedule() returns immediately. You 
			can use schedule_timeout() here if you need
			a timeout, obviously */
		schedule();
	}

	set_current_state(TASK_RUNNING);
	remove_wait_queue(&q, &wait);

	if (signal_pending(current)) {
		/* You've been signalled. Deal with it. If you don't 
			want signals to wake you, use TASK_UNINTERRUPTIBLE
			above instead of TASK_INTERRUPTIBLE. Be aware
			that you'll add one to the load average all the
			time your task is sleeping then. */
		return -EINTR;
	}
}	

Alternatively, you could up() a semaphore for each task that's do be done, and down() it again each time you remove one from the queue.

Signature · 7 lines
dwmw2


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#19 lore raw
In reply to John Levon
Quoted 2 lines · David D.W. Downey

And don't tell me "Well, then you shouldn't be touching the kernel if you're not a developer" because that's crap too.

No this is a good advise. "Never touch anything you don't understand." If you like to develop for Linux, you should understand the API you use and if you don't understand it, either learn more about it (e.g. reading the source ;-)) or stop using it.

Regards

Ingo Oeser, reading it since 1996

Signature · 6 lines
10.+11.03.2001 - 3. Chemnitzer LinuxTag <http://www.tu-chemnitz.de/linux/tag>
         <<<<<<<<<<<<       come and join the fun       >>>>>>>>>>>>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
#20 lore raw
In reply to Manfred Spraul
Quoted 4 lines · Timur Tabi

What makes it more frustrating is that some people on this list talk as if things things are common knowledge. I've been following this mailing list for months, and until today I had no idea sleep_on was bad. All the documentation I've read to date freely uses sleep_on in the sample code. In fact, I still

When Linux documentation uses sleep_on it is probably broken and should be fixed. Unix (not linux) documentation uses sleep_on commonly, but Unix has different wait queue semantics and it is usually safe there.

You're probably reading the wrong documentation, e.g. Rusty's kernel hacking HOWTO describes it correctly (and a lot of the other rules)

Quoted 2 lines

don't even know WHY it's bad. Not only that, but what am I supposed to use instead?

You can miss wakeups. The standard pattern is:

	get locks

	add_wait_queue(&waitqueue, &wait);
	for (;;) { 
		if (condition you're waiting for is true) 
			break; 
		unlock any non sleeping locks you need for condition
		__set_task_state(current, TASK_UNINTERRUPTIBLE); 
		schedule(); 
		__set_task_state(current, TASK_RUNNING); 
		reaquire locks
	}
	remove_wait_queue(&waitqueue, &wait); 

When you want to handle signals you can check for them before or after the condition check. Also use TASK_INTERRUPTIBLE in this case.

When you need a timeout use schedule_timeout().

For some cases you can also use the wait_event_* macros which encapsulate that for you, assuming condition can be tested/used lockless.

An alternative is to use a semaphore, although that behaves a bit differently under load.

Quoted 3 lines

This is what I find most frustrating about Linux. If I were a Windows driver programmer, I could walk into any bookstore and pick up any of a dozen books that explains everything, leaving no room for doubt.

Just why are Windows drivers so buggy then?

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#21 lore raw

Hi,

Quoted 15 lines · Andi Kleen

You can miss wakeups. The standard pattern is:

	get locks

	add_wait_queue(&waitqueue, &wait);
	for (;;) { 
		if (condition you're waiting for is true) 
			break; 
		unlock any non sleeping locks you need for condition
		__set_task_state(current, TASK_UNINTERRUPTIBLE); 
		schedule(); 
		__set_task_state(current, TASK_RUNNING); 
		reaquire locks
	}
	remove_wait_queue(&waitqueue, &wait); 

You still miss wakeups. :)
Always set the task state first, then check the condition. See the wait_event*() macros you mentioned for the right order.

bye, Roman

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#22 lore raw
In reply to Andi Kleen
Quoted 1 line · Roman Zippel

You still miss wakeups. :)

And there was another race in it, I know. The first __set_task_state has to be set_task_state to get the right memory write order on SMP.

-Andi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#23 lore raw
In reply to Andi Kleen
Quoted 20 lines · Roman Zippel

Hi,

Quoted 15 lines · Andi Kleen

You can miss wakeups. The standard pattern is:

	get locks

	add_wait_queue(&waitqueue, &wait);
	for (;;) { 
		if (condition you're waiting for is true) 
			break; 
		unlock any non sleeping locks you need for condition
		__set_task_state(current, TASK_UNINTERRUPTIBLE); 
		schedule(); 
		__set_task_state(current, TASK_RUNNING); 
		reaquire locks
	}
	remove_wait_queue(&waitqueue, &wait); 
Quoted 3 lines

You still miss wakeups. :)
Always set the task state first, then check the condition. See the wait_event*() macros you mentioned for the right order.

If the wakeup happens with the spinlock acquired (as the above code seems to assume) you don't need to set the task state as uninterruptible before checking the condition, however the above is wrong anyways because it should do __set_task_state _before_ releasing the lock and not after.

Andrea

#24 lore raw
In reply to Andi Kleen
Quoted 5 lines · Andi Kleen
Quoted 1 line · Roman Zippel

You still miss wakeups. :)

And there was another race in it, I know. The first __set_task_state has to be set_task_state to get the right memory write order on SMP.

If the wakeup is serialized by the spinlock too (as your code looks like to assume) you can legally use __set_task_state instead of set_task_state. An example of such an usage (where wakeup is serialized by the spinlock) is lock_sock/unlock_sock.

Andrea

#25 lore raw
In reply to Manfred Spraul
Quoted 4 lines

And one more point for the Janitor's list:
Get rid of superflous irqsave()/irqrestore()'s - in 90% of the cases either spin_lock_irq() or spin_lock() is sufficient. That's both faster and better readable.

Expect me to drop any submissions that do this. I'd rather take the two clock hit in most cases because the effect of spin_lock_irq() being used and people then changing which functions call each other and producing impossible to debug irq mishandling cases is unacceptable.

The original Linux network code did this with sti() not save/restore flags. I've been there before, I am not going to allow a rerun of that disaster for a few cycles

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/

#26 lore raw
Quoted 11 lines · Alan Cox
Quoted 5 lines

And one more point for the Janitor's list:
Get rid of superflous irqsave()/irqrestore()'s - in 90% of the cases either spin_lock_irq() or spin_lock() is sufficient. That's both faster and better readable.

Expect me to drop any submissions that do this. I'd rather take the two clock hit in most cases because the effect of spin_lock_irq() being used and people then changing which functions call each other and producing impossible to debug irq mishandling cases is unacceptable.

IMHO the main problem of spin_lock_irqsave is not the lost cpu cycles, but readability:

void public_function()

{
	spin_lock_irqsave();
	if(rare_event)
		internal_function()
	spin_unlock_irqrestore();
}

static void internal_function()

{
	...
	spin_unlock_irq();
	kmalloc(GFP_KERNEL);
	spin_lock_irq();
}

IMHO functions that are not irq safe somewhere hidden in internal functions should never use spin_lock_irqsave(). make_request() in 2.2 falls into that category, and the irqsave() was removed.

Obviously spin_lock_irq() instead of spin_lock_irqsave() should only be done if the implementation doesn't support disabled interrupts, not if currently noone calls a function with disabled interrupts.

(make_request(), down(), smp_call_function()...)

Quoted 3 lines

The original Linux network code did this with sti() not save/restore flags. I've been there before, I am not going to allow a rerun of that disaster for a few cycles

I hope that during 2.5 we can add debugging into spin_lock_irq():
BUG() if it's called with disabled interrupts.
It's not yet possible due to schedule() with disabled interrupts (I tried it a few months ago)

--
Manfred
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/