From patchwork Tue Oct 13 11:13:12 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: 54845 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id 107D823001 for ; Tue, 13 Oct 2015 11:42:43 +0000 (UTC) Received: by lbbpc3 with SMTP id pc3sf7983725lbb.2 for ; Tue, 13 Oct 2015 04:42:41 -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:spamdiagnosticoutput :spamdiagnosticmetadata:cc: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=HREM9OReToGOeR5WDC71pZgEgcCv8fTCVrbObtNCsdM=; b=Fxt0kY73mW5pxjr3Ln8mhFydecrbDKv65rEO7gYW67iYhDiU1XUc5rHSthm1AUobzm FsjZK4jbaOrZGbXVmjqKwPknYOIaJ8g2DlETRxakGQe1wtur8/UY2V8uf1F/zogRfD8I f2Sw0ZqVL1NMYfyYpIIwDOkHJsS85hQQWcgS1wrhMNsIZ01yDk/PY5yXYWsQKRDGKtiv h+twLcwWaqXbxr9ZzWUA4Ju0BjX0BZ/u8I5vO4qv6nYikqIEuja1TiJrKvnrvUT1IXaR UDxGEKKi6MkR2CgpRF/jROgkFlzKaJVwcmWRKqbxdCLP5AJRX1PzhULaqj/VNOzjdsEf NxGQ== X-Gm-Message-State: ALoCoQkfkPylpeY/Kny9XVeGYFqkxene8gOFcnHwXWhM3gc/CyWbdWRslZsQL2hJdM39IicynyJJ X-Received: by 10.194.94.66 with SMTP id da2mr2589568wjb.7.1444736561631; Tue, 13 Oct 2015 04:42:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.81.208 with SMTP id f199ls151185lfb.101.gmail; Tue, 13 Oct 2015 04:42:41 -0700 (PDT) X-Received: by 10.25.147.76 with SMTP id v73mr10042142lfd.102.1444736561502; Tue, 13 Oct 2015 04:42:41 -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 li9si1888812lbc.121.2015.10.13.04.42.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Oct 2015 04:42:41 -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 lbbck17 with SMTP id ck17so16438073lbb.1 for ; Tue, 13 Oct 2015 04:42:41 -0700 (PDT) X-Received: by 10.25.207.82 with SMTP id f79mr9905452lfg.73.1444736561380; Tue, 13 Oct 2015 04:42:41 -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.59.35 with SMTP id w3csp2078316lbq; Tue, 13 Oct 2015 04:42:40 -0700 (PDT) X-Received: by 10.140.43.70 with SMTP id d64mr38193274qga.11.1444736560201; Tue, 13 Oct 2015 04:42:40 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b27si2442872qkb.9.2015.10.13.04.42.39; Tue, 13 Oct 2015 04:42:40 -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 CFA1861A23; Tue, 13 Oct 2015 11:42:39 +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=-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 [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 270BA61B6A; Tue, 13 Oct 2015 11:34:12 +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 CC54B61B5C; Tue, 13 Oct 2015 11:33:54 +0000 (UTC) Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1bon0136.outbound.protection.outlook.com [157.56.111.136]) by lists.linaro.org (Postfix) with ESMTPS id D2D0961A55 for ; Tue, 13 Oct 2015 11:32:08 +0000 (UTC) Received: from CO2PR03CA0028.namprd03.prod.outlook.com (10.141.194.155) by BLUPR03MB485.namprd03.prod.outlook.com (10.141.79.16) with Microsoft SMTP Server (TLS) id 15.1.293.16; Tue, 13 Oct 2015 11:31:50 +0000 Received: from BY2FFO11FD013.protection.gbl (2a01:111:f400:7c0c::198) by CO2PR03CA0028.outlook.office365.com (2a01:111:e400:1414::27) with Microsoft SMTP Server (TLS) id 15.1.286.15 via Frontend Transport; Tue, 13 Oct 2015 11:31:50 +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 BY2FFO11FD013.mail.protection.outlook.com (10.1.14.75) with Microsoft SMTP Server (TLS) id 15.1.293.9 via Frontend Transport; Tue, 13 Oct 2015 11:31:49 +0000 Received: from hongbo.ap.freescale.net (hongbo.ap.freescale.net [10.193.20.96]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t9DBVOFq009638; Tue, 13 Oct 2015 04:31:46 -0700 From: To: Date: Tue, 13 Oct 2015 19:13:12 +0800 Message-ID: <1444734798-29063-9-git-send-email-hongbo.zhang@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444734798-29063-1-git-send-email-hongbo.zhang@freescale.com> References: <1444734798-29063-1-git-send-email-hongbo.zhang@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD013; 1:oudKZgrTjDgw3JiHrFKGUQWtX1js6Uql7/50bVsnvLhrh/uqwKIhXMMCgEUi1zbsnhTDXnmRio06xeblW9gl3L5wrbS06LDEghsYIGPskGAU3o9/JvclBjUcfLe7cBpSq2qRj+GP2s53mxiv6Tt0W6z5raozKClRCoG9NI+lnpVWe3guCoFcHjSHoXwh7ExmWS0PwuoO/Fz7n0VklHWQuTEbENunrksVH4gEdISYG+QRUURkX0arP9hT8dhZCQe3vyziz8nlJG7QktNmbRPuk7FQU1Z7lK9+9Mst/Gpu0BN03VaNylwTzEpMzzRB7XSCabxe0SBSDkyIIX/DePapEUONbIdQR5etsRRNVQiSryWkws3vixw24LOqxBL5dAaYcsSBPyYPkxsdLMI6weETMQ== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(50226001)(87936001)(85426001)(19580405001)(106466001)(77096005)(2351001)(6806005)(229853001)(105606002)(189998001)(92566002)(19580395003)(104016004)(76176999)(36756003)(2950100001)(86362001)(11100500001)(5001960100002)(50986999)(5003940100001)(48376002)(110136002)(5001920100001)(86152002)(50466002)(64706001)(33646002)(5007970100001)(97736004)(81156007)(46102003)(5008740100001)(47776003)(41533002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR03MB485; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1;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v0ZPM/4fbzyj+8BRDI230eeLwRZdSJcZSSOtb7aQbEnSa0X1ahjfdor5DnPyEp3iYo8cK2wMA8ttSWy2R5HRUwbo=; 4:G/5xBr9gNe01V7645Ab9eBopLb7wRkwu/LAaxLfeLFjNqJ2mBE01crQKExILamX17FhNvsyl7aeM9jQEAm+or9JviCCo/9yo83rjUUVHZPij8ShEzcNj+KLD1d49/Bj8aHTmkhfmEr7dmESHg/I3ODt5vDHioKB1TwqYq6KUIlg2WKw63fln++dcJCsZjNne64fLV2IvDesfkhtorllr1BeudeSNn9W+mIOzL1/MJ3KKfNmfhTycR7mHQc4DO3Y171gYHhtHwRebf3/2aC4IlQXVGpPDCAwiv5DyOFUlo0qQeeQNhbAB6/8I9OqnK43L8AyI8B2nENzMEuWzZuj8xHxyh+QLGVjBfZAeC4CVfsY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(3002001); SRVR:BLUPR03MB485; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB485; X-Forefront-PRVS: 07283408BE X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR03MB485; 23:gT0R7msPKPLkDCloHcBt/gPVGdeDHzbqnP3WzQ3O/Z?= =?us-ascii?Q?0ihFBPIELOTlpKpihKcne3cTarjH/tzb29A6Edhga00SqTGwQXxIE+lJkVTn?= =?us-ascii?Q?tYEacav2FY9IWxLoeCb6o+CKTZVXLpY2IPU3CinOA7BTLOhgjjq2DJJxAOQ+?= =?us-ascii?Q?zFyMSMmsE0l5ZjGAvWwBdhS94IabxwuofNPhaKJhWr6APf5SR3fKmNBNzBh8?= =?us-ascii?Q?BxunhB2H6jOfepF9MQmTP8mCNJ+8PeCaG2AjxbvL5OGWRzbR2WFw/D3s9q5l?= =?us-ascii?Q?olVxO9c1dGUAVV6eGeQftGAa62xaZBHG8Nx9iMTQiW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D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB485; 5:p0JEif+4AudPdnmo4ZCuLFztnaUpPQmSzayYYDZTekPFmm5RceSlxpjHuRKqPJkAN6vYB+hcPeZW3LcdGkNepQoR3xomEU5qTqLtY5XAGbkJG9ZW0g1avPMlaiX4ayCl427sZwy0vk2Tix4937Dt0Q==; 24:LSiWBT5sqLKt2WRuVv6o7OzTwLo/DpuhND9D6qSjLOXhw/D6jA9Wg8nEs7MKJdcvPhvCmFyt913UAFBDEhbzKBTyqOiSl2wEs5vJrAFunHI=; 20:7b9ddf+xtQdpqYvxPMW7lbM5plBICfXHHgYah0XVo1BybqRRSfa1E2/xd/F/jCYfZjlIUfjdGKhV8EM5WhBXZw== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2015 11:31:49.8154 (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: BLUPR03MB485 X-Topics: patch Cc: petri.savolainen@nokia.com, stuart.haslam@arm.com Subject: [lng-odp] [API NEXT PATCH v7 08/14] linux-generic: sysinfo: revise odp_cpu_hz() to return current 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.mailfrom=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 The odp_cpu_hz_max() is added to returm maximum frequency of CPU, while the odp_cpu_hz(), as shown by its name, should return current frequency of CPU, this patch revise odp_cpu_hz() for this purpose. Signed-off-by: Hongbo Zhang --- platform/linux-generic/odp_system_info.c | 56 +++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index cff6d65..385a7d0 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -143,6 +143,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) { + if (sscanf(pos, "processor : %d", &cpu) == 1) + if (cpu == id) + break; + } + } + + /* extract the cpu current speed */ + while (fgets(str, sizeof(str), file) != NULL) { + pos = strstr(str, "cpu MHz"); + if (pos) { + if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1) + 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, @@ -151,6 +187,11 @@ odp_system_info_t *sysinfo ODP_UNUSED) return 0; } +static uint64_t arch_cpu_hz_current(int id ODP_UNUSED) +{ + return -1; +} + #elif defined __OCTEON__ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) @@ -192,6 +233,12 @@ static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo) return 0; } + +static uint64_t arch_cpu_hz_current(int id ODP_UNUSED) +{ + return -1; +} + #elif defined __powerpc__ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) { @@ -233,6 +280,11 @@ static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo) return 0; } +static uint64_t arch_cpu_hz_current(int id ODP_UNUSED) +{ + return -1; +} + #else #error GCC target not found #endif @@ -365,7 +417,9 @@ int odp_system_info_init(void) */ uint64_t odp_cpu_hz(void) { - return odp_global_data.system_info.cpu_hz[0]; + int id = sched_getcpu(); + + return arch_cpu_hz_current(id); } uint64_t odp_cpu_hz_max(void)