[PATCH 1/9] perf bench: fix assert when NDEBUG is defined

2012-09-08 Thread Arnaldo Carvalho de Melo
From: Irina Tirdea 

When NDEBUG is defined, the assert macro will be expanded to nothing.
Some assert calls used in perf are also including some functionality
(e.g. system calls), not only validity checks. Therefore, if NDEBUG is
defined, this functionality will be removed along with the assert.  Perf
also defines BUG_ON based on assert, so it has the same problem.

Define BUG_ON so that the condition will be executed when NDEBUG is
defined.  Replace the assert statements that have these side effects
with BUG_ON.

For defining BUG_ON, use "if (cond) {}" insted of "if (cond) ;" because
in the latter case build fails with "error: suggest braces around empty
body in an ‘if’ statement [-Werror=empty-body]"

Suggested-by: Peter Zijlstra 
Signed-off-by: Irina Tirdea 
Reviewed-by: Namhyung Kim 
Reviewed-by: Pekka Enberg 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Paul Mackerras 
Cc: Peter Zijlstra 
Cc: Steven Rostedt 
Link: 
http://lkml.kernel.org/r/1347082551-2394-1-git-send-email-irina.tir...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/bench/sched-pipe.c  |6 +++---
 tools/perf/util/include/linux/kernel.h |4 
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index 0c7454f..15911e9 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -56,13 +56,13 @@ int bench_sched_pipe(int argc, const char **argv,
 * causes error in building environment for perf
 */
int __used ret, wait_stat;
-   pid_t pid, retpid;
+   pid_t pid, retpid __used;
 
argc = parse_options(argc, argv, options,
 bench_sched_pipe_usage, 0);
 
-   assert(!pipe(pipe_1));
-   assert(!pipe(pipe_2));
+   BUG_ON(pipe(pipe_1));
+   BUG_ON(pipe(pipe_2));
 
pid = fork();
assert(pid >= 0);
diff --git a/tools/perf/util/include/linux/kernel.h 
b/tools/perf/util/include/linux/kernel.h
index b6842c1..4af9a10 100644
--- a/tools/perf/util/include/linux/kernel.h
+++ b/tools/perf/util/include/linux/kernel.h
@@ -47,8 +47,12 @@
 #endif
 
 #ifndef BUG_ON
+#ifdef NDEBUG
+#define BUG_ON(cond) do { if (cond) {} } while (0)
+#else
 #define BUG_ON(cond) assert(!(cond))
 #endif
+#endif
 
 /*
  * Both need more care to handle endianness
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/9] perf bench: fix assert when NDEBUG is defined

2012-09-08 Thread Arnaldo Carvalho de Melo
From: Irina Tirdea irina.tir...@intel.com

When NDEBUG is defined, the assert macro will be expanded to nothing.
Some assert calls used in perf are also including some functionality
(e.g. system calls), not only validity checks. Therefore, if NDEBUG is
defined, this functionality will be removed along with the assert.  Perf
also defines BUG_ON based on assert, so it has the same problem.

Define BUG_ON so that the condition will be executed when NDEBUG is
defined.  Replace the assert statements that have these side effects
with BUG_ON.

For defining BUG_ON, use if (cond) {} insted of if (cond) ; because
in the latter case build fails with error: suggest braces around empty
body in an ‘if’ statement [-Werror=empty-body]

Suggested-by: Peter Zijlstra a.p.zijls...@chello.nl
Signed-off-by: Irina Tirdea irina.tir...@intel.com
Reviewed-by: Namhyung Kim namhy...@kernel.org
Reviewed-by: Pekka Enberg penb...@kernel.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@redhat.com
Cc: Namhyung Kim namhyung@lge.com
Cc: Paul Mackerras pau...@samba.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Cc: Steven Rostedt rost...@goodmis.org
Link: 
http://lkml.kernel.org/r/1347082551-2394-1-git-send-email-irina.tir...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/bench/sched-pipe.c  |6 +++---
 tools/perf/util/include/linux/kernel.h |4 
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index 0c7454f..15911e9 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -56,13 +56,13 @@ int bench_sched_pipe(int argc, const char **argv,
 * causes error in building environment for perf
 */
int __used ret, wait_stat;
-   pid_t pid, retpid;
+   pid_t pid, retpid __used;
 
argc = parse_options(argc, argv, options,
 bench_sched_pipe_usage, 0);
 
-   assert(!pipe(pipe_1));
-   assert(!pipe(pipe_2));
+   BUG_ON(pipe(pipe_1));
+   BUG_ON(pipe(pipe_2));
 
pid = fork();
assert(pid = 0);
diff --git a/tools/perf/util/include/linux/kernel.h 
b/tools/perf/util/include/linux/kernel.h
index b6842c1..4af9a10 100644
--- a/tools/perf/util/include/linux/kernel.h
+++ b/tools/perf/util/include/linux/kernel.h
@@ -47,8 +47,12 @@
 #endif
 
 #ifndef BUG_ON
+#ifdef NDEBUG
+#define BUG_ON(cond) do { if (cond) {} } while (0)
+#else
 #define BUG_ON(cond) assert(!(cond))
 #endif
+#endif
 
 /*
  * Both need more care to handle endianness
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/