From patchwork Mon Nov 3 15:04:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yogesh Tillu X-Patchwork-Id: 40028 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 79D7621894 for ; Mon, 3 Nov 2014 15:10:38 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf2572526lbv.1 for ; Mon, 03 Nov 2014 07:10:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=T6N2Bdp2iTbO7yBcNbx+LywuICJ6R+0doKRW/t2tRKA=; b=CH4ZdBPFXa0aJT3I7DId4HA9NsNVZDhsJlTHaJxEUuCb74gsfe/4pEABJyBX/b7idz LlETcGTjh27jnyYxUDeZdwld3fe6EfD+3BrqVpFW40jRc4z0DYNwj8Qo02NscX8Tox6P PuYQDUEdywa3oDHStgvw/w9uV4idFwVf7IhtJW/9HVNgGd0QaO53KDJr0CjTGdU0I3ar 9gOP0mvjt8UwHZ6hBCcuVC2QMQOON8bVsLxsW1Hfp89qQ9Q4LVXsTa8gFWnP/e1d7O1K AXLdVoeH3PmGKxOfsf2Ixk83BNIL4gSxxkjW+WiGkeHxu7+HVm+7NOguhBcO70DNefuR oHGA== X-Gm-Message-State: ALoCoQmF8QbtKPKFbZoJGdd36ZUtr/e1HfHtrt1OUJCPn35JXVHA6D1Dc7LZE6PjSwmPwOcYuZ66 X-Received: by 10.112.38.101 with SMTP id f5mr2926140lbk.7.1415027437342; Mon, 03 Nov 2014 07:10:37 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.243.4 with SMTP id wu4ls177927lac.51.gmail; Mon, 03 Nov 2014 07:10:37 -0800 (PST) X-Received: by 10.152.43.197 with SMTP id y5mr52333815lal.82.1415027437079; Mon, 03 Nov 2014 07:10:37 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id ao5si32852405lbc.58.2014.11.03.07.10.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Nov 2014 07:10:36 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id z11so7461575lbi.19 for ; Mon, 03 Nov 2014 07:10:36 -0800 (PST) X-Received: by 10.152.5.38 with SMTP id p6mr51077740lap.44.1415027436644; Mon, 03 Nov 2014 07:10:36 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.141.34 with SMTP id rl2csp2930lbb; Mon, 3 Nov 2014 07:10:35 -0800 (PST) X-Received: by 10.66.182.130 with SMTP id ee2mr43847865pac.22.1415027434958; Mon, 03 Nov 2014 07:10:34 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id t11si11390865pdl.62.2014.11.03.07.10.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Nov 2014 07:10:34 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XlJFU-0004gh-No; Mon, 03 Nov 2014 15:08:52 +0000 Received: from mail-pa0-f50.google.com ([209.85.220.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XlJFP-0004cA-Te for linux-arm-kernel@lists.infradead.org; Mon, 03 Nov 2014 15:08:48 +0000 Received: by mail-pa0-f50.google.com with SMTP id eu11so12412900pac.9 for ; Mon, 03 Nov 2014 07:08:27 -0800 (PST) X-Received: by 10.70.37.8 with SMTP id u8mr24886409pdj.9.1415027306946; Mon, 03 Nov 2014 07:08:26 -0800 (PST) Received: from yogesh-Dell-System-Vostro-3360.Airtel4Grouter.cpe ([14.140.2.178]) by mx.google.com with ESMTPSA id mp5sm17413005pbc.33.2014.11.03.07.08.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Nov 2014 07:08:25 -0800 (PST) From: Yogesh Tillu To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 1/5] Application: reads perf cycle counter using perf_event_open syscall Date: Mon, 3 Nov 2014 20:34:01 +0530 Message-Id: <1415027045-6573-2-git-send-email-yogesh.tillu@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415027045-6573-1-git-send-email-yogesh.tillu@linaro.org> References: <1415027045-6573-1-git-send-email-yogesh.tillu@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141103_070847_987686_6C165DEE X-CRM114-Status: GOOD ( 13.30 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.50 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.220.50 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: magnus.karlsson@avagotech.com, tillu.yogesh@gmail.com, Prasun.Kapoor@caviumnetworks.com, linux-perf-users@vger.kernel.org, Andrew.Pinski@caviumnetworks.com, mike.holmes@linaro.org, ola.liljedahl@linaro.org, Yogesh Tillu , linaro-networking@linaro.org, jean.pihet@linaro.org, arnd@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: yogesh.tillu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This patchset is for application reading perf cycle counter using syscall perf_event_open. Signed-off-by: Yogesh Tillu --- app_readcounter.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 app_readcounter.c diff --git a/app_readcounter.c b/app_readcounter.c new file mode 100644 index 0000000..5363dd4 --- /dev/null +++ b/app_readcounter.c @@ -0,0 +1,83 @@ +/* +Application to Read perf cycle counter using perf_event_open syscall + +To Run: pass randon number to create busy loop +e.g.: $./app_readcounter 64 + +*/ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +static int fddev = -1; +__attribute__((constructor)) static void +init(void) +{ + static struct perf_event_attr attr; + attr.type = PERF_TYPE_HARDWARE; + attr.config = PERF_COUNT_HW_CPU_CYCLES; + fddev = syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0); +} + +__attribute__((destructor)) static void +fini(void) +{ + close(fddev); +} + +static inline long long +cpucycles(void) +{ + long long result = 0; + if (read(fddev, &result, sizeof(result)) < sizeof(result)) return 0; + return result; +} + +/* Simple loop body to keep things interested. Make sure it gets inlined. */ +static inline int +loop(int* __restrict__ a, int* __restrict__ b, int n) +{ + unsigned sum = 0; + int i=0; + for ( i = 0; i < n; ++i) + if(a[i] > b[i]) + sum += a[i] + 5; + return sum; +} + +int +main(int ac, char **av) +{ + long long time_start = 0; + long long time_end = 0; + + int *a = NULL; + int *b = NULL; + int len = 0; + int i,sum = 0; + if (ac != 2) return -1; + len = atoi(av[1]); + printf("%s: len = %d\n", av[0], len); + + a = malloc(len*sizeof(*a)); + b = malloc(len*sizeof(*b)); + + for (i = 0; i < len; ++i) { + a[i] = i+128; + b[i] = i+64; + } + + printf("%s: beginning loop\n", av[0]); + time_start = cpucycles(); + sum = loop(a, b, len); + time_end = cpucycles(); + printf("%s: done. sum = %d; time delta = %llu\n", av[0], sum, time_end - time_start); + + free(a); free(b); + return 0; +}