[dpdk-dev] rte_eal_init() behavior

Bao-Long Tran tranbaolong at niometrics.com
Fri Nov 15 10:28:58 CET 2019


Hi,

In most of the examples, the argc and argv from main are passed directly
to rte_eal_init(). This has the implication that argv[0] is the program
name. When a user crafts his own argv, he must submit a placeholder at
argv[0] as well, or else the EAL parameters won't be parsed correctly.

Below is a minimal demonstration. It requests 1 lcore, but EAL
initializes all available lcores instead. If I put in some placeholder,
then it's working as expected.

#include <stdio.h> 
#include <string.h> 
#include <rte_eal.h>
#include <rte_lcore.h>

int main(void) 
{
        int argc = 0;
        char *argv[4];

        // if we don't add "foo", EAL won't initialize correctly
        //argv[argc++] = strdup("foo"); 
        argv[argc++] = strdup("-l 0");

        if (rte_eal_init(argc, argv) < 0)
                rte_exit(EXIT_FAILURE, "EAL initialization error\n");

        printf("%s: lcore count specificed: 1, got: %u\n", 
                1 == rte_lcore_count() ? "PASS" : "FAIL", 
                rte_lcore_count());

        return 0; 
}

If I'm not mistaken, this behavior is not documented anywhere, including
the source code or API. It is also totally silent, no warning
whatsoever. I guess one way to make sure that rte_eal_init() was
correctly executed is to compare its return value to the number of args
passed in, but this is too cumbersome and in fact most of the examples
don't do it.

I suggest we should document this behavior, and maybe fix it so that
users won't need to pass in a placeholder.

--BL


More information about the dev mailing list