LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-13-2005, 05:22 PM   #1
tantrix
LQ Newbie
 
Registered: Apr 2005
Posts: 6

Rep: Reputation: 0
Programming a module.. need help


Hi, I've been programming a module to benchmark the time it takes for memcpy to execute on various boards. Now, there are two different memcpy functions implemented in my case, one that uses the hardware memory controller and another that contains software DMA enhancements.

The problem lies in the place where I get time. The way the I get time is that I call a function to get the current number of clocks for the processor (which it started counting since startup). This is an unsigned long long value. I'm facing problems when I take the difference of two of these unsigned long long values as for END-START, I'm getting negative number of clock cycles in some cases..

This bug/anomaly is very consistent in the sense that it does happen..
It happens only when the number of repetitions are higher than 1000.
It happens for random transfers (not for the same ones)..

Is there any problem with the way I'm printing / calculating this difference.

---------------------------------------------------------------------------------------------------

This is my code:

unsigned long long start, end, difference;

unsigned long long tstart()
{
unsigned long long x;
x = do_getclkcycles();
}

unsigned long long tend()
{
unsigned long long x;
x = do_getclkcycles();
}

void main()
{
start = tstart();

//////data transfer

end = tend();
if (end < start)
printk( "error");

}
 
Old 04-13-2005, 05:38 PM   #2
eternallySecure
LQ Newbie
 
Registered: Apr 2005
Distribution: FreeBSD, Fedora Core 3
Posts: 23

Rep: Reputation: 15
Try this:

#include <time.h>

time_t time1;
time_t time2;
double timeTaken;

int main()
{
/* Start time */
time1= time((time_t *)0);

/* Data transfer here */

/* End time */
time2= (time((time_t *)0);

/* Calculate difference */
timeTaken= difftime(time1, time2);
printf("%d", timeTaken);
}

This should work

--RF
 
Old 04-13-2005, 05:48 PM   #3
tantrix
LQ Newbie
 
Registered: Apr 2005
Posts: 6

Original Poster
Rep: Reputation: 0
what kind of resolution does this method have? as I'm checking time over a single memcpy command and that can be in microseconds or even nanoseconds..
 
Old 04-14-2005, 07:15 PM   #4
eternallySecure
LQ Newbie
 
Registered: Apr 2005
Distribution: FreeBSD, Fedora Core 3
Posts: 23

Rep: Reputation: 15
This only measures seconds. If you need more than that this method won't work. I don't know what else to do. I'm still learning C.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
module programming b123coder Programming 0 12-13-2004 04:05 AM
Kernel module programming lokutas Programming 2 04-27-2004 03:26 AM
Module programming linuxanswer Programming 2 12-12-2003 03:16 PM
Module Programming nu2linux Programming 4 06-01-2002 03:01 PM
Kernel Module Programming Thomas.P Programming 1 11-10-2001 11:23 AM

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

All times are GMT -5. The time now is 02:50 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration