Re: [hybi] voting on frame length ideas

John Tamplin <jat@google.com> Mon, 23 August 2010 16:50 UTC

Return-Path: <jat@google.com>
X-Original-To: hybi@core3.amsl.com
Delivered-To: hybi@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id 56A293A6922 for <hybi@core3.amsl.com>; Mon, 23 Aug 2010 09:50:42 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -105.147
X-Spam-Level:
X-Spam-Status: No, score=-105.147 tagged_above=-999 required=5 tests=[AWL=0.229, BAYES_00=-2.599, FM_FORGED_GMAIL=0.622, HTML_MESSAGE=0.001, J_CHICKENPOX_66=0.6, RCVD_IN_DNSWL_MED=-4, USER_IN_WHITELIST=-100]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OF0bt6v8yYR7 for <hybi@core3.amsl.com>; Mon, 23 Aug 2010 09:50:39 -0700 (PDT)
Received: from smtp-out.google.com (smtp-out.google.com [74.125.121.35]) by core3.amsl.com (Postfix) with ESMTP id 448773A68BF for <hybi@ietf.org>; Mon, 23 Aug 2010 09:50:39 -0700 (PDT)
Received: from wpaz33.hot.corp.google.com (wpaz33.hot.corp.google.com [172.24.198.97]) by smtp-out.google.com with ESMTP id o7NGpBWY001770 for <hybi@ietf.org>; Mon, 23 Aug 2010 09:51:11 -0700
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1282582272; bh=P3gkvXpovzqD7u6Ke2Lar6Asdiw=; h=MIME-Version:In-Reply-To:References:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=LKKGBQ7o/Oa3JevPU0ftXWa9FhaWhSpqpsdNqbyeuLjFx2r33sSuTl7hlTOu1s6oG 2U3w6Y+nm2yBu5Vg1tbvA==
DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=mime-version:in-reply-to:references:from:date:message-id: subject:to:cc:content-type:x-system-of-record; b=s5hLsXkhRyJO1j4VMtPSzFtBB1EkcPOJ0tkBbOyG3Y9rv49BTLCN6UEa1DdoP8BpO WgeoQNub9zJOxxCy9mtVA==
Received: from ywe9 (ywe9.prod.google.com [10.192.5.9]) by wpaz33.hot.corp.google.com with ESMTP id o7NGobcm003154 for <hybi@ietf.org>; Mon, 23 Aug 2010 09:51:10 -0700
Received: by ywe9 with SMTP id 9so1779836ywe.33 for <hybi@ietf.org>; Mon, 23 Aug 2010 09:51:10 -0700 (PDT)
Received: by 10.150.59.19 with SMTP id h19mr5392490yba.389.1282582270103; Mon, 23 Aug 2010 09:51:10 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.151.103.4 with HTTP; Mon, 23 Aug 2010 09:50:50 -0700 (PDT)
In-Reply-To: <fe0a821d3c2bd14039e395ed1800263a.squirrel@sm.webmail.pair.com>
References: <AANLkTinh5ON_L9yc29Y2CMrEeJHV=nvRhQauMSFi3ib1@mail.gmail.com> <4C7222EC.2000804@gmx.de> <dd27e6adb004dcab167038b2ec0ab280.squirrel@sm.webmail.pair.com> <AANLkTinmp+mG0ac4FgqFnJJZjxR5_hcaXYX5H7Y+cNNO@mail.gmail.com> <fe0a821d3c2bd14039e395ed1800263a.squirrel@sm.webmail.pair.com>
From: John Tamplin <jat@google.com>
Date: Mon, 23 Aug 2010 12:50:50 -0400
Message-ID: <AANLkTinsTTvoecxE-kqVTCL4QiK2WN=7Lyb1-QSE6_CN@mail.gmail.com>
To: shelby@coolpage.com
Content-Type: multipart/alternative; boundary="000e0cd6e8309ad22e048e807467"
X-System-Of-Record: true
Cc: Hybi <hybi@ietf.org>
Subject: Re: [hybi] voting on frame length ideas
X-BeenThere: hybi@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: Server-Initiated HTTP <hybi.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/hybi>
List-Post: <mailto:hybi@ietf.org>
List-Help: <mailto:hybi-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 23 Aug 2010 16:50:42 -0000

