LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2010, 01:46 PM   #1
sportic
LQ Newbie
 
Registered: May 2010
Posts: 3

Rep: Reputation: 0
kernel space to user space


I'm writing a kernel module in Solaris and am looking for an efficient mechanism in Solaris 10 and/or Linux to communicate from a kernel module to an application in user space. The kernel module would need to send an event along with some data to the user space app. I would prefer to use a mechanism which is common to both Solaris and Linux
I have read about netlink sockets but dont think these are available in Solaris.
Any help would be appreciated and I would also ask if you could point me to a code example for the mechanism that you suggest.

Thanks...
 
Old 05-06-2010, 02:16 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Shared memory ?
 
Old 05-06-2010, 03:04 PM   #3
ArthurSittler
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 124

Rep: Reputation: 31
kernel IO module is a device driver

If you are transferring data from a kernel level module, then you are writing something that fits the definition of a device driver.

Linux Device Drivers, third edition, by Corbet, Rubini, and Kroah, describes how to implement device drivers in Linux (and, by extension, in Solaris 10, because that is also, in fact, Linux). Actually, if Solaris 10 is the 2.4 kernel (I can't recall whether it is 2.4 or 2.6) then you should use the second edition, by Rubini, which is now freely available online.

As always, the Linux source is the ultimate authority on the structure of device drivers. It is also a handy source for examples, though I find much of the code a bit short of comments and therefore somewhat opaque. If you find a device driver hard to read, just try looking at a different one. There are thousands or tens of thousands of them available for your reading enjoyment.

The basic paradigm in Unices is that everything is a file. However, there are two classes of device drivers, character streams (like consoles and printers) and block devices (like disk drives). Even if your device produces a stream of blocks of data, you may wish to regard it as a stream device.

Once you have the device driver working, you open the device and read from it. You can read either in blocking or nonblocking mode. The simplest approach may be to have a reader thread reading from the device in blocking mode. The reader thread uses some signaling method, such as a semaphore, to communicate with the data consumer.

This method is efficient because all the data transfers are data driven. The device driver consumes no CPU until a hardware interrupt activates it. Your reader thread consumes no CPU until the next data block from the device driver activates it. Your data consumer consumes no CPU until the reader thread signals that data is available.
 
Old 05-06-2010, 11:10 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
The "device driver" metaphor is, indeed, very good when you want to implement something like this.
 
Old 05-07-2010, 12:38 AM   #5
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Rep: Reputation: 41
Use a combination of signals and ioctl calls.
 
Old 05-07-2010, 05:24 PM   #6
sportic
LQ Newbie
 
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
thanks for info. I was thinking in terms of using doors for performance reasons. Your thoughts?
 
Old 05-07-2010, 06:29 PM   #7
ArthurSittler
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 124

Rep: Reputation: 31
doors could be limiting

I had not heard about doors, so I consulted The Oracle. It sounds like doors are somewhat special to Solaris. The drawback that I see here is that you may be restricting the choice of platforms that could support your application to Solaris, which is all ready a narrower field than any of the three most popular Linux distributions. Though I cannot see the future, I believe that the more durable choice of platforms is Linux. Solaris may or may not be around five or ten years down the road. I believe Linux will be around for twenty years or more, though probably in a much different form. Considering how much Linux device drivers have changed between 2.2 and 2.6, even if you write your application using Linux device drivers you may expect to need to update the driver structure considerably over the next twenty years as we progress to 256-bit 64-core CPUs running at what would look like, to us now, hundreds of GHz or a few THz.
 
Old 05-08-2010, 08:57 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
"Efficiency" is probably an irrelevant consideration. The process will not take a significant amount of time to make the transition. Keep it simple.

Look at the entire /proc filesystem, for instance: an elegantly simple solution to a vexing problem. Plenty of source-code examples abound, within the Linux kernel.

A "virtual file" can read and write an unlimited amount of data. For example, ls -l /proc can handle an unlimited number of processes). You've got an easy and well-defined interface (read/write/ioctl) that is easy for both application programs and the kernel to work with.
 
Old 05-10-2010, 04:36 PM   #9
sportic
LQ Newbie
 
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
if anyone has used the doors functions can you tell me if door_call() can be used from a kernel module?

thanks
 
Old 05-11-2010, 07:12 PM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Door_call is a system call and thus is intended by definition to be called by a userland application, not from a kernel module. The Solaris door API is designed to provide fast inter process communication. If you are adventurous, you might explore an undocumented kernel function (door_ki_create) that allows creating a door between the kernel and user processes.
http://src.opensolaris.org/source/xr...oor_sys.c#3420
Here is a (C++ ??) code that apparently uses it (don't ask me to explain what it does and how ...) :
http://src.opensolaris.org/source/xr...ateway.cc#1120

Of course, as already stated, this won't be portable to Linux. There was an attempt to implement that API to Linux but unfortunately, that project is no more updated since many years: http://ldoor.sourceforge.net/
 
Old 05-11-2010, 07:21 PM   #11
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by ArthurSittler View Post
Linux Device Drivers, third edition, by Corbet, Rubini, and Kroah, describes how to implement device drivers in Linux (and, by extension, in Solaris 10, because that is also, in fact, Linux). Actually, if Solaris 10 is the 2.4 kernel (I can't recall whether it is 2.4 or 2.6)
You should put a smiley somewhere for this joke not to be taken too seriously, just in case. Of course the Solaris kernel and the Linux one are pretty foreign to each other for many reasons.

Good references about Solaris device drivers are here:
http://hub.opensolaris.org/bin/view/...evice_drivers/
http://docs.sun.com/app/docs/doc/816-4854
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Division of Logical Memory Space in to User Space and Kernel Space shreshtha Linux - Newbie 2 01-14-2010 09:59 AM
Do we have any chance of calling user space callback function from kernel space? ravishankar.g Linux - Newbie 1 09-22-2009 07:14 PM
Function in kernel space called form user space.. Linux_Kid_ Programming 2 09-22-2009 04:34 AM
how to call socket prog code written in user space from kernel space???HELP kurt2 Programming 2 07-15-2009 09:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration