From patchwork Fri Apr 28 12:09:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 98359 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp233902qgf; Fri, 28 Apr 2017 05:16:35 -0700 (PDT) X-Received: by 10.36.79.6 with SMTP id c6mr9302123itb.45.1493381795634; Fri, 28 Apr 2017 05:16:35 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e200si6841349ite.89.2017.04.28.05.16.35; Fri, 28 Apr 2017 05:16:35 -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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1F1CA62B67; Fri, 28 Apr 2017 12:16:35 +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=-4.7 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 8073062C2B; Fri, 28 Apr 2017 12:12:06 +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 7FB0962B68; Fri, 28 Apr 2017 12:11:36 +0000 (UTC) Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30105.outbound.protection.outlook.com [40.107.3.105]) by lists.linaro.org (Postfix) with ESMTPS id D1A2362BC4 for ; Fri, 28 Apr 2017 12:11:11 +0000 (UTC) Received: from AM4PR07CA0019.eurprd07.prod.outlook.com (2603:10a6:205:1::32) by AM2PR07MB0899.eurprd07.prod.outlook.com (2a01:111:e400:8428::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1075.1; Fri, 28 Apr 2017 12:11:10 +0000 Received: from VE1EUR03FT033.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::200) by AM4PR07CA0019.outlook.office365.com (2603:10a6:205:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1075.1 via Frontend Transport; Fri, 28 Apr 2017 12:11:10 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning linaro.org discourages use of 131.228.2.240 as permitted sender) Received: from mailrelay.int.nokia.com (131.228.2.240) by VE1EUR03FT033.mail.protection.outlook.com (10.152.18.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1047.9 via Frontend Transport; Fri, 28 Apr 2017 12:11:09 +0000 Received: from fihe3nok0734.emea.nsn-net.net (localhost [127.0.0.1]) by fihe3nok0734.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id v3SC9wdG001682 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 28 Apr 2017 15:09:58 +0300 Received: from 10.144.19.15 ([10.144.104.219]) by fihe3nok0734.emea.nsn-net.net (8.14.9/8.14.5) with ESMTP id v3SC9wn9001645 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NOT) for ; Fri, 28 Apr 2017 15:09:58 +0300 X-HPESVCS-Source-Ip: 10.144.104.219 From: Petri Savolainen To: Date: Fri, 28 Apr 2017 15:09:58 +0300 Message-ID: <20170428120958.17526-12-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170428120958.17526-1-petri.savolainen@linaro.org> References: <20170428120958.17526-1-petri.savolainen@linaro.org> X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:131.228.2.240; IPV:CAL; CTRY:FI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(39450400003)(39840400002)(39860400002)(39400400002)(39410400002)(39850400002)(2980300002)(189002)(199003)(9170700003)(81166006)(76176999)(2906002)(50986999)(47776003)(22756006)(110136004)(36756003)(86362001)(48376002)(5660300001)(356003)(6916009)(2950100002)(305945005)(8676002)(2351001)(77096006)(189998001)(5003940100001)(1076002)(106466001)(50226002)(105596002)(50466002)(38730400002)(53936002)(33646002)(8936002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM2PR07MB0899; H:mailrelay.int.nokia.com; FPR:; SPF:SoftFail; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; VE1EUR03FT033; 1:EbXIeZOkx/KxG6wjDnyx7uK0nQnaR4pLMGVKlmlUdv2FeU3asTT6w3cqZ7ss9StmarLbGbOtDaM00o0yQ+YpqrOITF8Vv7OL57vRTlhQ00Ve4+z1xND+39vI7bh1n2cvCeIzcP+7LsTGU0WLdjOQW9d9Gbt+JRWQx4DQmzOilSUE3MU+iFsJHweJRKfi77xSJwXYSQukv7lefwpHRnyBIeQ7h0uD8EtLywW3GzIi1HAQBh/Xku+HBtqeY8cZEgEzR3hxIlRboJR07K2TsGtuzuHIJgUS/sUDdFtWPQ8KX9RpkfZzNxjkPp98A1U0VQvsNdfPIfDQBR1FRcD2sRT12zLUqJYV436sB0M2L95HjwOGvT3fQfO42I7YZGtZlYm/UypIzyhFVRBkRDGdCL3x/e9y3MfmXCAKN1U+qTRz6MjalfsmcWlHw930MQ9rRwT1GO2lBblVOYzwsppetbmD05Gny/fRGLGRiR/OpnTPGF5KBRqyWwRGGvmKMFd552SSn469snr9m/EBbNhjVAMEbw== MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: acf92fac-3a73-4a33-6b4b-08d48e2fa806 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(201703131423075)(201703031133081); SRVR:AM2PR07MB0899; X-Microsoft-Exchange-Diagnostics: 1; AM2PR07MB0899; 3:B+JrdO4AQ9iyEjTh9W9DTdP/lux06DSCXgo6pGCcfNdAvClP32hwdc5A+JgBgVSC1Ki4ShaHrRZ+IKNTwGZdUNPabm/0hlMoCL0eWlVr3PjVO2yuPZYJRk6mheTDzLjIcJFR4I79XGuZtHcx0wuJHNNKJWs7Yr3XR8yg2Y2E+4zUe14dG4UkYOQ3emTeDfCtFRfHdPXx406pJOe5AAPB2e68IeKMieE9Km8H6kEcBZNGs/YBLWAneKiPtGkIMe4WTOVN++xhFsLFLHvEuiSD5Oxd3TPwraJPpvD1wMKezMu66x7CBsuGslf85IXSMKK8lFI27vEeHlEFEpG7n2jJMQtzvk58iem48wc2dcml98ZZIUBiA5juV83wZ4NZiOYz1S+ila7i9khyF0nREuaFTwM2euGVaxQxPEjv9O+qY9Bvx1LZqP4wNquDixeDnPkhH5FjGpFEHwbUX/EuOsIKwg== X-Microsoft-Exchange-Diagnostics: 1; AM2PR07MB0899; 25:kkJWVaxeEpBmySe5oS0meu3fWktZCBA+0SN2OUp789ME6xlQvk016bmAt78flTvhrrtpacC8BHuVGzL3hKtlLfHvEQQ51rfH+1Zz1r1OvTK8G9RzGdU9zJx8eEW7QIZALXMQMQE50U1tlOKLPIfMvG1Dq1IvMJGdsgzrRN6aK+XyxOHrlTBi0BkUzD2E2vWR4hUMr65w8+br2j1r1RzCt674J2cyVz2+mM6nNSZEStdAZPgnKGPht8R06culF/rCmhFZyOhUvh3dH4wlPtzFN/Q2H+py+/P+v7aqkLAkMRPuVKV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ZC5G8vELzPdmBBj+uAIgpo90EqJnlw22c2N9RtLO322K/oIC8Cr9I8iM= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(13013025)(13021025)(13023025)(3002001)(10201501046)(93006095)(93003095)(6055026)(6041248)(20161123555025)(20161123564025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061750153)(20161123560025)(6072148); SRVR:AM2PR07MB0899; BCL:0; PCL:0; RULEID:; SRVR:AM2PR07MB0899; X-Microsoft-Exchange-Diagnostics: 1; AM2PR07MB0899; 4:Ch0Ba1yisnmVgakM7Jw6S2usEuj03OegxvsKHQ1XBvdtQlQXV0jY0/RL1ZEE39luvyqRuT+s+g8Xri9mfPf+2yHKEo+uBwz5jQhBxzMPXKfXvNm9RzPajGzcF3DPkHEAs5qF0zt8tMQZ6+d3oRazvYLdeYk50q6DKvp263B27kjCO0EI+u4ND4I7+kSro8eK4bHseX7tzNBoOtx5zAoXNPk9M271oag7FmWuVzsCtHEjaNevtQnam5tlB8t/w+uofvoaztUv5kBh94oemb/rooz0qyY2oFlbKqRb6SD7Gv45+aiVsmWeOJTkr4CQgRIyVXgmWhlIu6AugjZuGJ1cMobA9vGxeKDEvOmg7yzp5mLM3NB9T1ITmuYUOyFIk6OXyVnWKhpgMA4Ej5ZFNFu+vz47XMoF9bp0oKK4W0yErEPF5jYi4fUtnZMNTP5NsGiNiD8zqwlzAJdN4RGhGO3ZSK8LzXubArHzJSd0+y03Y00cDhqHHKdKfz+9i0m9JPlzY8eoeMnioWB7XMY4o1DoaxtJ+2M7NR7qzEtSTKZrfldwGyodDtp9P7Lvczv8R1sCjBOva5j1lxx/ZAwRY4MDZbSwf4iWDbp5kqqmCeJwCyDFpeh99KLLWurFLtc2b7TIAnrAtTzykqLDvLDzrrLXzwBsl82UiSECRDnuvI4f1ER9FXyFIxpzX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yu6SCXXM8Yt5fdB2i9vp40BRhA9Lu9dO69uHnSy/Ge1tHlkk/C+xdv22JzaXuNzxW38= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM2PR07MB0899; 7:r5kXtnf673HbD3zpzz6vjzaIt4maDrRgFyynaAoXc4Hp6LZ1WsxdbF0cmMxYpLYcpynmlv++ccdEC1wQ42RkUZTAdTC8nf4htU1M9deEI+qrzgNILNBgF6plZNPwLWz6neU3Mf6cXsropu5562GyBATBvmHs98m8P+PBeu3Y+XqHNES0Vc8pMkkuSf29O8mwO/jNpxaM0gvoRfLMRPncWxhYfsvj9Ckl+UT4l5L3UwhjzJkFB7QXSzir2WDcki4jBIQV2d4RYUTnrM2axMC4MtKS9LPwRbMHI7JfDKLm4NGy9NBYnp30+iIWJZD08xUdmVoPoN2tlATc5LXyN29FSw== X-OriginatorOrg: nokia.onmicrosoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2017 12:11:09.7963 (UTC) X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5d471751-9675-428d-917b-70f44f9630b0; Ip=[131.228.2.240]; Helo=[mailrelay.int.nokia.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR07MB0899 Subject: [lng-odp] [API-NEXT PATCH v3 11/11] linux-gen: time: store timespec as nsec X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Use single 64 bit nanosecond value to store time when using posix time. Posix time stamp is converted directly from timespec (sec + nsec) to nsec time. Storage space for odp_time_t is halved as both posix and HW time use single u64. Some functions (sum, diff, cmp) are generic for both time sources. Signed-off-by: Petri Savolainen --- .../include/odp/api/plat/time_types.h | 32 ++--- platform/linux-generic/odp_time.c | 143 ++++++--------------- 2 files changed, 52 insertions(+), 123 deletions(-) -- 2.11.0 diff --git a/platform/linux-generic/include/odp/api/plat/time_types.h b/platform/linux-generic/include/odp/api/plat/time_types.h index 1cafb1f7..71e354e6 100644 --- a/platform/linux-generic/include/odp/api/plat/time_types.h +++ b/platform/linux-generic/include/odp/api/plat/time_types.h @@ -22,32 +22,24 @@ extern "C" { **/ /** - * @internal Time structure used to isolate odp-linux implementation from - * the linux timespec structure, which is dependent on POSIX extension level. + * @internal Time structure used for both POSIX timespec and HW counter + * implementations. */ typedef struct odp_time_t { union { - /** @internal Posix timespec */ - struct { - /** @internal Seconds */ - int64_t tv_sec; - - /** @internal Nanoseconds */ - int64_t tv_nsec; - } spec; - - /** @internal HW time counter */ - struct { - /** @internal Counter value */ - uint64_t count; - - /** @internal Reserved */ - uint64_t reserved; - } hw; + /** @internal Used with generic 64 bit operations */ + uint64_t u64; + + /** @internal Nanoseconds */ + uint64_t nsec; + + /** @internal HW timer counter value */ + uint64_t count; + }; } odp_time_t; -#define ODP_TIME_NULL ((odp_time_t){.spec = {0, 0} }) +#define ODP_TIME_NULL ((odp_time_t){.u64 = 0}) /** * @} diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index ac82175d..2bbe5666 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -15,10 +15,10 @@ #include typedef struct time_global_t { - odp_time_t start_time; - int use_hw; - uint64_t hw_start; - uint64_t hw_freq_hz; + struct timespec spec_start; + int use_hw; + uint64_t hw_start; + uint64_t hw_freq_hz; } time_global_t; static time_global_t global; @@ -27,19 +27,23 @@ static time_global_t global; * Posix timespec based functions */ -static inline odp_time_t time_spec_diff(odp_time_t t2, odp_time_t t1) +static inline uint64_t time_spec_diff_nsec(struct timespec *t2, + struct timespec *t1) { - odp_time_t time; + struct timespec diff; + uint64_t nsec; - time.spec.tv_sec = t2.spec.tv_sec - t1.spec.tv_sec; - time.spec.tv_nsec = t2.spec.tv_nsec - t1.spec.tv_nsec; + diff.tv_sec = t2->tv_sec - t1->tv_sec; + diff.tv_nsec = t2->tv_nsec - t1->tv_nsec; - if (time.spec.tv_nsec < 0) { - time.spec.tv_nsec += ODP_TIME_SEC_IN_NS; - --time.spec.tv_sec; + if (diff.tv_nsec < 0) { + diff.tv_nsec += ODP_TIME_SEC_IN_NS; + diff.tv_sec -= 1; } - return time; + nsec = (diff.tv_sec * ODP_TIME_SEC_IN_NS) + diff.tv_nsec; + + return nsec; } static inline odp_time_t time_spec_cur(void) @@ -52,10 +56,9 @@ static inline odp_time_t time_spec_cur(void) if (odp_unlikely(ret != 0)) ODP_ABORT("clock_gettime failed\n"); - time.spec.tv_sec = sys_time.tv_sec; - time.spec.tv_nsec = sys_time.tv_nsec; + time.nsec = time_spec_diff_nsec(&sys_time, &global.spec_start); - return time_spec_diff(time, global.start_time); + return time; } static inline uint64_t time_spec_res(void) @@ -70,48 +73,16 @@ static inline uint64_t time_spec_res(void) return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec; } -static inline int time_spec_cmp(odp_time_t t2, odp_time_t t1) -{ - if (t2.spec.tv_sec < t1.spec.tv_sec) - return -1; - - if (t2.spec.tv_sec > t1.spec.tv_sec) - return 1; - - return t2.spec.tv_nsec - t1.spec.tv_nsec; -} - -static inline odp_time_t time_spec_sum(odp_time_t t1, odp_time_t t2) -{ - odp_time_t time; - - time.spec.tv_sec = t2.spec.tv_sec + t1.spec.tv_sec; - time.spec.tv_nsec = t2.spec.tv_nsec + t1.spec.tv_nsec; - - if (time.spec.tv_nsec >= (long)ODP_TIME_SEC_IN_NS) { - time.spec.tv_nsec -= ODP_TIME_SEC_IN_NS; - ++time.spec.tv_sec; - } - - return time; -} - static inline uint64_t time_spec_to_ns(odp_time_t time) { - uint64_t ns; - - ns = time.spec.tv_sec * ODP_TIME_SEC_IN_NS; - ns += time.spec.tv_nsec; - - return ns; + return time.nsec; } static inline odp_time_t time_spec_from_ns(uint64_t ns) { odp_time_t time; - time.spec.tv_sec = ns / ODP_TIME_SEC_IN_NS; - time.spec.tv_nsec = ns - time.spec.tv_sec * ODP_TIME_SEC_IN_NS; + time.nsec = ns; return time; } @@ -124,7 +95,7 @@ static inline odp_time_t time_hw_cur(void) { odp_time_t time; - time.hw.count = cpu_global_time() - global.hw_start; + time.count = cpu_global_time() - global.hw_start; return time; } @@ -136,40 +107,11 @@ static inline uint64_t time_hw_res(void) return global.hw_freq_hz / 10; } -static inline int time_hw_cmp(odp_time_t t2, odp_time_t t1) -{ - if (odp_likely(t2.hw.count > t1.hw.count)) - return 1; - - if (t2.hw.count < t1.hw.count) - return -1; - - return 0; -} - -static inline odp_time_t time_hw_diff(odp_time_t t2, odp_time_t t1) -{ - odp_time_t time; - - time.hw.count = t2.hw.count - t1.hw.count; - - return time; -} - -static inline odp_time_t time_hw_sum(odp_time_t t1, odp_time_t t2) -{ - odp_time_t time; - - time.hw.count = t1.hw.count + t2.hw.count; - - return time; -} - static inline uint64_t time_hw_to_ns(odp_time_t time) { uint64_t nsec; uint64_t freq_hz = global.hw_freq_hz; - uint64_t count = time.hw.count; + uint64_t count = time.count; uint64_t sec = 0; if (count >= freq_hz) { @@ -197,8 +139,7 @@ static inline odp_time_t time_hw_from_ns(uint64_t ns) count = sec * freq_hz; count += (ns * freq_hz) / ODP_TIME_SEC_IN_NS; - time.hw.reserved = 0; - time.hw.count = count; + time.count = count; return time; } @@ -225,26 +166,22 @@ static inline uint64_t time_res(void) static inline int time_cmp(odp_time_t t2, odp_time_t t1) { - if (global.use_hw) - return time_hw_cmp(t2, t1); - - return time_spec_cmp(t2, t1); -} + if (odp_likely(t2.u64 > t1.u64)) + return 1; -static inline odp_time_t time_diff(odp_time_t t2, odp_time_t t1) -{ - if (global.use_hw) - return time_hw_diff(t2, t1); + if (t2.u64 < t1.u64) + return -1; - return time_spec_diff(t2, t1); + return 0; } static inline odp_time_t time_sum(odp_time_t t1, odp_time_t t2) { - if (global.use_hw) - return time_hw_sum(t1, t2); + odp_time_t time; + + time.u64 = t1.u64 + t2.u64; - return time_spec_sum(t1, t2); + return time; } static inline uint64_t time_to_ns(odp_time_t time) @@ -284,7 +221,11 @@ odp_time_t odp_time_global(void) odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) { - return time_diff(t2, t1); + odp_time_t time; + + time.u64 = t2.u64 - t1.u64; + + return time; } uint64_t odp_time_to_ns(odp_time_t time) @@ -338,7 +279,6 @@ void odp_time_wait_until(odp_time_t time) int odp_time_init_global(void) { - struct timespec sys_time; int ret = 0; memset(&global, 0, sizeof(time_global_t)); @@ -357,13 +297,10 @@ int odp_time_init_global(void) return 0; } - global.start_time = ODP_TIME_NULL; + global.spec_start.tv_sec = 0; + global.spec_start.tv_nsec = 0; - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &sys_time); - if (ret == 0) { - global.start_time.spec.tv_sec = sys_time.tv_sec; - global.start_time.spec.tv_nsec = sys_time.tv_nsec; - } + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &global.spec_start); return ret; }