Skip to contentSkip to conversation

eal/linux: fix return after alarm registration failure

PATCH Superseded Thomas Monjalon 5 participants 12 messages Jun 26, 2019 – Jun 27, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal/linux: fix return after alarm registration failure

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier understanding.

Fixes af75078fece3 ("first public release")
---
 lib/librte_eal/linux/eal/eal_alarm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/librte_eal/linux/eal/eal_alarm.c +6 -2
index 840ede780..d6d70e8c3 100644
@@ -137,9 +137,13 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)
 
 	rte_spinlock_lock(&alarm_list_lk);
 	if (!handler_registered) {
-		ret |= rte_intr_callback_register(&intr_handle,
+		ret = rte_intr_callback_register(&intr_handle,
 				eal_alarm_callback, NULL);
-		handler_registered = (ret == 0) ? 1 : 0;
+		if (ret == 0)
+			handler_registered = 1;
+		else
+			/* not fatal, callback can be registered later */
+			ret = 0;
 	}
 
 	if (LIST_EMPTY(&alarm_list))
Signature · 1 line
2.21.0
#1 lore raw
Quoted 38 lines · Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier understanding.

Fixes af75078fece3 ("first public release")
---
 lib/librte_eal/linux/eal/eal_alarm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
lib/librte_eal/linux/eal/eal_alarm.c +6 -2
index 840ede780..d6d70e8c3 100644
@@ -137,9 +137,13 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback
 cb_fn, void *cb_arg)
 
        rte_spinlock_lock(&alarm_list_lk);
        if (!handler_registered) {
-               ret |= rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(&intr_handle,
                                eal_alarm_callback, NULL);
-               handler_registered = (ret == 0) ? 1 : 0;
+               if (ret == 0)
+                       handler_registered = 1;
+               else
+                       /* not fatal, callback can be registered later */
+                       ret = 0;
        }
 
Quoted 2 lines

if (LIST_EMPTY(&alarm_list))

Well, then it means that you don't want to touch ret at all. How about:
if (rte_intr_callback_register(&intr_handle,

                               eal_alarm_callback, NULL) == 0)
        handler_registered = 1;

?

Signature · 1 line
David Marchand
#2 lore raw

26/06/2019 13:20, David Marchand:

Quoted 12 lines
Quoted 9 lines · Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier understanding.

[...]

Quoted 17 lines

lib/librte_eal/linux/eal/eal_alarm.c rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg) · line 147

Quoted 13 lines
lib/librte_eal/linux/eal/eal_alarm.c +6 -2
        if (!handler_registered) {
-               ret |= rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(&intr_handle,
                                eal_alarm_callback, NULL);
-               handler_registered = (ret == 0) ? 1 : 0;
+               if (ret == 0)
+                       handler_registered = 1;
+               else
+                       /* not fatal, callback can be registered later */
+                       ret = 0;
        }

Well, then it means that you don't want to touch ret at all. How about:
if (rte_intr_callback_register(&intr_handle,

Quoted 4 lines
                               eal_alarm_callback, NULL) == 0)
        handler_registered = 1;

?

Too much simple :)

I think we try to avoid calling a function in a "if" per coding style.
And my proposal has the benefit of offering a comment about the non-fatal error.

After saying these arguments, I have to say I have no strong opinion :) I'm fine either way.

Reviewed-by
#3 lore raw
Quoted 36 lines · Thomas Monjalon

26/06/2019 13:20, David Marchand:

Quoted 11 lines
Quoted 8 lines · Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier

understanding.

Quoted 1 line
Quoted 1 line

[...]

Quoted 11 lines

lib/librte_eal/linux/eal/eal_alarm.c rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)

Quoted 11 lines
lib/librte_eal/linux/eal/eal_alarm.c +5 -2
        if (!handler_registered) {
-               ret |= rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(&intr_handle,
                                eal_alarm_callback, NULL);
-               handler_registered = (ret == 0) ? 1 : 0;
+               if (ret == 0)
+                       handler_registered = 1;
+               else
+                       /* not fatal, callback can be registered later

*/

Quoted 9 lines
Quoted 2 lines
+                       ret = 0;
        }

