[API-NEXT,PATCHv2,4/5] linux-gen: implementation of odp_load_driver function

Message ID 1478517324-11324-5-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard Nov. 7, 2016, 11:15 a.m.
Implementation of the driver loading function, of north API

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 configure.ac                                       |  4 ++--
 platform/linux-generic/include/.gitignore          |  1 +
 .../linux-generic/include/odp_platform_config.h.in | 11 +++++++++++
 platform/linux-generic/m4/configure.m4             |  1 +
 platform/linux-generic/m4/odp_drivers.m4           | 16 ++++++++++++++++
 platform/linux-generic/odp_init.c                  | 22 ++++++++++++++++++++++
 6 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 platform/linux-generic/include/.gitignore
 create mode 100644 platform/linux-generic/include/odp_platform_config.h.in
 create mode 100644 platform/linux-generic/m4/odp_drivers.m4

-- 
2.7.4

Comments

Maxim Uvarov Nov. 8, 2016, 2:06 p.m. | #1
are there any system for linux-generic platform where dlopen is not 
supported?
I think that we don't need ifdefs.

Maxim.


On 11/07/16 14:15, Christophe Milard wrote:
> Implementation of the driver loading function, of north API

>

> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

> ---

>   configure.ac                                       |  4 ++--

>   platform/linux-generic/include/.gitignore          |  1 +

>   .../linux-generic/include/odp_platform_config.h.in | 11 +++++++++++

>   platform/linux-generic/m4/configure.m4             |  1 +

>   platform/linux-generic/m4/odp_drivers.m4           | 16 ++++++++++++++++

>   platform/linux-generic/odp_init.c                  | 22 ++++++++++++++++++++++

>   6 files changed, 53 insertions(+), 2 deletions(-)

>   create mode 100644 platform/linux-generic/include/.gitignore

>   create mode 100644 platform/linux-generic/include/odp_platform_config.h.in

>   create mode 100644 platform/linux-generic/m4/odp_drivers.m4

>

> diff --git a/configure.ac b/configure.ac

> index 8942894..a92469c 100644

> --- a/configure.ac

> +++ b/configure.ac

> @@ -47,7 +47,7 @@ AC_PROG_MAKE_SET

>   

>   AM_PROG_AR

>   #Use libtool

> -LT_INIT([])

> +LT_INIT([dlopen])

>   AC_SUBST([LIBTOOL_DEPS])

>   AM_PROG_LIBTOOL

>   

> @@ -58,7 +58,7 @@ AC_CHECK_FUNCS([bzero clock_gettime gethostbyname getpagesize gettimeofday memse

>   

>   # Checks for header files.

>   AC_HEADER_RESOLV

> -AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h])

> +AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h dlfcn.h])

>   

>   # Checks for typedefs, structures, and compiler characteristics.

>   AC_HEADER_STDBOOL

> diff --git a/platform/linux-generic/include/.gitignore b/platform/linux-generic/include/.gitignore

> new file mode 100644

> index 0000000..a32f733

> --- /dev/null

> +++ b/platform/linux-generic/include/.gitignore

> @@ -0,0 +1 @@

> +odp_platform_config.h

> diff --git a/platform/linux-generic/include/odp_platform_config.h.in b/platform/linux-generic/include/odp_platform_config.h.in

> new file mode 100644

> index 0000000..3b0ed2c

> --- /dev/null

> +++ b/platform/linux-generic/include/odp_platform_config.h.in

> @@ -0,0 +1,11 @@

> +/* Copyright (c) 2016, Linaro Limited

> + * All rights reserved.

> + *

> + * SPDX-License-Identifier:     BSD-3-Clause

> + */

> +

> +/* the .h.in file is parsed by automake which performs substitutions

> + * according to the AC_SUBST macro given in m4 files.

> + */

> +

> +#define HAVE_DLFCN_H @HAVE_DLFCN_H@

> diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4

> index d3e5528..487f21e 100644

> --- a/platform/linux-generic/m4/configure.m4

> +++ b/platform/linux-generic/m4/configure.m4

> @@ -35,6 +35,7 @@ m4_include([platform/linux-generic/m4/odp_netmap.m4])

>   m4_include([platform/linux-generic/m4/odp_dpdk.m4])

>   m4_include([platform/linux-generic/m4/odp_ipc.m4])

>   m4_include([platform/linux-generic/m4/odp_schedule.m4])

> +m4_include([platform/linux-generic/m4/odp_drivers.m4])

>   

>   AC_CONFIG_FILES([platform/linux-generic/Makefile

>                    platform/linux-generic/include/odp/api/plat/static_inline.h])

> diff --git a/platform/linux-generic/m4/odp_drivers.m4 b/platform/linux-generic/m4/odp_drivers.m4

> new file mode 100644

> index 0000000..f0ceccc

> --- /dev/null

> +++ b/platform/linux-generic/m4/odp_drivers.m4

> @@ -0,0 +1,16 @@

> +##########################################################################

> +# Check for dlopen and lt equivalent availability

> +##########################################################################

> +

> +AC_SEARCH_LIBS([dlopen], [dl dld],

> +    [

> +	HAVE_DLFCN_H=1

> +	AM_LDFLAGS="$AM_LDFLAGS -ldl"

> +    ],

> +    [

> +	echo "Warning! dlopen not available: won't be able to load drivers!"

> +	HAVE_DLFCN_H=0

> +    ])

> +

> +AC_SUBST(HAVE_DLFCN_H)

> +AC_CONFIG_FILES([platform/linux-generic/include/odp_platform_config.h])

> diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c

> index d4a8e09..3dfbbc6 100644

> --- a/platform/linux-generic/odp_init.c

> +++ b/platform/linux-generic/odp_init.c

> @@ -3,6 +3,7 @@

>    *

>    * SPDX-License-Identifier:     BSD-3-Clause

>    */

> +#include <odp_platform_config.h>

>   #include <odp/api/init.h>

>   #include <odp_debug_internal.h>

>   #include <odp/api/debug.h>

> @@ -11,6 +12,10 @@

>   #include <odp_schedule_if.h>

>   #include <string.h>

>   

> +#if HAVE_DLFCN_H

> +# include <dlfcn.h>

> +#endif

> +

>   struct odp_global_data_s odp_global_data;

>   

>   int odp_init_global(odp_instance_t *instance,

> @@ -374,3 +379,20 @@ int _odp_term_local(enum init_stage stage)

>   

>   	return rc;

>   }

> +

> +int odp_load_driver(const char *filename)

> +{

> +/*

> + * If dlopen is not available, then dynamic loading is not available:

> + * return error.

> + */

> +#if HAVE_DLFCN_H

> +	if (dlopen(filename, RTLD_NOW) == NULL) {

> +		ODP_ERR("dlopen failed:%s\n", dlerror());

> +		return -1;

> +	}

> +	return 0;

> +

> +#endif

> +	return -1;

> +}
Christophe Milard Nov. 8, 2016, 2:15 p.m. | #2
On 8 November 2016 at 15:06, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> are there any system for linux-generic platform where dlopen is not

> supported?

> I think that we don't need ifdefs.


Are you saying we should limit us to plain linux? including the test??
I am not sure I agree with this really,...
Any other voices?

>

> Maxim.

>

>

>

> On 11/07/16 14:15, Christophe Milard wrote:

>>

>> Implementation of the driver loading function, of north API

>>

>> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

>> ---

>>   configure.ac                                       |  4 ++--

>>   platform/linux-generic/include/.gitignore          |  1 +

>>   .../linux-generic/include/odp_platform_config.h.in | 11 +++++++++++

>>   platform/linux-generic/m4/configure.m4             |  1 +

>>   platform/linux-generic/m4/odp_drivers.m4           | 16 ++++++++++++++++

>>   platform/linux-generic/odp_init.c                  | 22

>> ++++++++++++++++++++++

>>   6 files changed, 53 insertions(+), 2 deletions(-)

>>   create mode 100644 platform/linux-generic/include/.gitignore

>>   create mode 100644

>> platform/linux-generic/include/odp_platform_config.h.in

>>   create mode 100644 platform/linux-generic/m4/odp_drivers.m4

>>

>> diff --git a/configure.ac b/configure.ac

>> index 8942894..a92469c 100644

>> --- a/configure.ac

>> +++ b/configure.ac

>> @@ -47,7 +47,7 @@ AC_PROG_MAKE_SET

>>     AM_PROG_AR

>>   #Use libtool

>> -LT_INIT([])

