Live data from Hacker News

TCP in 30 instructions (1993)

pdl.cmu.edu

21–30 of 41 posts

Re: TCP in 30 instructions (1993)

#21

Earlier quoted context omitted.

You guys are just to smart for me, I guess I'll have to withdraw from having any conversation at all since I've been downvoted into hellban for asking a question.

Here's some very personal advice. This is my opinion, and others won't agree. However, for what it's worth ... I would suggest that you would benefit from learning how to ask questions. Here's a start: http://www.catb.org/~esr/faqs/smart-questions.html However, there's more advice than that, and that, although a good start, is not to be taken as gospel. You probably also should read the site-specific commentary, and…

It also probably doesn't help that the username "FuckFrankie" sounds aggressive / combative

Re: TCP in 30 instructions (1993)

#22

I love the opinionated writing style. I wish I knew more about this so I could relate to the comments about the "compiler braindamage", "mbuf chain stupidity", and "netipl software interrupt bs".

The "compiler braindamage" is that it is generating instructions to load individual registers 4 bytes at a time where it could instead generate instructions that load eight (properly aligned) bytes at a time into two four-byte registers at once. The bytes in question are some fields in the tcp header and some fields in the pcb (which is like all the state related to the TCP connection).

These instructions here are loading the header into registers:

        ld [%i0+4],%l3     ! load packet tcp header fields
        ld [%i0+8],%l4
        ld [%i0+12],%l2
        ld [%i0+16],%l0
That's the assembler for this:

        u_long seq = ((u_long*)ti)[1];
        u_long ack = ((u_long*)ti)[2];
        u_long flg = ((u_long*)ti)[3];
        u_long sum = ((u_long*)ti)[4];
ld loads 4 bytes at a time into a register but there is a sparc instruction ldd that will load 8 bytes into two registers at a time. If the compiler used ldd these four instructions turn into two. That gets us from 33 to 31. I'm not 100% clear which two fields from the pcb can be loaded simultaneously but there is this line

        ld [%i1+72],%o0                 ! compute header checksum
and then further down

       ld [%i1+68],%o0
which I think are:

       u_long cksum = tp->ph_sum;
and

        if ((flg & FMASK) == tp->pred_flags && seq == tp->rcv_nxt) {
Obviously that line is multiple instructions but what I meant is the part where tp->rcv_nxt is loaded into a register.

So probably tp->ph_sum and tp->rcv_nxt are adjacent in his version of struct tcpcb and he thinks the compiler should do use the same parallel load instruction (loading two registers from 8 bytes at once) for those fields.

Re: TCP in 30 instructions (1993)

#23

Earlier quoted context omitted.

Wouldn't "all the TCP logic" be the entire internet?

The internet is a very large and general term. It comprises millions of servers, routers, generally includes things like web browsers, http, etc. TCP is just one protocol of the thousands of protocols used for the internet, typically to carry other protocols. UDP is also used on the internet. "not all the logic" means that this implementation is not a full implementation of the TCP protocol. Check out: http://en.wiki…

Dewees?

Re: TCP in 30 instructions (1993)

#25

Might be off topic, but I have always wondered where do these public domain university emails come from? Was E-mail a public forum back then?

I'm not sure what you mean by "these public domain university emails." This is an email that has been saved and re-forwarded many times, including to mailing lists such as the one archived in the main link. Originally it would have been forwarded by either the sender or one of the recipients.

Re: TCP in 30 instructions (1993)

#26
post #18

I am curious to know if today's modern TCP stacks (windows, popular linux distros,etc..) are coded with the same approach. Does anyone know?

More or less, yes.

In the original TCP implementations from the early 80s, performance was (understandably) not the main priority.. they just wanted to get it working first. Also, nobody was sure what networking protocols would become popular (IP? OSI? XNS?) so a lot of work went into making everything as flexible as possible. This reached an apogee with AT&T's "STREAMS" subsystem (a competitor to the sockets API for writing networking code on UNIX) which was very flexible but also extremely complicated.

What Van Jacobson's work was saying is "look guys: by paying close attention to the fastpath you can saturate your 10Mbps network with TCP traffic" I'm sure everybody who has written a TCP stack has seen this email and has taken the tricks to heart.

These days not all of the tweaks might be still relevant. For instance, the hardware is probably doing the hardware checksum for you. However, the spirit of "do as little as possible in the fastpath" is certainly still followed in modern stacks.

Re: TCP in 30 instructions (1993)

#27
post #18

I am curious to know if today's modern TCP stacks (windows, popular linux distros,etc..) are coded with the same approach. Does anyone know?

More or less, yes. In the original TCP implementations from the early 80s, performance was (understandably) not the main priority.. they just wanted to get it working first. Also, nobody was sure what networking protocols would become popular (IP? OSI? XNS?) so a lot of work went into making everything as flexible as possible. This reached an apogee with AT&T's "STREAMS" subsystem (a competitor to the sockets API for…

Just as a historical note, classic Mac OS (versions 7-9) used STREAMS for TCP, in the Open Transport networking API. Sockets were provided as a wrapper around STREAMS, which worked about as well as you might expect. It had its fans but most of us were pleased to get real sockets in Mac OS X.

Re: TCP in 30 instructions (1993)

#28
post #5

Earlier quoted context omitted.

No, it would not be anything close.

Well, TCP is a very simple protocol so I can't imagine what the OP means by "all of TCP" unless he's talking about IP and it's associated services.

TCP is actually extremely complex, see http://en.m.wikipedia.org/wiki/Transmission_Control_Protocol

I don't think I could implement it in under 4000 sloc, and I'd guess it'd be over two months worth of work for just a minimal TCP stack that could interoperate with the internet at large.

Re: TCP in 30 instructions (1993)

#29

Might be off topic, but I have always wondered where do these public domain university emails come from? Was E-mail a public forum back then?

In the header at the top it says Cc: ips@ece.cmu.edu, so it was carbon copied to the mailing list.

Re: TCP in 30 instructions (1993)

#30
post #28

Earlier quoted context omitted.

Well, TCP is a very simple protocol so I can't imagine what the OP means by "all of TCP" unless he's talking about IP and it's associated services.

TCP is actually extremely complex, see http://en.m.wikipedia.org/wiki/Transmission_Control_Protocol I don't think I could implement it in under 4000 sloc, and I'd guess it'd be over two months worth of work for just a minimal TCP stack that could interoperate with the internet at large.

TCP is only complex because of all the optional bits for performance tuning, but if you are only interested in size, look on the embedded side. The actual core functionality is much smaller, and I would even go as far as to say that a lot of the widely used open-source TCP/IP stacks obfuscate this with their added complexities.

E.g. http://en.wikipedia.org/wiki/UIP_(micro_IP)

Post reply on HN