diff --git a/gems/src/server/http_block/http.cc b/gems/src/server/http_block/http.cc index d02ef3d24..a8e12eb18 100644 --- a/gems/src/server/http_block/http.cc +++ b/gems/src/server/http_block/http.cc @@ -15,6 +15,7 @@ #include #include #include +#include extern "C" { #include @@ -295,9 +296,11 @@ void Http::cmd_get(size_t file_offset, size_t size, off_t offset) void __attribute__((constructor)) init() { + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + lwip_tcpip_init(); - if (lwip_nic_init(0, 0, 0)) { + if (lwip_nic_init(0, 0, 0, BUF_SIZE, BUF_SIZE)) { PERR("DHCP failed"); throw -1; } diff --git a/libports/include/lwip/genode.h b/libports/include/lwip/genode.h index be8977129..6af19b3dc 100644 --- a/libports/include/lwip/genode.h +++ b/libports/include/lwip/genode.h @@ -33,6 +33,8 @@ void lwip_tcpip_init(void); * DHCP * \param netmask IPv4 network mask in network byte order * \param gateway IPv4 network-gateway address in network byte order + * \param tx_buf_size packet stream buffer size for TX direction + * \param rx_buf_size packet stream buffer size for RX direction * * \return 0 on success, or 1 if DHCP failed. * @@ -40,7 +42,10 @@ void lwip_tcpip_init(void); * requests. */ int lwip_nic_init(genode_int32_t ip_addr, - genode_int32_t netmask, genode_int32_t gateway); + genode_int32_t netmask, + genode_int32_t gateway, + __SIZE_TYPE__ tx_buf_size, + __SIZE_TYPE__ rx_buf_size); #ifdef __cplusplus } diff --git a/libports/src/lib/libc_lwip_nic_dhcp/init.cc b/libports/src/lib/libc_lwip_nic_dhcp/init.cc index 23745c044..f87ec6977 100644 --- a/libports/src/lib/libc_lwip_nic_dhcp/init.cc +++ b/libports/src/lib/libc_lwip_nic_dhcp/init.cc @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -32,6 +33,8 @@ extern void create_etc_resolv_conf_plugin(); void __attribute__((constructor)) init_nic_dhcp(void) { + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + PDBG("init_nic_dhcp()\n"); bool provide_etc_resolv_conf = true; @@ -43,6 +46,8 @@ void __attribute__((constructor)) init_nic_dhcp(void) genode_int32_t ip_addr = 0; genode_int32_t netmask = 0; genode_int32_t gateway = 0; + Genode::Number_of_bytes tx_buf_size(BUF_SIZE); + Genode::Number_of_bytes rx_buf_size(BUF_SIZE); try { Genode::Xml_node libc_node = Genode::config()->xml_node().sub_node("libc"); @@ -64,6 +69,14 @@ void __attribute__((constructor)) init_nic_dhcp(void) libc_node.attribute("gateway").value(gateway_str, sizeof(gateway_str)); } catch(...) { } + try { + libc_node.attribute("tx_buf_size").value(&tx_buf_size); + } catch(...) { } + + try { + libc_node.attribute("rx_buf_size").value(&rx_buf_size); + } catch(...) { } + /* either none or all 3 interface attributes must exist */ if ((strlen(ip_addr_str) != 0) || (strlen(netmask_str) != 0) || @@ -108,7 +121,8 @@ void __attribute__((constructor)) init_nic_dhcp(void) create_lwip_plugin(); try { - lwip_nic_init(ip_addr, netmask, gateway); + lwip_nic_init(ip_addr, netmask, gateway, + (Genode::size_t)tx_buf_size, (Genode::size_t)rx_buf_size); } catch (Genode::Parent::Service_denied) { /* ignore for now */ } diff --git a/libports/src/lib/lwip/include/nic.h b/libports/src/lib/lwip/include/nic.h index 7753dea57..1874f2896 100644 --- a/libports/src/lib/lwip/include/nic.h +++ b/libports/src/lib/lwip/include/nic.h @@ -14,6 +14,12 @@ #ifndef _LWIP__NIC_H_ #define _LWIP__NIC_H_ +struct netif_buf_sizes { + __SIZE_TYPE__ tx_buf_size; + __SIZE_TYPE__ rx_buf_size; +}; + + /** * Initializes the genode nic backend. * diff --git a/libports/src/lib/lwip/platform/nic.cc b/libports/src/lib/lwip/platform/nic.cc index 027232ac9..3227e646f 100644 --- a/libports/src/lib/lwip/platform/nic.cc +++ b/libports/src/lib/lwip/platform/nic.cc @@ -244,17 +244,15 @@ extern "C" { LWIP_ASSERT("netif != NULL", (netif != NULL)); /* Initialize nic-session */ - enum { - PACKET_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE, - BUF_SIZE = Nic::Session::QUEUE_SIZE * PACKET_SIZE, - }; - Nic::Packet_allocator *tx_block_alloc = new (env()->heap()) Nic::Packet_allocator(env()->heap()); + struct netif_buf_sizes *nbs = (struct netif_buf_sizes *) netif->state; Nic::Connection *nic = 0; try { - nic = new (env()->heap()) Nic::Connection(tx_block_alloc, BUF_SIZE, BUF_SIZE); + nic = new (env()->heap()) Nic::Connection(tx_block_alloc, + nbs->tx_buf_size, + nbs->rx_buf_size); } catch (Parent::Service_denied) { destroy(env()->heap(), tx_block_alloc); return ERR_IF; diff --git a/libports/src/lib/lwip/platform/sys_arch.cc b/libports/src/lib/lwip/platform/sys_arch.cc index 151ed9d45..4b5745198 100644 --- a/libports/src/lib/lwip/platform/sys_arch.cc +++ b/libports/src/lib/lwip/platform/sys_arch.cc @@ -135,11 +135,17 @@ extern "C" { /* in lwip/genode.h */ - int lwip_nic_init(genode_int32_t ip_addr, - genode_int32_t netmask, genode_int32_t gateway) + int lwip_nic_init(Genode::int32_t ip_addr, + Genode::int32_t netmask, + Genode::int32_t gateway, + Genode::size_t tx_buf_size, + Genode::size_t rx_buf_size) { static struct netif netif; struct ip_addr ip, nm, gw; + static struct netif_buf_sizes nbs; + nbs.tx_buf_size = tx_buf_size; + nbs.rx_buf_size = rx_buf_size; ip.addr = ip_addr; nm.addr = netmask; gw.addr = gateway; @@ -157,7 +163,8 @@ extern "C" { * * See: http://lwip.wikia.com/wiki/Writing_a_device_driver */ - struct netif *ret = netif_add(&netif, &ip, &nm, &gw, NULL, genode_netif_init, tcpip_input); + struct netif *ret = netif_add(&netif, &ip, &nm, &gw, &nbs, + genode_netif_init, tcpip_input); if (!ret) throw Nic_not_availble(); diff --git a/libports/src/test/lwip/http_clnt/main.cc b/libports/src/test/lwip/http_clnt/main.cc index 82ffc0285..0deb3ea4e 100644 --- a/libports/src/test/lwip/http_clnt/main.cc +++ b/libports/src/test/lwip/http_clnt/main.cc @@ -17,6 +17,7 @@ #include #include #include +#include extern "C" { #include @@ -38,12 +39,14 @@ static const char *http_get_request = */ int main() { + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + static Timer::Connection _timer; lwip_tcpip_init(); char serv_addr[] = "10.0.2.55"; - if( lwip_nic_init(0, 0, 0)) + if( lwip_nic_init(0, 0, 0, BUF_SIZE, BUF_SIZE)) { PERR("We got no IP address!"); return 0; diff --git a/libports/src/test/lwip/http_srv/main.cc b/libports/src/test/lwip/http_srv/main.cc index d05ae2ec2..8865eeb54 100644 --- a/libports/src/test/lwip/http_srv/main.cc +++ b/libports/src/test/lwip/http_srv/main.cc @@ -21,6 +21,7 @@ #include #include #include +#include /* LwIP includes */ extern "C" { @@ -78,12 +79,14 @@ void http_server_serve(int conn) { int main() { + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + int s; lwip_tcpip_init(); /* Initialize network stack and do DHCP */ - if (lwip_nic_init(0, 0, 0)) { + if (lwip_nic_init(0, 0, 0, BUF_SIZE, BUF_SIZE)) { PERR("We got no IP address!"); return -1; } diff --git a/libports/src/test/lwip/http_srv_static/main.cc b/libports/src/test/lwip/http_srv_static/main.cc index df795cdc2..3dd778171 100644 --- a/libports/src/test/lwip/http_srv_static/main.cc +++ b/libports/src/test/lwip/http_srv_static/main.cc @@ -21,6 +21,7 @@ #include #include #include +#include /* LwIP includes */ extern "C" { @@ -78,12 +79,15 @@ void http_server_serve(int conn) { int main() { + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + int s; lwip_tcpip_init(); /* Initialize network stack */ - if (lwip_nic_init(inet_addr("10.0.2.55"), inet_addr("255.255.255.0"), inet_addr("10.0.2.1"))) { + if (lwip_nic_init(inet_addr("10.0.2.55"), inet_addr("255.255.255.0"), + inet_addr("10.0.2.1"), BUF_SIZE, BUF_SIZE)) { PERR("We got no IP address!"); return -1; } diff --git a/libports/src/test/lwip/http_srv_tracing/main.cc b/libports/src/test/lwip/http_srv_tracing/main.cc index 06be7eac2..9aec6ef6e 100644 --- a/libports/src/test/lwip/http_srv_tracing/main.cc +++ b/libports/src/test/lwip/http_srv_tracing/main.cc @@ -21,6 +21,7 @@ #include #include #include +#include /* LwIP includes */ extern "C" { @@ -98,12 +99,14 @@ void http_server_serve(int conn) { int main() { + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + int s; lwip_tcpip_init(); /* Initialize network stack and do DHCP */ - if (lwip_nic_init(0, 0, 0)) { + if (lwip_nic_init(0, 0, 0, BUF_SIZE, BUF_SIZE)) { PERR("We got no IP address!"); return -1; } diff --git a/libports/src/test/lwip/http_srv_tracing_nonblocking/main.cc b/libports/src/test/lwip/http_srv_tracing_nonblocking/main.cc index 60a374a49..c16991bcc 100644 --- a/libports/src/test/lwip/http_srv_tracing_nonblocking/main.cc +++ b/libports/src/test/lwip/http_srv_tracing_nonblocking/main.cc @@ -21,6 +21,7 @@ #include #include #include +#include /* LwIP includes */ extern "C" { @@ -92,6 +93,8 @@ void http_server_serve(int conn) { int main() { + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + int s, c_num; fd_set rs, ws, es; @@ -99,7 +102,7 @@ int main() lwip_tcpip_init(); /* Initialize network stack and do DHCP */ - if (lwip_nic_init(0, 0, 0)) { + if (lwip_nic_init(0, 0, 0, BUF_SIZE, BUF_SIZE)) { PERR("We got no IP address!"); return -1; } diff --git a/libports/src/test/lwip/pingpong/server/main.cc b/libports/src/test/lwip/pingpong/server/main.cc index 350636788..006aebbdf 100644 --- a/libports/src/test/lwip/pingpong/server/main.cc +++ b/libports/src/test/lwip/pingpong/server/main.cc @@ -16,6 +16,7 @@ #include #ifdef LWIP_NATIVE +#include #include #endif @@ -139,9 +140,11 @@ main(int argc, char *argv[]) char listenip[16] = "0.0.0.0"; #ifdef LWIP_NATIVE + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + lwip_tcpip_init(); /* DHCP */ - if (lwip_nic_init(0, 0, 0)) { + if (lwip_nic_init(0, 0, 0, BUF_SIZE, BUF_SIZE)) { printf("ERROR: We got no IP address!\n"); return 1; } diff --git a/os/include/nic_session/connection.h b/os/include/nic_session/connection.h index 237a0225e..17778a2ee 100644 --- a/os/include/nic_session/connection.h +++ b/os/include/nic_session/connection.h @@ -31,8 +31,8 @@ namespace Nic { * \param rx_buf_size size of reception buffer in bytes */ Connection(Genode::Range_allocator *tx_block_alloc, - Genode::size_t tx_buf_size = 64*1024, - Genode::size_t rx_buf_size = 64*1024) + Genode::size_t tx_buf_size, + Genode::size_t rx_buf_size) : Genode::Connection( session("ram_quota=%zd, tx_buf_size=%zd, rx_buf_size=%zd", diff --git a/os/src/test/nic_loopback/main.cc b/os/src/test/nic_loopback/main.cc index dc2978248..da73abc68 100644 --- a/os/src/test/nic_loopback/main.cc +++ b/os/src/test/nic_loopback/main.cc @@ -14,6 +14,7 @@ #include #include #include +#include #include using namespace Genode; @@ -162,13 +163,15 @@ int main(int, char **) { printf("--- NIC loop-back test ---\n"); + enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; + bool config_test_roundtrip = true; bool config_test_batch = true; if (config_test_roundtrip) { printf("-- test roundtrip two times (packet offsets should be the same) --\n"); Allocator_avl tx_block_alloc(env()->heap()); - Nic::Connection nic(&tx_block_alloc); + Nic::Connection nic(&tx_block_alloc, BUF_SIZE, BUF_SIZE); single_packet_roundtrip(&nic, 'a', 100); single_packet_roundtrip(&nic, 'b', 100); } @@ -176,7 +179,7 @@ int main(int, char **) if (config_test_batch) { printf("-- test submitting and receiving batches of packets --\n"); Allocator_avl tx_block_alloc(env()->heap()); - Nic::Connection nic(&tx_block_alloc); + Nic::Connection nic(&tx_block_alloc, BUF_SIZE, BUF_SIZE); enum { NUM_PACKETS = 1000 }; batch_packets(&nic, NUM_PACKETS); } diff --git a/ports/run/netperf.inc b/ports/run/netperf.inc index 850bbd728..ba8e2f5ce 100644 --- a/ports/run/netperf.inc +++ b/ports/run/netperf.inc @@ -161,10 +161,10 @@ append config { - } -append_if [have_spec linux] config " - " -append config { + + } append_if $use_nic_bridge config {