tcp_update_metrics() fail fast before declaring variables

From: Donatas Abraitis <hidden>
Date: 2015-08-07 19:49:49

Hi folks,

one short question regarding net.ipv4.tcp_no_metrics_save sysctl
parameter. Code snippet is actually the following:

void tcp_update_metrics(struct sock *sk)
{
  struct tcp_sock *tp = tcp_sk(sk);
  struct dst_entry *dst = __sk_dst_get(sk);

  if (sysctl_tcp_nometrics_save)
    return;

Why this 'if' statement can't be moved before variables? I think fail
fast could save some instructions in this place. Any thoughts?

Here is the performance benchmarking results:

Test #1 (sysctl -w net.ipv4.tcp_no_metrics_save=0)
sum: 79726, avg: 1295ns
min: 453ns, max: 16487ns

Test #2 (sysctl -w net.ipv4.tcp_no_metrics_save=1)
sum: 77515, avg: 1181ns
min: 431ns, max: 15989ns

Benchmarked with Systemtap:

global c;
probe kernel.function("tcp_update_metrics").return
{
        c <<< (gettimeofday_ns() - @entry(gettimeofday_ns()));
}
probe timer.s(60)
{
        printf("sum: %d, avg: %dns\n", @count(c), @avg(c));
        printf("min: %dns, max: %dns\n", @min(c), @max(c));
        delete c;
        exit();
}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help