>> +LT_INIT([dlopen])

>>   AC_SUBST([LIBTOOL_DEPS])

>>   AM_PROG_LIBTOOL

>>   @@ -58,7 +58,7 @@ AC_CHECK_FUNCS([bzero clock_gettime gethostbyname

>> getpagesize gettimeofday memse

>>     # Checks for header files.

>>   AC_HEADER_RESOLV

>> -AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h

>> netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h

>> sys/time.h unistd.h])

>> +AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h

>> netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h

>> sys/time.h unistd.h dlfcn.h])

>>     # Checks for typedefs, structures, and compiler characteristics.

>>   AC_HEADER_STDBOOL

>> diff --git a/platform/linux-generic/include/.gitignore

>> b/platform/linux-generic/include/.gitignore

>> new file mode 100644

>> index 0000000..a32f733

>> --- /dev/null

>> +++ b/platform/linux-generic/include/.gitignore

>> @@ -0,0 +1 @@

>> +odp_platform_config.h

>> diff --git a/platform/linux-generic/include/odp_platform_config.h.in

>> b/platform/linux-generic/include/odp_platform_config.h.in

>> new file mode 100644

>> index 0000000..3b0ed2c

>> --- /dev/null

>> +++ b/platform/linux-generic/include/odp_platform_config.h.in

>> @@ -0,0 +1,11 @@

>> +/* Copyright (c) 2016, Linaro Limited

>> + * All rights reserved.

>> + *

>> + * SPDX-License-Identifier:     BSD-3-Clause

>> + */

>> +

>> +/* the .h.in file is parsed by automake which performs substitutions

>> + * according to the AC_SUBST macro given in m4 files.

>> + */

>> +

>> +#define HAVE_DLFCN_H @HAVE_DLFCN_H@

>> diff --git a/platform/linux-generic/m4/configure.m4

>> b/platform/linux-generic/m4/configure.m4

>> index d3e5528..487f21e 100644

>> --- a/platform/linux-generic/m4/configure.m4

>> +++ b/platform/linux-generic/m4/configure.m4

>> @@ -35,6 +35,7 @@ m4_include([platform/linux-generic/m4/odp_netmap.m4])

>>   m4_include([platform/linux-generic/m4/odp_dpdk.m4])

>>   m4_include([platform/linux-generic/m4/odp_ipc.m4])

>>   m4_include([platform/linux-generic/m4/odp_schedule.m4])

>> +m4_include([platform/linux-generic/m4/odp_drivers.m4])

>>     AC_CONFIG_FILES([platform/linux-generic/Makefile

>>

>> platform/linux-generic/include/odp/api/plat/static_inline.h])

>> diff --git a/platform/linux-generic/m4/odp_drivers.m4

>> b/platform/linux-generic/m4/odp_drivers.m4

>> new file mode 100644

>> index 0000000..f0ceccc

>> --- /dev/null

>> +++ b/platform/linux-generic/m4/odp_drivers.m4

>> @@ -0,0 +1,16 @@

>>

>> +##########################################################################

>> +# Check for dlopen and lt equivalent availability

>>

>> +##########################################################################

>> +

>> +AC_SEARCH_LIBS([dlopen], [dl dld],

>> +    [

>> +       HAVE_DLFCN_H=1

>> +       AM_LDFLAGS="$AM_LDFLAGS -ldl"

>> +    ],

>> +    [

>> +       echo "Warning! dlopen not available: won't be able to load

>> drivers!"

>> +       HAVE_DLFCN_H=0

>> +    ])

>> +

>> +AC_SUBST(HAVE_DLFCN_H)

>> +AC_CONFIG_FILES([platform/linux-generic/include/odp_platform_config.h])

>> diff --git a/platform/linux-generic/odp_init.c

>> b/platform/linux-generic/odp_init.c

>> index d4a8e09..3dfbbc6 100644

>> --- a/platform/linux-generic/odp_init.c

>> +++ b/platform/linux-generic/odp_init.c

>> @@ -3,6 +3,7 @@

>>    *

>>    * SPDX-License-Identifier:     BSD-3-Clause

>>    */

>> +#include <odp_platform_config.h>

>>   #include <odp/api/init.h>

>>   #include <odp_debug_internal.h>

>>   #include <odp/api/debug.h>

>> @@ -11,6 +12,10 @@

