From: Vakul Garg <vakul.garg@nxp.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: "borisp@mellanox.com" <borisp@mellanox.com>,
"aviadye@mellanox.com" <aviadye@mellanox.com>,
"davejwatson@fb.com" <davejwatson@fb.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"doronrk@fb.com" <doronrk@fb.com>,
Vakul Garg <vakul.garg@nxp.com>
Subject: [PATCH net-next] strparser: Return if socket does not have required number of bytes
Date: Wed, 30 Jan 2019 07:31:44 +0000 [thread overview]
Message-ID: <20190130072933.23281-1-vakul.garg@nxp.com> (raw)
Function strp_data_ready() should peek the associated socket to check
whether it has the required number of bytes available before queueing
work or initiating socket read via strp_read_sock(). This saves cpu
cycles because strp_read_sock() is called only when required amount of
data is available.
Signed-off-by: Vakul Garg <vakul.garg@nxp.com>
---
net/strparser/strparser.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/net/strparser/strparser.c b/net/strparser/strparser.c
index da1a676860ca..38f8d8d8f4ad 100644
--- a/net/strparser/strparser.c
+++ b/net/strparser/strparser.c
@@ -384,6 +384,14 @@ void strp_data_ready(struct strparser *strp)
if (unlikely(strp->stopped) || strp->paused)
return;
+ /* If the socket does not contain the number bytes required by
+ * stream parser context to proceed, return silently.
+ */
+ if (strp->need_bytes) {
+ if (strp_peek_len(strp) < strp->need_bytes)
+ return;
+ }
+
/* This check is needed to synchronize with do_strp_work.
* do_strp_work acquires a process lock (lock_sock) whereas
* the lock held here is bh_lock_sock. The two locks can be
@@ -396,11 +404,6 @@ void strp_data_ready(struct strparser *strp)
return;
}
- if (strp->need_bytes) {
- if (strp_peek_len(strp) < strp->need_bytes)
- return;
- }
-
if (strp_read_sock(strp) == -ENOMEM)
queue_work(strp_wq, &strp->work);
}
--
2.13.6
next reply other threads:[~2019-01-30 7:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-30 7:31 Vakul Garg [this message]
2019-01-31 5:59 ` [PATCH net-next] strparser: Return if socket does not have required number of bytes David Miller
2019-01-31 6:25 ` Vakul Garg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190130072933.23281-1-vakul.garg@nxp.com \
--to=vakul.garg@nxp.com \
--cc=aviadye@mellanox.com \
--cc=borisp@mellanox.com \
--cc=davejwatson@fb.com \
--cc=davem@davemloft.net \
--cc=doronrk@fb.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox