From: Wei Yang <richard.weiyang@linux.alibaba.com>
To: rostedt@goodmis.org, mingo@redhat.com
Cc: linux-kernel@vger.kernel.org,
Wei Yang <richard.weiyang@linux.alibaba.com>
Subject: [PATCH 1/5] tracing: use union to simplify the trace_event_functions initialization
Date: Fri, 3 Jul 2020 10:06:08 +0800 [thread overview]
Message-ID: <20200703020612.12930-1-richard.weiyang@linux.alibaba.com> (raw)
There are for 4 fields in trace_event_functions with the same type of
trace_print_func. Initialize them in register_trace_event() one by one
looks redundant.
Let's take advantage of union to simplify the procedure.
Signed-off-by: Wei Yang <richard.weiyang@linux.alibaba.com>
---
include/linux/trace_events.h | 13 +++++++++----
kernel/trace/trace_output.c | 14 +++++---------
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 5c6943354049..1a421246f4a2 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -122,10 +122,15 @@ typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
int flags, struct trace_event *event);
struct trace_event_functions {
- trace_print_func trace;
- trace_print_func raw;
- trace_print_func hex;
- trace_print_func binary;
+ union {
+ struct {
+ trace_print_func trace;
+ trace_print_func raw;
+ trace_print_func hex;
+ trace_print_func binary;
+ };
+ trace_print_func print_funcs[4];
+ };
};
struct trace_event {
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 73976de7f8cc..47bf9f042b97 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -728,7 +728,7 @@ void trace_event_read_unlock(void)
int register_trace_event(struct trace_event *event)
{
unsigned key;
- int ret = 0;
+ int i, ret = 0;
down_write(&trace_event_sem);
@@ -770,14 +770,10 @@ int register_trace_event(struct trace_event *event)
goto out;
}
- if (event->funcs->trace == NULL)
- event->funcs->trace = trace_nop_print;
- if (event->funcs->raw == NULL)
- event->funcs->raw = trace_nop_print;
- if (event->funcs->hex == NULL)
- event->funcs->hex = trace_nop_print;
- if (event->funcs->binary == NULL)
- event->funcs->binary = trace_nop_print;
+ for (i = 0; i < ARRAY_SIZE(event->funcs->print_funcs); i++) {
+ if (!event->funcs->print_funcs[i])
+ event->funcs->print_funcs[i] = trace_nop_print;
+ }
key = event->type & (EVENT_HASHSIZE - 1);
--
2.20.1 (Apple Git-117)
next reply other threads:[~2020-07-03 2:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-03 2:06 Wei Yang [this message]
2020-07-03 2:06 ` [PATCH 2/5] tracing: simplify the logic by defining next to be "lasst + 1" Wei Yang
2020-07-09 21:59 ` Steven Rostedt
2020-07-03 2:06 ` [PATCH 3/5] tracing: save one trace_event->type by using __TRACE_LAST_TYPE Wei Yang
2020-07-09 22:04 ` Steven Rostedt
2020-07-03 2:06 ` [PATCH 4/5] tracing: use NULL directly to create root level tracefs Wei Yang
2020-07-03 2:06 ` [PATCH 5/5] tracing: toplevel d_entry already initialized Wei Yang
2020-07-09 22:13 ` Steven Rostedt
2020-07-10 1:11 ` Wei Yang
2020-07-10 13:08 ` Steven Rostedt
2020-07-09 21:57 ` [PATCH 1/5] tracing: use union to simplify the trace_event_functions initialization Steven Rostedt
2020-07-10 1:10 ` Wei Yang
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=20200703020612.12930-1-richard.weiyang@linux.alibaba.com \
--to=richard.weiyang@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).