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

cpu/native: use async read for stdio_read() #19002

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion cpu/native/async_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ void native_async_read_cleanup(void) {
unregister_interrupt(SIGIO);

for (int i = 0; i < _next_index; i++) {
real_close(_fds[i].fd);
/* don't close stdin */
benpicco marked this conversation as resolved.
Show resolved Hide resolved
if (_fds[i].fd != STDIN_FILENO) {
real_close(_fds[i].fd);
}
if (pollers[i].child_pid) {
kill(pollers[i].child_pid, SIGKILL);
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/native/include/async_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
* @brief Maximum number of file descriptors
*/
#ifndef ASYNC_READ_NUMOF
#define ASYNC_READ_NUMOF 2
#define ASYNC_READ_NUMOF 8
benpicco marked this conversation as resolved.
Show resolved Hide resolved
#endif

/**
Expand Down
5 changes: 3 additions & 2 deletions cpu/native/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
typedef void (*init_func_t)(int argc, char **argv, char **envp);
#ifdef __APPLE__
/* Taken from the sources of Apple's dyld launcher
* https://github.com/opensource-apple/dyld/blob/3f928f32597888c5eac6003b9199d972d49857b5/src/dyldInitialization.cpp#L85-L104

Check warning on line 449 in cpu/native/startup.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
*/
/* Find the extents of the __DATA __mod_init_func section */
extern init_func_t __init_array_start __asm("section$start$__DATA$__mod_init_func");
Expand All @@ -465,8 +465,6 @@
__attribute__((constructor)) static void startup(int argc, char **argv, char **envp)
{
_native_init_syscalls();
/* initialize stdio as early as possible */
early_init();

_native_argv = argv;
_progname = argv[0];
Expand Down Expand Up @@ -682,6 +680,9 @@

register_interrupt(SIGUSR1, _reset_handler);

/* initialize stdio after signal setup */
early_init();

puts("RIOT native hardware initialization complete.\n");
irq_enable();
kernel_init();
Expand Down
25 changes: 20 additions & 5 deletions cpu/native/stdio_native/stdio_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,40 @@
*
* @file
* @author Martine S. Lenders <[email protected]>
* @author Benjamin Valentin <[email protected]>
*/

#include "async_read.h"
#include "kernel_defines.h"
#include "native_internal.h"

#include "stdio_base.h"

void stdio_init(void)
{
static void _async_read_wrapper(int fd, void *arg) {
uint8_t buf[1];

int res = real_read(fd, &buf, sizeof(buf));
if (res > 0) {
isrpipe_write(arg, buf, res);
}

native_async_read_continue(fd);
}

ssize_t stdio_read(void* buffer, size_t max_len)
static void _init(void)
{
return real_read(STDIN_FILENO, buffer, max_len);
native_async_read_setup();
if (IS_USED(MODULE_STDIN)) {
native_async_read_add_int_handler(STDIN_FILENO, &stdin_isrpipe,
_async_read_wrapper);
}
}

ssize_t stdio_write(const void* buffer, size_t len)
static ssize_t _write(const void* buffer, size_t len)
{
return real_write(STDOUT_FILENO, buffer, len);
}

STDIO_PROVIDER(STDIO_NATIVE, _init, NULL, _write)

/** @} */
2 changes: 1 addition & 1 deletion cpu/native/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ ssize_t _native_read(int fd, void *buf, size_t count)
{
ssize_t r;

if (fd == STDIN_FILENO) {
if (fd == STDIN_FILENO && IS_USED(MODULE_STDIN)) {
return stdio_read(buf, count);
}

Expand Down
1 change: 0 additions & 1 deletion examples/gnrc_border_router/Makefile.native.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ZEP_PORT_BASE ?= 17754
ZEP_PORT_MAX := $(shell expr $(ZEP_PORT_BASE) + $(ZEP_DEVICES) - 1)

CFLAGS += -DSOCKET_ZEP_MAX=$(ZEP_DEVICES)
CFLAGS += -DASYNC_READ_NUMOF=$(shell expr $(ZEP_DEVICES) + 1)
CFLAGS += -DCONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX=$(ZEP_DEVICES)

# Set CFLAGS if not being set via Kconfig
Expand Down
7 changes: 7 additions & 0 deletions examples/telnet_server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ USEMODULE += ps
# Include the telnet server
USEMODULE += stdio_telnet

# select a 2nd stdio method
ifeq (,$(filter native%,$(BOARD)))
USEMODULE += stdio_uart
else
USEMODULE += stdio_native
endif

# Enable faster re-connects
CFLAGS += -DCONFIG_GNRC_TCP_EXPERIMENTAL_DYN_MSL_EN=1

Expand Down
1 change: 0 additions & 1 deletion examples/telnet_server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ int main(void)

/* start shell */
printf("All up, awaiting connection on port %u\n", CONFIG_TELNET_PORT);
puts("Local shell disabled");
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);

Expand Down
1 change: 0 additions & 1 deletion makefiles/stdio.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ STDIO_MODULES = \
STDIO_LEGACY_MODULES = \
ethos_stdio \
stdio_ethos \
stdio_native # requires #19002 \
#

# select stdio_uart if no other stdio module is slected
Expand Down
37 changes: 37 additions & 0 deletions pkg/ubasic/patches/0002-avoid-use-of-floating-point-math.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
From 5a492cf6ba56d2d16cfeaa18b6d1f0cb21429640 Mon Sep 17 00:00:00 2001
From: Benjamin Valentin <[email protected]>
Date: Mon, 12 Jun 2023 16:23:01 +0200
Subject: [PATCH] avoid use of floating point math

---
tests.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests.c b/tests.c
index a7bab89..77be22f 100644
--- a/tests.c
+++ b/tests.c
@@ -93,7 +93,7 @@ void run(const char program[]) {
fflush(stdout);

clock_t start_t, end_t;
- double delta_t;
+ unsigned delta_t;

start_t = clock();

@@ -104,9 +104,9 @@ void run(const char program[]) {
} while(!ubasic_finished());

end_t = clock();
- delta_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
+ delta_t = (1000UL * (end_t - start_t)) / CLOCKS_PER_SEC;

- printf("done. Run time: %.3f s\n", delta_t);
+ printf("done. Run time: %u ms\n", delta_t);
}

/*---------------------------------------------------------------------------*/
--
2.39.2

2 changes: 1 addition & 1 deletion sys/Kconfig.stdio
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ config MODULE_SLIPDEV_STDIO
bool "SLIP network device"
depends on MODULE_SLIPDEV
select USE_STDOUT_BUFFERED
select MODULE_ISRPIPE

config MODULE_STDIO_NULL
bool "Null"
Expand All @@ -59,6 +58,7 @@ config MODULE_STDIO_UART_ONLCR
config MODULE_STDIO_NATIVE
bool "Native"
depends on CPU_ARCH_NATIVE
select MODULE_ISRPIPE

config MODULE_STDIO_ETHOS
bool "ETHOS"
Expand Down
2 changes: 1 addition & 1 deletion sys/include/net/telnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int telnet_server_start(void);
*
* @return 0 on success, error otherwise
*/
int telnet_server_write(const void* buffer, size_t len);
ssize_t telnet_server_write(const void* buffer, size_t len);

/**
* @brief Read data from the telnet client, will block until data is available.
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/telnet/telnet_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static void *telnet_thread(void *arg)
return NULL;
}

int telnet_server_write(const void* buffer, size_t len)
ssize_t telnet_server_write(const void* buffer, size_t len)
{
if (connected) {
int res = _write_buffer(buffer, len);
Expand Down
1 change: 1 addition & 0 deletions tests/pkg/libfixmath_unittests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include ../Makefile.pkg_common
USEMODULE += libfixmath-unittests

ifneq (,$(filter native native64,$(BOARD)))
DISABLE_MODULE += test_utils_interactive_sync
LINKFLAGS += -lm
endif

Expand Down
2 changes: 1 addition & 1 deletion tests/pkg/ubasic/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def testfunc(child):
for i in range(1, 6):
child.expect(r"Running test #%d... done. Run time: \d+.\d{3} s" % i,
child.expect(r"Running test #%d... done. Run time: \d+ ms" % i,
timeout=TIMEOUT)


Expand Down
2 changes: 2 additions & 0 deletions tests/pkg/wolfssl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ USEMODULE += xtimer

ifeq (,$(filter native native64,$(BOARD)))
CFLAGS += -DBENCH_EMBEDDED
else
DISABLE_MODULE += test_utils_interactive_sync
endif

TEST_ON_CI_WHITELIST += native native64
Expand Down
4 changes: 0 additions & 4 deletions tests/pkg/wolfssl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
int main(void)
{
LOG_INFO("wolfSSL Crypto Test!\n");
/* Wait to work around a failing tests
* on platforms that don't have RTC synchronized
*/
xtimer_sleep(1);
wolfcrypt_test(NULL);
#ifdef MODULE_WOLFCRYPT_BENCHMARK
LOG_INFO("wolfSSL Benchmark!\n");
Expand Down
12 changes: 0 additions & 12 deletions tests/sys/shell/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,6 @@ def check_line_canceling(child):
assert garbage_expected == garbage_received


def check_erase_long_line(child, longline):
# FIXME: this only works on native, due to #10634 combined with socat
# insisting in line-buffering the terminal.

if BOARD in ['native', 'native64']:
longline_erased = longline + "\b"*len(longline) + "echo"
child.sendline(longline_erased)
child.expect_exact('"echo"')


def check_control_d(child):
# The current shell instance was initiated by shell_run_once(). The shell will exit.
child.sendline(CONTROL_D)
Expand Down Expand Up @@ -220,8 +210,6 @@ def testfunc(child):
else:
print("skipping check_line_canceling()")

check_erase_long_line(child, longline)

check_control_d(child)

# loop other defined commands and expected output
Expand Down
Loading