LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-04-2015, 09:46 AM   #16
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

A context-switch takes very little resources, actually. The interrupt can activate a very high priority process, in userland, which gathers information and/or sends it, and there will be very little "latency" involved. This process might, in turn, signal other client processes, also in userland.
 
Old 08-04-2015, 11:02 AM   #17
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
yes. The advantage is not wasting application time (and code) doing what the kernel already does.
 
Old 08-04-2015, 12:06 PM   #18
shekharrana
LQ Newbie
 
Registered: Sep 2006
Location: bangalore, IN
Posts: 6

Rep: Reputation: 1
@david_8274,
"--- if the blocking read is in thread_1, doesn't the user-space program have to first go back to thread_1 before the blocking read gets the interrupt? If the program doesn't do context switching constantly, how does thread_1 gets the interrupt?"


constant cont_switching is not required. when in ISR u invoke wake_up_interruptible(), it will set the TIF NEED_RESCHED flag => on exits from ISR i.e. "rfi", scheduler() would be invoked and context switch could happen.
So your thread_1 will get CPU.
Hope that clarifies...

Last edited by shekharrana; 08-04-2015 at 12:08 PM.
 
Old 08-04-2015, 12:45 PM   #19
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shekharrana View Post
@david_8274,
"--- if the blocking read is in thread_1, doesn't the user-space program have to first go back to thread_1 before the blocking read gets the interrupt? If the program doesn't do context switching constantly, how does thread_1 gets the interrupt?"


constant cont_switching is not required. when in ISR u invoke wake_up_interruptible(), it will set the TIF NEED_RESCHED flag => on exits from ISR i.e. "rfi", scheduler() would be invoked and context switch could happen.
So your thread_1 will get CPU.
Hope that clarifies...
@shekharrana
Thank you for the clarification. Then I think this is the way to go -- create a queue and use wait_event_interruptible() and wake_up_interruptible() to catch the event.

Wei
 
Old 08-04-2015, 06:26 PM   #20
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by david_8274 View Post
@shekharrana
Thank you for the clarification. Then I think this is the way to go -- create a queue and use wait_event_interruptible() and wake_up_interruptible() to catch the event.

Wei
Only if you are writing device drivers...

This only works in kernel mode.
 
Old 08-04-2015, 08:51 PM   #21
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
I personally think that the best strategy is to go to user-land, and to make sure that the next user-land process to get control of the CPU is the special-purpose one that you want.
 
Old 08-05-2015, 01:49 AM   #22
shekharrana
LQ Newbie
 
Registered: Sep 2006
Location: bangalore, IN
Posts: 6

Rep: Reputation: 1
Quote:
Originally Posted by jpollard View Post
Only if you are writing device drivers...

This only works in kernel mode.
with either approaches (waitqueue or send_signal), things shall be modified in kernel aswell as userland.

would be nice to hear another approach without tweaking in kernel!!
 
Old 08-05-2015, 05:56 AM   #23
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by shekharrana View Post
with either approaches (waitqueue or send_signal), things shall be modified in kernel aswell as userland.

would be nice to hear another approach without tweaking in kernel!!

There are lots of ways.

select, epoll, semaphores, sockets, read/write, threads, shared memory, dbus, ...

Userspace has lots of tools, and are (for the most part) relatively easy to debug. Granted, it does get more complex as you add more parallel activity.
 
Old 08-05-2015, 06:46 AM   #24
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
Another common technique is to write a virtual device type, which gives you the "read/write/ioctl" interface that can be used by any userland program. As well as oodles of examples of how to do it, in existing kernel source-code. The whole thing can be bundled as a loadable kernel module.

Last edited by sundialsvcs; 08-05-2015 at 06:48 AM.
 
  


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
Getting hardware interrupt in user-space program david_8274 Linux - Newbie 1 07-29-2015 08:56 PM
[SOLVED] Catch LPT interrupt in user space. LEICIF Linux - Newbie 9 06-25-2011 11:15 AM
Mechanism for interrupt report to user space zvivered Linux - Embedded & Single-board computer 0 08-11-2009 03:59 PM
how to trensfer data from user space to interrupt handler? rose_hatami Programming 4 12-19-2007 05:17 AM
can interrupt handler call user space function? pot_po Programming 0 11-07-2002 09:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:15 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