2004-03-29 02:47:14

by lml

[permalink] [raw]
Subject: Kernel / Userspace Data Transfer

Hello,

I have a set of counters in a Kernel module that i want to export to a
userspace application. I originally decided to use a /proc entry and parse
the output whenever the userspace application needed this data, however,
i need more than the 4096 that is allowed in /proc and i'm not too keen
on parsing large chunks of text anyway.

What i would like to do is copy these slabs of text from the kernel to my
userspace application (whenever the application requests it). I've seen the
'copy_to_user' function and it looks usefull, but have no idea where to start
or how to use it :-/

Can someone provide and example or point me in the right direction? Or is there
a better place to ask this question?

Regards
-J


2004-03-29 03:31:33

by Karim Yaghmour

[permalink] [raw]
Subject: Re: Kernel / Userspace Data Transfer


[email protected] wrote:
> I have a set of counters in a Kernel module that i want to export to a
> userspace application. I originally decided to use a /proc entry and parse
> the output whenever the userspace application needed this data, however,
> i need more than the 4096 that is allowed in /proc and i'm not too keen
> on parsing large chunks of text anyway.
>
> What i would like to do is copy these slabs of text from the kernel to my
> userspace application (whenever the application requests it). I've seen the
> 'copy_to_user' function and it looks usefull, but have no idea where to start
> or how to use it :-/
>
> Can someone provide and example or point me in the right direction? Or is there
> a better place to ask this question?

relayfs has been designed with this type of requirements in mind:
http://www.opersys.com/relayfs/index.html

Karim
--
Author, Speaker, Developer, Consultant
Pushing Embedded and Real-Time Linux Systems Beyond the Limits
http://www.opersys.com || [email protected] || 1-866-677-4546

2004-03-29 04:54:42

by Ross Dickson

[permalink] [raw]
Subject: Re: Kernel / Userspace Data Transfer

[email protected] wrote:
> I have a set of counters in a Kernel module that i want to export to a
> userspace application. I originally decided to use a /proc entry and parse
> the output whenever the userspace application needed this data, however,
> i need more than the 4096 that is allowed in /proc and i'm not too keen
> on parsing large chunks of text anyway.
>
> What i would like to do is copy these slabs of text from the kernel to my
> userspace application (whenever the application requests it). I've seen the
> 'copy_to_user' function and it looks usefull, but have no idea where to start
> or how to use it :-/
>
> Can someone provide and example or point me in the right direction? Or is there
> a better place to ask this question?

Here is a good starter on-line reference
http://www.faqs.org/docs/kernel/
Relevant page
http://www.faqs.org/docs/kernel/x848.html
or as pdf
http://www.tldp.org/LDP/lkmpg/lkmpg.pdf

There is also mbuff that maps shared memory between kernel and user space.
It is pretty easy to use.
http://sourceforge.net/projects/mbuff/

Regards
Ross.

2004-03-29 08:53:01

by Pavel Mironchik

[permalink] [raw]
Subject: Re: Kernel / Userspace Data Transfer

The best Userspace-kernelspace-Userspace transfer thing is soket.
Unix or TCP/UDP sockets API is avaible from kernel space.
You should use it...

Pavel Mironchik


On Sun, 28 Mar 2004 22:37:23 -0500
Karim Yaghmour <[email protected]> wrote:

>
> [email protected] wrote:
> > I have a set of counters in a Kernel module that i want to export to a
> > userspace application. I originally decided to use a /proc entry and parse
> > the output whenever the userspace application needed this data, however,
> > i need more than the 4096 that is allowed in /proc and i'm not too keen
> > on parsing large chunks of text anyway.
> >
> > What i would like to do is copy these slabs of text from the kernel to my
> > userspace application (whenever the application requests it). I've seen the
> > 'copy_to_user' function and it looks usefull, but have no idea where to start
> > or how to use it :-/
> >
> > Can someone provide and example or point me in the right direction? Or is there
> > a better place to ask this question?
>
> relayfs has been designed with this type of requirements in mind:
> http://www.opersys.com/relayfs/index.html
>
> Karim
> --
> Author, Speaker, Developer, Consultant
> Pushing Embedded and Real-Time Linux Systems Beyond the Limits
> http://www.opersys.com || [email protected] || 1-866-677-4546
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2004-03-29 09:11:43

by Emmanuel Fleury

[permalink] [raw]
Subject: Re: Kernel / Userspace Data Transfer

On Mon, 2004-03-29 at 11:45, Pavel Mironchik wrote:
> The best Userspace-kernelspace-Userspace transfer thing is soket.
> Unix or TCP/UDP sockets API is avaible from kernel space.
> You should use it...

Do you mean Netlink ?

Regards
--
Emmanuel Fleury

Computer Science Department, | Office: B1-201
Aalborg University, | Phone: +45 96 35 72 23
Fredriks Bajersvej 7E, | Fax: +45 98 15 98 89
9220 Aalborg East, Denmark | Email: [email protected]

2004-03-29 09:50:12

by Tigran Aivazian

[permalink] [raw]
Subject: Re: Kernel / Userspace Data Transfer

Hello,

One possible solution is to use seq_file API for a /proc file.
I have written a process/system monitor using this method which is about 100
times faster than reading various bits and pieces from /proc by a user application,
so a kernel module is well worth having in this respect. Unfortunately, this software
is not under GPL, but if you do want more information I can send you (or upload
somewhere) a stripped down version which just shows how to use the API
most efficiently and safely.

Kind regards
Tigran
Freeserve AnyTime - HALF PRICE for the first 3 months - Save ?7.50 a month
http://www.freeserve.com/anytime

2004-03-29 14:24:12

by Karim Yaghmour

[permalink] [raw]
Subject: Re: Kernel / Userspace Data Transfer


Pavel Mironchik wrote:
> The best Userspace-kernelspace-Userspace transfer thing is soket.
> Unix or TCP/UDP sockets API is avaible from kernel space.
> You should use it...

Sockets suck for the kind of application relayfs is used for. Try
running LTT on sockets, for example, and let me know what type of
performance you get. For simple transfers, maybe, but for real
high-speed, large scale data transfers, sockets just don't cut it.
That's where relayfs is most useful.

Karim
--
Author, Speaker, Developer, Consultant
Pushing Embedded and Real-Time Linux Systems Beyond the Limits
http://www.opersys.com || [email protected] || 1-866-677-4546