mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
sim/net: Replace the busy polling with work
netdriver_loop should check there is data to read before queue the work
This commit is contained in:
@@ -116,6 +116,7 @@ config SIM_NETDEV
|
||||
depends on NET_ETHERNET
|
||||
select ARCH_HAVE_NETDEV_STATISTICS
|
||||
select SCHED_LPWORK
|
||||
select SIM_WALLTIME
|
||||
---help---
|
||||
Build in support for a simulated network device using a TAP device on Linux or
|
||||
WPCAP on Windows.
|
||||
|
||||
@@ -167,7 +167,7 @@ ifeq ($(CONFIG_SIM_NETDEV),y)
|
||||
CSRCS += up_netdriver.c
|
||||
HOSTCFLAGS += -DNETDEV_BUFSIZE=$(CONFIG_NET_ETH_PKTSIZE)
|
||||
ifneq ($(HOSTOS),Cygwin)
|
||||
HOSTSRCS += up_tapdev.c up_netdev.c
|
||||
HOSTSRCS += up_tapdev.c
|
||||
ifeq ($(CONFIG_SIM_NET_BRIDGE),y)
|
||||
HOSTCFLAGS += -DCONFIG_SIM_NET_BRIDGE
|
||||
HOSTCFLAGS += -DCONFIG_SIM_NET_BRIDGE_DEVICE=\"$(CONFIG_SIM_NET_BRIDGE_DEVICE)\"
|
||||
@@ -176,7 +176,7 @@ ifeq ($(CONFIG_SIM_NET_HOST_ROUTE),y)
|
||||
HOSTCFLAGS += -DCONFIG_SIM_NET_HOST_ROUTE
|
||||
endif
|
||||
else # HOSTOS != Cygwin
|
||||
HOSTSRCS += up_wpcap.c up_netdev.c
|
||||
HOSTSRCS += up_wpcap.c
|
||||
DRVLIB = /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a
|
||||
endif # HOSTOS != Cygwin
|
||||
endif # CONFIG_SIM_NETDEV
|
||||
|
||||
@@ -272,12 +272,6 @@ bool simuart_checkc(void);
|
||||
char *up_deviceimage(void);
|
||||
void up_registerblockdevice(void);
|
||||
|
||||
/* up_netdev.c **************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
unsigned long up_getwalltime(void);
|
||||
#endif
|
||||
|
||||
/* up_x11framebuffer.c ******************************************************/
|
||||
|
||||
#ifdef CONFIG_SIM_X11FB
|
||||
@@ -324,12 +318,14 @@ FAR struct ioexpander_dev_s *sim_ioexpander_initialize(void);
|
||||
|
||||
#if defined(CONFIG_SIM_NETDEV) && !defined(__CYGWIN__)
|
||||
void tapdev_init(void);
|
||||
int tapdev_avail(void);
|
||||
unsigned int tapdev_read(unsigned char *buf, unsigned int buflen);
|
||||
void tapdev_send(unsigned char *buf, unsigned int buflen);
|
||||
void tapdev_ifup(in_addr_t ifaddr);
|
||||
void tapdev_ifdown(void);
|
||||
|
||||
# define netdev_init() tapdev_init()
|
||||
# define netdev_avail() tapdev_avail()
|
||||
# define netdev_read(buf,buflen) tapdev_read(buf,buflen)
|
||||
# define netdev_send(buf,buflen) tapdev_send(buf,buflen)
|
||||
# define netdev_ifup(ifaddr) tapdev_ifup(ifaddr)
|
||||
@@ -344,6 +340,7 @@ unsigned int wpcap_read(unsigned char *buf, unsigned int buflen);
|
||||
void wpcap_send(unsigned char *buf, unsigned int buflen);
|
||||
|
||||
# define netdev_init() wpcap_init()
|
||||
# define netdev_avail() 1
|
||||
# define netdev_read(buf,buflen) wpcap_read(buf,buflen)
|
||||
# define netdev_send(buf,buflen) wpcap_send(buf,buflen)
|
||||
# define netdev_ifup(ifaddr) {}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/sim/up_tapdev.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL (void*)0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
unsigned long up_getwalltime(void)
|
||||
{
|
||||
struct timeval tm;
|
||||
gettimeofday(&tm, NULL);
|
||||
return tm.tv_sec*1000 + tm.tv_usec/1000;
|
||||
}
|
||||
+200
-224
File diff suppressed because it is too large
Load Diff
@@ -231,11 +231,10 @@ void tapdev_init(void)
|
||||
set_macaddr();
|
||||
}
|
||||
|
||||
unsigned int tapdev_read(unsigned char *buf, unsigned int buflen)
|
||||
int tapdev_avail(void)
|
||||
{
|
||||
fd_set fdset;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
struct timeval tv;
|
||||
fd_set fdset;
|
||||
|
||||
/* We can't do anything if we failed to open the tap device */
|
||||
|
||||
@@ -247,13 +246,19 @@ unsigned int tapdev_read(unsigned char *buf, unsigned int buflen)
|
||||
/* Wait for data on the tap device (or a timeout) */
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1000;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(gtapdevfd, &fdset);
|
||||
|
||||
ret = select(gtapdevfd + 1, &fdset, NULL, NULL, &tv);
|
||||
if (ret == 0)
|
||||
return select(gtapdevfd + 1, &fdset, NULL, NULL, &tv) > 0;
|
||||
}
|
||||
|
||||
unsigned int tapdev_read(unsigned char *buf, unsigned int buflen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!tapdev_avail())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ CONFIG_SCHED_HAVE_PARENT=y
|
||||
CONFIG_SCHED_ONEXIT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIM_WALLTIME=y
|
||||
CONFIG_START_DAY=3
|
||||
CONFIG_START_MONTH=4
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
|
||||
@@ -57,7 +57,6 @@ CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SIM_M32=y
|
||||
CONFIG_SIM_NET_BRIDGE=y
|
||||
CONFIG_SIM_RPTUN_MASTER=y
|
||||
CONFIG_SIM_WALLTIME=y
|
||||
CONFIG_SYSLOG_PREFIX=y
|
||||
CONFIG_SYSLOG_PREFIX_STRING="server: "
|
||||
CONFIG_SYSLOG_RPMSG_SERVER=y
|
||||
|
||||
@@ -48,7 +48,6 @@ CONFIG_SCHED_HAVE_PARENT=y
|
||||
CONFIG_SCHED_ONEXIT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIM_WALLTIME=y
|
||||
CONFIG_START_MONTH=6
|
||||
CONFIG_START_YEAR=2008
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
|
||||
@@ -57,7 +57,6 @@ CONFIG_SCHED_HAVE_PARENT=y
|
||||
CONFIG_SCHED_ONEXIT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIM_WALLTIME=y
|
||||
CONFIG_START_MONTH=6
|
||||
CONFIG_START_YEAR=2008
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
|
||||
@@ -48,7 +48,6 @@ CONFIG_SCHED_HAVE_PARENT=y
|
||||
CONFIG_SCHED_ONEXIT=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_SIM_WALLTIME=y
|
||||
CONFIG_START_MONTH=6
|
||||
CONFIG_START_YEAR=2008
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
|
||||
Reference in New Issue
Block a user