Re: [CFR] Replacing while loops with proper division and multiplication

From: Neel Natu <neelnatu_at_gmail.com>
Date: Fri, 5 Jun 2015 12:05:00 -0700
Hi Hans,

On Fri, Jun 5, 2015 at 11:53 AM, Hans Petter Selasky <hps_at_selasky.org> wrote:
> On 06/05/15 20:31, Neel Natu wrote:
>>>>
>>>> -       runs = 0;
>>>> >>-       while (now >= state->nexthard) {
>>>> >>-               state->nexthard += tick_sbt;
>>>> >>-               runs++;
>>>> >>-       }
>>>> >>-       if (runs) {
>>>> >>+       runs = (now - state->nexthard) / tick_sbt;
>>>> >>+       if (runs > 0) {
>>>> >>+               printf("R%d ", (int)runs);
>>>> >>+               state->nexthard += tick_sbt * runs;
>>>> >>                 hct = DPCPU_PTR(hardclocktime);
>>>> >>                 *hct = state->nexthard - tick_sbt;
>>>> >>                 if (fake < 2) {
>>
>> There is a difference in behavior in the two implementations when 'now
>> == state->nexthard'. In the loop-based implementation this would end
>> up with 'runs = 1' whereas in the division-based implementation it
>> would end up with 'runs = 0'.
>>
>> I am not sure if this is intentional or just an oversight.
>
>
> Hi Neel,
>
> The nexthard is mainly updated in this piece of code. We can assume that
> "state->nexthard" is aligned to "ticks_sbt". If "state->nexthard % ticks_sbt
> == 0", is that still an issue?
>

I am not very familiar with this subsystem to make the call (mav_at_ or
davide_at_ would know for sure though).

I just noticed a discrepancy in the patch and wanted to highlight that
in case it might be an issue.

best
Neel

> --HPS
Received on Fri Jun 05 2015 - 17:05:02 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:58 UTC