tweak lwipopts.h
This commit is contained in:
4
Makefile
4
Makefile
@@ -23,9 +23,9 @@ LWIP_C_FILES += $(NETIFFILES)
|
|||||||
LWIP_C_FILES += $(HTTPFILES)
|
LWIP_C_FILES += $(HTTPFILES)
|
||||||
|
|
||||||
LWIP_C_FILES_WITH_PATH := $(LWIP_C_FILES)
|
LWIP_C_FILES_WITH_PATH := $(LWIP_C_FILES)
|
||||||
LWIP_PORT_FILES := $(wildcard $(PORT_DIR)/*.c)
|
LWIP_PORT_FILES := $(wildcard $(PORT_DIR)/*.c $(PORT_DIR)/arch/*.c)
|
||||||
|
|
||||||
INCLUDE_DIRS ?= \
|
INCLUDE_DIRS += \
|
||||||
-I./inc \
|
-I./inc \
|
||||||
-I$(LWIP_DIR)/src/include \
|
-I$(LWIP_DIR)/src/include \
|
||||||
-I$(PORT_DIR)
|
-I$(PORT_DIR)
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -28,20 +28,6 @@ while (1) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
seems okayish
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ wrk -t12 -c500 -d10s http://192.168.102.119
|
|
||||||
Running 10s test @ http://192.168.102.119
|
|
||||||
12 threads and 500 connections
|
|
||||||
Thread Stats Avg Stdev Max +/- Stdev
|
|
||||||
Latency 1.87ms 6.98ms 613.62ms 99.63%
|
|
||||||
Req/Sec 334.20 201.29 0.88k 74.58%
|
|
||||||
8197 requests in 10.10s, 5.30MB read
|
|
||||||
Requests/sec: 811.63
|
|
||||||
Transfer/sec: 537.39KB
|
|
||||||
```
|
|
||||||
|
|
||||||
## Impl note
|
## Impl note
|
||||||
|
|
||||||
This driver is kinda functional but not optimized
|
This driver is kinda functional but not optimized
|
||||||
|
|||||||
@@ -32,4 +32,6 @@
|
|||||||
|
|
||||||
#define LWIP_RAND() ((u32_t)rand())
|
#define LWIP_RAND() ((u32_t)rand())
|
||||||
|
|
||||||
|
#include "arch/sys_arch.h"
|
||||||
|
|
||||||
#endif /* LWIP_ARCH_CC_H */
|
#endif /* LWIP_ARCH_CC_H */
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
#include "sys_arch.h"
|
||||||
|
|
||||||
#include "ch32fun.h"
|
#include "ch32fun.h"
|
||||||
#include "lwip/def.h"
|
#include "lwip/sys.h"
|
||||||
#include "systick.h"
|
#include "systick.h"
|
||||||
|
|
||||||
typedef uint32_t sys_prot_t;
|
|
||||||
static unsigned long next = 1;
|
static unsigned long next = 1;
|
||||||
|
|
||||||
int rand(void) {
|
int rand(void) {
|
||||||
@@ -15,11 +16,11 @@ void srand(unsigned int seed) { next = seed; }
|
|||||||
uint32_t sys_now(void) { return millis(); }
|
uint32_t sys_now(void) { return millis(); }
|
||||||
|
|
||||||
sys_prot_t sys_arch_protect(void) {
|
sys_prot_t sys_arch_protect(void) {
|
||||||
unsigned int old_mstatus;
|
__disable_irq();
|
||||||
__asm__ volatile("csrrci %0, mstatus, 8" : "=r"(old_mstatus));
|
return 1;
|
||||||
return old_mstatus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sys_arch_unprotect(sys_prot_t pval) {
|
void sys_arch_unprotect(sys_prot_t pval) {
|
||||||
__asm__ volatile("csrw mstatus, %0" : : "r"(pval));
|
(void)pval;
|
||||||
}
|
__enable_irq();
|
||||||
|
}
|
||||||
8
port/arch/sys_arch.h
Normal file
8
port/arch/sys_arch.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef LWIP_ARCH_SYS_ARCH_H
|
||||||
|
#define LWIP_ARCH_SYS_ARCH_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef uint32_t sys_prot_t;
|
||||||
|
|
||||||
|
#endif /* LWIP_ARCH_SYS_ARCH_H */
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
#define IFNAME0 'e'
|
#define IFNAME0 'e'
|
||||||
#define IFNAME1 'n'
|
#define IFNAME1 'n'
|
||||||
|
|
||||||
#define ETH_RX_BUF_COUNT 2
|
#define ETH_RX_BUF_COUNT 4
|
||||||
#define ETH_TX_BUF_COUNT 2
|
#define ETH_TX_BUF_COUNT 2
|
||||||
/* buf size should be at least ETH_MAX_PACKET_SIZE */
|
/* buf size should be at least ETH_MAX_PACKET_SIZE */
|
||||||
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE
|
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE
|
||||||
@@ -58,8 +58,8 @@ static inline void tx_queue_produce(tx_queue_t* q) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
static inline void tx_queue_consume(tx_queue_t* q) {
|
static inline void tx_queue_consume(tx_queue_t* q) {
|
||||||
q->is_full = false;
|
|
||||||
q->tail = (q->tail + 1) % ETH_TX_BUF_COUNT;
|
q->tail = (q->tail + 1) % ETH_TX_BUF_COUNT;
|
||||||
|
q->is_full = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void low_level_init(struct netif* netif);
|
static void low_level_init(struct netif* netif);
|
||||||
@@ -200,11 +200,11 @@ static err_t low_level_output(struct netif* netif, struct pbuf* p) {
|
|||||||
struct ethernetif* ethernetif = netif->state;
|
struct ethernetif* ethernetif = netif->state;
|
||||||
err_t errval = ERR_OK;
|
err_t errval = ERR_OK;
|
||||||
|
|
||||||
NVIC_DisableIRQ(ETH_IRQn);
|
|
||||||
|
|
||||||
if (tx_queue_is_full(ðernetif->tx_q)) {
|
if (tx_queue_is_full(ðernetif->tx_q)) {
|
||||||
|
// should this be ERR_BUF or ERR_MEM? does ERR_MEM re-queue the packet?
|
||||||
// queue full, drop pkt
|
// queue full, drop pkt
|
||||||
errval = ERR_BUF;
|
errval = ERR_BUF;
|
||||||
|
// errval = ERR_MEM;
|
||||||
} else {
|
} else {
|
||||||
uint32_t current_idx = ethernetif->tx_q.head;
|
uint32_t current_idx = ethernetif->tx_q.head;
|
||||||
uint8_t* tx_buf_ptr = (uint8_t*)g_dma_tx_descs[current_idx].Buffer1Addr;
|
uint8_t* tx_buf_ptr = (uint8_t*)g_dma_tx_descs[current_idx].Buffer1Addr;
|
||||||
@@ -218,19 +218,10 @@ static err_t low_level_output(struct netif* netif, struct pbuf* p) {
|
|||||||
g_dma_tx_descs[current_idx].Status = len;
|
g_dma_tx_descs[current_idx].Status = len;
|
||||||
|
|
||||||
tx_queue_produce(ðernetif->tx_q);
|
tx_queue_produce(ðernetif->tx_q);
|
||||||
|
|
||||||
LINK_STATS_INC(link.xmit);
|
|
||||||
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tx_start_if_possible();
|
tx_start_if_possible();
|
||||||
|
|
||||||
NVIC_EnableIRQ(ETH_IRQn);
|
|
||||||
|
|
||||||
if (errval == ERR_BUF) {
|
|
||||||
LINK_STATS_INC(link.drop);
|
|
||||||
}
|
|
||||||
|
|
||||||
return errval;
|
return errval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,8 +323,10 @@ void ETH_IRQHandler(void) {
|
|||||||
ETH10M->EIR = RB_ETH_EIR_TXIF;
|
ETH10M->EIR = RB_ETH_EIR_TXIF;
|
||||||
|
|
||||||
if (!tx_queue_is_empty(ðernetif->tx_q)) {
|
if (!tx_queue_is_empty(ðernetif->tx_q)) {
|
||||||
|
LINK_STATS_INC(link.xmit);
|
||||||
tx_queue_consume(ðernetif->tx_q);
|
tx_queue_consume(ðernetif->tx_q);
|
||||||
}
|
}
|
||||||
|
|
||||||
tx_start_if_possible();
|
tx_start_if_possible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
// #define ETHARP_DEBUG LWIP_DBG_ON
|
// #define ETHARP_DEBUG LWIP_DBG_ON
|
||||||
|
|
||||||
#define NO_SYS 1
|
#define NO_SYS 1
|
||||||
#define SYS_LIGHTWEIGHT_PROT 0
|
#define SYS_LIGHTWEIGHT_PROT 1
|
||||||
#define LWIP_NETCONN 0
|
#define LWIP_NETCONN 0
|
||||||
#define LWIP_SOCKET 0
|
#define LWIP_SOCKET 0
|
||||||
|
|
||||||
@@ -20,20 +20,20 @@
|
|||||||
#define MEM_SIZE (4 * 1024)
|
#define MEM_SIZE (4 * 1024)
|
||||||
|
|
||||||
// Pbuf options
|
// Pbuf options
|
||||||
#define PBUF_POOL_SIZE 4
|
#define PBUF_POOL_SIZE 6
|
||||||
#define PBUF_POOL_BUFSIZE 1524
|
#define PBUF_POOL_BUFSIZE 590
|
||||||
|
|
||||||
#define MEMP_NUM_PBUF 8 // default 16
|
#define MEMP_NUM_PBUF 6 // default 16
|
||||||
|
|
||||||
// TCP options
|
// TCP options
|
||||||
#define LWIP_TCP 1
|
#define LWIP_TCP 1
|
||||||
#define TCP_MSS 536
|
#define TCP_MSS 536
|
||||||
#define TCP_SND_BUF (2 * TCP_MSS)
|
#define TCP_SND_BUF (2 * TCP_MSS)
|
||||||
#define TCP_WND (2 * TCP_MSS)
|
#define TCP_WND (4 * TCP_MSS)
|
||||||
#define TCP_QUEUE_OOSEQ 0
|
#define TCP_QUEUE_OOSEQ 0
|
||||||
|
|
||||||
#define LWIP_UDP 1
|
#define LWIP_UDP 1
|
||||||
#define MEMP_NUM_UDP_PCB 2 // # of concurrent UDP "connections"
|
#define MEMP_NUM_UDP_PCB 3 // # of concurrent UDP "connections"
|
||||||
#define LWIP_ICMP 1
|
#define LWIP_ICMP 1
|
||||||
|
|
||||||
#define LWIP_DHCP 1
|
#define LWIP_DHCP 1
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
#define CHECKSUM_CHECK_TCP 1
|
#define CHECKSUM_CHECK_TCP 1
|
||||||
#define LWIP_CHECKSUM_ON_COPY 0
|
#define LWIP_CHECKSUM_ON_COPY 0
|
||||||
|
|
||||||
#define LWIP_STATS 1
|
#define LWIP_STATS 0
|
||||||
#define LINK_STATS 1
|
#define LINK_STATS 0
|
||||||
|
|
||||||
#endif /* __LWIPOPTS_H__ */
|
#endif /* __LWIPOPTS_H__ */
|
||||||
|
|||||||
Reference in New Issue
Block a user