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 1D4F1A00E6 for ; Wed, 12 Jun 2019 20:19:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A686E1D01F; Wed, 12 Jun 2019 20:19:14 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 564321CFE3 for ; Wed, 12 Jun 2019 20:19:12 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2019 11:19:11 -0700 X-ExtLoop1: 1 Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga006.jf.intel.com with ESMTP; 12 Jun 2019 11:19:10 -0700 Received: from fmsmsx119.amr.corp.intel.com (10.18.124.207) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 12 Jun 2019 11:19:10 -0700 Received: from fmsmsx115.amr.corp.intel.com ([169.254.4.97]) by FMSMSX119.amr.corp.intel.com ([169.254.14.107]) with mapi id 14.03.0415.000; Wed, 12 Jun 2019 11:19:09 -0700 From: "Carrillo, Erik G" To: Stephen Hemminger , "rsanford@akamai.com" CC: "dev@dpdk.org" Thread-Topic: [RFC] rte_timer: add rte_timer_next_ticks Thread-Index: AQHVH94khe3v6/L8vEuV8dBvYvxAMaaYPqFw Date: Wed, 12 Jun 2019 18:19:09 +0000 Message-ID: References: <20190610224441.5461-1-stephen@networkplumber.org> In-Reply-To: <20190610224441.5461-1-stephen@networkplumber.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMWEzNjZjMzctMGZjNy00ZGQ1LWI0MTgtZjA5OTU2YWZjZmY3IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiVWJcL09tT21XYUN1ZnlqdExycXhvU2Ntd0cwQWJIR0NmMVpcLzd4Zm0xUzhpZmZ1cGZpbUZlS295Nm5tNkV4dldhIn0= x-ctpclassification: CTP_NT x-originating-ip: [10.1.200.106] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [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" Hi Stephen, This looks like a useful addition. Some comments in-line: > -----Original Message----- > From: Stephen Hemminger > Sent: Monday, June 10, 2019 5:45 PM > To: rsanford@akamai.com; Carrillo, Erik G > Cc: dev@dpdk.org; Stephen Hemminger > Subject: [RFC] rte_timer: add rte_timer_next_ticks >=20 > 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 hoo= k > to query the number of ticks remaining. >=20 > 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(+) >=20 > 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; > } >=20 > +int64_t __rte_experimental > +rte_timer_next_ticks(void) > +{ > + struct priv_timer *priv_timer =3D default_timer_data.priv_timer; The timer data instance used above is used by the legacy API. We should do= something like the following instead: --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -1035,15 +1035,24 @@ rte_timer_stop_all(uint32_t timer_data_id, unsigned= int *walk_lcores, int64_t __rte_experimental rte_timer_next_ticks(void) { - struct priv_timer *priv_timer =3D default_timer_data.priv_timer; + struct priv_timer *priv_timer; + struct rte_timer_data *timer_data; unsigned int lcore_id =3D rte_lcore_id(); uint64_t cur_time =3D rte_get_timer_cycles(); const struct rte_timer *tm; int64_t left =3D -1; =20 + TIMER_DATA_VALID_GET_OR_ERR_RET(default_data_id, timer_data, -EINVA= L); + priv_timer =3D timer_data->priv_timer; This will select the correct instance that was allocated in shared memory. > + unsigned int lcore_id =3D rte_lcore_id(); > + uint64_t cur_time =3D rte_get_timer_cycles(); > + const struct rte_timer *tm; > + int64_t left =3D -1; > + > + rte_spinlock_lock(&priv_timer[lcore_id].list_lock); > + tm =3D priv_timer[lcore_id].pending_head.sl_next[0]; > + if (tm) { > + left =3D tm->expire - cur_time; > + if (left < 0) > + left =3D 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); >=20 > +/** This comment is missing the "@warning" and "@b EXPERIMENTAL" lines. > + * Time until the next timer > + * > + * This function gives the interval until the next timer s/interval/interval in ticks/ ? > + * will be active. > + * > + * @return > + * 0: A timer is already pending I would say "The next timer has already expired" or "A timer is already run= ning" here... the timer library describes timers that have been started but= have not yet expired as "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 Thanks, Erik