Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1221194 > unrolled thread

[PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes

Started bykan.liang@intel.com
First post2015-09-09 04:50 +0200
Last post2015-09-10 23:00 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes kan.liang@intel.com - 2015-09-09 04:50 +0200
    Re: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU  attributes Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-10 16:00 +0200
      Re: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU  attributes Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-10 17:40 +0200
        RE: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU  attributes "Liang, Kan" <kan.liang@intel.com> - 2015-09-10 23:00 +0200

#1221194 — [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes

Fromkan.liang@intel.com
Date2015-09-09 04:50 +0200
Subject[PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes
Message-ID<q6DCq-6DS-7@gated-at.bofh.it>
From: Kan Liang <kan.liang@intel.com>

This patch introduces generic FEAT for CPU attributes. For the patch
set, we only need cpu max frequency. But it can be easily extented to
support more other CPU attributes.
The cpu max frequency is from the first online cpu.

Signed-off-by: Kan Liang <kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/cpumap.c | 32 ++++++++++++++++++++++++++
 tools/perf/util/cpumap.h |  1 +
 tools/perf/util/header.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/header.h | 12 ++++++++++
 4 files changed, 104 insertions(+)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index a05d76a..671ee83 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -514,3 +514,35 @@ int cpu__setup_cpunode_map(void)
 	closedir(dir1);
 	return 0;
 }
+
+u64 get_cpu_max_freq(void)
+{
+	const char *mnt;
+	char path[PATH_MAX], tmp;
+	FILE *fp;
+	u64 freq;
+	int cpu = 0;
+	int ret;
+
+	mnt = sysfs__mountpoint();
+	if (!mnt)
+		return 0;
+
+	snprintf(path, PATH_MAX, "%s/devices/system/cpu/online", mnt);
+	fp = fopen(path, "r");
+	if (fp) {
+		ret = fscanf(fp, "%u%c", &cpu, &tmp);
+		fclose(fp);
+		if (ret < 1)
+			return 0;
+	}
+
+	snprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", mnt, cpu);
+	fp = fopen(path, "r");
+	if (!fp)
+		return 0;
+	ret = fscanf(fp, "%lu", &freq);
+	fclose(fp);
+
+	return (ret == 1) ? freq : 0;
+}
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 8982d53..06cd2c4 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -60,6 +60,7 @@ int max_node_num;
 int *cpunode_map;
 
 int cpu__setup_cpunode_map(void);
+u64 get_cpu_max_freq(void);
 
 static inline int cpu__max_node(void)
 {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 8fd7b7d..3535dcb 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -885,6 +885,23 @@ write_it:
 	return do_write_string(fd, buffer);
 }
 
+static int write_cpu_attributes(int fd, struct perf_header *h __maybe_unused,
+				struct perf_evlist *evlist __maybe_unused)
+{
+	u32 tag_id;
+	u64 max_freq;
+	int ret;
+
+	tag_id = PERF_HEADER_CPU_MAX_FREQ;
+	ret = do_write(fd, &tag_id, sizeof(tag_id));
+	if (ret < 0)
+		return ret;
+
+	max_freq = get_cpu_max_freq();
+
+	return do_write(fd, &max_freq, sizeof(max_freq));
+}
+
 static int write_branch_stack(int fd __maybe_unused,
 			      struct perf_header *h __maybe_unused,
 		       struct perf_evlist *evlist __maybe_unused)
@@ -1185,6 +1202,11 @@ static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
 	fprintf(fp, "# cpuid : %s\n", ph->env.cpuid);
 }
 
+static void print_cpu_attributes(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
+{
+	fprintf(fp, "# CPU attributes: max frequency = %lu KHz\n", ph->env.cpuattr.max_freq);
+}
+
 static void print_branch_stack(struct perf_header *ph __maybe_unused,
 			       int fd __maybe_unused, FILE *fp)
 {
@@ -1498,6 +1520,42 @@ static int process_cpuid(struct perf_file_section *section __maybe_unused,
 	return ph->env.cpuid ? 0 : -ENOMEM;
 }
 
+static int process_cpu_attributes(struct perf_file_section *section __maybe_unused,
+				  struct perf_header *ph, int fd,
+				  void *data __maybe_unused)
+{
+	ssize_t ret;
+	u32 i, tag_id;
+	u64 nr;
+
+	for (i = 0; i < PERF_HEADER_CPU_ATTR_MAX; i++) {
+
+		ret = readn(fd, &tag_id, sizeof(tag_id));
+		if (ret != sizeof(tag_id))
+			return -1;
+
+		if (ph->needs_swap)
+			nr = bswap_32(tag_id);
+
+		if (tag_id >= PERF_HEADER_CPU_ATTR_MAX) {
+			pr_debug("The number of cpu attributes is not expected. "
+				 "You may need to upgrade the perf tool.\n");
+			return -1;
+		}
+
+		ret = readn(fd, &nr, sizeof(nr));
+		if (ret != sizeof(nr))
+			return -1;
+
+		if (ph->needs_swap)
+			nr = bswap_64(nr);
+
+		ph->env.cpu_attr[tag_id] = nr;
+	}
+
+	return 0;
+}
+
 static int process_total_mem(struct perf_file_section *section __maybe_unused,
 			     struct perf_header *ph, int fd,
 			     void *data __maybe_unused)
@@ -1983,6 +2041,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
 	FEAT_OPP(HEADER_PMU_MAPPINGS,	pmu_mappings),
 	FEAT_OPP(HEADER_GROUP_DESC,	group_desc),
 	FEAT_OPP(HEADER_AUXTRACE,	auxtrace),
+	FEAT_OPP(HEADER_CPU_ATTR,	cpu_attributes),
 };
 
 struct header_print_data {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 975d803..dd9f6b0 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -31,6 +31,7 @@ enum {
 	HEADER_PMU_MAPPINGS,
 	HEADER_GROUP_DESC,
 	HEADER_AUXTRACE,
+	HEADER_CPU_ATTR,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
@@ -71,6 +72,11 @@ struct cpu_topology_map {
 	int	core_id;
 };
 
+enum perf_header_cpu_attr {
+	PERF_HEADER_CPU_MAX_FREQ	= 0,
+	PERF_HEADER_CPU_ATTR_MAX,
+};
+
 struct perf_env {
 	char			*hostname;
 	char			*os_release;
@@ -95,6 +101,12 @@ struct perf_env {
 	char			*numa_nodes;
 	char			*pmu_mappings;
 	struct cpu_topology_map	*cpu;
+	union  {
+		u64		cpu_attr[PERF_HEADER_CPU_ATTR_MAX];
+		struct {
+			u64	max_freq;
+		} cpuattr;
+	};
 };
 
 struct perf_header {
-- 
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/

[toc] | [next] | [standalone]


#1222216 — Re: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-09-10 16:00 +0200
SubjectRe: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes
Message-ID<q7aym-3dh-25@gated-at.bofh.it>
In reply to#1221194
Em Tue, Sep 08, 2015 at 03:32:44PM -0400, kan.liang@intel.com escreveu:
> From: Kan Liang <kan.liang@intel.com>
> 
> This patch introduces generic FEAT for CPU attributes. For the patch
> set, we only need cpu max frequency. But it can be easily extented to
> support more other CPU attributes.
> The cpu max frequency is from the first online cpu.

Ok, but don't we have to do error handling? i.e. you are returning 0 for
any error in trying to read the cpu max freq, shouldn't we bail out
somewhere?

And please move this get_cpu_max_freq() thing out of the cpumap.[ch]
files, it is not even a need completely specific to perf tooling, there
must be somewhere in tools/lib/api/ (kernel APIs) where this fits, no?

More comments below.

- Arnaldo
 
> Signed-off-by: Kan Liang <kan.liang@intel.com>
> Acked-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/util/cpumap.c | 32 ++++++++++++++++++++++++++
>  tools/perf/util/cpumap.h |  1 +
>  tools/perf/util/header.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/perf/util/header.h | 12 ++++++++++
>  4 files changed, 104 insertions(+)
> 
> diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
> index a05d76a..671ee83 100644
> --- a/tools/perf/util/cpumap.c
> +++ b/tools/perf/util/cpumap.c
> @@ -514,3 +514,35 @@ int cpu__setup_cpunode_map(void)
>  	closedir(dir1);
>  	return 0;
>  }
> +
> +u64 get_cpu_max_freq(void)
> +{
> +	const char *mnt;
> +	char path[PATH_MAX], tmp;
> +	FILE *fp;
> +	u64 freq;
> +	int cpu = 0;
> +	int ret;
> +
> +	mnt = sysfs__mountpoint();
> +	if (!mnt)
> +		return 0;

See? Can't find the sysfs mount point? No problem, return 0 max freq.

> +
> +	snprintf(path, PATH_MAX, "%s/devices/system/cpu/online", mnt);
> +	fp = fopen(path, "r");
> +	if (fp) {
> +		ret = fscanf(fp, "%u%c", &cpu, &tmp);
> +		fclose(fp);
> +		if (ret < 1)
> +			return 0;

Can't parse it? 0

> +	}
> +
> +	snprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", mnt, cpu);
> +	fp = fopen(path, "r");
> +	if (!fp)
> +		return 0;

Ditto. Return soem error here please.

> +	ret = fscanf(fp, "%lu", &freq);
> +	fclose(fp);
> +
> +	return (ret == 1) ? freq : 0;
> +}
> diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
> index 8982d53..06cd2c4 100644
> --- a/tools/perf/util/cpumap.h
> +++ b/tools/perf/util/cpumap.h
> @@ -60,6 +60,7 @@ int max_node_num;
>  int *cpunode_map;
>  
>  int cpu__setup_cpunode_map(void);
> +u64 get_cpu_max_freq(void);

>  
>  static inline int cpu__max_node(void)
>  {
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 8fd7b7d..3535dcb 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -885,6 +885,23 @@ write_it:
>  	return do_write_string(fd, buffer);
>  }
>  
> +static int write_cpu_attributes(int fd, struct perf_header *h __maybe_unused,
> +				struct perf_evlist *evlist __maybe_unused)
> +{
> +	u32 tag_id;
> +	u64 max_freq;
> +	int ret;
> +
> +	tag_id = PERF_HEADER_CPU_MAX_FREQ;
> +	ret = do_write(fd, &tag_id, sizeof(tag_id));
> +	if (ret < 0)
> +		return ret;
> +
> +	max_freq = get_cpu_max_freq();

Here, do the error handling, return whatever errno code this function
returned, probably the feature code will use it to warn the user
somehow.

> +
> +	return do_write(fd, &max_freq, sizeof(max_freq));
> +}
> +
>  static int write_branch_stack(int fd __maybe_unused,
>  			      struct perf_header *h __maybe_unused,
>  		       struct perf_evlist *evlist __maybe_unused)
> @@ -1185,6 +1202,11 @@ static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
>  	fprintf(fp, "# cpuid : %s\n", ph->env.cpuid);
>  }
>  
> +static void print_cpu_attributes(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
> +{
> +	fprintf(fp, "# CPU attributes: max frequency = %lu KHz\n", ph->env.cpuattr.max_freq);
> +}
> +
>  static void print_branch_stack(struct perf_header *ph __maybe_unused,
>  			       int fd __maybe_unused, FILE *fp)
>  {
> @@ -1498,6 +1520,42 @@ static int process_cpuid(struct perf_file_section *section __maybe_unused,
>  	return ph->env.cpuid ? 0 : -ENOMEM;
>  }
>  
> +static int process_cpu_attributes(struct perf_file_section *section __maybe_unused,
> +				  struct perf_header *ph, int fd,
> +				  void *data __maybe_unused)
> +{
> +	ssize_t ret;
> +	u32 i, tag_id;
> +	u64 nr;
> +
> +	for (i = 0; i < PERF_HEADER_CPU_ATTR_MAX; i++) {
> +
> +		ret = readn(fd, &tag_id, sizeof(tag_id));
> +		if (ret != sizeof(tag_id))
> +			return -1;

Return some sensible errno... Its not because
perf_header__process_sections() doesn't check them that we shouldn't
return ;-\ I'll fix perf_header__process_sections() to stop the process
and warn the user if some error happens...

> +
> +		if (ph->needs_swap)
> +			nr = bswap_32(tag_id);
> +
> +		if (tag_id >= PERF_HEADER_CPU_ATTR_MAX) {
> +			pr_debug("The number of cpu attributes is not expected. "
> +				 "You may need to upgrade the perf tool.\n");
> +			return -1;


ditto
> +		}
> +
> +		ret = readn(fd, &nr, sizeof(nr));
> +		if (ret != sizeof(nr))
> +			return -1;


ditto

> +
> +		if (ph->needs_swap)
> +			nr = bswap_64(nr);
> +
> +		ph->env.cpu_attr[tag_id] = nr;
> +	}
> +
> +	return 0;
> +}
> +
>  static int process_total_mem(struct perf_file_section *section __maybe_unused,
>  			     struct perf_header *ph, int fd,
>  			     void *data __maybe_unused)
> @@ -1983,6 +2041,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
>  	FEAT_OPP(HEADER_PMU_MAPPINGS,	pmu_mappings),
>  	FEAT_OPP(HEADER_GROUP_DESC,	group_desc),
>  	FEAT_OPP(HEADER_AUXTRACE,	auxtrace),
> +	FEAT_OPP(HEADER_CPU_ATTR,	cpu_attributes),
>  };
>  
>  struct header_print_data {
> diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
> index 975d803..dd9f6b0 100644
> --- a/tools/perf/util/header.h
> +++ b/tools/perf/util/header.h
> @@ -31,6 +31,7 @@ enum {
>  	HEADER_PMU_MAPPINGS,
>  	HEADER_GROUP_DESC,
>  	HEADER_AUXTRACE,
> +	HEADER_CPU_ATTR,
>  	HEADER_LAST_FEATURE,
>  	HEADER_FEAT_BITS	= 256,
>  };
> @@ -71,6 +72,11 @@ struct cpu_topology_map {
>  	int	core_id;
>  };
>  
> +enum perf_header_cpu_attr {
> +	PERF_HEADER_CPU_MAX_FREQ	= 0,
> +	PERF_HEADER_CPU_ATTR_MAX,
> +};
> +
>  struct perf_env {
>  	char			*hostname;
>  	char			*os_release;
> @@ -95,6 +101,12 @@ struct perf_env {
>  	char			*numa_nodes;
>  	char			*pmu_mappings;
>  	struct cpu_topology_map	*cpu;
> +	union  {
> +		u64		cpu_attr[PERF_HEADER_CPU_ATTR_MAX];
> +		struct {
> +			u64	max_freq;
> +		} cpuattr;
> +	};

Ok, these need moving to env.h, but lets first get that patchkit
merged... Looking at your other patches

>  };
>  
>  struct perf_header {
> -- 
> 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/

[toc] | [prev] | [next] | [standalone]


#1222266 — Re: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-09-10 17:40 +0200
SubjectRe: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes
Message-ID<q7c79-5Cv-25@gated-at.bofh.it>
In reply to#1222216
Em Thu, Sep 10, 2015 at 10:58:38AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Tue, Sep 08, 2015 at 03:32:44PM -0400, kan.liang@intel.com escreveu:
> > This patch introduces generic FEAT for CPU attributes. For the patch
> > set, we only need cpu max frequency. But it can be easily extented to
> > support more other CPU attributes.
> > The cpu max frequency is from the first online cpu.
 
> Ok, but don't we have to do error handling? i.e. you are returning 0 for
> any error in trying to read the cpu max freq, shouldn't we bail out
> somewhere?
 
> And please move this get_cpu_max_freq() thing out of the cpumap.[ch]
> files, it is not even a need completely specific to perf tooling, there
> must be somewhere in tools/lib/api/ (kernel APIs) where this fits, no?

So, I've updated my perf/env branch with routines to do that, that uses
infrastructure to read files from virtual dirs that was there plus a few
I just introduced, in the same vein, I will update your patches to use
them and put there as well, for your consideration.

The HEAD there is the one below:

- Arnaldo

commit 2bc1fae4ed8a842f52dc374449d37c3ec1fa1986
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Thu Sep 10 12:20:14 2015 -0300

    tools lib cpu: Introduce cpu.[ch] to read sysfs cpu related information
    
    E.g.:
    
     $ ./cpu__get_max_freq
     3200000
    
    It does that, as Kan's patch does, by looking at these files:
    
      $ cat /sys/devices/system/cpu/online
      0-3
      $ ./sysfs__read_ull
      devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
      /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq=3200000
      $
    
    I.e. find out the first online CPU, then read its cpufreq info.
    
    But do it in tools/lib/api/, so that other tools living code can use
    it, not just perf.
    
    Based-on-a-patch-by: Kan Liang <kan.liang@intel.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Borislav Petkov <bp@suse.de>
    Cc: David Ahern <dsahern@gmail.com>
    Cc: Frederic Weisbecker <fweisbec@gmail.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Stephane Eranian <eranian@google.com>
    Link: http://lkml.kernel.org/n/tip-915v4cvxqplaub8qco66b9mv@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

diff --git a/tools/lib/api/Build b/tools/lib/api/Build
index 3653965cf481..e8b8a23b9bf4 100644
--- a/tools/lib/api/Build
+++ b/tools/lib/api/Build
@@ -1,2 +1,3 @@
 libapi-y += fd/
 libapi-y += fs/
+libapi-y += cpu.o
diff --git a/tools/lib/api/cpu.c b/tools/lib/api/cpu.c
new file mode 100644
index 000000000000..8c6489356e3a
--- /dev/null
+++ b/tools/lib/api/cpu.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+#include "cpu.h"
+#include "fs/fs.h"
+
+int cpu__get_max_freq(unsigned long long *freq)
+{
+	char entry[PATH_MAX];
+	int cpu;
+
+	if (sysfs__read_int("devices/system/cpu/online", &cpu) < 0)
+		return -1;
+
+	snprintf(entry, sizeof(entry),
+		 "devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu);
+
+	return sysfs__read_ull(entry, freq);
+}
diff --git a/tools/lib/api/cpu.h b/tools/lib/api/cpu.h
new file mode 100644
index 000000000000..81e9d3955961
--- /dev/null
+++ b/tools/lib/api/cpu.h
@@ -0,0 +1,6 @@
+#ifndef __API_CPU__
+#define __API_CPU__
+
+int cpu__get_max_freq(unsigned long long *freq);
+
+#endif /* __API_CPU__ */
--
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/

[toc] | [prev] | [next] | [standalone]


#1222394 — RE: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes

From"Liang, Kan" <kan.liang@intel.com>
Date2015-09-10 23:00 +0200
SubjectRE: [PATCH V9 1/6] perf,tools: introduce generic FEAT for CPU attributes
Message-ID<q7h6O-4ne-11@gated-at.bofh.it>
In reply to#1222266
> 
> Em Thu, Sep 10, 2015 at 10:58:38AM -0300, Arnaldo Carvalho de Melo
> escreveu:
> > Em Tue, Sep 08, 2015 at 03:32:44PM -0400, kan.liang@intel.com escreveu:
> > > This patch introduces generic FEAT for CPU attributes. For the patch
> > > set, we only need cpu max frequency. But it can be easily extented
> > > to support more other CPU attributes.
> > > The cpu max frequency is from the first online cpu.
> 
> > Ok, but don't we have to do error handling? i.e. you are returning 0
> > for any error in trying to read the cpu max freq, shouldn't we bail
> > out somewhere?
> 
> > And please move this get_cpu_max_freq() thing out of the cpumap.[ch]
> > files, it is not even a need completely specific to perf tooling,
> > there must be somewhere in tools/lib/api/ (kernel APIs) where this fits,
> no?
> 
> So, I've updated my perf/env branch with routines to do that, that uses
> infrastructure to read files from virtual dirs that was there plus a few I just
> introduced, in the same vein

The two new patches in perf/env are good to me.
Commit 4ee5cc5708d89f380ab5371181b65dd74935352d
Commit 57d54be1e9074049c8695c522a499f8a7d62ef2d
Acked-by: Kan Liang <kan.liang@intel.com>

> I will update your patches to use them and
> put there as well, for your consideration.
> 

Thanks. Please let me know, when you finished.
I will update the rest of the per-sample freq patches, and repost them
for review then.

Thanks,
Kan

> The HEAD there is the one below:
> 
> - Arnaldo
> 
> commit 2bc1fae4ed8a842f52dc374449d37c3ec1fa1986
> Author: Arnaldo Carvalho de Melo <acme@redhat.com>
> Date:   Thu Sep 10 12:20:14 2015 -0300
> 
>     tools lib cpu: Introduce cpu.[ch] to read sysfs cpu related information
> 
>     E.g.:
> 
>      $ ./cpu__get_max_freq
>      3200000
> 
>     It does that, as Kan's patch does, by looking at these files:
> 
>       $ cat /sys/devices/system/cpu/online
>       0-3
>       $ ./sysfs__read_ull
>       devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
>       /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq=3200000
>       $
> 
>     I.e. find out the first online CPU, then read its cpufreq info.
> 
>     But do it in tools/lib/api/, so that other tools living code can use
>     it, not just perf.
> 
>     Based-on-a-patch-by: Kan Liang <kan.liang@intel.com>
>     Cc: Adrian Hunter <adrian.hunter@intel.com>
>     Cc: Borislav Petkov <bp@suse.de>
>     Cc: David Ahern <dsahern@gmail.com>
>     Cc: Frederic Weisbecker <fweisbec@gmail.com>
>     Cc: Jiri Olsa <jolsa@redhat.com>
>     Cc: Namhyung Kim <namhyung@kernel.org>
>     Cc: Stephane Eranian <eranian@google.com>
>     Link: http://lkml.kernel.org/n/tip-
> 915v4cvxqplaub8qco66b9mv@git.kernel.org
>     Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> diff --git a/tools/lib/api/Build b/tools/lib/api/Build index
> 3653965cf481..e8b8a23b9bf4 100644
> --- a/tools/lib/api/Build
> +++ b/tools/lib/api/Build
> @@ -1,2 +1,3 @@
>  libapi-y += fd/
>  libapi-y += fs/
> +libapi-y += cpu.o
> diff --git a/tools/lib/api/cpu.c b/tools/lib/api/cpu.c new file mode 100644
> index 000000000000..8c6489356e3a
> --- /dev/null
> +++ b/tools/lib/api/cpu.c
> @@ -0,0 +1,18 @@
> +#include <stdio.h>
> +
> +#include "cpu.h"
> +#include "fs/fs.h"
> +
> +int cpu__get_max_freq(unsigned long long *freq) {
> +	char entry[PATH_MAX];
> +	int cpu;
> +
> +	if (sysfs__read_int("devices/system/cpu/online", &cpu) < 0)
> +		return -1;
> +
> +	snprintf(entry, sizeof(entry),
> +		 "devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq",
> cpu);
> +
> +	return sysfs__read_ull(entry, freq);
> +}
> diff --git a/tools/lib/api/cpu.h b/tools/lib/api/cpu.h new file mode 100644
> index 000000000000..81e9d3955961
> --- /dev/null
> +++ b/tools/lib/api/cpu.h
> @@ -0,0 +1,6 @@
> +#ifndef __API_CPU__
> +#define __API_CPU__
> +
> +int cpu__get_max_freq(unsigned long long *freq);
> +
> +#endif /* __API_CPU__ */
--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web