>>   #include <odp_schedule_if.h>

>>   #include <string.h>

>>   +#if HAVE_DLFCN_H

>> +# include <dlfcn.h>

>> +#endif

>> +

>>   struct odp_global_data_s odp_global_data;

>>     int odp_init_global(odp_instance_t *instance,

>> @@ -374,3 +379,20 @@ int _odp_term_local(enum init_stage stage)

>>         return rc;

>>   }

>> +

>> +int odp_load_driver(const char *filename)

>> +{

>> +/*

>> + * If dlopen is not available, then dynamic loading is not available:

>> + * return error.

>> + */

>> +#if HAVE_DLFCN_H

>> +       if (dlopen(filename, RTLD_NOW) == NULL) {

>> +               ODP_ERR("dlopen failed:%s\n", dlerror());

>> +               return -1;

>> +       }

>> +       return 0;

>> +

>> +#endif

>> +       return -1;

>> +}

>

>
Maxim Uvarov Nov. 8, 2016, 2:24 p.m. | #3
On 11/08/16 17:15, Christophe Milard wrote:
> On 8 November 2016 at 15:06, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

>> are there any system for linux-generic platform where dlopen is not

>> supported?

>> I think that we don't need ifdefs.

> Are you saying we should limit us to plain linux? including the test??

> I am not sure I agree with this really,...

> Any other voices?


Tests should not care about dlopen. They should call api 
odp_driver_load() and if call is not supported then skip test.

Maxim.

>> Maxim.

>>

>>

>>

>> On 11/07/16 14:15, Christophe Milard wrote:

>>> Implementation of the driver loading function, of north API

>>>

>>> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

>>> ---

>>>    configure.ac                                       |  4 ++--

>>>    platform/linux-generic/include/.gitignore          |  1 +

>>>    .../linux-generic/include/odp_platform_config.h.in | 11 +++++++++++

>>>    platform/linux-generic/m4/configure.m4             |  1 +

>>>    platform/linux-generic/m4/odp_drivers.m4           | 16 ++++++++++++++++

>>>    platform/linux-generic/odp_init.c                  | 22

>>> ++++++++++++++++++++++

>>>    6 files changed, 53 insertions(+), 2 deletions(-)

>>>    create mode 100644 platform/linux-generic/include/.gitignore

>>>    create mode 100644

>>> platform/linux-generic/include/odp_platform_config.h.in

>>>    create mode 100644 platform/linux-generic/m4/odp_drivers.m4

>>>

>>> diff --git a/configure.ac b/configure.ac

>>> index 8942894..a92469c 100644

>>> --- a/configure.ac

>>> +++ b/configure.ac

>>> @@ -47,7 +47,7 @@ AC_PROG_MAKE_SET

>>>      AM_PROG_AR

>>>    #Use libtool

>>> -LT_INIT([])

>>> +LT_INIT([dlopen])

>>>    AC_SUBST([LIBTOOL_DEPS])

>>>    AM_PROG_LIBTOOL

>>>    @@ -58,7 +58,7 @@ AC_CHECK_FUNCS([bzero clock_gettime gethostbyname

>>> getpagesize gettimeofday memse

>>>      # Checks for header files.

>>>    AC_HEADER_RESOLV

>>> -AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h

>>> netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h

>>> sys/time.h unistd.h])

>>> +AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h

>>> netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h

>>> sys/time.h unistd.h dlfcn.h])

>>>      # Checks for typedefs, structures, and compiler characteristics.

>>>    AC_HEADER_STDBOOL

>>> diff --git a/platform/linux-generic/include/.gitignore

>>> b/platform/linux-generic/include/.gitignore

>>> new file mode 100644

>>> index 0000000..a32f733

>>> --- /dev/null

>>> +++ b/platform/linux-generic/include/.gitignore

>>> @@ -0,0 +1 @@

>>> +odp_platform_config.h

>>> diff --git a/platform/linux-generic/include/odp_platform_config.h.in

>>> b/platform/linux-generic/include/odp_platform_config.h.in

>>> new file mode 100644

>>> index 0000000..3b0ed2c

>>> --- /dev/null

>>> +++ b/platform/linux-generic/include/odp_platform_config.h.in

>>> @@ -0,0 +1,11 @@

