Received: by 10.223.185.116 with SMTP id b49csp1706990wrg; Sat, 17 Feb 2018 03:38:55 -0800 (PST) X-Google-Smtp-Source: AH8x227wp16pEmsDIymJb0BXTCVxvMCNi/q3u2ew6XmfSjGN+1ui5ZxwpJPpxBgXfTDTAf4IQ6Ml X-Received: by 10.98.60.144 with SMTP id b16mr8479998pfk.61.1518867535603; Sat, 17 Feb 2018 03:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518867535; cv=none; d=google.com; s=arc-20160816; b=n+cwSLa0olp9cWlVZBBI0MCnSMYCGHSEmrGwqEmLluGyehxyz7mOQFCxIGD17Y94kP Zw8d/Qo0ZtO/i6AvCu3AGH13sMm1et4CKU4gCMac98diLtDnbj5zIdqZ3op0wBAz6t6O w1insclq80xQs3R0iX/TdIkoud2B/FQG3GxQVAg0VFVDc65pgtPOmyDQecjpkekuWRCo JnBb6CAD+9TljXUDWTxA+Fa4iB0DRWXaVScrABpzZ+HfOFZaj77WYx+9a2CJiq33pWZz VYoIT9LsYtjIpNCoVBSBCVLLqQCfkllvA8VSDHfEHToSgCFecylZXKA5O0jFOPOjz8FM 8zWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=cIjmnVg7Jl4E7hBk/2AIosPFDQNp8Fo7AlrFrHdk1Qk=; b=J25O9rLoFaO8SP8HK8b/11W0T7hjMr237/6Ykw+BbuZA3e7E2tRiqf5ibG04lkUjwi qW3IADl1jeugXi8oTOpXrGp/ZQGm+GpwhGZZnqTvjFimNscM+Ui8K5A5IqycQN1szF+y NWVJwVTmrUX8JH+Hv0qu5QuZkS9gMn5QCLD/TmKeh81KEIyyjbb0teKKPi3jfZvdtlQG VrIcM6ys9UOmypyd4Zal6qkvkvbbfq1Ljp3xFLN9V2j+99c+Yj3uvQjCqlYcfL7wFMg0 5aaMXtBZpcShmP+qw7ptFkc35qxtP/k1Xz3TM5nao+G6dtwU939ObHtG+RlWCW17JP4A sFEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si2587981pgo.550.2018.02.17.03.38.41; Sat, 17 Feb 2018 03:38:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751170AbeBQLhj (ORCPT + 99 others); Sat, 17 Feb 2018 06:37:39 -0500 Received: from terminus.zytor.com ([198.137.202.136]:51295 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179AbeBQLhV (ORCPT ); Sat, 17 Feb 2018 06:37:21 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1HBbBJr008114; Sat, 17 Feb 2018 03:37:11 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1HBbAWO008110; Sat, 17 Feb 2018 03:37:10 -0800 Date: Sat, 17 Feb 2018 03:37:10 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Thomas Richter Message-ID: Cc: hpa@zytor.com, acme@redhat.com, mingo@kernel.org, tmricht@linux.vnet.ibm.com, tglx@linutronix.de, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, brueckner@linux.vnet.ibm.com, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, brueckner@linux.vnet.ibm.com, heiko.carstens@de.ibm.com, schwidefsky@de.ibm.com, tglx@linutronix.de, tmricht@linux.vnet.ibm.com, mingo@kernel.org, acme@redhat.com, hpa@zytor.com In-Reply-To: <20180213151419.80737-1-tmricht@linux.vnet.ibm.com> References: <20180213151419.80737-1-tmricht@linux.vnet.ibm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf record: Provide detailed information on s390 CPU Git-Commit-ID: eca0fa28cd0df7369701dbee0e30ddce19c039b8 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: eca0fa28cd0df7369701dbee0e30ddce19c039b8 Gitweb: https://git.kernel.org/tip/eca0fa28cd0df7369701dbee0e30ddce19c039b8 Author: Thomas Richter AuthorDate: Tue, 13 Feb 2018 16:14:16 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 16 Feb 2018 15:15:23 -0300 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 Reviewed-by: Hendrik Brueckner Cc: Heiko Carstens Cc: Martin Schwidefsky 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 --- tools/perf/arch/s390/util/header.c | 130 +++++++++++++++++++++++++++++++++++-- 1 file changed, 125 insertions(+), 5 deletions(-) diff --git a/tools/perf/arch/s390/util/header.c b/tools/perf/arch/s390/util/header.c index 9fa6c3e..a78064c 100644 --- a/tools/perf/arch/s390/util/header.c +++ b/tools/perf/arch/s390/util/header.c @@ -1,8 +1,9 @@ /* * Implementation of get_cpuid(). * - * Copyright 2014 IBM Corp. + * Copyright IBM Corp. 2014, 2018 * Author(s): Alexander Yarygin + * Thomas Richter * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License (version 2 only) @@ -13,16 +14,135 @@ #include #include #include +#include #include "../../util/header.h" +#include "../../util/util.h" + +#define SYSINFO_MANU "Manufacturer:" +#define SYSINFO_TYPE "Type:" +#define SYSINFO_MODEL "Model:" +#define SRVLVL_CPUMF "CPU-MF:" +#define SRVLVL_VERSION "version=" +#define SRVLVL_AUTHORIZATION "authorization=" +#define SYSINFO "/proc/sysinfo" +#define SRVLVL "/proc/service_levels" int get_cpuid(char *buffer, size_t sz) { - const char *cpuid = "IBM/S390"; + char *cp, *line = NULL, *line2; + char type[8], model[33], version[8], manufacturer[32], authorization[8]; + int tpsize = 0, mdsize = 0, vssize = 0, mfsize = 0, atsize = 0; + int read; + unsigned long line_sz; + size_t nbytes; + FILE *sysinfo; + + /* + * Scan /proc/sysinfo line by line and read out values for + * Manufacturer:, Type: and Model:, for example: + * Manufacturer: IBM + * Type: 2964 + * Model: 702 N96 + * The first word is the Model Capacity and the second word is + * Model (can be omitted). Both words have a maximum size of 16 + * bytes. + */ + memset(manufacturer, 0, sizeof(manufacturer)); + memset(type, 0, sizeof(type)); + memset(model, 0, sizeof(model)); + memset(version, 0, sizeof(version)); + memset(authorization, 0, sizeof(authorization)); + + sysinfo = fopen(SYSINFO, "r"); + if (sysinfo == NULL) + return -1; + + while ((read = getline(&line, &line_sz, sysinfo)) != -1) { + if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) { + line2 = line + strlen(SYSINFO_MANU); + + while ((cp = strtok_r(line2, "\n ", &line2))) { + mfsize += scnprintf(manufacturer + mfsize, + sizeof(manufacturer) - mfsize, "%s", cp); + } + } + + if (!strncmp(line, SYSINFO_TYPE, strlen(SYSINFO_TYPE))) { + line2 = line + strlen(SYSINFO_TYPE); + + while ((cp = strtok_r(line2, "\n ", &line2))) { + tpsize += scnprintf(type + tpsize, + sizeof(type) - tpsize, "%s", cp); + } + } + + if (!strncmp(line, SYSINFO_MODEL, strlen(SYSINFO_MODEL))) { + line2 = line + strlen(SYSINFO_MODEL); + + while ((cp = strtok_r(line2, "\n ", &line2))) { + mdsize += scnprintf(model + mdsize, sizeof(type) - mdsize, + "%s%s", model[0] ? "," : "", cp); + } + break; + } + } + fclose(sysinfo); - if (strlen(cpuid) + 1 > sz) + /* Missing manufacturer, type or model information should not happen */ + if (!manufacturer[0] || !type[0] || !model[0]) return -1; - strcpy(buffer, cpuid); - return 0; + /* + * Scan /proc/service_levels and return the CPU-MF counter facility + * version number and authorization level. + * Optional, does not exist on z/VM guests. + */ + sysinfo = fopen(SRVLVL, "r"); + if (sysinfo == NULL) + goto skip_sysinfo; + while ((read = getline(&line, &line_sz, sysinfo)) != -1) { + if (strncmp(line, SRVLVL_CPUMF, strlen(SRVLVL_CPUMF))) + continue; + + line2 = line + strlen(SRVLVL_CPUMF); + while ((cp = strtok_r(line2, "\n ", &line2))) { + if (!strncmp(cp, SRVLVL_VERSION, + strlen(SRVLVL_VERSION))) { + char *sep = strchr(cp, '='); + + vssize += scnprintf(version + vssize, + sizeof(version) - vssize, "%s", sep + 1); + } + if (!strncmp(cp, SRVLVL_AUTHORIZATION, + strlen(SRVLVL_AUTHORIZATION))) { + char *sep = strchr(cp, '='); + + atsize += scnprintf(authorization + atsize, + sizeof(authorization) - atsize, "%s", sep + 1); + } + } + } + fclose(sysinfo); + +skip_sysinfo: + free(line); + + if (version[0] && authorization[0] ) + nbytes = snprintf(buffer, sz, "%s,%s,%s,%s,%s", + manufacturer, type, model, version, + authorization); + else + nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type, + model); + return (nbytes >= sz) ? -1 : 0; +} + +char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused) +{ + char *buf = malloc(128); + + if (buf && get_cpuid(buf, 128) < 0) + zfree(&buf); + return buf; }