2009-07-29 11:24:33 strange problem of times function
maverick gao (CHINA)
Message: 78169
hi,
I use times function to get system ticks from boot. But sometimes times function return uncorrect value. for example:
while(1)
{
printf("%d\n", times(NULL));
}
output:
1717975765
1717975765
1718063730
1717975766
1717975766
1717975766
why 1718063730?
Do I make something wrong ?
Regards,
Maverick
TranslateQuoteReplyEditDelete
2009-07-29 13:11:19 Re: strange problem of times function
Robin Getz (UNITED STATES)
Message: 78173
Maverick:
times returns a clock_t, which is a long int, which should print out as "%ld"
-Robin
QuoteReplyEditDelete
2009-07-29 22:22:21 Re: strange problem of times function
maverick gao (CHINA)
Message: 78181
Robin:
Thanks for your advice. But I try "%ld", get the same result of "%d".
Maverick
TranslateQuoteReplyEditDelete
2009-07-30 10:25:31 Re: strange problem of times function
Robin Getz (UNITED STATES)
Message: 78217
Maverick:
I tried this: I could not make if fail. Can you give me a complibable example that fails?
#include <stdio.h>
#include <sys/times.h>
int main () {
clock_t i,j;
i = 0;
while(1) {
j = times(NULL);
if (j != i)
printf("old:%ld new:%ld\n", i, j);
if (j < i )
break;
i = j;
}
return 0;
}
QuoteReplyEditDelete
2009-07-30 22:59:50 Re: strange problem of times function
maverick gao (CHINA)
Message: 78227
Robin:
Below is my test code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/times.h>
int main()
{
clock_t t1, t2;
t1 = t2 = times(NULL);
while (1)
{
t2 = times(NULL);
printf("%ld\n", t2);
if (t2 < t1)
{
printf("%ld %ld\n", t1, t2);
break;
}
t1 = t2;
}
return 0;
}
Maverick
TranslateQuoteReplyEditDelete
2009-07-31 00:53:50 Re: strange problem of times function
Yi Li (CHINA)
Message: 78231
I ran your test for a hour on BF537-STAMP and it works ok.
Here is my kernel and I am using 2009R1-rc10 toolchain:
"Linux version 2.6.30.3-ADI-2010R1-pre-svn7084 (adam@adam-desktop) (gcc version 4.1.2 (ADI svn))"
If your bug is producible, please tell me what is your toolchain/kernel version, and what is you blackfin part.
You can try to use 2009R1 branch or trunk kernel and toolchain to have a test on your side.
-Yi
QuoteReplyEditDelete
2009-08-04 05:21:46 Re: strange problem of times function
maverick gao (CHINA)
Message: 78345
Yi:
my test code will failed after server minutes on my bf531 board. I use obsolete kernel and toolchain supplied by HHTech almost 2 years ago. maybe I should try a latest one. thanks for you and robin. you are very kind.
Regards,
Maverick.
TranslateQuoteReplyEditDelete
2009-08-04 08:19:53 Re: strange problem of times function
Robin Getz (UNITED STATES)
Message: 78354
Maverick:
Yeah - there were some old problems (years ago), which caused time to go backwards. this should be fixed in the 2008R1.5 or 2009 releases.
-Robin