Skip to content

Skip the ARP cache search for an active TCP peer - #1382

Open
comotion wants to merge 3 commits into
FreeRTOS:mainfrom
comotion:tcp-skip-arp-lookup
Open

comotion wants to merge 3 commits into
FreeRTOS:mainfrom
comotion:tcp-skip-arp-lookup

Conversation

@comotion

@comotion comotion commented Nov 3, 2026

Copy link
Copy Markdown

Skip the ARP cache search for an active TCP peer

Description

A connected TCP socket can now send each segment to the peer MAC in its header template, and search the ARP cache only after the peer has been quiet for a while, as RFC 1122 2.3.2.1 allows.
The search runs for every sent segment and limits send throughput ona slow CPU.

  • ipconfigTCP_SKIP_ARP_LOOKUP_MS sets how long the peer may be quiet before the stack searches the cache again, and a hit then replaces the MAC in the template.
  • The default is 0, which searches the cache for every segment as before.

Test Steps

Measure transmit speeds for MSS, 16KB and 256KB transmits.
My measurements are on a 125MHz Nios-V with a msgDMA ethernet driver and a 10GbE PHY.
On TX, 1514 byte MSS sends this is 8% faster than baseline, 16KB sends, this is 3% faster and on 256KB sends, 2% faster.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

#1380

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

A connected TCP socket can now send each segment to the peer MAC in its
header template, and search the ARP cache only after the peer has been
quiet for a while, as RFC 1122 2.3.2.1 allows.

- ipconfigTCP_SKIP_ARP_LOOKUP_MS sets how long the peer may be quiet
  before the stack searches the cache again, and a hit then replaces
  the MAC in the template.
- The search runs for every sent segment and limits send throughput on
  a slow CPU.
- The default is 0, which searches the cache for every segment as
  before.

@htibosch htibosch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will test this PR and come back to it. I like it.

}
#else /* if ( ipconfigTCP_SKIP_ARP_LOOKUP_MS > 0U ) */
{
eResult = eARPGetCacheEntry( &ulDestinationIPAddress, &xMACAddress, &pxEndPoint );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @comotion

You are right, this was a waste of time to call eARPGetCacheEntry over and again, knowing that the function has no optimisation.

This is indeed the place to store the counter MAC-address:
pxSocket->u.xTCP.xPacket.u.ucLastPacket )->xEthernetHeader.xSourceAddress.ucBytes.

I am curious what other developers think about this proposal. I like it!

I will test it together with your PR #1381

Thanks,
Hein

The proof runs once with the default configuration and once with the skip enabled, so CI checks the code that the option compiles in.
The skip reads the time of the socket's last activity, which only hang protection keeps, so a build without it failed with a missing member. It now stops with an error that names the option it needs. That time also moves on every state change, so the description no longer says it is only the time the peer was heard from.
@comotion

Copy link
Copy Markdown
Author

Thanks for testing. I'm adding CBMC proof run for this branch and a dependency on ipconfigTCP_HANG_PROTECTION, since the build fails if that is set to off.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants