linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>,
	Irina Tirdea <irina.tirdea@intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Pekka Enberg <penberg@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Steven Rostedt <rostedt@goodmis.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 23/25] perf tools: Add on_exit implementation
Date: Mon,  8 Oct 2012 19:32:48 -0300	[thread overview]
Message-ID: <1349735570-19339-24-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1349735570-19339-1-git-send-email-acme@infradead.org>

From: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>

on_exit() is only available in new versions of glibc.
It is not implemented in Bionic and will lead to linking errors when
compiling for Android.

Implement a wrapper for on_exit using atexit.

The implementation for on_exit is the one sent by Bernhard Rosenkraenzer in
https://lkml.org/lkml/2012/8/23/316. The configuration part from the Makefile
is different than the one from the original patch.

Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Irina Tirdea <irina.tirdea@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1349678613-7045-2-git-send-email-irina.tirdea@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile                 |    6 ++++++
 tools/perf/builtin-record.c         |   32 ++++++++++++++++++++++++++++++++
 tools/perf/config/feature-tests.mak |   11 ++++++++++-
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index d80a333..a7d8745 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -753,6 +753,12 @@ ifndef NO_STRLCPY
 	endif
 endif
 
+ifndef NO_ON_EXIT
+	ifeq ($(call try-cc,$(SOURCE_ON_EXIT),),y)
+		BASIC_CFLAGS += -DHAVE_ON_EXIT
+	endif
+endif
+
 ifndef NO_BACKTRACE
        ifeq ($(call try-cc,$(SOURCE_BACKTRACE),),y)
                BASIC_CFLAGS += -DBACKTRACE_SUPPORT
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e9231659..73b5d7f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -31,6 +31,38 @@
 #include <sched.h>
 #include <sys/mman.h>
 
+#ifndef HAVE_ON_EXIT
+#ifndef ATEXIT_MAX
+#define ATEXIT_MAX 32
+#endif
+static int __on_exit_count = 0;
+typedef void (*on_exit_func_t) (int, void *);
+static on_exit_func_t __on_exit_funcs[ATEXIT_MAX];
+static void *__on_exit_args[ATEXIT_MAX];
+static int __exitcode = 0;
+static void __handle_on_exit_funcs(void);
+static int on_exit(on_exit_func_t function, void *arg);
+#define exit(x) (exit)(__exitcode = (x))
+
+static int on_exit(on_exit_func_t function, void *arg)
+{
+	if (__on_exit_count == ATEXIT_MAX)
+		return -ENOMEM;
+	else if (__on_exit_count == 0)
+		atexit(__handle_on_exit_funcs);
+	__on_exit_funcs[__on_exit_count] = function;
+	__on_exit_args[__on_exit_count++] = arg;
+	return 0;
+}
+
+static void __handle_on_exit_funcs(void)
+{
+	int i;
+	for (i = 0; i < __on_exit_count; i++)
+		__on_exit_funcs[i] (__exitcode, __on_exit_args[i]);
+}
+#endif
+
 enum write_mode_t {
 	WRITE_FORCE,
 	WRITE_APPEND
diff --git a/tools/perf/config/feature-tests.mak b/tools/perf/config/feature-tests.mak
index 4add41b..eaeb0fd 100644
--- a/tools/perf/config/feature-tests.mak
+++ b/tools/perf/config/feature-tests.mak
@@ -203,4 +203,13 @@ int main(void)
 	return audit_open();
 }
 endef
-endif
\ No newline at end of file
+endif
+
+define SOURCE_ON_EXIT
+#include <stdio.h>
+
+int main(void)
+{
+	return on_exit(NULL, NULL);
+}
+endef
-- 
1.7.9.2.358.g22243


  parent reply	other threads:[~2012-10-08 22:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08 22:32 [GIT PULL 00/25] perf/core improvements and fixes Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 01/25] perf trace: Validate target task/user/cpu argument Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 02/25] perf trace: Explicitly enable system-wide mode if no option is given Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 03/25] perf trace: Add support for tracing workload given by command line Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 04/25] perf diff: Add -b option for perf diff to display paired entries only Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 05/25] perf diff: Add ratio computation way to compare hist entries Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 06/25] perf diff: Add option to sort entries based on diff computation Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 07/25] perf diff: Add weighted diff computation way to compare hist entries Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 08/25] perf diff: Add -p option to display period values for " Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 09/25] perf diff: Add -F option to display formula for computation Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 10/25] perf diff: Include samples without symbol in overall stats Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 11/25] perf diff: Display empty space for non paired samples Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 12/25] perf tools: Have the page size value available for all tools Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 13/25] perf machine: Introduce find_thread method Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 14/25] perf event: No need to create a thread when handling PERF_RECORD_EXIT Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 15/25] perf annotate: Handle PERF_RECORD_EXIT events Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 16/25] perf sched: " Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 17/25] perf machine: Carve up event processing specific from perf_tool Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 18/25] perf tools: Remove duplicated include from trace-event-python.c Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 19/25] perf kvm: Only process events for vcpus of interest Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 20/25] perf kvm: Remove typecast in init_kvm_event_record Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 21/25] perf kvm: Total count is a u64, print as so Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 22/25] perf kvm: Add braces around multi-line statements Arnaldo Carvalho de Melo
2012-10-08 22:32 ` Arnaldo Carvalho de Melo [this message]
2012-10-08 22:32 ` [PATCH 24/25] perf tools: Update Makefile for Android Arnaldo Carvalho de Melo
2012-10-08 22:32 ` [PATCH 25/25] Documentation: add documentation on compiling " Arnaldo Carvalho de Melo
2012-10-09 13:34 ` [GIT PULL 00/25] perf/core improvements and fixes Ingo Molnar

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=1349735570-19339-24-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=Bernhard.Rosenkranzer@linaro.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=irina.tirdea@intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=penberg@kernel.org \
    --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).