Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1974669imu; Thu, 17 Jan 2019 06:25:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN47M4edVv6hjI9qyan8mRvFDKghaZnz2msw0tzEsd9iYCr9Aq/QXpYdRb4OLmAYq0U78VU5 X-Received: by 2002:a17:902:14b:: with SMTP id 69mr15362358plb.52.1547735108612; Thu, 17 Jan 2019 06:25:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547735108; cv=none; d=google.com; s=arc-20160816; b=FkVTTZkPTR2O3+Gwyk/HZiyPTpvHqfsHBGWBpluDZTQWtkRRk7L+tRChdIYIkS+apB sbA0BaKWaVqFGLM3PeRhSrxDbpCTz5y2CeDpQeLnOi1zdjqW6tyHzMzgXc2HB2+u+y4a +C3oKbvN2t2rfP3UKevkjpm58CrGa9kRZB9+pet/WYP6ssIuktiQNWRATLVzybhBnUja yZs6SPlDlUGcAkEItz7CoQzYG9FTmsry0zibPzmjNu4XV+wgPU4i1bsn3Owj2c9VmXxl EXTOLsZYqLS5urYIRJMI4BYb7BFc1pOXk+pJDpFzi997KillDOQPn953I04DpKwVnGu6 9aVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yDRCcqgOzX9Pany53Y2LRKPLsSRwD0pqmAdYNPMxV7o=; b=gPFS1oGDR/6NTi7O52upk5O7OD4qJ9eeLhtUUJ8RdrcW89CA3cecxLrT3JxDgKsxTf 4tdSDKug/F1kv2v5eLredMahM6RGbPdGsHtT+hYYRm+su4H4gPLrvEf/bMY/7AK2bk8y OUe0ZIuWf3qz7KTEUPOU8KoAnPzZhKrx6J+dbUO2BLCWYwI1n9NYLDklHhj4fh4214k/ PXwQAh+R8X1r3uNXEjGfnX5JtFyse+2wkQByFPFF1UgeZxr5OmnL1QkEyRqw2CdpFNI4 gmS626yZpI6ESETNACpWbgmQ0PS6VvYLA9AuBj5xkovf/GSga+bH8xdQssaZZyfDKldJ lQoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GTbg+QNc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s5si1723059plr.211.2019.01.17.06.24.50; Thu, 17 Jan 2019 06:25:08 -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; dkim=pass header.i=@kernel.org header.s=default header.b=GTbg+QNc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727692AbfAQOBA (ORCPT + 99 others); Thu, 17 Jan 2019 09:01:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:54682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727664AbfAQOA6 (ORCPT ); Thu, 17 Jan 2019 09:00:58 -0500 Received: from quaco.ghostprotocols.net (unknown [190.15.121.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9EB1420652; Thu, 17 Jan 2019 14:00:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547733657; bh=QZ0XJiyyvpjZU20z7uyqZyvM3RqJUcir3vlkVaCqBek=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GTbg+QNcaNrUtpzo92lS3CWJ2kw5Wm4M8RBZ0KtUULehAafscPm3wNws7cwsXLLbO 4cMk4MINUz68qmmCoZ0HRWKH8zzA3etYqj4+NNburgtN8fzZV1oW9AenBtiKDLwn2d zjCbIlLWBR2Vo8YtW6yCLbse0iQeWjHeXUqZSboo= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id D2CA841AB5; Thu, 17 Jan 2019 11:00:53 -0300 (-03) Date: Thu, 17 Jan 2019 11:00:53 -0300 From: Arnaldo Carvalho de Melo To: Thomas Richter Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, brueckner@linux.vnet.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: Re: [PATCHv2 1/3] perf report: Display s390 diagnostic counter sets Message-ID: <20190117140053.GJ11922@kernel.org> References: <20190117093003.96287-1-tmricht@linux.ibm.com> <20190117093003.96287-2-tmricht@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190117093003.96287-2-tmricht@linux.ibm.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Thu, Jan 17, 2019 at 10:30:01AM +0100, Thomas Richter escreveu: > On s390 the event bc000 (also named CF_DIAG) > extracts the CPU Measurement Facility diagnostic counter sets > and displays them as counter number and counter value > pairs sorted by counter set number. Thanks for taking my comments into account, I did some changes, documented in the updated patch, that is at the end of this message, first my changes to your patch, the end result should be the same: $ interdiff /wb/thomas.patch /wb/acme.patch diff -u b/tools/perf/util/Build b/tools/perf/util/Build --- b/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -44,7 +44,6 @@ libperf-y += map.o libperf-y += pstack.o libperf-y += session.o -libperf-y += trace-event-sample-raw.o libperf-y += s390-sample-raw.o libperf-$(CONFIG_TRACE) += syscalltbl.o libperf-y += ordered-events.o diff -u b/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c --- b/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -150,8 +150,8 @@ * its raw data. * The function is only invoked when the dump flag -D is set. */ -void s390_sample_raw(struct perf_evlist *evlist, union perf_event *event, - struct perf_sample *sample) +void perf_evlist__s390_sample_raw(struct perf_evlist *evlist, union perf_event *event, + struct perf_sample *sample) { struct perf_evsel *ev_bc000; diff -u b/tools/perf/util/session.c b/tools/perf/util/session.c --- b/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1065,8 +1065,8 @@ file_offset, event->header.size, event->header.type); trace_event(event); - if (event->header.type == PERF_RECORD_SAMPLE) - trace_event_sample_raw(evlist, event, sample); + if (event->header.type == PERF_RECORD_SAMPLE && evlist->trace_event_sample_raw) + evlist->trace_event_sample_raw(evlist, event, sample); if (sample) perf_evlist__print_tstamp(evlist, event, sample); reverted: --- b/tools/perf/util/session.h +++ a/tools/perf/util/session.h @@ -128,9 +128,4 @@ struct perf_evlist *evlist, struct machine *machine); -void trace_event_sample_raw(struct perf_evlist *evlist __maybe_unused, - union perf_event *event __maybe_unused, - struct perf_sample *sample __maybe_unused); -void s390_sample_raw(struct perf_evlist *evlist, union perf_event *event, - struct perf_sample *sample); #endif /* __PERF_SESSION_H */ reverted: --- b/tools/perf/util/trace-event-sample-raw.c +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright IBM Corp. 2019 - * Author(s): 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) - * as published by the Free Software Foundation. - * - * Architecture specific trace_event function. Save event's bc000 raw data - * to file. File name is aux.ctr.## where ## stands for the CPU number the - * sample was taken from. - */ - -#include - -#include "session.h" -#include "evlist.h" - -/* Check platform the perf data file was created on and perform platform - * specific interpretation. - */ -void trace_event_sample_raw(struct perf_evlist *evlist, union perf_event *event, - struct perf_sample *sample) -{ - const char *arch_pf = perf_env__arch(evlist->env); - - if (arch_pf && !strcmp("s390", arch_pf)) - s390_sample_raw(evlist, event, sample); -} only in patch2: unchanged: --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -41,6 +41,18 @@ int sigqueue(pid_t pid, int sig, const union sigval value); #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define SID(e, x, y) xyarray__entry(e->sample_id, x, y) +/* + * Check platform the perf data file was created on and perform platform + * specific interpretation. + */ +static void perf_evlist__init_trace_event_sample_raw(struct perf_evlist *evlist) +{ + const char *arch_pf = perf_env__arch(evlist->env); + + if (arch_pf && !strcmp("s390", arch_pf)) + evlist->trace_event_sample_raw = perf_evlist__s390_sample_raw; +} + void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, struct thread_map *threads) { @@ -53,6 +65,7 @@ void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, fdarray__init(&evlist->pollfd, 64); evlist->workload.pid = -1; evlist->bkw_mmap_state = BKW_MMAP_NOTREADY; + perf_evlist__init_trace_event_sample_raw(evlist); } struct perf_evlist *perf_evlist__new(void) only in patch2: unchanged: --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -49,6 +49,9 @@ struct perf_evlist { struct perf_evsel *selected; struct events_stats stats; struct perf_env *env; + void (*trace_event_sample_raw)(struct perf_evlist *evlist, + union perf_event *event, + struct perf_sample *sample); u64 first_sample_time; u64 last_sample_time; }; @@ -315,4 +318,6 @@ void perf_evlist__force_leader(struct perf_evlist *evlist); struct perf_evsel *perf_evlist__reset_weak_group(struct perf_evlist *evlist, struct perf_evsel *evsel); +void perf_evlist__s390_sample_raw(struct perf_evlist *evlist, union perf_event *event, + struct perf_sample *sample); #endif /* __PERF_EVLIST_H */ only in patch2: unchanged: --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -25,6 +25,7 @@ util/parse-branch-options.c util/rblist.c util/counts.c util/print_binary.c +util/s390-sample-raw.c util/strlist.c util/trace-event.c ../lib/rbtree.c --------------------------------------- And the updated patch: $ cat /wb/acme.patch commit b7dd95b7479ed6773c6dbec72e0b867a1cfd3765 Author: Thomas Richter Date: Thu Jan 17 10:37:17 2019 -0300 erf report: Display arch specific diagnostic counter sets, starting with s390 On s390 the event bc000 (also named CF_DIAG) extracts the CPU Measurement Facility diagnostic counter sets and displays them as counter number and counter value pairs sorted by counter set number. Output: [root@s35lp76 perf]# ./perf report -D --stdio [00000000] Counterset:0 Counters:6 Counter:000 Value:0x000000000085ec36 Counter:001 Value:0x0000000000796c94 Counter:002 Value:0x0000000000005ada Counter:003 Value:0x0000000000092460 Counter:004 Value:0x0000000000006073 Counter:005 Value:0x00000000001a9a73 [0x000038] Counterset:1 Counters:2 Counter:000 Value:0x000000000007c59f Counter:001 Value:0x000000000002fad6 [0x000050] Counterset:2 Counters:16 Counter:000 Value:000000000000000000 Counter:001 Value:000000000000000000 Counter:002 Value:000000000000000000 Counter:003 Value:000000000000000000 Counter:004 Value:000000000000000000 Counter:005 Value:000000000000000000 Counter:006 Value:000000000000000000 Counter:007 Value:000000000000000000 Counter:008 Value:000000000000000000 Counter:009 Value:000000000000000000 Counter:010 Value:000000000000000000 Counter:011 Value:000000000000000000 Counter:012 Value:000000000000000000 Counter:013 Value:000000000000000000 Counter:014 Value:000000000000000000 Counter:015 Value:000000000000000000 [0x0000d8] Counterset:3 Counters:128 Counter:000 Value:0x000000000000020f Counter:001 Value:0x00000000000001d8 Counter:002 Value:0x000000000000d7fa Counter:003 Value:0x000000000000008b ... The number in brackets is the offset into the raw data field of the sample. New functions trace_event_sample_raw__init() and s390_sample_raw() are introduced in the code path to enable interpretation on non s390 platforms. This event bc000 attached raw data is generated only on s390 platform. Correct display on other platforms requires correct endianness handling. Committer notes: Added a init function that sets up a evlist function pointer to avoid repeated tests on evlist->env and calls to perf_env__name() that involves normalizing, etc, for each PERF_RECORD_SAMPLE. Removed needless __maybe_unused from the trace_event_raw() prototype in session.h, move it to be an static function in evlist. Reviewed-by: Hendrik Brueckner Cc: Martin Schwidefsky Cc: Heiko Carstens Signed-off-by: Thomas Richter Link: https://lkml.kernel.org/r/20190117093003.96287-2-tmricht@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo diff --git a/tools/perf/util/Build b/tools/perf/util/Build index af72be7f5b3b..5ff0087ba693 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -44,6 +44,7 @@ libperf-y += machine.o libperf-y += map.o libperf-y += pstack.o libperf-y += session.o +libperf-y += s390-sample-raw.o libperf-$(CONFIG_TRACE) += syscalltbl.o libperf-y += ordered-events.o libperf-y += namespaces.o diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 8c902276d4b4..5f01bced3116 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -41,6 +41,18 @@ int sigqueue(pid_t pid, int sig, const union sigval value); #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define SID(e, x, y) xyarray__entry(e->sample_id, x, y) +/* + * Check platform the perf data file was created on and perform platform + * specific interpretation. + */ +static void perf_evlist__init_trace_event_sample_raw(struct perf_evlist *evlist) +{ + const char *arch_pf = perf_env__arch(evlist->env); + + if (arch_pf && !strcmp("s390", arch_pf)) + evlist->trace_event_sample_raw = perf_evlist__s390_sample_raw; +} + void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, struct thread_map *threads) { @@ -53,6 +65,7 @@ void perf_evlist__init(struct perf_evlist *evlist, struct cpu_map *cpus, fdarray__init(&evlist->pollfd, 64); evlist->workload.pid = -1; evlist->bkw_mmap_state = BKW_MMAP_NOTREADY; + perf_evlist__init_trace_event_sample_raw(evlist); } struct perf_evlist *perf_evlist__new(void) diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 868294491194..18365b1f80b0 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -49,6 +49,9 @@ struct perf_evlist { struct perf_evsel *selected; struct events_stats stats; struct perf_env *env; + void (*trace_event_sample_raw)(struct perf_evlist *evlist, + union perf_event *event, + struct perf_sample *sample); u64 first_sample_time; u64 last_sample_time; }; @@ -315,4 +318,6 @@ void perf_evlist__force_leader(struct perf_evlist *evlist); struct perf_evsel *perf_evlist__reset_weak_group(struct perf_evlist *evlist, struct perf_evsel *evsel); +void perf_evlist__s390_sample_raw(struct perf_evlist *evlist, union perf_event *event, + struct perf_sample *sample); #endif /* __PERF_EVLIST_H */ diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 7aa0ea64544e..aada3e69565b 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -25,6 +25,7 @@ util/parse-branch-options.c util/rblist.c util/counts.c util/print_binary.c +util/s390-sample-raw.c util/strlist.c util/trace-event.c ../lib/rbtree.c diff --git a/tools/perf/util/s390-cpumcf-kernel.h b/tools/perf/util/s390-cpumcf-kernel.h new file mode 100644 index 000000000000..d4356030b504 --- /dev/null +++ b/tools/perf/util/s390-cpumcf-kernel.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Support for s390 CPU measurement counter set diagnostic facility + * + * Copyright IBM Corp. 2019 + Author(s): Hendrik Brueckner + * Thomas Richter + */ +#ifndef S390_CPUMCF_KERNEL_H +#define S390_CPUMCF_KERNEL_H + +#define S390_CPUMCF_DIAG_DEF 0xfeef /* Counter diagnostic entry ID */ +#define PERF_EVENT_CPUM_CF_DIAG 0xBC000 /* Event: Counter sets */ + +struct cf_ctrset_entry { /* CPU-M CF counter set entry (8 byte) */ + unsigned int def:16; /* 0-15 Data Entry Format */ + unsigned int set:16; /* 16-23 Counter set identifier */ + unsigned int ctr:16; /* 24-39 Number of stored counters */ + unsigned int res1:16; /* 40-63 Reserved */ +}; + +struct cf_trailer_entry { /* CPU-M CF trailer for raw traces (64 byte) */ + /* 0 - 7 */ + union { + struct { + unsigned int clock_base:1; /* TOD clock base */ + unsigned int speed:1; /* CPU speed */ + /* Measurement alerts */ + unsigned int mtda:1; /* Loss of MT ctr. data alert */ + unsigned int caca:1; /* Counter auth. change alert */ + unsigned int lcda:1; /* Loss of counter data alert */ + }; + unsigned long flags; /* 0-63 All indicators */ + }; + /* 8 - 15 */ + unsigned int cfvn:16; /* 64-79 Ctr First Version */ + unsigned int csvn:16; /* 80-95 Ctr Second Version */ + unsigned int cpu_speed:32; /* 96-127 CPU speed */ + /* 16 - 23 */ + unsigned long timestamp; /* 128-191 Timestamp (TOD) */ + /* 24 - 55 */ + union { + struct { + unsigned long progusage1; + unsigned long progusage2; + unsigned long progusage3; + unsigned long tod_base; + }; + unsigned long progusage[4]; + }; + /* 56 - 63 */ + unsigned int mach_type:16; /* Machine type */ + unsigned int res1:16; /* Reserved */ + unsigned int res2:32; /* Reserved */ +}; + +#define CPUMF_CTR_SET_BASIC 0 /* Basic Counter Set */ +#define CPUMF_CTR_SET_USER 1 /* Problem-State Counter Set */ +#define CPUMF_CTR_SET_CRYPTO 2 /* Crypto-Activity Counter Set */ +#define CPUMF_CTR_SET_EXT 3 /* Extended Counter Set */ +#define CPUMF_CTR_SET_MT_DIAG 4 /* MT-diagnostic Counter Set */ +#endif diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c new file mode 100644 index 000000000000..05871da374b6 --- /dev/null +++ b/tools/perf/util/s390-sample-raw.c @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright IBM Corp. 2019 + * Author(s): 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) + * as published by the Free Software Foundation. + * + * Architecture specific trace_event function. Save event's bc000 raw data + * to file. File name is aux.ctr.## where ## stands for the CPU number the + * sample was taken from. + */ + +#include +#include +#include +#include + +#include +#include + +#include "debug.h" +#include "util.h" +#include "auxtrace.h" +#include "session.h" +#include "evlist.h" +#include "config.h" +#include "color.h" +#include "s390-cpumcf-kernel.h" + +static size_t ctrset_size(struct cf_ctrset_entry *set) +{ + return sizeof(*set) + set->ctr * sizeof(u64); +} + +static bool ctrset_valid(struct cf_ctrset_entry *set) +{ + return set->def == S390_CPUMCF_DIAG_DEF; +} + +/* CPU Measurement Counter Facility raw data is a byte stream. It is 8 byte + * aligned and might have trailing padding bytes. + * Display the raw data on screen. + */ +static bool s390_cpumcfdg_testctr(struct perf_sample *sample) +{ + size_t len = sample->raw_size, offset = 0; + unsigned char *buf = sample->raw_data; + struct cf_trailer_entry *te; + struct cf_ctrset_entry *cep, ce; + + if (!len) + return false; + while (offset < len) { + cep = (struct cf_ctrset_entry *)(buf + offset); + ce.def = be16_to_cpu(cep->def); + ce.set = be16_to_cpu(cep->set); + ce.ctr = be16_to_cpu(cep->ctr); + ce.res1 = be16_to_cpu(cep->res1); + + if (!ctrset_valid(&ce) || offset + ctrset_size(&ce) > len) { + /* Raw data for counter sets are always multiple of 8 + * bytes. Prepending a 4 bytes size field to the + * raw data block in the sample causes the perf tool + * to append 4 padding bytes to make the raw data part + * of the sample a multiple of eight bytes again. + * + * If the last entry (trailer) is 4 bytes off the raw + * area data end, all is good. + */ + if (len - offset - sizeof(*te) == 4) + break; + pr_err("Invalid counter set entry at %#" PRIx64 "\n", + offset); + return false; + } + offset += ctrset_size(&ce); + } + return true; +} + +/* Dump event bc000 on screen, already tested on correctness. */ +static void s390_cpumcfdg_dumptrail(const char *color, size_t offset, + struct cf_trailer_entry *tep) +{ + struct cf_trailer_entry te; + + te.flags = be64_to_cpu(tep->flags); + te.cfvn = be16_to_cpu(tep->cfvn); + te.csvn = be16_to_cpu(tep->csvn); + te.cpu_speed = be32_to_cpu(tep->cpu_speed); + te.timestamp = be64_to_cpu(tep->timestamp); + te.progusage1 = be64_to_cpu(tep->progusage1); + te.progusage2 = be64_to_cpu(tep->progusage2); + te.progusage3 = be64_to_cpu(tep->progusage3); + te.tod_base = be64_to_cpu(tep->tod_base); + te.mach_type = be16_to_cpu(tep->mach_type); + te.res1 = be16_to_cpu(tep->res1); + te.res2 = be32_to_cpu(tep->res2); + + color_fprintf(stdout, color, " [%#08zx] Trailer:%c%c%c%c%c" + " Cfvn:%d Csvn:%d Speed:%d TOD:%#llx\n", + offset, te.clock_base ? 'T' : ' ', + te.speed ? 'S' : ' ', te.mtda ? 'M' : ' ', + te.caca ? 'C' : ' ', te.lcda ? 'L' : ' ', + te.cfvn, te.csvn, te.cpu_speed, te.timestamp); + color_fprintf(stdout, color, "\t\t1:%lx 2:%lx 3:%lx TOD-Base:%#llx" + " Type:%x\n\n", + te.progusage1, te.progusage2, te.progusage3, + te.tod_base, te.mach_type); +} + +static void s390_cpumcfdg_dump(struct perf_sample *sample) +{ + size_t i, len = sample->raw_size, offset = 0; + unsigned char *buf = sample->raw_data; + const char *color = PERF_COLOR_BLUE; + struct cf_ctrset_entry *cep, ce; + u64 *p; + + while (offset < len) { + cep = (struct cf_ctrset_entry *)(buf + offset); + + ce.def = be16_to_cpu(cep->def); + ce.set = be16_to_cpu(cep->set); + ce.ctr = be16_to_cpu(cep->ctr); + ce.res1 = be16_to_cpu(cep->res1); + + if (!ctrset_valid(&ce)) { /* Print trailer */ + s390_cpumcfdg_dumptrail(color, offset, + (struct cf_trailer_entry *)cep); + return; + } + + color_fprintf(stdout, color, " [%#08zx] Counterset:%d" + " Counters:%d\n", offset, ce.set, ce.ctr); + for (i = 0, p = (u64 *)(cep + 1); i < ce.ctr; i += 2, p += 2) + color_fprintf(stdout, color, + "\tCounter:%03d Value:%#018lx" + " Counter:%03d Value:%#018lx\n", + i, be64_to_cpu(*p), + i + 1, be64_to_cpu(*(p + 1))); + offset += ctrset_size(&ce); + } +} + +/* S390 specific trace event function. Check for PERF_RECORD_SAMPLE events + * and if the event was triggered by a counter set diagnostic event display + * its raw data. + * The function is only invoked when the dump flag -D is set. + */ +void perf_evlist__s390_sample_raw(struct perf_evlist *evlist, union perf_event *event, + struct perf_sample *sample) +{ + struct perf_evsel *ev_bc000; + + if (event->header.type != PERF_RECORD_SAMPLE) + return; + + ev_bc000 = perf_evlist__event2evsel(evlist, event); + if (ev_bc000 == NULL || + ev_bc000->attr.config != PERF_EVENT_CPUM_CF_DIAG) + return; + + /* Display raw data on screen */ + if (!s390_cpumcfdg_testctr(sample)) { + pr_err("Invalid counter set data encountered\n"); + return; + } + s390_cpumcfdg_dump(sample); +} diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index d6f41611f504..379a54702ba9 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1065,6 +1065,8 @@ static void dump_event(struct perf_evlist *evlist, union perf_event *event, file_offset, event->header.size, event->header.type); trace_event(event); + if (event->header.type == PERF_RECORD_SAMPLE && evlist->trace_event_sample_raw) + evlist->trace_event_sample_raw(evlist, event, sample); if (sample) perf_evlist__print_tstamp(evlist, event, sample);