From: Huawei Xie <huawei.xie@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] lib/librte_vhost: combine select with sleep
Date: Fri, 6 Mar 2015 13:52:27 +0800 [thread overview]
Message-ID: <1425621147-14904-1-git-send-email-huawei.xie@intel.com> (raw)
combine sleep into select when there is no file descriptors to be monitored.
Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
lib/librte_vhost/vhost_user/fd_man.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/librte_vhost/vhost_user/fd_man.c b/lib/librte_vhost/vhost_user/fd_man.c
index 63ac4df..a89b6fe 100644
--- a/lib/librte_vhost/vhost_user/fd_man.c
+++ b/lib/librte_vhost/vhost_user/fd_man.c
@@ -211,25 +211,26 @@ fdset_event_dispatch(struct fdset *pfdset)
void *dat;
int fd;
int remove1, remove2;
+ int ret;
if (pfdset == NULL)
return;
while (1) {
+ struct timeval tv;
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
FD_ZERO(&rfds);
FD_ZERO(&wfds);
pthread_mutex_lock(&pfdset->fd_mutex);
maxfds = fdset_fill(&rfds, &wfds, pfdset);
- if (maxfds == -1) {
- pthread_mutex_unlock(&pfdset->fd_mutex);
- sleep(1);
- continue;
- }
pthread_mutex_unlock(&pfdset->fd_mutex);
- select(maxfds + 1, &rfds, &wfds, NULL, NULL);
+ ret = select(maxfds + 1, &rfds, &wfds, NULL, &tv);
+ if (ret <= 0)
+ continue;
for (i = 0; i < num; i++) {
remove1 = remove2 = 0;
--
1.8.1.4
next reply other threads:[~2015-03-06 5:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-06 5:52 Huawei Xie [this message]
2015-03-06 10:04 ` Ananyev, Konstantin
2015-03-09 8:26 ` Thomas Monjalon
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=1425621147-14904-1-git-send-email-huawei.xie@intel.com \
--to=huawei.xie@intel.com \
--cc=dev@dpdk.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;
as well as URLs for NNTP newsgroup(s).