From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id D5EA95A57 for ; Fri, 6 Nov 2015 18:22:30 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 06 Nov 2015 09:22:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,252,1444719600"; d="scan'208";a="829332887" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.208.62]) by fmsmga001.fm.intel.com with SMTP; 06 Nov 2015 09:22:28 -0800 Received: by (sSMTP sendmail emulation); Fri, 06 Nov 2015 17:22:27 +0025 Date: Fri, 6 Nov 2015 17:22:27 +0000 From: Bruce Richardson To: Stephen Hemminger , Thomas Monjalon , dev@dpdk.org, adrien.mazarguil@6wind.com Message-ID: <20151106172227.GC19512@bricha3-MOBL3> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151106171007.GB19512@bricha3-MOBL3> Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) 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: Fri, 06 Nov 2015 17:22:31 -0000 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? > > /Bruce And here's the version if we are happy to have file and line number instead of function name. I think this might be the best option. /Bruce #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_LOG(ERR, PMD, __FILE__", " RTE_STR(__LINE__) ": " __VA_ARGS__) #else -#define RTE_PMD_DEBUG_TRACE(fmt, args...) +#define RTE_PMD_DEBUG_TRACE(...) #endif