Bert Miemietz wrote: > Came upon a strange thing with ddi_get_lbolt and cv_timedwait. > Following a code fragment to show the issue: > > mutex_enter(&ptr->mutex); > while (ptr->busy != 0) { > clock_t until; > (void) ddi_get_lbolt(); /* just call function, seems not to work at first > call */ > until = ddi_get_lbolt() + drv_usectohz(tmo); > if (cv_timedwait(&ptr->cv, &ptr->mutex, until) == -1) { > mutex_exit(&ptr->mutex); > err = EAGAIN; > goto somewhere_else; > } > } > mutex_exit(&mstr_ptr->vv_mutex); > > In theory the line "(void) ddi_get_lbolt();" should be completely unnecessary. > But in case I omit this line and ddi_get_lbolt() has never been called before > in the driver cv_timedwait() will not return when timeout is reached without > the condition being signaled. Inserting that (in theory useless) line makes > everything work fine. > > Did I understand or do something wrong or is it really a bug? > I'm a little bit unsure if I have seen this on all platforms. Last time I was > getting > into this trap was on Solaris x86 / single cpu machine. >
I suspect a bug in your code. Are you holding the ptr->mutex when doing the cv_signal? What is the value of tmo? Also, be aware that mutex deadlocks may occur -- cv_timedwait() drops, and reacquires the lock. If it can't reacquire the lock, then badness will ensue, and it may appear hung when it is merely blocked. -- Garrett > > > This message posted from opensolaris.org > _______________________________________________ > opensolaris-code mailing list > opensolaris-code@opensolaris.org > http://mail.opensolaris.org/mailman/listinfo/opensolaris-code > _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code