Skip to content

use efficient this_cpu_* helper

Shan Wei lkml netdev 3 versions – Applied

Status from this message: Applied.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest8 of 9 patches 23 repliesApplied
  2. v39 patches 13 repliesSuperseded
  3. v28 of 9 patches 19 repliesSuperseded

Changes in v4 from the cover letter

1. [read|write]ing fields of struct rds_ib_cache_head using __this_cpu_* operation for rds subsystem. see patch2
2. fix bug in xfrm to read pointer. see patch3.
3. avoid type cast in patch7.

8 of 9 patches are in this archive. The cover letter announces 9.

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/9net: core: use this_cpu_ptr per-cpu helpernet/core/flow.c+1 -32 replies
2/9net: rds: use this_cpu_* per-cpu helpernet/rds/ib.h net/rds/ib_recv.c+14 -122 replies
3/9net: xfrm: use __this_cpu_read per-cpu helpernet/xfrm/xfrm_ipcomp.c+3 -55 replies
4/9net: openvswitch: use this_cpu_ptr per-cpu helpernet/openvswitch/datapath.c net/openvswitch/vport.c+4 -52 replies
5/9kernel: padata : use __this_cpu_read per-cpu helperkernel/padata.c+2 -32 replies
7/9trace: use this_cpu_ptr per-cpu helperkernel/trace/blktrace.c kernel/trace/trace.c+2 -54 replies
8/9clocksource: use this_cpu_ptr per-cpu helperdrivers/clocksource/arm_generic.c+1 -11 reply
9/9net: batman-adv: use per_cpu_add helpernet/batman-adv/main.h+1 -32 replies

Reviews trailers per patch

7 of 8 patches have a Reviewed-by or Acked-by.

PatchChristoph LameterSteffen Klassert
1/9R-b
2/9R-b
3/9
4/9R-b
5/9R-b A-b
7/9R-b
8/9R-b
9/9R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH 0/9 v4] use efficient this_cpu_* helper

this_cpu_ptr/this_cpu_read is faster than per_cpu_ptr(p, smp_processor_id()) and can reduce memory accesses.
The latter helper needs to find the offset for current cpu,
and needs more assembler instructions which objdump shows in following.

this_cpu_ptr relocates and address. this_cpu_read() relocates the address and performs the fetch. If you want to operate on rda(defined as per_cpu) then you can only use this_cpu_ptr. this_cpu_read() saves you more instructions since it can do the relocation and the fetch in one instruction.

per_cpu_ptr(p, smp_processor_id()):

  1e:   65 8b 04 25 00 00 00 00         mov    %gs:0x0,%eax
  26:   48 98                           cltq
  28:   31 f6                           xor    %esi,%esi
  2a:   48 c7 c7 00 00 00 00            mov    $0x0,%rdi
  31:   48 8b 04 c5 00 00 00 00         mov    0x0(,%rax,8),%rax
  39:   c7 44 10 04 14 00 00 00         movl   $0x14,0x4(%rax,%rdx,1)

this_cpu_ptr(p)

  1e:   65 48 03 14 25 00 00 00 00      add    %gs:0x0,%rdx
  27:   31 f6                           xor    %esi,%esi
  29:   c7 42 04 14 00 00 00            movl   $0x14,0x4(%rdx)
  30:   48 c7 c7 00 00 00 00            mov    $0x0,%rdi

Changelog V4:
1. [read|write]ing fields of struct rds_ib_cache_head using __this_cpu_* operation for rds subsystem. see patch2
2. fix bug in xfrm to read pointer. see patch3.
3. avoid type cast in patch7.

Changelog V3:
1. use this_cpu_read directly read member of per-cpu variable, so that droping the this_cpu_ptr operation.
2. for preemption off and bottom halves off case, use __this_cpu_read instead of this_cpu_read.

Changelog V2:
1. Use this_cpu_read directly instead of ref to field of per-cpu variable.
2. Patch5 about ftrace is dropped from this series.
3. Add new patch9 to replace get_cpu;per_cpu_ptr;put_cpu with this_cpu_add opt.
4. For preemption disable case, use __this_cpu_read instead.

$ git diff --stat d4185bbf62a5d8d777ee445db1581beb17882a07
 drivers/clocksource/arm_generic.c |    2 +-
 kernel/padata.c                   |    5 ++---
 kernel/rcutree.c                  |    2 +-
 kernel/trace/blktrace.c           |    2 +-
 kernel/trace/trace.c              |    5 +----
 net/batman-adv/main.h             |    4 +---
 net/core/flow.c                   |    4 +---
 net/openvswitch/datapath.c        |    4 ++--
 net/openvswitch/vport.c           |    5 ++---
 net/rds/ib.h                      |    2 +-
 net/rds/ib_recv.c                 |   24 +++++++++++++-----------
 net/xfrm/xfrm_ipcomp.c            |    8 +++-----
 12 files changed, 29 insertions(+), 38 deletions(-)