From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id BCD7BA0352; Tue, 17 Dec 2019 01:55:18 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D380B1D9E; Tue, 17 Dec 2019 01:55:17 +0100 (CET) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by dpdk.org (Postfix) with ESMTP id A8BD7235 for ; Tue, 17 Dec 2019 01:55:15 +0100 (CET) Received: by mail-pl1-f193.google.com with SMTP id az3so5250820plb.11 for ; Mon, 16 Dec 2019 16:55:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H8VD6i/6uIalacjjYaOVCqQ0LDqsIUdwfRjqdoycY4c=; b=00gt5XE9/0JNyVGnsrgk8LC77GnPG9fw4STsmLa84sy4QNmLkTL5JuGJRoHawf5jNf wOy1VYpLxudh8dqrDbLLTCWIlrogjAE1ulxjVy3UgvAR5R9za0yW0One/Yp+kfLL5qIO Z1QOrJ/AN8DALtsccMsQkbB35NOepRkAl9+hCreNOuzr4O+h6Mjf5EvLGCXMeOTYbs6u 6lgjnEz5YmLQeo5ph7b+TU//dHxWh/JX8Snm+izsWpelGbIdBrgIBx7WTQION/Sbfunb BCQpzE/BnLKL+eeGTAnFrALgs/80TjbsZ7+qLMnLanf5j9gTVzM11rfJ5ouokp2xW3xp 06Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H8VD6i/6uIalacjjYaOVCqQ0LDqsIUdwfRjqdoycY4c=; b=YrwwsQPbkGuYZQooDHS5ogaPa/UdF/5+RY6hmS/p5mVUJ9acllic3W2NlG6KDWxfTp Ec1WAn9Sn9KDZu28qIPulBws+JZH+OgMdnpvCV5A9FawjlgLvFkwa6JYstGRWSnLULur synETEkERF3ZusFl8WKglEQTXUDgKgmbpK+23rr3UUWtH7IaVvulwR3lqhHcw7Obi6i9 2TYwiYDDFVwVWyqh4oCC16BjGtmukUYxYUHVa/HwPTGFVjUs/ynyvSbKwIQQvQOnbxGY fyTJbNDeG5+Xp1wLwhK1UzX/wKO0jRXt42LqvzSjSlkKrZhCu5JYF1ptOFNilqLlZAIj roSg== X-Gm-Message-State: APjAAAVO0aa65t6rO1SMzPry31WZXxGhsl3n0TNQYNLp91tPt+jNWwCd CXBmtAyqCtj0rYXu6Zyhrl0uXQlh+YoQ1A== X-Google-Smtp-Source: APXvYqyh7jmi3Beg30yTwYJhYYqTkPmS/hlkLNDKVLJXckTG/8iUL4oh20qqsTOe4eIDtc+nG+k71Q== X-Received: by 2002:a17:902:70cb:: with SMTP id l11mr19927628plt.216.1576544114046; Mon, 16 Dec 2019 16:55:14 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id l1sm24301778pgs.47.2019.12.16.16.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 16:55:13 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: erik.g.carrillo@intel.com, Stephen Hemminger Date: Mon, 16 Dec 2019 16:55:03 -0800 Message-Id: <20191217005503.31196-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190610224441.5461-1-stephen@networkplumber.org> References: <20190610224441.5461-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v1] rte_timer: add rte_timer_next_ticks X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" It is useful to know when the next timer will expire when using rte_epoll_wait (or sleep when idle). This experimental API provides a hook to query the number of ticks remaining. Signed-off-by: Stephen Hemminger --- v1 - incorporate feedback from old RFC lib/librte_timer/rte_timer.c | 27 ++++++++++++++++++++++++++ lib/librte_timer/rte_timer.h | 16 +++++++++++++++ lib/librte_timer/rte_timer_version.map | 1 + 3 files changed, 44 insertions(+) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index ca88454ff68a..a1ed186cf591 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -978,6 +978,33 @@ rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores, return 0; } +int64_t +rte_timer_next_ticks(void) +{ + unsigned int lcore_id = rte_lcore_id(); + struct rte_timer_data *timer_data; + struct priv_timer *priv_timer; + const struct rte_timer *tm; + uint64_t cur_time; + int64_t left = -ENOENT; + + TIMER_DATA_VALID_GET_OR_ERR_RET(default_data_id, timer_data, -EINVAL); + + priv_timer = timer_data->priv_timer; + cur_time = rte_get_timer_cycles(); + + rte_spinlock_lock(&priv_timer[lcore_id].list_lock); + tm = priv_timer[lcore_id].pending_head.sl_next[0]; + if (tm) { + left = tm->expire - cur_time; + if (left < 0) + left = 0; + } + rte_spinlock_unlock(&priv_timer[lcore_id].list_lock); + + return left; +} + /* dump statistics about timers */ static void __rte_timer_dump_stats(struct rte_timer_data *timer_data __rte_unused, FILE *f) diff --git a/lib/librte_timer/rte_timer.h b/lib/librte_timer/rte_timer.h index 9dc5fc309249..c5031d0448ba 100644 --- a/lib/librte_timer/rte_timer.h +++ b/lib/librte_timer/rte_timer.h @@ -331,6 +331,22 @@ void rte_timer_stop_sync(struct rte_timer *tim); */ int rte_timer_pending(struct rte_timer *tim); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Time until the next timer + * This function gives the ticks until the next timer will be active. + * + * @return + * - -EINVAL: invalid timer data instance identifier + * - -ENOENT: no timer pending + * - 0: a timer is pending and will run at next rte_timer_manage() + * - >0: ticks until the next timer is ready + */ +__rte_experimental +int64_t rte_timer_next_ticks(void); + /** * Manage the timer list and execute callback functions. * diff --git a/lib/librte_timer/rte_timer_version.map b/lib/librte_timer/rte_timer_version.map index 2a59d3f081c4..4471cef92be5 100644 --- a/lib/librte_timer/rte_timer_version.map +++ b/lib/librte_timer/rte_timer_version.map @@ -23,6 +23,7 @@ EXPERIMENTAL { rte_timer_alt_stop; rte_timer_data_alloc; rte_timer_data_dealloc; + rte_timer_next_ticks; rte_timer_stop_all; rte_timer_subsystem_finalize; }; -- 2.20.1