Skip to content

Conversation

jia200x
Copy link
Member

@jia200x jia200x commented Dec 19, 2019

Contribution description

This PR is an implementation of the ideas proposed in #9903

It removes the internal allocation of gnrc_netif_t objects in gnrc_netif and assumes the gnrc_netif_xxx_create caller allocates the network interface. This means the allocation is decentralized and we move to a linked list approach for gnrc_netif_numof and gnrc_netif_iter (as described in #9903)

Some benefits:

  • No need to do tricks for incrementing the number of interfaces. Just call gnrc_netif_xxx_create and they will be in the linked list :)
  • Auto init can define the number of interfaces depending of the number of devices (e.g 2 IEEE802.15.4 interfaces if there are 2 AT86RF2XX radios)
  • A little bit less of ROM and RAM, since it's safe to assume the pointers are always there.

I added a GNRC_NETIF_SINGLE macro (as proposed in #9903) to keep the optimizations when there's a single interface.

Testing procedure

This should be carefully tested. Probably 95% of testing here is just compile tests, but it would be nice to ensure that the single interface optimization (GNRC_NETIF_SINGLE) still works as the original GNRC_NETIF_NUMOF==1.

Also, ensure that the devices still work.

Issues/PRs references

#9903
Alternative to #12308
Fixes stuff like #11979

@jia200x jia200x added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet labels Dec 19, 2019
if ((netif == NULL) && (_netifs[i].ops == NULL)) {
netif = &_netifs[i];
}
if(DEVELHELP && GNRC_NETIF_SINGLE && netif_iter(NULL)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if(DEVELHELP && GNRC_NETIF_SINGLE && netif_iter(NULL)) {
if (DEVELHELP && GNRC_NETIF_SINGLE && netif_iter(NULL)) {

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

@jia200x jia200x changed the title [WIP] gnrc_netif: implementation of dynamic GNRC_NETIF_NUMOF approach gnrc_netif: implementation of dynamic GNRC_NETIF_NUMOF approach Jan 6, 2020
@jia200x jia200x removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Jan 6, 2020
@jia200x
Copy link
Member Author

jia200x commented Jan 6, 2020

I removed the WIP label

@jia200x jia200x force-pushed the pr/gnrc_netif_desc_alloc branch from 92779d5 to b13c746 Compare January 6, 2020 10:47
Copy link
Member

@smlng smlng left a comment

Choose a reason for hiding this comment

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

to me it looks like all *_create functions can be changed from int to void as always 0 is returned. Otherwise, nice work!

@jia200x
Copy link
Member Author

jia200x commented Jan 27, 2020

@smlng solved. In order to rebase, I will need to squash. May I?

@smlng
Copy link
Member

smlng commented Jan 27, 2020

yeah, please squash and rebase.

@jia200x jia200x force-pushed the pr/gnrc_netif_desc_alloc branch 3 times, most recently from 98d4c1c to 4a503e9 Compare January 27, 2020 09:55
@jia200x
Copy link
Member Author

jia200x commented Jan 27, 2020

@smlng done!

miri64
miri64 previously requested changes Jan 28, 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.

IMHO at least examples/gnrc_minimal should use the new macro, better would be if the build system could detect somehow how many network devices there are and set it if it is only one.

@@ -38,6 +38,10 @@ extern "C" {
*/
#define NETDEV_MSG_TYPE_EVENT (0x1234)

#ifndef GNRC_NETIF_SINGLE
#define GNRC_NETIF_SINGLE (0)
#endif
Copy link
Member

Choose a reason for hiding this comment

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

This should be exposed in sys/include/net/gnrc/netif/conf.h IMHO! This is an important optimization option that should not be hidden (also I think its usage isn't localized to the gnrc_netif module, no?)

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed

Copy link
Member

Choose a reason for hiding this comment

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

Ping?

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

netif = &_netifs[i];
}
if (DEVELHELP && GNRC_NETIF_SINGLE && netif_iter(NULL)) {
DEBUG("gnrc_netif: GNRC_NETIF_SINGLE set but more than one interface is being registered.");
Copy link
Member

Choose a reason for hiding this comment

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

Make this a LOG_WARNING (also line length!)

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

if ((netif == NULL) && (_netifs[i].ops == NULL)) {
netif = &_netifs[i];
}
if (DEVELHELP && GNRC_NETIF_SINGLE && netif_iter(NULL)) {
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
if (DEVELHELP && GNRC_NETIF_SINGLE && netif_iter(NULL)) {
if (IS_ACTIVE(DEVELHELP) && GNRC_NETIF_SINGLE && netif_iter(NULL)) {

Copy link
Member

Choose a reason for hiding this comment

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

Ping

Copy link
Member Author

Choose a reason for hiding this comment

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

done! I also added IS_ACTIVE to GNRC_NETIF_SINGLE

Copy link
Member Author

Choose a reason for hiding this comment

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

hmmm maybe is cleaner to change here that GNRC_NETIF_SINGLE to the gnrc_netif_highlander call.

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

}
if (DEVELHELP && GNRC_NETIF_SINGLE && netif_iter(NULL)) {
DEBUG("gnrc_netif: GNRC_NETIF_SINGLE set but more than one interface is being registered.");
assert(false);
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
assert(false);
assert(netif_iter(NULL) == NULL);

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

@@ -24,7 +24,7 @@
#include "net/netdev_test.h"
#include "od.h"

static netdev_test_t _devs[GNRC_NETIF_NUMOF];
static netdev_test_t _devs[4];
Copy link
Member

Choose a reason for hiding this comment

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

This needs a new internal define in common.h!

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 forgot to add it during the PR cleanup phase

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

@jia200x
Copy link
Member Author

jia200x commented Jan 28, 2020

Let's merge #13226 first

@jia200x jia200x added the State: waiting for other PR State: The PR requires another PR to be merged first label Jan 28, 2020
@jia200x jia200x force-pushed the pr/gnrc_netif_desc_alloc branch from 4a503e9 to 31be76e Compare March 17, 2020 13:16
@jia200x
Copy link
Member Author

jia200x commented Mar 27, 2020

strange... do you have the GNRC_NETIF_SINGLE option enabled?

@jia200x
Copy link
Member Author

jia200x commented Mar 27, 2020

anyway, I will investigate

@benpicco
Copy link
Contributor

Indeed when I set CFLAGS += -DGNRC_NETIF_SINGLE=1 I can ping without specifying the interface.

@jia200x
Copy link
Member Author

jia200x commented Mar 27, 2020

ok, then I think I know what happened. The gnrc_netif_highlander() function is wrong.
It should be something like this:

if (IS_ACTIVE(GNRC_NETIF_SINGLE)) {
    return true;
}
else {
    return gnrc_netif_numof() == 1;
}

@jia200x
Copy link
Member Author

jia200x commented Mar 27, 2020

could you quickly check if that works for you? If so, I can open a PR (unless you are faster)

@benpicco
Copy link
Contributor

Yes this works!

@jia200x
Copy link
Member Author

jia200x commented Mar 27, 2020

I'm on it

@jia200x
Copy link
Member Author

jia200x commented Mar 27, 2020

It's there: #13736

@leandrolanzieri
Copy link
Contributor

Similarly to the above, the test for emcute is failing, but it works when
CFLAGS += -DGNRC_NETIF_SINGLE=1.

Run test case
{'data_len_end': 503,
 'data_len_start': 0,
 'data_len_step': 50,
 'mode': 'sub',
 'qos_level': 0,
 'topic_name': '/test'}

Traceback (most recent call last):
  File "/home/leandro/Work/RIOT/tests/emcute/tests/01-run.py", line 482, in <module>
    sys.exit(run(testfunc, timeout=TIMEOUT, echo=False))
  File "/home/leandro/Work/RIOT/dist/pythonlibs/testrunner/__init__.py", line 30, in run
    testfunc(child)
  File "/home/leandro/Work/RIOT/tests/emcute/tests/01-run.py", line 473, in testfunc
    server.run()
  File "/usr/local/lib/python3.7/dist-packages/scapy/automaton.py", line 994, in run
    six.reraise(c.exc_info[0], c.exc_info[1], c.exc_info[2])
  File "/usr/local/lib/python3.7/dist-packages/scapy/modules/six.py", line 697, in reraise
    raise value
  File "/usr/local/lib/python3.7/dist-packages/scapy/automaton.py", line 836, in _do_control
    state = next(iterator)
  File "/usr/local/lib/python3.7/dist-packages/scapy/automaton.py", line 873, in _do_iter
    result=state_output, state=self.state.state)  # noqa: E501
scapy.automaton.ErrorState: Reached MESSAGE_TIMEOUT: ['\nCONNECT timed out']
make: *** [/home/leandro/Work/RIOT/tests/emcute/../../Makefile.include:733: test] Error 1

yan-foto added a commit to yan-foto/RIOT that referenced this pull request Sep 14, 2020
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
yan-foto added a commit to yan-foto/RIOT that referenced this pull request Oct 23, 2020
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to yan-foto/RIOT that referenced this pull request Jan 6, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to yan-foto/RIOT that referenced this pull request Jan 6, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to yan-foto/RIOT that referenced this pull request Jan 24, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to yan-foto/RIOT that referenced this pull request Jan 24, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to Pairarma/RIOT that referenced this pull request Jan 27, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to Pairarma/RIOT that referenced this pull request Jan 27, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to Pairarma/RIOT that referenced this pull request Jan 31, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to Pairarma/RIOT that referenced this pull request Jan 31, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to yan-foto/RIOT that referenced this pull request Feb 1, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to yan-foto/RIOT that referenced this pull request Feb 1, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
Pairarma pushed a commit to yan-foto/RIOT that referenced this pull request Feb 1, 2022
'GNRC_NETIF_NUMOF' has been removed in PR RIOT-OS#12994. The solution applied
here has been adapted from a patch applied to (deprecated) 'ndn-riot'
package [1]. From now on, it is the responsibility of the programmer
to indicate how many interfaces are available/usable.

[1] https://github.com/RIOT-OS/RIOT/pull/12994/files#diff-5c72dbe2d11f0fdf149c8a398c1175c3
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 CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants