Re: use of preempt_count instead of in_atomic() at leds-gpio.c

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <stefanr@...>
Cc: <akpm@...>, <linux-kernel@...>
Date: Sunday, March 23, 2008 - 1:53 am

Hello.


So, just "if (in_atomic()) return;" check is insufficient for detecting
all cases when it is not permitted to sleep. I see.

Is "in_atomic() returns false inside spinlock on non-preemptible kernels."
the only case that the in_atomic() can't tell whether it is permitted to sleep or not?
If this is the only case, can't we somehow know it by remembering
"how many spinlocks does this CPU is holding now" since
"it is not permitted to sleep inside the spinlock" means
"the CPU the current process is running will not change".
Something like

#ifdef CONFIG_COUNT_SPINLOCKS_HELD
atomic_t spinlock_held_counter[NR_CPUS];
#endif

void spin_lock(x)
{
	/* obtain this spinlock. */
#ifdef CONFIG_COUNT_SPINLOCKS_HELD
	/* increment spinlock_held_counter[this_CPU]. */
#endif
}

void spin_unlock(x)
{
#ifdef CONFIG_COUNT_SPINLOCKS_HELD
	/* decrement spinlock_held_counter[this_CPU]. */
#endif
	/* release this spinlock. */
}

bool in_spinlock()
{
#ifdef CONFIG_COUNT_SPINLOCKS_HELD
	/* return spinlock_held_counter[this_CPU] != 0. */
#else
	return false;
#endif
}

and use "if (in_atomic() || in_spinlock()) return;" instead of "if (in_atomic()) return;" ?
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
use of preempt_count instead of in_atomic() at leds-gpio.c, Henrique de Moraes Holschuh..., (Sun Mar 16, 2:43 pm)
Re: use of preempt_count instead of in_atomic() at leds-gpio.c, Henrique de Moraes Holschuh..., (Thu Mar 20, 6:56 pm)
Re: use of preempt_count instead of in_atomic() at leds-gpio.c, Henrique de Moraes Holschuh..., (Thu Mar 20, 10:10 pm)
Re: use of preempt_count instead of in_atomic() at leds-gpio.c, Henrique de Moraes Holschuh..., (Thu Mar 20, 8:36 pm)
Re: use of preempt_count instead of in_atomic() at leds-gpio.c, Henrique de Moraes Holschuh..., (Fri Mar 21, 8:37 am)
Re: use of preempt_count instead of in_atomic() at leds-gpio.c, Tetsuo Handa, (Sun Mar 23, 1:53 am)
Re: use of preempt_count instead of in_atomic() at leds-gpio.c, Henrique de Moraes Holschuh..., (Wed Mar 26, 12:17 pm)