From: Adrien Mazarguil <adrien.mazarguil@6wind.com>
To: Bruce Richardson <bruce.richardson@intel.com>,
Stephen Hemminger <stephen@networkplumber.org>,
Thomas Monjalon <thomas.monjalon@6wind.com>,
dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH v3 2/4] ethdev: move error checking macros to header
Date: Mon, 9 Nov 2015 14:50:31 +0100 [thread overview]
Message-ID: <20151109135031.GM4013@6wind.com> (raw)
In-Reply-To: <20151109133905.GL4013@6wind.com>
On Mon, Nov 09, 2015 at 02:39:05PM +0100, Adrien Mazarguil wrote:
> 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)];
Of course this line should read:
static __thread char buffer[vsnprintf(NULL, 0, fmt, ap) + 1];
> 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);
> }
>
> > 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
>
> Much cleaner indeed, however __func__ might be useful when comparing log
> outputs from different source code versions. I think we should keep it.
--
Adrien Mazarguil
6WIND
next prev parent reply other threads:[~2015-11-09 13:50 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-12 11:28 [dpdk-dev] [PATCH 0/4] ethdev: Add checks for function support in driver Bruce Richardson
2015-06-12 11:28 ` [dpdk-dev] [PATCH 1/4] ethdev: rename macros to have RTE_ETH prefix Bruce Richardson
2015-06-12 11:28 ` [dpdk-dev] [PATCH 2/4] ethdev: move RTE_ETH_FPTR_OR_ERR macros to header Bruce Richardson
2015-06-12 11:28 ` [dpdk-dev] [PATCH 3/4] ethdev: remove duplicated debug functions Bruce Richardson
2015-06-12 11:28 ` [dpdk-dev] [PATCH 4/4] ethdev: check support for rx_queue_count and descriptor_done fns Bruce Richardson
2015-06-12 17:32 ` Roger B. Melton
2015-06-15 10:14 ` Bruce Richardson
2015-07-06 15:11 ` Thomas Monjalon
2015-07-26 20:44 ` Thomas Monjalon
2015-09-09 15:09 ` [dpdk-dev] [PATCH v2 0/4] ethdev: minor cleanup Bruce Richardson
2015-09-09 15:09 ` [dpdk-dev] [PATCH v2 1/4] ethdev: rename macros to have RTE_ETH prefix Bruce Richardson
2015-09-09 15:09 ` [dpdk-dev] [PATCH v2 2/4] ethdev: move error checking macros to header Bruce Richardson
2015-09-09 15:09 ` [dpdk-dev] [PATCH v2 3/4] ethdev: remove duplicated debug functions Bruce Richardson
2015-09-09 15:09 ` [dpdk-dev] [PATCH v2 4/4] ethdev: check driver support for functions Bruce Richardson
2015-09-28 10:23 ` [dpdk-dev] [PATCH v2 0/4] ethdev: minor cleanup Bruce Richardson
2015-11-03 1:11 ` Thomas Monjalon
2015-11-03 10:06 ` Bruce Richardson
2015-11-03 12:00 ` [dpdk-dev] [PATCH v3 " Bruce Richardson
2015-11-03 12:00 ` [dpdk-dev] [PATCH v3 1/4] ethdev: rename macros to have RTE_ETH prefix Bruce Richardson
2015-11-03 12:00 ` [dpdk-dev] [PATCH v3 2/4] ethdev: move error checking macros to header Bruce Richardson
2015-11-04 1:19 ` Thomas Monjalon
2015-11-04 10:24 ` Adrien Mazarguil
2015-11-04 14:10 ` Bruce Richardson
2015-11-04 15:25 ` Adrien Mazarguil
2015-11-04 18:39 ` Stephen Hemminger
2015-11-05 15:09 ` Adrien Mazarguil
2015-11-05 15:17 ` Bruce Richardson
2015-11-06 11:49 ` Bruce Richardson
2015-11-06 17:10 ` Bruce Richardson
2015-11-06 17:22 ` Bruce Richardson
2015-11-09 13:39 ` Adrien Mazarguil
2015-11-09 13:50 ` Adrien Mazarguil [this message]
2015-11-09 14:02 ` Richardson, Bruce
2015-11-10 10:31 ` Declan Doherty
2015-11-10 16:08 ` Adrien Mazarguil
2015-11-10 16:21 ` Richardson, Bruce
2015-11-10 17:12 ` Adrien Mazarguil
2015-11-11 10:51 ` Bruce Richardson
2015-11-03 12:00 ` [dpdk-dev] [PATCH v3 3/4] ethdev: remove duplicated debug functions Bruce Richardson
2015-11-03 12:00 ` [dpdk-dev] [PATCH v3 4/4] ethdev: check driver support for functions Bruce Richardson
2015-11-03 22:00 ` Stephen Hemminger
2015-11-04 14:15 ` Bruce Richardson
2015-11-17 12:21 ` [dpdk-dev] [PATCH v4 0/2] ethdev: debug code cleanup Bruce Richardson
2015-11-17 12:21 ` [dpdk-dev] [PATCH v4 1/2] ethdev: remove duplicated debug functions Bruce Richardson
2015-11-17 12:21 ` [dpdk-dev] [PATCH v4 2/2] ethdev: add sanity checks to functions Bruce Richardson
2015-11-17 15:53 ` Stephen Hemminger
2015-11-24 14:56 ` Bruce Richardson
2015-11-24 15:29 ` Thomas Monjalon
2015-11-24 15:45 ` Bruce Richardson
2015-11-24 15:48 ` Thomas Monjalon
2015-11-24 17:37 ` [dpdk-dev] [PATCH v5 0/2] ethdev: debug code cleanup Bruce Richardson
2015-11-24 17:37 ` [dpdk-dev] [PATCH v5 1/2] ethdev: remove duplicated debug functions Bruce Richardson
2015-11-25 18:14 ` Thomas Monjalon
2015-11-24 17:37 ` [dpdk-dev] [PATCH v5 2/2] ethdev: add sanity checks to functions Bruce Richardson
2015-11-25 18:21 ` [dpdk-dev] [PATCH v5 0/2] ethdev: debug code cleanup Thomas Monjalon
2015-11-06 11:52 [dpdk-dev] [PATCH v3 2/4] ethdev: move error checking macros to header Bruce Richardson
2015-11-06 12:25 ` Adrien Mazarguil
2015-11-06 14:39 ` Richardson, Bruce
2015-11-06 14:54 ` Adrien Mazarguil
2015-11-06 15:30 ` Richardson, Bruce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151109135031.GM4013@6wind.com \
--to=adrien.mazarguil@6wind.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
--cc=thomas.monjalon@6wind.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).