Re: [RFC3 02/14] Basic counter functionality

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> There is no need to disable interrupts AFAICS, but only preemption
> (which could cause problems as your comment above describes). I suppose
> that these counters are not accessed at interrupt time and are not meant
> to be, right?
> 
> Which means that if an interrupt happens at any point in the code,
> the state will be consistent after the IRQ(s) handler(s) finish and
> execution restarts where it had been interrupted.
> 
> Why not use preempt_disable/preempt_enable? Those would disappear
> if !CONFIG_PREEMPT, and could be faster than the interrupt
> disabling/enabling (no need to save "flags" on stack, but increment
> preempt count, which has a chance to be on cache, I guess).

Which is what local_t does for BITS_PER_LONG==32 arches:

#define LOCAL_INIT(i)   { ATOMIC_INIT(i) }

#define local_read(l)   ((unsigned long)atomic_read(&(l)->a))
#define local_set(l,i)  atomic_set((&(l)->a),(i))
#define local_inc(l)    atomic_inc(&(l)->a)
#define local_dec(l)    atomic_dec(&(l)->a)
#define local_add(i,l)  atomic_add((i),(&(l)->a))
#define local_sub(i,l)  atomic_sub((i),(&(l)->a))

/* Non-atomic variants, ie. preemption disabled and won't be touched
 * in interrupt, etc.  Some archs can optimize this case well. */
#define __local_inc(l)          local_set((l), local_read(l) + 1)
#define __local_dec(l)          local_set((l), local_read(l) - 1)
#define __local_add(i,l)        local_set((l), local_read(l) + (i))
#define __local_sub(i,l)        local_set((l), local_read(l) - (i))

> It would also be nice to have all code related to debugging only
> counters selectable at compile time, since it might not be interesting
> data for some scenarios (but unnecessary bloat) - seems that was the
> original intent by Andrew as you noted.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux