[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT/LIBMICROPYTHON PATCH v3 4/6] Add patches.


  • To: "minios-devel@xxxxxxxxxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Wed, 9 Oct 2019 12:17:16 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0Eq8CW2I+WK5WxE2nLC5+YCMmXUrp15gFuLwrkyjOWQ=; b=elzLIgCzUKWX8tKrrCVethg6N/2YF3Evpt8FCdytdXYDk636yPXXbkFGVFrHfTJpwBI7BUU4kDoh/lS5Z+erjFiBqEVdwFOJeZqioCNDv8VobMPIMELQU0GOoUp+730vrY29ofNzQ0PdmBtjOg/Hy8mWoPrtFhLX3S+o24diQcw2+NbrsMP0+1x/qtzpsann32hGJjQ4003aq+B3VGYpUWAK9k9pzrpx4dI+Pq22KEisfrQlD7cfzW2OeHK/NPnR5YEEApEdCp6qRBRgXQSn2lHqNMgAn5NHDClcCzr3jjmwmTotP/1GFQS6qRpAgOnv6ui+gTXC5dGDCGWwTcmAHQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FhxP75R/mXaZogxGWCZ6UOKfeE1I0tv7sPjq3OlJM+XFYV5jMn8gg62z3BC2mqMnDfiT1qpJktxCk3rwjX+muouQ392mjNiU0woh1+ui6B+MNHP1zfgLiLaX/+BtOzJN3WzXPwgt9IClTmWO3+sx2kCn1m4Qk6qHQt3uBNtADda2feVLN3cXf2uBU84CyjnrxFZ5NhRYm8Xe6cfhlm6B4BDU4zSZokATnke9wN+7QKkVhouGtwj31ChBdJjVdBOxATsXjO8XfFugBPfAtYANbeg2idHVZl1GjcYp0TZND74mvcSsKxvRLN/l1c/Q5CAjGx9fZr0WMg4hgypw14dWlA==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Delivery-date: Wed, 09 Oct 2019 12:17:23 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVfnFDWW3dBX66/kW3O9iSf4QV0KdSOhaA
  • Thread-topic: [Minios-devel] [UNIKRAFT/LIBMICROPYTHON PATCH v3 4/6] Add patches.

Hey Felipe,

Please see one comment inline.

Reviewed-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>

On 09.10.2019 10:14, Felipe Huici wrote:
> Add patches to fix compilation errors and to adapt unix/main.c and
> modlwip.c to Unikraft.
>
> Signed-off-by: Felipe Huici <felipe.huici@xxxxxxxxx>
> ---
>   patches/0001-missing-board-defines.patch      |  11 +
>   patches/0002-clearup-nlrpush-frame.patch      |  10 +
>   ...compile-guard-gc-function-unix-alloc.patch |  16 ++
>   patches/0004-adapt-main-c-to-unikraft.patch   |  46 ++++
>   patches/0005-adapt-modlwip-to-unikraft.patch  | 242 ++++++++++++++++++
>   5 files changed, 325 insertions(+)
>   create mode 100644 patches/0001-missing-board-defines.patch
>   create mode 100644 patches/0002-clearup-nlrpush-frame.patch
>   create mode 100644 patches/0003-compile-guard-gc-function-unix-alloc.patch
>   create mode 100644 patches/0004-adapt-main-c-to-unikraft.patch
>   create mode 100644 patches/0005-adapt-modlwip-to-unikraft.patch
>
> diff --git a/patches/0001-missing-board-defines.patch 
> b/patches/0001-missing-board-defines.patch
> new file mode 100644
> index 0000000..22a7313
> --- /dev/null
> +++ b/patches/0001-missing-board-defines.patch
> @@ -0,0 +1,11 @@
> +--- a/unix/mpconfigport.h.orig       2017-11-18 08:43:56.096441368 +0100
> ++++ b/unix/mpconfigport.h    2017-11-18 08:42:05.225463413 +0100
> +@@ -25,6 +25,8 @@
> +  */
> +
> + // options to control how MicroPython is built
> ++#define MICROPY_HW_BOARD_NAME "unix"
> ++#define MICROPY_HW_MCU_NAME "unknown-cpu"
> +
> + #define MICROPY_ALLOC_PATH_MAX      (PATH_MAX)
> + #define MICROPY_PERSISTENT_CODE_LOAD (1)
> diff --git a/patches/0002-clearup-nlrpush-frame.patch 
> b/patches/0002-clearup-nlrpush-frame.patch
> new file mode 100644
> index 0000000..44b5849
> --- /dev/null
> +++ b/patches/0002-clearup-nlrpush-frame.patch
> @@ -0,0 +1,10 @@
> +--- a/py/nlrx64.c.orig       2017-08-23 11:50:10.000000000 +0200
> ++++ b/py/nlrx64.c    2017-11-21 14:44:45.513728670 +0100
> +@@ -64,6 +64,7 @@
> +     #if defined(__APPLE__) || defined(__MACH__)
> +     "pop    %rbp                \n" // undo function's prelude
> +     #endif
> ++    "leaveq                     \n" // clean up our frame
> +     "movq   (%rsp), %rax        \n" // load return %rip
> +     "movq   %rax, 16(%rdi)      \n" // store %rip into nlr_buf
> +     "movq   %rbp, 24(%rdi)      \n" // store %rbp into nlr_buf
> diff --git a/patches/0003-compile-guard-gc-function-unix-alloc.patch 
> b/patches/0003-compile-guard-gc-function-unix-alloc.patch
> new file mode 100644
> index 0000000..6863e68
> --- /dev/null
> +++ b/patches/0003-compile-guard-gc-function-unix-alloc.patch
> @@ -0,0 +1,16 @@
> +--- a/unix/alloc.c   2019-10-02 11:16:25.154625696 +0200
> ++++ b/unix/alloc.c   2019-10-02 11:16:47.878383872 +0200
> +@@ -79,11 +79,13 @@
> +     }
> + }
> +
> ++#if MICROPY_ENABLE_GC
> + void mp_unix_mark_exec(void) {
> +     for (mmap_region_t *rg = MP_STATE_VM(mmap_region_head); rg != NULL; rg 
> = rg->next) {
> +         gc_collect_root(rg->ptr, rg->len / sizeof(mp_uint_t));
> +     }
> + }
> ++#endif

Currently enabling the GC is not viable. In the future we should have a 
config option to toggle the GC.

