[systemd-devel] [PATCH 09/24] sd-dhcp6-client: Add DHCPv6 client Solicitation timeout handling

Patrik Flykt Patrik.Flykt at linux.intel.com
Thu Jun 19 00:55:25 PDT 2014


	Hi,

On Wed, 2014-06-18 at 15:50 +0200, Zbigniew Jędrzejewski-Szmek wrote:
> > +        if (!client->retransmit_time) {
> > +                client->retransmit_time =
> > +                        client_timeout_compute_random(init_retransmit_time);
> > +        } else {
> > +                if (max_retransmit_time &&
> > +                    client->retransmit_time > max_retransmit_time / 2)
> > +                        client->retransmit_time = client_timeout_compute_random(max_retransmit_time);
> > +                else
> > +                        client->retransmit_time = client_timeout_compute_random(client->retransmit_time);

There is a bug in here, this latter one should be += so that the value
actually doubles, thanks for noticing!

> > +        }
> Hm, I don't understand why the " / 2" is here. It seems that the
> retransmit time suddenly jumps from max_retransmit_time/2 to
> max_retransmit_time.

The existing client->retransmit_time contains the value calculated for
the current timeout. With the above bug fixed, this value is going to be
doubled with some randomness added. Instead of wasting expensive(?) CPU
cycles on computing the new, properly doubled value with randomness
added and see it thrown away immediately if found to be greater than the
given max_retransmit_time, I tried to be smart and avoid the computation
by checking it against half the value up front. After that the code only
needs to do the proper computation once.

It may have been clearer to multiply the retransmit_time by two instead.
Here I also rely on the compiler being smart enough to replace
multiplications or divisions by two with a bit shift to get it done
quickly enough.


Cheers,

	Patrik



More information about the systemd-devel mailing list