Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Aug 2002 20:07:46 -0700 (PDT)
From:      Julian Elischer <julian@elischer.org>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        Archie Cobbs <archie@dellroad.org>, arch@FreeBSD.ORG
Subject:   Re: Process/thread states.
Message-ID:  <Pine.BSF.4.21.0208261956550.82717-100000@InterJet.elischer.org>
In-Reply-To: <3D6ACE3A.3D17935B@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help


On Mon, 26 Aug 2002, Terry Lambert wrote:

> Archie Cobbs wrote:
> > Julian Elischer writes:
> > > #define TD_ST_SUSPQ        0x01    /* uses runq field */
> > > #define TD_ST_RUNQ         0x02    /* uses runq field */
> > > #define TD_ST_RUNNING      0x03    /* uses no (virtual) field */
> > > #define TD_ST_MTX          0x04    /* uses mtx field */
> > > #define TD_ST_RQ_MASK      0x07    /* mask of non sleep states */
> > > #define TD_ST_SLPQ         0x08    /* uses slpq field */
> > > enum thread_state {
> [ ... ]
> 
> > I like your idea.. it makes things clearer because they are more
> > explicit. Whenever "implicit developer knowledge" is required to
> > do something correctly that's more opportunity for bugs.
> > 
> > If you comment those flags in the header file(s) really well,
> > that's even better. Especially all of the cases where there is
> > any duplicate or inter-dependent state, which can be evil.
> > 
> > E.g., if TDS_SLP always implies wchan != NULL, then that should be
> > commented somewhere.
> > 
> > That is, any 'trickiness' in an object's state like depedence between
> > fields or special invariants should either be very clearly documented
> > or else hidden behind an object-like functional interface (like Alfred
> > suggested).
> 
> 
> The part that causes me a little bit of pain is that the compares
> will all end up having to be:
> 
> 	if ( (x & VALUE) == VALUE)
> 
> or
> 
> 	if ( (x & VALUE) != VALUE)
> 
> To get them out of the bitmaps.  This makes the compares look a
> little cleaner (I guess) but it doubles the number of cycles for
> each one, when the common case is/should be that only one bit is
> significant (e.g. the use of McCarthy operators like && and ||
> save work on failure/success, respectively).
> 
> I guess there is no way to refactor the code so that the depndencies
> don't have to be tested?


One test could be:
if (td->td_state == TDS_RUNQ)

this is a big win becasue it also tests that you are NOT on the sleep
queue. 

only way to test them completely separatly would be to put the m in
separate words..

if ( (td->td_state1 == TDS_RUNQ) && (td->td_flags & TDF_ONSLPQ == 0))


but at the moment that looks like:

if ( (td->td_state == TDS_RUNQ) && (td->td_wchan == 0))

which is not so different and harder to remember to do all the time..


if you didn't care about the condition of the sleep queue then you would
have reverse efficienciess..

e.g.
if ((td->td_state & TDS_MASK) == TDS_RUNQ)
vs
if (td->td_state1 == TDS_RUNQ) 
vs
if (td->td_state == TDS_RUNQ)
 
you win sometimes you lose other times..
the thing that bothers me is that in the current situation, you
have this thing called SLEEP state, but what it really means is 
"SLEEP in the absence of anythign better" state
and it doesn;t even reflect whether or not the thread can be awakenned,
or is on the sleep queue, because that is a completely differnet test.

I'd like to do it with inlines and MACROs as much as possible,
but there are som places where it gets tricky to do so..
e.g. in the mutex code..


> 
> -- Terry
> 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0208261956550.82717-100000>