Subject: pthread_create and timer_settime
To: None <tech-userlevel@netbsd.org>
From: Herb Peyerl <hpeyerl@beer.org>
List: tech-userlevel
Date: 04/18/2005 16:39:07
I'm mostly doing a brain-dump because I'm confused and in a corner...

Background:  I'm having trouble with 'ntop' which keeps dying shortly  
after startup with:

assertion "retval == 0" failed: file  
"/home/builds/ab/netbsd-2-0-2-RELEASE/src/lib/libpthread/ 
pthread_alarms.c", line 105, function "pthread__alarm_add"

So, pthread__alarm_add calls timer_settime which is really  
sys_timer_settime.  By checking with ddb, I can see that (itimerspec  
*)value is getting  >1000000 nanoseconds as an argument:

db> b sys_timer_settime
db> c
Breakpoint in pid 365.1 (ntop) at       netbsd:sys_timer_settime:        
pushl   %
ebp
db> t
sys_timer_settime(cb3e5948,cc863f64,cc863f5c,0,c123d000) at  
netbsd:sys_timer_set
time
syscall_plain() at netbsd:syscall_plain+0x7e
--- syscall (number 237) ---
0x493bc10b:
db> x/x cc863f64,10
netbsd:usb_all_tasks+0xc07cff0: 4           0           bfbff6d0    0
netbsd:usb_all_tasks+0xc07d000: 0           0           0           0
netbsd:usb_all_tasks+0xc07d010: 1           c123d040    c1115fa0     
49396250
netbsd:usb_all_tasks+0xc07d020: 64          bfbff8a0    bfbff6e8     
c0100d64
db> x/x bfbff6d0,10
0xbfbff6d0:     0           5f5e100     0           5f5e100      
49396250    0
0xbfbff6e8:     bfbff7f8    4938ee61    64          1            
bfbff7f8    4938
ee14    49388cb2    49e00000    bfbff71c    64
db>

5F5E100 = 100000000

In sys/kern/kern_time.c:

int
itimerfix(struct timeval *tv)
{

         if (tv->tv_sec < 0 || tv->tv_usec < 0 || tv->tv_usec >= 1000000)
                 return (EINVAL);
         if (tv->tv_sec == 0 && tv->tv_usec != 0 && tv->tv_usec < tick)
                 tv->tv_usec = tick;
         return (0);
}


So itimerfix() is getting 100000 which is less than 1000000.  But I  
already know from this printf() I put in sys_timer_settime():

         if (itimerfix(&val.it_value) || itimerfix(&val.it_interval)) {
                 // 3: 16 0
                 printf("3: %x %x\n", itimerfix(&val.it_value),  
itimerfix(&val.it_interval));
                 return (EINVAL);
         }

that itimerfix(&val.it_value) is returning EINVAL.

Anyway, maybe I'm going down the garden path here but I'd really like  
to just make ntop work.  Others have complained about the same thing so  
I thought I'd dig in.

Does anyone have any ideas or have I totally missed the boat?