aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Richter <tmricht@linux.vnet.ibm.com>2018-02-13 10:14:16 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-02-16 13:15:23 -0500
commiteca0fa28cd0df7369701dbee0e30ddce19c039b8 (patch)
treeec81bfc68943d0160a585256700092e70770ccb2
parent4281da235e3de91bb8deae44bc6506336ceaa88a (diff)
perf record: Provide detailed information on s390 CPU
When perf record ... is setup to record data, the s390 cpu information was a fixed string "IBM/S390". Replace this string with one containing more information about the machine. The information included in the cpuid is a comma separated list: manufacturer,type,model-capacity,model[,version,authorization] with - manufacturer: up to 16 byte name of the manufacturer (IBM). - type: a four digit number refering to the machine generation. - model-capacitiy: up to 16 characters describing number of cpus etc. - model: up to 16 characters describing model. - version: the CPU-MF counter facility version number, available on LPARs only, omitted on z/VM guests. - authorization: the CPU-MF counter facility authorization level, available on LPARs only, omitted on z/VM guests. Before: [root@s8360047 perf]# ./perf record -- sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.001 MB perf.data (4 samples) ] [root@s8360047 perf]# ./perf report --header | fgrep cpuid # cpuid : IBM/S390 [root@s8360047 perf]# After: [root@s35lp76 perf]# ./perf report --header|fgrep cpuid # cpuid : IBM,3906,704,M03,3.5,002f [root@s35lp76 perf]# Signed-off-by: Thomas Richter <tmricht@linux.vnet.ibm.com> Reviewed-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Link: http://lkml.kernel.org/r/20180213151419.80737-1-tmricht@linux.vnet.ibm.com [ Use scnprintf instead of strncat to fix build errors on gcc GNU C99 5.4.0 20160609 -march=zEC12 -m64 -mzarch -ggdb3 -O6 -std=gnu99 -fPIC -fno-omit-frame-pointer -funwind-tables -fstack-protector-all ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/arch/s390/util/header.c130
1 files changed, 125 insertions, 5 deletions
diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util/header.c
index 9fa6c3e5782c..a78064c25ced 100644
--- a/tools/perf/arch/s390/util/header.c
+++ b/tools/perf/arch/s390/util/header.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * Implementation of get_cpuid(). 2 * Implementation of get_cpuid().
3 * 3 *
4 * Copyright 2014 IBM Corp. 4 * Copyright IBM Corp. 2014, 2018
5 * Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com> 5 * Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com>
6 * Thomas Richter <tmricht@linux.vnet.ibm.com>
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License (version 2 only) 9 * it under the terms of the GNU General Public License (version 2 only)
@@ -13,16 +14,135 @@
13#include <unistd.h> 14#include <unistd.h>
14#include <stdio.h> 15#include <stdio.h>
15#include <string.h> 16#include <string.h>
17#include <ctype.h>
16 18
17#include "../../util/header.h" 19#include "../../util/header.h"
20#include "../../util/util.h"
21
22#define SYSINFO_MANU "Manufacturer:"
23#define SYSINFO_TYPE "Type:"
24#define SYSINFO_MODEL "Model:"
25#define SRVLVL_CPUMF "CPU-MF:"
26#define SRVLVL_VERSION "version="
27#define SRVLVL_AUTHORIZATION "authorization="
28#define SYSINFO "/proc/sysinfo"
29#define SRVLVL "/proc/service_levels"
18 30
19int get_cpuid(char *buffer, size_t sz) 31int get_cpuid(char *buffer, size_t sz)
20{ 32{
21 const char *cpuid = "IBM/S390"; 33 char *cp, *line = NULL, *line2;
34 char type[8], model[33], version[8], manufacturer[32], authorization[8];
35 int tpsize = 0, mdsize = 0, vssize = 0, mfsize = 0, atsize = 0;
36 int read;
37 unsigned long line_sz;
38 size_t nbytes;
39 FILE *sysinfo;
40
41 /*
42 * Scan /proc/sysinfo line by line and read out values for
43 * Manufacturer:, Type: and Model:, for example:
44 * Manufacturer: IBM
45 * Type: 2964
46 * Model: 702 N96
47 * The first word is the Model Capacity and the second word is
48 * Model (can be omitted). Both words have a maximum size of 16
49 * bytes.
50 */
51 memset(manufacturer, 0, sizeof(manufacturer));
52 memset(type, 0, sizeof(type));
53 memset(model, 0, sizeof(model));
54 memset(version, 0, sizeof(version));
55 memset(authorization, 0, sizeof(authorization));
56
57 sysinfo = fopen(SYSINFO, "r");
58 if (sysinfo == NULL)
59 return -1;
60
61 while ((read = getline(&line, &line_sz, sysinfo)) != -1) {
62 if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) {
63 line2 = line + strlen(SYSINFO_MANU);
64
65 while ((cp = strtok_r(line2, "\n ", &line2))) {
66 mfsize += scnprintf(manufacturer + mfsize,
67 sizeof(manufacturer) - mfsize, "%s", cp);
68 }
69 }
70
71 if (!strncmp(line, SYSINFO_TYPE, strlen(SYSINFO_TYPE))) {
72 line2 = line + strlen(SYSINFO_TYPE);
73
74 while ((cp = strtok_r(line2, "\n ", &line2))) {
75 tpsize += scnprintf(type + tpsize,
76 sizeof(type) - tpsize, "%s", cp);
77 }
78 }
79
80 if (!strncmp(line, SYSINFO_MODEL, strlen(SYSINFO_MODEL))) {
81 line2 = line + strlen(SYSINFO_MODEL);
82
83 while ((cp = strtok_r(line2, "\n ", &line2))) {
84 mdsize += scnprintf(model + mdsize, sizeof(type) - mdsize,
85 "%s%s", model[0] ? "," : "", cp);
86 }
87 break;
88 }
89 }
90 fclose(sysinfo);
22 91
23 if (strlen(cpuid) + 1 > sz) 92 /* Missing manufacturer, type or model information should not happen */
93 if (!manufacturer[0] || !type[0] || !model[0])
24 return -1; 94 return -1;
25 95
26 strcpy(buffer, cpuid); 96 /*
27 return 0; 97 * Scan /proc/service_levels and return the CPU-MF counter facility
98 * version number and authorization level.
99 * Optional, does not exist on z/VM guests.
100 */
101 sysinfo = fopen(SRVLVL, "r");
102 if (sysinfo == NULL)
103 goto skip_sysinfo;
104 while ((read = getline(&line, &line_sz, sysinfo)) != -1) {
105 if (strncmp(line, SRVLVL_CPUMF, strlen(SRVLVL_CPUMF)))
106 continue;
107
108 line2 = line + strlen(SRVLVL_CPUMF);
109 while ((cp = strtok_r(line2, "\n ", &line2))) {
110 if (!strncmp(cp, SRVLVL_VERSION,
111 strlen(SRVLVL_VERSION))) {
112 char *sep = strchr(cp, '=');
113
114 vssize += scnprintf(version + vssize,
115 sizeof(version) - vssize, "%s", sep + 1);
116 }
117 if (!strncmp(cp, SRVLVL_AUTHORIZATION,
118 strlen(SRVLVL_AUTHORIZATION))) {
119 char *sep = strchr(cp, '=');
120
121 atsize += scnprintf(authorization + atsize,
122 sizeof(authorization) - atsize, "%s", sep + 1);
123 }
124 }
125 }
126 fclose(sysinfo);
127
128skip_sysinfo:
129 free(line);
130
131 if (version[0] && authorization[0] )
132 nbytes = snprintf(buffer, sz, "%s,%s,%s,%s,%s",
133 manufacturer, type, model, version,
134 authorization);
135 else
136 nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type,
137 model);
138 return (nbytes >= sz) ? -1 : 0;
139}
140
141char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
142{
143 char *buf = malloc(128);
144
145 if (buf && get_cpuid(buf, 128) < 0)
146 zfree(&buf);
147 return buf;
28} 148}