lkml.org 
[lkml]   [2006]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [patch 3/4] net: Percpufy frequently used variables -- proto.sockets_allocated
    On Sat, Jan 28, 2006 at 01:35:03AM +0100, Eric Dumazet wrote:
    > Eric Dumazet a écrit :
    > >Andrew Morton a écrit :
    > >>Eric Dumazet <dada1@cosmosbay.com> wrote:
    > >
    > >#ifdef CONFIG_SMP
    > >void percpu_counter_mod(struct percpu_counter *fbc, long amount)
    > >{
    > > long old, new;
    > > atomic_long_t *pcount;
    > >
    > > pcount = per_cpu_ptr(fbc->counters, get_cpu());
    > >start:
    > > old = atomic_long_read(pcount);
    > > new = old + amount;
    > > if (new >= FBC_BATCH || new <= -FBC_BATCH) {
    > > if (unlikely(atomic_long_cmpxchg(pcount, old, 0) != old))
    > > goto start;
    > > atomic_long_add(new, &fbc->count);
    > > } else
    > > atomic_long_add(amount, pcount);
    > >
    > > put_cpu();
    > >}
    > >EXPORT_SYMBOL(percpu_counter_mod);
    > >
    > >long percpu_counter_read_accurate(struct percpu_counter *fbc)
    > >{
    > > long res = 0;
    > > int cpu;
    > > atomic_long_t *pcount;
    > >
    > > for_each_cpu(cpu) {
    > > pcount = per_cpu_ptr(fbc->counters, cpu);
    > > /* dont dirty cache line if not necessary */
    > > if (atomic_long_read(pcount))
    > > res += atomic_long_xchg(pcount, 0);
    ---------------------------> (A)
    > > }
    >

    > atomic_long_add(res, &fbc->count);
    ---------------------------> (B)
    > res = atomic_long_read(&fbc->count);
    >
    > > return res;
    > >}

    The read is still theoritically FBC_BATCH * NR_CPUS inaccurate no?
    What happens when other cpus update their local counters at (A) and (B)?

    (I am hoping we don't need percpu_counter_read_accurate anywhere yet and
    this is just demo ;). I certainly don't want to go on all cpus for read /
    add cmpxchg on the write path for the proto counters that started this
    discussion)

    Thanks,
    Kiran
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2006-01-28 05:55    [W:4.356 / U:0.104 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site