diff mbox

[1/3] linux-generic: timer: convert assert to ODP_ASSERT

Message ID 1426717061-21983-1-git-send-email-mike.holmes@linaro.org
State New
Headers show

Commit Message

Mike Holmes March 18, 2015, 10:17 p.m. UTC
ODP implementations should not call assert directly.

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 platform/linux-generic/odp_timer.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Stuart Haslam March 19, 2015, 11:09 a.m. UTC | #1
On Wed, Mar 18, 2015 at 06:17:39PM -0400, Mike Holmes wrote:
> ODP implementations should not call assert directly.
> 
> Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> ---
>  platform/linux-generic/odp_timer.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
> index b7cb04f..39d7064 100644
> --- a/platform/linux-generic/odp_timer.c
> +++ b/platform/linux-generic/odp_timer.c
> @@ -23,9 +23,7 @@
>  
>  /* For snprint, POSIX timers and sigevent */
>  #define _POSIX_C_SOURCE 200112L
> -#include <assert.h>
>  #include <errno.h>
> -#include <string.h>
>  #include <stdlib.h>
>  #include <time.h>
>  #include <signal.h>
> @@ -123,8 +121,9 @@ static void timer_init(odp_timer *tim,
>  /* Teardown when timer is freed */
>  static void timer_fini(odp_timer *tim, tick_buf_t *tb)
>  {
> -	assert(tb->exp_tck.v == TMO_UNUSED);
> -	assert(tb->tmo_buf == ODP_BUFFER_INVALID);
> +	ODP_ASSERT(tb->exp_tck.v == TMO_UNUSED, "tb->exp_tck.v == TMO_UNUSED");
> +	ODP_ASSERT(tb->tmo_buf == ODP_BUFFER_INVALID,
> +		   "tb->tmo_buf == ODP_BUFFER_INVALID");

This isn't too pleasant, and the comments could become stale. How about
we just modify ODP_ASSERT() to do this? (there are no users of it yet)

Something like this perhaps;

#define ODP_ASSERT(cond) ODP_ASSERT_STR(cond, " assert failed: " #cond)

#define ODP_ASSERT_STR(cond, msg) \
	do { if ((ODP_DEBUG == 1) && (!(cond))) { \
		ODP_ERR("%s\n", msg); \
		odp_global_data.abort_fn(); } \
	} while (0)
Mike Holmes March 19, 2015, 11:33 a.m. UTC | #2
I was hoping some one would say that, it was my thought also, I agree.

On 19 March 2015 at 07:09, Stuart Haslam <stuart.haslam@linaro.org> wrote:

> On Wed, Mar 18, 2015 at 06:17:39PM -0400, Mike Holmes wrote:
> > ODP implementations should not call assert directly.
> >
> > Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> > ---
> >  platform/linux-generic/odp_timer.c | 20 +++++++++++---------
> >  1 file changed, 11 insertions(+), 9 deletions(-)
> >
> > diff --git a/platform/linux-generic/odp_timer.c
> b/platform/linux-generic/odp_timer.c
> > index b7cb04f..39d7064 100644
> > --- a/platform/linux-generic/odp_timer.c
> > +++ b/platform/linux-generic/odp_timer.c
> > @@ -23,9 +23,7 @@
> >
> >  /* For snprint, POSIX timers and sigevent */
> >  #define _POSIX_C_SOURCE 200112L
> > -#include <assert.h>
> >  #include <errno.h>
> > -#include <string.h>
> >  #include <stdlib.h>
> >  #include <time.h>
> >  #include <signal.h>
> > @@ -123,8 +121,9 @@ static void timer_init(odp_timer *tim,
> >  /* Teardown when timer is freed */
> >  static void timer_fini(odp_timer *tim, tick_buf_t *tb)
> >  {
> > -     assert(tb->exp_tck.v == TMO_UNUSED);
> > -     assert(tb->tmo_buf == ODP_BUFFER_INVALID);
> > +     ODP_ASSERT(tb->exp_tck.v == TMO_UNUSED, "tb->exp_tck.v ==
> TMO_UNUSED");
> > +     ODP_ASSERT(tb->tmo_buf == ODP_BUFFER_INVALID,
> > +                "tb->tmo_buf == ODP_BUFFER_INVALID");
>
> This isn't too pleasant, and the comments could become stale. How about
> we just modify ODP_ASSERT() to do this? (there are no users of it yet)
>
> Something like this perhaps;
>
> #define ODP_ASSERT(cond) ODP_ASSERT_STR(cond, " assert failed: " #cond)
>
> #define ODP_ASSERT_STR(cond, msg) \
>         do { if ((ODP_DEBUG == 1) && (!(cond))) { \
>                 ODP_ERR("%s\n", msg); \
>                 odp_global_data.abort_fn(); } \
>         } while (0)
>
> --
> Stuart.
>
Ola Liljedahl March 19, 2015, 7:13 p.m. UTC | #3
I can only approve of Mike's patch if we change ODP_ASSERT to do something
like this.


On 19 March 2015 at 12:09, Stuart Haslam <stuart.haslam@linaro.org> wrote:

> On Wed, Mar 18, 2015 at 06:17:39PM -0400, Mike Holmes wrote:
> > ODP implementations should not call assert directly.
> >
> > Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
> > ---
> >  platform/linux-generic/odp_timer.c | 20 +++++++++++---------
> >  1 file changed, 11 insertions(+), 9 deletions(-)
> >
> > diff --git a/platform/linux-generic/odp_timer.c
> b/platform/linux-generic/odp_timer.c
> > index b7cb04f..39d7064 100644
> > --- a/platform/linux-generic/odp_timer.c
> > +++ b/platform/linux-generic/odp_timer.c
> > @@ -23,9 +23,7 @@
> >
> >  /* For snprint, POSIX timers and sigevent */
> >  #define _POSIX_C_SOURCE 200112L
> > -#include <assert.h>
> >  #include <errno.h>
> > -#include <string.h>
> >  #include <stdlib.h>
> >  #include <time.h>
> >  #include <signal.h>
> > @@ -123,8 +121,9 @@ static void timer_init(odp_timer *tim,
> >  /* Teardown when timer is freed */
> >  static void timer_fini(odp_timer *tim, tick_buf_t *tb)
> >  {
> > -     assert(tb->exp_tck.v == TMO_UNUSED);
> > -     assert(tb->tmo_buf == ODP_BUFFER_INVALID);
> > +     ODP_ASSERT(tb->exp_tck.v == TMO_UNUSED, "tb->exp_tck.v ==
> TMO_UNUSED");
> > +     ODP_ASSERT(tb->tmo_buf == ODP_BUFFER_INVALID,
> > +                "tb->tmo_buf == ODP_BUFFER_INVALID");
>
> This isn't too pleasant, and the comments could become stale. How about
> we just modify ODP_ASSERT() to do this? (there are no users of it yet)
>
> Something like this perhaps;
>
> #define ODP_ASSERT(cond) ODP_ASSERT_STR(cond, " assert failed: " #cond)
>
> #define ODP_ASSERT_STR(cond, msg) \
>         do { if ((ODP_DEBUG == 1) && (!(cond))) { \
>                 ODP_ERR("%s\n", msg); \
>                 odp_global_data.abort_fn(); } \
>         } while (0)
>
> --
> Stuart.
>
Mike Holmes March 19, 2015, 7:32 p.m. UTC | #4
I will take a look at change to the macro its self.

On 19 March 2015 at 15:13, Ola Liljedahl <ola.liljedahl@linaro.org> wrote:

> I can only approve of Mike's patch if we change ODP_ASSERT to do something
> like this.
>
>
> On 19 March 2015 at 12:09, Stuart Haslam <stuart.haslam@linaro.org> wrote:
>
>> On Wed, Mar 18, 2015 at 06:17:39PM -0400, Mike Holmes wrote:
>> > ODP implementations should not call assert directly.
>> >
>> > Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
>> > ---
>> >  platform/linux-generic/odp_timer.c | 20 +++++++++++---------
>> >  1 file changed, 11 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/platform/linux-generic/odp_timer.c
>> b/platform/linux-generic/odp_timer.c
>> > index b7cb04f..39d7064 100644
>> > --- a/platform/linux-generic/odp_timer.c
>> > +++ b/platform/linux-generic/odp_timer.c
>> > @@ -23,9 +23,7 @@
>> >
>> >  /* For snprint, POSIX timers and sigevent */
>> >  #define _POSIX_C_SOURCE 200112L
>> > -#include <assert.h>
>> >  #include <errno.h>
>> > -#include <string.h>
>> >  #include <stdlib.h>
>> >  #include <time.h>
>> >  #include <signal.h>
>> > @@ -123,8 +121,9 @@ static void timer_init(odp_timer *tim,
>> >  /* Teardown when timer is freed */
>> >  static void timer_fini(odp_timer *tim, tick_buf_t *tb)
>> >  {
>> > -     assert(tb->exp_tck.v == TMO_UNUSED);
>> > -     assert(tb->tmo_buf == ODP_BUFFER_INVALID);
>> > +     ODP_ASSERT(tb->exp_tck.v == TMO_UNUSED, "tb->exp_tck.v ==
>> TMO_UNUSED");
>> > +     ODP_ASSERT(tb->tmo_buf == ODP_BUFFER_INVALID,
>> > +                "tb->tmo_buf == ODP_BUFFER_INVALID");
>>
>> This isn't too pleasant, and the comments could become stale. How about
>> we just modify ODP_ASSERT() to do this? (there are no users of it yet)
>>
>> Something like this perhaps;
>>
>> #define ODP_ASSERT(cond) ODP_ASSERT_STR(cond, " assert failed: " #cond)
>>
>> #define ODP_ASSERT_STR(cond, msg) \
>>         do { if ((ODP_DEBUG == 1) && (!(cond))) { \
>>                 ODP_ERR("%s\n", msg); \
>>                 odp_global_data.abort_fn(); } \
>>         } while (0)
>>
>> --
>> Stuart.
>>
>
>
diff mbox

Patch

diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c
index b7cb04f..39d7064 100644
--- a/platform/linux-generic/odp_timer.c
+++ b/platform/linux-generic/odp_timer.c
@@ -23,9 +23,7 @@ 
 
 /* For snprint, POSIX timers and sigevent */
 #define _POSIX_C_SOURCE 200112L
-#include <assert.h>
 #include <errno.h>
-#include <string.h>
 #include <stdlib.h>
 #include <time.h>
 #include <signal.h>
@@ -123,8 +121,9 @@  static void timer_init(odp_timer *tim,
 /* Teardown when timer is freed */
 static void timer_fini(odp_timer *tim, tick_buf_t *tb)
 {
-	assert(tb->exp_tck.v == TMO_UNUSED);
-	assert(tb->tmo_buf == ODP_BUFFER_INVALID);
+	ODP_ASSERT(tb->exp_tck.v == TMO_UNUSED, "tb->exp_tck.v == TMO_UNUSED");
+	ODP_ASSERT(tb->tmo_buf == ODP_BUFFER_INVALID,
+		   "tb->tmo_buf == ODP_BUFFER_INVALID");
 	tim->queue = ODP_QUEUE_INVALID;
 	tim->user_ptr = NULL;
 }
@@ -137,7 +136,8 @@  static inline uint32_t get_next_free(odp_timer *tim)
 
 static inline void set_next_free(odp_timer *tim, uint32_t nf)
 {
-	assert(tim->queue == ODP_QUEUE_INVALID);
+	ODP_ASSERT(tim->queue == ODP_QUEUE_INVALID,
+		   "tim->queue == ODP_QUEUE_INVALID");
 	/* Reusing 'queue' for next free index */
 	tim->queue = _odp_cast_scalar(odp_queue_t, nf);
 }
@@ -195,7 +195,7 @@  static inline uint32_t handle_to_idx(odp_timer_t hdl,
 static inline odp_timer_t tp_idx_to_handle(struct odp_timer_pool_s *tp,
 		uint32_t idx)
 {
-	assert(idx < (1U << INDEX_BITS));
+	ODP_ASSERT(idx < (1U << INDEX_BITS), "idx < (1U << INDEX_BITS)");
 	return (tp->tp_idx << INDEX_BITS) | idx;
 }
 
@@ -281,7 +281,8 @@  static inline odp_timer_t timer_alloc(odp_timer_pool *tp,
 	if (odp_likely(tp->num_alloc < tp->param.num_timers)) {
 		tp->num_alloc++;
 		/* Remove first unused timer from free list */
-		assert(tp->first_free != tp->param.num_timers);
+		ODP_ASSERT(tp->first_free != tp->param.num_timers,
+			   "tp->first_free != tp->param.num_timers");
 		uint32_t idx = tp->first_free;
 		odp_timer *tim = &tp->timers[idx];
 		tp->first_free = get_next_free(tim);
@@ -322,7 +323,7 @@  static inline odp_buffer_t timer_free(odp_timer_pool *tp, uint32_t idx)
 	odp_spinlock_lock(&tp->lock);
 	set_next_free(tim, tp->first_free);
 	tp->first_free = idx;
-	assert(tp->num_alloc != 0);
+	ODP_ASSERT(tp->num_alloc != 0, "tp->num_alloc != 0");
 	tp->num_alloc--;
 	odp_spinlock_unlock(&tp->lock);
 
@@ -597,7 +598,8 @@  static unsigned odp_timer_pool_expire(odp_timer_pool_t tpid, uint64_t tick)
 	unsigned nexp = 0;
 	uint32_t i;
 
-	assert(high_wm <= tpid->param.num_timers);
+	ODP_ASSERT(high_wm <= tpid->param.num_timers,
+		   "high_wm <= tpid->param.num_timers");
 	for (i = 0; i < high_wm;) {
 #ifdef __ARM_ARCH
 		/* As a rare occurence, we can outsmart the HW prefetcher