Well, then it means that you don't want to touch ret at all. How about:
if (rte_intr_callback_register(&intr_handle,

                               eal_alarm_callback, NULL) == 0)
        handler_registered = 1;
Quoted 9 lines
Quoted 1 line

?

Too much simple :)

I think we try to avoid calling a function in a "if" per coding style.
And my proposal has the benefit of offering a comment about the non-fatal error.

/* not fatal, callback can be registered later */
if (rte_intr_callback_register(&intr_handle,

                              eal_alarm_callback, NULL) == 0)
       handler_registered = 1;
Quoted 3 lines

After saying these arguments, I have to say I have no strong opinion :) I'm fine either way.

I won't insist either, if you feel like taking my proposal, you can keep the reviewed-by token.

Signature · 1 line
David Marchand
#4 lore raw
Quoted 48 lines · David Marchand
Quoted 36 lines · Thomas Monjalon

26/06/2019 13:20, David Marchand:

Quoted 11 lines
Quoted 8 lines · Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier

understanding.

Quoted 1 line
Quoted 1 line

[...]

Quoted 11 lines

lib/librte_eal/linux/eal/eal_alarm.c rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)

Quoted 11 lines
lib/librte_eal/linux/eal/eal_alarm.c +5 -2
         if (!handler_registered) {
-               ret |= rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(&intr_handle,
                                 eal_alarm_callback, NULL);
-               handler_registered = (ret == 0) ? 1 : 0;
+               if (ret == 0)
+                       handler_registered = 1;
+               else
+                       /* not fatal, callback can be registered later

*/

Quoted 9 lines
Quoted 2 lines
+                       ret = 0;
         }

Well, then it means that you don't want to touch ret at all. How about:
if (rte_intr_callback_register(&intr_handle,

                                eal_alarm_callback, NULL) == 0)
         handler_registered = 1;
Quoted 9 lines
Quoted 1 line

?

Too much simple :)

I think we try to avoid calling a function in a "if" per coding style.
And my proposal has the benefit of offering a comment about the non-fatal error.

Quoted 5 lines

/* not fatal, callback can be registered later */
if (rte_intr_callback_register(&intr_handle,

                               eal_alarm_callback, NULL) == 0)
        handler_registered = 1;

I prefer the original. It's more explicit and conveys the intention better. Did i break the tie? :)

Signature · 2 lines
Thanks,
Anatoly
#5 lore raw

26/06/2019 13:43, Burakov, Anatoly:

Quoted 49 lines · David Marchand
Quoted 48 lines · Thomas Monjalon
Quoted 46 lines

26/06/2019 13:20, David Marchand:

Quoted 11 lines
Quoted 8 lines · Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier

understanding.

Quoted 1 line
Quoted 1 line

[...]

Quoted 11 lines

lib/librte_eal/linux/eal/eal_alarm.c rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)

Quoted 11 lines
lib/librte_eal/linux/eal/eal_alarm.c +5 -2
         if (!handler_registered) {
-               ret |= rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(&intr_handle,
                                 eal_alarm_callback, NULL);
-               handler_registered = (ret == 0) ? 1 : 0;
+               if (ret == 0)
+                       handler_registered = 1;
+               else
+                       /* not fatal, callback can be registered later

*/

Quoted 10 lines
Quoted 2 lines
+                       ret = 0;
         }

Well, then it means that you don't want to touch ret at all. How about:
if (rte_intr_callback_register(&intr_handle,

                                eal_alarm_callback, NULL) == 0)
         handler_registered = 1;

?

Too much simple :)

I think we try to avoid calling a function in a "if" per coding style.
And my proposal has the benefit of offering a comment about the non-fatal error.

Quoted 8 lines
Quoted 5 lines

/* not fatal, callback can be registered later */
if (rte_intr_callback_register(&intr_handle,

                               eal_alarm_callback, NULL) == 0)
        handler_registered = 1;

I prefer the original. It's more explicit and conveys the intention better. Did i break the tie? :)

I was going to send a v2 with David's suggestion.
Now I'm confused.

#6 lore raw
Quoted 56 lines · Thomas Monjalon

26/06/2019 13:43, Burakov, Anatoly:

