mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jason Baron <jbaron@akamai.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [RFC][PATCH] tracing/jump-labels: Add message when a trace event has no instances
Date: Wed, 11 Oct 2017 09:21:09 +0200	[thread overview]
Message-ID: <20171011072109.gthv2xms77erl6ij@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20171010185630.78053ea9@gandalf.local.home>

On Tue, Oct 10, 2017 at 06:56:30PM -0400, Steven Rostedt wrote:

> +/* Without jump labels we don't know how many instances, just assume one */
> +static inline int static_key_instances(struct static_key *key)
> +{
> +	return 1;
> +}

That's a tad dodgy.. it works for your current usage, but..


> +int static_key_instances(struct static_key *key)
> +{
> +	return jump_label_update(key, true);
>  }

That's a bit yuck too :/ But I'm not entirely sure something like the
below is actually better...

---
 kernel/jump_label.c | 50 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 0bf2e8f5244a..97286ed6c93d 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -354,9 +354,17 @@ static enum jump_label_type jump_label_type(struct jump_entry *entry)
 	return enabled ^ branch;
 }
 
-static void __jump_label_update(struct static_key *key,
-				struct jump_entry *entry,
-				struct jump_entry *stop)
+typedef void (*jump_label_visit_f)(struct jump_entry *entry, void *data);
+
+void __jump_label_update(struct jump_entry *entry, void *data)
+{
+	arch_jump_label_transform(entry, jump_label_type(entry));
+}
+
+static void
+__jump_label_visit(struct static_key *key, struct jump_entry *entry,
+		   struct jump_entry *stop, jump_label_visit_f *visit,
+		   void *data)
 {
 	for (; (entry < stop) && (jump_entry_key(entry) == key); entry++) {
 		/*
@@ -365,7 +373,7 @@ static void __jump_label_update(struct static_key *key,
 		 * init code, see jump_label_invalidate_module_init().
 		 */
 		if (entry->code && kernel_text_address(entry->code))
-			arch_jump_label_transform(entry, jump_label_type(entry));
+			visit(entry, data);
 	}
 }
 
@@ -470,7 +478,8 @@ static int __jump_label_mod_text_reserved(void *start, void *end)
 				start, end);
 }
 
-static void __jump_label_mod_update(struct static_key *key)
+static void
+__jump_label_mod_visit(struct static_key *key, jump_label_visit_f visit, void *data)
 {
 	struct static_key_mod *mod;
 
@@ -490,7 +499,8 @@ static void __jump_label_mod_update(struct static_key *key)
 			stop = __stop___jump_table;
 		else
 			stop = m->jump_entries + m->num_jump_entries;
-		__jump_label_update(key, mod->entries, stop);
+
+		__jump_label_visit(key, mod->entries, stop, visit, data);
 	}
 }
 
@@ -571,7 +581,7 @@ static int jump_label_add_module(struct module *mod)
 
 		/* Only update if we've changed from our initial state */
 		if (jump_label_type(iter) != jump_label_init_type(iter))
-			__jump_label_update(key, iter, iter_stop);
+			__jump_label_visit(key, iter, iter_stop, __jump_label_update, NULL);
 	}
 
 	return 0;
@@ -711,7 +721,7 @@ int jump_label_text_reserved(void *start, void *end)
 	return ret;
 }
 
-static void jump_label_update(struct static_key *key)
+static void jump_label_visit(struct static_key *key, jump_label_visit_f visit, void *data)
 {
 	struct jump_entry *stop = __stop___jump_table;
 	struct jump_entry *entry;
@@ -719,7 +729,7 @@ static void jump_label_update(struct static_key *key)
 	struct module *mod;
 
 	if (static_key_linked(key)) {
-		__jump_label_mod_update(key);
+		__jump_label_mod_visit(key, visit, data);
 		return;
 	}
 
@@ -732,7 +742,27 @@ static void jump_label_update(struct static_key *key)
 	entry = static_key_entries(key);
 	/* if there are no users, entry can be NULL */
 	if (entry)
-		__jump_label_update(key, entry, stop);
+		__jump_label_visit(key, entry, stop, visit, data);
+}
+
+static void jump_label_update(struct static_key *key)
+{
+	jump_label_visit(key, __jump_label_update, NULL);
+}
+
+static void __jump_label_count(struct jump_entry *entry, void *data)
+{
+	unsigned int *count = data;
+	count++;
+}
+
+unsigned int static_key_instances(struct static_key *key)
+{
+	unsigned int count = 0;
+
+	jump_label_visit(key, __jump_label_count, &count);
+
+	return count;
 }
 
 #ifdef CONFIG_STATIC_KEYS_SELFTEST

  reply	other threads:[~2017-10-11  7:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-10 22:56 Steven Rostedt
2017-10-11  7:21 ` Peter Zijlstra [this message]
2017-10-11 12:55   ` Steven Rostedt
2017-10-11 14:00 ` Jason Baron
2017-10-11 14:14   ` 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=20171011072109.gthv2xms77erl6ij@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=jbaron@akamai.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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®