Date: Wed, 19 Feb 2020 07:42:44 -0700 From: Ian Lepore <ian@freebsd.org> To: Arpan Palit <babupalit@gmail.com>, freebsd-hackers@freebsd.org, freebsd-questions@freebsd.org Subject: Re: msleep_spin is failed to waken up even after wakeup routine is invoked for the same. Message-ID: <890a299c074fc83a02911583531d686257924be8.camel@freebsd.org> In-Reply-To: <CAF3txfi6Kz1y0a8jusGKrYFyMAER60xpkngQS0m-%2BY9G1RX5cw@mail.gmail.com> References: <CAF3txfi6Kz1y0a8jusGKrYFyMAER60xpkngQS0m-%2BY9G1RX5cw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 2020-02-19 at 14:13 +0530, Arpan Palit wrote: > Hi, > > I am facing one issue where wakeup rountine call is unable to waken up a > msleep_spin routine call with a timeout value of 10 Seconds. > > The real scenario is as follows: post a hardware command and sleep using > msleep_spin routine till interrupt comes, After getting the interrupt waken > up the sleeping process using wakeup_one/wakeup routine call. As there are > more than 2048 command and 16 parallel threads are running, > observed randomly *one or two of the posted command* is *timing out* for > which the *interrupt has came and also wakeup routine is invoked *after > getting the interrupt for the same command. > > Note: > *The issue is not seen when number of commands are less than 2048 with > timeout of 10 seconds. > *The issue can be seen with less number of commands also when timeout value > 1 second. > > Can anyone please provide me an optimized way to schedule the process or a > better way to do the scheduling. > > Thanks, > Arpan Palit > Is there any chance this is the classic "missed wakeup" scenario, where the wakeup happens before the thread enters msleep_spin()? That can happen with code structured like enqueue_request(req); err = msleep_spin(req, etc); /* Handle done req or timeout */ and a fix is to structure the code using the same idiom required for pthread_cond_wait() in userland, something like: req->doneflag = false; enqueue_request(req); while (!req->doneflag && err == 0) err = msleep_spin(req, etc); /* Handle done req or timeout */ and of course on the interrupt handler side you need something like /* lock mutex, do hardware stuff */ req->doneflag = true; wakeup(req); /* unlock mutex */ -- Ian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?890a299c074fc83a02911583531d686257924be8.camel>