On Mon, Aug 23, 2010 at 12:34 PM, Shelby Moore <shelby@coolpage.com> wrote:

> > I think it is ludicrous to suggest that an implementation would advertise
> > a
> > maximum frame length of 126 just so its code for option #2 would look
> > like:
> >
> > int len=readByte();
> >
> > rather than:
> >
> > long long len = readByte();
> > switch (len) {
> >   case 126:
> >      len = readUnsignedShort();
> >      break;
> >   case 127:
> >      len = readLongLong();
> >      break;
> > }
>
>
> I do not think is it ludicrous for an implementation to choose the option
> that gives it the highest throughput.
>

I think that depends on what you call througput.  If you mean frames/second,
then clearly it should always indicate a size of 1 so it can get the most
possible frames.  If you mean payload bytes/second, then I disagree --
having one 100k frame and doing an extra compare instruction is going to get
far more payload bytes through in the same time than processing 100k 1-byte
frames, even if it doesn't include a comparison.


> I do not expect an implementation to be coded with concern as to the load
> on the senders CPU, when it conflicts with its own internal efficiency.
> Economics and game theory.


There was no such assumption, see above.


> I already refuted that:
>
> http://www.ietf.org/mail-archive/web/hybi/current/msg03517.html
>
> If the receiver expects to be attacked, then checking the size field
> guarantees nothing.


Not checking it means a sender that ignored the maximum frame size could get
the receiver out of sync with framing boundaries.  Experience has shown many
attacks to follow from such problems.

> Regardless, I think the cost of a compare and an untaken branch is
> > absolutely negligible when comparing the other costs of processing a
> > frame.
>
> Someone else in list said otherwise.


Which you are taking out of context and extending it far beyond the
circumstances it was intended.  You also attributed that person to support
your proposal, which in fact they did not.  Regardless, it would be best to
speak your own opinions rather than restating someone elses.


> Any way, we lose nothing (negligible
> 2-4% loss) by getting rid of the conditional branches.  And we gain more
> reserved bits and other advantages with the "Option 8/16/32/64-bit".
>
> Are you arguing both sides of the fence in the post below?
>
> http://www.ietf.org/mail-archive/web/hybi/current/msg03532.html
>
> Is the extra byte costly or not?


Between these options, there is an extra byte for small frames regardless.


> >> 3) After I proposed "Option 15/63-bit", a new option was proposed
> >> "Option
> >> 8/16/32/64-bit". I can't yet decide between these two options, so I
> >> voted
> >> for both of them in the informal poll (and voted against all other
> >> options, except "Option #2 - 7/16/63-bit"). The "Option 8/16/32/64-bit"
> >> gives more reversed bits, but it adds a CPU cost of loading the LenLen,
> >> loading a value of 1 and left shifting by LenLen.
> >
> >
> > Rather than calculating a number of bytes to read for the length, it
> seems
> > more likely it will be:
> >
> > short header = readUnsignedShort();
> > long long len;
> > // possibly shifting to make it 0-3 for table jump implementations
> > switch(header & LEN_LEN_MASK) {
> >   case LEN_LEN_8:
> >      len = readByte();
> >      break;
> >   case LEN_LEN_16:
> >      len = readUnsignedShort();
> >      break;
> >   case LEN_LEN_32:
> >      len = readUnsignedLong();
> >      break;
> >   case LEN_LEN_64:
> >      len = readLongLong();
> >      break;
> > }
>
>
> Yikes! Why?  Why not use the left shift, it is much more efficient than a
> branch.  Branches destroy CPU pipelining.
>

You are going to have branches anyway.  Your suggestion would be (inlining
the loop for clarity):

short header = readUnsignedShort();
long long len;
int lenlen = (header & LEN_LEN_MASK) >> LEN_LEN_SHIFT;
int lengthBytes = 1 << lenlen;
while (lengthBytes-- > 0) {
  lenlen = (lenlen << 8) | readByte();
}

Even if you unroll the loop and branch to different points in the reading
code, there is still a branch there:

It is really pretty basic -- if you have a variable number of bytes for the
length, there will be branches regardless.  If the number of branches are
small, you can optimize for the branch-not-taken case, which will have
minimal impact on the pipeline on most architectures in the 98% case.

-- 
John A. Tamplin
Software Engineer (GWT), Google