From: Kent Overstreet <kmo@daterainc.com>
To: Christoph Lameter <cl@gentwo.org>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
Tejun Heo <tj@kernel.org>, Oleg Nesterov <oleg@redhat.com>,
Ingo Molnar <mingo@redhat.com>, Andi Kleen <andi@firstfloor.org>,
Jens Axboe <axboe@kernel.dk>,
"Nicholas A. Bellinger" <nab@linux-iscsi.org>
Subject: [PATCH] idr: Use this_cpu_ptr() for percpu_ida
Date: Wed, 7 Aug 2013 12:57:33 -0700 [thread overview]
Message-ID: <20130807195733.GB11612@kmo-pixel> (raw)
In-Reply-To: <000001405a4b39ef-0715410a-5061-41e9-9414-86559f16570d-000000@email.amazonses.com>
On Wed, Aug 07, 2013 at 07:40:15PM +0000, Christoph Lameter wrote:
> On Wed, 7 Aug 2013, Kent Overstreet wrote:
>
> > I was breaking it apart because I was using this_cpu elsewhere too - for
> > the bitmap of which cpus have non empty freelists.
>
> this_cpu can be retrieved with smp_processor_id().
>
> > Or is this_cpu_ptr() doing something smarter than per_cpu_ptr(ptr,
> > smp_processer_id())? There's so many variants I'm not 100% sure they're
> > the same.
>
> Yes it is. It uses a sepecial register that contains the offset of this
> cpus per cpu area instead of going through the table of all processor
> offsets. Its less code.
Alright, well here's a fixup patch - untested for the moment though.
One thing that was bugging me - I was never able to figure out for sure
if smp_processor_id() returns a number in the range [0, nr_cpu_ids), at
least I couldn't find where it was documented - could you tell me if
that's true?
>From e2b8016de49c28c0ccbe7849d7254f005c7e2e77 Mon Sep 17 00:00:00 2001
From: Kent Overstreet <kmo@daterainc.com>
Date: Wed, 7 Aug 2013 12:52:58 -0700
Subject: [PATCH] idr: Use this_cpu_ptr() for percpu_ida
diff --git a/lib/idr.c b/lib/idr.c
index fb374c3..320ffea 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -748,12 +748,10 @@ int percpu_ida_alloc(struct percpu_ida *pool, gfp_t gfp)
DEFINE_WAIT(wait);
struct percpu_ida_cpu *tags;
unsigned long flags;
- unsigned this_cpu;
int tag;
local_irq_save(flags);
- this_cpu = smp_processor_id();
- tags = per_cpu_ptr(pool->tag_cpu, this_cpu);
+ tags = this_cpu_ptr(pool->tag_cpu);
/* Fastpath */
tag = alloc_local_tag(pool, tags);
@@ -782,7 +780,8 @@ int percpu_ida_alloc(struct percpu_ida *pool, gfp_t gfp)
if (tags->nr_free) {
tag = tags->freelist[--tags->nr_free];
if (tags->nr_free)
- set_bit(this_cpu, pool->cpus_have_tags);
+ set_bit(smp_processor_id(),
+ pool->cpus_have_tags);
}
spin_unlock(&pool->ida.lock);
@@ -794,8 +793,7 @@ int percpu_ida_alloc(struct percpu_ida *pool, gfp_t gfp)
schedule();
local_irq_save(flags);
- this_cpu = smp_processor_id();
- tags = per_cpu_ptr(pool->tag_cpu, this_cpu);
+ tags = this_cpu_ptr(pool->tag_cpu);
}
finish_wait(&pool->wait, &wait);
@@ -814,13 +812,12 @@ void percpu_ida_free(struct percpu_ida *pool, unsigned tag)
{
struct percpu_ida_cpu *tags;
unsigned long flags;
- unsigned nr_free, this_cpu;
+ unsigned nr_free;
BUG_ON(tag >= pool->nr_tags);
local_irq_save(flags);
- this_cpu = smp_processor_id();
- tags = per_cpu_ptr(pool->tag_cpu, this_cpu);
+ tags = this_cpu_ptr(pool->tag_cpu);
spin_lock(&tags->lock);
tags->freelist[tags->nr_free++] = tag;
@@ -829,7 +826,8 @@ void percpu_ida_free(struct percpu_ida *pool, unsigned tag)
spin_unlock(&tags->lock);
if (nr_free == 1) {
- set_bit(this_cpu, pool->cpus_have_tags);
+ set_bit(smp_processor_id(),
+ pool->cpus_have_tags);
wake_up(&pool->wait);
}
next prev parent reply other threads:[~2013-08-07 19:57 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-07 17:34 IDA/IDR rewrite, percpu ida Kent Overstreet
2013-08-07 17:34 ` [PATCH 03/10] idr: Rewrite ida Kent Overstreet
2013-08-07 20:22 ` Tejun Heo
2013-08-07 20:51 ` [PATCH] idr: Document ida tree sections Kent Overstreet
2013-08-09 14:57 ` Tejun Heo
2013-08-13 22:13 ` Kent Overstreet
2013-08-13 22:19 ` Tejun Heo
2013-08-13 22:27 ` Kent Overstreet
2013-08-13 22:44 ` Tejun Heo
2013-08-13 22:59 ` Kent Overstreet
2013-08-13 23:22 ` Tejun Heo
2013-08-13 23:51 ` Kent Overstreet
2013-08-13 23:59 ` Tejun Heo
2013-08-15 0:04 ` Kent Overstreet
2013-08-15 0:22 ` Tejun Heo
2013-08-13 22:33 ` Kent Overstreet
2013-08-07 17:34 ` [PATCH 04/10] idr: Percpu ida Kent Overstreet
2013-08-07 17:56 ` Christoph Lameter
2013-08-07 18:33 ` Kent Overstreet
2013-08-07 19:40 ` Christoph Lameter
2013-08-07 19:57 ` Kent Overstreet [this message]
2013-08-08 14:32 ` [PATCH] idr: Use this_cpu_ptr() for percpu_ida Christoph Lameter
2013-08-20 21:19 ` Nicholas A. Bellinger
2013-08-20 21:29 ` Andrew Morton
2013-08-21 2:01 ` Kent Overstreet
2013-08-21 2:07 ` Tejun Heo
2013-08-21 2:31 ` Kent Overstreet
2013-08-21 11:59 ` Tejun Heo
2013-08-21 21:09 ` Kent Overstreet
2013-08-21 21:16 ` Tejun Heo
2013-08-21 21:24 ` Kent Overstreet
2013-08-21 21:31 ` Tejun Heo
2013-08-21 14:32 ` Christoph Lameter
2013-08-21 17:49 ` Nicholas A. Bellinger
2013-08-21 20:49 ` Andrew Morton
2013-08-22 16:44 ` Christoph Lameter
2013-08-22 16:56 ` Jens Axboe
2013-08-07 17:46 ` [PATCH 05/10] idr: Kill old deprecated idr interfaces Kent Overstreet
2013-08-07 17:46 ` [PATCH 06/10] idr: Rename idr_get_next() -> idr_find_next() Kent Overstreet
2013-08-07 17:46 ` [PATCH 07/10] idr: Rename idr_alloc() -> idr_alloc_range() Kent Overstreet
2013-08-07 17:46 ` [Drbd-dev] " Kent Overstreet
2013-08-07 19:04 ` Wolfram Sang
2013-08-07 19:04 ` [Drbd-dev] " Wolfram Sang
2013-08-07 17:46 ` [PATCH 08/10] idr: Reimplement idr on top of ida/radix trees Kent Overstreet
[not found] ` <1375896905-6074-1-git-send-email-kmo-PEzghdH756F8UrSeD/g0lQ@public.gmane.org>
2013-08-07 17:46 ` [PATCH 09/10] idr: Remove unneeded idr locking, idr_preload() usage Kent Overstreet
2013-08-07 17:46 ` Kent Overstreet
2013-08-07 17:46 ` [Cluster-devel] [PATCH 10/10] idr: Rework idr_preload() Kent Overstreet
2013-08-07 17:46 ` Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130807195733.GB11612@kmo-pixel \
--to=kmo@daterainc.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=axboe@kernel.dk \
--cc=cl@gentwo.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nab@linux-iscsi.org \
--cc=oleg@redhat.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.