Quoted 55 lines · David Marchand
Quoted 53 lines · Thomas Monjalon
Quoted 37 lines

26/06/2019 13:20, David Marchand:

Quoted 11 lines
Quoted 8 lines · Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier

understanding.

Quoted 1 line
Quoted 1 line

[...]

Quoted 11 lines

lib/librte_eal/linux/eal/eal_alarm.c rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)

Quoted 11 lines
lib/librte_eal/linux/eal/eal_alarm.c +5 -2
         if (!handler_registered) {
-               ret |= rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(&intr_handle,
                                 eal_alarm_callback, NULL);
-               handler_registered = (ret == 0) ? 1 : 0;
+               if (ret == 0)
+                       handler_registered = 1;
+               else
+                       /* not fatal, callback can be registered later

*/

Quoted 9 lines
Quoted 2 lines
+                       ret = 0;
         }

Well, then it means that you don't want to touch ret at all. How about:
if (rte_intr_callback_register(&intr_handle,

                                eal_alarm_callback, NULL) == 0)
         handler_registered = 1;
Quoted 9 lines
Quoted 1 line

?

Too much simple :)

I think we try to avoid calling a function in a "if" per coding style.
And my proposal has the benefit of offering a comment about the non-fatal error.

/* not fatal, callback can be registered later */
if (rte_intr_callback_register(&intr_handle,

                               eal_alarm_callback, NULL) == 0)
        handler_registered = 1;
Quoted 6 lines
Quoted 2 lines

I prefer the original. It's more explicit and conveys the intention better. Did i break the tie? :)

I was going to send a v2 with David's suggestion.
Now I'm confused.

I always tend to prefer shorter versions, so +1 for v2 (does that make it a v3? :-) )

/Bruce

#7 lore raw
Quoted 60 lines · Bruce Richardson
Quoted 59 lines · Thomas Monjalon

26/06/2019 13:43, Burakov, Anatoly:

Quoted 57 lines · David Marchand
Quoted 48 lines · Thomas Monjalon
Quoted 37 lines

26/06/2019 13:20, David Marchand:

Quoted 11 lines
Quoted 8 lines · Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier

understanding.

Quoted 1 line
Quoted 1 line

[...]

Quoted 11 lines

lib/librte_eal/linux/eal/eal_alarm.c

Quoted 11 lines
lib/librte_eal/linux/eal/eal_alarm.c +5 -2
          if (!handler_registered) {
-               ret |= rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(&intr_handle,
                                  eal_alarm_callback, NULL);
-               handler_registered = (ret == 0) ? 1 : 0;
+               if (ret == 0)
+                       handler_registered = 1;
+               else
+                       /* not fatal, callback can be registered later

*/

Quoted 9 lines
Quoted 2 lines
+                       ret = 0;
          }

Well, then it means that you don't want to touch ret at all. How about:
if (rte_intr_callback_register(&intr_handle,

                                 eal_alarm_callback, NULL) == 0)
          handler_registered = 1;
Quoted 9 lines
Quoted 1 line

?

Too much simple :)

I think we try to avoid calling a function in a "if" per coding style.
And my proposal has the benefit of offering a comment about the non-fatal error.

Quoted 5 lines

/* not fatal, callback can be registered later */
if (rte_intr_callback_register(&intr_handle,

                                eal_alarm_callback, NULL) == 0)
         handler_registered = 1;

I prefer the original. It's more explicit and conveys the intention better. Did i break the tie? :)

Quoted 8 lines
Quoted 3 lines

I was going to send a v2 with David's suggestion.
Now I'm confused.

I always tend to prefer shorter versions, so +1 for v2 (does that make it a v3? :-) )

/Bruce

OK, but then the suggested comment needs to be fixed. It makes it seem like registering the handler is the "non fatal" part. Perhaps something like:

/* failed register is not a fatal error - callback can be registered later */

Signature · 2 lines
Thanks,
Anatoly
#8 lore raw

26/06/2019 14:52, Burakov, Anatoly:

Quoted 70 lines · Bruce Richardson
Quoted 60 lines · Thomas Monjalon
Quoted 59 lines

26/06/2019 13:43, Burakov, Anatoly:

