On Sun, Apr 16, 2006 at 12:38:52 +0200, tyler@xxxxxxxx wrote: > On Sun, Apr 16, 2006 at 04:56:12PM +0800, Min-Hua Chen wrote: > > hi: > > > > Can anyone tell me the usage of in_atomic() macro? > > > > (preempt_count() & ~PREEMPT_ACTIVE) means in interrupt or softirq or > > kernel preemption is disabled. > > kernel_locked() means we are in BKL. > > > > # define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != > > kernel_locked()) > > > > thx > > in_atomic() tries to define if we are in an atomic context. An atomic > context means that the operations won't be interrupted. Um, I'd suggest s/won't/must not/. It is usually used to check for locking/calling rules violatons. > We are in interrupt context if : > _ the BKL is locked > _ or the preemption is disabled Um, no. If BKL is locked, we don't really need to be in interrupt (or any other non-process) context. Atomic context is any such context where schedule() wouldn't work, but BKL, by design, does NOT prevent schedule(). BKL is magic lock that makes SMP an UP. > Here are the diffrent composants of the condition : > _ kernel_locked() returns true if the BKL is locked > _ preempt_count() is true (> 0) if the thread is preemptible (=0) > otherwise > _ ~PREEMPT_ACTIVE is true if preemption is disabled > > This means that to be in atomic : > _ if the BKL is unlocked, the preemption must be disabled > _ if the BKL is locked, we're in atomic mode except if preemption is > disabled and the current thread is preemptible (this means there is a > bug I guess) No bug, really. The comparison is INTEGERAL (there is no other in C, right) and preempt_count actually IS a COUNT, saying how many times preemption disable was requested. We are in atomic, if it was not requested, or it was requested by BKL (ie. kernel_locked() == 1 && preempt_count() == 1). > I'm not sure of what I said : correct me if I'm wrong. Well, it's a pretty tricky stuff. Took me some time to realize what it really compares. -- Jan 'Bulb' Hudec <bulb@xxxxxx>
Attachment:
signature.asc
Description: Digital signature