> +
> + #if MICROPY_FORCE_PLAT_ALLOC_EXEC
> + // Provide implementation of libffi ffi_closure_* functions in terms
> diff --git a/patches/0004-adapt-main-c-to-unikraft.patch 
> b/patches/0004-adapt-main-c-to-unikraft.patch
> new file mode 100644
> index 0000000..d924d58
> --- /dev/null
> +++ b/patches/0004-adapt-main-c-to-unikraft.patch
> @@ -0,0 +1,46 @@
> +--- a/unix/main.c    2017-08-23 03:50:11.000000000 +0200
> ++++ b/unix/main.c    2019-10-07 20:47:18.419884044 +0200
> +@@ -51,6 +51,8 @@
> + #include "genhdr/mpversion.h"
> + #include "input.h"
> +
> ++#include <uk/plat/memory.h>
> ++
> + // Command line options, with their defaults
> + STATIC bool compile_only = false;
> + STATIC uint emit_opt = MP_EMIT_OPT_NONE;
> +@@ -614,14 +616,26 @@
> +         }
> +     }
> +
> +-    if (ret == NOTHING_EXECUTED || inspect) {
> +-        if (isatty(0)) {
> +-            prompt_read_history();
> +-            ret = do_repl();
> +-            prompt_write_history();
> +-        } else {
> +-            ret = execute_from_lexer(LEX_SRC_STDIN, NULL, 
> MP_PARSE_FILE_INPUT, false);
> +-        }
> ++    /* see if script is available from initrd */
> ++    struct ukplat_memregion_desc img;
> ++    char *cstr;
> ++    if (ukplat_memregion_find_initrd0(&img) >= 0) {
> ++      cstr = (char *)img.base;
> ++      ret = do_str(cstr);
> ++    }
> ++    /* repl mode */
> ++    else {
> ++      #if MICROPY_REPL_EVENT_DRIVEN
> ++      pyexec_event_repl_init();
> ++      for (;;) {
> ++    int c = mp_hal_stdin_rx_chr();
> ++    if (pyexec_event_repl_process_char(c)) {
> ++      break;
> ++    }
> ++      }
> ++      #else
> ++      pyexec_friendly_repl();
> ++      #endif
> +     }
> +
> +     #if MICROPY_PY_MICROPYTHON_MEM_INFO
> diff --git a/patches/0005-adapt-modlwip-to-unikraft.patch 
> b/patches/0005-adapt-modlwip-to-unikraft.patch
> new file mode 100644
> index 0000000..f1f99e2
> --- /dev/null
> +++ b/patches/0005-adapt-modlwip-to-unikraft.patch
> @@ -0,0 +1,242 @@
> +--- a/extmod/modlwip.c       2017-08-23 03:50:08.000000000 +0200
> ++++ b/extmod/modlwip.c       2019-10-08 09:30:52.025714373 +0200
> +@@ -29,6 +29,16 @@
> + #include <string.h>
> + #include <stdio.h>
> +
> ++#include <uk/print.h>
> ++#include <netif/uknetdev.h>
> ++
> ++#include "lwip/init.h"
> ++#include "lwip/timeouts.h"
> ++#include "lwip/tcp.h"
> ++#include "lwip/udp.h"
> ++#include "lwip/dns.h"
> ++#include "lwip/igmp.h"
> ++
> + #include "py/nlr.h"
> + #include "py/objlist.h"
> + #include "py/runtime.h"
> +@@ -38,20 +48,7 @@
> +
> + #include "lib/netutils/netutils.h"
> +
> +-#include "lwip/init.h"
> +-#include "lwip/timers.h"
> +-#include "lwip/tcp.h"
> +-#include "lwip/udp.h"
> +-//#include "lwip/raw.h"
> +-#include "lwip/dns.h"
> +-#include "lwip/tcp_impl.h"
> +-#include "lwip/igmp.h"
> +-
> +-#if 0 // print debugging info
> +-#define DEBUG_printf DEBUG_printf
> +-#else // don't print debugging info
> +-#define DEBUG_printf(...) (void)0
> +-#endif
> ++#define DEBUG_printf uk_pr_debug
> +
> + // All socket options should be globally distinct,
> + // because we ignore option levels for efficiency.
> +@@ -264,6 +261,11 @@
> + #else
> +     mp_hal_delay_ms(1);
> + #endif
> ++
> ++    /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
> ++    uknetdev_poll_all();
> ++    sys_check_timeouts();
> ++    /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
> + }
> +
> + 
> /*******************************************************************************/
> +@@ -305,6 +307,7 @@
> +     lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
> +
> +     socket->state = STATE_CONNECTED;
> ++    DEBUG_printf("Socket %p connected\n", socket);
> +     return ERR_OK;
> + }
> +
> +@@ -346,6 +349,7 @@
> +             // is idle.
> +             tcp_poll(newpcb, _lwip_tcp_accept_finished, 1);
> +         }
> ++    DEBUG_printf("Accepted new connection on socket %p\n", socket);
> +         return ERR_OK;
> +     }
> + }
> +@@ -498,6 +502,7 @@
> +     u16_t write_len = MIN(available, len);
> +
> +     err_t err = tcp_write(socket->pcb.tcp, buf, write_len, 
> TCP_WRITE_FLAG_COPY);
> ++    DEBUG_printf("Write to socket %p @%p %u bytes: %d\n", socket, buf, 
> write_len, err);
> +
> +     if (err != ERR_OK) {
> +         *_errno = error_lookup_table[-err];
> +@@ -524,6 +529,7 @@
> +         }
> +
> +         mp_uint_t start = mp_hal_ticks_ms();
> ++    DEBUG_printf("Wait for data on socket %p to receive...\n", socket);
> +         while (socket->state == STATE_CONNECTED && socket->incoming.pbuf == 
> NULL) {
> +             if (socket->timeout != -1 && mp_hal_ticks_ms() - start > 
> socket->timeout) {
> +                 *_errno = MP_ETIMEDOUT;
> +@@ -531,6 +537,7 @@
> +             }
> +             poll_sockets();
> +         }
> ++    DEBUG_printf("Done\n");
> +
> +         if (socket->state == STATE_PEER_CLOSED) {
> +             if (socket->incoming.pbuf == NULL) {
> +@@ -636,6 +643,7 @@
> + STATIC mp_obj_t lwip_socket_close(mp_obj_t self_in) {
> +     lwip_socket_obj_t *socket = self_in;
> +     bool socket_is_listener = false;
> ++    err_t err;
> +
> +     if (socket->pcb.tcp == NULL) {
> +         return mp_const_none;
> +@@ -644,8 +652,14 @@
> +         case MOD_NETWORK_SOCK_STREAM: {
> +             if (socket->pcb.tcp->state == LISTEN) {
> +                 socket_is_listener = true;
> +-            }
> +-            if (tcp_close(socket->pcb.tcp) != ERR_OK) {
> ++            } else {
> ++            /* Flush output queue */
> ++            tcp_output(socket->pcb.tcp);
> ++        }
> ++
> ++        err = tcp_close(socket->pcb.tcp);
> ++        DEBUG_printf("Closed socket %p: %d\n", socket, err);
> ++            if (err != ERR_OK) {
> +                 DEBUG_printf("lwip_close: had to call tcp_abort()\n");
> +                 tcp_abort(socket->pcb.tcp);
> +             }
> +@@ -660,6 +674,7 @@
> +         if (!socket_is_listener) {
> +             pbuf_free(socket->incoming.pbuf);
> +         } else {
> ++        DEBUG_printf("Abort incoming connection request %p\n", 
> socket->incoming.connection);
> +             tcp_abort(socket->incoming.connection);
> +         }
> +         socket->incoming.pbuf = NULL;
> +@@ -694,6 +709,7 @@
> +         mp_raise_OSError(error_lookup_table[-err]);
> +     }
> +
> ++    DEBUG_printf("lwip_close: Bind socket %p\n", socket);
> +     return mp_const_none;
> + }
> + STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_bind_obj, lwip_socket_bind);
> +@@ -716,6 +732,7 @@
> +     socket->pcb.tcp = new_pcb;
> +     tcp_accept(new_pcb, _lwip_tcp_accept);
> +
> ++    DEBUG_printf("lwip_listen: Listen on socket %p\n", socket);
> +     return mp_const_none;
> + }
> + STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_listen_obj, 
> lwip_socket_listen);
> +@@ -748,9 +765,11 @@
> +                 mp_raise_OSError(MP_ETIMEDOUT);
> +             }
> +         } else {
> ++        DEBUG_printf("Wait for connection on socket %p\n", socket);
> +             while (socket->incoming.connection == NULL) {
> +                 poll_sockets();
> +             }
> ++        DEBUG_printf("Done\n");
> +         }
> +     }
> +
> +@@ -773,6 +792,7 @@
> +     tcp_arg(socket2->pcb.tcp, (void*)socket2);
> +     tcp_err(socket2->pcb.tcp, _lwip_tcp_error);
> +     tcp_recv(socket2->pcb.tcp, _lwip_tcp_recv);
> ++    DEBUG_printf("New socket for endpoint connection: %p\n", socket2);
> +
> +     tcp_accepted(listener);
> +
> +@@ -1226,6 +1246,7 @@
> + // Support functions for memory protection. lwIP has its own memory 
> management
> + // routines for its internal structures, and since they might be called in
> + // interrupt handlers, they need some protection.
> ++/*
> + sys_prot_t sys_arch_protect() {
> +     return (sys_prot_t)MICROPY_BEGIN_ATOMIC_SECTION();
> + }
> +@@ -1233,6 +1254,7 @@
> + void sys_arch_unprotect(sys_prot_t state) {
> +     MICROPY_END_ATOMIC_SECTION((mp_uint_t)state);
> + }
> ++*/
> +
> + 
> /******************************************************************************/
> + // Polling callbacks for the interfaces connected to lwIP. Right now it 
> calls
> +@@ -1246,6 +1268,7 @@
> + STATIC nic_poll_t lwip_poll_list;
> +
> + void mod_lwip_register_poll(void (* poll)(void *arg), void *poll_arg) {
> ++    DEBUG_printf("Register poll: %p (argp %p)\n", poll, poll_arg);
> +     lwip_poll_list.poll = poll;
> +     lwip_poll_list.poll_arg = poll_arg;
> + }
> +@@ -1256,15 +1279,21 @@
> +
> + 
> /******************************************************************************/
> + // The lwip global functions.
> ++#include <netif/uknetdev.h>
> +
> + STATIC mp_obj_t mod_lwip_reset() {
> +-    lwip_init();
> ++    DEBUG_printf("lwip reset\n");
> ++    //lwip_init();
> +     lwip_poll_list.poll = NULL;
> ++
> ++    /* Register uknetdev polling to molwip */
> ++    mod_lwip_register_poll(uknetdev_poll_all, NULL);
> +     return mp_const_none;
> + }
> + MP_DEFINE_CONST_FUN_OBJ_0(mod_lwip_reset_obj, mod_lwip_reset);
> +
> + STATIC mp_obj_t mod_lwip_callback() {
> ++    DEBUG_printf("Exec callback\n");
> +     if (lwip_poll_list.poll != NULL) {
> +         lwip_poll_list.poll(lwip_poll_list.poll_arg);
> +     }
> +@@ -1295,6 +1324,7 @@
> +     if (n_args > 2) {
> +         mp_warning("getaddrinfo constraints not supported");
> +     }
> ++    DEBUG_printf("getaddrinfo\n");
> +
> +     mp_obj_t host_in = args[0], port_in = args[1];
> +     const char *host = mp_obj_str_get_str(host_in);
> +@@ -1335,13 +1365,13 @@
> + STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_getaddrinfo_obj, 2, 6, 
> lwip_getaddrinfo);
> +
> + // Debug functions
> +-
> ++/*
> + STATIC mp_obj_t lwip_print_pcbs() {
> +     tcp_debug_print_pcbs();
> +     return mp_const_none;
> + }
> + MP_DEFINE_CONST_FUN_OBJ_0(lwip_print_pcbs_obj, lwip_print_pcbs);
> +-
> ++*/
> + #ifdef MICROPY_PY_LWIP
> +
> + STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
> +@@ -1349,7 +1379,7 @@
> +     { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&mod_lwip_reset_obj) },
> +     { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&mod_lwip_callback_obj) },
> +     { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&lwip_getaddrinfo_obj) },
> +-    { MP_ROM_QSTR(MP_QSTR_print_pcbs), MP_ROM_PTR(&lwip_print_pcbs_obj) },
> ++    //{ MP_ROM_QSTR(MP_QSTR_print_pcbs), MP_ROM_PTR(&lwip_print_pcbs_obj) },
> +     // objects
> +     { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&lwip_socket_type) },
> + #ifdef MICROPY_PY_LWIP_SLIP
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.