>>> +/* Copyright (c) 2016, Linaro Limited

>>> + * All rights reserved.

>>> + *

>>> + * SPDX-License-Identifier:     BSD-3-Clause

>>> + */

>>> +

>>> +/* the .h.in file is parsed by automake which performs substitutions

>>> + * according to the AC_SUBST macro given in m4 files.

>>> + */

>>> +

>>> +#define HAVE_DLFCN_H @HAVE_DLFCN_H@

>>> diff --git a/platform/linux-generic/m4/configure.m4

>>> b/platform/linux-generic/m4/configure.m4

>>> index d3e5528..487f21e 100644

>>> --- a/platform/linux-generic/m4/configure.m4

>>> +++ b/platform/linux-generic/m4/configure.m4

>>> @@ -35,6 +35,7 @@ m4_include([platform/linux-generic/m4/odp_netmap.m4])

>>>    m4_include([platform/linux-generic/m4/odp_dpdk.m4])

>>>    m4_include([platform/linux-generic/m4/odp_ipc.m4])

>>>    m4_include([platform/linux-generic/m4/odp_schedule.m4])

>>> +m4_include([platform/linux-generic/m4/odp_drivers.m4])

>>>      AC_CONFIG_FILES([platform/linux-generic/Makefile

>>>

>>> platform/linux-generic/include/odp/api/plat/static_inline.h])

>>> diff --git a/platform/linux-generic/m4/odp_drivers.m4

>>> b/platform/linux-generic/m4/odp_drivers.m4

>>> new file mode 100644

>>> index 0000000..f0ceccc

>>> --- /dev/null

>>> +++ b/platform/linux-generic/m4/odp_drivers.m4

>>> @@ -0,0 +1,16 @@

>>>

>>> +##########################################################################

>>> +# Check for dlopen and lt equivalent availability

>>>

>>> +##########################################################################

>>> +

>>> +AC_SEARCH_LIBS([dlopen], [dl dld],

>>> +    [

>>> +       HAVE_DLFCN_H=1

>>> +       AM_LDFLAGS="$AM_LDFLAGS -ldl"

>>> +    ],

>>> +    [

>>> +       echo "Warning! dlopen not available: won't be able to load

>>> drivers!"

>>> +       HAVE_DLFCN_H=0

>>> +    ])

>>> +

>>> +AC_SUBST(HAVE_DLFCN_H)

>>> +AC_CONFIG_FILES([platform/linux-generic/include/odp_platform_config.h])

>>> diff --git a/platform/linux-generic/odp_init.c

>>> b/platform/linux-generic/odp_init.c

>>> index d4a8e09..3dfbbc6 100644

>>> --- a/platform/linux-generic/odp_init.c

>>> +++ b/platform/linux-generic/odp_init.c

>>> @@ -3,6 +3,7 @@

>>>     *

>>>     * SPDX-License-Identifier:     BSD-3-Clause

>>>     */

>>> +#include <odp_platform_config.h>

>>>    #include <odp/api/init.h>

>>>    #include <odp_debug_internal.h>

>>>    #include <odp/api/debug.h>

>>> @@ -11,6 +12,10 @@

>>>    #include <odp_schedule_if.h>

>>>    #include <string.h>

>>>    +#if HAVE_DLFCN_H

>>> +# include <dlfcn.h>

>>> +#endif

>>> +

>>>    struct odp_global_data_s odp_global_data;

>>>      int odp_init_global(odp_instance_t *instance,

>>> @@ -374,3 +379,20 @@ int _odp_term_local(enum init_stage stage)

>>>          return rc;

>>>    }

>>> +

>>> +int odp_load_driver(const char *filename)

>>> +{

>>> +/*

>>> + * If dlopen is not available, then dynamic loading is not available:

>>> + * return error.

>>> + */

>>> +#if HAVE_DLFCN_H

>>> +       if (dlopen(filename, RTLD_NOW) == NULL) {

>>> +               ODP_ERR("dlopen failed:%s\n", dlerror());

>>> +               return -1;

>>> +       }

>>> +       return 0;

>>> +

>>> +#endif

>>> +       return -1;

>>> +}

>>
Christophe Milard Nov. 8, 2016, 2:42 p.m. | #4
On 8 November 2016 at 15:24, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
> On 11/08/16 17:15, Christophe Milard wrote:

>>

