Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Mar 2007 12:16:41 -0800 (PST)
From:      Jeff Roberson <jroberson@chesapeake.net>
To:        Max Laier <max@love2party.net>
Cc:        cvs-src@freebsd.org, Jeff Roberson <jeff@freebsd.org>, src-committers@freebsd.org, cvs-all@freebsd.org
Subject:   Re: cvs commit: src/sys/kern sched_ule.c
Message-ID:  <20070317121427.H560@10.0.0.1>
In-Reply-To: <200703172100.13218.max@love2party.net>
References:  <200703171813.l2HIDXWI008212@repoman.freebsd.org> <20070317110821.I560@10.0.0.1> <200703172100.13218.max@love2party.net>

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

On Sat, 17 Mar 2007, Max Laier wrote:

> On Saturday 17 March 2007 20:09, Jeff Roberson wrote:
>> Any language lawyers care to comment on this?
>
> I find this strange.  According to the spec "(Decrementing is equivalent
> to subtracting 1.)", but "pri = --pri % RQ_NQS;" will behave like you
> expect, while "pri = (pri - 1) % RQ_NQS;" clearly didn't.

I noticed this as well.

When you do --pri, pri is promoted to int for the math and then demoted 
back to char wich truncates the value.  Subsequently this value is used 
in the % operation, which gives the expected results.

When you do pri - 1 the intermediate result is promoted to a signed int 
which doesn't yield the result you'd like when you mod with 64.

Jeff

>
>> On Sat, 17 Mar 2007, Jeff Roberson wrote:
>>> jeff        2007-03-17 18:13:33 UTC
>>>
>>>  FreeBSD src repository
>>>
>>>  Modified files:
>>>    sys/kern             sched_ule.c
>>>  Log:
>>>   - Cast the intermediate value in priority computtion back down to
>>>     unsigned char.  Weirdly, casting the 1 constant to u_char still
>>> produces a signed integer result that is then used in the %
>>> computation.  This avoids that mess all together and causes a 0 pri
>>> to turn into 255 % 64 as we expect.
>>>
>>>  Reported by:    kkenn (about 4 times, thanks)
>>>
>>>  Revision  Changes    Path
>>>  1.190     +1 -1      src/sys/kern/sched_ule.c
>
> -- 
> /"\  Best regards,                      | mlaier@freebsd.org
> \ /  Max Laier                          | ICQ #67774661
> X   http://pf4freebsd.love2party.net/  | mlaier@EFnet
> / \  ASCII Ribbon Campaign              | Against HTML Mail and News
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070317121427.H560>