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 04-28-2007, 01:07 PM   #1
vmt1
LQ Newbie
 
Registered: Nov 2005
Distribution: slackware 11
Posts: 18

Rep: Reputation: 0
Inserting void function into Linux Kernel 2.6.17.14 (Where to insert?)


Hi,

I'm trying to hack the linux kernel code to insert a function to help me analyze the running kernel. My problem is this: I have a function (prototype is
Code:
 void foo (int bar)
which dumps the necessary information as the kernel is running, but I don't know of a 'safe' place to put it - that is, somewhere where it will be called, but also where it won't be called to regularly (which would cause a lot of latency).

I'm fairly new at kernel hacking, and initially thought to insert the function in the scheduler - this way, I could be sure it would run, and would be fairly easy to impliment. However, on thinking this through, I realized this would be a bad idea due to latency issues (it would be always called, and would cause my computer to run really slowly).

I did some research on how the kernel is built, but I'm not sure of where a good place to put this is - please note I'm in physics, not software engineering, so I apologize in advance for any silly mistakes or questions.

To be very concise, I'm looking for the exact file (and maybe line number) where I could put this code in. Ideally, the file should be among the first called, but not so often that it would cause unbearable latency.

I would also appreciate any resources on this matter; I've looked at the kernel hacking guide, but, to be completely upfront, I haven't read it thoroughly enough to determine where I can best place my function, so I'm looking for some advice on how I should go about doing it.


Thank you and warm Regards,

Vmt1
 
Old 04-29-2007, 03:38 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
The question is how often you want that function to be run. If not very often, you may use some ioctl (eg. from a driver you use) or (probably better) sysctl. If you want to run it more regularly and/or more often, it's more complicated issue and would be hard to answer without knowing which kernel subsystem you deal with (in plain English: what does the code show).
 
Old 04-29-2007, 08:32 PM   #3
vmt1
LQ Newbie
 
Registered: Nov 2005
Distribution: slackware 11
Posts: 18

Original Poster
Rep: Reputation: 0
Hi,

Thank you very much for your reply.

What I'm actually trying to do is compile the kernel with profile guided optimizations using the ICC compiler. However, it's necessary to dump the profile data at intervals, and it's not feasible to have the kernel write the profile data when it shuts down (for obvious reasons). I'm doing this partially to see if I can, and partially so I can contribute it for a local beowolf cluster for condensed matter research, and run some benchmarks.

To this end, here's what I'm doing:

I've talked to the guys at Intel about what I'm trying to do, and they've been helpful in pointing out how I can get the kernel to dump profile information at intervals. They noted that I can do this by including the PGO API Header library and the _PGOPTI_Set_Interval_Prof_Dump() function. I've played a lot with using it on small programs, and I've almost got it working nicely. In general, I can apply it by doing the following:

Code:
#include "pgouser.h"

/* Blah */

void main() {

_PGOPTI_Set_Interval_Prof_Dump(5000); 

/*
*Prototype is
* void _PGOPTI_Set_Interval_Prof_Dump(int interval);
* interval is in the time domain, in milliseconds
*/

/* Blah */
In otherwords, I know what I need to do, I'm just having trouble figuring out where I can do this. You had a really neat idea with using drivers - I got the idea I could put it in the soundcore.c file (assuming you're in the linux source directory, this is located in /sound/sound_core.c ). However, when I looked in it, I wasn't able to find a main function, and I'm guessing it may not be safe to insert one on a whim.

Any insights?

Warm regards,

vmt1

Last edited by vmt1; 04-29-2007 at 08:34 PM.
 
  


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
insert lines in a function using shell script shyamdey Programming 1 08-30-2006 07:48 AM
int * function(void)??? kalleanka Programming 5 08-01-2006 09:37 AM
difference between function declaration: func() and func(void) koyi Programming 4 11-19-2005 10:19 AM
void * pointer in function xailer Programming 23 01-16-2004 02:14 PM

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

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