From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id EBF3D3237 for ; Tue, 19 Jul 2016 15:17:42 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP; 19 Jul 2016 06:17:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,389,1464678000"; d="scan'208";a="1009765187" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga001.fm.intel.com with ESMTP; 19 Jul 2016 06:17:28 -0700 Received: from fmsmsx122.amr.corp.intel.com (10.18.125.37) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 19 Jul 2016 06:17:28 -0700 Received: from fmsmsx113.amr.corp.intel.com ([169.254.13.33]) by fmsmsx122.amr.corp.intel.com ([169.254.5.131]) with mapi id 14.03.0248.002; Tue, 19 Jul 2016 06:17:28 -0700 From: "Wiles, Keith" To: "jozmarti@cisco.com" CC: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] rte_delay_us can be replaced with user function Thread-Index: AQHR4bsNEYrvrKxEm0e9RraujWx1NKAgMayA Date: Tue, 19 Jul 2016 13:17:28 +0000 Message-ID: <48BAF571-3AFC-4562-BD24-364CC3BD9642@intel.com> References: <1468932143-9321-1-git-send-email-jozmarti@cisco.com> In-Reply-To: <1468932143-9321-1-git-send-email-jozmarti@cisco.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.254.10.75] Content-Type: text/plain; charset="us-ascii" Content-ID: <985EEBCB99353E4384D02B1E6CCC8CD6@intel.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] rte_delay_us can be replaced with user function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jul 2016 13:17:43 -0000 Hi Jozef, I have two quick comments inline. > On Jul 19, 2016, at 7:42 AM, jozmarti@cisco.com wrote: >=20 > From: Jozef Martiniak >=20 > when running single-core, some drivers tend to call rte_delay_us for a > long time, and that is causing packet drops. > Attached patch introduces 2 new functions: >=20 > void rte_delay_us_callback_register(void(*userfunc)(unsigned)); > void rte_delay_us_callback_unregister(void); >=20 > First one replaces rte_delay_us with userfunc and second one restores > original rte_delay_us. > Test user_delay_us is included. >=20 > Signed-off-by: Jozef Martiniak > --- > app/test/test_cycles.c | 39 +++++++++++++++++= +++++ > lib/librte_eal/common/eal_common_timer.c | 19 +++++++++++ > lib/librte_eal/common/include/generic/rte_cycles.h | 13 ++++++++ > 3 files changed, 71 insertions(+) >=20 > diff --git a/app/test/test_cycles.c b/app/test/test_cycles.c > index f6c043a..2b44a53 100644 > --- a/app/test/test_cycles.c > +++ b/app/test/test_cycles.c > @@ -90,3 +90,42 @@ test_cycles(void) > } >=20 > REGISTER_TEST_COMMAND(cycles_autotest, test_cycles); > + > +/* > + * rte_delay_us_callback test > + * > + * - check if callback is correctly registered/unregistered > + * > + */ > + > +static int pattern; > +static void my_rte_delay_us(unsigned us) > +{ > + pattern +=3D us; > +} > + > +static int > +test_user_delay_us(void) > +{ > + pattern =3D 0; > + > + rte_delay_us_callback_register(my_rte_delay_us); > + > + rte_delay_us(2); > + if (pattern !=3D 2) > + return -1; > + > + rte_delay_us(3); > + if (pattern !=3D 5) > + return -1; > + > + rte_delay_us_callback_unregister(); > + > + rte_delay_us(3); > + if (pattern !=3D 5) > + return -1; > + > + return 0; > +} > + > +REGISTER_TEST_COMMAND(user_delay_us, test_user_delay_us); > diff --git a/lib/librte_eal/common/eal_common_timer.c b/lib/librte_eal/co= mmon/eal_common_timer.c > index c4227cd..a982562 100644 > --- a/lib/librte_eal/common/eal_common_timer.c > +++ b/lib/librte_eal/common/eal_common_timer.c > @@ -47,9 +47,18 @@ > /* The frequency of the RDTSC timer resolution */ > static uint64_t eal_tsc_resolution_hz; >=20 > +/* User function which replaces rte_delay_us function */ > +static void (*rte_delay_us_override)(unsigned) =3D NULL; > + > void > rte_delay_us(unsigned us) > { > + if (unlikely(rte_delay_us_override !=3D NULL)) > + { > + rte_delay_us_override(us); > + return; > + } > + > const uint64_t start =3D rte_get_timer_cycles(); > const uint64_t ticks =3D (uint64_t)us * rte_get_timer_hz() / 1E6; > while ((rte_get_timer_cycles() - start) < ticks) > @@ -84,3 +93,13 @@ set_tsc_freq(void) > RTE_LOG(DEBUG, EAL, "TSC frequency is ~%" PRIu64 " KHz\n", freq / 1000); > eal_tsc_resolution_hz =3D freq; > } > + > +void rte_delay_us_callback_register(void (*userfunc)(unsigned)) > +{ > + rte_delay_us_override =3D userfunc; > +} > + > +void rte_delay_us_callback_unregister(void) > +{ > + rte_delay_us_override =3D NULL; > +} I guess I would have used the rte_delay_us_callback_register(NULL) to unreg= ister, but this is fine. > diff --git a/lib/librte_eal/common/include/generic/rte_cycles.h b/lib/lib= rte_eal/common/include/generic/rte_cycles.h > index 8cc21f2..274f798 100644 > --- a/lib/librte_eal/common/include/generic/rte_cycles.h > +++ b/lib/librte_eal/common/include/generic/rte_cycles.h > @@ -202,4 +202,17 @@ rte_delay_ms(unsigned ms) > rte_delay_us(ms * 1000); > } >=20 > +/** > + * Replace rte_delay_us with user defined function. > + * > + * @param userfunc > + * User function which replaces rte_delay_us. > + */ > +void rte_delay_us_callback_register(void(*userfunc)(unsigned)); > + > +/** > + * Unregister user callback function. Restores original rte_delay_us. > + */ > +void rte_delay_us_callback_unregister(void); Just a note we need to add these two new APIs to the map file for ABI check= ing. Other then these two comments I would give this one a +1 unless someone els= e has some comments. > + > #endif /* _RTE_CYCLES_H_ */ > --=20 > 2.1.4 >=20