linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* preempt.h: some SOFTIRQ_OFFSET should be SOFTIRQ_MASK?
@ 2019-02-05 18:34 Denys Vlasenko
  2019-02-13  4:05 ` Frederic Weisbecker
  0 siblings, 1 reply; 3+ messages in thread
From: Denys Vlasenko @ 2019-02-05 18:34 UTC (permalink / raw)
  To: Frederic Weisbecker, Linux Kernel Mailing List

SOFTIRQ is a counter.
Why here:

#define in_serving_softirq()    (softirq_count() & SOFTIRQ_OFFSET)
#define in_task()               (!(preempt_count() & \
                                   (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)))

we check only lowest bit?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: preempt.h: some SOFTIRQ_OFFSET should be SOFTIRQ_MASK?
  2019-02-05 18:34 preempt.h: some SOFTIRQ_OFFSET should be SOFTIRQ_MASK? Denys Vlasenko
@ 2019-02-13  4:05 ` Frederic Weisbecker
  2019-02-13 10:37   ` Denys Vlasenko
  0 siblings, 1 reply; 3+ messages in thread
From: Frederic Weisbecker @ 2019-02-13  4:05 UTC (permalink / raw)
  To: Denys Vlasenko; +Cc: Frederic Weisbecker, Linux Kernel Mailing List

On Tue, Feb 05, 2019 at 07:34:31PM +0100, Denys Vlasenko wrote:
> SOFTIRQ is a counter.
> Why here:
> 
> #define in_serving_softirq()    (softirq_count() & SOFTIRQ_OFFSET)
> #define in_task()               (!(preempt_count() & \
>                                    (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)))
> 
> we check only lowest bit?

So we have SOFTIRQ_OFFSET that is used when serving softirqs.
And we have SOFTIRQ_DISABLE_OFFSET that is used when we disable
softirqs.

I think the choice is right on both tests above, or am I missing something?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: preempt.h: some SOFTIRQ_OFFSET should be SOFTIRQ_MASK?
  2019-02-13  4:05 ` Frederic Weisbecker
@ 2019-02-13 10:37   ` Denys Vlasenko
  0 siblings, 0 replies; 3+ messages in thread
From: Denys Vlasenko @ 2019-02-13 10:37 UTC (permalink / raw)
  To: Frederic Weisbecker; +Cc: Frederic Weisbecker, Linux Kernel Mailing List

On Wed, Feb 13, 2019 at 5:05 AM Frederic Weisbecker <frederic@kernel.org> wrote:
> On Tue, Feb 05, 2019 at 07:34:31PM +0100, Denys Vlasenko wrote:
> > SOFTIRQ is a counter.
> > Why here:
> >
> > #define in_serving_softirq()    (softirq_count() & SOFTIRQ_OFFSET)
> > #define in_task()               (!(preempt_count() & \
> >                                    (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)))
> >
> > we check only lowest bit?
>
> So we have SOFTIRQ_OFFSET that is used when serving softirqs.
> And we have SOFTIRQ_DISABLE_OFFSET that is used when we disable
> softirqs.
>
> I think the choice is right on both tests above, or am I missing something?

From my reading of the following:

 * We put the hardirq and softirq counter into the preemption
 * counter. The bitmask has the following meaning:
 * - bits 0-7 are the preemption count (max preemption depth: 256)
 * - bits 8-15 are the softirq count (max # of softirqs: 256)
 * The hardirq count could in theory be the same as the number of
 * interrupts in the system, but we run all interrupt handlers with
 * interrupts disabled, so we cannot have nesting interrupts. Though
 * there are a few palaeontologic drivers which reenable interrupts in
 * the handler, so we need more than one bit here.
 *         PREEMPT_MASK:        0x000000ff
 *         SOFTIRQ_MASK:        0x0000ff00
 *         HARDIRQ_MASK:        0x000f0000
 *             NMI_MASK:        0x00100000
 * PREEMPT_NEED_RESCHED:        0x80000000
 */
#define PREEMPT_BITS    8
#define SOFTIRQ_BITS    8
#define HARDIRQ_BITS    4
#define NMI_BITS        1

it seems that 8-bit SOFTIRQ_MASK contains depth count of nested softirqs.
Therefore, to test whether we are in softirq, you need:

define in_serving_softirq()    (softirq_count() & SOFTIRQ_MASK)

But existing code uses SOFTIRQ_OFFSET, not SOFTIRQ_MASK, for the mask.
This means that if nest count is e.g. 2, in_serving_softirq() will return
"false".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-13 10:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-05 18:34 preempt.h: some SOFTIRQ_OFFSET should be SOFTIRQ_MASK? Denys Vlasenko
2019-02-13  4:05 ` Frederic Weisbecker
2019-02-13 10:37   ` Denys Vlasenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).