Quoted 57 lines · David Marchand
Quoted 48 lines · Thomas Monjalon
Quoted 37 lines

26/06/2019 13:20, David Marchand:

Quoted 11 lines
Quoted 8 lines · Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is reset to 0 so the behaviour and the return code are consistent.
Other return code related lines are cleaned up for easier

understanding.

Quoted 1 line
Quoted 1 line

[...]

Quoted 11 lines

lib/librte_eal/linux/eal/eal_alarm.c

Quoted 11 lines
lib/librte_eal/linux/eal/eal_alarm.c +5 -2
          if (!handler_registered) {
-               ret |= rte_intr_callback_register(&intr_handle,
+               ret = rte_intr_callback_register(&intr_handle,
                                  eal_alarm_callback, NULL);
-               handler_registered = (ret == 0) ? 1 : 0;
+               if (ret == 0)
+                       handler_registered = 1;
+               else
+                       /* not fatal, callback can be registered later

*/

Quoted 9 lines
Quoted 2 lines
+                       ret = 0;
          }

Well, then it means that you don't want to touch ret at all. How about:
if (rte_intr_callback_register(&intr_handle,

                                 eal_alarm_callback, NULL) == 0)
          handler_registered = 1;
Quoted 9 lines
Quoted 1 line

?

Too much simple :)

I think we try to avoid calling a function in a "if" per coding style.
And my proposal has the benefit of offering a comment about the non-fatal error.

Quoted 5 lines

/* not fatal, callback can be registered later */
if (rte_intr_callback_register(&intr_handle,

                                eal_alarm_callback, NULL) == 0)
         handler_registered = 1;

I prefer the original. It's more explicit and conveys the intention better. Did i break the tie? :)

Quoted 8 lines
Quoted 3 lines

I was going to send a v2 with David's suggestion.
Now I'm confused.

I always tend to prefer shorter versions, so +1 for v2 (does that make it a v3? :-) )

/Bruce

Quoted 6 lines

OK, but then the suggested comment needs to be fixed. It makes it seem like registering the handler is the "non fatal" part. Perhaps something like:

/* failed register is not a fatal error - callback can be registered later */

Of course! I had prepared this:
/* registration can fail, callback can be registered later */

#9 lore raw

PATCH v2 1/1 eal/linux: fix return after alarm registration failure

In reply to Thomas Monjalon

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is not set anymore to be consistent with the behaviour.

Fixes af75078fece3 ("first public release")

---
v2: do not use variable ret

---
 lib/librte_eal/linux/eal/eal_alarm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/librte_eal/linux/eal/eal_alarm.c +4 -3
index 840ede780..0924c9205 100644
@@ -137,9 +137,10 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)
 
 	rte_spinlock_lock(&alarm_list_lk);
 	if (!handler_registered) {
-		ret |= rte_intr_callback_register(&intr_handle,
-				eal_alarm_callback, NULL);
-		handler_registered = (ret == 0) ? 1 : 0;
+		/* registration can fail, callback can be registered later */
+		if (rte_intr_callback_register(&intr_handle,
+				eal_alarm_callback, NULL) == 0)
+			handler_registered = 1;
 	}
 
 	if (LIST_EMPTY(&alarm_list))
Signature · 1 line
2.21.0
Acked-by on v2 1/1
#10 lore raw
Quoted 5 lines · On Wed, 26 Jun 2019 16:02:34 +0200 Thomas Monjalon <[email protected]> wrote:

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

Quoted 8 lines

The error code is not set anymore to be consistent with the behaviour.

Fixes af75078fece3 ("first public release")

---
v2: do not use variable ret

author Applied
#11 lore raw

27/06/2019 01:09, Stephen Hemminger:

Quoted 10 lines
Quoted 7 lines · On Wed, 26 Jun 2019 16:02:34 +0200 Thomas Monjalon <[email protected]> wrote:

When adding an alarm, if an error happen when registering the common alarm callback, it is not considered as a major failure. The alarm is then inserted in the list.
However it was returning an error code after inserting the alarm.

The error code is not set anymore to be consistent with the behaviour.

Quoted 8 lines
Quoted 6 lines
Fixes af75078fece3 ("first public release")

---
v2: do not use variable ret

Applied