Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: make auto_init_ng_netif less board-dependant #2901

Merged
merged 4 commits into from
May 18, 2015

Conversation

kaspar030
Copy link
Contributor

PR for #2900, IMHO improves #2891.

This is work in progress, let's please discuss the concept.

I've adapted ng_at86rf2xx and xbee but only the iot-lab_M3 node.
Couldn't test xbee for lack of device.

@kaspar030 kaspar030 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 Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR labels May 1, 2015
/**
* @name AT86RF231 configuration
*/
static const at86rf2xx_params_t at86rf2xx_params[] =
Copy link
Member

Choose a reason for hiding this comment

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

indentation

@miri64
Copy link
Member

miri64 commented May 1, 2015

Can we find a solution that has less code duplication AND does not need any arrays stored in memory?

@kaspar030
Copy link
Contributor Author

@authmillenon Where does this store arrays in memory?

Only the device structs are stored in memory, but they have to.

AT86RF231_SLEEP,
AT86RF231_SPI_CLK,
},
};
Copy link
Member

Choose a reason for hiding this comment

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

@authmillenon Where does this store arrays in memory?

here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This get's optimized out.

@miri64
Copy link
Member

miri64 commented May 1, 2015

Only the device structs are stored in memory, but they have to.

Yes but not for the whole run-time as global constants IMHO.

@kaspar030
Copy link
Contributor Author

Only the device structs are stored in memory, but they have to.

Yes but not for the whole run-time as global constants IMHO.

They are driver-specific state variables. If they get stored in memory, that's how the driver has been implemented.

@miri64
Copy link
Member

miri64 commented May 1, 2015

Have look at this example:

#include <stdio.h>

#define ARRAY_SIZE  (2)

struct test {
    int one;
    int two;
};

const struct test t_array[] = {
    { 1, 2 },
    { 2, 3 },
};

void output(const struct test *t, size_t t_size) {
    for (int i = 0; i < t_size; i++) {
        printf("one: %d; two: %d\n", t[i].one, t[i].two);
    }
}

int main(int argc, char **argv) {
    output(t_array, ARRAY_SIZE);
}
   text    data     bss     dec     hex filename
   1406     560       8    1974     7b6 main

vs.

#include <stdio.h>

#define ARRAY_SIZE  (2)

struct test {
    int one;
    int two;
};

#define ARRAY (struct test[]){ \
    { 1, 2 }, \
    { 2, 3 }, \
}

void output(const struct test *t, size_t t_size) {
    for (int i = 0; i < t_size; i++) {
        printf("one: %d; two: %d\n", t[i].one, t[i].two);
    }
}

int main(int argc, char **argv) {
    output(ARRAY, ARRAY_SIZE);
}
   text    data     bss     dec     hex filename
   1394     560       8    1962     7aa main

@miri64
Copy link
Member

miri64 commented May 1, 2015

Interesting… I'm a little bit surprised, that the text section is shrinking... not the bss section oO

Compiler was clang btw

@miri64
Copy link
Member

miri64 commented May 1, 2015

However, the current device init-functions do not allow for that currently. But since you introduce this structs anyways, we can save parameters and just define them with your param struct.

@miri64
Copy link
Member

miri64 commented May 1, 2015

You are however propably right about the optimization when I look at the bss section ;-)

@kaspar030
Copy link
Contributor Author

