Skip to content

gnrc_netif: Add bootstrap function for device setup#9329

Closed
bergzand wants to merge 14 commits intoRIOT-OS:masterfrom
bergzand:pr/netdev/layer/gnrc_netif
Closed

gnrc_netif: Add bootstrap function for device setup#9329
bergzand wants to merge 14 commits intoRIOT-OS:masterfrom
bergzand:pr/netdev/layer/gnrc_netif

Conversation

@bergzand
Copy link
Copy Markdown
Member

Contribution description

This adds a bootstrap function to the gnrc_netif initialization. This bootstrap function can be used to initialize a layered netdev structure. This way the required structures can be kept on the stack of the netif thread while keeping the total structure somewhat dynamic.

For now the bootstrap functions are empty. They are used as soon as there are separate netdev layers that require them.

Issues/PRs references

next step of #8198

@bergzand bergzand added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: network Area: Networking GNRC labels Jun 12, 2018
@bergzand bergzand requested a review from miri64 June 12, 2018 09:17
@jnohlgard
Copy link
Copy Markdown
Member

This is something that could be useful in a project I am working on. Thanks @bergzand!

dev->context = netif;
/* register the event callback with the device driver */
dev->event_callback = _event_cb;
dev->context = netif;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unrelated move?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup

Copy link
Copy Markdown
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 initial comments

*
* @param[in] args The network interface
*/
void *gnrc_netif_thread(void *args);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mhhh... Can we somehow get around exposing this function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Would it be okay to have it in sys/include/net/gnrc/netif/internal.h?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe you can use a trampoline function somehow?

*
* @param[in] args The network interface
*/
void *gnrc_netif_thread(void *args);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Line below missing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ack

typedef struct {
const gnrc_netif_ops_t *ops; /**< Operations of the network interface */
netdev_t *dev; /**< Network device of the network interface */
netdev_t *hwdev; /**< Hardware layer of the network device */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either change name of hwdev or the name and doc on dev (that is the top-layer of netdev). hwdev can be misleading if you have "virtual" devices.

static void *_bootstrap(void *args)
{
gnrc_netif_t *netif = args;
netif->hwdev = netif->dev;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why don't netif_ethernet or netif_raw require this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

gnrc_netif_ieee802154.c requires access to the ieee802154_netdev struct, for the pan_id, and sequence numbers and more. The other mac layers don't require this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If we can build a getter or something for this we can omit the whole hwdev member here altogether (solving the issue above too)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mh... if that is possible, I would prefer that. Then most of the changes in #9330 wouldn't be necessary also.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

By "make a separate layer" I mean move the sequence number, pan id, lladdr etc to a gnrc_netif_ieee802154 internal variables, or a proper layer, whichever is most feasible

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@gebart I would like to stick with the proposed solution of doing a get() call for the struct for now. I agree with your solution, but I'd rather not rework half of this PR at the moment, but do it in a follow up afterwards.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@miri64 I've implemented a getter in #9335

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good. A future possible TSCH implementation needs to use a different frame format than the traditional 802.15.4 frames use, so it would be a good improvement to decouple the framing from the device driver

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See #9335 (comment). I think something is wrong with the concept here.... The layered approach should make it possible that it doesn't matter which pointer you use. And if it's not the case the pointer change should certainly not be implemented here IMHO, but in the netdev_ieee802154 adaption PR.

netdev_t *dev)
{
return gnrc_netif_create(stack, stacksize, priority, name, dev,
gnrc_netif_thread,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not here a special _bootstrap method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probably because I forgot to correctly adapt this one

@miri64
Copy link
Copy Markdown
Member

miri64 commented Jun 12, 2018

I think lwmac and gomac also need adaptation.

@bergzand
Copy link
Copy Markdown
Member Author

I think lwmac and gomac also need adaptation.

Done!

@bergzand
Copy link
Copy Markdown
Member Author

Done!

Now even on the correct branch

@bergzand bergzand force-pushed the pr/netdev/layer/gnrc_netif branch from 378de5f to 9b9ac70 Compare July 9, 2018 10:18
@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Jul 9, 2018

Reworked a bit to contain only the minimal required for the this PR.

Also rebased to resolve the merge conflict.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Jul 9, 2018

Hi, while I agree with your approach, now after looking at it after some time, I think the name "bootstrip" might be confusing. I was searching for a while where this "bootstrap" method is called, only to realize that it is the thread handler. Maybe rename the variable to thread_run or something to clear things up?

@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Jul 9, 2018

While I agree that it might be confusing, I think that thread_run doesn't cover the full goal of the function here. Maybe thread_setup_and_run? :)

@miri64
Copy link
Copy Markdown
Member

miri64 commented Jul 9, 2018

The easiest would be thread_handler ;-). Why is thread_setup_and_run less confusing? The setup happens in the "run" method of the thread (forgive my Java/Python linguo), so why distinguish specifically?

@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Jul 9, 2018

The setup happens in the "run" method of the thread (forgive my Java/Python linguo), so why distinguish specifically?

The idea behind this "setup" function is to be able to have L2 protocol specific setup before the handling of the netif loop starts. In my case specifically to have a place to instantiate netdev structs on the stack of the netif thread.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Jul 9, 2018

I know, but what you are doing here at the moment is allowing to customize the thread handler. With a function name called setup I would expect it to be called before starting the thread handler or maybe to be the very first thing to be called within the thread handler, not the thread handler itself. "bootstrap" implies on the otherhand that it is what bootstraps the interface, which is completely wrong here also.

@bergzand
Copy link
Copy Markdown
Member Author

bergzand commented Jul 9, 2018

Okay, I was afraid that the goal of the function was not completely clear anymore.

I don't have a better idea at the moment, so I'm fine with thread_run if you think that is the better(documentation-wise) name here. gnrc_netif_ieee802154_thread_run for completeness or just thread_run?

@miri64
Copy link
Copy Markdown
Member

miri64 commented Nov 22, 2018

Needs rebase.

@stale
Copy link
Copy Markdown

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking State: stale State: The issue / PR has no activity for >185 days State: waiting for other PR State: The PR requires another PR to be merged first 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.

3 participants