Re: kernel condvars: how to use?

2017-12-13 Thread Mouse
Okay, I seem to have things at least mostly working. For anyone interested, I've created a new3/ directory, parallel to the new2/ I mentioned upthread, with my current version in it. I think I've fixed most of the issues people have raised; the major exception that comes to mind is that it's

Re: kernel condvars: how to use?

2017-12-11 Thread Taylor R Campbell
> Date: Mon, 11 Dec 2017 11:13:16 -0500 (EST) > From: Mouse > > > If read does > > > while (sc->sc_foo < sc->sc_bar) > > cv_wait(>sc_cv, >sc_lock); > > > then whoever changes sc_foo or sc_bar might test whether they changed > > from sc->sc_foo <

Re: kernel condvars: how to use?

2017-12-11 Thread Mouse
>>> If anything, you should just test rather whether you changed from a >>> state that would block a read to a state in which a read can make >>> progress. >> That's kind-of what LPT_RF_WAITING records. > What I meant is the condition that read actually loops on. [...] Yes, that's what I thought

Re: kernel condvars: how to use?

2017-12-10 Thread Taylor R Campbell
> Date: Fri, 8 Dec 2017 14:00:40 -0500 (EST) > From: Mouse > > > If anything, you should just test rather whether you changed from a > > state that would block a read to a state in which a read can make > > progress. > > That's kind-of what LPT_RF_WAITING records.

Re: kernel condvars: how to use?

2017-12-08 Thread Mouse
>>> Where do you set LPT_RF_WAITING? >> Hm, now that you mention it, I think I don't. > Note that a flag like this is not normally necessary, Of course. > or even particularly helpful -- cv_broadcast already has essentially > the same optimization internally. That doesn't surprise me, but it

Re: kernel condvars: how to use?

2017-12-08 Thread Taylor R Campbell
> Date: Fri, 8 Dec 2017 09:04:25 -0500 (EST) > From: Mouse > > > Where do you set LPT_RF_WAITING? > > Hm, now that you mention it, I think I don't. Note that a flag like this is not normally necessary, or even particularly helpful -- cv_broadcast already has

Re: kernel condvars: how to use?

2017-12-08 Thread Mouse
> For lptclose, note that callout_stop does not wait for the callout to > stop if it was in the middle of executing, and does not destroy it. > You must use callout_halt to wait, and then use callout_destroy to > destroy it. Okay, manpage bug - 5.2's callout(9) does not mention callout_halt

Re: kernel condvars: how to use?

2017-12-08 Thread Mouse
> Where do you set LPT_RF_WAITING? Hm, now that you mention it, I think I don't. That should prevent read() from ever being woken up, but I don't think it should deadlock the whole system. > Some other general comments: > Are you sure that's the code you're using? lpt_raw_read seems to >

Re: kernel condvars: how to use?

2017-12-08 Thread Nick Hudson
On 12/08/17 09:04, Nick Hudson wrote: On 12/08/17 03:26, Mouse wrote: [Brian Buhrow] 1.  [...].  Mutexes that use spin locks can't be used in interrupt context. Sure you don't have that backwards?  I _think_ mutex(9) says that spin mutexes are the only ones that _can_ be used from an

Re: kernel condvars: how to use?

2017-12-08 Thread Nick Hudson
On 12/08/17 03:26, Mouse wrote: [Brian Buhrow] 1. [...]. Mutexes that use spin locks can't be used in interrupt context. Sure you don't have that backwards? I _think_ mutex(9) says that spin mutexes are the only ones that _can_ be used from an interrupt. Brain did get it backwards. To

Re: kernel condvars: how to use?

2017-12-07 Thread Taylor R Campbell
> Date: Thu, 7 Dec 2017 22:26:54 -0500 (EST) > From: Mouse > > DIAGNOSTIC and DEBUG are both on already. None of the LOCK* options > are, though - see Paul Goyette's response, below. My usual debug-all-the-things kernel configuration is: makeoptions DBG=-"-g"

Re: kernel condvars: how to use?

2017-12-07 Thread Mouse
Omnibus reply here to some half-dozen of the replies; I'll try to get all the attributions right. First, a big thank you to everyone who replied. I was not expecting this many, nor this helpful, responses to something about NetBSD as old as 5.2! [me - all the double-quoted text here is mine] >>

Re: kernel condvars: how to use?

2017-12-07 Thread Paul Goyette
On Thu, 7 Dec 2017, Brian Buhrow wrote: 4. If you run into lock contention when debugging your code, pay careful attention to who holds the lock at the time of the panic. I found times when I was locking against myself in non-obvious manners. You might well find LOCKDEBUG to be your friend

Re: kernel condvars: how to use?

2017-12-07 Thread Brian Buhrow
. -Brian On Dec 7, 6:24pm, Mouse wrote: } Subject: kernel condvars: how to use? } I'm trying to write some kernel code, interlocking between an interrupt } (in my case, a callout()-called function) and a driver read() function. } I'm using 5.2, so if this is because of bugs that have been fixed

Re: kernel condvars: how to use?

2017-12-07 Thread Taylor R Campbell
> Date: Thu, 7 Dec 2017 18:24:22 -0500 (EST) > From: Mouse > > On reflection, I think I know why. Userland's syscall handler took the > mutex in preparation for cv_wait_sig(), the interrupt happens, my code > is called (verified with a printf), and it tries to take

Re: kernel condvars: how to use?

2017-12-07 Thread Taylor R Campbell
> Date: Thu, 7 Dec 2017 18:24:22 -0500 (EST) > From: Mouse > > db{0}> tr > breakpoint() at netbsd:breakpoint+0x5 > comintr() at netbsd:comintr+0x53a > Xintr_ioapic_edge7() at netbsd:Xintr_ioapic_edge7+0xeb > --- interrupt --- > x86_pause() at netbsd:x86_pause >

kernel condvars: how to use?

2017-12-07 Thread Mouse
I'm trying to write some kernel code, interlocking between an interrupt (in my case, a callout()-called function) and a driver read() function. I'm using 5.2, so if this is because of bugs that have been fixed since then, that's useful information. (And anyone who isn't interested because I'm on