From patchwork Thu Jul 9 10:46:07 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: 50939 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ECBCD228E5 for ; Thu, 9 Jul 2015 10:51:46 +0000 (UTC) Received: by wgfk9 with SMTP id k9sf78192186wgf.1 for ; Thu, 09 Jul 2015 03:51:46 -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=EmByOCvERcPk3wao0duivrzS81boj59h73NAKCXniHY=; b=QA4oFK9jqMrbBdwzphuDEzqlzruD963btGYnqiXGtorjvRid6fupi4ozKShPXK8uHM rtxn/OmL55N1hZfgknmJnmD0TuPwjXwNcKhYLg3S5QD4LH28G7yBwb7xJL1TN5wH87jR wFZjNyoQnae+Csdjfq6pB/+yShAKbcl3DhxI9aUvCQnw5Ls7ECJ1bOmQEbIkWhjaaaPc jyb92oDB+QYnRyzhNAxyRT1WI+Rgsg3VBHEUcIvZMTR/nBQ3OGeysgMR3FWzKPN1Kld9 +PsRypWN6xzcTl8NXa08mKJQeZoqlqoNIbRRFjBpMG3I4ont2zdjGKqaEkpm/HJYpQmN WeLg== X-Gm-Message-State: ALoCoQmhICexgq1zYLOK8Rc+4OlhO1t2h6Y/d1xq3XScjNmZpwyrwcwaetvfBke+1/kwNKfD/USU X-Received: by 10.180.87.201 with SMTP id ba9mr23466578wib.3.1436439106321; Thu, 09 Jul 2015 03:51:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.74 with SMTP id k10ls1099711laf.30.gmail; Thu, 09 Jul 2015 03:51:46 -0700 (PDT) X-Received: by 10.152.20.138 with SMTP id n10mr13996477lae.115.1436439106181; Thu, 09 Jul 2015 03:51:46 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id r6si4139573lag.118.2015.07.09.03.51.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jul 2015 03:51:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbbpo10 with SMTP id po10so72674351lbb.3 for ; Thu, 09 Jul 2015 03:51:46 -0700 (PDT) X-Received: by 10.152.5.228 with SMTP id v4mr6761942lav.36.1436439106042; Thu, 09 Jul 2015 03:51:46 -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 hn6csp578964lbb; Thu, 9 Jul 2015 03:51:44 -0700 (PDT) X-Received: by 10.140.236.77 with SMTP id h74mr24261893qhc.21.1436439104046; Thu, 09 Jul 2015 03:51:44 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 21si6374469qgp.63.2015.07.09.03.51.43; Thu, 09 Jul 2015 03:51:44 -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 E968461FBD; Thu, 9 Jul 2015 10:51:42 +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=BAD_ENC_HEADER,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 8E5B961FC6; Thu, 9 Jul 2015 10:47:21 +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 5A29961F6F; Thu, 9 Jul 2015 10:46:55 +0000 (UTC) Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1bon0112.outbound.protection.outlook.com [157.56.111.112]) by lists.linaro.org (Postfix) with ESMTPS id 0C2CC61FBF for ; Thu, 9 Jul 2015 10:46:25 +0000 (UTC) Received: from BN3PR0301CA0081.namprd03.prod.outlook.com (10.160.152.177) by CH1PR03MB611.namprd03.prod.outlook.com (10.255.156.167) with Microsoft SMTP Server (TLS) id 15.1.207.19; Thu, 9 Jul 2015 10:46:24 +0000 Received: from BN1AFFO11FD042.protection.gbl (2a01:111:f400:7c10::142) by BN3PR0301CA0081.outlook.office365.com (2a01:111:e400:401e::49) with Microsoft SMTP Server (TLS) id 15.1.213.14 via Frontend Transport; Thu, 9 Jul 2015 10:46:23 +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 BN1AFFO11FD042.mail.protection.outlook.com (10.58.52.253) with Microsoft SMTP Server (TLS) id 15.1.201.10 via Frontend Transport; Thu, 9 Jul 2015 10:46:22 +0000 Received: from hongbo.ap.freescale.net (hongbo.ap.freescale.net [10.193.20.67]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t69AkBfi022771; Thu, 9 Jul 2015 03:46:21 -0700 From: To: Date: Thu, 9 Jul 2015 18:46:07 +0800 Message-ID: <1436438768-4258-8-git-send-email-hongbo.zhang@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436438768-4258-1-git-send-email-hongbo.zhang@freescale.com> References: <1436438768-4258-1-git-send-email-hongbo.zhang@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD042; 1:vlkietyTJjWF37Q8mzjIFD84v/GhYuMtJhE8P7dlGR6UrV1XAjxDKpnSFQYktmFy9bbvemeQ7M+oulkUafISWsLJOzvj+C0eDAYJIouGybpBaeujJsRKpQ70AGyIAFOwSkRm3xeqX3Q1FMmdIy1Bxfgoz6h4RW0qkeCQxOfn50blFpcRKSz7sG5JK8Zwt0XgSXPoGP+LIlOsglUjZNEDYOiY2Pn8KJpsmmntTEdvSRkIuxlmPoUhK9UN/g8L+IMyDm9N+3iGcl7w3wtlkiperMKCFMwbh662Ei6f9u98jnvhQAUDLSt+UL2HmAGl7sI+ X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(199003)(189002)(2950100001)(77096005)(92566002)(5003940100001)(50226001)(36756003)(106466001)(62966003)(47776003)(110136002)(189998001)(46102003)(87936001)(6806004)(86152002)(105606002)(77156002)(48376002)(2351001)(85426001)(50466002)(19580405001)(5001960100002)(33646002)(50986999)(76176999)(19580395003)(229853001)(86362001)(104016003)(41533002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:CH1PR03MB611; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; CH1PR03MB611; 2:IlRuMpktuyyY7yVcZ1+wWE3JzucNp2tYkNFJqlkveAE0QNjBczAiHQpNOToAZAxX; 3:xrTgD6B5MWgn3HC3WHgEdFg6VxZUh6j8HP4xwAvpgONN5Jnzqj2Vbqe3x+lN2Kr2wLduEdmgarhT+CbJMVBZ2jh+H+oAefPqUwwqrK9C7LlTHGFODijZNDFi6Z4hPGMoasHnCHyAj55l8FqzbF3LOn/AdqcrDEE4N5gGhMImIyXg4s45GOOJgWHayuuFFDHJbqy5O05AZ9JV4jH5w6QHyaQddB0PjcpSQuhGZXx84o0=; 25:VqNUpd3frnMjcmBiULzvDYPYYPHyrH8yiSSDl1vgQISpkJC+9r/nnfI3MaVQrIzGAAr5wlejbCbdvdQVHgcnrRhzGu9smtrqh6fQSolpdYj27fEAIqvO+UH/UPLi/HTy+ypZh6xZdvJb7a7b3+BE2UeqxQJeRk8oy2Alxi2zL2Atv0P2AEhZmIhegszxOAuJREWEW8C7Q/ISs1rQiiMnNGf/1QzMsSFBgScwmNOBk0mniaVYgTNFb9abkMROE8mphd/Vvfj2Xai2F56xT8L+6w==; 20:SnYqgwSgTg9dXlIqo24rjbJguK1S8YjlJEu9Fvdi39OP3PV5RDwYspgNHEUl3LeUD/JFsbgw2Psna/rdmFq5k0LH+8R0WJ9KQCGFjOF3duCxIkNLGPAetolVcrf3ZMVC72vTfKe6Dvqv5zfGJwtVyoF7xCf8rOnZ4FEWwJkF0pUY7Xka+MP01e5oKr/Tv18vV94zi3mVZgcPmFkQybLG7YYEdCaariN4w8T+msVytQ2w9vUlZlkScaq/i6RFrXIuRBTgfLVVojVXW/AoML2FaPsfT57t8Xj9plYuEQKKtIlsZ0Vxwj9Z2LPzaxXme+sKivCgq6Ot0e1skWdWM8W92g4ZfAd9SQzuUW14kTvjPxI= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CH1PR03MB611; 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:CH1PR03MB611; BCL:0; PCL:0; RULEID:; SRVR:CH1PR03MB611; X-Microsoft-Exchange-Diagnostics: 1; CH1PR03MB611; 4:aOUyH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=?us-ascii?Q?m4dLKNAlApVCbhoxB91WM9oN2RVX3jk1omLJZkmj0MnhgjKJbE+ov27hRT0F?= =?us-ascii?Q?op9wrae6gDrJAh+t30WBl6Xf4jMtas87T1dRfkJrXGlS07yLd+7kzLRzc8EZ?= =?us-ascii?Q?/NI7T+XoQq1bTFif5vVqAcCFxtynWGixkkJYU4Pv+gOifZy84RPoThBZsnh3?= =?us-ascii?Q?LQXc5WLoYgUH13VV9i/Cl47ibj55jOKGm25nqUouv9QD14eiVtnrFCRWvKIg?= =?us-ascii?Q?T0NbUSs40DpUqomwELtrYjSyonaHnOw3ugMnNmKVzChaU4atuiDEefhlvQEl?= =?us-ascii?Q?nbiYq6gJd89rAKSjFBIPmGODJC1vhs6o5KrX68Uk+yIFIsw4RdCgRTHYB84E?= =?us-ascii?Q?8kKb94apgi5tqOCqmZVaaK9lYhQ8Ipwuv7I8gFTA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CH1PR03MB611; 5:6nsxGV1qHJcUQAer/cBz5I8hBBDJjBaR9UQ58uX/i1TKWOmzxSx0oLKzVkrK+yzSSDLKJKIeM+e6R42HJ9dNop56etcsF+NnZFZ3pL5t2fnWTZ4b0B7fdyYnCkzNvfflrIEy9o1YbaxN9Hbc+E7cIQ==; 24:piZgRYL1hnmz0Yfza1lO/5I4Go7Z/CDAoG127tPaaNscQQ/Mz1vbvZdISVxx67fs4cCIXQu3KPl3H9oTvtcnrww5CKxfEEjP+4IOj6CUvxo=; 20:HhXkOOiuKBkZmZQibSlESAVOH5K1oaswM5+Lpj8l8uh9n0XuM9cDTHAehH1lGo+60dlQu8gddX65iRUkAqfM5Q== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2015 10:46:22.9249 (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: CH1PR03MB611 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v3 7/8] 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.171 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 Previous CPU frequency API is adapted to return max frequency, now new APIs are added for getting the current CPU frequency. odp_cpu_id_hz(int id) returns frequency of the CPU specified by parameter id, while odp_cpu_hz() returns frequency of the CPU on which the thread is running. Signed-off-by: Hongbo Zhang --- include/odp/api/cpu.h | 20 ++++++++++ platform/linux-generic/odp_system_info.c | 63 ++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/include/odp/api/cpu.h b/include/odp/api/cpu.h index 3ecef1f..8809a46 100644 --- a/include/odp/api/cpu.h +++ b/include/odp/api/cpu.h @@ -64,6 +64,26 @@ uint64_t odp_cpu_hz_max(void); uint64_t odp_cpu_id_hz_max(int id); /** + * Current CPU frequency in Hz + * + * Returns current frequency of this CPU + * + * @return CPU frequency in Hz + */ +uint64_t odp_cpu_hz(void); + +/** + * Current CPU frequency of a CPU (in Hz) + * + * Returns current frequency of the specified CPU + * + * @param id CPU ID + * + * @return CPU frequency in Hz + */ +uint64_t odp_cpu_id_hz(int id); + +/** * CPU model name * * @return Pointer to CPU model name string diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 00d009c..b780b13 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -145,6 +145,42 @@ static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo) return 0; } +static uint64_t arch_cpu_hz_current(int id) +{ + char str[1024]; + FILE *file; + int cpu; + char *pos; + double mhz = 0.0; + + file = fopen("/proc/cpuinfo", "rt"); + + /* 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 == id) + 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 +189,11 @@ odp_system_info_t *sysinfo ODP_UNUSED) return 0; } +static uint64_t arch_cpu_hz_current(int id) +{ + return -1; +} + #elif defined __OCTEON__ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) @@ -195,6 +236,11 @@ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) return 0; } +static uint64_t arch_cpu_hz_current(int id) +{ + return -1; +} + #elif defined __powerpc__ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) { @@ -236,6 +282,11 @@ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) return 0; } +static uint64_t arch_cpu_hz_current(int id) +{ + return -1; +} + #else #error GCC target not found #endif @@ -379,6 +430,18 @@ uint64_t odp_cpu_id_hz_max(int id) return -1; } +uint64_t odp_cpu_hz(void) +{ + int id = sched_getcpu(); + + return arch_cpu_hz_current(id); +} + +uint64_t odp_cpu_id_hz(int id) +{ + return arch_cpu_hz_current(id); +} + uint64_t odp_sys_huge_page_size(void) { return odp_global_data.system_info.huge_page_size;