* [PATCH net-next] ipv6: remove useless spin_lock/spin_unlock
@ 2014-12-03 1:32 Duan Jiong
2014-12-03 1:57 ` Eric Dumazet
2014-12-03 2:29 ` [PATCH net-next v2] " Duan Jiong
0 siblings, 2 replies; 6+ messages in thread
From: Duan Jiong @ 2014-12-03 1:32 UTC (permalink / raw)
To: David Miller; +Cc: netdev
xchg is atomic, so there is no necessary to use spin_lock/spin_unlock
to protect it.
Signed-off-by: Duan Jiong <duanj.fnst@cn.fujitsu.com>
---
net/ipv6/ipv6_sockglue.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index e1a9583..92ca907 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -112,9 +112,7 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
}
opt = xchg(&inet6_sk(sk)->opt, opt);
} else {
- spin_lock(&sk->sk_dst_lock);
opt = xchg(&inet6_sk(sk)->opt, opt);
- spin_unlock(&sk->sk_dst_lock);
}
sk_dst_reset(sk);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] ipv6: remove useless spin_lock/spin_unlock
2014-12-03 1:32 [PATCH net-next] ipv6: remove useless spin_lock/spin_unlock Duan Jiong
@ 2014-12-03 1:57 ` Eric Dumazet
2014-12-03 2:05 ` Duan Jiong
2014-12-03 2:29 ` [PATCH net-next v2] " Duan Jiong
1 sibling, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2014-12-03 1:57 UTC (permalink / raw)
To: Duan Jiong; +Cc: David Miller, netdev
On Wed, 2014-12-03 at 09:32 +0800, Duan Jiong wrote:
> xchg is atomic, so there is no necessary to use spin_lock/spin_unlock
> to protect it.
>
> Signed-off-by: Duan Jiong <duanj.fnst@cn.fujitsu.com>
> ---
> net/ipv6/ipv6_sockglue.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
> index e1a9583..92ca907 100644
> --- a/net/ipv6/ipv6_sockglue.c
> +++ b/net/ipv6/ipv6_sockglue.c
> @@ -112,9 +112,7 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
> }
> opt = xchg(&inet6_sk(sk)->opt, opt);
> } else {
> - spin_lock(&sk->sk_dst_lock);
> opt = xchg(&inet6_sk(sk)->opt, opt);
> - spin_unlock(&sk->sk_dst_lock);
> }
> sk_dst_reset(sk);
>
Why keeping 2 copies of opt = xchg(&inet6_sk(sk)->opt, opt); then ?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next] ipv6: remove useless spin_lock/spin_unlock
2014-12-03 1:57 ` Eric Dumazet
@ 2014-12-03 2:05 ` Duan Jiong
0 siblings, 0 replies; 6+ messages in thread
From: Duan Jiong @ 2014-12-03 2:05 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David Miller, netdev
On 12/03/2014 09:57 AM, Eric Dumazet wrote:
> On Wed, 2014-12-03 at 09:32 +0800, Duan Jiong wrote:
>> xchg is atomic, so there is no necessary to use spin_lock/spin_unlock
>> to protect it.
>>
>> Signed-off-by: Duan Jiong <duanj.fnst@cn.fujitsu.com>
>> ---
>> net/ipv6/ipv6_sockglue.c | 2 --
>> 1 file changed, 2 deletions(-)
>>
>> diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
>> index e1a9583..92ca907 100644
>> --- a/net/ipv6/ipv6_sockglue.c
>> +++ b/net/ipv6/ipv6_sockglue.c
>> @@ -112,9 +112,7 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
>> }
>> opt = xchg(&inet6_sk(sk)->opt, opt);
>> } else {
>> - spin_lock(&sk->sk_dst_lock);
>> opt = xchg(&inet6_sk(sk)->opt, opt);
>> - spin_unlock(&sk->sk_dst_lock);
>> }
>> sk_dst_reset(sk);
>>
>
> Why keeping 2 copies of opt = xchg(&inet6_sk(sk)->opt, opt); then ?
>
Thanks for you remind, i didn't notice that.
The else statement could be removed, opt = xchg(&inet6_sk(sk)->opt, opt); should be
moved out, and i will send v2.
Thanks,
Duan
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v2] ipv6: remove useless spin_lock/spin_unlock
2014-12-03 1:32 [PATCH net-next] ipv6: remove useless spin_lock/spin_unlock Duan Jiong
2014-12-03 1:57 ` Eric Dumazet
@ 2014-12-03 2:29 ` Duan Jiong
2014-12-03 5:18 ` Joe Perches
2014-12-09 18:18 ` David Miller
1 sibling, 2 replies; 6+ messages in thread
From: Duan Jiong @ 2014-12-03 2:29 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Eric Dumazet
xchg is atomic, so there is no necessary to use spin_lock/spin_unlock
to protect it. At last, remove the redundant
opt = xchg(&inet6_sk(sk)->opt, opt); statement.
Signed-off-by: Duan Jiong <duanj.fnst@cn.fujitsu.com>
---
v2: remove the redundant opt = xchg(&inet6_sk(sk)->opt, opt); statement.
net/ipv6/ipv6_sockglue.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index e1a9583..66980d8 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -110,12 +110,8 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
}
- opt = xchg(&inet6_sk(sk)->opt, opt);
- } else {
- spin_lock(&sk->sk_dst_lock);
- opt = xchg(&inet6_sk(sk)->opt, opt);
- spin_unlock(&sk->sk_dst_lock);
}
+ opt = xchg(&inet6_sk(sk)->opt, opt);
sk_dst_reset(sk);
return opt;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2] ipv6: remove useless spin_lock/spin_unlock
2014-12-03 2:29 ` [PATCH net-next v2] " Duan Jiong
@ 2014-12-03 5:18 ` Joe Perches
2014-12-09 18:18 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: Joe Perches @ 2014-12-03 5:18 UTC (permalink / raw)
To: Duan Jiong; +Cc: David Miller, netdev, Eric Dumazet
On Wed, 2014-12-03 at 10:29 +0800, Duan Jiong wrote:
> xchg is atomic, so there is no necessary to use spin_lock/spin_unlock
> to protect it. At last, remove the redundant
> opt = xchg(&inet6_sk(sk)->opt, opt); statement.
>
> Signed-off-by: Duan Jiong <duanj.fnst@cn.fujitsu.com>
> ---
> v2: remove the redundant opt = xchg(&inet6_sk(sk)->opt, opt); statement.
>
> net/ipv6/ipv6_sockglue.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
> index e1a9583..66980d8 100644
> --- a/net/ipv6/ipv6_sockglue.c
> +++ b/net/ipv6/ipv6_sockglue.c
> @@ -110,12 +110,8 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
> icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
> icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
> }
> - opt = xchg(&inet6_sk(sk)->opt, opt);
> - } else {
> - spin_lock(&sk->sk_dst_lock);
> - opt = xchg(&inet6_sk(sk)->opt, opt);
> - spin_unlock(&sk->sk_dst_lock);
> }
> + opt = xchg(&inet6_sk(sk)->opt, opt);
> sk_dst_reset(sk);
>
> return opt;
The original function could now be written
integrating the multiple ifs like:
---
net/ipv6/ipv6_sockglue.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index e1a9583..12c9c6b 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -102,20 +102,19 @@ static
struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
struct ipv6_txoptions *opt)
{
- if (inet_sk(sk)->is_icsk) {
- if (opt &&
- !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
- inet_sk(sk)->inet_daddr != LOOPBACK4_IPV6) {
- struct inet_connection_sock *icsk = inet_csk(sk);
- icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
- icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
- }
- opt = xchg(&inet6_sk(sk)->opt, opt);
- } else {
- spin_lock(&sk->sk_dst_lock);
- opt = xchg(&inet6_sk(sk)->opt, opt);
- spin_unlock(&sk->sk_dst_lock);
+ struct inet_sock *inet = inet_sk(sk);
+
+ if (inet->is_icsk &&
+ opt &&
+ !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
+ inet->inet_daddr != LOOPBACK4_IPV6) {
+ struct inet_connection_sock *icsk = inet_csk(sk);
+
+ icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
+ icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
}
+
+ opt = xchg(&inet6_sk(sk)->opt, opt);
sk_dst_reset(sk);
return opt;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v2] ipv6: remove useless spin_lock/spin_unlock
2014-12-03 2:29 ` [PATCH net-next v2] " Duan Jiong
2014-12-03 5:18 ` Joe Perches
@ 2014-12-09 18:18 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2014-12-09 18:18 UTC (permalink / raw)
To: duanj.fnst; +Cc: netdev, eric.dumazet
From: Duan Jiong <duanj.fnst@cn.fujitsu.com>
Date: Wed, 3 Dec 2014 10:29:40 +0800
> xchg is atomic, so there is no necessary to use spin_lock/spin_unlock
> to protect it. At last, remove the redundant
> opt = xchg(&inet6_sk(sk)->opt, opt); statement.
>
> Signed-off-by: Duan Jiong <duanj.fnst@cn.fujitsu.com>
> ---
> v2: remove the redundant opt = xchg(&inet6_sk(sk)->opt, opt); statement.
Applied, thank you.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-12-09 18:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-03 1:32 [PATCH net-next] ipv6: remove useless spin_lock/spin_unlock Duan Jiong
2014-12-03 1:57 ` Eric Dumazet
2014-12-03 2:05 ` Duan Jiong
2014-12-03 2:29 ` [PATCH net-next v2] " Duan Jiong
2014-12-03 5:18 ` Joe Perches
2014-12-09 18:18 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).