>> On 8 November 2016 at 15:06, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

>>>

>>> are there any system for linux-generic platform where dlopen is not

>>> supported?

>>> I think that we don't need ifdefs.

>>

>> Are you saying we should limit us to plain linux? including the test??

>> I am not sure I agree with this really,...

>> Any other voices?

>

>

> Tests should not care about dlopen. They should call api odp_driver_load()

> and if call is not supported then skip test.


There are 2 underlying questions here:
1) are all linux supporting dl_open()?
My assumption is that linux does not necessarily implies dlopen(),
even if it often so. Hence the flag tests in the code.

2)What should happen on system which do not have dlopen? As
odp_driver_load() is part of the API, my assumption was that all ODP
implementation should support calls to odp_driver_load() -so that
application remains portable-, but those implementation which do not
have dl_open, will just return failures on call to odp_driver_load().
So the call test is irrelevant on such systems: what is really
important is that the test can be compiled, proving that the API
function exists. Hence the flag test in the test to skip the test at
run time when dlopen() is not supported.

Isn't the right approach? what should we do then?

Christophe

>

> Maxim.

>

>

>>> Maxim.

>>>

>>>

>>>

>>> On 11/07/16 14:15, Christophe Milard wrote:

>>>>

>>>> Implementation of the driver loading function, of north API

>>>>

>>>> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

>>>> ---

>>>>    configure.ac                                       |  4 ++--

>>>>    platform/linux-generic/include/.gitignore          |  1 +

>>>>    .../linux-generic/include/odp_platform_config.h.in | 11 +++++++++++

>>>>    platform/linux-generic/m4/configure.m4             |  1 +

>>>>    platform/linux-generic/m4/odp_drivers.m4           | 16

>>>> ++++++++++++++++

>>>>    platform/linux-generic/odp_init.c                  | 22

>>>> ++++++++++++++++++++++

>>>>    6 files changed, 53 insertions(+), 2 deletions(-)

>>>>    create mode 100644 platform/linux-generic/include/.gitignore

>>>>    create mode 100644

>>>> platform/linux-generic/include/odp_platform_config.h.in

>>>>    create mode 100644 platform/linux-generic/m4/odp_drivers.m4

>>>>

>>>> diff --git a/configure.ac b/configure.ac

>>>> index 8942894..a92469c 100644

>>>> --- a/configure.ac

>>>> +++ b/configure.ac

>>>> @@ -47,7 +47,7 @@ AC_PROG_MAKE_SET

>>>>      AM_PROG_AR

>>>>    #Use libtool

>>>> -LT_INIT([])

>>>> +LT_INIT([dlopen])

>>>>    AC_SUBST([LIBTOOL_DEPS])

>>>>    AM_PROG_LIBTOOL

>>>>    @@ -58,7 +58,7 @@ AC_CHECK_FUNCS([bzero clock_gettime gethostbyname

>>>> getpagesize gettimeofday memse

>>>>      # Checks for header files.

>>>>    AC_HEADER_RESOLV

>>>> -AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h

>>>> netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h

>>>> sys/socket.h

>>>> sys/time.h unistd.h])

>>>> +AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h

>>>> netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h

>>>> sys/socket.h

>>>> sys/time.h unistd.h dlfcn.h])

>>>>      # Checks for typedefs, structures, and compiler characteristics.

>>>>    AC_HEADER_STDBOOL

>>>> diff --git a/platform/linux-generic/include/.gitignore

>>>> b/platform/linux-generic/include/.gitignore

>>>> new file mode 100644

>>>> index 0000000..a32f733

>>>> --- /dev/null

>>>> +++ b/platform/linux-generic/include/.gitignore

>>>> @@ -0,0 +1 @@

>>>> +odp_platform_config.h

>>>> diff --git a/platform/linux-generic/include/odp_platform_config.h.in

>>>> b/platform/linux-generic/include/odp_platform_config.h.in

>>>> new file mode 100644

>>>> index 0000000..3b0ed2c

>>>> --- /dev/null

>>>> +++ b/platform/linux-generic/include/odp_platform_config.h.in

>>>> @@ -0,0 +1,11 @@

>>>> +/* Copyright (c) 2016, Linaro Limited

>>>> + * All rights reserved.

>>>> + *

>>>> + * SPDX-License-Identifier:     BSD-3-Clause

>>>> + */

>>>> +

>>>> +/* the .h.in file is parsed by automake which performs substitutions

>>>> + * according to the AC_SUBST macro given in m4 files.

>>>> + */

>>>> +

>>>> +#define HAVE_DLFCN_H @HAVE_DLFCN_H@

>>>> diff --git a/platform/linux-generic/m4/configure.m4

>>>> b/platform/linux-generic/m4/configure.m4

>>>> index d3e5528..487f21e 100644

>>>> --- a/platform/linux-generic/m4/configure.m4

>>>> +++ b/platform/linux-generic/m4/configure.m4

>>>> @@ -35,6 +35,7 @@ m4_include([platform/linux-generic/m4/odp_netmap.m4])

>>>>    m4_include([platform/linux-generic/m4/odp_dpdk.m4])

>>>>    m4_include([platform/linux-generic/m4/odp_ipc.m4])

>>>>    m4_include([platform/linux-generic/m4/odp_schedule.m4])

>>>> +m4_include([platform/linux-generic/m4/odp_drivers.m4])

>>>>      AC_CONFIG_FILES([platform/linux-generic/Makefile

>>>>

>>>> platform/linux-generic/include/odp/api/plat/static_inline.h])

>>>> diff --git a/platform/linux-generic/m4/odp_drivers.m4

>>>> b/platform/linux-generic/m4/odp_drivers.m4

>>>> new file mode 100644

>>>> index 0000000..f0ceccc

>>>> --- /dev/null

>>>> +++ b/platform/linux-generic/m4/odp_drivers.m4

>>>> @@ -0,0 +1,16 @@

>>>>

>>>>

>>>> +##########################################################################

>>>> +# Check for dlopen and lt equivalent availability

>>>>

>>>>

>>>> +##########################################################################

>>>> +

>>>> +AC_SEARCH_LIBS([dlopen], [dl dld],

>>>> +    [

>>>> +       HAVE_DLFCN_H=1

>>>> +       AM_LDFLAGS="$AM_LDFLAGS -ldl"

>>>> +    ],

>>>> +    [

>>>> +       echo "Warning! dlopen not available: won't be able to load

>>>> drivers!"

>>>> +       HAVE_DLFCN_H=0

>>>> +    ])

>>>> +

>>>> +AC_SUBST(HAVE_DLFCN_H)

>>>> +AC_CONFIG_FILES([platform/linux-generic/include/odp_platform_config.h])

>>>> diff --git a/platform/linux-generic/odp_init.c

>>>> b/platform/linux-generic/odp_init.c

>>>> index d4a8e09..3dfbbc6 100644

>>>> --- a/platform/linux-generic/odp_init.c

>>>> +++ b/platform/linux-generic/odp_init.c

>>>> @@ -3,6 +3,7 @@

>>>>     *

>>>>     * SPDX-License-Identifier:     BSD-3-Clause

>>>>     */

>>>> +#include <odp_platform_config.h>

>>>>    #include <odp/api/init.h>

>>>>    #include <odp_debug_internal.h>

>>>>    #include <odp/api/debug.h>

>>>> @@ -11,6 +12,10 @@

>>>>    #include <odp_schedule_if.h>

>>>>    #include <string.h>

>>>>    +#if HAVE_DLFCN_H

>>>> +# include <dlfcn.h>

>>>> +#endif

>>>> +

>>>>    struct odp_global_data_s odp_global_data;

>>>>      int odp_init_global(odp_instance_t *instance,

>>>> @@ -374,3 +379,20 @@ int _odp_term_local(enum init_stage stage)

>>>>          return rc;

>>>>    }

>>>> +

>>>> +int odp_load_driver(const char *filename)

>>>> +{

>>>> +/*

>>>> + * If dlopen is not available, then dynamic loading is not available:

>>>> + * return error.

>>>> + */

>>>> +#if HAVE_DLFCN_H

>>>> +       if (dlopen(filename, RTLD_NOW) == NULL) {

>>>> +               ODP_ERR("dlopen failed:%s\n", dlerror());

>>>> +               return -1;

>>>> +       }

>>>> +       return 0;

>>>> +

>>>> +#endif

>>>> +       return -1;

>>>> +}

>>>

>>>

>

Patch

