From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 0973F559C for ; Tue, 10 Nov 2015 11:26:17 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 10 Nov 2015 02:26:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,270,1444719600"; d="scan'208";a="846857758" Received: from dwdohert-dpdk-fedora-20.ir.intel.com ([163.33.213.96]) by orsmga002.jf.intel.com with ESMTP; 10 Nov 2015 02:26:16 -0800 To: "Richardson, Bruce" , Adrien Mazarguil References: <1441811374-28984-1-git-send-email-bruce.richardson@intel.com> <1446552059-5446-1-git-send-email-bruce.richardson@intel.com> <1446552059-5446-3-git-send-email-bruce.richardson@intel.com> <4698587.GS9blBozDC@xps13> <20151104102418.GN3518@6wind.com> <20151104103957.4cabd090@xeon-e3> <20151105150918.GV3518@6wind.com> <20151106171007.GB19512@bricha3-MOBL3> <20151106172227.GC19512@bricha3-MOBL3> <20151109133905.GL4013@6wind.com> <59AF69C657FD0841A61C55336867B5B03598018B@IRSMSX103.ger.corp.intel.com> From: Declan Doherty Message-ID: <5641C775.5050006@intel.com> Date: Tue, 10 Nov 2015 10:31:17 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <59AF69C657FD0841A61C55336867B5B03598018B@IRSMSX103.ger.corp.intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH v3 2/4] ethdev: move error checking macros to header 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, 10 Nov 2015 10:26:18 -0000 On 09/11/15 14:02, Richardson, Bruce wrote: > > >> -----Original Message----- >> From: Adrien Mazarguil [mailto:adrien.mazarguil@6wind.com] >> Sent: Monday, November 9, 2015 1:39 PM >> To: Richardson, Bruce >> Cc: Stephen Hemminger ; Thomas Monjalon >> ; dev@dpdk.org >> Subject: Re: [dpdk-dev] [PATCH v3 2/4] ethdev: move error checking macros >> to header >> >> On Fri, Nov 06, 2015 at 05:22:27PM +0000, Bruce Richardson wrote: >>> On Fri, Nov 06, 2015 at 05:10:07PM +0000, Bruce Richardson wrote: >>>> On Thu, Nov 05, 2015 at 04:09:18PM +0100, Adrien Mazarguil wrote: >>>>> >>>>> I won't argue against this as it's obviously more complex than the >> original >>>>> method, however note that users of the RTE_PMD_DEBUG_TRACE() macro >> do not >>>>> have to modify their code. They shouldn't care about the >> implementation. >>>>> >>>>> Also note that we can do much cleaner code if we drop the all macros >>>>> implementation using a (much easier to debug) static inline >> function, >>>>> only perhaps with a wrapper macro that provides __LINE__, __func__ >> and >>>>> __FILE__ as arguments. Nontrival code shouldn't be done in macros >> anyway. >>>>> >>>> Getting something working with __FILE__ and probably __LINE__ would be >> easy enough >>>> with a helper macro, but __func__ is not so easy as it's not a >> preprocessor symbol >>>> [since the pre-processor has no idea what function you are in]. >>>> >>>> However, using func, here is the best I've come up with so far. It's >> not that >>>> pretty, but it's probably easier to work with than the macro version. >>>> >>>> #ifdef RTE_LIBRTE_ETHDEV_DEBUG >>>> -#define RTE_PMD_DEBUG_TRACE(fmt, args...) \ >>>> - RTE_LOG(ERR, PMD, "%s: " fmt, __func__, ## args) >>>> +#define RTE_PMD_DEBUG_TRACE(...) \ >>>> + rte_pmd_debug_trace(__func__, __VA_ARGS__) >>>> + >>>> +static inline void >>>> +rte_pmd_debug_trace(const char *func_name, const char *fmt, ...) >>>> +{ >>>> + static __thread char buffer[128]; >>>> + char *out_buf = buffer; >>>> + unsigned count; >>>> + va_list ap; >>>> + >>>> + count = snprintf(buffer, sizeof(buffer), "%s: %s", func_name, >> fmt); >>>> + if (count >= sizeof(buffer)) { // truncated output >>>> + char *new_buf = malloc(count + 1); >>>> + if (new_buf == NULL) // no memory, just print 128 >> chars >>>> + goto print_buffer; >>>> + snprintf(new_buf, count + 1, "%s: %s", func_name, >> fmt); >>>> + va_start(ap, fmt); >>>> + rte_vlog(RTE_LOG_ERR, RTE_LOGTYPE_PMD, buffer, ap); >>>> + va_end(ap); >>>> + free(new_buf); >>>> + return; >>>> + } >>>> + >>>> +print_buffer: >>>> + va_start(ap, fmt); >>>> + rte_vlog(RTE_LOG_ERR, RTE_LOGTYPE_PMD, out_buf, ap); >>>> + va_end(ap); >>>> +} >>>> #else >>>> #define RTE_PMD_DEBUG_TRACE(fmt, args...) >>>> #endif >>>> >>>> Comments or improvements? >> >> Such a function shouldn't malloc() anything. The entire line should fit on >> the stack (crashing is fine if it does not, then it's probably a bug). We >> did something in two passes along these lines in mlx5_defs.h (not pretty >> but >> quite useful): >> >> /* Allocate a buffer on the stack and fill it with a printf format >> string. */ >> #define MKSTR(name, ...) \ >> char name[snprintf(NULL, 0, __VA_ARGS__) + 1]; \ >> \ >> snprintf(name, sizeof(name), __VA_ARGS__) >> >> Untested but I guess modifying that function accordingly would look like: >> >> static inline void >> rte_pmd_debug_trace(const char *func_name, const char *fmt, ...) >> { >> va_list ap; >> va_start(ap, fmt); >> >> static __thread char buffer[vsnprintf(NULL, 0, fmt, ap)]; >> >> va_end(ap); >> va_start(ap, fmt); >> vsnprintf(buffer, sizeof(buffer), fmt, ap); >> va_end(ap); >> rte_log(RTE_LOG_ERR, RTE_LOGTYPE_PMD, "%s: %s", func_name, >> buffer); >> } >> > > Looks a much better option. > > From this, though, I assume then that we are only looking to support the -pedantic flag in conjuction with c99 mode or above. Supporting -pedantic with the pre-gcc-5 versions won't allow that to work though, as variably sized arrays only came in with c99, and were gnu extensions before that. > > Regards, > /Bruce > I had made some similar changes in the cryptodev patch set to allow these macros to be shared between the ethdev and cryptodev, but I wasn't aware of the -pedantic build issues. I've incorporate the changes from patch 1 & 2 discussed here into the cryptodev patch set. See patch 2/10 (http://dpdk.org/ml/archives/dev/2015-November/027888.html) for the implementation of the rte_pmf_debug_trace function. Any comments or ack's are welcome :) Declan