SUNRPC: use assign_bit() where applicable
Subsystems (4)
PATCH 1/1 SUNRPC: use assign_bit() where applicable
From: Peng Fan <[email protected]>
Convert open-coded if/else with set_bit/clear_bit the assign_bit API.
Done with Coccinelle semantic patch:
// set_bit -> clear_bit => assign_bit
@@
expression cond, bit, addr;
@@
-if (cond)
- set_bit(bit, addr);
-else
- clear_bit(bit, addr);
+assign_bit(bit, addr, cond);
@@
expression cond, bit, addr;
@@
-if (cond)
- clear_bit(bit, addr);
-else
- set_bit(bit, addr);
+assign_bit(bit, addr, !cond);--- net/sunrpc/svcsock.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
net/sunrpc/svcsock.c +6 -12
@@ -352,10 +352,8 @@ static void svc_sock_setbufsize(struct svc_sock *svsk, unsigned int nreqs)static void svc_sock_secure_port (struct svc_rqst *rqstp) { -if (svc_port_is_privileged (svc_addr (rqstp))) -set_bit (RQ_SECURE , &rqstp->rq_flags); -else -clear_bit (RQ_SECURE , &rqstp->rq_flags); +assign_bit (RQ_SECURE , &rqstp->rq_flags, +svc_port_is_privileged (svc_addr (rqstp))); }/*
@@ -941,10 +939,8 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) slen = offsetof(struct sockaddr , sa_data);svc_xprt_set_local (&newsvsk->sk_xprt, sin, slen); -if (sock_is_loopback (newsock->sk)) -set_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); -else -clear_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); +assign_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags, +sock_is_loopback (newsock->sk));if (serv->sv_stats) serv->sv_stats->nettcpconn++;
@@ -1290,10 +1286,8 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) rqstp->rq_xprt_ctxt =NULL ; rqstp->rq_prot =IPPROTO_TCP ; -if (test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags)) -set_bit (RQ_LOCAL , &rqstp->rq_flags); -else -clear_bit (RQ_LOCAL , &rqstp->rq_flags); +assign_bit (RQ_LOCAL , &rqstp->rq_flags, +test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags));/* Completing one message stops ->read_sock with whatever * follows still queued, and no path from here re-arms XPT_DATA.
Signature · 1 line
2.51.0
Chuck Lever
maintainerQuoted 3 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Convert open-coded if/else with set_bit/clear_bit the
assign_bitAPI.
The above sentence explains the same thing that the diff body shows me, so it does not add value.
But I don't have any context here: why is this being done? Is there some kind of tree-wide clean-up underway so that a new feature can be added, or is this patch just a one-off change?
Including a URL that points to an explainer, or making this patch part of a series would help orient reviewers.
Quoted 75 lines
Done with Coccinelle semantic patch:
// set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - set_bit(bit, addr); -else - clear_bit(bit, addr); +assign_bit(bit, addr, cond); @@ expression cond, bit, addr; @@ -if (cond) - clear_bit(bit, addr); -else - set_bit(bit, addr); +assign_bit(bit, addr, !cond);Signed-off-by Peng Fan <[email protected]>--- net/sunrpc/svcsock.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)net/sunrpc/svcsock.c +2
-4@@ -352,10 +352,8 @@ static void svc_sock_setbufsize(struct svc_sock *svsk, unsigned int nreqs)static void svc_sock_secure_port (struct svc_rqst *rqstp) { -if (svc_port_is_privileged (svc_addr (rqstp))) -set_bit (RQ_SECURE , &rqstp->rq_flags); -else -clear_bit (RQ_SECURE , &rqstp->rq_flags); +assign_bit (RQ_SECURE , &rqstp->rq_flags, +svc_port_is_privileged (svc_addr (rqstp))); }/*
net/sunrpc/svcsock.c +4
-8@@ -941,10 +939,8 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) slen = offsetof(struct sockaddr , sa_data);svc_xprt_set_local (&newsvsk->sk_xprt, sin, slen); -if (sock_is_loopback (newsock->sk)) -set_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); -else -clear_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); +assign_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags, +sock_is_loopback (newsock->sk));if (serv->sv_stats) serv->sv_stats->nettcpconn++;@@ -1290,10 +1286,8 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) rqstp->rq_xprt_ctxt =NULL ; rqstp->rq_prot =IPPROTO_TCP ; -if (test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags)) -set_bit (RQ_LOCAL , &rqstp->rq_flags); -else -clear_bit (RQ_LOCAL , &rqstp->rq_flags); +assign_bit (RQ_LOCAL , &rqstp->rq_flags, +test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags));/* Completing one message stops ->read_sock with whatever * follows still queued, and no path from here re-arms XPT_DATA. Signature · 1 line
2.51.0
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Quoted 5 lines · Chuck Lever
Quoted 2 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Quoted 8 lines
Quoted 1 line
Convert open-coded if/else with set_bit/clear_bit the
assign_bitAPI.The above sentence explains the same thing that the diff body shows me, so it does not add value.
But I don't have any context here: why is this being done? Is there some kind of tree-wide clean-up underway so that a new feature can be added, or is this patch just a one-off change?
It is just a one-off change. I don't group other patches to use assign_bit() into a large patchset, just separate patches.
Free to drop if it does not make sense to you.
Thanks,
Peng
Quoted 85 lines
Including a URL that points to an explainer, or making this patch part of a series would help orient reviewers.
Quoted 75 lines
Done with Coccinelle semantic patch:
// set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - set_bit(bit, addr); -else - clear_bit(bit, addr); +assign_bit(bit, addr, cond); @@ expression cond, bit, addr; @@ -if (cond) - clear_bit(bit, addr); -else - set_bit(bit, addr); +assign_bit(bit, addr, !cond);Signed-off-by Peng Fan <[email protected]>--- net/sunrpc/svcsock.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)net/sunrpc/svcsock.c +2
-4@@ -352,10 +352,8 @@ static void svc_sock_setbufsize(struct svc_sock *svsk, unsigned int nreqs)static void svc_sock_secure_port (struct svc_rqst *rqstp) { -if (svc_port_is_privileged (svc_addr (rqstp))) -set_bit (RQ_SECURE , &rqstp->rq_flags); -else -clear_bit (RQ_SECURE , &rqstp->rq_flags); +assign_bit (RQ_SECURE , &rqstp->rq_flags, +svc_port_is_privileged (svc_addr (rqstp))); }/*
net/sunrpc/svcsock.c +4
-8@@ -941,10 +939,8 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) slen = offsetof(struct sockaddr , sa_data);svc_xprt_set_local (&newsvsk->sk_xprt, sin, slen); -if (sock_is_loopback (newsock->sk)) -set_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); -else -clear_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); +assign_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags, +sock_is_loopback (newsock->sk));if (serv->sv_stats) serv->sv_stats->nettcpconn++;@@ -1290,10 +1286,8 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) rqstp->rq_xprt_ctxt =NULL ; rqstp->rq_prot =IPPROTO_TCP ; -if (test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags)) -set_bit (RQ_LOCAL , &rqstp->rq_flags); -else -clear_bit (RQ_LOCAL , &rqstp->rq_flags); +assign_bit (RQ_LOCAL , &rqstp->rq_flags, +test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags));/* Completing one message stops ->read_sock with whatever * follows still queued, and no path from here re-arms XPT_DATA. Signature · 1 line
2.51.0Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Chuck Lever
maintainerQuoted 11 lines · Peng Fan
Quoted 10 lines · Chuck Lever
Quoted 3 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Convert open-coded if/else with set_bit/clear_bit the
assign_bitAPI.The above sentence explains the same thing that the diff body shows me, so it does not add value.
Quoted 8 lines
Quoted 3 lines
But I don't have any context here: why is this being done? Is there some kind of tree-wide clean-up underway so that a new feature can be added, or is this patch just a one-off change?
It is just a one-off change. I don't group other patches to use
assign_bit()into a large patchset, just separate patches.Free to drop if it does not make sense to you.
It makes sense. But I'd rather not make assumptions.
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Jeff Layton
maintainerQuoted 11 lines · Peng Fan
Quoted 10 lines · Chuck Lever
Quoted 3 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Convert open-coded if/else with set_bit/clear_bit the
assign_bitAPI.The above sentence explains the same thing that the diff body shows me, so it does not add value.
Quoted 10 lines
Quoted 3 lines
But I don't have any context here: why is this being done? Is there some kind of tree-wide clean-up underway so that a new feature can be added, or is this patch just a one-off change?
It is just a one-off change. I don't group other patches to use
assign_bit()into a large patchset, just separate patches.Free to drop if it does not make sense to you.
I think the problem is that you haven't explained the benefit of using assign_bit() here. It's now 2 lines instead of 4, but that doesn't seem like a substantive change. Does this create better assembly or something?
Without a clear benefit, this seems like pointless churn.
Quoted 84 lines
Quoted 84 lines
Including a URL that points to an explainer, or making this patch part of a series would help orient reviewers.
Quoted 75 lines
Done with Coccinelle semantic patch:
// set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - set_bit(bit, addr); -else - clear_bit(bit, addr); +assign_bit(bit, addr, cond); @@ expression cond, bit, addr; @@ -if (cond) - clear_bit(bit, addr); -else - set_bit(bit, addr); +assign_bit(bit, addr, !cond);Signed-off-by Peng Fan <[email protected]>--- net/sunrpc/svcsock.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)net/sunrpc/svcsock.c +2
-4@@ -352,10 +352,8 @@ static void svc_sock_setbufsize(struct svc_sock *svsk, unsigned int nreqs)static void svc_sock_secure_port (struct svc_rqst *rqstp) { -if (svc_port_is_privileged (svc_addr (rqstp))) -set_bit (RQ_SECURE , &rqstp->rq_flags); -else -clear_bit (RQ_SECURE , &rqstp->rq_flags); +assign_bit (RQ_SECURE , &rqstp->rq_flags, +svc_port_is_privileged (svc_addr (rqstp))); }/*
net/sunrpc/svcsock.c +4
-8@@ -941,10 +939,8 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) slen = offsetof(struct sockaddr , sa_data);svc_xprt_set_local (&newsvsk->sk_xprt, sin, slen); -if (sock_is_loopback (newsock->sk)) -set_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); -else -clear_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); +assign_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags, +sock_is_loopback (newsock->sk));if (serv->sv_stats) serv->sv_stats->nettcpconn++;@@ -1290,10 +1286,8 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) rqstp->rq_xprt_ctxt =NULL ; rqstp->rq_prot =IPPROTO_TCP ; -if (test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags)) -set_bit (RQ_LOCAL , &rqstp->rq_flags); -else -clear_bit (RQ_LOCAL , &rqstp->rq_flags); +assign_bit (RQ_LOCAL , &rqstp->rq_flags, +test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags));/* Completing one message stops ->read_sock with whatever * follows still queued, and no path from here re-arms XPT_DATA. Signature · 1 line
2.51.0Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 23 lines · Jeff Layton
Quoted 11 lines · Peng Fan
Quoted 10 lines · Chuck Lever
Quoted 3 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
Convert open-coded if/else with set_bit/clear_bit the
assign_bitAPI.The above sentence explains the same thing that the diff body shows me, so it does not add value.
Quoted 10 lines
Quoted 3 lines
But I don't have any context here: why is this being done? Is there some kind of tree-wide clean-up underway so that a new feature can be added, or is this patch just a one-off change?
It is just a one-off change. I don't group other patches to use
assign_bit()into a large patchset, just separate patches.Free to drop if it does not make sense to you.
Quoted 6 lines
I think the problem is that you haven't explained the benefit of using
assign_bit()here. It's now 2 lines instead of 4, but that doesn't seem like a substantive change. Does this create better assembly or something?Without a clear benefit, this seems like pointless churn.
commit 5259401ef8f4b ("bitops: let the compiler optimize {__,}assign_bit()") may give some information:
"
Atomic assign_bit() is less affected due to its nature, but let's convert it to a macro as well to keep the code consistent and not leave a place for possible suboptimal codegen. Moreover, with certain kernel configuration it actually gives some saves (x86):
do_ip_setsockopt 4154 4099 -55
"
I did not do such build test to compare vmlinux size.
If you need me to do a image comparation w/o this patch, I could setup a build to see whether there are size reduction for the functions that this patch touched and update commit log in V2. Or we just drop this patch. Both fine to me.
Thanks
Peng
Quoted 90 lines
Quoted 85 lines
Quoted 85 lines
Including a URL that points to an explainer, or making this patch part of a series would help orient reviewers.
Quoted 75 lines
Done with Coccinelle semantic patch:
// set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@ -if (cond) - set_bit(bit, addr); -else - clear_bit(bit, addr); +assign_bit(bit, addr, cond); @@ expression cond, bit, addr; @@ -if (cond) - clear_bit(bit, addr); -else - set_bit(bit, addr); +assign_bit(bit, addr, !cond);Signed-off-by Peng Fan <[email protected]>--- net/sunrpc/svcsock.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)net/sunrpc/svcsock.c +2
-4@@ -352,10 +352,8 @@ static void svc_sock_setbufsize(struct svc_sock *svsk, unsigned int nreqs)static void svc_sock_secure_port (struct svc_rqst *rqstp) { -if (svc_port_is_privileged (svc_addr (rqstp))) -set_bit (RQ_SECURE , &rqstp->rq_flags); -else -clear_bit (RQ_SECURE , &rqstp->rq_flags); +assign_bit (RQ_SECURE , &rqstp->rq_flags, +svc_port_is_privileged (svc_addr (rqstp))); }/*
net/sunrpc/svcsock.c +4
-8@@ -941,10 +939,8 @@ static struct svc_xprt *svc_tcp_accept(struct svc_xprt *xprt) slen = offsetof(struct sockaddr , sa_data);svc_xprt_set_local (&newsvsk->sk_xprt, sin, slen); -if (sock_is_loopback (newsock->sk)) -set_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); -else -clear_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags); +assign_bit (XPT_LOCAL , &newsvsk->sk_xprt.xpt_flags, +sock_is_loopback (newsock->sk));if (serv->sv_stats) serv->sv_stats->nettcpconn++;@@ -1290,10 +1286,8 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) rqstp->rq_xprt_ctxt =NULL ; rqstp->rq_prot =IPPROTO_TCP ; -if (test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags)) -set_bit (RQ_LOCAL , &rqstp->rq_flags); -else -clear_bit (RQ_LOCAL , &rqstp->rq_flags); +assign_bit (RQ_LOCAL , &rqstp->rq_flags, +test_bit (XPT_LOCAL , &svsk->sk_xprt.xpt_flags));/* Completing one message stops ->read_sock with whatever * follows still queued, and no path from here re-arms XPT_DATA. Signature · 1 line
2.51.0Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)Signature · 1 line
Jeff Layton <[email protected]>
Chuck Lever
maintainerQuoted 10 lines · Peng Fan (OSS)
Convert open-coded if/else with set_bit/clear_bit the
assign_bitAPI.Done with Coccinelle semantic patch:
// set_bit -> clear_bit => assign_bit @@ expression cond, bit, addr; @@[...]
Applied to nfsd-testing, thanks! This narrow clean-up should be easy to discover and apply as a pre-requisite should it ever conflict with an LTS backport.
[1/1] SUNRPC: use assign_bit() where applicable
commit: 1a2b6be91033a31e13b676163be3e232201b1e3f
--
Chuck Lever