From: Eric Dumazet <hidden> Date: 2012-11-26 06:44:07
On Mon, 2012-11-26 at 11:29 +0800, ling.ma.program@gmail.com wrote:
From: Ma Ling <redacted>
In order to reduce memory latency when last level cache miss occurs,
modern CPUs i.e. x86 and arm introduced Critical Word First(CWF) or
Early Restart(ER) to get data ASAP. For CWF if critical word is first member
in cache line, memory feed CPU with critical word, then fill others
data in cache line one by one, otherwise after critical word it must
cost more cycle to fill the remaining cache line. For Early First CPU will
restart until critical word in cache line reaches.
Hash value is critical word, so in this patch we place it as first member
in cache line(sock address is cache-line aligned), and it is also good for
Early Restart platform as well .
Thanks
Ling
networking patches should be sent to netdev.
(I understand this patch is more a generic one, but at least CC netdev)
You give no performance numbers for this change...
I never heard of this CWF/ER, where are the official Intel documents
about this, and what models really benefit from it ?
Also, why not moving skc_net as well ?
BTW, skc_daddr & skc_rcv_saddr are 'critical' as well, we use them in
INET_MATCH()
It seems we have a 32bit hole on 64bit arches, so we probably should
move inet_dport/inet_num in it. It could well remove a full cache line
miss (I'll send a patch for this after tests)
Thanks
From: Ben Hutchings <hidden> Date: 2012-11-26 20:40:44
On Sun, 2012-11-25 at 22:44 -0800, Eric Dumazet wrote:
On Mon, 2012-11-26 at 11:29 +0800, ling.ma.program@gmail.com wrote:
quoted
From: Ma Ling <redacted>
In order to reduce memory latency when last level cache miss occurs,
modern CPUs i.e. x86 and arm introduced Critical Word First(CWF) or
Early Restart(ER) to get data ASAP. For CWF if critical word is first member
in cache line, memory feed CPU with critical word, then fill others
data in cache line one by one, otherwise after critical word it must
cost more cycle to fill the remaining cache line. For Early First CPU will
restart until critical word in cache line reaches.
Hash value is critical word, so in this patch we place it as first member
in cache line(sock address is cache-line aligned), and it is also good for
Early Restart platform as well .
Thanks
Ling
networking patches should be sent to netdev.
(I understand this patch is more a generic one, but at least CC netdev)
You give no performance numbers for this change...
I never heard of this CWF/ER, where are the official Intel documents
about this, and what models really benefit from it ?
[...]
CWF is a standard feature of SDRAM. Ulrich Drepper's series of articles
on memory covers this in part 2 <http://lwn.net/Articles/252125/>
section 3.5.2. As for whether it's slower to start fetching from the
middle, that may depend on the memory controller and memory type that
are used. Drepper's benchmark showed only a small penalty (<1%) for
fetching from the middle, though he didn't say anything particular about
the hardware configuration.
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
Also, why not moving skc_net as well ?
BTW, skc_daddr & skc_rcv_saddr are 'critical' as well, we use them in
INET_MATCH()
Ling: in the looking-up routine, hash value is the most important key,
if it is matched, the other values have most possibility to be
satisfied, and CFW is limited by memory bandwidth(64bit usually), so
we only move hash value as critical first word.
Thanks
Ling
From: Eric Dumazet <hidden> Date: 2012-11-27 13:58:08
On Tue, 2012-11-27 at 21:48 +0800, Ling Ma wrote:
Ling: in the looking-up routine, hash value is the most important key,
if it is matched, the other values have most possibility to be
satisfied, and CFW is limited by memory bandwidth(64bit usually), so
we only move hash value as critical first word.
In practice, we have at most one TCP socket per hash slot.
99.9999 % of lookups need all fields to complete.
Your patch introduces a misalignment error. I am not sure all 64 bit
arches are able to cope with that gracefully.
It seems all CWF docs I could find are very old stuff, mostly academic,
without good performance data.
I was asking for up2date statements from Intel/AMD/... about current
cpus and current memory. Because optimizing for 10 years olds cpus is
not worth the pain.
I am assuming cpus are implementing the CWF/ER automatically, and that
only prefetches could have a slight disadvantage if the needed word is
not the first word in the cache line. Its not clear why the prefetch()
hint could not also use CWF. It seems it also could be done by the
hardware.
So before random patches in linux kernel adding their possible bugs, we
need a good study.
Thanks
Hi Eric,
Attached benchmark test-cwf.c(cc -o test-cwf test-cwf.c), the result
shows when last level cache(LLC) miss and CPU fetches data from
memory, critical word as first 64bit member in cache line has better
performance(costs 158290336 cycles ) than other positions(offset 0x10,
costs 164100732 ) in cache line, the performance is improved by 3.6%
in this case.
cpu-info is also involved too.
Thanks
Ling
From: Eric Dumazet <hidden> Date: 2012-12-02 17:20:18
On Sun, 2012-12-02 at 21:25 +0800, Ling Ma wrote:
Hi Eric,
Attached benchmark test-cwf.c(cc -o test-cwf test-cwf.c), the result
shows when last level cache(LLC) miss and CPU fetches data from
memory, critical word as first 64bit member in cache line has better
performance(costs 158290336 cycles ) than other positions(offset 0x10,
costs 164100732 ) in cache line, the performance is improved by 3.6%
in this case.
cpu-info is also involved too.
Thanks
Ling
Thanks Ling.
Note that I was more interested by the case we read more fields per
cache line, like we do in tcp lookups. (skc_daddr, skc_rcv_saddr,
skc_bound_dev_if, skc_net).
I made changes to net-next to prepare your patch.
You'll have to move both skc_rxhash & skc_portpair before the
skc_addrpair.
I have to fix an endianness sparse problem, I'll send a patch for this
in a separate thread right now.