* [PATCH] lib/librte_vhost: combine select with sleep
@ 2015-03-06 5:52 Huawei Xie
[not found] ` <1425621147-14904-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Huawei Xie @ 2015-03-06 5:52 UTC (permalink / raw)
To: dev-VfR2kkLFssw
combine sleep into select when there is no file descriptors to be monitored.
Signed-off-by: Huawei Xie <huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread[parent not found: <1425621147-14904-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>]
* Re: [PATCH] lib/librte_vhost: combine select with sleep [not found] ` <1425621147-14904-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> @ 2015-03-06 10:04 ` Ananyev, Konstantin [not found] ` <2601191342CEEE43887BDE71AB977258213F4481-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org> 0 siblings, 1 reply; 3+ messages in thread From: Ananyev, Konstantin @ 2015-03-06 10:04 UTC (permalink / raw) To: Xie, Huawei, dev-VfR2kkLFssw@public.gmane.org > -----Original Message----- > From: Xie, Huawei > Sent: Friday, March 06, 2015 5:52 AM > To: dev-VfR2kkLFssw@public.gmane.org > Cc: Ananyev, Konstantin; Xie, Huawei > Subject: [PATCH] lib/librte_vhost: combine select with sleep > > combine sleep into select when there is no file descriptors to be monitored. > > Signed-off-by: Huawei Xie <huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> Acked-by: Konstantin Ananyev <konstantin.ananyev-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> > --- > 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <2601191342CEEE43887BDE71AB977258213F4481-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org>]
* Re: [PATCH] lib/librte_vhost: combine select with sleep [not found] ` <2601191342CEEE43887BDE71AB977258213F4481-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org> @ 2015-03-09 8:26 ` Thomas Monjalon 0 siblings, 0 replies; 3+ messages in thread From: Thomas Monjalon @ 2015-03-09 8:26 UTC (permalink / raw) To: Xie, Huawei; +Cc: dev-VfR2kkLFssw > > combine sleep into select when there is no file descriptors to be monitored. > > > > Signed-off-by: Huawei Xie <huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> > > Acked-by: Konstantin Ananyev <konstantin.ananyev-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> Applied, thanks ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-09 8:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-06 5:52 [PATCH] lib/librte_vhost: combine select with sleep Huawei Xie
[not found] ` <1425621147-14904-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-06 10:04 ` Ananyev, Konstantin
[not found] ` <2601191342CEEE43887BDE71AB977258213F4481-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-09 8:26 ` Thomas Monjalon
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.