Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3871022pxb; Tue, 10 Nov 2020 02:07:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxP2EYvASY0TTXsiwljMiOMCA6w0XameWqm+XwFCEOK0XextWBOQ42qp4MLIMiyfk28+R+A X-Received: by 2002:a17:906:6949:: with SMTP id c9mr19301381ejs.482.1605002848051; Tue, 10 Nov 2020 02:07:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605002848; cv=none; d=google.com; s=arc-20160816; b=0Co99YF7zjS5NI8vod+6szMdtjgMwSJOSZo2PvjbbnW09Hyz8YMfGCRV276A2+INos RhNTD3JoUAAFxgPy2hQyKo0jXcLmH7AbdmJPQM9Jag9jqZls21i0R0lV8ZVUmKCvNNfm nupZajEWR8x2NqbK0mrFe4F9rDwwy5eZ/QlOWVIPRe7ct6x2jtYclbUMyuuziczXlqyc 04iXr0y5Q4F3MV7xYdB7SuUNbYFnC+H3oXOXiz7oIfUBYtlm8AQ7WHAoPEyB0bFje02C QbsrlBYwLv444RT7av9AaG8f9VAiygHeQNKuZ6QBhOj3FChwx1djcpHNkj93UtikKPQw ffZA== 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=Sh/0QbfpyBISYZm1ueGZyhZ7Zpfk7dKLcbQRbbsbtMo=; b=hhICrvFdoEY3mPArOq7n3C4t7uwaPfv9K3WKLc2RkUoHDybvqYXKvnst+HPLLppIQ2 xJ16Fva5E2JObx5yBDsI7hX/l+d/1h3gtMAWCsl8glQ8OgPlqJ5n0vHU0+KKFqfB3GUv GR3RlSoA0yUom5WsZ8kX3x1eBwDg//T83TXHVi1wejgwNIW5SmQfiwGfGyKwdbvlw7Gu 7eyhTMJj2KjuGDkipI4JU397Prk2b3cJF6VFh3NkbVss65zeW9siZ/BrWjZ1jbqGOr1J /Wgh1IKGYrdlcFWc7y56Wv+m7FHBGSaUqKnmBmtRj2/20/JhDZloJsV8sSuLtsCa6kbw yEzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pJ4R94Wz; 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 di3si8566703edb.554.2020.11.10.02.07.04; Tue, 10 Nov 2020 02:07:28 -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=pJ4R94Wz; 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 S1731976AbgKJKEr (ORCPT + 99 others); Tue, 10 Nov 2020 05:04:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731729AbgKJKER (ORCPT ); Tue, 10 Nov 2020 05:04:17 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3A9DC0613D1 for ; Tue, 10 Nov 2020 02:04:15 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id k10so6748334pfh.17 for ; Tue, 10 Nov 2020 02:04:15 -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=Sh/0QbfpyBISYZm1ueGZyhZ7Zpfk7dKLcbQRbbsbtMo=; b=pJ4R94Wzv239XG323FxsHetBCnjilNMjZsyiA+0jlwno+xwvsQ/f4mdxhy4MJHARwC Z5tVO2m0q4Lv4EFIYRIB+FeMmlBp40cbaoygXQCoWDWd3U0IW8x5fj/CxOVKokr7uJ42 SboaO9uTMUtEgMgyvYLv/FN6gnj4RycriVjcXsI9SUljb3lwZsJLStZyLdqtq0Nj5or7 DDUeyVZ94sdOet/YnV1CkB5/WTds/MZKEWYNeiy0JdBKZuHN0kWcWAm6bVBsn3oGZpkd DmBk6T8+ZKpjZQXskdZY2IcHKEMhkeXNIQpwdNybPygLrTxQUuaJaImGe7Ggr0/WgH2n 1kXA== 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=Sh/0QbfpyBISYZm1ueGZyhZ7Zpfk7dKLcbQRbbsbtMo=; b=LDQTov1YCSMMwi3sxFDgrvGEErBdqDycEHsvNRlnQjshTZliHdBUf0inbBsfSVKgmi aVIqo5wXPWeY8HJ7kLGXYzdTRH1Fe79DDoCih51Z2hX7R0PE6NVADZhXPCInoi+HkGct JkLewKIZdk8kH/seHy+AdKyhVKNtNMahvGjDxSSISwqwVKB3X8BsRVShWKj+NKDPQQMx hMUVl6/B2lRpRxwZGAPoJidWHaKXjh2gc4+WbBznw1K8rL9Y9C9FV1vbekoC5Fco6yPN tK+Dtg0BNgfzQTYz4j+YeAbdBwydT4Uwr4Gn00p+gFGMAwQxdffYP6Vhv6i82lUrAJTS szoQ== X-Gm-Message-State: AOAM531OptDV71LffbRrwImj16mqdQOewsiupEU1c+xKxMlE/8xTPf+P eONNjmFqUGvO4f3mHqxbYjCyCxn0pMTK 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:a17:90a:db96:: with SMTP id h22mr4244472pjv.57.1605002655221; Tue, 10 Nov 2020 02:04:15 -0800 (PST) Date: Tue, 10 Nov 2020 02:03:43 -0800 In-Reply-To: <20201110100346.2527031-1-irogers@google.com> Message-Id: <20201110100346.2527031-10-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 09/12] perf topdown-paser: Add code generation API. 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 Add API that is called to generate code using all registered targets. Co-authored-by: Stephane Eranian Signed-off-by: Ian Rogers Signed-off-by: Sandeep Dasgupta --- .../topdown-parser/code_gen_target.cpp | 51 ++++++++++++ .../topdown-parser/code_gen_target.h | 77 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 tools/perf/pmu-events/topdown-parser/code_gen_target.cpp create mode 100644 tools/perf/pmu-events/topdown-parser/code_gen_target.h diff --git a/tools/perf/pmu-events/topdown-parser/code_gen_target.cpp b/tools/perf/pmu-events/topdown-parser/code_gen_target.cpp new file mode 100644 index 000000000000..c6d7ce8eb661 --- /dev/null +++ b/tools/perf/pmu-events/topdown-parser/code_gen_target.cpp @@ -0,0 +1,51 @@ +/* + * Copyright 2020 Google LLC. + * SPDX-License-Identifier: GPL-2.0 + */ + +#include "code_gen_target.h" + +#include "configuration.h" + +namespace topdown_parser +{ +/** + * Dump event list. Used for testing of auto-generation. + */ +bool g_DumpEvents = false; + +namespace +{ +/** + * `kRegisteredTargets` enumerates all the target supported by the + * topdown generator tool. Each target is responsible for generating a + * "code", which essentially encodes the topdown metric expressions, in + * a particular language or format support. + */ +TargetInfo *kRegisteredTargets[] = { + &kTargetPerfJson /* target to generate JSon code */, +}; + +} // namespace + +void CodeGenTarget( + const std::unordered_map &dependence_dag) +{ + for (size_t i = 0; + i < sizeof(kRegisteredTargets) / sizeof(TargetInfo *); ++i) { + const std::string &target_name = kRegisteredTargets[i]->name; + + if (target_name == kConfigParams->target_) { + kRegisteredTargets[i]->codegen_entry_point( + dependence_dag); + if (kRegisteredTargets[i] + ->codegen_test_harness_entry_point) { + kRegisteredTargets[i] + ->codegen_test_harness_entry_point(); + } + break; + } + } +} + +} // namespace topdown_parser diff --git a/tools/perf/pmu-events/topdown-parser/code_gen_target.h b/tools/perf/pmu-events/topdown-parser/code_gen_target.h new file mode 100644 index 000000000000..ab3e2b48bebc --- /dev/null +++ b/tools/perf/pmu-events/topdown-parser/code_gen_target.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +// -------------------------------------------------- +// File: code_gen_target.h +// -------------------------------------------------- +// + +// The header provides the interface `CodeGenTarget` to generate code, encoding +// the topdown metric expressions, using the data `dependence_dag` read from +// the input csv file. The language or format of the generated code is the one +// supported by a specific project (e.g. perf or projects using perf ) to encode +// the topdown metric metric expressions. We define a `target` as a specific +// project and use that to guide generation of topdown code in a language +// supported by the project. + +#ifndef TOPDOWN_PARSER_CODE_GEN_TARGET_H_ +#define TOPDOWN_PARSER_CODE_GEN_TARGET_H_ + +#include +#include + +namespace topdown_parser +{ +class MappedData; + +/** + * Dump event list. Used for testing of auto-generation. + */ +extern bool g_DumpEvents; + +/** + * The structure `TargetInfo` is used to specify a target. + */ +struct TargetInfo { + /** + * Name of the target. This will be used to invoke code generation for a + * particular target. + */ + std::string name; + + /** + * Descriptive information of the target (Optional). + */ + std::string description; + + /** + * The entry point function for generating code. + */ + void (*codegen_entry_point)( + const std::unordered_map + &dependence_dag); + + /** + * Function to generate golden reference for testing the auto-generated + * code. + * (Optional) + */ + void (*codegen_test_harness_entry_point)(); +}; + +/** + * Target information for generating JSon code for perf encoding the topdown + * metric expressions. + */ +extern TargetInfo kTargetPerfJson; + +/** + * `CodeGenTarget` dispatches an appropriate callback, based on the + * configuration variable `kConfigParams->target_`, to generate "code" for a + * particular target. + */ +void CodeGenTarget( + const std::unordered_map &dependence_dag); + +} // namespace topdown_parser + +#endif // TOPDOWN_PARSER_CODE_GEN_TARGET_H_ -- 2.29.2.222.g5d2a92d10f8-goog