Commit 6510ea9
net: Use this_cpu_inc() to increment net->core_stats
The macro dev_core_stats_##FIELD##_inc() disables preemption and invokes
netdev_core_stats_alloc() to return a per-CPU pointer.
netdev_core_stats_alloc() will allocate memory on its first invocation
which breaks on PREEMPT_RT because it requires non-atomic context for
memory allocation.
This can be avoided by enabling preemption in netdev_core_stats_alloc()
assuming the caller always disables preemption.
It might be better to replace local_inc() with this_cpu_inc() now that
dev_core_stats_##FIELD##_inc() gained a preempt-disable section and does
not rely on already disabled preemption. This results in less
instructions on x86-64:
local_inc:
| incl %gs:__preempt_count(%rip) # __preempt_count
| movq 488(%rdi), %rax # _1->core_stats, _22
| testq %rax, %rax # _22
| je .L585 #,
| add %gs:this_cpu_off(%rip), %rax # this_cpu_off, tcp_ptr__
| .L586:
| testq %rax, %rax # _27
| je .L587 #,
| incq (%rax) # _6->a.counter
| .L587:
| decl %gs:__preempt_count(%rip) # __preempt_count
this_cpu_inc(), this patch:
| movq 488(%rdi), %rax # _1->core_stats, _5
| testq %rax, %rax # _5
| je .L591 #,
| .L585:
| incq %gs:(%rax) # _18->rx_dropped
Use unsigned long as type for the counter. Use this_cpu_inc() to
increment the counter. Use a plain read of the counter.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/YmbO0pxgtKpCw4SY@linutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>1 parent acb16b3 commit 6510ea9
2 files changed
Lines changed: 14 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| |||
3843 | 3843 | | |
3844 | 3844 | | |
3845 | 3845 | | |
3846 | | - | |
| 3846 | + | |
3847 | 3847 | | |
3848 | | - | |
| 3848 | + | |
3849 | 3849 | | |
3850 | 3850 | | |
3851 | 3851 | | |
3852 | 3852 | | |
3853 | 3853 | | |
3854 | | - | |
| 3854 | + | |
3855 | 3855 | | |
3856 | 3856 | | |
3857 | 3857 | | |
3858 | 3858 | | |
3859 | 3859 | | |
3860 | 3860 | | |
3861 | 3861 | | |
3862 | | - | |
| 3862 | + | |
3863 | 3863 | | |
3864 | | - | |
3865 | 3864 | | |
3866 | | - | |
3867 | 3865 | | |
3868 | | - | |
3869 | | - | |
| 3866 | + | |
3870 | 3867 | | |
3871 | 3868 | | |
3872 | 3869 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10304 | 10304 | | |
10305 | 10305 | | |
10306 | 10306 | | |
10307 | | - | |
| 10307 | + | |
10308 | 10308 | | |
10309 | 10309 | | |
10310 | 10310 | | |
| |||
10315 | 10315 | | |
10316 | 10316 | | |
10317 | 10317 | | |
10318 | | - | |
10319 | | - | |
10320 | | - | |
10321 | | - | |
10322 | | - | |
| 10318 | + | |
10323 | 10319 | | |
10324 | 10320 | | |
10325 | 10321 | | |
| |||
10356 | 10352 | | |
10357 | 10353 | | |
10358 | 10354 | | |
10359 | | - | |
10360 | | - | |
10361 | | - | |
| 10355 | + | |
| 10356 | + | |
| 10357 | + | |
10362 | 10358 | | |
10363 | 10359 | | |
10364 | 10360 | | |
| |||
0 commit comments