Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3870554pxb; Tue, 10 Nov 2020 02:06:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwggp8aP9DNIO2FtEKxRbnnhyeTxGLbKc3GjYYHUO4hweNOl3MOszoVi3hPbvw+U4JmXvIa X-Received: by 2002:a17:906:d41:: with SMTP id r1mr18974727ejh.383.1605002803282; Tue, 10 Nov 2020 02:06:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605002803; cv=none; d=google.com; s=arc-20160816; b=XVUXOLk9IcxQ/1KVb45GsPxJcq0UCWwBV6GwjLLzZtUdMChVm66jfMID6KicF68Dxd YdwfxrGDAMi5w7DdMUhkxFzjeZOpNSforjxux+8B3JtNb/OxdsYXSlgTvbZ3VWEmZkdG w4cJKpn+I7N4ueZOvbelzYN9hERWJhn8oVPzggdzNPk1kEm4KuYj3vQeW1SB2ZBv6Qcp e3+jQXptP7hdc9NVCXVzolYgGvRHJyKN0rbAHe+05zyN601NjIFRBEjw6/d+WPH6q+nL v0fDnm9elwMnfoM2CtDiqUX4+WHle8LJCA8hfTGEM1ozPllucwxGzW0NPjq99BGh1f4f FoXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=nrzFexJvGrTq0QIzrzo0g61dQEjFkiepI4OPSOH1Szg=; b=hP71Ui6UDTXERNhHbvQYsq5kj77o14A4PlpRH7vhK1flhdMvzY9msdQdxdntGKP955 73AyPZxJjrl6GOSo0sZV7ZbrlKeJYD7LRFIYwLt8x5o2n6iJTFgSjzEVegoL5Q7w2y7g SBsgpX+JD9BeWsUgtlBtTI1KB2qXJVkJXAtm7dXrwN/hzSowUmjcXv58nXCrQadZpu9W 0R3iPAQ2NVmodgnU7D6HfuA0ME1mLqrYxhymamCWesBQmBdAc/qV1+DjwK9K1cY2GhIc EoQ9raD8w3Ti/iMxSog6FU/X97DJhOzMCDjKgzqrO1hKdLrajq10AXPYb0+z1ykkpFDJ uf3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WWy2hxeq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si9323675edv.293.2020.11.10.02.06.20; Tue, 10 Nov 2020 02:06:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WWy2hxeq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732006AbgKJKEf (ORCPT + 99 others); Tue, 10 Nov 2020 05:04:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731878AbgKJKEV (ORCPT ); Tue, 10 Nov 2020 05:04:21 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2199DC0613D1 for ; Tue, 10 Nov 2020 02:04:20 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id f9so8275335qkg.13 for ; Tue, 10 Nov 2020 02:04:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=nrzFexJvGrTq0QIzrzo0g61dQEjFkiepI4OPSOH1Szg=; b=WWy2hxeqmTRKWfkhRGKk8yvm002V6UDoKI/7Gpec21YMQcMxLCkbtZiVJkYV9lEx3Z NfZAi5QpKOidF4FUILEV3V14CA4Cgx3YvwVsvA8cgvEvEjAStf49y/2J19+e0x+nrCBI 094vQHO289WHFKJb46Orw3bHNl2iIRRJd6oxGqw5FAvyrjW7kP5SAVJL7Cv6A2huQGWa 5vUznMV96uDjPxe2EjBIJJUFoKA8wnHAfMTezC4Ikc3sCw7EKmnIAsmZDU4Cc8/l9Ybp s9v/0Fh3XQ9bb/2j3P7572FiSIpbq1vxezMWRcs3j5+qdnZZpfXsSOGBiquqjUbuB4NW ufgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=nrzFexJvGrTq0QIzrzo0g61dQEjFkiepI4OPSOH1Szg=; b=Lxm8S1cXLASbQUusJRX+VNBGwM6NTkTT3zuuvjB8xNqMQ32NF/asATBKQwxOfu3q9t G/U+xH2GRo9R0II53vX/echh6FvdTdNOR1aMpl/C/X3BmrSnpDtb5nnYbV43bWdfDE6V XdwzkS0iyB6QLi1YeZzMQGGBviY4s9L3DxUTtftmAz1Pub/6CBzIzDaNWMsrhoLqUCiO 70ferRh5ToAN/+dOqB2ASjTFW7SE5+A5Zj6fxkkjZc7Uvs4lELG6TGZsPnUkGO0FN7jg 6mJNFusqz8cXDMpqPlrRKMNx8yA8OBqNVZY55i7o/+Bp7dfFvW6U8tiiby2SONzhTEK6 Wgsg== X-Gm-Message-State: AOAM530Po1N2I/Z5bvg1l48FTcxlXGZDHn5QEXWYG7hVmmJIl7awuopf LaCPRlg3Z5GFjkzDmg6hv4foOHovgNug Sender: "irogers via sendgmr" X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:2:f693:9fff:fef4:4583]) (user=irogers job=sendgmr) by 2002:a0c:9e65:: with SMTP id z37mr18791387qve.39.1605002659243; Tue, 10 Nov 2020 02:04:19 -0800 (PST) Date: Tue, 10 Nov 2020 02:03:45 -0800 In-Reply-To: <20201110100346.2527031-1-irogers@google.com> Message-Id: <20201110100346.2527031-12-irogers@google.com> Mime-Version: 1.0 References: <20201110100346.2527031-1-irogers@google.com> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [RFC PATCH 11/12] perf topdown-parser: Main driver. From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org, Andi Kleen , Jin Yao , John Garry , Paul Clarke , kajoljain Cc: Stephane Eranian , Sandeep Dasgupta , linux-perf-users@vger.kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sandeep Dasgupta Invoke the necessary configuration reading and parsing, then code generation. Handles command line arguments. Add a minor README. Co-authored-by: Stephane Eranian Co-authored-by: Ian Rogers Signed-off-by: Ian Rogers Signed-off-by: Sandeep Dasgupta --- tools/perf/pmu-events/topdown-parser/README | 5 + .../topdown-parser/topdown_parser_main.cpp | 155 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tools/perf/pmu-events/topdown-parser/README create mode 100644 tools/perf/pmu-events/topdown-parser/topdown_parser_main.cpp diff --git a/tools/perf/pmu-events/topdown-parser/README b/tools/perf/pmu-events/topdown-parser/README new file mode 100644 index 000000000000..7f100792b00c --- /dev/null +++ b/tools/perf/pmu-events/topdown-parser/README @@ -0,0 +1,5 @@ +Topdown parser and code generator +================================= + +The topdown parser processes a TMA_Metrics.csv file and generates +Intel specific metrics from the data in the spreadsheet cells. \ No newline at end of file diff --git a/tools/perf/pmu-events/topdown-parser/topdown_parser_main.cpp b/tools/perf/pmu-events/topdown-parser/topdown_parser_main.cpp new file mode 100644 index 000000000000..ba9acd32726e --- /dev/null +++ b/tools/perf/pmu-events/topdown-parser/topdown_parser_main.cpp @@ -0,0 +1,155 @@ +/* + * Copyright 2020 Google LLC. + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include + +#include +#include +#include +#include + +#include "code_gen_target.h" +#include "configuration.h" +#include "csvreader.h" +#include "dependence_dag_utils.h" +#include "event_info.h" +#include "logging.h" + +namespace topdown_parser +{ +namespace +{ +/** + * Printing usage model + */ +[[noreturn]] void ShowUsage() +{ + std::cout + << "\n" + " Usage: topdown_parser --csv-file \n" + " --events-data-dir \n" + " --config-file \n" + " --output-path \n" + " [Options]\n" + " Synopsis: Auto-generates topdown.c \n\n" + " Options\n" + "\t--dump-events : Dump the unique events for each metric.\n" + "generated topdown file. Used for testing.\n" + "\t--help : Show help\n"; + exit(0); +} + +/** + * The input csv file name specifying formula encoding for topdown + * metric + */ +char *g_CsvFile = nullptr; + +/** + * ProcessArgs parses command-line arguments + */ +bool ProcessArgs(int argc, char **argv) +{ + // The following command-line arguments to the program + // todown_parser are required: --csv-file , + // --events-data-dir , --config-file --output-path + // + if (argc < 9) { + ShowUsage(); + return false; + } + + const char *const short_opts = "f:a:z:hdt"; + const option long_opts[] = { + { "csv-file", required_argument, nullptr, 'f' }, + { "events-data-dir", required_argument, nullptr, 'a' }, + { "config-file", required_argument, nullptr, 'z' }, + { "output-path", required_argument, nullptr, 'o' }, + { "dump-events", no_argument, nullptr, 'd' }, + { "help", no_argument, nullptr, 'h' }, + { nullptr, no_argument, nullptr, 0 } + }; + + while (true) { + const auto opt = + getopt_long(argc, argv, short_opts, long_opts, nullptr); + + if (opt == -1) + break; + + switch (opt) { + case 'f': + g_CsvFile = optarg; + break; + + case 'a': + kConfigParams->event_data_dir_ = optarg; + kConfigParams->event_data_dir_ += "/"; + break; + + case 'z': + kConfigParams->config_file_ = optarg; + break; + + case 'o': + kConfigParams->output_path_ = optarg; + break; + + case 'd': + g_DumpEvents = true; + break; + + case 'h': + case '?': + default: + ShowUsage(); + return false; + } + } + + INFO("csv filename: |" << g_CsvFile << "|"); + INFO("events data dir: |" << kConfigParams->event_data_dir_ << "|"); + INFO("config file : |" << kConfigParams->config_file_ << "|"); + return true; +} + +} // namespace + +} // namespace topdown_parser + +/** + * Main driver function for generating topdown files. + */ +int main(int argc, char *argv[]) +{ + bool process_arg_stat = topdown_parser::ProcessArgs(argc, argv); + if (!process_arg_stat) { + FATAL("Failed to process the command-line arguments"); + } + + // Read the configuration file "configuration.json" + int read_config_stat = topdown_parser::ReadConfig(); + if (read_config_stat != 0) { + FATAL("Failed to read configuration file"); + } + + // Read the input csv file + topdown_parser::CsvReader reader(topdown_parser::g_CsvFile); + std::vector > records = reader.getData(); + std::unordered_map + dependence_dag = topdown_parser::ProcessRecords(&records); + + // Read and process the json files specifying the event encodings + topdown_parser::ProcessEventEncodings(); + + // Generate topdown files for a specific target (or purpose) + topdown_parser::CodeGenTarget(dependence_dag); + + return 0; +} -- 2.29.2.222.g5d2a92d10f8-goog