Kernel Newbies archive mirror
 help / color / mirror / Atom feed
From: "Chan Kim" <ckim@etri.re.kr>
To: <kernelnewbies@kernelnewbies.org>
Subject: clock_gettime function doesn't scale to real time.. and changing CNTFRQ_EL0 doesn't make any change..(arm64)
Date: Fri, 4 Nov 2022 18:04:15 +0900	[thread overview]
Message-ID: <143801d8f02c$6a126f90$3e374eb0$@etri.re.kr> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1797 bytes --]

Hello linux experts and newbies,

I have ported linux on our arm64 fpga board. Both 5.10.0 and 5.15.xx works
ok with minimal config.
I have run a simple application and timed the processing time using
clock_gettime function.
It felt like it took almost 2.3 seconds but the program say it took only
0.36 seconds.
Here is how I did  it in the application.

	Int main() {

	struct timespec start, stop;
	    float exec_time_sec, exec_time_nsec;
	
	//check start time
	    if (clock_gettime(CLOCK_REALTIME, &start) == -1 )  {
	        perror ("clock_gettime");
	        exit(EXIT_FAILURE);
	    }

	Do something... (calculate fibonacci value for 1 ~ 30)

	//check end time

	    if (clock_gettime(CLOCK_REALTIME, &stop) == -1 )  {
	        perror ("clock_gettime");
	        exit(EXIT_FAILURE);
	    }

	    //Normalize to mili second
	    exec_time_sec = (float)(stop.tv_sec - start.tv_sec);
	    exec_time_nsec = (float)((double)(stop.tv_nsec -
start.tv_nsec)/(double)BILLION);

	    printf("Execution time : %f sec\n", exec_time_sec +
exec_time_nsec);
	
	return 0;
	}


I used u-boot program for loading linux kernel and the u-boot program sets
the CNTFRQ_EL0 register with 5000000. 
(which is 5MHz, I heard the system clock runs at 5MHz in the board).
The description of the register in armv8 arch manual says :

This register is provided so that software can discover the frequency of the
system counter. It must
be programmed with this value as part of system initialization. The value of
the register is not
interpreted by hardware.

I tried setting the CNTFRQ_EL0 with 20Mhz, expecting the execution to be
displayed 4 times shorter but it is the same!
I couldn't find how linux uses clock_gettime.
How can I solve this problem?
Any advice will be deeply appreciated.

Thank you!

Chan Kim





[-- Attachment #1.2: Type: text/html, Size: 9588 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

             reply	other threads:[~2022-11-04  9:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04  9:04 Chan Kim [this message]
2022-11-04 12:04 ` clock_gettime function doesn't scale to real time.. and changing CNTFRQ_EL0 doesn't make any change..(arm64) Linus Probert
2022-11-04 19:51 ` Siddh Raman Pant
2022-11-05 11:46   ` Chan Kim
2022-11-08  5:15     ` Chan Kim
2022-11-08 10:31       ` Siddh Raman Pant
2022-11-08  5:18     ` Chan Kim

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='143801d8f02c$6a126f90$3e374eb0$@etri.re.kr' \
    --to=ckim@etri.re.kr \
    --cc=kernelnewbies@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 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 read-only IMAP folder(s) and NNTP newsgroup(s).