From patchwork Mon Mar 10 13:35:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 25968 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5D0AD2055F for ; Mon, 10 Mar 2014 13:34:18 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf28576784oag.8 for ; Mon, 10 Mar 2014 06:34:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type; bh=E5epfxzzfM8YeEBzxPz4Zjts44dZF5K6EFPtyhafiKQ=; b=kDVv+y/3cEy5OMDH9Ox0K7kjFNRkXbf85lBUMTJgP3cTqLa2QKgIdDPdw4IBA4gS+j Ogg238IcIKBmBlqod3VTPxvJUG/7v5KRhl4i8aGoFv5vS8cmav0OTn8xjbTv5stUmYbz b9pAuKN+GViZmiu2wYY37+vYqXEDuLGsLBI5DuxiCuqYh5VQgROD/byRvraHk2j6BxNB LFLsrImolW/ql0QvE9kw/1NUd5EqUqxjGN9mBsST81dp3FI0Ky6DRNlmGqz8HET8GYvq d0nLRtwajvDD6nr14vf9vF77WY3blzHUkOzGVrOyWRClc+C44EEvrVSn96NOYZmPMSur p7UA== X-Gm-Message-State: ALoCoQlfrXMwi0kyQmveRb3dqb6cIta+6qtuEkLq1EMIrctgAuBPA5SMP1o866rjdHoeXdTPBlDp X-Received: by 10.182.129.129 with SMTP id nw1mr13354275obb.34.1394458457855; Mon, 10 Mar 2014 06:34:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.140.39.202 with SMTP id v68ls2012729qgv.88.gmail; Mon, 10 Mar 2014 06:34:17 -0700 (PDT) X-Received: by 10.140.20.17 with SMTP id 17mr39046868qgi.28.1394458457632; Mon, 10 Mar 2014 06:34:17 -0700 (PDT) Received: from mail-qg0-f47.google.com (mail-qg0-f47.google.com [209.85.192.47]) by mx.google.com with ESMTPS id 45si9400813qgg.105.2014.03.10.06.34.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Mar 2014 06:34:17 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.47 is neither permitted nor denied by best guess record for domain of petri.savolainen@linaro.org) client-ip=209.85.192.47; Received: by mail-qg0-f47.google.com with SMTP id 63so2013108qgz.6 for ; Mon, 10 Mar 2014 06:34:17 -0700 (PDT) X-Received: by 10.224.165.133 with SMTP id i5mr7723556qay.75.1394458457517; Mon, 10 Mar 2014 06:34:17 -0700 (PDT) Received: from localhost.localdomain (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id k32sm26276628qgf.18.2014.03.10.06.34.14 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Mar 2014 06:34:16 -0700 (PDT) From: Petri Savolainen To: lng-odp@linaro.org Cc: Petri Savolainen Subject: [lng-odp] [PATCH] Timer API first draft Date: Mon, 10 Mar 2014 15:35:37 +0200 Message-Id: <1394458537-7771-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 1.8.5.3 X-Original-Sender: petri.savolainen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.192.47 is neither permitted nor denied by best guess record for domain of petri.savolainen@linaro.org) smtp.mail=petri.savolainen@linaro.org Precedence: list Mailing-list: list lng-odp@linaro.org; contact lng-odp+owners@linaro.org List-ID: X-Google-Group-Id: 474323889996 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Petri Savolainen --- include/odp_timer.h | 139 ++++++++++++++++++++++++++ platform/linux-generic/Makefile | 1 + platform/linux-generic/include/odp_internal.h | 3 + platform/linux-generic/source/odp_init.c | 5 + platform/linux-generic/source/odp_timer.c | 14 +++ 5 files changed, 162 insertions(+) create mode 100644 include/odp_timer.h create mode 100644 platform/linux-generic/source/odp_timer.c diff --git a/include/odp_timer.h b/include/odp_timer.h new file mode 100644 index 0000000..ff54b8e --- /dev/null +++ b/include/odp_timer.h @@ -0,0 +1,139 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +/** + * @file + * + * ODP timer + */ + +#ifndef ODP_TIMER_H_ +#define ODP_TIMER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + + +/** +* ODP timer handle +*/ +typedef uint32_t odp_timer_t; + +#define ODP_TIMER_INVALID 0 + + +/** +* ODP timeout handle +*/ +typedef uint32_t odp_timer_tmo_t; + +#define ODP_TIMER_TMO_INVALID 0 + + +/** + * Create a timer + * + * Creates a new timer with requested properties. + * + * @param name Name + * @param pool Buffer pool for allocating timeout notifications + * @param resolution Timeout resolution in nanoseconds + * @param min_tmo Minimum timeout duration in nanoseconds + * @param max_tmo Maximum timeout duration in nanoseconds + * + * @return Timer handle if successful, otherwise ODP_TIMER_INVALID + */ +odp_timer_t odp_timer_create(const char *name, odp_buffer_pool_t pool, + uint64_t resolution, uint64_t min_tmo, + uint64_t max_tmo); + +/** + * Convert timer ticks to nanoseconds + * + * @param timer Timer + * @param ticks Timer ticks + * + * @return Nanoseconds + */ +uint64_t odp_timer_tick_to_ns(odp_timer_t timer, uint64_t ticks); + +/** + * Convert nanoseconds to timer ticks + * + * @param timer Timer + * @param ns Nanoseconds + * + * @return Timer ticks + */ +uint64_t odp_timer_ns_to_tick(odp_timer_t timer, uint64_t ns); + +/** + * Timer resolution in nanoseconds + * + * @param timer Timer + * + * @return Resolution in nanoseconds + */ +uint64_t odp_timer_resolution(odp_timer_t timer); + +/** + * Maximum timeout in timer ticks + * + * @param timer Timer + * + * @return Maximum timeout in timer ticks + */ +uint64_t odp_timer_maximum_tmo(odp_timer_t timer); + +/** + * Current timer tick + * + * @param timer Timer + * + * @return Current time in timer ticks + */ +uint64_t odp_timer_current_tick(odp_timer_t timer); + +/** + * Request timeout with an absolute timer tick + * + * When tick reaches tmo_tick, the timer enqueues the timeout notification into + * the destination queue. + * + * @param timer Timer + * @param tmo_tick Absolute timer tick value which triggers the timeout + * @param queue Destination queue for the timeout notification + * @param buf User defined timeout notification buffer. When + * ODP_BUFFER_INVALID, default timeout notification is used. + * + * @return Timeout handle if successful, otherwise ODP_TIMER_TMO_INVALID + */ +odp_timer_tmo_t odp_timer_absolute_tmo(odp_timer_t timer, uint64_t tmo_tick, + odp_queue_t queue, odp_buffer_t buf); + +/** + * Cancel a timeout + * + * @param timer Timer + * @param tmo Timeout to cancel + * + * @return 0 if successful + */ +int odp_timer_cancel_tmo(odp_timer_t timer, odp_timer_tmo_t tmo); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/Makefile b/platform/linux-generic/Makefile index c35eb07..9f3e3db 100644 --- a/platform/linux-generic/Makefile +++ b/platform/linux-generic/Makefile @@ -65,6 +65,7 @@ OBJS += $(OBJ_DIR)/odp_system_info.o OBJS += $(OBJ_DIR)/odp_thread.o OBJS += $(OBJ_DIR)/odp_ticketlock.o OBJS += $(OBJ_DIR)/odp_time.o +OBJS += $(OBJ_DIR)/odp_timer.o OBJS += $(OBJ_DIR)/odp_ring.o OBJS += $(OBJ_DIR)/odp_rwlock.o ifeq ($(ODP_HAVE_NETMAP),yes) diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 1f42d2a..ff34b5e 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -43,6 +43,9 @@ int odp_schedule_init_global(void); int odp_schedule_init_local(void); +int odp_timer_init_global(void); + + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/source/odp_init.c b/platform/linux-generic/source/odp_init.c index 1d9cccd..d4c2eb8 100644 --- a/platform/linux-generic/source/odp_init.c +++ b/platform/linux-generic/source/odp_init.c @@ -40,6 +40,11 @@ int odp_init_global(void) return -1; } + if (odp_timer_init_global()) { + ODP_ERR("ODP timer init failed.\n"); + return -1; + } + return 0; } diff --git a/platform/linux-generic/source/odp_timer.c b/platform/linux-generic/source/odp_timer.c new file mode 100644 index 0000000..b090257 --- /dev/null +++ b/platform/linux-generic/source/odp_timer.c @@ -0,0 +1,14 @@ +/* Copyright (c) 2013, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + + +int odp_timer_init_global(void) +{ + return 0; +}