From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 026A65677 for ; Fri, 6 Mar 2015 06:52:35 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 05 Mar 2015 21:51:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,351,1422950400"; d="scan'208";a="536922936" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga003.jf.intel.com with ESMTP; 05 Mar 2015 21:52:20 -0800 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t265qVRb029996; Fri, 6 Mar 2015 13:52:31 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t265qTqJ014938; Fri, 6 Mar 2015 13:52:31 +0800 Received: (from hxie5@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t265qTNW014934; Fri, 6 Mar 2015 13:52:29 +0800 From: Huawei Xie To: dev@dpdk.org Date: Fri, 6 Mar 2015 13:52:27 +0800 Message-Id: <1425621147-14904-1-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.7.4.1 Subject: [dpdk-dev] [PATCH] lib/librte_vhost: combine select with sleep X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Mar 2015 05:52:36 -0000 combine sleep into select when there is no file descriptors to be monitored. Signed-off-by: Huawei Xie --- 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