From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH 09/13] ftrace: Free hash with call_rcu_sched()
Date: Wed, 18 May 2011 22:12:00 -0400 [thread overview]
Message-ID: <20110519021256.720408836@goodmis.org> (raw)
In-Reply-To: <20110519021151.600991800@goodmis.org>
[-- Attachment #1: 0009-ftrace-Free-hash-with-call_rcu_sched.patch --]
[-- Type: text/plain, Size: 3112 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
When a hash is modified and might be in use, we need to perform
a schedule RCU operation on it, as the hashes will soon be used
directly in the function tracer callback.
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/trace/ftrace.c | 55 +++++++++++++++++++++++++------------------------
1 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index dcce0bf..92b6fdf 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -913,6 +913,7 @@ struct ftrace_hash {
unsigned long size_bits;
struct hlist_head *buckets;
unsigned long count;
+ struct rcu_head rcu;
};
/*
@@ -1058,6 +1059,21 @@ static void free_ftrace_hash(struct ftrace_hash *hash)
kfree(hash);
}
+static void __free_ftrace_hash_rcu(struct rcu_head *rcu)
+{
+ struct ftrace_hash *hash;
+
+ hash = container_of(rcu, struct ftrace_hash, rcu);
+ free_ftrace_hash(hash);
+}
+
+static void free_ftrace_hash_rcu(struct ftrace_hash *hash)
+{
+ if (!hash || hash == EMPTY_HASH)
+ return;
+ call_rcu_sched(&hash->rcu, __free_ftrace_hash_rcu);
+}
+
static struct ftrace_hash *alloc_ftrace_hash(int size_bits)
{
struct ftrace_hash *hash;
@@ -1122,7 +1138,8 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
struct ftrace_func_entry *entry;
struct hlist_node *tp, *tn;
struct hlist_head *hhd;
- struct ftrace_hash *hash = *dst;
+ struct ftrace_hash *old_hash;
+ struct ftrace_hash *new_hash;
unsigned long key;
int size = src->count;
int bits = 0;
@@ -1133,13 +1150,11 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
* the empty_hash.
*/
if (!src->count) {
- free_ftrace_hash(*dst);
- *dst = EMPTY_HASH;
+ free_ftrace_hash_rcu(*dst);
+ rcu_assign_pointer(*dst, EMPTY_HASH);
return 0;
}
- ftrace_hash_clear(hash);
-
/*
* Make the hash size about 1/2 the # found
*/
@@ -1150,27 +1165,9 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
if (bits > FTRACE_HASH_MAX_BITS)
bits = FTRACE_HASH_MAX_BITS;
- /* We can't modify the empty_hash */
- if (hash == EMPTY_HASH) {
- /* Create a new hash */
- *dst = alloc_ftrace_hash(bits);
- if (!*dst) {
- *dst = EMPTY_HASH;
- return -ENOMEM;
- }
- hash = *dst;
- } else {
- size = 1 << bits;
-
- /* Use the old hash, but create new buckets */
- hhd = kzalloc(sizeof(*hhd) * size, GFP_KERNEL);
- if (!hhd)
- return -ENOMEM;
-
- kfree(hash->buckets);
- hash->buckets = hhd;
- hash->size_bits = bits;
- }
+ new_hash = alloc_ftrace_hash(bits);
+ if (!new_hash)
+ return -ENOMEM;
size = 1 << src->size_bits;
for (i = 0; i < size; i++) {
@@ -1181,10 +1178,14 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
else
key = 0;
remove_hash_entry(src, entry);
- __add_hash_entry(hash, entry);
+ __add_hash_entry(new_hash, entry);
}
}
+ old_hash = *dst;
+ rcu_assign_pointer(*dst, new_hash);
+ free_ftrace_hash_rcu(old_hash);
+
return 0;
}
--
1.7.4.4
next prev parent reply other threads:[~2011-05-19 2:13 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-19 2:11 [PATCH 00/13] [GIT PULL] ftrace: Allow function tracer to be used by multiple clients Steven Rostedt
2011-05-19 2:11 ` [PATCH 01/13] ftrace: Replace FTRACE_FL_NOTRACE flag with a hash of ignored Steven Rostedt
2011-05-19 2:11 ` [PATCH 02/13] ftrace: Use hash instead for FTRACE_FL_FILTER Steven Rostedt
2011-05-19 2:11 ` [PATCH 03/13] ftrace: Create a global_ops to hold the filter and notrace hashes Steven Rostedt
2011-05-19 2:11 ` [PATCH 04/13] ftrace: Separate hash allocation and assignment Steven Rostedt
2011-05-19 2:11 ` [PATCH 05/13] ftrace: Use counters to enable functions to trace Steven Rostedt
2011-05-19 2:11 ` [PATCH 06/13] ftrace: Add enabled_functions file Steven Rostedt
2011-05-19 2:11 ` [PATCH 07/13] ftrace: Add ops parameter to ftrace_startup/shutdown functions Steven Rostedt
2011-05-19 2:11 ` [PATCH 08/13] ftrace: Have global_ops store the functions that are to be traced Steven Rostedt
2011-05-19 2:12 ` Steven Rostedt [this message]
2011-05-19 2:12 ` [PATCH 10/13] ftrace: Implement separate user function filtering Steven Rostedt
2011-05-19 2:12 ` [PATCH 11/13] ftrace: Allow dynamically allocated function tracers Steven Rostedt
2011-05-19 2:12 ` [PATCH 12/13] ftrace: Modify ftrace_set_filter/notrace to take ops Steven Rostedt
2011-05-19 2:12 ` [PATCH 13/13] ftrace: Add self-tests for multiple function trace users Steven Rostedt
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=20110519021256.720408836@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulmck@linux.vnet.ibm.com \
/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
Powered by JetHome