From patchwork Thu Jun 25 09:05:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hongbo.zhang@freescale.com X-Patchwork-Id: 50306 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E4C1A228FC for ; Thu, 25 Jun 2015 09:23:22 +0000 (UTC) Received: by wgfj7 with SMTP id j7sf17591962wgf.1 for ; Thu, 25 Jun 2015 02:23:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references:mime-version:subject:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:content-type:content-transfer-encoding:errors-to :sender:x-original-sender:x-original-authentication-results :mailing-list; bh=IbIbL+d8i09QQMpS285jvn3qTDcDeASFeqWojV78Kps=; b=ZwrFX+kenYy+tp3pOTwazRtkCQsfz4CMxH/eQ3ElQSYNGlRRtPUduwrdOy9VpOD343 SdbQW+rbMSUsgGvl23P2eZUD5QK2k70sJNQlRwmyBY6R+jZlTKLGr1APEBcgzKzVI/R9 w/CXT/zSj/bN3bJKuYYYw1VdDF4gi0H/zxu87/ffNrd2W9QSGFpwnJ36AtrKevlc0XQy oyCW54gouhwY1Af6gRv0cCjV8wIgeJBQx66jJ+b6rVvegWwzLJuudbqDGnFfJC3jLv2y V/17FvkyT4FcGqHhkl8o59XMRTEO1e3py2J6Jtr9jTrsCrYAx1/poqlGhsuhc4GpSVCH hPoA== X-Gm-Message-State: ALoCoQm78zrD0CBYwiO4kWog3truT8Bx++VpHzdbeReRYusVM3seg0/KGOsphWTpfccyO9kxmsxE X-Received: by 10.180.97.9 with SMTP id dw9mr1756007wib.2.1435224202247; Thu, 25 Jun 2015 02:23:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.115.198 with SMTP id jq6ls132674lab.4.gmail; Thu, 25 Jun 2015 02:23:22 -0700 (PDT) X-Received: by 10.112.162.38 with SMTP id xx6mr44009879lbb.110.1435224202112; Thu, 25 Jun 2015 02:23:22 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id j8si24218937lah.14.2015.06.25.02.23.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jun 2015 02:23:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by lagx9 with SMTP id x9so41227449lag.1 for ; Thu, 25 Jun 2015 02:23:22 -0700 (PDT) X-Received: by 10.152.1.40 with SMTP id 8mr44872917laj.56.1435224202006; Thu, 25 Jun 2015 02:23:22 -0700 (PDT) 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.108.230 with SMTP id hn6csp464176lbb; Thu, 25 Jun 2015 02:23:20 -0700 (PDT) X-Received: by 10.140.146.205 with SMTP id 196mr60896237qhs.27.1435224200318; Thu, 25 Jun 2015 02:23:20 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 17si16898573qht.35.2015.06.25.02.23.19; Thu, 25 Jun 2015 02:23:20 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id 4C2A661E84; Thu, 25 Jun 2015 09:23:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 714BE61DB1; Thu, 25 Jun 2015 09:22:28 +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 64C2161DBA; Thu, 25 Jun 2015 09:22:25 +0000 (UTC) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0139.outbound.protection.outlook.com [65.55.169.139]) by lists.linaro.org (Postfix) with ESMTPS id 3DA7B61DA0 for ; Thu, 25 Jun 2015 09:21:57 +0000 (UTC) Received: from BN3PR0301CA0055.namprd03.prod.outlook.com (10.160.152.151) by BY2PR03MB609.namprd03.prod.outlook.com (10.255.93.40) with Microsoft SMTP Server (TLS) id 15.1.195.15; Thu, 25 Jun 2015 09:21:56 +0000 Received: from BL2FFO11OLC004.protection.gbl (2a01:111:f400:7c09::139) by BN3PR0301CA0055.outlook.office365.com (2a01:111:e400:401e::23) with Microsoft SMTP Server (TLS) id 15.1.195.15 via Frontend Transport; Thu, 25 Jun 2015 09:21:55 +0000 Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11OLC004.mail.protection.outlook.com (10.173.161.188) with Microsoft SMTP Server (TLS) id 15.1.201.10 via Frontend Transport; Thu, 25 Jun 2015 09:21:55 +0000 Received: from hongbo.ap.freescale.net (hongbo.ap.freescale.net [10.193.20.1]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t5P9Li90032447; Thu, 25 Jun 2015 02:21:53 -0700 From: To: Date: Thu, 25 Jun 2015 17:05:04 +0800 Message-ID: <1435223104-15434-4-git-send-email-hongbo.zhang@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435223104-15434-1-git-send-email-hongbo.zhang@freescale.com> References: <1435223104-15434-1-git-send-email-hongbo.zhang@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC004; 1:RRBCPXnfHjKRkQP9SWNd8hSwauhfCFkAvnRz7Va7RTQcuJ+ysxJWYKnWpHYqKkPGCjUOQlx2tw/6g1GU4nHtLt9eT/Lv2IcjCf8sxLGl5/vh6Mdv+f4ISClV/SaOH29Ck+KWTXEowTAmLx4YbDruCg6oLtUBGdD2/bsCr9STqf9wcU8vwCrWeYuGHtgvgr9ypLoeUg0l/x0qoi+gvHmqLc+IgRpFRTMXF0JNQpRVCz6u+r85fIs476cgBFdSxttybwOA1FGgTBTt99fQbrE9sPM0q5lON396Anx+z3j4RO1MyT3Tq8Oqiu5UcLqeRX+1 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(19580395003)(87936001)(19580405001)(86152002)(189998001)(86362001)(6806004)(5001960100002)(77156002)(62966003)(2950100001)(50226001)(77096005)(2351001)(92566002)(106466001)(229853001)(85426001)(110136002)(105606002)(46102003)(104016003)(47776003)(50986999)(76176999)(48376002)(50466002)(36756003)(33646002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR03MB609; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB609; 2:BzqMCzHigWIjfFqf1E93gxAaYe4KMR0FZMg0VwMZyqzDt0yJb9+EEiiVnLEU4Ac8; 3:9pECKheZ/8rN7Ju+sEU9JxCFzR3a+kBQe5dd1NEQJNwH72bM06aTx3OEsqKyca1Qtn1D2o50EB1VQlo3Cq5uSKZabf8dlM7R3p1xp2PUUHCQvn0WDJfNv+96ZaUpcGXNauh43/QKKgHGwpKA25H3vuWrW7HDr62JWu44kFMkNW4BX/DK3TyZpG9lC9+n3dQZkWcoCHyV4GFQgDUlECYr367Hf0m3kpXCoNaWcQyhNOI=; 20:u0Gw8F4sbb2YD0MaiFnIMbrdTjBadsnZH5FdpLx+Ca/lzlW3PSoP1P1uwrBf/iNdw6PHbcRcFuhsvrUzHpFat+/4BA9aSOYm+C2r5kLpIKPTLCbG7aIXVhBHlHaJ4pnFROLvauOa/XaA1cHWd+1nYQgSmwxjRKh9TSOOfw1FZWfSwjPcO9suH1sOlo+2S5cwTMYGYamSqebpY8d8kAvvv1mCsUdwUyAhEfPpB5f0u9YJqO1wI5s5RCO4Tzq9HTAV4XaTs5+RgV7xltGyrD8wOKE+epefeHVYkS4pmbYBXrJQdvO58Hlr/LM4g+Y7GZBSxz5w8RyrO+zA3ICZj1qNbulVAMOmYAmXJaicpU+gbVw=; 4:o/aW75MnIr8+pYIxrApplDrdmg/fLbjHjhgzOyhM6NDR4axRkELT4+REfsSJIJv7eDGVIpnzUtScwYxHYmrvnvbW3e3rYQ7Li3NPH54eIe21pH/mdkW/K8KzltEh9LF57JwwIALhiKnBjQ1s+0AyUtZaRj/EkUopM/lNG2+ETmE94GMfdgsUxNzKJBxXZUq0CM02GS4AY/H0D+CZfPnpzDmuLpR6We9IaS8pWQ838K+VFEGtCVG6gEQydL37ZJ1hT80NhMnEVgZ7/pdK/wYOUFNkYRhlTb1sPukvLEye5aA= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB609; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BY2PR03MB609; BCL:0; PCL:0; RULEID:; SRVR:BY2PR03MB609; X-Forefront-PRVS: 0618E4E7E1 X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB609; 23:eVnrhssFAY0hqIoaR941EyU2YSl1m0vVnZIsfXBSP7VlQfouvyJlkcGptTnhXnwm8Xb6rhno3QgRb/YXssBN6KDcmnZTtTNIN6DEUns6g88H3wgSvpGsiNZNpxbjp02WOwwJWBE061cYVMTNI3movZd4LOBmiVAvQ0rUD/KQcEtDDM8KDxLIhyLW8kc2ZnQADa5QxoOYeVJ1uU9VgexstqtUv5fLWN0ZYfSan6MR033n0n5CU4m6hVsaTj0Ho94Z+mDvNbBxLJkw50nhM+oAxacdSfikhmpaUSHp87dpd333C3qwcu//IN594HHxHgKTUXN61lY03EpWJfduRFF7GdyX9lxKmcztQik79b/+9VoGr2vPk9LiNMj9tqpdOpKURtwT+ZP13zgI5AETQTscuOt8NcIp9wGqKm2a6FwE3qagbQmOg33NoFDyn98N8+jtgBdO7qRDgGKSl0sR8f32rNYLBIkGMmbqI93Dpepe0h9FVlMCcZaChrvNKNV3ywwKqpe9hTlU+NBUxk07OyEb3EtrMiFuTgVoY0VXB2oI82BWUv04O/IUemCBWM+7NHQFkc06u80u7IKcOjGEppXdl32XycJl6NFt10+hIXnkk8jGTVuZ3gE+draEGUkkga5XTXTsQA/N7XJIrVRSwxp6yM63zuMUa8V1VMOrEdQsiIzUgyIeDpz2URpgoE92/M/QJD0MDig6GThoZEsOlgPiQ5Yf+gHV2iVLNGPU8jxdbaOey3uDels85TAqGUEvndW9C7TfNnbSCu49xgR2aYPiWdn1LVm/e1unWiopk3EJ3BAmF9tu9IpT+0frtVsumuOVZCGCpGWSjY98kLroNZruilmEzzO6aFm9QWqv1vN8BH6XtoQWqjBw8Qilwa982SOTpfhysPrYyziZXKwOO9hcxg== X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB609; 5:voU8KoWOgyC0rr4aXd630MbKQP8hT58VC4W6VO3xo2jsK26BJL9HqAWxQevXU8nBZHNp+3Uxa/sIdbPpSXYuo05A2WSH2DYFq7ijfEGbJ1PumphN69HQLnfsgUp2eT93cp+qbVyybS41Tvvc+FK7Fw==; 24:FNyhHk4bglBrrHdWXflRl+RlcU6aZPdc4WZ4oB2YKzGWj8F2Rlc2c0oZLM/9G+hC0zf1b2VlSYW71s0bukeF/tpuam9PZyZDdN+/eYhrAvM=; 20:3tNOGA4sBOHm5oPt3e2vbBEHZsiA4E/0ZFaBQ/sC450IZNtebMh2dH6etuWBiWwjYxOyEPnMyA/3Iq8sp+MUEA== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2015 09:21:55.2358 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB609 X-Topics: patch Subject: [lng-odp] [PATCH 3/3] linux-generic: sysinfo: add API to get current CPU frequency X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@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.215.45 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 From: Hongbo Zhang This patch add API to return the current frequency of the CPU on which the thread is running. Only x86 platform is implemented, others are to be done. Signed-off-by: Hongbo Zhang --- include/odp/api/system_info.h | 7 ++++++ platform/linux-generic/odp_system_info.c | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/odp/api/system_info.h b/include/odp/api/system_info.h index 55a4180..02fabd3 100644 --- a/include/odp/api/system_info.h +++ b/include/odp/api/system_info.h @@ -33,6 +33,13 @@ uint64_t odp_sys_cpu_hz(void); uint64_t odp_sys_cpu_hz_amp(int cpu); /** + * CPU current frequency in Hz + * + * @return CPU current frequency in Hz + */ +uint64_t odp_sys_cpu_hz_current(void); + +/** * Huge page size in bytes * * @return Huge page size in bytes diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 3ca8b27..624d75d 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -145,6 +145,41 @@ static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo) return 0; } +static uint64_t arch_cpu_hz_current(void) +{ + char str[1024]; + FILE *file; + int cpu_curr, cpu; + char *pos; + double mhz = 0.0; + + file = fopen("/proc/cpuinfo", "rt"); + cpu_curr = sched_getcpu(); + + while (fgets(str, sizeof(str), file) != NULL) { + pos = strstr(str, "processor"); + if (pos) { + sscanf(pos, "processor : %d", &cpu); + if (cpu == cpu_curr) + break; + } + } + + while (fgets(str, sizeof(str), file) != NULL) { + pos = strstr(str, "cpu MHz"); + if (pos) { + sscanf(pos, "cpu MHz : %lf", &mhz); + break; + } + } + + fclose(file); + if (mhz) + return (uint64_t)(mhz * 1000000.0); + + return -1; +} + #elif defined __arm__ || defined __aarch64__ static int cpuinfo_arm(FILE *file ODP_UNUSED, @@ -378,6 +413,11 @@ uint64_t odp_sys_cpu_hz_amp(int cpu) return -1; } +uint64_t odp_sys_cpu_hz_current(void) +{ + return arch_cpu_hz_current(); +} + uint64_t odp_sys_huge_page_size(void) { return odp_global_data.system_info.huge_page_size;