From patchwork Thu Jan 18 14:01:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 124967 Delivered-To: patch@linaro.org Received: by 10.46.64.27 with SMTP id n27csp140675lja; Thu, 18 Jan 2018 06:07:40 -0800 (PST) X-Google-Smtp-Source: ACJfBos/F+/ZXQR1AJ3p6qX+fsbt3XMXhS8ZW2H2MVcys34jS4kW/vXFZMQrv+kM4JMMk/AvL6R3 X-Received: by 10.55.12.4 with SMTP id 4mr44867095qkm.158.1516284460711; Thu, 18 Jan 2018 06:07:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516284460; cv=none; d=google.com; s=arc-20160816; b=EgUMW7hfE6Xwjsz4xRT6MiwvzdKqGJnZpeqTaNJ7B9P8RhVtmOzulQophud1q7/ig7 vHNPdqaaPwFICilebZn7MNK0nnNI/bGWaIfRw6hL7eM7VVLY2gU7Eme6Yg7Xz2faDkTt 7mRKyGTLid5lRxFBPhTGm17MWKemO4RorXRy5mGOrtf+agQqbnNzKPJU5B0r7EhMtEez 0Nu+9yasMsWkzBwFcjApmByUMIHHlC+GMxsCieXlfFNG3+juHJcFxmEigOtq+oqrF3VJ XPWh6YFLl1ZNfDzc0ndBnVNoVvH00sLJaLCidiOsPmpXMwaVV6iW3cLabGDfOXssLprf R2rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=W9VL/pGMe0aDfj/UrZGGhLbbyNx76NC9Q6W3mF9iD5k=; b=KLG3twfukkMY8brNik5dKAwrNJqXnuVNij0eDFgUweeo4snapamnyDwS0cKzilUaVz Xr/SAr/UoBYaQm0sR6zms9N+SlBjgmWO/f54Z6io3IUg+AHa6ncbjoJ/DaiRIBB9n+5N IsuBTciv4IM4LmD9YVc8M8AO9hvO8Na8mfinuBkVlMN5iLsjcbCf01jtPEZmVGiQIESE av360Ukrj6xw56N5dK9S0yMB2kJ80LcsL7xzEqHBi2Ckf7BAXoS5WpaFoemzVBQpBU95 wxFl2BgDj8xC2IFRdcDFzT+Ujf91SDYiK88tOuJi+p8bmfGVv7Sbfyde8QX3QjfHPX8t HKIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id k53si888907qtc.244.2018.01.18.06.07.40; Thu, 18 Jan 2018 06:07:40 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 55EB462787; Thu, 18 Jan 2018 14:07:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id E01F162807; Thu, 18 Jan 2018 14:03:26 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 5E63E627F1; Thu, 18 Jan 2018 14:03:10 +0000 (UTC) Received: from forward103j.mail.yandex.net (forward103j.mail.yandex.net [5.45.198.246]) by lists.linaro.org (Postfix) with ESMTPS id 1535962800 for ; Thu, 18 Jan 2018 14:01:22 +0000 (UTC) Received: from mxback10o.mail.yandex.net (mxback10o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::24]) by forward103j.mail.yandex.net (Yandex) with ESMTP id 04CED34C531E for ; Thu, 18 Jan 2018 17:01:21 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback10o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 6NX7SSei2n-1KjS1njQ; Thu, 18 Jan 2018 17:01:20 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id sNY3tHYRi1-1Khq0bsL; Thu, 18 Jan 2018 17:01:20 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 18 Jan 2018 17:01:15 +0300 Message-Id: <1516284076-2857-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516284076-2857-1-git-send-email-odpbot@yandex.ru> References: <1516284076-2857-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 381 Subject: [lng-odp] [PATCH CATERPILLAR v4 4/5] example: instrum: configure papi event set X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Bogdan Pricope Configure the set of papi counters to be acquired via an environment variable. Signed-off-by: Bogdan Pricope --- /** Email created from pull request 381 (bogdanPricope:cat_benchmark_poc) ** https://github.com/Linaro/odp/pull/381 ** Patch: https://github.com/Linaro/odp/pull/381.patch ** Base sha: 4d17f8ae64aba0e6f24877be30f86ae5880cef7e ** Merge commit sha: c651bdf2f6e197eb49c2aecff6f64a247db2b982 **/ example/instrum/papi_cnt.c | 44 +++++++++++++++++++++++++++++++++++++++----- example/instrum/papi_cnt.h | 2 ++ example/instrum/sample.h | 2 +- example/instrum/store.c | 4 +++- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/example/instrum/papi_cnt.c b/example/instrum/papi_cnt.c index c38c856a0..da8267834 100644 --- a/example/instrum/papi_cnt.c +++ b/example/instrum/papi_cnt.c @@ -6,17 +6,25 @@ #include #include +#include #include #include #include -static int papi_event_tab[SAMPLE_COUNTER_TAB_SIZE] = {PAPI_BR_CN, PAPI_L2_DCM}; +#define PAPI_EVENTS_ENV "ODP_INSTRUM_PAPI_EVENTS" + +#define PAPI_EVENT_TAB_SIZE_DFLT 2 +int papi_event_tab_dflt[PAPI_EVENT_TAB_SIZE_DFLT] = {PAPI_BR_CN, PAPI_L2_DCM}; + +static int papi_event_tab[SAMPLE_COUNTER_TAB_SIZE]; +static int papi_event_tab_size; static __thread int event_set = PAPI_NULL; int papi_init(void) { int retval, i; + char *papi_events_env = NULL; retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { @@ -35,7 +43,28 @@ int papi_init(void) goto err_shutdown; } - for (i = 0; i < SAMPLE_COUNTER_TAB_SIZE; i++) { + papi_events_env = getenv(PAPI_EVENTS_ENV); + if (papi_events_env) { + char *tk = strtok(papi_events_env, ","); + int papi_event; + + while (tk != NULL && + papi_event_tab_size < SAMPLE_COUNTER_TAB_SIZE) { + if (PAPI_event_name_to_code(tk, &papi_event) == PAPI_OK) + papi_event_tab[papi_event_tab_size++] = + papi_event; + + tk = strtok(NULL, ","); + } + } + + if (!papi_event_tab_size) { + for (i = 0; i < PAPI_EVENT_TAB_SIZE_DFLT; i++) + papi_event_tab[i] = papi_event_tab_dflt[i]; + papi_event_tab_size = PAPI_EVENT_TAB_SIZE_DFLT; + } + + for (i = 0; i < papi_event_tab_size; i++) { retval = PAPI_query_event(papi_event_tab[i]); if (retval != PAPI_OK) { printf("PAPI_query_event %d - error\n", i); @@ -75,7 +104,7 @@ int papi_init_local(void) } retval = PAPI_add_events(event_set, papi_event_tab, - SAMPLE_COUNTER_TAB_SIZE); + papi_event_tab_size); if (retval != PAPI_OK) { printf("PAPI_add_events error: %d\n", retval); goto err_clean_evset; @@ -103,7 +132,7 @@ int papi_term_local(void) if (PAPI_stop(event_set, last_counters) == PAPI_OK) { int i; - for (i = 0; i < SAMPLE_COUNTER_TAB_SIZE; i++) + for (i = 0; i < papi_event_tab_size; i++) printf("Counter[%d] = %lld\n", i, last_counters[i]); } @@ -113,6 +142,11 @@ int papi_term_local(void) return 0; } +int papi_counters_cnt(void) +{ + return papi_event_tab_size; +} + int papi_sample_start(profiling_sample_t *spl) { spl->timestamp_ns = PAPI_get_real_nsec(); @@ -134,7 +168,7 @@ int papi_sample_end(profiling_sample_t *spl) return -1; } - for (i = 0; i < SAMPLE_COUNTER_TAB_SIZE; i++) + for (i = 0; i < papi_event_tab_size; i++) spl->counters[i] = end_counters[i] - spl->counters[i]; spl->diff_cyc = end_cyc - spl->diff_cyc; diff --git a/example/instrum/papi_cnt.h b/example/instrum/papi_cnt.h index 72e49c72c..db55e75e0 100644 --- a/example/instrum/papi_cnt.h +++ b/example/instrum/papi_cnt.h @@ -18,6 +18,8 @@ void papi_term(void); int papi_init_local(void); int papi_term_local(void); +int papi_counters_cnt(void); + int papi_sample_start(profiling_sample_t *spl); int papi_sample_end(profiling_sample_t *spl); diff --git a/example/instrum/sample.h b/example/instrum/sample.h index ca5f183a1..e88ef4f96 100644 --- a/example/instrum/sample.h +++ b/example/instrum/sample.h @@ -12,7 +12,7 @@ extern "C" { #endif #define SAMPLE_NAME_SIZE_MAX 20 -#define SAMPLE_COUNTER_TAB_SIZE 2 +#define SAMPLE_COUNTER_TAB_SIZE 10 typedef struct { char name[SAMPLE_NAME_SIZE_MAX]; diff --git a/example/instrum/store.c b/example/instrum/store.c index aa338aa6c..ccc6f05ae 100644 --- a/example/instrum/store.c +++ b/example/instrum/store.c @@ -23,6 +23,7 @@ static __thread uint64_t profile_sample_ovf; #define STORE_FILE_NAME_SIZE_MAX 250 static char store_dir[STORE_DIR_NAME_SIZE_MAX]; +static int counters_cnt; int instr_store_init(void) { @@ -38,6 +39,7 @@ int instr_store_init(void) if (papi_init()) return -1; + counters_cnt = papi_counters_cnt(); return 0; } @@ -78,7 +80,7 @@ static void store_dump(void) profile_sample_tab[i].timestamp_ns, profile_sample_tab[i].diff_cyc, profile_sample_tab[i].name); - for (j = 0; j < SAMPLE_COUNTER_TAB_SIZE; j++) { + for (j = 0; j < counters_cnt; j++) { sprintf(smpl_tmp, ",%lld", profile_sample_tab[i].counters[j]); strcat(smpl, smpl_tmp);