Skip to content

Conversation

jia200x
Copy link
Member

@jia200x jia200x commented Jan 28, 2020

Contribution description

This PR defines a gnrc_netif_single function that indicates if there's only one GNRC network interface.
It has the same purpose of GNRC_NETIF_NUMOF == 1 but having it as a function makes the migration to #12994 easier.
I also rearranged some functions to use standard ifs instead of macros, so the code is more readable and can be checked by static tests.

Testing procedure

  • make doc
  • Check that generates the same binaries when changing GNRC_NETIF_NUMOF

Issues/PRs references

@jia200x jia200x added Area: network Area: Networking Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels Jan 28, 2020
@jia200x jia200x requested a review from miri64 January 28, 2020 20:08
@miri64
Copy link
Member

miri64 commented Jan 28, 2020

In general 👍. I'm not 100% sure about the name, but maybe some sleep gets me over that. I also want to make some sample checks if the size does not change.

@jia200x
Copy link
Member Author

jia200x commented Jan 29, 2020

hmmmm maybe gnrc_netif_single_instance()?

@miri64
Copy link
Member

miri64 commented Jan 29, 2020

hmmmm maybe gnrc_netif_single_instance()?

My problem with both this name and the one proposed in the PR, is that it implies to me that the function returns true if there is a single interface / instance. I.e. with the rework in #12994 I would expect the function to return gnrc_netif_iter(NULL)->next == NULL. This, as far as I understand, can't be the case: The result must be statically dependent on GNRC_NETIF_NUMOF/GNRC_NETIF_SINGLE. Otherwise we lose the optimization advantage.

@miri64
Copy link
Member

miri64 commented Jan 29, 2020

gnrc_netif_there_can_be_only_one()? gnrc_netif_highlander()? 😅

@@ -333,7 +333,7 @@ static inline bool gnrc_netif_is_rtr_adv(const gnrc_netif_t *netif)
* @brief Checks if the interface uses a protocol that requires 6Lo to run
*
* @attention Requires prior locking
* @note Assumed to be true, when @ref GNRC_NETIF_NUMOF == 1 and
* @note Assumed to be true, when @ref gnrc_netif_single return true and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent of the name

Suggested change
* @note Assumed to be true, when @ref gnrc_netif_single return true and
* @note Assumed to be true, when @ref gnrc_netif_single() return true and

@miri64
Copy link
Member

miri64 commented Jan 29, 2020

gnrc_netif_there_can_be_only_one()? gnrc_netif_highlander()? sweat_smile

The more I think about it: Does anything speak against this joke (gnrc_netif_highlander())? It wouldn't be the first pop-culture reference in software engineering, it references the fact, that there can be only one interface, and gives enough pause compared to gnrc_netif_single() that a dev will look up the doc if they really are unsure what this function is doing.

@jia200x
Copy link
Member Author

jia200x commented Jan 29, 2020

The more I think about it: Does anything speak against this joke (gnrc_netif_highlander())? It wouldn't be the first pop-culture reference in software engineering, it references the fact, that there can be only one interface, and gives enough pause compared to gnrc_netif_single() that a dev will look up the doc if they really are unsure what this function is doing.

+1 on my side :P

@miri64
Copy link
Member

miri64 commented Jan 29, 2020

Then lets go ahead with that :-)

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a closer glance, apart from the rename, there are some issues other issues:

