diff --git a/ports/6502/sys_c64.c b/ports/6502/sys_c64.c index 1ed52fd..a282c0b 100644 --- a/ports/6502/sys_c64.c +++ b/ports/6502/sys_c64.c @@ -114,7 +114,7 @@ sys_arch_timeouts(void) } /*-----------------------------------------------------------------------------------*/ sys_thread_t -sys_thread_new(void (* function)(void *arg), void *arg) +sys_thread_new(void (* function)(void *arg), void *arg, int prio) { return 0; } diff --git a/ports/coldfire/netif/5272fec.c b/ports/coldfire/netif/5272fec.c index 5addc15..bd92427 100644 --- a/ports/coldfire/netif/5272fec.c +++ b/ports/coldfire/netif/5272fec.c @@ -741,7 +741,7 @@ etharp_timer_thread(void *arg) static void etharp_timer_init(void *arg) { - sys_thread_new((void *)etharp_timer_thread, arg); + sys_thread_new((void *)etharp_timer_thread, arg, DEFAULT_THREAD_PRIO); } diff --git a/ports/coldfire/proj/lwipopts.h b/ports/coldfire/proj/lwipopts.h index 2e0768b..8b63207 100644 --- a/ports/coldfire/proj/lwipopts.h +++ b/ports/coldfire/proj/lwipopts.h @@ -200,4 +200,17 @@ a lot of data that needs to be copied, this should be set high. */ #define LWIP_COMPAT_SOCKETS 1 #define LWIP_PROVIDE_ERRNO 1 + +/* People often make a mistake on the priority of their communications task. + The TCP/IP stack should be at a relatively low priority if it is an endpoint + (not a router) on a somewhat underpowered CPU. You are'nt going to keep up + with network traffic during a denial of service attack or misconfigured network + and you don't want an overburdened network task to cause other important tasks + (including your UI) to stop working. Drop packets! It forces flow control and + lets the rest of your system run. +*/ +#define TCPIP_THREAD_PRIO 220 // Relatively low priority + +#define DEFAULT_THREAD_PRIO 240 + #endif /* __LWIPOPTS_H__ */ diff --git a/ports/coldfire/sys_arch.c b/ports/coldfire/sys_arch.c index 92216b7..84db9fc 100644 --- a/ports/coldfire/sys_arch.c +++ b/ports/coldfire/sys_arch.c @@ -73,15 +73,6 @@ static struct sys_hisr *hisrs = NULL; #define SYS_MBOX_SIZE 128 // Number of elements in mbox queue #define SYS_STACK_SIZE 2048 // A minimum Nucleus stack for coldfire #define SYS_HISR_STACK_SIZE 2048 // A minimum Nucleus stack for coldfire -/* People often make a mistake on the priority of their communications task. - The TCP/IP stack should be at a relatively low priority if it is an endpoint - (not a router) on a somewhat underpowered CPU. You are'nt going to keep up - with network traffic during a denial of service attack or misconfigured network - and you don't want an overburdened network task to cause other important tasks - (including your UI) to stop working. Drop packets! It forces flow control and - lets the rest of your system run. -*/ -#define SYS_THREAD_PRIORITY 220 // Relatively low priority /*---------------------------------------------------------------------------------*/ void @@ -127,7 +118,7 @@ introduce_thread(NU_TASK *id, void (*function)(void *arg), void *arg) /* We use Nucleus task as thread. Create one with a standard size stack at a standard * priority. */ sys_thread_t -sys_thread_new(void (*function)(void *arg), void *arg) +sys_thread_new(void (*function)(void *arg), void *arg, int prio) { NU_TASK *p_thread; u8_t *p_stack; @@ -156,7 +147,7 @@ sys_thread_new(void (*function)(void *arg), void *arg) st, p_stack, SYS_STACK_SIZE, - SYS_THREAD_PRIORITY, + prio, 0, //Disable timeslicing NU_PREEMPT, NU_START); diff --git a/ports/rtxc/netif/sioslipif.c b/ports/rtxc/netif/sioslipif.c index 847be57..60ad2e6 100644 --- a/ports/rtxc/netif/sioslipif.c +++ b/ports/rtxc/netif/sioslipif.c @@ -164,7 +164,7 @@ sioslipif_init(struct netif *netif) netif->output = sioslipif_output; netif_pass = netif; - sys_thread_new((void *)sioslipif_loop, NULL); + sys_thread_new((void *)sioslipif_loop, NULL, DEFAULT_THREAD_PRIO); /* Do some magic to make it possible to receive data from the serial I/O device. */ } /*-----------------------------------------------------------------------------------*/ diff --git a/ports/rtxc/sys_arch.c b/ports/rtxc/sys_arch.c index b20b27e..45edbb5 100644 --- a/ports/rtxc/sys_arch.c +++ b/ports/rtxc/sys_arch.c @@ -242,10 +242,10 @@ sys_thread(void) } /*-----------------------------------------------------------------------------------*/ sys_thread_t -sys_thread_new(void (* function)(void *arg), void *arg) +sys_thread_new(void (* function)(void *arg), void *arg, int prio) { TASK newtask; - PRIORITY pri = 2; /* This may have to be changed. */ + PRIORITY pri = prio; /* This may have to be changed. */ char *stack; int stacksize = 512; /* This may have to be changed. */ struct sys_thread_arg threadarg; diff --git a/ports/unix/include/arch/cc.h b/ports/unix/include/arch/cc.h index 96205e7..7010a5d 100644 --- a/ports/unix/include/arch/cc.h +++ b/ports/unix/include/arch/cc.h @@ -36,9 +36,9 @@ #include /* Define platform endianness */ -#ifndef BYTE_ORDER -#define BYTE_ORDER LITTLE_ENDIAN -#endif /* BYTE_ORDER */ +//#ifndef BYTE_ORDER +//#define BYTE_ORDER LITTLE_ENDIAN +//#endif /* BYTE_ORDER */ /* Define generic types used in lwIP */ typedef unsigned char u8_t; diff --git a/ports/unix/netif/delif.c b/ports/unix/netif/delif.c index 6b353f9..6b42f98 100644 --- a/ports/unix/netif/delif.c +++ b/ports/unix/netif/delif.c @@ -314,7 +314,7 @@ delif_init_thread(struct netif *netif) del->netif->netmask = netif->netmask; del->input = netif->input; del->netif->input = delif_input; - sys_thread_new(delif_thread, netif); + sys_thread_new(delif_thread, netif, DEFAULT_THREAD_PRIO); return ERR_OK; } diff --git a/ports/unix/netif/pcapif.c b/ports/unix/netif/pcapif.c index f41440a..92e0233 100644 --- a/ports/unix/netif/pcapif.c +++ b/ports/unix/netif/pcapif.c @@ -209,7 +209,7 @@ pcapif_init(struct netif *netif) p->p = NULL; p->lasttime = 0; - sys_thread_new(pcapif_thread, netif); + sys_thread_new(pcapif_thread, netif, DEFAULT_THREAD_PRIO); return ERR_OK; } /*-----------------------------------------------------------------------------------*/ diff --git a/ports/unix/netif/tapif.c b/ports/unix/netif/tapif.c index 7fd520c..8d10eba 100644 --- a/ports/unix/netif/tapif.c +++ b/ports/unix/netif/tapif.c @@ -126,7 +126,7 @@ low_level_init(struct netif *netif) DEBUGF(TAPIF_DEBUG, ("tapif_init: system(\"%s\");\n", buf)); system(buf); - sys_thread_new(tapif_thread, netif); + sys_thread_new(tapif_thread, netif, DEFAULT_THREAD_PRIO); } /*-----------------------------------------------------------------------------------*/ diff --git a/ports/unix/netif/tunif.c b/ports/unix/netif/tunif.c index f24d81f..910b7e0 100644 --- a/ports/unix/netif/tunif.c +++ b/ports/unix/netif/tunif.c @@ -97,7 +97,7 @@ low_level_init(struct netif *netif) DEBUGF(TUNIF_DEBUG, ("tunif_init: system(\"%s\");\n", buf)); system(buf); - sys_thread_new(tunif_thread, netif); + sys_thread_new(tunif_thread, netif, DEFAULT_THREAD_PRIO); } /*-----------------------------------------------------------------------------------*/ diff --git a/ports/unix/netif/unixif.c b/ports/unix/netif/unixif.c index 76c4bcc..ca28b31 100644 --- a/ports/unix/netif/unixif.c +++ b/ports/unix/netif/unixif.c @@ -452,8 +452,8 @@ unixif_init_server(struct netif *netif) unixif->fd = fd2; unixif->sem = sys_sem_new(0); - sys_thread_new(unixif_thread, netif); - sys_thread_new(unixif_thread2, netif); + sys_thread_new(unixif_thread, netif, DEFAULT_THREAD_PRIO); + sys_thread_new(unixif_thread2, netif, DEFAULT_THREAD_PRIO); return ERR_OK; } /*-----------------------------------------------------------------------------------*/ @@ -476,8 +476,8 @@ unixif_init_client(struct netif *netif) } unixif->q = list_new(UNIXIF_QUEUELEN); unixif->sem = sys_sem_new(0); - sys_thread_new(unixif_thread, netif); - sys_thread_new(unixif_thread2, netif); + sys_thread_new(unixif_thread, netif, DEFAULT_THREAD_PRIO); + sys_thread_new(unixif_thread2, netif, DEFAULT_THREAD_PRIO); return ERR_OK; } /*-----------------------------------------------------------------------------------*/ diff --git a/ports/unix/proj/unixsim/Makefile b/ports/unix/proj/unixsim/Makefile index 6734e7b..fc59553 100644 --- a/ports/unix/proj/unixsim/Makefile +++ b/ports/unix/proj/unixsim/Makefile @@ -66,7 +66,7 @@ NETIFFILES=$(LWIPDIR)/netif/loopif.c \ $(LWIPDIR)/netif/etharp.c $(LWIPDIR)/netif/slipif.c # ARCHFILES: Architecture specific files. -ARCHFILES=$(wildcard $(LWIPARCH)/*.c $(LWIPARCH)/netif/*.c) +ARCHFILES=$(wildcard $(LWIPARCH)/*.c $(LWIPARCH)/netif/tapif.c $(LWIPARCH)/netif/tcpdump.c) # APPFILES: Applications. APPFILES=apps/fs.c apps/httpd.c \ diff --git a/ports/unix/proj/unixsim/apps/shell.c b/ports/unix/proj/unixsim/apps/shell.c index 3b1e95e..216eed2 100644 --- a/ports/unix/proj/unixsim/apps/shell.c +++ b/ports/unix/proj/unixsim/apps/shell.c @@ -1052,7 +1052,7 @@ shell_thread(void *arg) void shell_init(void) { - sys_thread_new(shell_thread, NULL); + sys_thread_new(shell_thread, NULL, DEFAULT_THREAD_PRIO); } diff --git a/ports/unix/proj/unixsim/apps/tcpecho.c b/ports/unix/proj/unixsim/apps/tcpecho.c index 1a3ce68..83ad9e6 100644 --- a/ports/unix/proj/unixsim/apps/tcpecho.c +++ b/ports/unix/proj/unixsim/apps/tcpecho.c @@ -80,7 +80,7 @@ tcpecho_thread(void *arg) void tcpecho_init(void) { - sys_thread_new(tcpecho_thread, NULL); + sys_thread_new(tcpecho_thread, NULL, DEFAULT_THREAD_PRIO); } /*-----------------------------------------------------------------------------------*/ diff --git a/ports/unix/proj/unixsim/apps/udpecho.c b/ports/unix/proj/unixsim/apps/udpecho.c index c87a54b..733d34c 100644 --- a/ports/unix/proj/unixsim/apps/udpecho.c +++ b/ports/unix/proj/unixsim/apps/udpecho.c @@ -62,5 +62,5 @@ udpecho_thread(void *arg) void udpecho_init(void) { - sys_thread_new(udpecho_thread, NULL); + sys_thread_new(udpecho_thread, NULL, DEFAULT_THREAD_PRIO); } diff --git a/ports/unix/proj/unixsim/simhost.c b/ports/unix/proj/unixsim/simhost.c index c314ac2..adf49ae 100644 --- a/ports/unix/proj/unixsim/simhost.c +++ b/ports/unix/proj/unixsim/simhost.c @@ -174,7 +174,7 @@ main(int argc, char **argv) printf("System initialized.\n"); - sys_thread_new((void *)(main_thread), NULL); + sys_thread_new((void *)(main_thread), NULL, DEFAULT_THREAD_PRIO); pause(); return 0; } diff --git a/ports/unix/proj/unixsim/simnode.c b/ports/unix/proj/unixsim/simnode.c index 0d95dfd..c6d9e67 100644 --- a/ports/unix/proj/unixsim/simnode.c +++ b/ports/unix/proj/unixsim/simnode.c @@ -139,7 +139,7 @@ main(int argc, char **argv) printf("System initialized.\n"); - sys_thread_new((void *)(main_thread), NULL); + sys_thread_new((void *)(main_thread), NULL, DEFAULT_THREAD_PRIO); pause(); return 0; } diff --git a/ports/unix/proj/unixsim/simrouter.c b/ports/unix/proj/unixsim/simrouter.c index 27a9ac1..c2d0644 100644 --- a/ports/unix/proj/unixsim/simrouter.c +++ b/ports/unix/proj/unixsim/simrouter.c @@ -150,7 +150,7 @@ main(int argc, char **argv) printf("System initialized.\n"); - sys_thread_new((void *)(main_thread), NULL); + sys_thread_new((void *)(main_thread), NULL, DEFAULT_THREAD_PRIO); pause(); return 0; } diff --git a/ports/unix/sys_arch.c b/ports/unix/sys_arch.c index bff5f52..c93953a 100644 --- a/ports/unix/sys_arch.c +++ b/ports/unix/sys_arch.c @@ -151,7 +151,7 @@ current_thread(void) } /*-----------------------------------------------------------------------------------*/ sys_thread_t -sys_thread_new(void (*function)(void *arg), void *arg) +sys_thread_new(void (*function)(void *arg), void *arg, int prio) { int code; pthread_t tmp;