aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <eric.dumazet@gmail.com>2011-11-28 07:04:18 -0500
committerDavid S. Miller <davem@davemloft.net>2011-11-29 00:27:11 -0500
commit08e29af3a9096ffdff477e537daea67faefd3952 (patch)
tree11c8ab801659f1c77f9949cc20f30f232e95fe3a
parentb90e5794c5bdef91d26c623e992257947c506e35 (diff)
net: optimize socket timestamping
We can test/set multiple bits from sk_flags at once, to shorten a bit socket setup/dismantle phase. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/sock.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/net/core/sock.c b/net/core/sock.c
index 16069139797c..9777da86aeac 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -276,14 +276,14 @@ static void sock_warn_obsolete_bsdism(const char *name)
276 } 276 }
277} 277}
278 278
279static void sock_disable_timestamp(struct sock *sk, int flag) 279#define SK_FLAGS_TIMESTAMP ((1UL << SOCK_TIMESTAMP) | (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE))
280
281static void sock_disable_timestamp(struct sock *sk, unsigned long flags)
280{ 282{
281 if (sock_flag(sk, flag)) { 283 if (sk->sk_flags & flags) {
282 sock_reset_flag(sk, flag); 284 sk->sk_flags &= ~flags;
283 if (!sock_flag(sk, SOCK_TIMESTAMP) && 285 if (!(sk->sk_flags & SK_FLAGS_TIMESTAMP))
284 !sock_flag(sk, SOCK_TIMESTAMPING_RX_SOFTWARE)) {
285 net_disable_timestamp(); 286 net_disable_timestamp();
286 }
287 } 287 }
288} 288}
289 289
@@ -689,7 +689,7 @@ set_rcvbuf:
689 SOCK_TIMESTAMPING_RX_SOFTWARE); 689 SOCK_TIMESTAMPING_RX_SOFTWARE);
690 else 690 else
691 sock_disable_timestamp(sk, 691 sock_disable_timestamp(sk,
692 SOCK_TIMESTAMPING_RX_SOFTWARE); 692 (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE));
693 sock_valbool_flag(sk, SOCK_TIMESTAMPING_SOFTWARE, 693 sock_valbool_flag(sk, SOCK_TIMESTAMPING_SOFTWARE,
694 val & SOF_TIMESTAMPING_SOFTWARE); 694 val & SOF_TIMESTAMPING_SOFTWARE);
695 sock_valbool_flag(sk, SOCK_TIMESTAMPING_SYS_HARDWARE, 695 sock_valbool_flag(sk, SOCK_TIMESTAMPING_SYS_HARDWARE,
@@ -1187,8 +1187,7 @@ static void __sk_free(struct sock *sk)
1187 RCU_INIT_POINTER(sk->sk_filter, NULL); 1187 RCU_INIT_POINTER(sk->sk_filter, NULL);
1188 } 1188 }
1189 1189
1190 sock_disable_timestamp(sk, SOCK_TIMESTAMP); 1190 sock_disable_timestamp(sk, SK_FLAGS_TIMESTAMP);
1191 sock_disable_timestamp(sk, SOCK_TIMESTAMPING_RX_SOFTWARE);
1192 1191
1193 if (atomic_read(&sk->sk_omem_alloc)) 1192 if (atomic_read(&sk->sk_omem_alloc))
1194 printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n", 1193 printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n",
@@ -1326,8 +1325,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
1326 if (newsk->sk_prot->sockets_allocated) 1325 if (newsk->sk_prot->sockets_allocated)
1327 percpu_counter_inc(newsk->sk_prot->sockets_allocated); 1326 percpu_counter_inc(newsk->sk_prot->sockets_allocated);
1328 1327
1329 if (sock_flag(newsk, SOCK_TIMESTAMP) || 1328 if (newsk->sk_flags & SK_FLAGS_TIMESTAMP)
1330 sock_flag(newsk, SOCK_TIMESTAMPING_RX_SOFTWARE))
1331 net_enable_timestamp(); 1329 net_enable_timestamp();
1332 } 1330 }
1333out: 1331out:
@@ -2165,16 +2163,15 @@ EXPORT_SYMBOL(sock_get_timestampns);
2165void sock_enable_timestamp(struct sock *sk, int flag) 2163void sock_enable_timestamp(struct sock *sk, int flag)
2166{ 2164{
2167 if (!sock_flag(sk, flag)) { 2165 if (!sock_flag(sk, flag)) {
2166 unsigned long previous_flags = sk->sk_flags;
2167
2168 sock_set_flag(sk, flag); 2168 sock_set_flag(sk, flag);
2169 /* 2169 /*
2170 * we just set one of the two flags which require net 2170 * we just set one of the two flags which require net
2171 * time stamping, but time stamping might have been on 2171 * time stamping, but time stamping might have been on
2172 * already because of the other one 2172 * already because of the other one
2173 */ 2173 */
2174 if (!sock_flag(sk, 2174 if (!(previous_flags & SK_FLAGS_TIMESTAMP))
2175 flag == SOCK_TIMESTAMP ?
2176 SOCK_TIMESTAMPING_RX_SOFTWARE :
2177 SOCK_TIMESTAMP))
2178 net_enable_timestamp(); 2175 net_enable_timestamp();
2179 } 2176 }
2180} 2177}