[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1374083403-14591-10-git-send-email-jolsa@redhat.com>
Date: Wed, 17 Jul 2013 19:49:49 +0200
From: Jiri Olsa <jolsa@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: Jiri Olsa <jolsa@...hat.com>,
Corey Ashford <cjashfor@...ux.vnet.ibm.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Ingo Molnar <mingo@...e.hu>,
Namhyung Kim <namhyung@...nel.org>,
Paul Mackerras <paulus@...ba.org>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
Andi Kleen <ak@...ux.intel.com>,
David Ahern <dsahern@...il.com>
Subject: [PATCH 09/23] perf tools: Introduce swap_features function
Introducing swap_features function to make the swapping
code more clear and extensible.
Signed-off-by: Jiri Olsa <jolsa@...hat.com>
Cc: Corey Ashford <cjashfor@...ux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Ingo Molnar <mingo@...e.hu>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Andi Kleen <ak@...ux.intel.com>
Cc: David Ahern <dsahern@...il.com>
---
tools/perf/util/header.c | 69 ++++++++++++++++++++++++------------------------
1 file changed, 35 insertions(+), 34 deletions(-)
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 4ebe4a1..4d82dac 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2512,6 +2512,39 @@ do { \
return -1;
}
+static void swap_features(unsigned long *adds_features)
+{
+ /*
+ * feature bitmap is declared as an array of unsigned longs --
+ * not good since its size can differ between the host that
+ * generated the data file and the host analyzing the file.
+ *
+ * We need to handle endianness, but we don't know the size of
+ * the unsigned long where the file was generated. Take a best
+ * guess at determining it: try 64-bit swap first (ie., file
+ * created on a 64-bit host), and check if the hostname feature
+ * bit is set (this feature bit is forced on as of fbe96f2).
+ * If the bit is not, undo the 64-bit swap and try a 32-bit
+ * swap. If the hostname bit is still not set (e.g., older data
+ * file), punt and fallback to the original behavior --
+ * clearing all feature bits and setting buildid.
+ */
+ mem_bswap_64(adds_features, BITS_TO_U64(HEADER_FEAT_BITS));
+
+ if (!test_bit(HEADER_HOSTNAME, adds_features)) {
+ /* unswap as u64 */
+ mem_bswap_64(adds_features, BITS_TO_U64(HEADER_FEAT_BITS));
+
+ /* unswap as u32 */
+ mem_bswap_32(adds_features, BITS_TO_U32(HEADER_FEAT_BITS));
+ }
+
+ if (!test_bit(HEADER_HOSTNAME, adds_features)) {
+ bitmap_zero(adds_features, HEADER_FEAT_BITS);
+ set_bit(HEADER_BUILD_ID, adds_features);
+ }
+}
+
int perf_file_header__read(struct perf_file_header *header,
struct perf_header *ph, int fd)
{
@@ -2540,40 +2573,8 @@ int perf_file_header__read(struct perf_file_header *header,
bitmap_zero(header->adds_features, HEADER_FEAT_BITS);
else
return -1;
- } else if (ph->needs_swap) {
- /*
- * feature bitmap is declared as an array of unsigned longs --
- * not good since its size can differ between the host that
- * generated the data file and the host analyzing the file.
- *
- * We need to handle endianness, but we don't know the size of
- * the unsigned long where the file was generated. Take a best
- * guess at determining it: try 64-bit swap first (ie., file
- * created on a 64-bit host), and check if the hostname feature
- * bit is set (this feature bit is forced on as of fbe96f2).
- * If the bit is not, undo the 64-bit swap and try a 32-bit
- * swap. If the hostname bit is still not set (e.g., older data
- * file), punt and fallback to the original behavior --
- * clearing all feature bits and setting buildid.
- */
- mem_bswap_64(&header->adds_features,
- BITS_TO_U64(HEADER_FEAT_BITS));
-
- if (!test_bit(HEADER_HOSTNAME, header->adds_features)) {
- /* unswap as u64 */
- mem_bswap_64(&header->adds_features,
- BITS_TO_U64(HEADER_FEAT_BITS));
-
- /* unswap as u32 */
- mem_bswap_32(&header->adds_features,
- BITS_TO_U32(HEADER_FEAT_BITS));
- }
-
- if (!test_bit(HEADER_HOSTNAME, header->adds_features)) {
- bitmap_zero(header->adds_features, HEADER_FEAT_BITS);
- set_bit(HEADER_BUILD_ID, header->adds_features);
- }
- }
+ } else if (ph->needs_swap)
+ swap_features(header->adds_features);
memcpy(&ph->adds_features, &header->adds_features,
sizeof(ph->adds_features));
--
1.7.11.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists