Messages in this thread | | | Subject | Re: When to save/restore_flags() vs cli/sti() | From | Jes Sorensen <> | Date | 26 Feb 1999 10:10:06 +0100 |
| |
>>>>> "Doug" == Doug Ledford <dledford@redhat.com> writes:
Doug> Just becuase I've not seen this mentioned and I'm being anal Doug> here for people reading this thread thay may not know this. Doug> save_flags(flags); by itself will not do anything truly Doug> interesting. You really need this construct:
Doug> save_flags(flags); /* save the current cpu flags */ cli(); /* Doug> actually turn interrupts off */ ... do stuff Doug> restore_flags(flags); /* restore the old cpu state */
Ok lets take it one step further then ;-)
On SMP cli(), save_flags() etc. are really expensive as they need to synchronize across all processors. Therefore using save_flag();cli() ... restore_flags(); in time critical code is a very bad idea.
In the past, before we had spin locks, we used to do it as a quick way to avoid anybody else fiddling with a data structure while we were messing with it, however this is now in a way coming back to bite us.
So for time critical code it is a very good idea to look at spin_lock_irqsave()/spin_unlock_irqrestore() - they will disable interrupts on the local processor take a spin lock thus not blocking the other processors until they try to get beyond the lock in question. For UP machines they will simply turn into the old save_flags();cli();/restore_flags(); set.
Jes
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |