setitimer shows different between amd64 and ia32
Hi, all I'm working on a test which invoking setitimer(), and it hang in ia32 and ppc, but passed in amd64, could you guys give some help? 1, I know the 'value.it_interval.tv_usec' is too short, but why amd64 passed? 2, If I switch clock source from "tsc" to "hpet" on ia32, it passed. 3, I compiled it in ia32 and run it with ia32-libs in amd64, it passed. Here is the source: #include <sys/time.h> #include <signal.h> #include <unistd.h> #include <stdio.h> #include <time.h> #include <errno.h> #define LOOP_LIMIT 1E2 volatile int sigcount = 0; void catcher(int sig) { struct itimerval value; int which = ITIMER_REAL; sigcount++; if (sigcount > 1) { getitimer(which, &value); value.it_value.tv_sec = 0; value.it_value.tv_usec = 0; /*setitimer( which, &value, NULL ); */ } } int main(int argc, char *argv[]) { int result = 0; struct itimerval value, ovalue, pvalue; int which = ITIMER_REAL; struct sigaction sact; volatile double count; time_t t; sigemptyset(&sact.sa_mask); sact.sa_flags = 0; sact.sa_handler = catcher; sigaction(SIGALRM, &sact, NULL); getitimer(which, &pvalue); /*Set a real time interval timer to repeat */ value.it_interval.tv_sec = 0; value.it_interval.tv_usec = 1; value.it_value.tv_sec = 0; value.it_value.tv_usec = 5; result = setitimer(which, &value, &ovalue); /*The interval timer value returned by setitimer() should be */ /*identical to the timer value returned by getitimer() */ if (ovalue.it_interval.tv_sec != pvalue.it_interval.tv_sec || ovalue.it_interval.tv_usec != pvalue.it_interval.tv_usec || ovalue.it_value.tv_sec != pvalue.it_value.tv_sec || ovalue.it_value.tv_usec != pvalue.it_value.tv_usec) { printf("Real time interval timer mismatch, test Failed\n"); result = -1; } time(&t); printf("Before loop, time is %s", ctime(&t)); for (count = 0; ((count < LOOP_LIMIT)); count++) ; time(&t); printf("After loop, time is %s\n", ctime(&t)); if (sigcount == 0) printf("The signal catcher never gained control\n"); else printf("The signal catcher gained control\n"); printf("The value of count is %.0f\n", count); return (result); } -- Regards, Adam Lee -------------------------------------------------- E-mail: adam8157@gmail.com Website: http://www.adam8157.info --------------------------------------------------
Hi.... On Mon, Jul 25, 2011 at 03:10, Adam Lee <adam8157@gmail.com> wrote:
Hi, all
I'm working on a test which invoking setitimer(), and it hang in ia32 and ppc, but passed in amd64, could you guys give some help?
1, I know the 'value.it_interval.tv_usec' is too short, but why amd64 passed?
All of my answers are pure speculation. Regarding AMD64 that successfully run the code, I am not sure it's due to the processor itself. Maybe because...in your machine that use AMD64, it uses HPET by default?
2, If I switch clock source from "tsc" to "hpet" on ia32, it passed.
This is interesting. I can only offer one explanation: finer grained timer resolution. TSC itself should be fast, but I am not whether it triggers interrupt...while on the other hand HPET will deliver interrupt.
3, I compiled it in ia32 and run it with ia32-libs in amd64, it passed.
Very confusing to me. Again I can only guess that maybe in your AMD64 machine, HPET is default timer? -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
Hi Adam, On Sun, Jul 24, 2011 at 8:10 PM, Adam Lee <adam8157@gmail.com> wrote:
Hi, all
I'm working on a test which invoking setitimer(), and it hang in ia32 and ppc, but passed in amd64, could you guys give some help?
1, I know the 'value.it_interval.tv_usec' is too short, but why amd64 passed?
2, If I switch clock source from "tsc" to "hpet" on ia32, it passed.
3, I compiled it in ia32 and run it with ia32-libs in amd64, it passed.
I ran it on my 64-bit machine and it hung because the interval was so short that it generated a continuous stream of signals. Each signal took longer to process than the interval of the timer. I added some memset's (since stack variables are uninitialized, and stuff like sact will get some random values in it if you don't). I changed the interval of the timer to be 1000 usec, and changed LOOP_LIMIT to be 1E6, and I got the catcher to be called multiple times. -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
On Sun, Jul 24, 2011 at 09:09:55PM -0700, Dave Hylands wrote:
Hi Adam,
On Sun, Jul 24, 2011 at 8:10 PM, Adam Lee <adam8157@gmail.com> wrote:
Hi, all
I'm working on a test which invoking setitimer(), and it hang in ia32 and ppc, but passed in amd64, could you guys give some help?
1, I know the 'value.it_interval.tv_usec' is too short, but why amd64 passed?
2, If I switch clock source from "tsc" to "hpet" on ia32, it passed.
3, I compiled it in ia32 and run it with ia32-libs in amd64, it passed.
I ran it on my 64-bit machine and it hung because the interval was so short that it generated a continuous stream of signals.
Each signal took longer to process than the interval of the timer.
I added some memset's (since stack variables are uninitialized, and stuff like sact will get some random values in it if you don't).
I changed the interval of the timer to be 1000 usec, and changed LOOP_LIMIT to be 1E6, and I got the catcher to be called multiple times.
Thank you all, I tried it again. Xeoc E5502, RHEL 6.1: tsc: just exit without any warning hpet: hang Xeon X7550, RHEL 5.7: tsc & hpet: "The signal catcher never gained control" I'm confused, maybe the result due to the processor? -- Regards, Adam Lee -------------------------------------------------- E-mail: adam8157@gmail.com Website: http://www.adam8157.info --------------------------------------------------
participants (3)
-
Adam Lee -
Dave Hylands -
Mulyadi Santosa