Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lwip echoserver #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions apps/lwipserver2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
#
# SPDX-License-Identifier: BSD-2-Clause
#

cmake_minimum_required(VERSION 3.8.2)

project(lwipserver_single C)
includeGlobalComponents()

find_package(projects_libs REQUIRED)

set(CAmkESCPP ON CACHE BOOL "" FORCE)
if("${KernelArch}" STREQUAL "x86")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just use the boolean flags

Suggested change
if("${KernelArch}" STREQUAL "x86")
if(KernelArchARM)
...
elseif(KernelArchX86)
...

set(cpp_define -DKernelArchX86)
elseif("${KernelArch}" STREQUAL "arm")
set(cpp_define -DKernelArchArm)
endif()
Copy link
Member

@axel-h axel-h Mar 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's give it a clear error message here for anything else and avoid potentially undefined default behavior

else()
    message(FATAL_ERROR "Unsupported architecture: '${KernelArch}'.")
endif()


include(${LWIP_HELPERS})
AddLWIPConfiguration(${CMAKE_CURRENT_LIST_DIR}/lwip_include)

set(libs sel4utils sel4vka sel4allocman sel4vspace sel4simple
sel4platsupport lwip)

set(sources src/tcp_echo_socket.c src/udp_echo_socket.c src/utilization_socket.c)

DeclareCAmkESComponent(
LWIPServer
SOURCES
${sources}
INCLUDES
include
LIBS
${libs}
LD_FLAGS
-Wl,--section-start=.note.gnu.build-id=0x400920
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It this just a copy paste from somewhere? Maybe add a comment about this, that this is just optional to set a specific build ID. The kernel is using -Wl,--build-id=none" # Ensure reproducible builds here.

)

CAmkESAddCPPInclude("${CMAKE_CURRENT_LIST_DIR}/include/")

if(KernelSel4ArchX86_64)
DeclareCAmkESComponent(Ethdriver82574DF SOURCES x86_64_eth_init.c LIBS "${ETHDRIVER_LIBS}")
DeclareCAmkESRootserver(lwipserver2_x86_64.camkes CPP_FLAGS ${cpp_define})
elseif(KernelPlatformImx8mm-evk)
DeclareCAmkESRootserver(lwipserver2_imx8mm.camkes CPP_FLAGS ${cpp_define})
else()
message(FATAL_ERROR "Unsupported platform.")
endif()
33 changes: 33 additions & 0 deletions apps/lwipserver2/include/echo/tuning_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

/* Number of buffers used for sending and receiving ethernet frames. */
#define TX_BUFS 510
#define RX_BUFS 510

/* Size used for ethernet buffers */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLease add the note again that this is the next 2^n for the 1500 byte MTU. I assume that this buffer size is independent of the buffer size that ius set it the other PRs, might be good to mention this in the comment also, so it's clear there are not pitfalls in here.

#define BUF_SIZE 2048

/* Maximum connected TCP clients */
#define MAX_TCP_CLIENTS 5

/* Size of initial TCP socket reads */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note why exactly this value is chosen? Is it random or related to TCP headers?

#define TCP_READ_SIZE 1400

/* Max size of UDP socket reads */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, is it random or related to UDP headers?

#define UDP_READ_SIZE 1500

/* DMA memory to use for descriptor rings */
#define DMA_RING_ALLOC_SIZE 0x4000

/* Total DMA memory to allocate = */
#define DMA_ALLOC_SIZE (DMA_RING_ALLOC_SIZE + BUF_SIZE * (TX_BUFS + RX_BUFS))


/* Heap size */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment how the heap is used, so there is a rough explanation what influcenses this?

#define HEAP_SIZE 0x800000
47 changes: 47 additions & 0 deletions apps/lwipserver2/lwip_include/lwipopts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#define NO_SYS 1
#define NO_SYS_NO_TIMERS 0
#define LWIP_TIMERS 1
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
#define LWIP_IGMP 1
#define LWIP_RAND rand
#define LWIP_DHCP 1

#define MEM_ALIGNMENT 4
#define MEM_SIZE 0x40000

#define ETHARP_SUPPORT_STATIC_ENTRIES 1
#define SYS_LIGHTWEIGHT_PROT 0
#define LWIP_NETIF_STATUS_CALLBACK 1

#define TCP_SND_QUEUELEN 2500
#define MEMP_NUM_TCP_SEG TCP_SND_QUEUELEN
#define TCP_SND_BUF (100 * TCP_MSS)
#define TCP_WND (100 * TCP_MSS)
#define LWIP_WND_SCALE 1
#define TCP_RCV_SCALE 10
#define PBUF_POOL_SIZE 1000
#define MEMP_NUM_SYS_TIMEOUT 512

/* Set this to 0 for performance */
#define LWIP_STATS 0

/* Debugging options */
#define LWIP_DEBUG
/* Change this to LWIP_DBG_LEVEL_ALL to see a trace */
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_WARNING

#define ETHARP_DEBUG LWIP_DBG_ON
#define PBUF_DEBUG LWIP_DBG_ON
#define IP_DEBUG LWIP_DBG_ON
#define TCPIP_DEBUG LWIP_DBG_ON
#define DHCP_DEBUG LWIP_DBG_ON
#define UDP_DEBUG LWIP_DBG_ON
120 changes: 120 additions & 0 deletions apps/lwipserver2/lwipserver2_imx8mm.camkes
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*/

import <std_connector.camkes>;
import <global-connectors.camkes>;
import <TimeServer/TimeServer.camkes>;
import <SerialServer/SerialServer.camkes>;

#include <camkes-lwip-ethernet-async.h>
#include <camkes-lwip-base.h>
#include <camkes-fdt-bind-driver.h>
#include <camkes-single-threaded.h>
#include <camkes-SerialServer-camkes-putchar-client.h>
#include <camkes-BenchUtiliz.h>

#include <echo/tuning_params.h>

component FDT_device {
hardware;
emits FDT resource;
}

component LWIPServer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, is there a way to have one common generic CAmkES file with the server that includes the platform specific driver files? So this can be extended to other platforms easily without copy/pasting common things?

single_threaded_component()
lwip_ethernet_async_client_interfaces(eth0)
lwip_base_interfaces(lwip_base)
SerialServer_putchar_printf_client(putchar)
BenchUtiliz_control_interfaces(idle)
}

component EthdriverARMPlatDF {
single_threaded_component()
lwip_ethernet_async_server_interfaces(eth0)
SerialServer_putchar_printf_client(putchar)

attribute int simple = true;
attribute int cnode_size_bits = 12;
attribute int simple_untyped20_pool = 2;
attribute int promiscuous_mode = 1;
attribute int heap_size = 0x10000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here what drives this heap size?

attribute int dma_pool = 0x200000;

consumes FDT EthDriver;
consumes FDT ocotp;
consumes FDT iomux;
consumes FDT ccm;
consumes FDT analog;
consumes FDT gpio1;
fdt_bind_drivers_interfaces(["/ethernet@30be0000"]);

composition {
component FDT_device ether_qos;
connection seL4DTBHWThreadless ethdriver_conn(from ether_qos.resource, to EthDriver);
connection seL4DTBHWThreadless ocotp_conn(from ether_qos.resource, to ocotp);
connection seL4DTBHWThreadless iomux_conn(from ether_qos.resource, to iomux);
connection seL4DTBHWThreadless ccm_conn(from ether_qos.resource, to ccm);
connection seL4DTBHWThreadless analog_conn(from ether_qos.resource, to analog);
connection seL4DTBHWThreadless gpio1_conn(from ether_qos.resource, to gpio1);
fdt_bind_driver_connections();
}

configuration {
EthDriver.dtb = dtb({ "path" : "/ethernet@30be0000" });
EthDriver.generate_interrupts = 1;
ocotp.dtb = dtb({ "path" : "/ocotp-ctrl@30350000" });
iomux.dtb = dtb({ "path" : "/pinctrl@30330000" });
ccm.dtb = dtb({ "path" : "/clock-controller@30380000" });
analog.dtb = dtb({ "path" : "/anatop@30360000" });
gpio1.dtb = dtb({"path" : "/gpio@30200000"});
}
};

assembly {
composition {
component LWIPServer lwipserver;

component EthdriverARMPlatDF ethdriver;

component TimeServer time_server;
component SerialServer serial_server;
component BenchUtiliz bench;

lwip_ethernet_async_connections(eth0, lwipserver, ethdriver)

lwip_base_connections(lwipserver, lwip_base, time_server.the_timer)

connection seL4TimeServer serialserver_timer (from serial_server.timeout, to time_server.the_timer);
SerialServer_processed_putchar_printf_connection(putchar, lwipserver, serial_server)
SerialServer_processed_putchar_printf_connection(putchar, ethdriver, serial_server)

BenchUtiliz_trace_connections(trace, lwipserver, bench)
BenchUtiliz_trace_connections(trace, ethdriver, bench)
BenchUtiliz_control_connections(idle, lwipserver, bench)
}

configuration {
echo._priority = 100;
lwipserver._priority = 100;
ethdriver._priority = 100;

/*
* Non-platform specific configurations
*/
time_server.timers_per_client = 8;

lwip_ethernet_async_configurations(eth0, lwipserver, ethdriver)
lwipserver.heap_size = 0x40000;

BenchUtiliz_trace_configurations(trace, ethdriver, 103)
BenchUtiliz_trace_configurations(trace, lwipserver, 102)

ethdriver.enable_tracing = 1;
lwipserver.enable_tracing = 1;

lwip_base_configuration(lwipserver, lwip_base, "", "0.0.0.0")
}
}
139 changes: 139 additions & 0 deletions apps/lwipserver2/lwipserver2_x86_64.camkes
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*/

import <std_connector.camkes>;
import <global-connectors.camkes>;
import <TimeServer/TimeServer.camkes>;
import <SerialServer/SerialServer.camkes>;

#include <camkes-lwip-ethernet-async.h>
#include <camkes-lwip-base.h>
#include <camkes-fdt-bind-driver.h>
#include <camkes-single-threaded.h>
#include <camkes-dynamic-untyped-allocators.h>
#include <camkes-x86-iospace-dma.h>
#include <camkes-BenchUtiliz.h>
#include <camkes-SerialServer-camkes-putchar-client.h>

#include <echo/tuning_params.h>

component LWIPServer {
include "lwipserver.h";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this include? It causes a lot of compiler errors and removing it seems to fix them.

single_threaded_component()
lwip_ethernet_async_client_interfaces(eth0)
lwip_base_interfaces(lwip_base)
SerialServer_putchar_printf_client(putchar)
BenchUtiliz_control_interfaces(idle)
}

/* Example hardware components that contain minimal necessary spec for different ethdrivers */
component HWEthDriver82574DF {
hardware;
emits IRQ irq;
dataport Buf(0x20000) mmio;
};

component Ethdriver82574DF {
single_threaded_component()
dynamic_untyped_allocators_interfaces(init_dynamic)
x86_iospace_dma_interfaces(init_iospaces, "0x12:0x0:0x19:0")
lwip_ethernet_async_server_interfaces(eth0)
SerialServer_putchar_printf_client(putchar)
/*
* The promiscuous mode is set according to whatever configuration you want, 1 by default.
*/
attribute int promiscuous_mode = 1;

consumes IRQ irq;
dataport Buf(0x20000) EthDriver;

/* MMIO and IRQ default values */
attribute int mmio_paddr = 0xf7f00000;
attribute int mmio_size = 0x20000;
attribute string irq_irq_type = "pci";
attribute int irq_irq_ioapic = 0;
attribute int irq_irq_ioapic_pin = 16;
attribute int irq_irq_vector = 16;

attribute int simple = 1;
attribute int cnode_size_bits = 14;
attribute int simple_untyped20_pool = 2;
attribute int heap_size = 0x40000;
attribute int dma_pool = 0x4000;
attribute int dma_pool_cached = 1;


composition {
component HWEthDriver82574DF hwethdriver;
connection seL4HardwareMMIO ethdrivermmio(from EthDriver, to hwethdriver.mmio);
connection seL4GlobalAsynchHardwareInterrupt hwethirq(from hwethdriver.irq, to irq);
dynamic_untyped_allocators_connections(init_dynamic)
x86_iospace_dma_connections(init_iospaces)
}

configuration {
hwethdriver.mmio_paddr <- mmio_paddr;
hwethdriver.mmio_size <- mmio_size;
hwethdriver.irq_irq_type <- irq_irq_type;
hwethdriver.irq_irq_ioapic <- irq_irq_ioapic;
hwethdriver.irq_irq_ioapic_pin <- irq_irq_ioapic_pin;
hwethdriver.irq_irq_vector <- irq_irq_vector;
dynamic_untyped_allocators_configuration(init_dynamic)
x86_iospace_dma_configuration(init_iospaces)
}
}

assembly {
composition {
/* LWIPServer component */
component LWIPServer lwipserver;

/* Ethdriver component */
component Ethdriver82574DF ethdriver;

/* Timer component */
component TimeServer time_server;
component BenchUtiliz bench;
component SerialServer serial_server;

/*
* Connections
*/

lwip_ethernet_async_connections(eth0, lwipserver, ethdriver)
lwip_base_connections(lwipserver, lwip_base, time_server.the_timer)
connection seL4TimeServer serialserver_timer (from serial_server.timeout, to time_server.the_timer);
SerialServer_processed_putchar_printf_connection(putchar, lwipserver, serial_server)
SerialServer_processed_putchar_printf_connection(putchar, ethdriver, serial_server)

BenchUtiliz_trace_connections(trace, ethdriver, bench)
BenchUtiliz_trace_connections(trace, lwipserver, bench)
BenchUtiliz_control_connections(idle, lwipserver, bench)
}

configuration {
echo._priority = 100;
lwipserver._priority = 100;
ethdriver._priority = 100;

lwip_ethernet_async_configurations(eth0, lwipserver, ethdriver)

BenchUtiliz_trace_configurations(trace, ethdriver, 103)
BenchUtiliz_trace_configurations(trace, lwipserver, 102)

lwipserver.enable_tracing = 1;
ethdriver.enable_tracing = 1;

time_server.timers_per_client = 8;

/*
* LWIPServer config
*/
/* IP and multicast address to assign to the networking device */
lwip_base_configuration(lwipserver, lwip_base, "", "0.0.0.0")
lwipserver.heap_size = 0x40000;
}
}
Loading