Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752242AbbHaShU (ORCPT ); Mon, 31 Aug 2015 14:37:20 -0400 Received: from mga01.intel.com ([192.55.52.88]:16618 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751577AbbHaShS (ORCPT ); Mon, 31 Aug 2015 14:37:18 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,442,1437462000"; d="scan'208";a="794799464" From: Kan Liang To: acme@kernel.org, jolsa@kernel.org Cc: ak@linux.intel.com, linux-kernel@vger.kernel.org, Kan Liang Subject: [PATCH V3 1/3] perf,tools: Separated functions to get core_id and socket_id Date: Mon, 31 Aug 2015 07:21:20 -0400 Message-Id: <1441020082-6345-1-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3278 Lines: 128 From: Kan Liang This patch moves the codes which read core_id and socket_id into separated functions, and expose them. Signed-off-by: Kan Liang --- tools/perf/util/cpumap.c | 51 +++++++++++++++++++++++++++++++----------------- tools/perf/util/cpumap.h | 2 ++ 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 3667e21..a05d76a 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -225,17 +225,12 @@ void cpu_map__put(struct cpu_map *map) cpu_map__delete(map); } -int cpu_map__get_socket(struct cpu_map *map, int idx) +int cpu_map__get_socket_id(int cpu) { FILE *fp; const char *mnt; char path[PATH_MAX]; - int cpu, ret; - - if (idx > map->nr) - return -1; - - cpu = map->map[idx]; + int socket_id, ret; mnt = sysfs__mountpoint(); if (!mnt) @@ -248,9 +243,22 @@ int cpu_map__get_socket(struct cpu_map *map, int idx) fp = fopen(path, "r"); if (!fp) return -1; - ret = fscanf(fp, "%d", &cpu); + ret = fscanf(fp, "%d", &socket_id); fclose(fp); - return ret == 1 ? cpu : -1; + + return ret == 1 ? socket_id : -1; +} + +int cpu_map__get_socket(struct cpu_map *map, int idx) +{ + int cpu; + + if (idx > map->nr) + return -1; + + cpu = map->map[idx]; + + return cpu_map__get_socket_id(cpu); } static int cmp_ids(const void *a, const void *b) @@ -289,17 +297,12 @@ static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, return 0; } -int cpu_map__get_core(struct cpu_map *map, int idx) +int cpu_map__get_core_id(int cpu) { FILE *fp; const char *mnt; char path[PATH_MAX]; - int cpu, ret, s; - - if (idx > map->nr) - return -1; - - cpu = map->map[idx]; + int core_id, ret; mnt = sysfs__mountpoint(); if (!mnt) @@ -312,11 +315,23 @@ int cpu_map__get_core(struct cpu_map *map, int idx) fp = fopen(path, "r"); if (!fp) return -1; - ret = fscanf(fp, "%d", &cpu); + ret = fscanf(fp, "%d", &core_id); fclose(fp); - if (ret != 1) + + return ret == 1 ? core_id : -1; +} + +int cpu_map__get_core(struct cpu_map *map, int idx) +{ + int cpu, s; + + if (idx > map->nr) return -1; + cpu = map->map[idx]; + + cpu = cpu_map__get_core_id(cpu); + s = cpu_map__get_socket(map, idx); if (s == -1) return -1; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 0af9cec..8982d53 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -18,7 +18,9 @@ struct cpu_map *cpu_map__new(const char *cpu_list); struct cpu_map *cpu_map__dummy_new(void); struct cpu_map *cpu_map__read(FILE *file); size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); +int cpu_map__get_socket_id(int cpu); int cpu_map__get_socket(struct cpu_map *map, int idx); +int cpu_map__get_core_id(int cpu); int cpu_map__get_core(struct cpu_map *map, int idx); int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp); int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep); -- 1.8.3.1 -- 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/