Re: settimeofday function taking 24 - 30 minutes to complete

From: Garrett Cooper <youshi10_at_u.washington.edu>
Date: Tue, 19 Dec 2006 12:20:18 -0800
On Dec 19, 2006, at 12:01 PM, Devon H. O'Dell wrote:

> 2006/12/19, Garrett Cooper <youshi10_at_u.washington.edu>:
>> Scot Hetzel wrote:
>> > While working on implementing the settimeofday function in the
>> > linuxolator, I was using the LTP testcase settimeofday01 to test  
>> it.
>> > Running this test caused the system to hang for 24-30 minutes.
>> >
>> > I then decided to rewrite the testcase so that it would run on
>> > FreeBSD, and it also hung the system for 24-30 minutes.  What the
>> > settimeofday01 test was doing is to set the time to a known  
>> value (100
>> > sec, 100 usec) and then use gettimeofday to retrieve the current  
>> time.
>> > It then compared the returned value to check if it was within  
>> +/- 500
>> > msec.
>> >
>> > I have since reduced the testcode down to the following testcase  
>> that
>> > is causing the hang.
>> >
>> > Any ideals as to what could be causing this hang?
>> >
>> > Scot
>> >
>> > #include <sys/time.h>
>> > #include <errno.h>
>> > #include <unistd.h>
>> >
>> > #define VAL_SEC         100
>> > #define VAL_MSEC        100
>> >
>> > int main(int argc, char **argv)
>> > {
>> >        struct timeval tp, tp1, save_tv;
>> >        long return_test, errno_test;
>> >        suseconds_t delta;
>> >
>> > #define TEST(SCALL) \
>> >        do { \
>> >                errno = 0; \
>> >                return_test = SCALL; \
>> >                errno_test = errno; \
>> >        } while (0)
>> >
>> >        /* Save the current time values */
>> >        if ((gettimeofday(&save_tv, (struct timezone *)&tp1)) ==  
>> -1) {
>> >                printf("BROK: gettimeofday failed. errno=%d\n",  
>> errno);
>> >                exit(1);
>> >        } else {
>> >                printf("INFO: Saved current time\n");
>> >        }
>> >
>> >        tp.tv_sec  =  VAL_SEC;
>> >        tp.tv_usec  =  VAL_MSEC;
>> >
>> >        /* Hang occurs here */
>> >        TEST(settimeofday(&tp, NULL));
>> >        if (return_test == -1) {
>> >                printf("FAIL: Error Setting Time, errno=%d\n",
>> > errno_test);
>> >        } else {
>> >                printf("INFO: settimeofday completed sucessfully 
>> \n");
>> >        }
>> >
>> >        /* restore the original time values. */
>> >        if ((settimeofday(&save_tv, NULL)) == -1) {
>> >                printf("WARN: FATAL COULD NOT RESET THE CLOCK\n");
>> >                printf("FAIL: Error Setting Time, errno=%d (%d, % 
>> d)\n",
>> >                         errno, tp.tv_sec, tp.tv_usec);
>> >        } else {
>> >                printf("INFO: Reset time to original value\n");
>> >        }
>> >
>> >        return(0);
>> > }
>> >
>>     Not sure about why it takes so long to complete, but it seems  
>> as if
>> the system is 'hanging' because it probably is using up all of  
>> your CPU
>> resources in the while loop under your TEST macro. Maybe the near  
>> 100%
>> CPU usage is effecting kernel operations as well, i.e. slowing it  
>> down
>> to stone age speeds? sleep(3)/nanosleep(2) to the rescue?
>
> The while loop in the TEST macro is a do { /* ... */ } while (0); so
> it should only execute once.
>
> --Devon

	Duh, of course. Sorry, must be hungry ><.
	One thing though, why don't you define your macro outside main()?  
Could it (TEST) be invoking itself instead many times through  
implicit recursion? I wouldn't think so because you used '\' to carry  
on the line, but meh.. you never know.
	I'll try compiling and running your code on a FC5 box since I don't  
have my FreeBSD box in front of me to test it on.
-Garrett
Received on Tue Dec 19 2006 - 19:20:15 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:04 UTC