tools lib traceevent: Get rid of *die finally!! (v3)
Namhyung Kim
maintainercover tools lib traceevent: Get rid of *die finally!! (v3)
Hello,
* changes in v3)
- move related header files to tools/include/ (Arnaldo)
- add WARN_ONCE() when a trace_seq misused (Jiri)
- add ack's from Jiri
You can also get this on the 'libtraceevent/die-removal-v6' branch in my tree
git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git
Any comments are welcome, thanks
Namhyung
Namhyung Kim (8):
tools include: Move perf's linux/compiler.h to a generic place tools include: Define likely/unlikely in linux/compiler.h tools include: Move perf's bug.h to a generic place
tools include: Include <linux/compiler.h> from asm/bug.h tools lib traceevent: Add state member to struct trace_seq tools lib traceevent: Check return value of realloc() tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init() tools lib traceevent: Get rid of die() finally!!
tools/include/asm/bug.h | 25 +++++++++++++ tools/include/linux/compiler.h | 38 ++++++++++++++++++++ tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/event-parse.h | 7 ++++ tools/lib/traceevent/event-utils.h | 4 --- tools/lib/traceevent/parse-utils.c | 44 ----------------------- tools/lib/traceevent/trace-seq.c | 58 ++++++++++++++++++++++++++---- tools/perf/Makefile.perf | 4 +-- tools/perf/config/Makefile | 1 + tools/perf/util/include/asm/bug.h | 22 ------------ tools/perf/util/include/linux/compiler.h | 30 ---------------- 11 files changed, 125 insertions(+), 110 deletions(-) create mode 100644 tools/include/asm/bug.h create mode 100644 tools/include/linux/compiler.h delete mode 100644 tools/perf/util/include/asm/bug.h delete mode 100644 tools/perf/util/include/linux/compiler.h
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 1/8 tools include: Move perf's linux/compiler.h to a generic place
So that it can be shared with others like libtraceevent.
--- tools/include/linux/compiler.h | 30 ++++++++++++++++++++++++++++++ tools/perf/Makefile.perf | 2 +- tools/perf/config/Makefile | 1 + tools/perf/util/include/linux/compiler.h | 30 ------------------------------ 4 files changed, 32 insertions(+), 31 deletions(-) create mode 100644 tools/include/linux/compiler.h delete mode 100644 tools/perf/util/include/linux/compiler.h
tools/include/linux/compiler.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef _TOOLS_LINUX_COMPILER_H_ +#define _TOOLS_LINUX_COMPILER_H_ + +#ifndef __always_inline +# define __always_inline inline __attribute__((always_inline)) +#endif + +#define __user + +#ifndef __attribute_const__ +# define __attribute_const__ +#endif + +#ifndef __maybe_unused +# define __maybe_unused __attribute__((unused)) +#endif + +#ifndef __packed +# define __packed __attribute__((__packed__)) +#endif + +#ifndef __force +# define __force +#endif + +#ifndef __weak +# define __weak __attribute__((weak)) +#endif + +#endif /* _TOOLS_LINUX_COMPILER_H */
tools/perf/Makefile.perf +1 -1
@@ -211,7 +211,7 @@ LIB_H += ../../include/linux/hash.h LIB_H += ../../include/linux/stringify.h LIB_H += util/include/linux/bitmap.h LIB_H += util/include/linux/bitops.h -LIB_H += util/include/linux/compiler.h +LIB_H += ../include/linux/compiler.h LIB_H += util/include/linux/const.h LIB_H += util/include/linux/ctype.h LIB_H += util/include/linux/kernel.h
tools/perf/config/Makefile +1 -0
@@ -224,6 +224,7 @@ endif CFLAGS += -I$(src-perf)/util/include CFLAGS += -I$(src-perf)/arch/$(ARCH)/include +CFLAGS += -I$(srctree)/tools/include/ CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi CFLAGS += -I$(srctree)/arch/$(ARCH)/include CFLAGS += -I$(srctree)/include/uapi
tools/perf/util/include/linux/compiler.h deleted +0 -30
@@ -1,30 +0,0 @@ -#ifndef _PERF_LINUX_COMPILER_H_ -#define _PERF_LINUX_COMPILER_H_ - -#ifndef __always_inline -# define __always_inline inline __attribute__((always_inline)) -#endif - -#define __user - -#ifndef __attribute_const__ -# define __attribute_const__ -#endif - -#ifndef __maybe_unused -# define __maybe_unused __attribute__((unused)) -#endif - -#ifndef __packed -# define __packed __attribute__((__packed__)) -#endif - -#ifndef __force -# define __force -#endif - -#ifndef __weak -# define __weak __attribute__((weak)) -#endif - -#endif
Signature · 1 line
1.7.9.2
tip-bot for Namhyung Kim
merge bot[tip:perf/core] tools include: Move perf's linux/ compiler.h to a generic place
tools include: Move perf's linux/compiler.h to a generic place
Commit-ID: 8a625c1f61f3dd5e4ea4b5b642650416aa101ce5 Gitweb: http://git.kernel.org/tip/8a625c1f61f3dd5e4ea4b5b642650416aa101ce5 Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 9 Jan 2014 23:00:52 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 13 Jan 2014 10:06:25 -0300
tools include: Move perf's linux/compiler.h to a generic place
So that it can be shared with others like libtraceevent.
---
tools/{perf/util => }/include/linux/compiler.h | 6 +++---
tools/perf/Makefile.perf | 2 +-
tools/perf/config/Makefile | 1 +
3 files changed, 5 insertions(+), 4 deletions(-)tools/include/linux/compiler.h renamed from tools/perf/util/include/linux/compiler.h +3 -3
@@ -1,5 +1,5 @@ -#ifndef _PERF_LINUX_COMPILER_H_ -#define _PERF_LINUX_COMPILER_H_ +#ifndef _TOOLS_LINUX_COMPILER_H_ +#define _TOOLS_LINUX_COMPILER_H_#ifndef __always_inline# define __always_inline inline __attribute__((always_inline))
@@ -27,4 +27,4 @@# define __weak __attribute__((weak))#endif -#endif +#endif /* _TOOLS_LINUX_COMPILER_H */
tools/perf/Makefile.perf +1 -1
@@ -211,7 +211,7 @@ LIB_H += ../../include/linux/hash.h LIB_H += ../../include/linux/stringify.h LIB_H += util/include/linux/bitmap.h LIB_H += util/include/linux/bitops.h -LIB_H += util/include/linux/compiler.h +LIB_H += ../include/linux/compiler.h LIB_H += util/include/linux/const.h LIB_H += util/include/linux/ctype.h LIB_H += util/include/linux/kernel.h
tools/perf/config/Makefile +1 -0
@@ -232,6 +232,7 @@ endif CFLAGS += -I$(src-perf)/util/include CFLAGS += -I$(src-perf)/arch/$(ARCH)/include +CFLAGS += -I$(srctree)/tools/include/ CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi CFLAGS += -I$(srctree)/arch/$(ARCH)/include CFLAGS += -I$(srctree)/include/uapi
Namhyung Kim
maintainerPATCH 2/8 tools include: Define likely/unlikely in linux/compiler.h
In reply to Namhyung Kim--- tools/include/linux/compiler.h | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/include/linux/compiler.h +8 -0
@@ -27,4 +27,12 @@# define __weak __attribute__((weak))#endif +#ifndef likely +# define likely (x) __builtin_expect(!!(x), 1) +#endif + +#ifndef unlikely +# define unlikely (x) __builtin_expect(!!(x), 0) +#endif +#endif /* _TOOLS_LINUX_COMPILER_H */
Signature · 1 line
1.7.9.2
tip-bot for Namhyung Kim
merge bot[tip:perf/core] tools include: Define likely/unlikely in linux/ compiler.h
tools include: Define likely/unlikely in linux/compiler.h
Commit-ID: 835d44b9041e578e3e553a57dfffc7003605c93b Gitweb: http://git.kernel.org/tip/835d44b9041e578e3e553a57dfffc7003605c93b Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 9 Jan 2014 23:00:53 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 13 Jan 2014 10:06:26 -0300
tools include: Define likely/unlikely in linux/compiler.h
--- tools/include/linux/compiler.h | 8 ++++++++ tools/perf/MANIFEST | 1 + 2 files changed, 9 insertions(+)
tools/include/linux/compiler.h +8 -0
@@ -27,4 +27,12 @@# define __weak __attribute__((weak))#endif +#ifndef likely +# define likely (x) __builtin_expect(!!(x), 1) +#endif + +#ifndef unlikely +# define unlikely (x) __builtin_expect(!!(x), 0) +#endif +#endif /* _TOOLS_LINUX_COMPILER_H */
tools/perf/MANIFEST +1 -0
@@ -4,6 +4,7 @@ tools/lib/traceevent tools/lib/lk tools/lib/symbol/kallsyms.c tools/lib/symbol/kallsyms.h +tools/include/linux/compiler.h include/linux/const.h include/linux/perf_event.h include/linux/rbtree.h
Namhyung Kim
maintainerPATCH 3/8 tools include: Move perf's bug.h to a generic place
In reply to Namhyung KimSo that it can be shared with others like libtraceevent.
--- tools/include/asm/bug.h | 23 +++++++++++++++++++++++ tools/perf/Makefile.perf | 2 +- tools/perf/util/include/asm/bug.h | 22 ---------------------- 3 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 tools/include/asm/bug.h delete mode 100644 tools/perf/util/include/asm/bug.h
tools/include/asm/bug.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef _TOOLS_ASM_BUG_H +#define _TOOLS_ASM_BUG_H + +#define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0) + +#define WARN(condition, format...) ({ \ + int __ret_warn_on = !!(condition); \ + if (unlikely(__ret_warn_on)) \ + __WARN_printf(format); \ + unlikely(__ret_warn_on); \ +}) + +#define WARN_ONCE(condition, format...) ({ \ + static int __warned; \ + int __ret_warn_once = !!(condition); \ + \ + if (unlikely(__ret_warn_once)) \ + if (WARN(!__warned, format)) \ + __warned = 1; \ + unlikely(__ret_warn_once); \ +}) + +#endif /* _TOOLS_ASM_BUG_H */
tools/perf/Makefile.perf +1 -1
@@ -226,7 +226,7 @@ LIB_H += util/include/linux/string.h LIB_H += util/include/linux/types.h LIB_H += util/include/linux/linkage.h LIB_H += util/include/asm/asm-offsets.h -LIB_H += util/include/asm/bug.h +LIB_H += ../include/asm/bug.h LIB_H += util/include/asm/byteorder.h LIB_H += util/include/asm/hweight.h LIB_H += util/include/asm/swab.h
tools/perf/util/include/asm/bug.h deleted +0 -22
@@ -1,22 +0,0 @@ -#ifndef _PERF_ASM_GENERIC_BUG_H -#define _PERF_ASM_GENERIC_BUG_H - -#define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0) - -#define WARN(condition, format...) ({ \ - int __ret_warn_on = !!(condition); \ - if (unlikely(__ret_warn_on)) \ - __WARN_printf(format); \ - unlikely(__ret_warn_on); \ -}) - -#define WARN_ONCE(condition, format...) ({ \ - static int __warned; \ - int __ret_warn_once = !!(condition); \ - \ - if (unlikely(__ret_warn_once)) \ - if (WARN(!__warned, format)) \ - __warned = 1; \ - unlikely(__ret_warn_once); \ -}) -#endif
Signature · 1 line
1.7.9.2
tip-bot for Namhyung Kim
merge bot[tip:perf/core] tools include: Move perf' s bug.h to a generic place
tools include: Move perf's bug.h to a generic place
Commit-ID: 02dfc8d775f0709ab494d4b2cce12c8429ff7530 Gitweb: http://git.kernel.org/tip/02dfc8d775f0709ab494d4b2cce12c8429ff7530 Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 9 Jan 2014 23:00:54 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 13 Jan 2014 10:06:26 -0300
tools include: Move perf's bug.h to a generic place
So that it can be shared with others like libtraceevent.
---
tools/{perf/util => }/include/asm/bug.h | 7 ++++---
tools/perf/MANIFEST | 1 +
tools/perf/Makefile.perf | 2 +-
3 files changed, 6 insertions(+), 4 deletions(-)tools/include/asm/bug.h renamed from tools/perf/util/include/asm/bug.h +4 -3
@@ -1,5 +1,5 @@ -#ifndef _PERF_ASM_GENERIC_BUG_H -#define _PERF_ASM_GENERIC_BUG_H +#ifndef _TOOLS_ASM_BUG_H +#define _TOOLS_ASM_BUG_H #define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0)
@@ -19,4 +19,5 @@ __warned =1 ; \unlikely (__ret_warn_once); \ }) -#endif + +#endif /* _TOOLS_ASM_BUG_H */
tools/perf/MANIFEST +1 -0
@@ -4,6 +4,7 @@ tools/lib/traceevent tools/lib/lk tools/lib/symbol/kallsyms.c tools/lib/symbol/kallsyms.h +tools/include/asm/bug.h tools/include/linux/compiler.h include/linux/const.h include/linux/perf_event.h
tools/perf/Makefile.perf +1 -1
@@ -226,7 +226,7 @@ LIB_H += util/include/linux/string.h LIB_H += util/include/linux/types.h LIB_H += util/include/linux/linkage.h LIB_H += util/include/asm/asm-offsets.h -LIB_H += util/include/asm/bug.h +LIB_H += ../include/asm/bug.h LIB_H += util/include/asm/byteorder.h LIB_H += util/include/asm/hweight.h LIB_H += util/include/asm/swab.h
Namhyung Kim
maintainerPATCH 4/8 tools include: Include <linux/compiler.h> from asm/bug.h
In reply to Namhyung KimSince it uses unlikely() macro inside WARN()
--- tools/include/asm/bug.h | 2 ++ 1 file changed, 2 insertions(+)
tools/include/asm/bug.h +2 -0
@@ -1,6 +1,8 @@#ifndef _TOOLS_ASM_BUG_H#define _TOOLS_ASM_BUG_H +#include <linux/compiler.h> + #define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0) #define WARN(condition, format...) ({ \
Signature · 1 line
1.7.9.2
tip-bot for Namhyung Kim
merge bot[tip:perf/core] tools include: Include <linux/compiler.h> from asm/bug.h
tools include: Include <linux/compiler.h> from asm/bug.h
Commit-ID: 741a0c59032faeddac80a6237f3d7846231a3740 Gitweb: http://git.kernel.org/tip/741a0c59032faeddac80a6237f3d7846231a3740 Author: Namhyung Kim <[email protected]> AuthorDate: Thu, 9 Jan 2014 23:00:55 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 13 Jan 2014 10:14:13 -0300
tools include: Include <linux/compiler.h> from asm/bug.h
Since it uses unlikely() macro inside WARN()
--- tools/include/asm/bug.h | 2 ++ 1 file changed, 2 insertions(+)
tools/include/asm/bug.h +2 -0
@@ -1,6 +1,8 @@#ifndef _TOOLS_ASM_BUG_H#define _TOOLS_ASM_BUG_H +#include <linux/compiler.h> + #define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0) #define WARN(condition, format...) ({ \
Namhyung Kim
maintainerPATCH 5/8 tools lib traceevent: Add state member to struct trace_seq
In reply to Namhyung KimThe trace_seq->state is for tracking errors during the use of trace_seq APIs and getting rid of die() in it.
--- tools/lib/traceevent/Makefile | 2 +- tools/lib/traceevent/event-parse.h | 7 ++++++ tools/lib/traceevent/trace-seq.c | 46 ++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 6 deletions(-)
tools/lib/traceevent/Makefile +1 -1
@@ -136,7 +136,7 @@ export Q VERBOSE EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) -INCLUDES = -I. $(CONFIG_INCLUDES) +INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES) # Set compile option CFLAGS if not set elsewhere CFLAGS ?= -g -Wall
tools/lib/traceevent/event-parse.h +7 -0
@@ -58,6 +58,12 @@ struct pevent_record {#endif }; +enum trace_seq_fail { +TRACE_SEQ__GOOD , +TRACE_SEQ__BUFFER_POISONED , +TRACE_SEQ__MEM_ALLOC_FAILED , +}; +/* * Trace sequences are used to allow a function to call several other functions * to create a string of data to use (up to a max of PAGE_SIZE).
@@ -68,6 +74,7 @@ struct trace_seq {unsigned int buffer_size;unsigned int len;unsigned int readpos; +enum trace_seq_fail state; };void trace_seq_init (struct trace_seq *s);
tools/lib/traceevent/trace-seq.c +41 -5
112 lines not on this page · raw message
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 6/8 tools lib traceevent: Check return value of realloc()
In reply to Namhyung KimIf realloc() fails, it'll leak the buffer. Also increate buffer size only if the allocation succeeded.
--- tools/lib/traceevent/trace-seq.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
tools/lib/traceevent/trace-seq.c +9 -4
@@ -81,11 +81,16 @@ void trace_seq_destroy(struct trace_seq *s)static void expand_buffer (struct trace_seq *s) { - s->buffer_size +=TRACE_SEQ_BUF_SIZE ; - s->buffer =realloc (s->buffer, s->buffer_size); -if (WARN_ONCE (!s->buffer, -"Can't allocate trace_seq buffer memory" )) +char *buf; + + buf =realloc (s->buffer, s->buffer_size +TRACE_SEQ_BUF_SIZE ); +if (WARN_ONCE (!buf,"Can't allocate trace_seq buffer memory" )) { s->state =TRACE_SEQ__MEM_ALLOC_FAILED ; +return ; + } + + s->buffer = buf; + s->buffer_size +=TRACE_SEQ_BUF_SIZE ; }/**
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 7/8 tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init()
In reply to Namhyung KimUse plain malloc() and check its return value.
--- tools/lib/traceevent/trace-seq.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/lib/traceevent/trace-seq.c +5 -2
@@ -47,8 +47,11 @@ void trace_seq_init(struct trace_seq *s) s->len =0 ; s->readpos =0 ; s->buffer_size =TRACE_SEQ_BUF_SIZE ; - s->buffer =malloc_or_die (s->buffer_size); - s->state =TRACE_SEQ__GOOD ; + s->buffer =malloc (s->buffer_size); +if (s->buffer !=NULL ) + s->state =TRACE_SEQ__GOOD ; +else + s->state =TRACE_SEQ__MEM_ALLOC_FAILED ; }/**
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 8/8 tools lib traceevent: Get rid of die() finally!!
In reply to Namhyung KimNow all of its users were gone. :)
--- tools/lib/traceevent/event-utils.h | 4 ---- tools/lib/traceevent/parse-utils.c | 44 ------------------------------------ 2 files changed, 48 deletions(-)
tools/lib/traceevent/event-utils.h +0 -4
@@ -23,18 +23,14 @@#include <ctype.h> /* Can be overridden */ -void die (const char *fmt, ...); -void *malloc_or_die (unsigned int size);void warning (const char *fmt, ...);void pr_stat (const char *fmt, ...);void vpr_stat (const char *fmt,va_list ap);/* Always available */ -void __die (const char *fmt, ...);void __warning (const char *fmt, ...);void __pr_stat (const char *fmt, ...); -void __vdie (const char *fmt, ...);void __vwarning (const char *fmt, ...);void __vpr_stat (const char *fmt, ...);
tools/lib/traceevent/parse-utils.c +0 -44
53 lines not on this page · raw message
Signature · 1 line
1.7.9.2