Skip to content

Commit

Permalink
pre-PR fixes
Browse files Browse the repository at this point in the history
Signed-off-by: alwin-joshy <[email protected]>
  • Loading branch information
alwin-joshy committed Oct 24, 2024
1 parent 4eaaf8c commit a7ef406
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 46 deletions.
4 changes: 2 additions & 2 deletions drivers/network/virtio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ CFLAGS := \

all: $(BUILD_DIR)/ethernet.o

$(BUILD_DIR)/ethernet.o: ethernet.c. microkit_ethernet.c ethernet.h
$(CC) -c $(CFLAGS) ethernet.c microkit_ethernet.c -o $(BUILD_DIR)/ethernet.o
$(BUILD_DIR)/ethernet.o: ethernet.c. ethernet.h
$(CC) -c $(CFLAGS) ethernet.c -o $(BUILD_DIR)/ethernet.o

.PHONY: clean
clean:
Expand Down
1 change: 1 addition & 0 deletions drivers/network/virtio/ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ static void eth_setup(void)
/* By the time we get to here, 'resources' should be valid */
void sddf_init(void)
{
// TODO: Should this just be passed in at the right offset?
regs = (volatile virtio_mmio_regs_t *)(resources.regs + VIRTIO_MMIO_NET_OFFSET);

ialloc_init(&rx_ialloc_desc, rx_descriptors, RX_COUNT);
Expand Down
2 changes: 0 additions & 2 deletions drivers/network/virtio/ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <stdint.h>
#include <sddf/util/printf.h>
#include <sddf/network/queue.h>
#include <sddf/virtio/virtio.h>
#include <sddf/virtio/virtio_queue.h>

// #define DEBUG_DRIVER

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@

<map mr="net_rx_free_copy0" vaddr="0x2_400_000" perms="rw" cached="true" setvar_vaddr="rx_free_cli0" />
<map mr="net_rx_active_copy0" vaddr="0x2_600_000" perms="rw" cached="true" setvar_vaddr="rx_active_cli0" />
<map mr="net_rx_free_copy1" vaddr="0x2_800_000" perms="rw" cached="true" setvar_vaddr="rx_free_cli1"/>
<map mr="net_rx_active_copy1" vaddr="0x2_a00_000" perms="rw" cached="true" setvar_vaddr="rx_active_cli1"/>
<map mr="net_rx_free_copy1" vaddr="0x2_800_000" perms="rw" cached="true"/>
<map mr="net_rx_active_copy1" vaddr="0x2_a00_000" perms="rw" cached="true"/>

<map mr="net_rx_buffer_data_region" vaddr="0x2_c00_000" perms="r" cached="true" setvar_vaddr="buffer_data_vaddr" />
<setvar symbol="buffer_data_paddr" region_paddr="net_rx_buffer_data_region" />
Expand Down Expand Up @@ -153,8 +153,8 @@

<map mr="net_tx_free_cli0" vaddr="0x2_400_000" perms="rw" cached="true" setvar_vaddr="tx_free_cli0" />
<map mr="net_tx_active_cli0" vaddr="0x2_600_000" perms="rw" cached="true" setvar_vaddr="tx_active_cli0" />
<map mr="net_tx_free_cli1" vaddr="0x2_800_000" perms="rw" cached="true" setvar_vaddr="tx_free_cli1"/>
<map mr="net_tx_active_cli1" vaddr="0x2_a00_000" perms="rw" cached="true" setvar_vaddr="tx_active_cli1"/>
<map mr="net_tx_free_cli1" vaddr="0x2_800_000" perms="rw" cached="true"/>
<map mr="net_tx_active_cli1" vaddr="0x2_a00_000" perms="rw" cached="true"/>

<map mr="net_tx_buffer_data_region_cli0" vaddr="0x2_c00_000" perms="r" cached="true" setvar_vaddr="buffer_data_region_cli0_vaddr" />
<map mr="net_tx_buffer_data_region_cli1" vaddr="0x2_e00_000" perms="r" cached="true" setvar_vaddr="buffer_data_region_cli1_vaddr" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <sddf/util/util.h>

#define NUM_NETWORK_CLIENTS 2
// #define NUM_NETWORK_CLIENTS 1

#define NET_CLI0_NAME "client0"
#define NET_CLI1_NAME "client1"
Expand Down
1 change: 0 additions & 1 deletion examples/echo_server/include/lwip/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#pragma once

// #include <stdlib.h>
#include <stdbool.h>
#include <sddf/network/constants.h>

Expand Down
11 changes: 6 additions & 5 deletions examples/echo_server/lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <sddf/timer/protocol.h>
// #include <sddf/benchmark/sel4bench.h>
// #include <serial_config.h>
// #include <ethernet_config.h>
#include <sddf/timer/client.h>
#include <sddf/network/util.h>
#include <sddf/util/string.h>
Expand Down Expand Up @@ -275,8 +274,8 @@ static void netif_status_callback(struct netif *netif)

void sddf_init(void)
{
serial_cli_queue_init_sys(microkit_name, NULL, NULL, NULL, &serial_tx_queue_handle, serial_tx_queue, serial_tx_data);
serial_putchar_init(SERIAL_TX_CH, &serial_tx_queue_handle);
// serial_cli_queue_init_sys(microkit_name, NULL, NULL, NULL, &serial_tx_queue_handle, serial_tx_queue, serial_tx_data);
// serial_putchar_init(SERIAL_TX_CH, &serial_tx_queue_handle);

net_queue_init(&state.rx_queue, resources.rx_free, resources.rx_active, resources.rx_queue_size);
net_queue_init(&state.tx_queue, resources.tx_free, resources.tx_active, resources.tx_queue_size);
Expand Down Expand Up @@ -313,8 +312,10 @@ void sddf_init(void)
}

setup_udp_socket();
// setup_utilization_socket();
// setup_tcp_socket();
#ifdef MICROKIT
setup_utilization_socket();
#endif /* MICROKIT */
setup_tcp_socket();

if (notify_rx && net_require_signal_free(&state.rx_queue)) {
net_cancel_signal_free(&state.rx_queue);
Expand Down
3 changes: 2 additions & 1 deletion examples/echo_server/lwip.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void init() {

#else

#define NET_MAX_CLIENT_QUEUE_SIZE 512 //@alwin: What to do about this?
// TODO: THIS IS BAD, but what is the max size/can we implement the lwip.c differently?
#define NET_MAX_CLIENT_QUEUE_CAPACITY 512 //@alwin: What to do about this?

#endif /* MICROKIT */
1 change: 0 additions & 1 deletion examples/echo_server/tcp_echo_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

#include <string.h>
#include <microkit.h>

#include "echo.h"
#include "lwip/ip.h"
Expand Down
2 changes: 0 additions & 2 deletions examples/echo_server/udp_echo_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

// #include <microkit.h>

#include "lwip/ip.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
Expand Down
4 changes: 2 additions & 2 deletions include/sddf/timer/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
static inline void sddf_timer_set_timeout(unsigned int id, uint64_t timeout)
{
// sddf_set_mr(0, timeout);
sddf_set_mr(0, timeout);
sddf_ppcall(id, seL4_MessageInfo_new(SDDF_TIMER_SET_TIMEOUT, 0, 0, 1));
}

Expand All @@ -28,6 +28,6 @@ static inline void sddf_timer_set_timeout(unsigned int id, uint64_t timeout)
static inline uint64_t sddf_timer_time_now(unsigned int id)
{
sddf_ppcall(id, seL4_MessageInfo_new(SDDF_TIMER_GET_TIME, 0, 0, 0));
uint64_t time_now = 0;//sddf_get_mr(0);
uint64_t time_now = sddf_get_mr(0);
return time_now;
}
1 change: 0 additions & 1 deletion include/sddf/util/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

#pragma once

// #include <microkit.h>
#include <sel4/sel4.h>
#include <sddf/serial/queue.h>

Expand Down
1 change: 0 additions & 1 deletion include/sddf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#pragma once

#include <stddef.h>
// #include <microkit.h>

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
Expand Down
4 changes: 2 additions & 2 deletions include/sys/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

extern void sddf_irq_ack(unsigned int id);
extern void sddf_notify(unsigned int id);
extern void sddf_notify_delayed(unsigned int id);
extern void sddf_deferred_notify(unsigned int id);
extern seL4_MessageInfo_t sddf_ppcall(unsigned int id, seL4_MessageInfo_t msginfo);
extern uint64_t sddf_get_mr(unsigned int n);
extern void sddf_set_mr(unsigned int n, uint64_t val);
inline unsigned int sddf_notify_delayed_curr();
inline unsigned int sddf_deferred_notify_curr();
2 changes: 1 addition & 1 deletion network/components/copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ void init() {
sddf_init();
}

#endif /* MICROKIT */
#endif /* MICROKIT */
20 changes: 10 additions & 10 deletions network/components/virt_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/* Used to signify that a packet has come in for the broadcast address and does not match with
* any particular client. */
#define BROADCAST_ID (NUM_NETWORK_CLIENTS + 1)
#define BROADCAST_ID (MAX_CLIENTS + 1)

/* In order to handle broadcast packets where the same buffer is given to multiple clients
* we keep track of a reference count of each buffer and only hand it back to the driver once
Expand All @@ -24,8 +24,8 @@ uint32_t buffer_refs[NET_RX_QUEUE_CAPACITY_DRIV] = { 0 };

typedef struct state {
net_queue_handle_t rx_queue_drv;
net_queue_handle_t rx_queue_clients[NUM_NETWORK_CLIENTS];
uint8_t mac_addrs[NUM_NETWORK_CLIENTS][ETH_HWADDR_LEN];
net_queue_handle_t rx_queue_clients[MAX_CLIENTS];
uint8_t mac_addrs[MAX_CLIENTS][ETH_HWADDR_LEN];
} state_t;

state_t state;
Expand All @@ -37,7 +37,7 @@ static bool notify_drv;
is a broadcast address. */
int get_mac_addr_match(struct ethernet_header *buffer)
{
for (int client = 0; client < NUM_NETWORK_CLIENTS; client++) {
for (int client = 0; client < resources.num_network_clients; client++) {
bool match = true;
for (int i = 0; (i < ETH_HWADDR_LEN) && match; i++) {
if (buffer->dest.addr[i] != state.mac_addrs[client][i]) {
Expand Down Expand Up @@ -65,7 +65,7 @@ int get_mac_addr_match(struct ethernet_header *buffer)
void rx_return(void)
{
bool reprocess = true;
bool notify_clients[NUM_NETWORK_CLIENTS] = {false};
bool notify_clients[MAX_CLIENTS] = {false};
while (reprocess) {
while (!net_queue_empty_active(&state.rx_queue_drv)) {
net_buff_desc_t buffer;
Expand All @@ -92,9 +92,9 @@ void rx_return(void)
// For broadcast packets, set the refcount to number of clients
// in the system. Only enqueue buffer back to driver if
// all clients have consumed the buffer.
buffer_refs[ref_index] = NUM_NETWORK_CLIENTS;
buffer_refs[ref_index] = resources.num_network_clients;

for (int i = 0; i < NUM_NETWORK_CLIENTS; i++) {
for (int i = 0; i < resources.num_network_clients; i++) {
err = net_enqueue_active(&state.rx_queue_clients[i], buffer);
assert(!err);
notify_clients[i] = true;
Expand Down Expand Up @@ -124,7 +124,7 @@ void rx_return(void)
}
}

for (int client = 0; client < NUM_NETWORK_CLIENTS; client++) {
for (int client = 0; client < resources.num_network_clients; client++) {
if (notify_clients[client] && net_require_signal_active(&state.rx_queue_clients[client])) {
net_cancel_signal_active(&state.rx_queue_clients[client]);
sddf_notify(resources.clients[client].client_id);
Expand All @@ -134,7 +134,7 @@ void rx_return(void)

void rx_provide(void)
{
for (int client = 0; client < NUM_NETWORK_CLIENTS; client++) {
for (int client = 0; client < resources.num_network_clients; client++) {
bool reprocess = true;
while (reprocess) {
while (!net_queue_empty_free(&state.rx_queue_clients[client])) {
Expand Down Expand Up @@ -189,7 +189,7 @@ void sddf_notified(unsigned int id)
void sddf_init(void)
{
/* Set up client queues */
for (int i = 0; i < NUM_NETWORK_CLIENTS; i++) {
for (int i = 0; i < resources.num_network_clients; i++) {
net_set_mac_addr((uint8_t *) &state.mac_addrs[i], resources.clients[i].mac_addr);
net_queue_init(&state.rx_queue_clients[i], resources.clients[i].rx_free, resources.clients[i].rx_active, resources.clients[i].queue_capacity);
}
Expand Down
7 changes: 5 additions & 2 deletions network/components/virt_rx.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ net_queue_t *rx_free_drv;
net_queue_t *rx_active_drv;
net_queue_t *rx_free_cli0;
net_queue_t *rx_active_cli0;
net_queue_t *rx_free_cli1;
net_queue_t *rx_active_cli1;

/* Buffer data regions */
uintptr_t buffer_data_vaddr;
Expand Down Expand Up @@ -85,4 +83,9 @@ void init() {
sddf_init();
}

#else

// TODO: THIS IS BAD, but what is the max size/can we implement the virt_rx differently?
#define NET_RX_QUEUE_CAPACITY_DRIV 512

#endif /* MICROKIT */
14 changes: 7 additions & 7 deletions network/components/virt_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

typedef struct state {
net_queue_handle_t tx_queue_drv;
net_queue_handle_t tx_queue_clients[NUM_NETWORK_CLIENTS];
uintptr_t buffer_region_vaddrs[NUM_NETWORK_CLIENTS];
uintptr_t buffer_region_paddrs[NUM_NETWORK_CLIENTS];
net_queue_handle_t tx_queue_clients[MAX_CLIENTS];
uintptr_t buffer_region_vaddrs[MAX_CLIENTS];
uintptr_t buffer_region_paddrs[MAX_CLIENTS];
} state_t;

state_t state;

int extract_offset(uintptr_t *phys)
{
for (int client = 0; client < NUM_NETWORK_CLIENTS; client++) {
for (int client = 0; client < resources.num_network_clients; client++) {
if (*phys >= state.buffer_region_paddrs[client]
&& *phys < state.buffer_region_paddrs[client] + state.tx_queue_clients[client].capacity * NET_BUFFER_SIZE) {
*phys = *phys - state.buffer_region_paddrs[client];
Expand All @@ -32,7 +32,7 @@ int extract_offset(uintptr_t *phys)
void tx_provide(void)
{
bool enqueued = false;
for (int client = 0; client < NUM_NETWORK_CLIENTS; client++) {
for (int client = 0; client < resources.num_network_clients; client++) {
bool reprocess = true;
while (reprocess) {
while (!net_queue_empty_active(&state.tx_queue_clients[client])) {
Expand Down Expand Up @@ -77,7 +77,7 @@ void tx_provide(void)
void tx_return(void)
{
bool reprocess = true;
bool notify_clients[NUM_NETWORK_CLIENTS] = {false};
bool notify_clients[MAX_CLIENTS] = {false};
while (reprocess) {
while (!net_queue_empty_free(&state.tx_queue_drv)) {
net_buff_desc_t buffer;
Expand All @@ -101,7 +101,7 @@ void tx_return(void)
}
}

for (int client = 0; client < NUM_NETWORK_CLIENTS; client++) {
for (int client = 0; client < resources.num_network_clients; client++) {
if (notify_clients[client] && net_require_signal_free(&state.tx_queue_clients[client])) {
net_cancel_signal_free(&state.tx_queue_clients[client]);
sddf_notify(resources.clients[client].client_id);
Expand Down
3 changes: 2 additions & 1 deletion network/components/virt_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ net_queue_t *tx_active_cli1;

uintptr_t buffer_data_region_cli0_vaddr;
uintptr_t buffer_data_region_cli0_paddr;
uintptr_t buffer_data_region_cli1_vaddr;
uintptr_t buffer_data_region_cli1_paddr;

void init() {
Expand Down Expand Up @@ -78,7 +77,9 @@ void init() {
}

resources.clients[0].buffer_data_region_paddr = buffer_data_region_cli0_paddr;
#ifdef NUM_NETWORK_CLIENTS > 1
resources.clients[1].buffer_data_region_paddr = buffer_data_region_cli1_paddr;
#endif /* NUM_NETWORK_CLIENTS > 1 */

sddf_init();
}
Expand Down

0 comments on commit a7ef406

Please sign in to comment.