lkml.org 
[lkml]   [2008]   [May]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[patch 05/41] cpu alloc: Percpu_counter conversion
Use cpu_alloc instead of allocpercpu.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
---
lib/percpu_counter.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

Index: linux-2.6/lib/percpu_counter.c
===================================================================
--- linux-2.6.orig/lib/percpu_counter.c 2008-05-28 17:56:17.000000000 -0700
+++ linux-2.6/lib/percpu_counter.c 2008-05-28 18:30:25.000000000 -0700
@@ -20,7 +20,7 @@

spin_lock(&fbc->lock);
for_each_possible_cpu(cpu) {
- s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
+ s32 *pcount = CPU_PTR(fbc->counters, cpu);
*pcount = 0;
}
fbc->count = amount;
@@ -31,20 +31,18 @@
void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch)
{
s64 count;
- s32 *pcount;
- int cpu = get_cpu();

- pcount = per_cpu_ptr(fbc->counters, cpu);
- count = *pcount + amount;
+ preempt_disable();
+ count = __CPU_READ(*fbc->counters) + amount;
if (count >= batch || count <= -batch) {
spin_lock(&fbc->lock);
fbc->count += count;
- *pcount = 0;
+ __CPU_WRITE(*fbc->counters, 0);
spin_unlock(&fbc->lock);
} else {
- *pcount = count;
+ __CPU_WRITE(*fbc->counters, count);
}
- put_cpu();
+ preempt_enable();
}
EXPORT_SYMBOL(__percpu_counter_add);

@@ -60,7 +58,7 @@
spin_lock(&fbc->lock);
ret = fbc->count;
for_each_online_cpu(cpu) {
- s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
+ s32 *pcount = CPU_PTR(fbc->counters, cpu);
ret += *pcount;
}
spin_unlock(&fbc->lock);
@@ -74,7 +72,7 @@
{
spin_lock_init(&fbc->lock);
fbc->count = amount;
- fbc->counters = alloc_percpu(s32);
+ fbc->counters = CPU_ALLOC(s32, GFP_KERNEL|__GFP_ZERO);
if (!fbc->counters)
return -ENOMEM;
#ifdef CONFIG_HOTPLUG_CPU
@@ -101,7 +99,7 @@
if (!fbc->counters)
return;

- free_percpu(fbc->counters);
+ CPU_FREE(fbc->counters);
fbc->counters = NULL;
#ifdef CONFIG_HOTPLUG_CPU
mutex_lock(&percpu_counters_lock);
@@ -128,7 +126,7 @@
unsigned long flags;

spin_lock_irqsave(&fbc->lock, flags);
- pcount = per_cpu_ptr(fbc->counters, cpu);
+ pcount = CPU_PTR(fbc->counters, cpu);
fbc->count += *pcount;
*pcount = 0;
spin_unlock_irqrestore(&fbc->lock, flags);
--


\
 
 \ /
  Last update: 2008-05-30 06:05    [W:0.256 / U:0.232 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site