From 13f231531436afba3c709acbc63b4315011b75d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 24 Jul 2018 20:02:13 +0200 Subject: [PATCH] CDev: add DEVICE_POLL_DEBUG macro that removes all poll debug output from the build by default Reduces 'uorb_tests latency_test' by about 1us --- src/lib/drivers/device/CDev.cpp | 26 +++++++++++++++----------- src/lib/drivers/device/CDev.hpp | 4 ++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lib/drivers/device/CDev.cpp b/src/lib/drivers/device/CDev.cpp index d71061b976..c3e8154133 100644 --- a/src/lib/drivers/device/CDev.cpp +++ b/src/lib/drivers/device/CDev.cpp @@ -44,6 +44,12 @@ #include "px4_posix.h" #include "drivers/drv_device.h" +#if 1 // Disable poll debug ouput by default completely as it uses CPU cycles +#define DEVICE_POLL_DEBUG(FMT, ...) +#else +#define DEVICE_POLL_DEBUG(FMT, ...) DEVICE_DEBUG(FMT, ##__VA_ARGS__) +#endif + namespace device { @@ -268,7 +274,7 @@ CDev::ioctl(file_t *filep, int cmd, unsigned long arg) int CDev::poll(file_t *filep, px4_pollfd_struct_t *fds, bool setup) { - DEVICE_DEBUG("CDev::Poll %s", setup ? "setup" : "teardown"); + DEVICE_POLL_DEBUG("CDev::Poll %s", setup ? "setup" : "teardown"); int ret = PX4_OK; if (setup) { @@ -277,7 +283,7 @@ CDev::poll(file_t *filep, px4_pollfd_struct_t *fds, bool setup) * benefit. */ fds->priv = (void *)filep; - DEVICE_DEBUG("CDev::poll: fds->priv = %p", filep); + DEVICE_POLL_DEBUG("CDev::poll: fds->priv = %p", filep); /* * Lock against poll_notify() and possibly other callers. @@ -354,8 +360,6 @@ CDev::poll(file_t *filep, px4_pollfd_struct_t *fds, bool setup) px4_sem_post(fds->sem); } - } else { - PX4_WARN("Store Poll Waiter error."); } ATOMIC_LEAVE; @@ -375,7 +379,7 @@ CDev::poll(file_t *filep, px4_pollfd_struct_t *fds, bool setup) void CDev::poll_notify(pollevent_t events) { - DEVICE_DEBUG("CDev::poll_notify events = %0x", events); + DEVICE_POLL_DEBUG("CDev::poll_notify events = %0x", events); /* lock against poll() as well as other wakeups */ ATOMIC_ENTER; @@ -392,12 +396,12 @@ CDev::poll_notify(pollevent_t events) void CDev::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events) { - DEVICE_DEBUG("CDev::poll_notify_one"); + DEVICE_POLL_DEBUG("CDev::poll_notify_one"); /* update the reported event set */ fds->revents |= fds->events & events; - DEVICE_DEBUG(" Events fds=%p %0x %0x %0x", fds, fds->revents, fds->events, events); + DEVICE_POLL_DEBUG(" Events fds=%p %0x %0x %0x", fds, fds->revents, fds->events, events); if (fds->revents != 0) { px4_sem_post(fds->sem); @@ -407,7 +411,7 @@ CDev::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events) pollevent_t CDev::poll_state(file_t *filep) { - DEVICE_DEBUG("CDev::poll_notify"); + DEVICE_POLL_DEBUG("CDev::poll_notify"); /* by default, no poll events to report */ return 0; } @@ -418,7 +422,7 @@ CDev::store_poll_waiter(px4_pollfd_struct_t *fds) /* * Look for a free slot. */ - DEVICE_DEBUG("CDev::store_poll_waiter"); + DEVICE_POLL_DEBUG("CDev::store_poll_waiter"); for (unsigned i = 0; i < _max_pollwaiters; i++) { if (nullptr == _pollset[i]) { @@ -436,7 +440,7 @@ CDev::store_poll_waiter(px4_pollfd_struct_t *fds) int CDev::remove_poll_waiter(px4_pollfd_struct_t *fds) { - DEVICE_DEBUG("CDev::remove_poll_waiter"); + DEVICE_POLL_DEBUG("CDev::remove_poll_waiter"); for (unsigned i = 0; i < _max_pollwaiters; i++) { if (fds == _pollset[i]) { @@ -447,7 +451,7 @@ CDev::remove_poll_waiter(px4_pollfd_struct_t *fds) } } - PX4_WARN("poll: bad fd state"); + DEVICE_POLL_DEBUG("poll: bad fd state"); return -EINVAL; } diff --git a/src/lib/drivers/device/CDev.hpp b/src/lib/drivers/device/CDev.hpp index 305f7e273a..2c956740ce 100644 --- a/src/lib/drivers/device/CDev.hpp +++ b/src/lib/drivers/device/CDev.hpp @@ -293,14 +293,14 @@ private: * * @return OK, or -errno on error. */ - int store_poll_waiter(px4_pollfd_struct_t *fds); + inline int store_poll_waiter(px4_pollfd_struct_t *fds); /** * Remove a poll waiter. * * @return OK, or -errno on error. */ - int remove_poll_waiter(px4_pollfd_struct_t *fds); + inline int remove_poll_waiter(px4_pollfd_struct_t *fds); /* do not allow copying this class */ CDev(const CDev &);