From patchwork Thu Jul 2 10:45:22 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: 50566 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 48C81214B3 for ; Thu, 2 Jul 2015 10:48:03 +0000 (UTC) Received: by lbcpe5 with SMTP id pe5sf12322098lbc.3 for ; Thu, 02 Jul 2015 03:48:02 -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=NQAgshpWPchHkg5dqFYA4/UcMbHBna7XA2dXOmY2S20=; b=b/ZlKUgNpZQptPwqn4JNDcHkeymDqb2eNyzEBMj97OiQJb+XnfEPDN+N9CcJcB2BDJ r/yQce3dbHmj0X0CrzeFGBLm7vlMWEMW5DR/S0ikjSMfs1CVPnUS7UR7SYCVuM2UwGOE 1AfHO7kWcteFUuBG4iPF8mVEYEA1rnPq1/7wbYX04jgPObbi4pSyqs8KR2NFZ+b8/Gpa XsE5isKgyLCb9zM/68/iGEaKbs7IBWQLDKvUipKpC/Dhpi1gDECLi8y9cvWrQ1yZUaXW xU8XKoVx5WkhdLP3mbuph3/24ur9fUCbbFqA5Y0N1fsxCLi61/w+n9bqrcQrIEibQvbD 5D2Q== X-Gm-Message-State: ALoCoQlFm+FJiKURccrn2UKEnmjEVDksD/aX4f7LeTIXRRBebZ8khwveeyOrWceCJ8edLyOM0pHp X-Received: by 10.112.9.100 with SMTP id y4mr19771104lba.20.1435834082209; Thu, 02 Jul 2015 03:48:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.199 with SMTP id m7ls322456lam.83.gmail; Thu, 02 Jul 2015 03:48:01 -0700 (PDT) X-Received: by 10.112.24.71 with SMTP id s7mr29036309lbf.37.1435834081827; Thu, 02 Jul 2015 03:48:01 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id r1si4152665lar.2.2015.07.02.03.48.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jul 2015 03:48:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbcui10 with SMTP id ui10so29358459lbc.0 for ; Thu, 02 Jul 2015 03:48:01 -0700 (PDT) X-Received: by 10.152.5.167 with SMTP id t7mr24506325lat.112.1435834081368; Thu, 02 Jul 2015 03:48:01 -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 hn6csp386164lbb; Thu, 2 Jul 2015 03:48:00 -0700 (PDT) X-Received: by 10.140.147.14 with SMTP id 14mr43035313qht.97.1435834079971; Thu, 02 Jul 2015 03:47:59 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 141si5863662qht.25.2015.07.02.03.47.59; Thu, 02 Jul 2015 03:47:59 -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 E828861F4E; Thu, 2 Jul 2015 10:47:58 +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 F2CBB61F57; Thu, 2 Jul 2015 10:45:50 +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 BCCEE61818; Thu, 2 Jul 2015 10:45:35 +0000 (UTC) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0102.outbound.protection.outlook.com [65.55.169.102]) by lists.linaro.org (Postfix) with ESMTPS id 9AAB9617FC for ; Thu, 2 Jul 2015 10:45:34 +0000 (UTC) Received: from CO2PR03CA0035.namprd03.prod.outlook.com (10.141.194.162) by BLUPR03MB602.namprd03.prod.outlook.com (10.255.124.39) with Microsoft SMTP Server (TLS) id 15.1.207.19; Thu, 2 Jul 2015 10:45:33 +0000 Received: from BY2FFO11FD018.protection.gbl (2a01:111:f400:7c0c::121) by CO2PR03CA0035.outlook.office365.com (2a01:111:e400:1414::34) with Microsoft SMTP Server (TLS) id 15.1.201.16 via Frontend Transport; Thu, 2 Jul 2015 10:45:33 +0000 Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD018.mail.protection.outlook.com (10.1.14.106) with Microsoft SMTP Server (TLS) id 15.1.201.10 via Frontend Transport; Thu, 2 Jul 2015 10:45:32 +0000 Received: from hongbo.ap.freescale.net (hongbo.ap.freescale.net [10.193.20.1]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t62AjPm3012040; Thu, 2 Jul 2015 03:45:31 -0700 From: To: Date: Thu, 2 Jul 2015 18:45:22 +0800 Message-ID: <1435833923-28361-5-git-send-email-hongbo.zhang@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435833923-28361-1-git-send-email-hongbo.zhang@freescale.com> References: <1435833923-28361-1-git-send-email-hongbo.zhang@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD018; 1:Nvd7Vz8145V6hxJAUAYr3VXXRdcenwlePoF6wCWLuWsi4t5MktSlXE3zGbd1exyhiApz30m8QllNOY+th3Z7EK/ir8nThNAelYA7lvD64VDSuwX/vTaoT+NiotFEZTg2DNgEKJGVDUsodEhDxdfIJ3Bh6Wx93mg69SvydhVC/XAw+edlagmpOBThnVRurwyLQBmVRiHDSzmwmOC9Dao1peSQgNk1zA7qS7dqTi8z1Xm7uq67IgFRf5isj+K8aFSq5iJjzjbs+w9upK7vu73lBpFF0Fge32bsYxhBfz++H/HVi076wGxrz7pqpQiv5Rmp X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(85426001)(189998001)(19580395003)(47776003)(36756003)(77096005)(2950100001)(76176999)(110136002)(48376002)(50986999)(86362001)(5001960100002)(87936001)(50466002)(86152002)(229853001)(33646002)(2351001)(77156002)(50226001)(106466001)(92566002)(19580405001)(62966003)(105606002)(6806004)(46102003)(104016003)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR03MB602; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB602; 2:woXx3tPMM2XTkAvLnoU37sRQnbc32zXAXAPvLPsCYOAp1DnqJnlKfu00rCYKJkaC; 3:LQGJTpl9W1DDz+MSwZiyDId0B+tR4zXhuhuuqAfDBwrypqObt5iaYDm4lDEx1VEwcXC3LthOVbgdTQih1f3QM6jqkAuyUS51Y7TiqtuybkZWeO1MAbiDd2Pu0osPdo/DXUMko3AeY2wOtl0oJepg9GQ2w89rcS/M2OjAvBR9v/qTSMn8q5YQhFwci3SIjiHY2AzUfOESoSvqKr4ddyjyf6nSz101TUP9Vy0gE6OlUYk=; 25:Zhh1oTCdQWHhtGt9X/3RNhhGy68y6fZyY2rZ2n48tdqj1/VxZmJLjNTznwuVRMBHyO61/M+WUzpq1nn0UA6FFeuQ4arX1S1RgaXUIXgpCZ4/MA6DKIkO+ULkXLFBM0XxoayP8yJPVu25157yUOQXZpVfNNQQUozSM8zLj9LAYqPtardsuG37TrM0pjVgoZGbTSxoxVvtZVgbw8MycZK59EqyOpLkNgLixQaF98c9WEEjP2ogF4zye7VbRQ0Sz7k7xonGmmQj0YnUd/0GLUF1YA==; 20:+lzPjl3IDWvmlRVexQRZ6aQu7dRKHsP6NaVdMywjHHXgWVoEtDTzRvhQrK4KfwJCC8nAMI7F+TzSY9ZDBXUoFTqozXNWc7A9sj95/HjhEBvt/7al/M47OlLOw5/JL6sWf2NQXo4xHlWuWPC8C1lmDMAu3k0rHRkBTCwTsDn2pP40ZB1IwhhmO2HbHcaC7TIH6/1N+Xm43HsZHdvLNxXUoshTrmQSrhgWVBGlG0aIYdj0VYM5CtoO8fW/Bp9xIvDjxPQwgYI9aepDrj+J2IZ0dgJP8NtHq34ReD78HK7t9qDZR727LThAQuJFhKZzspJDHhTT7BuIL0Spr7mL8NiAUKbO1u+mBMFgxePVBHAsF7M= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB602; 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:BLUPR03MB602; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB602; X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB602; 4:bvrtONOJraBYzaZhFgVkIXVFRuxZrKukpfE5DL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WnejpkrWK3uZ534OJMoFlf6CfF/63Y06s79TOawSK6fIHvc1ufNh4JmVAFFjHDBjSOs1k065xd2C7s0MAfQJrRC1vxyS6jSnuP8+MVwmAmLfMahUzAhaBe/X9FURZFMUHIfFUB40H9GOe/mz0okqHupgkERhyhbbXZpgJ6s6wtaBjqKjf4= X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB602; 5:6IpxYV9n6E+aAUvjN2Go20e7bg0TQ5AXbdrUaKFeHnxryT9LVzvYHkfEkCSpb/cKhxtKsxnpCadhojBQYxqFoF2h2F5NV5cgMCiLCezIcregRq2hFHL2D4nj1oxSebM8uE+hOBOGta70JJWpBm2f6g==; 24:JeRLKlH5W9g2uNSR/hC06H2n8QRmCZvrVjtGZr3Q/SB7hpdLUdKU8i2I2vcyuYrJBF2O7huMTNC/c3B1Kj+ygzwDdSomMswe3lvLZ1q2wO0=; 20:BzUAfsoFtKwix8L0z+nuCmpiafi82sTeEaS+gQt2Fxoxbfyxt0BaOoNmHp+NE1WSA/F5HSqua1otiNa9Zo3YnA== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2015 10:45:32.8911 (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.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB602 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v2 4/5] 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.217.172 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 now 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 | 58 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/include/odp/api/system_info.h b/include/odp/api/system_info.h index 8627d97..3737aa0 100644 --- a/include/odp/api/system_info.h +++ b/include/odp/api/system_info.h @@ -38,6 +38,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, -1 on error + */ +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 00b8d4d..c275c5c 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -145,6 +145,43 @@ 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(); + + /* find the correct processor instance */ + while (fgets(str, sizeof(str), file) != NULL) { + pos = strstr(str, "processor"); + if (pos) { + sscanf(pos, "processor : %d", &cpu); + if (cpu == cpu_curr) + break; + } + } + + /* extract the cpu current speed */ + 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, @@ -153,6 +190,11 @@ odp_system_info_t *sysinfo ODP_UNUSED) return 0; } +static uint64_t arch_cpu_hz_current(void) +{ + return -1; +} + #elif defined __OCTEON__ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) @@ -194,6 +236,12 @@ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) return 0; } + +static uint64_t arch_cpu_hz_current(void) +{ + return -1; +} + #elif defined __powerpc__ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) { @@ -235,6 +283,11 @@ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) return 0; } +static uint64_t arch_cpu_hz_current(void) +{ + return -1; +} + #else #error GCC target not found #endif @@ -378,6 +431,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;