Comment on lines 275 to 280
if(GNRC_NETIF_NUMOF == 1) {
return true;
}
else {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be boiled down to

return (GNRC_NETIF_NUMOF == 1);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have enough coffee that day

return gnrc_netif_is_rtr(netif) && gnrc_netif_is_6ln(netif);
/* if flag checkers even evaluate, otherwise just assume their result */
if (GNRC_IPV6_NIB_CONF_6LR && (IS_USED(MODULE_GNRC_IPV6_ROUTER) ||
(GNRC_NETIF_NUMOF > 1) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(GNRC_NETIF_NUMOF > 1) ||
(!gnrc_netif_single()) ||

Comment on lines 351 to 368
if((!gnrc_netif_single() &&
IS_USED(MODULE_GNRC_SIXLOWPAN)) || \
IS_USED(MODULE_GNRC_SIXLOENC)) {
switch (netif->device_type) {
#ifdef MODULE_GNRC_SIXLOENC
case NETDEV_TYPE_ETHERNET:
return (netif->flags & GNRC_NETIF_FLAGS_6LO);
#endif
case NETDEV_TYPE_IEEE802154:
case NETDEV_TYPE_CC110X:
case NETDEV_TYPE_BLE:
case NETDEV_TYPE_NRFMIN:
case NETDEV_TYPE_ESP_NOW:
return true;
default:
return false;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked the memory impact of moving this to static inline? examples/gnrc_border_router should be the application to look at.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it increased. The last commit fixes that problem (gnrc_netif_is_6lo is still static inline but I added a non-static function to check if the device requires 6Lo).

Now gnrc_border_router has the same size with and without this PR :)

@jia200x jia200x changed the title gnrc_netif: add gnrc_netif_single function gnrc_netif: add gnrc_netif_highlander function Feb 7, 2020
@jia200x
Copy link
Member Author

jia200x commented Mar 5, 2020

@miri64 may I squash?

@miri64
Copy link
Member

miri64 commented Mar 5, 2020

Yes, please!

@jia200x
Copy link
Member Author

jia200x commented Mar 6, 2020

done :)

@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 6, 2020
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with make all. The binaries for examples/gnrc_networking / examples/gnrc_border_router do have the same size, but their make objdump output differs (this might have different reasons though). For unification it could make sense to also adapt gnrc_netif_is_6ln() to the new style, but this can also be done in a follow-up cleanup.

@jia200x
Copy link
Member Author

jia200x commented Mar 10, 2020

There were some errors due to functions defined with macros. Instead of adding "(void)" here and there, I changed those functions to their inline variant.

@jia200x jia200x removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 10, 2020
@jia200x
Copy link
Member Author

jia200x commented Mar 10, 2020

Let's merge #13605 first

@jia200x jia200x added the State: waiting for other PR State: The PR requires another PR to be merged first label Mar 10, 2020
@leandrolanzieri leandrolanzieri added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 12, 2020
@leandrolanzieri
Copy link
Contributor

Let's merge #13605 first

Merged

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: waiting for other PR State: The PR requires another PR to be merged first labels Mar 12, 2020
@miri64
Copy link
Member

miri64 commented Mar 12, 2020

No need to let Murdock run this twice ;-).

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some style nits were introduced. Also, one style fix is possible without much notice.

@jia200x
Copy link
Member Author

jia200x commented Mar 12, 2020

Done. When I squash, I will also change the commit that introduces the function to reflect the new name of the function.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Murdock's not happy.

else {
/* XXX this is just a work-around ideally this should be defined in some
* run-time interface configuration */
DEBUG("auto_init_gnrc_rpl: please specify an interface" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are removing a space here. The \ is also not necessary.

Suggested change
DEBUG("auto_init_gnrc_rpl: please specify an interface" \
DEBUG("auto_init_gnrc_rpl: please specify an interface "

@leandrolanzieri
Copy link
Contributor

@jia200x this needs rebasing now

@jia200x jia200x force-pushed the pr/gnrc_netif_single branch from 7ca3efb to c2e491d Compare March 17, 2020 09:54
@jia200x
Copy link
Member Author

jia200x commented Mar 17, 2020

squashed and rebased

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Let's finally merge this! The line noted can also be fixed as a follow-up.

Comment on lines +80 to +83
#ifdef MODULE_GNRC_SIXLOENC
case NETDEV_TYPE_ETHERNET:
return (netif->flags & GNRC_NETIF_FLAGS_6LO);
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory this can also use link-time optimization as well:

        case NETDEV_TYPE_ETHERNET:
            if (IS_USED(MODULE_GNRC_SIXLOENC)) {
                return (netif->flags & GNRC_NETIF_FLAGS_6LO);
            }
            /* intentionally falls through */

@miri64 miri64 merged commit 171907d into RIOT-OS:master Mar 17, 2020
@leandrolanzieri leandrolanzieri added this to the Release 2020.04 milestone Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants