Getting kernel CONFIG_* values in userspace - Linux

This is a discussion on Getting kernel CONFIG_* values in userspace - Linux ; I have a userspace program that calls into a kernel module, but the kernel module can have several variants depending on the value of several CONFIG variables selected at kernel build time. The userspace tool needs to change to accomodate ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Getting kernel CONFIG_* values in userspace

  1. Getting kernel CONFIG_* values in userspace

    I have a userspace program that calls into a kernel module, but the
    kernel module can have several variants depending on the value of
    several CONFIG variables selected at kernel build time. The userspace
    tool needs to change to accomodate this, so I want to get access to the
    CONFIG variables either at runtime or when building the userspace tool.
    But what's the best way to do that?

    One idea is just to have the kernel module write the appropriate
    CONFIG_ variables to a header file that would be included by the
    userspace tool, but I wondered if there is some standard way?

    Thanks!

    M


  2. Re: Getting kernel CONFIG_* values in userspace


    Medgya wrote:
    > I have a userspace program that calls into a kernel module, but the
    > kernel module can have several variants depending on the value of
    > several CONFIG variables selected at kernel build time. The userspace
    > tool needs to change to accomodate this, so I want to get access to the
    > CONFIG variables either at runtime or when building the userspace tool.
    > But what's the best way to do that?
    >
    > One idea is just to have the kernel module write the appropriate
    > CONFIG_ variables to a header file that would be included by the
    > userspace tool, but I wondered if there is some standard way?
    >
    > Thanks!
    >
    > M

    You can find them in file /boot/config-your-linux-version. Some may
    have in under /proc/.

    Max


  3. Re: Getting kernel CONFIG_* values in userspace

    Medgya wrote:
    > I have a userspace program that calls into a kernel module, but the
    > kernel module can have several variants depending on the value of
    > several CONFIG variables selected at kernel build time. The userspace
    > tool needs to change to accomodate this, so I want to get access to the
    > CONFIG variables either at runtime or when building the userspace tool.
    > But what's the best way to do that?
    >
    > One idea is just to have the kernel module write the appropriate
    > CONFIG_ variables to a header file that would be included by the
    > userspace tool, but I wondered if there is some standard way?


    How about providing a "capability" function in the module?

    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett


  4. Re: Getting kernel CONFIG_* values in userspace

    Medgya wrote:
    > I have a userspace program that calls into a kernel module, but the
    > kernel module can have several variants depending on the value of
    > several CONFIG variables selected at kernel build time. The userspace
    > tool needs to change to accomodate this, so I want to get access to the
    > CONFIG variables either at runtime or when building the userspace tool.
    > But what's the best way to do that?


    > One idea is just to have the kernel module write the appropriate
    > CONFIG_ variables to a header file that would be included by the
    > userspace tool, but I wondered if there is some standard way?


    Probably the best solution (if you can change the kernel module)
    would be to have the kernel module output the relevant settings
    via the /proc or /sys file system, so they can be read from any
    userland program. In your program you should read in that pseudo-
    file and execute that part that deals with the way the module has
    been set up. That way you don't need the module running in the
    kernel while your program gets compiled and you don't have to
    recompile it if the kernel configuration changes (having to re-
    compile a set of userland programs every time you install a new
    kernel would probably become a PITA very soon, having to recompile
    external modules can already become quite tedious).

    If you can't change the kernel module things get "interesting"
    since you have no guarantee that the kernels configuration
    settings can be deduced. You can only hope that there's either
    a file in the /proc file system called /proc/config.gz or that
    you can get at the settings via

    /lib/modules/`uname -r`/build/.config

    or

    /lib/modules/`uname -r`/build/include/linux/autoconfig.h

    (but that may not work on machines where people didn't create
    their own kernel and the files you get there might also be out
    of sync with the running kernel). On some systems you also may
    have some luck with

    /boot/config-`uname -r`

    but again you can't expect that to exist on all systems. If none
    of these methods work I guess you're simply out of luck. On the
    other hand if a module can have different interfaces when compiled
    for different kernel configurations it should come with some method
    that lets on figure out what it is capable of and what not - other-
    wise I would consider it seriously broken.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
    \__________________________ http://www.toerring.de

  5. Re: Getting kernel CONFIG_* values in userspace


    Jens Toerring wrote:

    > Medgya wrote:
    > > I have a userspace program that calls into a kernel module, but the
    > > kernel module can have several variants depending on the value of
    > > several CONFIG variables selected at kernel build time. The userspace
    > > tool needs to change to accomodate this, so I want to get access to the
    > > CONFIG variables either at runtime or when building the userspace tool.
    > > But what's the best way to do that?

    >
    > > One idea is just to have the kernel module write the appropriate
    > > CONFIG_ variables to a header file that would be included by the
    > > userspace tool, but I wondered if there is some standard way?

    >
    > Probably the best solution (if you can change the kernel module)
    > would be to have the kernel module output the relevant settings
    > via the /proc or /sys file system, so they can be read from any
    > userland program. In your program you should read in that pseudo-
    > file and execute that part that deals with the way the module has
    > been set up.

    I wonder why kernel guys don't have this yet. This will be helpful.
    That way you don't need the module running in the
    > kernel while your program gets compiled and you don't have to
    > recompile it if the kernel configuration changes (having to re-
    > compile a set of userland programs every time you install a new
    > kernel would probably become a PITA very soon, having to recompile
    > external modules can already become quite tedious).
    >
    > If you can't change the kernel module things get "interesting"
    > since you have no guarantee that the kernels configuration
    > settings can be deduced. You can only hope that there's either
    > a file in the /proc file system called /proc/config.gz or that
    > you can get at the settings via
    >
    > /lib/modules/`uname -r`/build/.config
    >
    > or
    >
    > /lib/modules/`uname -r`/build/include/linux/autoconfig.h
    >
    > (but that may not work on machines where people didn't create
    > their own kernel and the files you get there might also be out
    > of sync with the running kernel). On some systems you also may
    > have some luck with
    >
    > /boot/config-`uname -r`
    >
    > but again you can't expect that to exist on all systems. If none
    > of these methods work I guess you're simply out of luck. On the
    > other hand if a module can have different interfaces when compiled
    > for different kernel configurations it should come with some method
    > that lets on figure out what it is capable of and what not - other-
    > wise I would consider it seriously broken.
    >
    > Regards, Jens
    > --
    > \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
    > \__________________________ http://www.toerring.de



  6. Re: Getting kernel CONFIG_* values in userspace

    Milind Dumbare wrote:
    > Jens Toerring wrote:
    > > Probably the best solution (if you can change the kernel module)
    > > would be to have the kernel module output the relevant settings
    > > via the /proc or /sys file system, so they can be read from any
    > > userland program.


    > I wonder why kernel guys don't have this yet. This will be helpful.


    There are two kernel options (CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC)
    that, if enabled, give you a file /proc/config.gz with all the options
    the kernel was compiled with. But since they can be switched off you
    unfortunately can't be sure it's available on all systems.

    Rgards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  7. Re: Getting kernel CONFIG_* values in userspace

    Thanks very much for all your replies. Excellent information. I'm
    building for an embedded system, rather than general use, so I have
    full control over the kernel build process and your suggestions solve
    the problem very nicely.

    M


+ Reply to Thread