@authmillenon gcc compiles like this: (main.c is the const array example, main2.c the second with #define ARRAY):

[kaspar@localhost hello-world]$ gcc -std=c99 main.c -Os -o main
[kaspar@localhost hello-world]$ gcc -std=c99 main2.c -Os -o main2
[kaspar@localhost hello-world]$ size main
   text    data     bss     dec     hex filename
   1360     560       8    1928     788 main
[kaspar@localhost hello-world]$ size main2
   text    data     bss     dec     hex filename
   1366     560       8    1934     78e main2
[kaspar@localhost hello-world]$ 

static void start_nomac(char *stack, int stack_size, ng_netdev_t *device, const char* name) {
/* starting NOMAC */
DEBUG("Start NOMAC layer for dev %s\n", name);
ng_nomac_init(stack, stack_size, MAC_PRIO, name,
Copy link
Member

Choose a reason for hiding this comment

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

What if other MAC layers than nomac want to be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uff. All the configurability, all the time.

Either #define AT86RF2XX_MAC NOMAC or another field in *_params, then a switch(...) over it. The first would be global for all devices of one type, the second would allow for two devices with different MAC layers.

Let's cross that bridge as soon as we have a) a second MAC layer, b) a use case.

Copy link
Member

Choose a reason for hiding this comment

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

Basically we need a mapping from MAC to device somewhere. I think it's safe to neglect the case of multiple radios of the same type with different MAC protocols for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it must be possible for a board, to specify the MAC layer that should be used, e.g. BOARD A, driver A, MAC A - BOARD B, driver A, MAC B... That is something, that we will see in the foreseeable future...

Copy link
Member

Choose a reason for hiding this comment

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

Sure.

Copy link
Member

Choose a reason for hiding this comment

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

Even for the same board this is required.

@kaspar030
Copy link
Contributor Author

However, the current device init-functions do not allow for that currently. But since you introduce this structs anyways, we can save parameters and just define them with your param struct.

well, that could be a next step.

@kaspar030
Copy link
Contributor Author

So you approve the concept? @haukepetersen what do you think?

@miri64
Copy link
Member

miri64 commented May 1, 2015

So you approve the concept?

Only problem laying still around is #2901 (comment)

@kaspar030
Copy link
Contributor Author

Only problem laying still around is #2901 (comment)

Easy to solve as soon as there's a second option for the MAC layer.

@miri64
Copy link
Member

miri64 commented May 1, 2015

I'd prefer to see your solution now :-).

@kaspar030
Copy link
Contributor Author

It's already in there and works with all available MAC layers. :-)

@miri64
Copy link
Member

miri64 commented May 1, 2015

No seriously? How do you propose to work with multiple MAC layers? Let's say the user wants at86rf2xx[0] to use nomac, at86rf2xx[1] ieee802154e, and xbee[0] nomac, too.

@kaspar030
Copy link
Contributor Author

in e.g., xbee_params.h:

static const netlayer_nr_typt_t xbee_mac_layers[XBEE_NUM] = { MAC_LAYER_NOMAC, MAC_LAYER_802154 }

in auto_init_ng_netif.c:

maclayer_start_functions[xbee_mac_layers[i]](xbee_dev);

@kaspar030
Copy link
Contributor Author

But anyhow, I'd rather go for selecting a sane standard MAC layer and not use auto_init for the special cases. Choice is good but not if it complicates 99% of the use cases.

#include "net/ng_nomac.h"
#include "net/ng_netbase.h"

#define ENABLE_DEBUG 1
Copy link
Member

Choose a reason for hiding this comment

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

(0)

@kaspar030
Copy link
Contributor Author

Should I squash this?

@kaspar030
Copy link
Contributor Author

@OlegHahm did you retry the xbee test?

@OlegHahm
Copy link
Member

I just did. Builds without problem on my system. Pleas squash.

@kaspar030 kaspar030 force-pushed the fix_auto_init_netif branch from f1bbc67 to 481a5b8 Compare May 12, 2015 16:44
@kaspar030
Copy link
Contributor Author

  • squashed

@kaspar030 kaspar030 removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label May 12, 2015
@kaspar030
Copy link
Contributor Author

@haukepetersen ping

@OlegHahm
Copy link
Member

Please rebase and add USEMODULE += fix_auto_init_netif to tests/driver_kw2xrf/Makefile.

ACK then. Let's get this merged.

@jonas-rem
Copy link
Contributor

I already prepared a new PR to adapt kw2xrf to this auto-init poperly. Will open when this is merged.

@OlegHahm
Copy link
Member

Cool! 👍

@kaspar030 kaspar030 force-pushed the fix_auto_init_netif branch from 481a5b8 to fa4bdd9 Compare May 17, 2015 19:02
@kaspar030
Copy link
Contributor Author

add USEMODULE += fix_auto_init_netif to tests/driver_kw2xrf/Makefile.

I fixed the problem differently: the auto_init_* functions where called whenever a radio module was selected, but the auto_init_ng_module wasn't linked in. Fixed. Pls have a quick look, then I'll squash.

@OlegHahm
Copy link
Member

Had a quick look. I'm fine. Go squashing.

@kaspar030 kaspar030 force-pushed the fix_auto_init_netif branch from fa4bdd9 to 8e1370b Compare May 17, 2015 19:23
@kaspar030
Copy link
Contributor Author

The last commit doesn't squash easily, so I just fixed the commit message.

@jonas-rem
Copy link
Contributor

@kaspar030 @OlegHahm I think Travis had an unrelated error. Could someone kick Travis?

@kaspar030
Copy link
Contributor Author

So this was ACKed? travis is happy...

@OlegHahm
Copy link
Member

I say ACK and as far as I understood @haukepetersen, he doesn't NACK.

@kaspar030
Copy link
Contributor Author

allright, then GO.

kaspar030 added a commit that referenced this pull request May 18, 2015
network: make auto_init_ng_netif less board-dependant
@kaspar030 kaspar030 merged commit 895b629 into RIOT-OS:master May 18, 2015
@kaspar030 kaspar030 deleted the fix_auto_init_netif branch May 18, 2015 11:09
@OlegHahm
Copy link
Member

🍻 🎈 🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking 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