diff --git a/configure.ac b/configure.ac
index 8942894..a92469c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,7 +47,7 @@  AC_PROG_MAKE_SET
 
 AM_PROG_AR
 #Use libtool
-LT_INIT([])
+LT_INIT([dlopen])
 AC_SUBST([LIBTOOL_DEPS])
 AM_PROG_LIBTOOL
 
@@ -58,7 +58,7 @@  AC_CHECK_FUNCS([bzero clock_gettime gethostbyname getpagesize gettimeofday memse
 
 # Checks for header files.
 AC_HEADER_RESOLV
-AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h])
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h limits.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h dlfcn.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_HEADER_STDBOOL
diff --git a/platform/linux-generic/include/.gitignore b/platform/linux-generic/include/.gitignore
new file mode 100644
index 0000000..a32f733
--- /dev/null
+++ b/platform/linux-generic/include/.gitignore
@@ -0,0 +1 @@ 
+odp_platform_config.h
diff --git a/platform/linux-generic/include/odp_platform_config.h.in b/platform/linux-generic/include/odp_platform_config.h.in
new file mode 100644
index 0000000..3b0ed2c
--- /dev/null
+++ b/platform/linux-generic/include/odp_platform_config.h.in
@@ -0,0 +1,11 @@ 
+/* Copyright (c) 2016, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier:     BSD-3-Clause
+ */
+
+/* the .h.in file is parsed by automake which performs substitutions
+ * according to the AC_SUBST macro given in m4 files.
+ */
+
+#define HAVE_DLFCN_H @HAVE_DLFCN_H@
diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4
index d3e5528..487f21e 100644
--- a/platform/linux-generic/m4/configure.m4
+++ b/platform/linux-generic/m4/configure.m4
@@ -35,6 +35,7 @@  m4_include([platform/linux-generic/m4/odp_netmap.m4])
 m4_include([platform/linux-generic/m4/odp_dpdk.m4])
 m4_include([platform/linux-generic/m4/odp_ipc.m4])
 m4_include([platform/linux-generic/m4/odp_schedule.m4])
+m4_include([platform/linux-generic/m4/odp_drivers.m4])
 
 AC_CONFIG_FILES([platform/linux-generic/Makefile
                  platform/linux-generic/include/odp/api/plat/static_inline.h])
diff --git a/platform/linux-generic/m4/odp_drivers.m4 b/platform/linux-generic/m4/odp_drivers.m4
new file mode 100644
index 0000000..f0ceccc
--- /dev/null
+++ b/platform/linux-generic/m4/odp_drivers.m4
@@ -0,0 +1,16 @@ 
+##########################################################################
+# Check for dlopen and lt equivalent availability
+##########################################################################
+
+AC_SEARCH_LIBS([dlopen], [dl dld],
+    [
+	HAVE_DLFCN_H=1
+	AM_LDFLAGS="$AM_LDFLAGS -ldl"
+    ],
+    [
+	echo "Warning! dlopen not available: won't be able to load drivers!"
+	HAVE_DLFCN_H=0
+    ])
+
+AC_SUBST(HAVE_DLFCN_H)
+AC_CONFIG_FILES([platform/linux-generic/include/odp_platform_config.h])
diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index d4a8e09..3dfbbc6 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -3,6 +3,7 @@ 
  *
  * SPDX-License-Identifier:     BSD-3-Clause
  */
+#include <odp_platform_config.h>
 #include <odp/api/init.h>
 #include <odp_debug_internal.h>
 #include <odp/api/debug.h>
@@ -11,6 +12,10 @@ 
 #include <odp_schedule_if.h>
 #include <string.h>
 
+#if HAVE_DLFCN_H
+# include <dlfcn.h>
+#endif
+
 struct odp_global_data_s odp_global_data;
 
 int odp_init_global(odp_instance_t *instance,
@@ -374,3 +379,20 @@  int _odp_term_local(enum init_stage stage)
 
 	return rc;
 }
+
+int odp_load_driver(const char *filename)
+{
+/*
+ * If dlopen is not available, then dynamic loading is not available:
+ * return error.
+ */
+#if HAVE_DLFCN_H
+	if (dlopen(filename, RTLD_NOW) == NULL) {
+		ODP_ERR("dlopen failed:%s\n", dlerror());
+		return -1;
+	}
+	return 0;
+
+#endif
+	return -1;
+}