Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934060Ab3GQR4V (ORCPT ); Wed, 17 Jul 2013 13:56:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17246 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933916Ab3GQRus (ORCPT ); Wed, 17 Jul 2013 13:50:48 -0400 From: Jiri Olsa To: linux-kernel@vger.kernel.org Cc: Jiri Olsa , Corey Ashford , Frederic Weisbecker , Ingo Molnar , Namhyung Kim , Paul Mackerras , Peter Zijlstra , Arnaldo Carvalho de Melo , Andi Kleen , David Ahern Subject: [PATCH 09/23] perf tools: Introduce swap_features function Date: Wed, 17 Jul 2013 19:49:49 +0200 Message-Id: <1374083403-14591-10-git-send-email-jolsa@redhat.com> In-Reply-To: <1374083403-14591-1-git-send-email-jolsa@redhat.com> References: <1374083403-14591-1-git-send-email-jolsa@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4161 Lines: 112 Introducing swap_features function to make the swapping code more clear and extensible. Signed-off-by: Jiri Olsa Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Arnaldo Carvalho de Melo Cc: Andi Kleen Cc: David Ahern --- 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/