LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 04-10-2004, 01:21 PM   #1
carbooky
LQ Newbie
 
Registered: Apr 2004
Posts: 2

Rep: Reputation: 0
questions about reference to "jiffies"


sorry I am a linux newbie ,
I want to reference the extern variable "jiffies" value updated by kernel
in my programming code , but I found error message at compiled time , I don't know which header files should be included correctly, or maybe some where goes wrong . Can someone teach me how to reference the "jiffies" anywhere in my code !!

help would be greatly appreciated.
Thank you in advance

my test.c file
----------------
#include <stdio.h>
#include <linux/timer.h>
#include <linux/times.h>
#include <linux/timex.h>
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <asm/uaccess.h>
extern unsigned long volatile jiffies;

int gett(void);

main ()
{
int result;
result = gett();
printf("result is %d\n", result);
printf("jiffies %.3lg \n", jiffies);
}
int gett(void){
int mult[2];
puts("puts multi a & b");
scanf("%d", &mult[0]);
scanf("%d", &mult[1]);
return mult[0]*mult[1];
}
--------------------

my makefile
---------------
INCLUDE = /usr/src/linux/include/
TARGET = test
CC = gcc
SRC = test.c

all:$(TARGET)

$(TARGET):$(SRC)
$(CC) -I$(INCLUDE) -o $(TARGET) $(SRC)

---------------------
 
Old 04-10-2004, 01:38 PM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
I don't think jiffies is available to userspace at all -- you'd have to write a kernel module to get ad it.
 
Old 04-10-2004, 02:52 PM   #3
carbooky
LQ Newbie
 
Registered: Apr 2004
Posts: 2

Original Poster
Rep: Reputation: 0
So if I want to estimate how long a code segment or a single function takes when called , by what manner or functions is recommanded while I can get the estimated time from entring it to leaving it , measured in micro second or even precisely ?
 
Old 04-10-2004, 03:15 PM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
clock_gettime() looks promising, and there's gettimeofday(). I'm not sure if either of those will really give microsecond precision -- they may be limited to 1/HZ.

If you're benchmarking something with a short running time, you should run it many times and divide, rather than trying to time just one run.
 
Old 04-12-2004, 10:16 AM   #5
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
there are various tools to do this ...gprof for one does that...profiles how much time is spent in what part of code...youd have to compile your code with -pg option for code to enable profiling...

or what aluser says is right..call gettimeofday...

also dont include the kernel space header files...
use the default /usr/include header files..
these are the files meant for the user space stuff....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"undefined reference"linker error for static field w/ C++ astorm Programming 5 08-27-2008 03:00 AM
Curl - undefined reference "DES_set_odd_parity" - SOLVED sundialsvcs Linux - Software 0 09-15-2005 09:58 AM
Comments request for "O'Reilly's Linux iptables Pocket Reference" carboncopy General 3 03-03-2005 09:24 PM
Undefined Screen " XFree86" reference by serverLayout "XFree86 Configured" comox *BSD 7 01-17-2005 05:47 PM
Kernel make bzImage error "undefined reference" w/ Prism2.5 USB driver under 2.6 joachimvb Mandriva 1 09-24-2004 07:43 PM


All times are GMT -5. The time now is 09:05 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration