History

tcp: syncookies: do not use getnstimeofday()

While it is true that getnstimeofday() uses about 40 cycles if TSC is available, it can use 1600 cycles if hpet is the clocksource. Switch to get_jiffies_64(), as this is more than enough, and go back to 60 seconds periods.

Eric Dumazet committed 12 years ago

Commit 63262311 parent 88050041 file · +6 −5Browse files

Unified · Split

include/net/tcp.h+6−5
@@ -480,20 +480,21 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, · 479 unmodified lines
480480 #ifdef CONFIG_SYN_COOKIES
481481 #include <linux/ktime.h>
482482
483−/* Syncookies use a monotonic timer which increments every 64 seconds.
483+/* Syncookies use a monotonic timer which increments every 60 seconds.
484484 * This counter is used both as a hash input and partially encoded into
485485 * the cookie value. A cookie is only validated further if the delta
486486 * between the current counter value and the encoded one is less than this,
487− * i.e. a sent cookie is valid only at most for 128 seconds (or less if
487+ * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
488488 * the counter advances immediately after a cookie is generated).
489489 */
490490 #define MAX_SYNCOOKIE_AGE 2
491491
492492 static inline u32 tcp_cookie_time(void)
493493 {
494− struct timespec now;
495− getnstimeofday(&now);
496− return now.tv_sec >> 6; /* 64 seconds granularity */
494+ u64 val = get_jiffies_64();
495+
496+ do_div(val, 60 * HZ);
497+ return val;
497498 }
498499
499500 u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t