* Communication between kernel and kernel module
@ 2012-05-22 18:18 drewd77.gm
2012-05-22 18:31 ` Vlad Dogaru
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: drewd77.gm @ 2012-05-22 18:18 UTC (permalink / raw)
To: kernelnewbies
Hi,
Is there any way to call a function defined in a kernel module from within
the kernel proper?
Here's what I'm trying to do:
I'm trying to keep track of when and for how long a process is being
executed on the processor, i.e. I need to know when context switches occur.
There is a function called context_switch() in linux/kernel/sched/core.c
that is called whenever a context switch happens. I would like to call a
function in a kernel module I've written from within context_switch() and
pass some data to it.
I've seen how to communicate between user space and kernel space, such as
using a file in /dev or using system calls, but not how to communicate
within the kernel itself.
Regards,
Drew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120522/97e3a558/attachment.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Communication between kernel and kernel module
2012-05-22 18:18 Communication between kernel and kernel module drewd77.gm
@ 2012-05-22 18:31 ` Vlad Dogaru
2012-05-23 1:07 ` 刘智猷
2012-05-23 11:48 ` Frank Ch. Eigler
2 siblings, 0 replies; 4+ messages in thread
From: Vlad Dogaru @ 2012-05-22 18:31 UTC (permalink / raw)
To: kernelnewbies
On Tue, May 22, 2012 at 9:18 PM, drewd77.gm <drewd77.gm@gmail.com> wrote:
> Hi,
>
> Is there any way to call a function defined in a kernel module from within
> the kernel proper?
>
> Here's what I'm trying to do:
>
> I'm trying to keep track of when and for how long a process is being
> executed on the processor, i.e. I need to know when context switches occur.
Kprobes [1] might be useful. I for one haven't used Kprobes before,
but I'm sure others on this list can provide useful insight.
[1] http://lwn.net/Articles/132196/
Hope this helps,
Vlad
^ permalink raw reply [flat|nested] 4+ messages in thread
* Communication between kernel and kernel module
2012-05-22 18:18 Communication between kernel and kernel module drewd77.gm
2012-05-22 18:31 ` Vlad Dogaru
@ 2012-05-23 1:07 ` 刘智猷
2012-05-23 11:48 ` Frank Ch. Eigler
2 siblings, 0 replies; 4+ messages in thread
From: 刘智猷 @ 2012-05-23 1:07 UTC (permalink / raw)
To: kernelnewbies
Hi,
On 05/23/2012 02:18 AM, drewd77.gm wrote:
> Hi,
>
> Is there any way to call a function defined in a kernel module from
> within the kernel proper?
>
> Here's what I'm trying to do:
>
> I'm trying to keep track of when and for how long a process is being
> executed on the processor, i.e. I need to know when context switches
> occur.
>
> There is a function called context_switch()
> in linux/kernel/sched/core.c that is called whenever a context switch
> happens. I would like to call a function in a kernel module I've
> written from within context_switch() and pass some data to it.
There are lots of ways to do it, maybe you don't need to write a module
or hacking the kernel like that... Check perf and systemtap. They may help.
>
> I've seen how to communicate between user space and kernel space, such
> as using a file in /dev or using system calls, but not how to
> communicate within the kernel itself.
>
> Regards,
> Drew
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Regards,
LIU Zhiyou
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120523/fdf36077/attachment.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Communication between kernel and kernel module
2012-05-22 18:18 Communication between kernel and kernel module drewd77.gm
2012-05-22 18:31 ` Vlad Dogaru
2012-05-23 1:07 ` 刘智猷
@ 2012-05-23 11:48 ` Frank Ch. Eigler
2 siblings, 0 replies; 4+ messages in thread
From: Frank Ch. Eigler @ 2012-05-23 11:48 UTC (permalink / raw)
To: kernelnewbies
"drewd77.gm" <drewd77.gm@gmail.com> writes:
> Is there any way to call a function defined in a kernel module from within the
> kernel proper?
One needs a proper hook mechanism such as kprobes or tracepoints.
> I'm trying to keep track of when and for how long a process is being executed
> on the processor, i.e. I need to know when context switches occur.
>
> There is a function called context_switch() in?linux/kernel/sched/core.c that
> is called whenever a context switch happens. I would like to call a function in
> a kernel module I've written from within context_switch() and pass some data to
> it.
The sched_switch tracepoint is probably the best spot for this. A
systemtap script that listens for these events and simply traces them
to stdout looks like:
probe scheduler.ctxswitch { println(cpu(), ":", prev_tid, "->", next_tid) }
- FChE
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-05-23 11:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-22 18:18 Communication between kernel and kernel module drewd77.gm
2012-05-22 18:31 ` Vlad Dogaru
2012-05-23 1:07 ` 刘智猷
2012-05-23 11:48 ` Frank Ch. Eigler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).