All of lore.kernel.org
 help / color / mirror / Atom feed
From: fche@redhat.com (Frank Ch. Eigler)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Communication between kernel and kernel module
Date: Wed, 23 May 2012 07:48:16 -0400	[thread overview]
Message-ID: <y0mipfnnmnz.fsf@fche.csb> (raw)
In-Reply-To: <CAMmx0woDVmusLb3qNdqN=2Y4wfucwaaHeKMXuu9EpJMiBXU_Gw@mail.gmail.com> (drewd77.gm@gmail.com's message of "Tue, 22 May 2012 11:18:32 -0700")

"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

      parent reply	other threads:[~2012-05-23 11:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=y0mipfnnmnz.fsf@fche.csb \
    --to=fche@redhat.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.