From: Ming Lei <tom.leiming@gmail.com>
To: Jens Axboe <axboe@kernel.dk>,
linux-kernel@vger.kernel.org, Kent Overstreet <kmo@daterainc.com>
Cc: Christoph Hellwig <hch@lst.de>, Shaohua Li <shli@kernel.org>,
Nicholas Bellinger <nab@linux-iscsi.org>,
Nick Swenson <nks@daterainc.com>,
Ming Lei <tom.leiming@gmail.com>
Subject: [PATCH 1/3] percpu_ida: introduce kobject for percpu_ida pool
Date: Tue, 29 Apr 2014 22:53:51 +0800 [thread overview]
Message-ID: <1398783234-7062-2-git-send-email-tom.leiming@gmail.com> (raw)
In-Reply-To: <1398783234-7062-1-git-send-email-tom.leiming@gmail.com>
So that we can export some allocation/free information
for monitoring percpu_ida performance.
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
include/linux/percpu_ida.h | 16 ++++++++++++++++
lib/percpu_ida.c | 21 ++++++++++++++++++---
2 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/include/linux/percpu_ida.h b/include/linux/percpu_ida.h
index f5cfdd6..463e3b3 100644
--- a/include/linux/percpu_ida.h
+++ b/include/linux/percpu_ida.h
@@ -8,6 +8,7 @@
#include <linux/spinlock_types.h>
#include <linux/wait.h>
#include <linux/cpumask.h>
+#include <linux/kobject.h>
struct percpu_ida_cpu;
@@ -52,6 +53,8 @@ struct percpu_ida {
unsigned nr_free;
unsigned *freelist;
} ____cacheline_aligned_in_smp;
+
+ struct kobject kobj;
};
/*
@@ -79,4 +82,17 @@ int percpu_ida_for_each_free(struct percpu_ida *pool, percpu_ida_cb fn,
void *data);
unsigned percpu_ida_free_tags(struct percpu_ida *pool, int cpu);
+
+static inline int percpu_ida_kobject_add(struct percpu_ida *pool,
+ struct kobject *parent, const char *name)
+{
+ if (pool->kobj.state_initialized)
+ return kobject_add(&pool->kobj, parent, name);
+ return 0;
+}
+static inline void percpu_ida_kobject_del(struct percpu_ida *pool)
+{
+ if (pool->kobj.state_in_sysfs)
+ kobject_del(&pool->kobj);
+}
#endif /* __PERCPU_IDA_H__ */
diff --git a/lib/percpu_ida.c b/lib/percpu_ida.c
index 93d145e..56ae350 100644
--- a/lib/percpu_ida.c
+++ b/lib/percpu_ida.c
@@ -260,6 +260,20 @@ void percpu_ida_free(struct percpu_ida *pool, unsigned tag)
}
EXPORT_SYMBOL_GPL(percpu_ida_free);
+static void percpu_ida_release(struct kobject *kobj)
+{
+ struct percpu_ida *pool = container_of(kobj,
+ struct percpu_ida, kobj);
+
+ free_percpu(pool->tag_cpu);
+ free_pages((unsigned long) pool->freelist,
+ get_order(pool->nr_tags * sizeof(unsigned)));
+}
+
+static struct kobj_type percpu_ida_ktype = {
+ .release = percpu_ida_release,
+};
+
/**
* percpu_ida_destroy - release a tag pool's resources
* @pool: pool to free
@@ -268,9 +282,8 @@ EXPORT_SYMBOL_GPL(percpu_ida_free);
*/
void percpu_ida_destroy(struct percpu_ida *pool)
{
- free_percpu(pool->tag_cpu);
- free_pages((unsigned long) pool->freelist,
- get_order(pool->nr_tags * sizeof(unsigned)));
+ if (pool->kobj.state_initialized)
+ kobject_put(&pool->kobj);
}
EXPORT_SYMBOL_GPL(percpu_ida_destroy);
@@ -324,6 +337,8 @@ int __percpu_ida_init(struct percpu_ida *pool, unsigned long nr_tags,
for_each_possible_cpu(cpu)
spin_lock_init(&per_cpu_ptr(pool->tag_cpu, cpu)->lock);
+ kobject_init(&pool->kobj, &percpu_ida_ktype);
+
return 0;
err:
percpu_ida_destroy(pool);
--
1.7.9.5
next prev parent reply other threads:[~2014-04-29 14:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-29 14:53 [PATCH 0/3] percpu_ida: support to export allocation/free information Ming Lei
2014-04-29 14:53 ` Ming Lei [this message]
2014-04-29 14:53 ` [PATCH 2/3] percpu_ida: support exporting allocation/free info via sysfs Ming Lei
2014-04-29 14:53 ` [PATCH 3/3] blk-mq: add percpu_ida kobjects Ming Lei
2014-05-05 9:16 ` [PATCH 0/3] percpu_ida: support to export allocation/free information Ming Lei
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=1398783234-7062-2-git-send-email-tom.leiming@gmail.com \
--to=tom.leiming@gmail.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=kmo@daterainc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nab@linux-iscsi.org \
--cc=nks@daterainc.com \
--cc=shli@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®