From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 0785EA00E6 for ; Tue, 11 Jun 2019 00:44:51 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4EE461C1B7; Tue, 11 Jun 2019 00:44:51 +0200 (CEST) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by dpdk.org (Postfix) with ESMTP id A6AE01C1AA for ; Tue, 11 Jun 2019 00:44:50 +0200 (CEST) Received: by mail-pl1-f195.google.com with SMTP id i2so4223069plt.1 for ; Mon, 10 Jun 2019 15:44:50 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=Vv5P7VSV7MtZW0gpeD8tDjMAsuGXqaMozSl6saENXvk=; b=pL9RDzUxqINaXnsXeP3CdCELRDudRoUx1yFAJpahuSqce0ibOjuN8c7CeQ3iY185pr Sbv2M+Jt1W8Sp2PaR+O6dvpcL+DpOB1pg7P2MYM7u0UC8hg/RpCG2ez4Rk2Rn413U1Lm DG/61LO9aXArlgj/X1ggGG+ySh6RxClaAbSC3YjaCV37rk7k7r2mHksmdJiohPADYJOo TMjN97mtWepbpl1WOYbQ300wlOBDu7/7K+5kKQLhkxGqU0X21K33D0xAsTT1WaZ0PyZZ 2tF2gMdWGAyJCuQ4Vk16FmRh7KQbeMz3dKtQhTQcaVQiAS1vxZafl5Z8KEPp8TzU6/Dy ItKw== 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:mime-version :content-transfer-encoding; bh=Vv5P7VSV7MtZW0gpeD8tDjMAsuGXqaMozSl6saENXvk=; b=f5zXjgQrSj+Ezbop1xsic/52NCDu9/3OfGedKy3oj1e9COTdZsOS29GYl89shpKk2R O/J0iu9xWrNDCIoZ/PZ14QXVwWytZe5452Cujxq06zHIEmYAyE6tOkCuEn5IolQZp8lr ML6Vfyf23Vx5KAdSv74+VDV3Sf0YT6GJHGjbWshtG1Mp8YOzAOX6TkKa2uykW4k9sUFw 4bkMlytY6Dq3nLnAZYBbi5QiaDk3sDmbiKI9fiS+YLuOLD+LOpyCJbOmXv1Z7QxBqofF Rh+PffMpnywnmWJ7waHvGWgz3sDZmD2NRZ6T+2hzGvArvVriSVNMaUIJEJyxkVJAtM7C hMPw== X-Gm-Message-State: APjAAAXjzxerPSXeqszJaABJ5Q6BXLW3Q/MItObkeDIkxY0/s7/KHFsn cvxM9g6EwcdqAjCeDHlTqovoZw== X-Google-Smtp-Source: APXvYqwtI1h6dkMRSSCGD2GYnU4x1jKvzgyEcSKorG007+Msrm7dDfMtGIHZ6jOlvt7ktoxLAHbfDg== X-Received: by 2002:a17:902:f087:: with SMTP id go7mr46727484plb.330.1560206689683; Mon, 10 Jun 2019 15:44:49 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id o192sm12576253pgo.74.2019.06.10.15.44.48 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 10 Jun 2019 15:44:49 -0700 (PDT) From: Stephen Hemminger To: rsanford@akamai.com, erik.g.carrillo@intel.com Cc: dev@dpdk.org, Stephen Hemminger Date: Mon, 10 Jun 2019 15:44:41 -0700 Message-Id: <20190610224441.5461-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [RFC] 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 --- lib/librte_timer/rte_timer.c | 21 +++++++++++++++++++++ lib/librte_timer/rte_timer.h | 14 ++++++++++++++ lib/librte_timer/rte_timer_version.map | 1 + 3 files changed, 36 insertions(+) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index dd795392244c..e9bd3c845470 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -1032,6 +1032,27 @@ rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores, return 0; } +int64_t __rte_experimental +rte_timer_next_ticks(void) +{ + struct priv_timer *priv_timer = default_timer_data.priv_timer; + unsigned int lcore_id = rte_lcore_id(); + uint64_t cur_time = rte_get_timer_cycles(); + const struct rte_timer *tm; + int64_t left = -1; + + 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 2196934b2e29..1c1d3cfd6d4f 100644 --- a/lib/librte_timer/rte_timer.h +++ b/lib/librte_timer/rte_timer.h @@ -338,6 +338,20 @@ void rte_timer_stop_sync(struct rte_timer *tim); */ int rte_timer_pending(struct rte_timer *tim); +/** + * Time until the next timer + * + * This function gives the interval until the next timer + * will be active. + * + * @return + * 0: A timer is already pending + * -1: No timer is pending + * otherwise ticks until the next timer. + */ +int64_t __rte_experimental +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 72f75c818134..d64400bcc7bd 100644 --- a/lib/librte_timer/rte_timer_version.map +++ b/lib/librte_timer/rte_timer_version.map @@ -33,6 +33,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