Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7219011imu; Tue, 22 Jan 2019 02:20:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN5aUY+Jn09qsNQlP3HQ0F9kZSb/Z3rmR783y6efRdKlfT2wIzZS9K4Cqs2JFZmN08HmsmlQ X-Received: by 2002:a63:ce50:: with SMTP id r16mr31015536pgi.217.1548152425215; Tue, 22 Jan 2019 02:20:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548152425; cv=none; d=google.com; s=arc-20160816; b=Bca6Jr4ConVmsRU75hWQLib9eNKP2qpjz+9ddIxA4K9e2AsY9u1ep7IkrMU6O2MCHh JsgSRWmt/VREVc48Tjk52Dmwz4bj+iDZ65qC+YmAB62ROWZMqnROljKwPGO8yQztL1rT kV0yBrydh4yndwtcBEiR+9jl+M6Av4TtV/pYUwY55fPxQ6YxlOrG/CiKsIwtgW0j6jE3 XhdjIo054fyR6Uy6ixV15Pw77dXn/erggJwwoEb5zaOBaXADyRIkuCWy24CC4IzhYsLl Lvz6Iqd4AWSGoDwH61S8y4PiBRgHWvYLXK4DU5rRNdCAIrxGa6I+J44134osx0oosWHw nZ2A== 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; bh=XRATZ2R8G/QzdK2nhSsDDsbGDwSzGMUI68xa8FYvPKI=; b=PCWpB5nT7XLW2GspItX7K08QVej3YZKg7m6uVBFJsZUBQRy/LYMN7nUUCp1qwF6oTJ Bnm5AW993p5GYKTyda5/3Fx3B+OO9Lmn/y8kCU/brcijIQn8mY+A6LrWtnaCb0XcPmOb zxJznrBP2JrUfuJ0DrJbU+UWhy9jNIf3ZoTrl5bQEwcmKZrLVmu3ShQzVJs9KbkVjNvq cvpz9gzJv/4l7+cOjeukRZgAWO9e5toMmtWOBZa+H2cUBACBxfZcklTt9mERa64j4J+B pK8XzCazACtTKJX5h2eCo94hcNfdz3dp3RwTjkz41Q8trhrfsEHzcX/EHY97SNscUD1v Fm7w== 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 u34si13850702pgk.24.2019.01.22.02.20.09; Tue, 22 Jan 2019 02:20:25 -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 S1728091AbfAVKSN (ORCPT + 99 others); Tue, 22 Jan 2019 05:18:13 -0500 Received: from terminus.zytor.com ([198.137.202.136]:54635 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727544AbfAVKSM (ORCPT ); Tue, 22 Jan 2019 05:18:12 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x0MAGxQj2906997 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 22 Jan 2019 02:16:59 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x0MAGxEg2906994; Tue, 22 Jan 2019 02:16:59 -0800 Date: Tue, 22 Jan 2019 02:16:59 -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: acme@redhat.com, tglx@linutronix.de, hpa@zytor.com, tmricht@linux.ibm.com, linux-kernel@vger.kernel.org, schwidefsky@de.ibm.com, brueckner@linux.ibm.com, heiko.carstens@de.ibm.com, mingo@kernel.org Reply-To: heiko.carstens@de.ibm.com, brueckner@linux.ibm.com, mingo@kernel.org, acme@redhat.com, tglx@linutronix.de, hpa@zytor.com, linux-kernel@vger.kernel.org, tmricht@linux.ibm.com, schwidefsky@de.ibm.com In-Reply-To: <20190117093003.96287-4-tmricht@linux.ibm.com> References: <20190117093003.96287-4-tmricht@linux.ibm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf report: Dump s390 counter set data to file Git-Commit-ID: 8dabe9c43af7aa78b16ce0d61bc595eca20c7a70 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, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: 8dabe9c43af7aa78b16ce0d61bc595eca20c7a70 Gitweb: https://git.kernel.org/tip/8dabe9c43af7aa78b16ce0d61bc595eca20c7a70 Author: Thomas Richter AuthorDate: Thu, 17 Jan 2019 10:30:03 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 21 Jan 2019 17:00:57 -0300 perf report: Dump s390 counter set data to file Add support for the new s390 PMU device cpum_cf_diag to extract the counter set diagnostic data. This data is available as event raw data and can be created with this command: [root@s35lp76 perf]# ./perf record -R -e '{rbd000,rbc000}' -- ~/mytests/facultaet 2500 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.009 MB perf.data ] [root@s35lp76 perf]# The new event 0xbc000 generated this counter set diagnostic trace data. The data can be extracted using command: [root@s35lp76 perf]# ./perf report --stdio --itrace=d # # Total Lost Samples: 0 # # Samples: 21 of events 'anon group { rbd000, rbc000 }' # Event count (approx.): 21 # # Overhead Command Shared Object Symbol # ................ ......... ................. ........................ # 80.95% 0.00% facultaet facultaet [.] facultaet 4.76% 0.00% facultaet [kernel.kallsyms] [k] check_chain_key 4.76% 0.00% facultaet [kernel.kallsyms] [k] ftrace_likely_update 4.76% 0.00% facultaet [kernel.kallsyms] [k] lock_release 4.76% 0.00% facultaet libc-2.26.so [.] _dl_addr [root@s35lp76 perf]# ll aux* -rw-r--r-- 1 root root 3408 Oct 16 12:40 aux.ctr.02 -rw-r--r-- 1 root root 4096 Oct 16 12:40 aux.smp.02 [root@s35lp76 perf]# The files named aux.ctr.## contain the counter set diagnostic data and the files named aux.smp.## contain the sampling diagnostic data. ## stand for the CPU number the data was taken from. Signed-off-by: Thomas Richter Reviewed-by: Hendrik Brueckner Cc: Heiko Carstens Cc: Martin Schwidefsky Link: http://lkml.kernel.org/r/20190117093003.96287-4-tmricht@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/s390-cpumsf.c | 77 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c index 68b2570304ec..835249c77f56 100644 --- a/tools/perf/util/s390-cpumsf.c +++ b/tools/perf/util/s390-cpumsf.c @@ -162,6 +162,7 @@ #include "auxtrace.h" #include "s390-cpumsf.h" #include "s390-cpumsf-kernel.h" +#include "s390-cpumcf-kernel.h" #include "config.h" struct s390_cpumsf { @@ -184,8 +185,58 @@ struct s390_cpumsf_queue { struct auxtrace_buffer *buffer; int cpu; FILE *logfile; + FILE *logfile_ctr; }; +/* Check if the raw data should be dumped to file. If this is the case and + * the file to dump to has not been opened for writing, do so. + * + * Return 0 on success and greater zero on error so processing continues. + */ +static int s390_cpumcf_dumpctr(struct s390_cpumsf *sf, + struct perf_sample *sample) +{ + struct s390_cpumsf_queue *sfq; + struct auxtrace_queue *q; + int rc = 0; + + if (!sf->use_logfile || sf->queues.nr_queues <= sample->cpu) + return rc; + + q = &sf->queues.queue_array[sample->cpu]; + sfq = q->priv; + if (!sfq) /* Queue not yet allocated */ + return rc; + + if (!sfq->logfile_ctr) { + char *name; + + rc = (sf->logdir) + ? asprintf(&name, "%s/aux.ctr.%02x", + sf->logdir, sample->cpu) + : asprintf(&name, "aux.ctr.%02x", sample->cpu); + if (rc > 0) + sfq->logfile_ctr = fopen(name, "w"); + if (sfq->logfile_ctr == NULL) { + pr_err("Failed to open counter set log file %s, " + "continue...\n", name); + rc = 1; + } + free(name); + } + + if (sfq->logfile_ctr) { + /* See comment above for -4 */ + size_t n = fwrite(sample->raw_data, sample->raw_size - 4, 1, + sfq->logfile_ctr); + if (n != 1) { + pr_err("Failed to write counter set data\n"); + rc = 1; + } + } + return rc; +} + /* Display s390 CPU measurement facility basic-sampling data entry */ static bool s390_cpumsf_basic_show(const char *color, size_t pos, struct hws_basic_entry *basic) @@ -792,7 +843,7 @@ static int s390_cpumsf_lost(struct s390_cpumsf *sf, struct perf_sample *sample) } static int -s390_cpumsf_process_event(struct perf_session *session __maybe_unused, +s390_cpumsf_process_event(struct perf_session *session, union perf_event *event, struct perf_sample *sample, struct perf_tool *tool) @@ -801,6 +852,8 @@ s390_cpumsf_process_event(struct perf_session *session __maybe_unused, struct s390_cpumsf, auxtrace); u64 timestamp = sample->time; + struct perf_evsel *ev_bc000; + int err = 0; if (dump_trace) @@ -811,6 +864,16 @@ s390_cpumsf_process_event(struct perf_session *session __maybe_unused, return -EINVAL; } + if (event->header.type == PERF_RECORD_SAMPLE && + sample->raw_size) { + /* Handle event with raw data */ + ev_bc000 = perf_evlist__event2evsel(session->evlist, event); + if (ev_bc000 && + ev_bc000->attr.config == PERF_EVENT_CPUM_CF_DIAG) + err = s390_cpumcf_dumpctr(sf, sample); + return err; + } + if (event->header.type == PERF_RECORD_AUX && event->aux.flags & PERF_AUX_FLAG_TRUNCATED) return s390_cpumsf_lost(sf, sample); @@ -891,9 +954,15 @@ static void s390_cpumsf_free_queues(struct perf_session *session) struct s390_cpumsf_queue *sfq = (struct s390_cpumsf_queue *) queues->queue_array[i].priv; - if (sfq != NULL && sfq->logfile) { - fclose(sfq->logfile); - sfq->logfile = NULL; + if (sfq != NULL) { + if (sfq->logfile) { + fclose(sfq->logfile); + sfq->logfile = NULL; + } + if (sfq->logfile_ctr) { + fclose(sfq->logfile_ctr); + sfq->logfile_ctr = NULL; + } } zfree(&queues->queue_array[i].priv); }