From: Joe Perches <joe@perches.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Andreas Schwab <schwab@linux-m68k.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Linux List Kernel Mailing <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Namhyung Kim <namhyung@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Tom Zanussi <zanussi@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro
Date: Fri, 21 Dec 2018 14:20:25 -0800 [thread overview]
Message-ID: <84199633fd49db573c9ba71f1992936422e907d4.camel@perches.com> (raw)
In-Reply-To: <20181221160826.34c544e6@gandalf.local.home>
On Fri, 2018-12-21 at 16:08 -0500, Steven Rostedt wrote:
> On Fri, 21 Dec 2018 21:58:32 +0100
> Andreas Schwab <schwab@linux-m68k.org> wrote:
>
>
> > > Well, perhaps I can just remove the ending ones. I get paranoid with
> > > macro variables, and tend to over do it so that there's no question.
> >
> > Why not make it an inline function?
>
> Matters if that removes the strlen(const) optimization. I could try it
> and see what happens.
Using
static inline bool str_has_prefix(const char *str, const char prefix[])
{
return !strncmp(str, prefix, strlen(prefix));
}
eliminates the strlen with gcc 4.8 (oldest I still have)
$ cat lib/test_module.c
* This module emits "Hello, world" on printk when loaded.
*
* It is designed to be used for basic evaluation of the module loading
* subsystem (for example when validating module signing/verification). It
* lacks any extra dependencies, and will not normally be loaded by the
* system unless explicitly requested by name.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/init.h>
#include <linux/module.h>
#include <linux/printk.h>
static inline bool str_has_prefix(const char *str, const char prefix[])
{
return !strncmp(str, prefix, strlen(prefix));
}
bool test_str_has_prefix(const char *foo)
{
return str_has_prefix("TomJonesPrefix", foo);
}
bool test_str_has_prefix_TomJones(void)
{
return str_has_prefix("TomJonesPrefix", "TomJones");
}
$ make CC=/usr/bin/gcc-4.8 lib/test_module.o
$ objdump -d -s lib/test_module.o
lib/test_module.o: file format elf64-x86-64
Contents of section .text:
0000 534889fb e8000000 00b90f00 00004883 SH............H.
0010 f80f4889 df480f4e c848c7c6 00000000 ..H..H.N.H......
0020 4839c9f3 a65b0f94 c0c3660f 1f440000 H9...[....f..D..
0030 b8010000 00c3 ......
Contents of section .rodata.str1.1:
0000 546f6d4a 6f6e6573 50726566 697800 TomJonesPrefix.
Contents of section .comment:
0000 00474343 3a202855 62756e74 7520342e .GCC: (Ubuntu 4.
0010 382e352d 34756275 6e747539 2920342e 8.5-4ubuntu9) 4.
0020 382e3500 8.5.
Contents of section .orc_unwind_ip:
0000 00000000 00000000 00000000 00000000 ................
0010 00000000 00000000 ........
Contents of section .orc_unwind:
0000 08000000 05001000 00000500 08000000 ................
0010 05000000 00000000 08000000 05000000 ................
0020 00000000 ....
Disassembly of section .text:
0000000000000000 <test_str_has_prefix>:
0: 53 push %rbx
1: 48 89 fb mov %rdi,%rbx
4: e8 00 00 00 00 callq 9 <test_str_has_prefix+0x9>
9: b9 0f 00 00 00 mov $0xf,%ecx
e: 48 83 f8 0f cmp $0xf,%rax
12: 48 89 df mov %rbx,%rdi
15: 48 0f 4e c8 cmovle %rax,%rcx
19: 48 c7 c6 00 00 00 00 mov $0x0,%rsi
20: 48 39 c9 cmp %rcx,%rcx
23: f3 a6 repz cmpsb %es:(%rdi),%ds:(%rsi)
25: 5b pop %rbx
26: 0f 94 c0 sete %al
29: c3 retq
2a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
0000000000000030 <test_str_has_prefix_TomJones>:
30: b8 01 00 00 00 mov $0x1,%eax
35: c3 retq
next prev parent reply other threads:[~2018-12-21 22:20 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-21 17:56 [for-next][PATCH 00/24] tracing: Updates for the next (coming soon) merge window Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 01/24] ftrace: Allow ftrace_replace_code() to be schedulable Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 02/24] arm64: ftrace: Set FTRACE_MAY_SLEEP before ftrace_modify_all_code() Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 03/24] fgraph: Add comment to describe ftrace_graph_get_ret_stack Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 04/24] x86/ftrace: Do not call function graph from dynamic trampolines Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 05/24] powerpc/frace: Use ftrace_graph_get_ret_stack() instead of curr_ret_stack Steven Rostedt
2018-12-22 9:51 ` Michael Ellerman
2018-12-22 12:24 ` Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 06/24] sparc64: " Steven Rostedt
2018-12-21 18:24 ` David Miller
2018-12-21 19:29 ` Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 07/24] sh: ftrace: " Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 08/24] arm64: " Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 10/24] seq_buf: Use size_t for len in seq_buf_puts() Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 11/24] tracing: Fix ftrace_graph_get_ret_stack() to use task and not current Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 12/24] tracing: Remove unnecessary hist trigger struct field Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 13/24] tracing: Change strlen to sizeof for hist trigger static strings Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 14/24] tracing: Use var_refs[] for hist trigger reference checking Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 15/24] tracing: Remove open-coding of hist trigger var_ref management Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 16/24] tracing: Use hist triggers var_ref array to destroy var_refs Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 17/24] tracing: Remove hist trigger synth_var_refs Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 18/24] tracing: Add hist trigger comments for variable-related fields Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 19/24] tracing: Merge seq_print_sym_short() and seq_print_sym_offset() Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 21/24] tracing: Simplify printfing in seq_print_sym Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro Steven Rostedt
2018-12-21 18:51 ` Linus Torvalds
2018-12-21 19:40 ` Steven Rostedt
2018-12-21 20:01 ` Linus Torvalds
2018-12-21 20:35 ` Steven Rostedt
2018-12-21 20:46 ` Joe Perches
2018-12-21 20:54 ` Steven Rostedt
2018-12-21 20:58 ` Andreas Schwab
2018-12-21 21:08 ` Steven Rostedt
2018-12-21 22:20 ` Joe Perches [this message]
2018-12-21 22:29 ` Linus Torvalds
2018-12-21 22:58 ` Steven Rostedt
2018-12-21 22:55 ` Steven Rostedt
2018-12-23 22:01 ` Rasmus Villemoes
2018-12-23 22:56 ` Steven Rostedt
2018-12-23 23:52 ` Rasmus Villemoes
2018-12-24 0:05 ` Steven Rostedt
2018-12-23 23:01 ` Joe Perches
2018-12-21 20:58 ` Steven Rostedt
[not found] ` <CAHk-=wjtkvFUuRNZU67KccuUKYHw=pYoDMQJ_9OVDFxOwmK9zQ@mail.gmail.com>
2018-12-21 20:55 ` Steven Rostedt
2018-12-21 22:08 ` Linus Torvalds
2018-12-21 22:48 ` Steven Rostedt
2018-12-21 22:57 ` Linus Torvalds
2018-12-21 23:03 ` Steven Rostedt
2018-12-22 10:20 ` Malcolm Priestley
2018-12-22 12:26 ` Steven Rostedt
2018-12-21 17:56 ` [for-next][PATCH 24/24] tracing: Use strncmp_prefix() helper for histogram code Steven Rostedt
[not found] ` <20181221175656.827708767@goodmis.org>
2018-12-21 18:00 ` [for-next][PATCH 09/24] seq_buf: Make seq_buf_puts() null-terminate the buffer Steven Rostedt
2018-12-21 18:05 ` Steven Rostedt
2018-12-27 5:25 ` Michael Ellerman
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=84199633fd49db573c9ba71f1992936422e907d4.camel@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=schwab@linux-m68k.org \
--cc=torvalds@linux-foundation.org \
--cc=zanussi@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;
as well as URLs for NNTP newsgroup(s).