diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 914ed6ec9..af72f23f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,9 +70,13 @@ jobs: - name: Build c/udpserver run: make ARCH=${{ matrix.arch }} A=apps/c/udpserver - name: Build c/iperf - run: make ARCH=${{ matrix.arch }} A=apps/c/iperf + run: | + git clone https://github.com/syswonder/rux-iperf ./apps/c/iperf/ \ + && make ARCH=${{ matrix.arch }} A=apps/c/iperf - name: Build c/redis - run: make ARCH=${{ matrix.arch }} A=apps/c/redis SMP=4 + run: | + git clone https://github.com/syswonder/rux-redis ./apps/c/redis/ \ + && make ARCH=${{ matrix.arch }} A=apps/c/redis SMP=4 build-apps-for-std: runs-on: ${{ matrix.os }} diff --git a/.gitignore b/.gitignore index ed439fc5d..fd3f0164b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,7 @@ disk.img actual.out qemu.log rusty-tags.vi +apps/c/redis/ +apps/c/iperf/ +apps/c/wamr/ +apps/c/nginx/ diff --git a/README.md b/README.md index f89170e0b..5747cf316 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ An experimental modular operating system (or unikernel) written in Rust. RuxOS was inspired by [Unikraft](https://github.com/unikraft/unikraft) and [ArceOS](https://github.com/rcore-os/arceos) -🚧 Working In Progress. +🚧 Working In Progress. See [RuxOS Book](https://ruxos.syswonder.org) for more information. ## Features & TODOs @@ -39,17 +39,8 @@ The currently supported applications (Rust), as well as their dependent modules | App | Extra modules | Enabled features | Description | |-|-|-|-| -| [helloworld](apps/helloworld/) | | | A minimal app that just prints a string | -| [exception](apps/exception/) | | paging | Exception handling test | -| [memtest](apps/memtest/) | axalloc | alloc, paging | Dynamic memory allocation test | | [display](apps/display/) | axalloc, ruxdisplay | alloc, paging, display | Graphic/GUI test | -| [yield](apps/task/yield/) | axalloc, ruxtask | alloc, paging, multitask, sched_fifo | Multi-threaded yielding test | -| [parallel](apps/task/parallel/) | axalloc, ruxtask | alloc, paging, multitask, sched_fifo | Parallel computing test (to test synchronization & mutex) | -| [sleep](apps/task/sleep/) | axalloc, ruxtask | alloc, paging, multitask, sched_fifo | Thread sleeping test | | [shell](apps/fs/shell/) | axalloc, ruxdriver, ruxfs | alloc, paging, fs | A simple shell that responds to filesystem operations | -| [httpclient](apps/net/httpclient/) | axalloc, ruxdriver, axnet | alloc, paging, net | A simple client that sends an HTTP request and then prints the response | -| [echoserver](apps/net/echoserver/) | axalloc, ruxdriver, axnet, ruxtask | alloc, paging, net, multitask | A multi-threaded TCP server that reverses messages sent by the client | -| [httpserver](apps/net/httpserver/) | axalloc, ruxdriver, axnet, ruxtask | alloc, paging, net, multitask | A multi-threaded HTTP server that serves a static web page | ### C @@ -119,13 +110,13 @@ Where `` should be one of `riscv64`, `aarch64`,`x86_64`. More arguments and targets can be found in [Makefile](Makefile). -For example, to run the [httpserver](apps/net/httpserver/) on `qemu-system-aarch64` with 4 cores: +For example, to run the [shell](apps/fs/shell/) on `qemu-system-aarch64`: ```bash -make A=apps/net/httpserver ARCH=aarch64 LOG=info SMP=4 run NET=y +make A=apps/fs/shell ARCH=aarch64 LOG=info run BLK=y ``` -Note that the `NET=y` argument is required to enable the network device in QEMU. These arguments (`BLK`, `GRAPHIC`, etc.) only take effect at runtime not build time. +Note that the `BLK=y` argument is required to enable the block device in QEMU. These arguments (`NET`, `GRAPHIC`, etc.) only take effect at runtime not build time. ### Your custom apps diff --git a/api/ruxos_posix_api/build.rs b/api/ruxos_posix_api/build.rs index 80daa27d8..5da21eb3c 100644 --- a/api/ruxos_posix_api/build.rs +++ b/api/ruxos_posix_api/build.rs @@ -103,6 +103,9 @@ typedef struct {{ "sigset_t", "sigaction", "kstat", + "stack_t", + "ino_t", + "dirent", ]; let allow_vars = [ "O_.*", @@ -122,6 +125,7 @@ typedef struct {{ "EINVAL", "CLONE_.*", "AT_.*", + "MAP_FAILED", ]; #[derive(Debug)] diff --git a/api/ruxos_posix_api/ctypes.h b/api/ruxos_posix_api/ctypes.h index f1ad47277..857e547b9 100644 --- a/api/ruxos_posix_api/ctypes.h +++ b/api/ruxos_posix_api/ctypes.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -29,3 +30,4 @@ #include #include #include +#include diff --git a/api/ruxos_posix_api/src/imp/fd_ops.rs b/api/ruxos_posix_api/src/imp/fd_ops.rs index c0c6be9f1..bb5ca1e43 100644 --- a/api/ruxos_posix_api/src/imp/fd_ops.rs +++ b/api/ruxos_posix_api/src/imp/fd_ops.rs @@ -153,6 +153,31 @@ pub fn sys_fcntl(fd: c_int, cmd: c_int, arg: usize) -> c_int { get_file_like(fd)?.set_nonblocking(arg & (ctypes::O_NONBLOCK as usize) > 0)?; Ok(0) } + ctypes::F_GETFL => { + use ctypes::{O_RDONLY, O_RDWR, O_WRONLY}; + let f_state = get_file_like(fd)?.poll()?; + let mut flags: core::ffi::c_uint = 0; + // Only support read/write flags(O_ACCMODE) + if f_state.writable && f_state.readable { + flags |= O_RDWR; + } else if f_state.writable { + flags |= O_WRONLY; + } else if f_state.readable { + flags |= O_RDONLY; + } + Ok(flags as c_int) + } + ctypes::F_SETFD => { + if arg == 0 || arg == 1 || arg == 2 { + return Ok(0); + } + FD_TABLE + .write() + .add_at(arg, get_file_like(fd)?) + .ok_or(LinuxError::EMFILE)?; + let _ = close_file_like(fd); + Ok(0) + } _ => { warn!("unsupported fcntl parameters: cmd {}", cmd); Ok(0) diff --git a/api/ruxos_posix_api/src/imp/fs.rs b/api/ruxos_posix_api/src/imp/fs.rs index 44ce939f2..a6bbe5b03 100644 --- a/api/ruxos_posix_api/src/imp/fs.rs +++ b/api/ruxos_posix_api/src/imp/fs.rs @@ -8,15 +8,16 @@ */ use alloc::sync::Arc; -use core::ffi::{c_char, c_int}; +use core::ffi::{c_char, c_int, c_long, c_uint}; use axerrno::{LinuxError, LinuxResult}; use axio::{PollState, SeekFrom}; use axsync::Mutex; -use ruxfs::fops::OpenOptions; +use ruxfs::fops::{DirEntry, OpenOptions}; use super::fd_ops::{get_file_like, FileLike}; use crate::{ctypes, utils::char_ptr_to_str}; +use alloc::vec::Vec; pub struct File { inner: Mutex, @@ -84,6 +85,58 @@ impl FileLike for File { } } +pub struct Directory { + inner: Mutex, +} + +impl Directory { + fn new(inner: ruxfs::fops::Directory) -> Self { + Self { + inner: Mutex::new(inner), + } + } + + fn add_to_fd_table(self) -> LinuxResult { + super::fd_ops::add_file_like(Arc::new(self)) + } + + fn from_fd(fd: c_int) -> LinuxResult> { + let f = super::fd_ops::get_file_like(fd)?; + f.into_any() + .downcast::() + .map_err(|_| LinuxError::EINVAL) + } +} + +impl FileLike for Directory { + fn read(&self, _buf: &mut [u8]) -> LinuxResult { + Err(LinuxError::EACCES) + } + + fn write(&self, _buf: &[u8]) -> LinuxResult { + Err(LinuxError::EACCES) + } + + fn stat(&self) -> LinuxResult { + Err(LinuxError::EACCES) + } + + fn into_any(self: Arc) -> Arc { + self + } + + fn poll(&self) -> LinuxResult { + Ok(PollState { + readable: true, + writable: true, + }) + } + + fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult { + Ok(()) + } +} + /// Convert open flags to [`OpenOptions`]. fn flags_to_options(flags: c_int, _mode: ctypes::mode_t) -> OpenOptions { let flags = flags as u32; @@ -133,8 +186,13 @@ pub fn sys_openat(_fd: usize, path: *const c_char, flags: c_int, mode: ctypes::m debug!("sys_openat <= {:?}, {:#o} {:#o}", path, flags, mode); syscall_body!(sys_openat, { let options = flags_to_options(flags, mode); - let file = ruxfs::fops::File::open(path?, &options)?; - File::new(file).add_to_fd_table() + if (flags as u32) & ctypes::O_DIRECTORY != 0 { + let dir = ruxfs::fops::Directory::open_dir(path?, &options)?; + Directory::new(dir).add_to_fd_table() + } else { + let file = ruxfs::fops::File::open(path?, &options)?; + File::new(file).add_to_fd_table() + } }) } @@ -402,3 +460,82 @@ pub fn sys_fchownat( ); syscall_body!(sys_fchownat, Ok(0)) } + +/// read value of a symbolic link relative to directory file descriptor +pub fn sys_readlinkat( + fd: c_int, + pathname: *const c_char, + buf: *mut c_char, + bufsize: usize, +) -> usize { + let path = char_ptr_to_str(pathname); + debug!( + "sys_readlinkat <= path = {:?}, fd = {:}, bufsize = {:}", + path, fd, bufsize + ); + syscall_body!(sys_readlinkat, { + let mut options = OpenOptions::new(); + options.read(true); + let dst = unsafe { core::slice::from_raw_parts_mut(buf as *mut u8, bufsize as _) }; + // if fd == AT_FDCWD then readat the relative path + if fd == ctypes::AT_FDCWD as c_int { + let file = ruxfs::fops::File::open(path?, &options)?; + let file = File::new(file); + Ok(file.read(dst)?) + } else { + let dir = Directory::from_fd(fd)?; + let mut file = dir.inner.lock().open_file_at(path?, &options)?; + Ok(file.read(dst)?) + } + }) +} + +type LinuxDirent64 = ctypes::dirent; + +fn convert_name_to_array(name: &[u8]) -> [i8; 256] { + let mut array = [0i8; 256]; + let len = name.len(); + let name_ptr = name.as_ptr() as *const i8; + let array_ptr = array.as_mut_ptr(); + + unsafe { + core::ptr::copy_nonoverlapping(name_ptr, array_ptr, len); + } + + array +} + +/// Read directory entries from a directory file descriptor. +/// +/// TODO: check errors, change 280 to a special value +pub unsafe fn sys_getdents64(fd: c_uint, dirent: *mut LinuxDirent64, count: c_uint) -> c_long { + debug!( + "sys_getdents64 <= fd: {}, dirent: {:p}, count: {}", + fd, dirent, count + ); + + syscall_body!(sys_getdents64, { + let expect_entries = count as usize / 280; + let dir = Directory::from_fd(fd as i32)?; + let mut my_dirent: Vec = + (0..expect_entries).map(|_| DirEntry::default()).collect(); + + let n = dir.inner.lock().read_dir(&mut my_dirent)?; + + for (i, entry) in my_dirent.iter().enumerate() { + let linux_dirent = LinuxDirent64 { + d_ino: 1, + d_off: 280, + d_reclen: 280, + d_type: entry.entry_type() as u8, + d_name: convert_name_to_array(entry.name_as_bytes()), + }; + + unsafe { + core::ptr::write(dirent.add(i), linux_dirent); + } + } + + Ok(n * 280) + }) +} diff --git a/api/ruxos_posix_api/src/imp/ioctl.rs b/api/ruxos_posix_api/src/imp/ioctl.rs index 3339ed880..245a3d358 100644 --- a/api/ruxos_posix_api/src/imp/ioctl.rs +++ b/api/ruxos_posix_api/src/imp/ioctl.rs @@ -17,6 +17,7 @@ pub const TIOCGPGRP: usize = 0x540F; pub const TIOCSPGRP: usize = 0x5410; pub const TIOCGWINSZ: usize = 0x5413; pub const FIONBIO: usize = 0x5421; +pub const FIOCLEX: usize = 0x5451; #[derive(Clone, Copy, Default)] pub struct ConsoleWinSize { @@ -56,6 +57,7 @@ pub fn sys_ioctl(fd: c_int, request: usize, data: usize) -> c_int { } Ok(0) } + FIOCLEX => Ok(0), _ => Err(LinuxError::EINVAL), } }) diff --git a/api/ruxos_posix_api/src/imp/mmap.rs b/api/ruxos_posix_api/src/imp/mmap.rs index 81934328b..6b3a1a6b1 100644 --- a/api/ruxos_posix_api/src/imp/mmap.rs +++ b/api/ruxos_posix_api/src/imp/mmap.rs @@ -69,3 +69,39 @@ pub fn sys_mprotect(addr: *mut c_void, len: ctypes::size_t, prot: c_int) -> c_in ); syscall_body!(sys_mprotect, Ok(0)) } + +/// Remap a virtual memory address +/// +/// TODO: only support +pub fn sys_mremap( + old_addr: *mut c_void, + old_size: ctypes::size_t, + new_size: ctypes::size_t, + _flags: c_int, + _new_addr: *mut c_void, +) -> *mut c_void { + debug!( + "sys_mremap <= old_addr: {:p}, old_size: {}, new_size: {}, flags: {}, new_addr: {:p}", + old_addr, old_size, new_size, _flags, _new_addr + ); + syscall_body!(sys_mremap, { + if old_addr.is_null() { + // TODO: It should be ctypes::MAP_FAILED, + // but it is not defined in ctypes for an unknown reason + return Ok(-1 as _); + } + Ok::<*mut c_void, LinuxError>(-1 as _) + }) +} + +/// give advice about use of memory +/// if success return 0, if error return -1 +/// +/// TODO: implement this +pub fn sys_madvice(addr: *mut c_void, len: ctypes::size_t, advice: c_int) -> c_int { + debug!( + "sys_madvice <= addr: {:p}, len: {}, advice: {}", + addr, len, advice + ); + syscall_body!(sys_madvice, Ok(0)) +} diff --git a/api/ruxos_posix_api/src/imp/signal.rs b/api/ruxos_posix_api/src/imp/signal.rs index 4da9474b1..6def81518 100644 --- a/api/ruxos_posix_api/src/imp/signal.rs +++ b/api/ruxos_posix_api/src/imp/signal.rs @@ -21,16 +21,21 @@ pub fn sys_sigaction( signum: u8, sigaction: Option<&k_sigaction>, oldact: Option<&mut k_sigaction>, -) { - Signal::sigaction( - signum, - sigaction.map(|act| act as *const k_sigaction as *const rx_sigaction), - oldact.map(|old| old as *mut k_sigaction as *mut rx_sigaction), - ); +) -> c_int { + debug!("sys_sigaction <= signum: {}", signum,); + syscall_body!(sys_sigaction, { + Signal::sigaction( + signum, + sigaction.map(|act| act as *const k_sigaction as *const rx_sigaction), + oldact.map(|old| old as *mut k_sigaction as *mut rx_sigaction), + ); + Ok(0) + }) } /// Set a timer to send a signal to the current process after a specified time pub unsafe fn sys_setitimer(which: c_int, new: *const ctypes::itimerval) -> c_int { + debug!("sys_setitimer <= which: {}, new: {:p}", which, new); syscall_body!(sys_setitimer, { let which = which as usize; let new_interval = Duration::from((*new).it_interval).as_nanos() as u64; @@ -45,6 +50,10 @@ pub unsafe fn sys_setitimer(which: c_int, new: *const ctypes::itimerval) -> c_in /// Get timer to send signal after some time pub unsafe fn sys_getitimer(which: c_int, curr_value: *mut ctypes::itimerval) -> c_int { + debug!( + "sys_getitimer <= which: {}, curr_value: {:p}", + which, curr_value + ); syscall_body!(sys_getitimer, { let ddl = Duration::from_nanos(Signal::timer_deadline(which as usize, None).unwrap()); if ddl.as_nanos() == 0 { @@ -65,3 +74,14 @@ pub unsafe fn sys_getitimer(which: c_int, curr_value: *mut ctypes::itimerval) -> Ok(0) }) } + +/// Sigal stack +/// +/// TODO: implement this && the parameter type should be ctypes::stack_t +pub unsafe fn sys_sigaltstack( + _ss: *const core::ffi::c_void, + _old_ss: *mut core::ffi::c_void, +) -> c_int { + debug!("sys_sigaltstack <= ss: {:p}, old_ss: {:p}", _ss, _old_ss); + syscall_body!(sys_sigaltstack, Ok(0)) +} diff --git a/api/ruxos_posix_api/src/imp/stdio.rs b/api/ruxos_posix_api/src/imp/stdio.rs index 39a02b09e..5d29c7a66 100644 --- a/api/ruxos_posix_api/src/imp/stdio.rs +++ b/api/ruxos_posix_api/src/imp/stdio.rs @@ -15,7 +15,11 @@ use axsync::Mutex; use {alloc::sync::Arc, axerrno::LinuxError, axerrno::LinuxResult, axio::PollState}; fn console_read_bytes() -> Option { - ruxhal::console::getchar().map(|c| if c == b'\r' { b'\n' } else { c }) + let ret = ruxhal::console::getchar().map(|c| if c == b'\r' { b'\n' } else { c }); + if let Some(c) = ret { + let _ = console_write_bytes(&[c]); + } + ret } fn console_write_bytes(buf: &[u8]) -> AxResult { diff --git a/api/ruxos_posix_api/src/lib.rs b/api/ruxos_posix_api/src/lib.rs index 5fe2e0c0f..d9d266e8b 100644 --- a/api/ruxos_posix_api/src/lib.rs +++ b/api/ruxos_posix_api/src/lib.rs @@ -60,9 +60,9 @@ pub use imp::fd_ops::sys_dup3; pub use imp::fd_ops::{sys_close, sys_dup, sys_dup2, sys_fcntl}; #[cfg(feature = "fs")] pub use imp::fs::{ - sys_fchownat, sys_fdatasync, sys_fstat, sys_fsync, sys_getcwd, sys_lseek, sys_lstat, sys_mkdir, - sys_mkdirat, sys_newfstatat, sys_open, sys_openat, sys_rename, sys_renameat, sys_rmdir, - sys_stat, sys_unlink, sys_unlinkat, + sys_fchownat, sys_fdatasync, sys_fstat, sys_fsync, sys_getcwd, sys_getdents64, sys_lseek, + sys_lstat, sys_mkdir, sys_mkdirat, sys_newfstatat, sys_open, sys_openat, sys_readlinkat, + sys_rename, sys_renameat, sys_rmdir, sys_stat, sys_unlink, sys_unlinkat, }; #[cfg(feature = "epoll")] pub use imp::io_mpx::{sys_epoll_create, sys_epoll_ctl, sys_epoll_pwait, sys_epoll_wait}; @@ -73,7 +73,7 @@ pub use imp::io_mpx::{sys_pselect6, sys_select}; #[cfg(feature = "fd")] pub use imp::ioctl::sys_ioctl; #[cfg(feature = "alloc")] -pub use imp::mmap::{sys_mmap, sys_mprotect, sys_munmap}; +pub use imp::mmap::{sys_madvice, sys_mmap, sys_mprotect, sys_mremap, sys_munmap}; #[cfg(feature = "net")] pub use imp::net::{ sys_accept, sys_bind, sys_connect, sys_freeaddrinfo, sys_getaddrinfo, sys_getpeername, @@ -98,7 +98,7 @@ pub use imp::pthread::{ sys_pthread_setspecific, }; #[cfg(feature = "signal")] -pub use imp::signal::{sys_getitimer, sys_setitimer, sys_sigaction}; +pub use imp::signal::{sys_getitimer, sys_setitimer, sys_sigaction, sys_sigaltstack}; #[cfg(feature = "multitask")] pub use imp::pthread::futex::sys_futex; diff --git a/apps/c/iperf/.gitignore b/apps/c/iperf/.gitignore deleted file mode 100644 index 64620fc22..000000000 --- a/apps/c/iperf/.gitignore +++ /dev/null @@ -1 +0,0 @@ -iperf-* diff --git a/apps/c/iperf/README.md b/apps/c/iperf/README.md deleted file mode 100644 index 592a7942e..000000000 --- a/apps/c/iperf/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# How to run iperf on Ruxos and benchmark network performance - -## Build & run - -Build and start the [`iperf3`](https://github.com/esnet/iperf) server on Ruxos: - -```bash -# in ruxos root directory -make A=apps/c/iperf BLK=y NET=y ARCH= run -``` - -## Benchmark - -In another shell, run the `iperf3` client: - -* iperf on Ruxos as the receiver: - - ```bash - # TCP - iperf3 -c 127.0.0.1 -p 5555 - # UDP - iperf3 -uc 127.0.0.1 -p 5555 -b -l - ``` - - You need to set the `` (in bits/sec) to avoid sending packets too fast from the client when use UDP. - -* iperf on Ruxos as the sender: - - ```bash - # TCP - iperf3 -c 127.0.0.1 -p 5555 -R - # UDP - iperf3 -uc 127.0.0.1 -p 5555 -b 0 -l -R - ``` - -By default, the `` is 128 KB for TCP and 8 KB for UDP. Larger buffer length may improve the performance. You can change it by the `-l` option of `iperf3`. - -Note that if the `` is greater than `1472` (total packet length is exceeded the MTU of the NIC) when use UDP, packets fragmentation will occur. You should enable fragmentation features in [smoltcp](https://github.com/smoltcp-rs/smoltcp): - -```toml -# in ruxos/modules/axnet/Cargo.toml -[dependencies.smoltcp] -git = "https://github.com/smoltcp-rs/smoltcp.git" -rev = "1f9b9f0" -default-features = false -features = [ - "medium-ethernet", - "proto-ipv4", - "socket-raw", "socket-icmp", "socket-udp", "socket-tcp", "socket-dns", - "fragmentation-buffer-size-65536", "proto-ipv4-fragmentation", - "reassembly-buffer-size-65536", "reassembly-buffer-count-32", - "assembler-max-segment-count-32", -] -``` diff --git a/apps/c/iperf/axbuild.mk b/apps/c/iperf/axbuild.mk deleted file mode 100644 index 7c4dcf7aa..000000000 --- a/apps/c/iperf/axbuild.mk +++ /dev/null @@ -1,32 +0,0 @@ -IPERF_VERSION := 3.1.3 -APP_CFLAGS := -Ulinux - -iperf_pkg := iperf-$(IPERF_VERSION) -iperf_dir := $(APP)/$(iperf_pkg) -iperf_src := \ - cjson.c \ - iperf_api.c \ - iperf_error.c \ - iperf_client_api.c \ - iperf_locale.c \ - iperf_server_api.c \ - iperf_tcp.c \ - iperf_udp.c \ - iperf_sctp.c \ - iperf_util.c \ - net.c \ - tcp_info.c \ - tcp_window_size.c \ - timer.c \ - units.c \ - main_server.c - -app-objs := $(patsubst %.c,$(iperf_pkg)/src/%.o,$(iperf_src)) - -.PRECIOUS: $(APP)/%.c -$(APP)/%.c: - @echo "Download iperf source code" - wget https://downloads.es.net/pub/iperf/$(iperf_pkg).tar.gz -P $(APP) - tar -zxvf $(APP)/$(iperf_pkg).tar.gz -C $(APP) && rm -f $(APP)/$(iperf_pkg).tar.gz - cd $(iperf_dir) && git init && git add . - patch -p1 -N -d $(iperf_dir) --no-backup-if-mismatch -r - < $(APP)/iperf.patch diff --git a/apps/c/iperf/features.txt b/apps/c/iperf/features.txt deleted file mode 100644 index 176c573d0..000000000 --- a/apps/c/iperf/features.txt +++ /dev/null @@ -1,7 +0,0 @@ -alloc -paging -net -fs -blkfs -select -fp_simd diff --git a/apps/c/iperf/iperf.patch b/apps/c/iperf/iperf.patch deleted file mode 100644 index 252e231b9..000000000 --- a/apps/c/iperf/iperf.patch +++ /dev/null @@ -1,664 +0,0 @@ -diff --git a/src/cjson.c b/src/cjson.c -index 595d919..43264e6 100644 ---- a/src/cjson.c -+++ b/src/cjson.c -@@ -105,7 +105,7 @@ void cJSON_Delete(cJSON *c) - /* Parse the input text to generate a number, and populate the result into item. */ - static const char *parse_number(cJSON *item,const char *num) - { -- double n=0,sign=1,scale=0;int subscale=0,signsubscale=1; -+ double n=0,sign=1;int subscale=0,signsubscale=1,scale=0; - - if (*num=='-') sign=-1,num++; /* Has sign? */ - if (*num=='0') num++; /* is zero */ -@@ -116,8 +116,11 @@ static const char *parse_number(cJSON *item,const char *num) - while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */ - } - -- n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */ -- -+ scale += subscale * signsubscale; -+ n = sign * n; -+ while (scale != 0) -+ { if (scale > 0) n *= 10.0,scale--; else n /= 10.0,scale++; -+ } - item->valuedouble=n; - item->valueint=(int64_t)n; - item->type=cJSON_Number; -diff --git a/src/iperf.h b/src/iperf.h -index 8ff25d7..4e96d9f 100755 ---- a/src/iperf.h -+++ b/src/iperf.h -@@ -37,6 +37,7 @@ - #include - #include - #include -+#include - - #if defined(HAVE_CPUSET_SETAFFINITY) - #include -diff --git a/src/iperf_api.c b/src/iperf_api.c -index 5b56af6..1e12a81 100755 ---- a/src/iperf_api.c -+++ b/src/iperf_api.c -@@ -32,7 +32,6 @@ - #include - #include - #include --#include - #include - #include - #include -@@ -52,7 +51,6 @@ - #include - #include - #include --#include - #include - #include - -@@ -95,7 +93,7 @@ static cJSON *JSON_read(int fd); - void - usage() - { -- fputs(usage_shortstr, stderr); -+ puts(usage_shortstr); - } - - -@@ -613,6 +611,7 @@ iperf_on_test_finish(struct iperf_test *test) - - /******************************************************************************/ - -+#if 0 - int - iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) - { -@@ -1035,6 +1034,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) - - return 0; - } -+#endif - - int - iperf_set_send_state(struct iperf_test *test, signed char state) -@@ -2639,8 +2639,7 @@ iperf_free_stream(struct iperf_stream *sp) - struct iperf_interval_results *irp, *nirp; - - /* XXX: need to free interval list too! */ -- munmap(sp->buffer, sp->test->settings->blksize); -- close(sp->buffer_fd); -+ free(sp->buffer); - if (sp->diskfile_fd >= 0) - close(sp->diskfile_fd); - for (irp = TAILQ_FIRST(&sp->result->interval_results); irp != NULL; irp = nirp) { -@@ -2691,35 +2690,10 @@ iperf_new_stream(struct iperf_test *test, int s) - TAILQ_INIT(&sp->result->interval_results); - - /* Create and randomize the buffer */ -- sp->buffer_fd = mkstemp(template); -- if (sp->buffer_fd == -1) { -- i_errno = IECREATESTREAM; -- free(sp->result); -- free(sp); -- return NULL; -- } -- if (unlink(template) < 0) { -- i_errno = IECREATESTREAM; -- free(sp->result); -- free(sp); -- return NULL; -- } -- if (ftruncate(sp->buffer_fd, test->settings->blksize) < 0) { -- i_errno = IECREATESTREAM; -- free(sp->result); -- free(sp); -- return NULL; -- } -- sp->buffer = (char *) mmap(NULL, test->settings->blksize, PROT_READ|PROT_WRITE, MAP_PRIVATE, sp->buffer_fd, 0); -- if (sp->buffer == MAP_FAILED) { -- i_errno = IECREATESTREAM; -- free(sp->result); -- free(sp); -- return NULL; -- } -- srandom(time(NULL)); -+ sp->buffer = (char *)malloc(test->settings->blksize); -+ srand(time(NULL)); - for (i = 0; i < test->settings->blksize; ++i) -- sp->buffer[i] = random(); -+ sp->buffer[i] = rand(); - - /* Set socket */ - sp->socket = s; -@@ -2731,7 +2705,7 @@ iperf_new_stream(struct iperf_test *test, int s) - sp->diskfile_fd = open(test->diskfile_name, test->sender ? O_RDONLY : (O_WRONLY|O_CREAT|O_TRUNC), S_IRUSR|S_IWUSR); - if (sp->diskfile_fd == -1) { - i_errno = IEFILE; -- munmap(sp->buffer, sp->test->settings->blksize); -+ free(sp->buffer); - free(sp->result); - free(sp); - return NULL; -@@ -2745,8 +2719,7 @@ iperf_new_stream(struct iperf_test *test, int s) - - /* Initialize stream */ - if (iperf_init_stream(sp, test) < 0) { -- close(sp->buffer_fd); -- munmap(sp->buffer, sp->test->settings->blksize); -+ free(sp->buffer); - free(sp->result); - free(sp); - return NULL; -@@ -2774,25 +2747,6 @@ iperf_init_stream(struct iperf_stream *sp, struct iperf_test *test) - return -1; - } - -- /* Set IP TOS */ -- if ((opt = test->settings->tos)) { -- if (getsockdomain(sp->socket) == AF_INET6) { --#ifdef IPV6_TCLASS -- if (setsockopt(sp->socket, IPPROTO_IPV6, IPV6_TCLASS, &opt, sizeof(opt)) < 0) { -- i_errno = IESETCOS; -- return -1; -- } --#else -- i_errno = IESETCOS; -- return -1; --#endif -- } else { -- if (setsockopt(sp->socket, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)) < 0) { -- i_errno = IESETTOS; -- return -1; -- } -- } -- } - - return 0; - } -diff --git a/src/iperf_api.h b/src/iperf_api.h -index 0f153fe..f2ff9bc 100755 ---- a/src/iperf_api.h -+++ b/src/iperf_api.h -@@ -29,6 +29,7 @@ - - #include - #include -+#include - - struct iperf_test; - struct iperf_stream_result; -diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c -index f19f6f1..ff0a4c8 100644 ---- a/src/iperf_client_api.c -+++ b/src/iperf_client_api.c -@@ -33,7 +33,6 @@ - #include - #include - #include --#include - #include - - #include "iperf.h" -diff --git a/src/iperf_config.h b/src/iperf_config.h -new file mode 100644 -index 0000000..979b858 ---- /dev/null -+++ b/src/iperf_config.h -@@ -0,0 +1,98 @@ -+/* src/iperf_config.h. Generated from iperf_config.h.in by configure. */ -+/* src/iperf_config.h.in. Generated from configure.ac by autoheader. */ -+ -+/* Define to 1 if you have the `cpuset_setaffinity' function. */ -+/* #undef HAVE_CPUSET_SETAFFINITY */ -+ -+/* Have CPU affinity support. */ -+// #define HAVE_CPU_AFFINITY 1 -+ -+/* Define to 1 if you have the header file. */ -+// #define HAVE_DLFCN_H 1 -+ -+/* Have IPv6 flowlabel support. */ -+// #define HAVE_FLOWLABEL 1 -+ -+/* Define to 1 if you have the header file. */ -+// #define HAVE_INTTYPES_H 1 -+ -+/* Define to 1 if you have the header file. */ -+// #define HAVE_MEMORY_H 1 -+ -+/* Define to 1 if you have the header file. */ -+/* #undef HAVE_NETINET_SCTP_H */ -+ -+/* Define to 1 if you have the `sched_setaffinity' function. */ -+// #define HAVE_SCHED_SETAFFINITY 1 -+ -+/* Have SCTP support. */ -+/* #undef HAVE_SCTP */ -+ -+/* Define to 1 if you have the `sendfile' function. */ -+// #define HAVE_SENDFILE 1 -+ -+/* Have SO_MAX_PACING_RATE sockopt. */ -+// #define HAVE_SO_MAX_PACING_RATE 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_STDINT_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_STDLIB_H 1 -+ -+/* Define to 1 if you have the header file. */ -+// #define HAVE_STRINGS_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_STRING_H 1 -+ -+/* Define to 1 if the system has the type `struct sctp_assoc_value'. */ -+/* #undef HAVE_STRUCT_SCTP_ASSOC_VALUE */ -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_SYS_SOCKET_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_SYS_STAT_H 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_SYS_TYPES_H 1 -+ -+/* Have TCP_CONGESTION sockopt. */ -+#define HAVE_TCP_CONGESTION 1 -+ -+/* Define to 1 if you have the header file. */ -+#define HAVE_UNISTD_H 1 -+ -+// /* Define to the sub-directory where libtool stores uninstalled libraries. */ -+// #define LT_OBJDIR ".libs/" -+ -+/* Name of package */ -+#define PACKAGE "iperf" -+ -+/* Define to the address where bug reports for this package should be sent. */ -+#define PACKAGE_BUGREPORT "https://github.com/esnet/iperf" -+ -+/* Define to the full name of this package. */ -+#define PACKAGE_NAME "iperf" -+ -+/* Define to the full name and version of this package. */ -+#define PACKAGE_STRING "iperf 3.1.3" -+ -+/* Define to the one symbol short name of this package. */ -+#define PACKAGE_TARNAME "iperf" -+ -+/* Define to the home page for this package. */ -+#define PACKAGE_URL "http://software.es.net/iperf/" -+ -+/* Define to the version of this package. */ -+#define PACKAGE_VERSION "3.1.3" -+ -+/* Define to 1 if you have the ANSI C header files. */ -+#define STDC_HEADERS 1 -+ -+/* Version number of package */ -+#define VERSION "3.1.3" -+ -+/* Define to empty if `const' does not conform to ANSI C. */ -+/* #undef const */ -diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c -index 227ec78..f0a4a30 100644 ---- a/src/iperf_server_api.c -+++ b/src/iperf_server_api.c -@@ -30,7 +30,6 @@ - #include - #include - #include --#include - #include - #include - #include -@@ -47,7 +46,6 @@ - #include - #include - #include --#include - #include - - #include "iperf.h" -diff --git a/src/iperf_util.c b/src/iperf_util.c -index 73dc362..4bfe6f9 100644 ---- a/src/iperf_util.c -+++ b/src/iperf_util.c -@@ -40,7 +40,6 @@ - #include - #include - #include --#include - #include - #include - -@@ -59,17 +58,17 @@ void - make_cookie(char *cookie) - { - static int randomized = 0; -- char hostname[500]; -+ char hostname[500] = "ruxos-iperf"; - struct timeval tv; - char temp[1000]; - - if ( ! randomized ) -- srandom((int) time(0) ^ getpid()); -+ srand((int) time(0) ^ getpid()); - - /* Generate a string based on hostname, time, randomness, and filler. */ -- (void) gethostname(hostname, sizeof(hostname)); -+ // (void) gethostname(hostname, sizeof(hostname)); - (void) gettimeofday(&tv, 0); -- (void) snprintf(temp, sizeof(temp), "%s.%ld.%06ld.%08lx%08lx.%s", hostname, (unsigned long int) tv.tv_sec, (unsigned long int) tv.tv_usec, (unsigned long int) random(), (unsigned long int) random(), "1234567890123456789012345678901234567890"); -+ (void) snprintf(temp, sizeof(temp), "%s.%ld.%06ld.%08lx%08lx.%s", hostname, (unsigned long int) tv.tv_sec, (unsigned long int) tv.tv_usec, (unsigned long int) rand(), (unsigned long int) rand(), "1234567890123456789012345678901234567890"); - - /* Now truncate it to 36 bytes and terminate. */ - memcpy(cookie, temp, 36); -@@ -178,50 +177,25 @@ delay(int us) - void - cpu_util(double pcpu[3]) - { -- static struct timeval last; -- static clock_t clast; -- static struct rusage rlast; -- struct timeval temp; -- clock_t ctemp; -- struct rusage rtemp; -- double timediff; -- double userdiff; -- double systemdiff; -- - if (pcpu == NULL) { -- gettimeofday(&last, NULL); -- clast = clock(); -- getrusage(RUSAGE_SELF, &rlast); - return; - } - -- gettimeofday(&temp, NULL); -- ctemp = clock(); -- getrusage(RUSAGE_SELF, &rtemp); -- -- timediff = ((temp.tv_sec * 1000000.0 + temp.tv_usec) - -- (last.tv_sec * 1000000.0 + last.tv_usec)); -- userdiff = ((rtemp.ru_utime.tv_sec * 1000000.0 + rtemp.ru_utime.tv_usec) - -- (rlast.ru_utime.tv_sec * 1000000.0 + rlast.ru_utime.tv_usec)); -- systemdiff = ((rtemp.ru_stime.tv_sec * 1000000.0 + rtemp.ru_stime.tv_usec) - -- (rlast.ru_stime.tv_sec * 1000000.0 + rlast.ru_stime.tv_usec)); -- -- pcpu[0] = (((ctemp - clast) * 1000000.0 / CLOCKS_PER_SEC) / timediff) * 100; -- pcpu[1] = (userdiff / timediff) * 100; -- pcpu[2] = (systemdiff / timediff) * 100; -+ pcpu[0] =0; -+ pcpu[1] =0; -+ pcpu[2] =0; - } - - const char * - get_system_info(void) - { - static char buf[1024]; -- struct utsname uts; -+ // struct utsname uts; - - memset(buf, 0, 1024); -- uname(&uts); -+ // uname(&uts); - -- snprintf(buf, sizeof(buf), "%s %s %s %s %s", uts.sysname, uts.nodename, -- uts.release, uts.version, uts.machine); -+ snprintf(buf, sizeof(buf), "%s %s %s %s %s", "ruxos", "iperf", "0", "0","null"); - - return buf; - } -diff --git a/src/main_server.c b/src/main_server.c -new file mode 100644 -index 0000000..c9964ba ---- /dev/null -+++ b/src/main_server.c -@@ -0,0 +1,42 @@ -+#include -+#include -+#include -+#include -+ -+#include -+ -+#include "iperf_api.h" -+ -+int main() { -+ int port; -+ struct iperf_test *test; -+ int consecutive_errors; -+ -+ port = 5555; -+ -+ test = iperf_new_test(); -+ if (test == NULL) { -+ printf("failed to create test\n"); -+ exit(-1); -+ } -+ iperf_defaults(test); -+ iperf_set_test_role(test, 's'); -+ iperf_set_test_server_port(test, port); -+ iperf_set_test_bind_address(test, "0.0.0.0"); -+ consecutive_errors = 0; -+ for (;;) { -+ if (iperf_run_server(test) < 0) { -+ printf("error - %s\n\n", iperf_strerror(i_errno)); -+ ++consecutive_errors; -+ if (consecutive_errors >= 5) { -+ printf("too many errors, exiting\n"); -+ break; -+ } -+ } else -+ consecutive_errors = 0; -+ iperf_reset_test(test); -+ } -+ -+ iperf_free_test(test); -+ return 0; -+} -diff --git a/src/net.c b/src/net.c -index aa4a15c..80271e2 100644 ---- a/src/net.c -+++ b/src/net.c -@@ -31,13 +31,13 @@ - #include - #include - #include --#include -+#include - #include - #include - #include - #include - #include --#include -+#include - - #ifdef HAVE_SENDFILE - #ifdef linux -diff --git a/src/tcp_info.c b/src/tcp_info.c -index 76b117a..950ab41 100644 ---- a/src/tcp_info.c -+++ b/src/tcp_info.c -@@ -45,7 +45,7 @@ - - #include - #include --#include -+// #include - #include - #include - #include -diff --git a/src/units.c b/src/units.c -index ed1ea60..3d590db 100644 ---- a/src/units.c -+++ b/src/units.c -@@ -78,116 +78,6 @@ extern "C" - const long MEGA_RATE_UNIT = 1000 * 1000; - const long GIGA_RATE_UNIT = 1000 * 1000 * 1000; - --/* ------------------------------------------------------------------- -- * unit_atof -- * -- * Given a string of form #x where # is a number and x is a format -- * character listed below, this returns the interpreted integer. -- * Gg, Mm, Kk are giga, mega, kilo respectively -- * ------------------------------------------------------------------- */ -- -- double unit_atof(const char *s) -- { -- double n; -- char suffix = '\0'; -- -- assert(s != NULL); -- -- /* scan the number and any suffices */ -- sscanf(s, "%lf%c", &n, &suffix); -- -- /* convert according to [Gg Mm Kk] */ -- switch (suffix) -- { -- case 'g': case 'G': -- n *= GIGA_UNIT; -- break; -- case 'm': case 'M': -- n *= MEGA_UNIT; -- break; -- case 'k': case 'K': -- n *= KILO_UNIT; -- break; -- default: -- break; -- } -- return n; -- } /* end unit_atof */ -- -- --/* ------------------------------------------------------------------- -- * unit_atof_rate -- * -- * Similar to unit_atof, but uses 10-based rather than 2-based -- * suffixes. -- * ------------------------------------------------------------------- */ -- -- double unit_atof_rate(const char *s) -- { -- double n; -- char suffix = '\0'; -- -- assert(s != NULL); -- -- /* scan the number and any suffices */ -- sscanf(s, "%lf%c", &n, &suffix); -- -- /* convert according to [Gg Mm Kk] */ -- switch (suffix) -- { -- case 'g': case 'G': -- n *= GIGA_RATE_UNIT; -- break; -- case 'm': case 'M': -- n *= MEGA_RATE_UNIT; -- break; -- case 'k': case 'K': -- n *= KILO_RATE_UNIT; -- break; -- default: -- break; -- } -- return n; -- } /* end unit_atof_rate */ -- -- -- --/* ------------------------------------------------------------------- -- * unit_atoi -- * -- * Given a string of form #x where # is a number and x is a format -- * character listed below, this returns the interpreted integer. -- * Gg, Mm, Kk are giga, mega, kilo respectively -- * ------------------------------------------------------------------- */ -- -- iperf_size_t unit_atoi(const char *s) -- { -- double n; -- char suffix = '\0'; -- -- assert(s != NULL); -- -- /* scan the number and any suffices */ -- sscanf(s, "%lf%c", &n, &suffix); -- -- /* convert according to [Gg Mm Kk] */ -- switch (suffix) -- { -- case 'g': case 'G': -- n *= GIGA_UNIT; -- break; -- case 'm': case 'M': -- n *= MEGA_UNIT; -- break; -- case 'k': case 'K': -- n *= KILO_UNIT; -- break; -- default: -- break; -- } -- return (iperf_size_t) n; -- } /* end unit_atof */ -- - /* ------------------------------------------------------------------- - * constants for byte_printf - * ------------------------------------------------------------------- */ -diff --git a/src/units.h b/src/units.h -index 6ab9216..437c89d 100644 ---- a/src/units.h -+++ b/src/units.h -@@ -28,7 +28,4 @@ enum { - UNIT_LEN = 32 - }; - --double unit_atof( const char *s ); --double unit_atof_rate( const char *s ); --iperf_size_t unit_atoi( const char *s ); - void unit_snprintf( char *s, int inLen, double inNum, char inFormat ); -diff --git a/src/version.h b/src/version.h -new file mode 100644 -index 0000000..db8f001 ---- /dev/null -+++ b/src/version.h -@@ -0,0 +1,27 @@ -+/* -+ * iperf, Copyright (c) 2014, The Regents of the University of -+ * California, through Lawrence Berkeley National Laboratory (subject -+ * to receipt of any required approvals from the U.S. Dept. of -+ * Energy). All rights reserved. -+ * -+ * If you have questions about your rights to use or distribute this -+ * software, please contact Berkeley Lab's Technology Transfer -+ * Department at TTD@lbl.gov. -+ * -+ * NOTICE. This software is owned by the U.S. Department of Energy. -+ * As such, the U.S. Government has been granted for itself and others -+ * acting on its behalf a paid-up, nonexclusive, irrevocable, -+ * worldwide license in the Software to reproduce, prepare derivative -+ * works, and perform publicly and display publicly. Beginning five -+ * (5) years after the date permission to assert copyright is obtained -+ * from the U.S. Department of Energy, and subject to any subsequent -+ * five (5) year renewals, the U.S. Government is granted for itself -+ * and others acting on its behalf a paid-up, nonexclusive, -+ * irrevocable, worldwide license in the Software to reproduce, -+ * prepare derivative works, distribute copies to the public, perform -+ * publicly and display publicly, and to permit others to do so. -+ * -+ * This code is distributed under a BSD style license, see the LICENSE -+ * file for complete information. -+ */ -+#define IPERF_VERSION "3.1.3" diff --git a/apps/c/nginx/.gitignore b/apps/c/nginx/.gitignore deleted file mode 100755 index a55620f53..000000000 --- a/apps/c/nginx/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -nginx-* -html -*.img -mnt -objs diff --git a/apps/c/nginx/README.md b/apps/c/nginx/README.md deleted file mode 100644 index cd532236b..000000000 --- a/apps/c/nginx/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# How to run nginx on ruxos - -## commands - -### download web page - -You should make sure there is a html folder in apps/c/nginx which contains the web page of nginx server. - -If you not use your own web page , you can run commands below: - -```shell -git clone https://github.com/syswonder/syswonder-web.git -mkdir -p apps/c/nginx/html -cp -r syswonder-web/docs/* apps/c/nginx/html -rm -f -r syswonder-web -``` - -### run nginx - -The commands below is to run nginx with different features. These examples run in aarch64 with musl, if you want to run in x86_64, just replace `ARCH=aarch64` with `ARCH=x86_64`, and if you do not want to run with musl , just delete `MUSL=y`. - -use v9p and musl in aarch64: - -```shell -make A=apps/c/nginx/ LOG=info NET=y BLK=y V9P=y V9P_PATH=apps/c/nginx/html/ ARCH=aarch64 SMP=4 ARGS="./nginx_app" MUSL=y run -``` - -not use v9p,but use musl in aarch64: - -```shell -make A=apps/c/nginx/ LOG=info NET=y BLK=y ARCH=aarch64 SMP=4 ARGS="./nginx_app" MUSL=y run -``` - -If you change running option or source code , remember to clean the compile files and before running. - -```shell -make clean_c A=apps/c/nginx -``` - -# nginx conf - -You can change next files to change nginx conf: - -`/nginx/conf/nginx.conf` - -`/nginx/conf/mime.types` - -After change you should copy them to disk.img (you can run `apps/c/nginx/create_nginx_img.sh` to do that) - diff --git a/apps/c/nginx/axbuild.mk b/apps/c/nginx/axbuild.mk deleted file mode 100755 index d52d70d1a..000000000 --- a/apps/c/nginx/axbuild.mk +++ /dev/null @@ -1,48 +0,0 @@ -nginx-version = 1.24.0 -nginx-src := $(APP)/nginx-$(nginx-version) -nginx-objdir := $(APP)/objs -nginx-objs := objs/nginx_app.o - -app-objs := $(nginx-objs) - -CFLAGS += -Wno-format - -nginx-build-args := \ - CC=$(CC) \ - CFLAGS="$(CFLAGS)" \ - USE_JEMALLOC=no \ - -j - -ifneq ($(V),) - nginx-build-args += V=$(V) -endif - -ifeq ($(V9P),y) - DISK_ARG = 9p -else - DISK_ARG = no_9p -endif - - -disk.img: - echo "nginx makefile create_nginx_img" - ./$(APP)/create_nginx_img.sh $(DISK_ARG) - -$(nginx-objdir): - git clone https://github.com/lhw2002426/nginx-app.git -b nginx-objs $(APP)/objs - -$(nginx-src): - @echo "Download nginx source code" - wget https://nginx.org/download/nginx-$(nginx-version).tar.gz -P $(APP) - tar -zxvf $(APP)/nginx-$(nginx-version).tar.gz -C $(APP) && rm -f $(APP)/nginx-$(nginx-version).tar.gz - -$(APP)/$(nginx-objs): build_nginx - -clean_c:: - find . -type f \( -name "*.o" -o -name "*.elf" -o -name "*.bin" \) -exec rm -f {} + - -build_nginx: $(nginx-src) disk.img $(nginx-objdir) - cd $(nginx-objdir) && $(MAKE) $(nginx-build-args) - - -.PHONY: build_nginx diff --git a/apps/c/nginx/create_nginx_img.sh b/apps/c/nginx/create_nginx_img.sh deleted file mode 100755 index 84f725261..000000000 --- a/apps/c/nginx/create_nginx_img.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# From https://github.com/rafalh/rust-fatfs/blob/master/scripts/create-test-img.sh -CUR_DIR=$(dirname $0) - -echo $OUT_DIR - -if [ $# -lt 1 ]; then - CONF="$CUR_DIR/nginx.conf" - echo "not us 9p" -elif [ "$1" == "9p" ]; then - CONF="$CUR_DIR/nginx_9p.conf" - echo "use 9p" -else - CONF="$CUR_DIR/nginx.conf" - echo "not use 9p" -fi - -create_test_img() { - local name=$1 - local blkcount=$2 - local fatSize=$3 - dd if=/dev/zero of="$name" bs=1024 count=$blkcount - mkfs.vfat -s 1 -F $fatSize -n "Test!" -i 12345678 "$name" - mkdir -p mnt - sudo mount -o loop "$name" mnt -o rw,uid=$USER,gid=$USER - mkdir -p "mnt/nginx/logs" - mkdir -p "mnt/etc" - echo "" >> "mnt/etc/localtime" - echo "root:x:0:0:root:/root:/bin/bash" >> "mnt/etc/passwd" - echo "root:x:0:" >> "mnt/etc/group" - mkdir -p "mnt/nginx/conf" - cp "$CONF" "mnt/nginx/conf/nginx.conf" - cp "$CUR_DIR/mime.types" "mnt/nginx/conf/mime.types" - mkdir -p "mnt/html" - cp -r "$CUR_DIR/html" "mnt/" - sudo umount mnt -} - -create_test_img "$CUR_DIR/fat32.img" 40000 32 -echo $CUR_DIR -echo "nginx create disk" -rm -f disk.img -cp $CUR_DIR/fat32.img disk.img diff --git a/apps/c/nginx/features.txt b/apps/c/nginx/features.txt deleted file mode 100755 index 7ac64ecbf..000000000 --- a/apps/c/nginx/features.txt +++ /dev/null @@ -1,14 +0,0 @@ -alloc -paging -fp_simd -irq -multitask -fs -blkfs -net -pipe -epoll -poll -select -virtio-9p -rtc diff --git a/apps/c/nginx/mime.types b/apps/c/nginx/mime.types deleted file mode 100755 index dd757ddb4..000000000 --- a/apps/c/nginx/mime.types +++ /dev/null @@ -1,98 +0,0 @@ - -types { - text/markdown md; - text/html html htm shtml; - text/css css; - text/xml xml; - image/gif gif; - image/jpeg jpeg jpg; - application/javascript js; - application/atom+xml atom; - application/rss+xml rss; - - text/mathml mml; - text/plain txt; - text/vnd.sun.j2me.app-descriptor jad; - text/vnd.wap.wml wml; - text/x-component htc; - - image/png png; - image/svg+xml svg svgz; - image/tiff tif tiff; - image/vnd.wap.wbmp wbmp; - image/webp webp; - image/x-icon ico; - image/x-jng jng; - image/x-ms-bmp bmp; - - font/woff woff; - font/woff2 woff2; - - application/java-archive jar war ear; - application/json json; - application/mac-binhex40 hqx; - application/msword doc; - application/pdf pdf; - application/postscript ps eps ai; - application/rtf rtf; - application/vnd.apple.mpegurl m3u8; - application/vnd.google-earth.kml+xml kml; - application/vnd.google-earth.kmz kmz; - application/vnd.ms-excel xls; - application/vnd.ms-fontobject eot; - application/vnd.ms-powerpoint ppt; - application/vnd.oasis.opendocument.graphics odg; - application/vnd.oasis.opendocument.presentation odp; - application/vnd.oasis.opendocument.spreadsheet ods; - application/vnd.oasis.opendocument.text odt; - application/vnd.openxmlformats-officedocument.presentationml.presentation - pptx; - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - xlsx; - application/vnd.openxmlformats-officedocument.wordprocessingml.document - docx; - application/vnd.wap.wmlc wmlc; - application/x-7z-compressed 7z; - application/x-cocoa cco; - application/x-java-archive-diff jardiff; - application/x-java-jnlp-file jnlp; - application/x-makeself run; - application/x-perl pl pm; - application/x-pilot prc pdb; - application/x-rar-compressed rar; - application/x-redhat-package-manager rpm; - application/x-sea sea; - application/x-shockwave-flash swf; - application/x-stuffit sit; - application/x-tcl tcl tk; - application/x-x509-ca-cert der pem crt; - application/x-xpinstall xpi; - application/xhtml+xml xhtml; - application/xspf+xml xspf; - application/zip zip; - - application/octet-stream bin exe dll; - application/octet-stream deb; - application/octet-stream dmg; - application/octet-stream iso img; - application/octet-stream msi msp msm; - - audio/midi mid midi kar; - audio/mpeg mp3; - audio/ogg ogg; - audio/x-m4a m4a; - audio/x-realaudio ra; - - video/3gpp 3gpp 3gp; - video/mp2t ts; - video/mp4 mp4; - video/mpeg mpeg mpg; - video/quicktime mov; - video/webm webm; - video/x-flv flv; - video/x-m4v m4v; - video/x-mng mng; - video/x-ms-asf asx asf; - video/x-ms-wmv wmv; - video/x-msvideo avi; -} diff --git a/apps/c/nginx/nginx.conf b/apps/c/nginx/nginx.conf deleted file mode 100755 index 95dbabebb..000000000 --- a/apps/c/nginx/nginx.conf +++ /dev/null @@ -1,40 +0,0 @@ -worker_processes 1; -daemon off; -master_process off; - -error_log logs/error.log debug; - -events { - worker_connections 32; -} - -http { - include mime.types; - default_type application/octet-stream; - - keepalive_timeout 65; - - server { - listen 5555; - server_name localhost; - - index index.html; - - root /html; - - location / { - try_files $uri $uri/ /404.html; - } - - error_page 404 /404.html; - location = /404.html { - root /html; - } - - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /html; - } - - } -} diff --git a/apps/c/nginx/nginx_9p.conf b/apps/c/nginx/nginx_9p.conf deleted file mode 100755 index 41217be52..000000000 --- a/apps/c/nginx/nginx_9p.conf +++ /dev/null @@ -1,40 +0,0 @@ -worker_processes 1; -daemon off; -master_process off; - -error_log logs/error.log debug; - -events { - worker_connections 32; -} - -http { - include mime.types; - default_type application/octet-stream; - - keepalive_timeout 65; - - server { - listen 5555; - server_name localhost; - - index index.html; - - root /v9fs; - - location / { - try_files $uri $uri/ /404.html; - } - - error_page 404 /404.html; - location = /404.html { - root /v9fs; - } - - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /v9fs; - } - - } -} diff --git a/apps/c/redis/.gitignore b/apps/c/redis/.gitignore deleted file mode 100644 index 7905e7add..000000000 --- a/apps/c/redis/.gitignore +++ /dev/null @@ -1 +0,0 @@ -redis-* diff --git a/apps/c/redis/Makefile b/apps/c/redis/Makefile deleted file mode 100644 index 59d5315b8..000000000 --- a/apps/c/redis/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# Build for linux - -ARCH ?= x86_64 - -CC := $(ARCH)-linux-musl-gcc - -CFLAGS := -LDFLAGS := -static -no-pie - -redis-version := 7.0.12 -redis-dir := $(CURDIR)/redis-$(redis-version) -redis-objs := $(redis-dir)/src/redis-server.o -redis-bin := redis-server - -redis-build-args := \ - CC=$(CC) \ - CFLAGS="$(CFLAGS)" \ - USE_JEMALLOC=no \ - -j - -ifneq ($(V),) - redis-build-args += V=$(V) -endif - -all: build - -$(redis-dir): - @echo "Download redis source code" - wget https://github.com/redis/redis/archive/$(redis-version).tar.gz -P $(APP) - tar -zxvf $(APP)/$(redis-version).tar.gz -C $(APP) && rm -f $(APP)/$(redis-version).tar.gz - cd $(redis-dir) && git init && git add . - patch -p1 -N -d $(redis-dir) --no-backup-if-mismatch -r - < $(APP)/redis.patch - -build: $(redis-dir) - cd $(redis-dir) && $(MAKE) $(redis-build-args) - $(CC) $(LDFLAGS) -o $(redis-bin) $(redis-objs) - -run: - ./$(redis-bin) - -clean: - $(MAKE) -C $(redis-dir) distclean - rm -f $(redis-bin) - -.PHONY: all build clean diff --git a/apps/c/redis/README.md b/apps/c/redis/README.md deleted file mode 100644 index 683a12ebf..000000000 --- a/apps/c/redis/README.md +++ /dev/null @@ -1,355 +0,0 @@ - -# How to run? -- Run: - - - for aarch64 - - ``` - make A=apps/c/redis/ LOG=error NET=y BLK=y ARCH=aarch64 SMP=4 ARGS="./redis-server,--bind,0.0.0.0,--port,5555,--save,\"\",--appendonly,no,--protected-mode,no,--ignore-warnings,ARM64-COW-BUG" run - ``` - - - for x86_64 - - ``` - make A=apps/c/redis/ LOG=error NET=y BLK=y ARCH=x86_64 SMP=4 ARGS="./redis-server,--bind,0.0.0.0,--port,5555,--save,\"\",--appendonly,no,--protected-mode,no" run - ``` - - - version 3 for aarch64(using 9pfs) - ``` - make A=apps/c/redis/ LOG=error NET=y V9P=y BLK=y V9P_PATH=apps/c/redis ARCH=aarch64 SMP=4 ARGS="./redis-server,/v9fs/redis.conf" run - ``` - - - version 3 for x86_64(using 9pfs) - ``` - make A=apps/c/redis/ LOG=error NET=y V9P=y BLK=y V9P_PATH=apps/c/redis ARCH=x86_64 SMP=4 ARGS="./redis-server,/v9fs/redis.conf" run - ``` - - -# How to test? -- Use `redis-cli -p 5555` to connect to redis-server, and enjoy Ruxos-Redis world! -- Use `redis-benchmark -p 5555` and other optional parameters to run the benchmark. - - Like: `redis-benchmark -p 5555 -n 5 -q -c 10`, this command issues 5 requests for each commands (like `set`, `get`, etc.), with 10 concurrency. - - `LRANGE_xxx` test may fail because of running out of memory(Follow notes 4, 5). - -# Notes -- Only test "aarch64". -- Use `SMP=xxx`. -- Must run `make clean`, this may be changed later. -- Enlarge memory size in `qemu.mk` and `qemu-virt-aarch64.toml` to 2G. -- Extend fd number to 4096, and comment out corresponding checks in `flatten_objects`. - -# Some test result -## AARCH64 -### SET and GET: -- Here test `SET` and `GET` throughput.(30 conns, 100k requests like `unikraft`) -- command: - - `redis-benchmark -p 5555 -n 100000 -q -t set -c 30` - - `redis-benchmark -p 5555 -n 100000 -q -t get -c 30` -- 0630 - -| Operation | Op number | Concurrency | Round | Result(request per seconds) | -|-|-|-|-|-| -| SET | 100K | 30 | 1 | 11921.79 | -| | | | 2 | 11873.66 | -| | | | 3 | 11499.54 | -| | | | 4 | 12001.92 | -| | | | 5 | 11419.44 | -| GET | 100K | 30 | 1 | 13002.21 | -| | | | 2 | 12642.23 | -| | | | 3 | 13674.28 | -| | | | 4 | 12987.01 | -| | | | 5 | 12853.47 | - -- 0710(Extend disk size) - -| Operation | Op number | Concurrency | Round | Result(request per seconds) | -|-|-|-|-|-| -| SET | 100K | 30 | 1 | 12740.48 | -| | | | 2 | 13150.97 | -| | | | 3 | 13147.52 | -| | | | 4 | 12898.23 | -| | | | 5 | 12918.23 | -| GET | 100K | 30 | 1 | 13253.81 | -| | | | 2 | 14332.81 | -| | | | 3 | 14600.67 | -| | | | 4 | 13974.29 | -| | | | 5 | 14005.60 | - -- 0714(Update net implementation, maximum: 2.9w(set)) - -| Operation | Op number | Concurrency | Round | Result(request per seconds) | -|-|-|-|-|-| -| SET | 100K | 30 | 1 | 25713.55 | -| | | | 2 | 25246.15 | -| | | | 3 | 24968.79 | -| | | | 4 | 25018.76 | -| | | | 5 | 25348.54 | -| GET | 100K | 30 | 1 | 27917.37 | -| | | | 2 | 28360.75 | -| | | | 3 | 27525.46 | -| | | | 4 | 27901.79 | -| | | | 5 | 27495.19 | - -### Other tests, one round -- Do other tests. -- Use `config set save ""` to avoid rapidly saving. -- Use `-c 30` - -- 0704 - -| Operation | Op number | Concurrency | Round | Result(request per seconds) | -|-|-|-|-|-| -| PING_INLINE | 100K | 30 | 1 | 12147.72 | -| INCR | 100K | 30 | 1 | 13097.58 | -| LPUSH | 100K | 30 | 1 | 12955.05 | -| RPUSH | 100K | 30 | 1 | 11339.15 | -| LPOP | 100K | 30 | 1 | 12611.93 | -| RPOP | 100K | 30 | 1 | 13106.16 | -| SADD | 100K | 30 | 1 | 12773.02 | -| HSET | 100K | 30 | 1 | 11531.37 | -| SPOP | 100K | 30 | 1 | 12918.23 | -| ZADD | 100K | 30 | 1 | 10462.44 | -| ZPOPMIN | 100K | 30 | 1 | 12817.23 | -| LRANGE_100 | 100K | 30 | 1 | 6462.45 | -| LRANGE_300 | 100K | 30 | 1 | 3318.84 | -| LRANGE_500 | 100K | 30 | 1 | 2522.13 | -| LRANGE_600 | 100K | 30 | 1 | 1877.30 | -| MSET | 100K | 30 | 1 | 8929.37 | - -- 0714 -``` -PING_INLINE: 28768.70 requests per second -PING_BULK: 31347.96 requests per second -SET: 23185.72 requests per second -GET: 25700.33 requests per second -INCR: 25746.65 requests per second -LPUSH: 20416.50 requests per second -RPUSH: 20868.12 requests per second -LPOP: 20370.75 requests per second -RPOP: 19956.10 requests per second -SADD: 25361.40 requests per second -HSET: 21431.63 requests per second -SPOP: 25438.82 requests per second -ZADD: 23820.87 requests per second -ZPOPMIN: 26954.18 requests per second -LPUSH (needed to benchmark LRANGE): 26385.22 requests per second -LRANGE_100 (first 100 elements): 23912.00 requests per second -LRANGE_300 (first 300 elements): 22665.46 requests per second -LRANGE_500 (first 450 elements): 23369.95 requests per second -LRANGE_600 (first 600 elements): 22256.84 requests per second -MSET (10 keys): 18460.40 requests per second -``` - -## X86_64 -### SET and GET -- command: - - `redis-benchmark -p 5555 -n 100000 -q -t set -c 30` - - `redis-benchmark -p 5555 -n 100000 -q -t get -c 30` - -- 0710 - -| Operation | Op number | Concurrency | Round | Result(request per seconds) | -|-|-|-|-|-| -| SET | 100K | 30 | 1 | 30931.02 | -| | | | 2 | 32258.07 | -| | | | 3 | 30571.69 | -| | | | 4 | 33344.45 | -| | | | 5 | 31655.59 | -| GET | 100K | 30 | 1 | 33523.30 | -| | | | 2 | 33134.53 | -| | | | 3 | 30450.67 | -| | | | 4 | 33178.50 | -| | | | 5 | 32268.47 | - -- 0714 - -| Operation | Op number | Concurrency | Round | Result(request per seconds) | -|-|-|-|-|-| -| SET | 100K | 30 | 1 | 105263.16 | -| | | | 2 | 105263.16 | -| | | | 3 | 103950.10 | -| | | | 4 | 107758.62 | -| | | | 5 | 105820.11 | -| GET | 100K | 30 | 1 | 103199.18 | -| | | | 2 | 104058.27 | -| | | | 3 | 99502.48 | -| | | | 4 | 106951.88 | -| | | | 5 | 105263.16 | - -### Other tests - -- 0710 - -| Operation | Op number | Concurrency | Round | Result(request per seconds) | -|-|-|-|-|-| -| PING_INLINE | 100K | 30 | 1 | 32992.41 | -| INCR | 100K | 30 | 1 | 32467.53 | -| LPUSH | 100K | 30 | 1 | 29815.14 | -| RPUSH | 100K | 30 | 1 | 30864.20 | -| LPOP | 100K | 30 | 1 | 34094.78 | -| RPOP | 100K | 30 | 1 | 31133.25 | -| SADD | 100K | 30 | 1 | 32948.93 | -| HSET | 100K | 30 | 1 | 31036.62 | -| SPOP | 100K | 30 | 1 | 32916.39 | -| ZADD | 100K | 30 | 1 | 30693.68 | -| ZPOPMIN | 100K | 30 | 1 | 31525.85 | -| LRANGE_100 | 100K | 30 | 1 | 22925.26 | -| LRANGE_300 | 100K | 30 | 1 | 7404.12 | -| LRANGE_500 | 100K | 30 | 1 | 9320.53 | -| LRANGE_600 | 100K | 30 | 1 | 7760.96 | -| MSET | 100K | 30 | 1 | 31269.54 | - -- 0714 - -``` -PING_INLINE: 111607.14 requests per second -PING_BULK: 102880.66 requests per second -SET: 80971.66 requests per second -GET: 103519.66 requests per second -INCR: 98425.20 requests per second -LPUSH: 70274.07 requests per second -RPUSH: 108108.11 requests per second -LPOP: 53561.86 requests per second -RPOP: 100200.40 requests per second -SADD: 62150.41 requests per second -HSET: 99009.90 requests per second -SPOP: 104712.05 requests per second -ZADD: 105263.16 requests per second -ZPOPMIN: 110497.24 requests per second -LPUSH (needed to benchmark LRANGE): 74682.60 requests per second -LRANGE_100 (first 100 elements): 62305.30 requests per second -LRANGE_300 (first 300 elements): 8822.23 requests per second -LRANGE_500 (first 450 elements): 22446.69 requests per second -LRANGE_600 (first 600 elements): 17280.11 requests per second -MSET (10 keys): 92081.03 requests per second -``` - -- Comparing to local Redis server -``` -PING_INLINE: 176056.33 requests per second -PING_BULK: 173611.12 requests per second -SET: 175131.36 requests per second -GET: 174825.17 requests per second -INCR: 177304.97 requests per second -LPUSH: 176678.45 requests per second -RPUSH: 176056.33 requests per second -LPOP: 178253.12 requests per second -RPOP: 176678.45 requests per second -SADD: 175746.92 requests per second -HSET: 176991.16 requests per second -SPOP: 176991.16 requests per second -ZADD: 177619.89 requests per second -ZPOPMIN: 176056.33 requests per second -LPUSH (needed to benchmark LRANGE): 178253.12 requests per second -LRANGE_100 (first 100 elements): 113895.21 requests per second -LRANGE_300 (first 300 elements): 50942.43 requests per second -LRANGE_500 (first 450 elements): 35186.49 requests per second -LRANGE_600 (first 600 elements): 28320.59 requests per second -MSET (10 keys): 183150.19 requests per second -``` - -## Unikraft -### AARCH64: -- `redis-benchmark -h 172.44.0.2 -q -n 100000 -c 30` -- Separately: - ``` - SET: 13814.06 requests per second - GET: 15297.54 requests per second - ``` -- The whole benchmark: - ``` - PING_INLINE: 14369.88 requests per second - PING_BULK: 13335.11 requests per second - SET: 13650.01 requests per second - GET: 12103.61 requests per second - INCR: 13395.85 requests per second - LPUSH: 10279.61 requests per second - RPUSH: 12536.04 requests per second - LPOP: 9541.07 requests per second - RPOP: 12540.76 requests per second - SADD: 11880.72 requests per second - HSET: 12318.30 requests per second - SPOP: 12235.41 requests per second - ZADD: 12130.03 requests per second - ZPOPMIN: 12223.45 requests per second - LPUSH (needed to benchmark LRANGE): 11125.95 requests per second - LRANGE_100 (first 100 elements): 6791.17 requests per second - LRANGE_300 (first 300 elements): 3772.30 requests per second - LRANGE_500 (first 450 elements): 2779.71 requests per second - LRANGE_600 (first 600 elements): 2230.80 requests per second - MSET (10 keys): 9215.74 requests per second - ``` -### X86_64 - -# Run Ruxos-Redis On PC - -## Notification - -- Comment out `spt_init()`(Already patched). -- It will be nicer to comment out `pthread_cond_wait` as well. - -## Compile and Run - -- `make A=apps/c/redis LOG=error PLATFORM=x86_64-pc-oslab SMP=4 FEATURES=driver-ixgbe,driver-ramdisk IP=10.2.2.2 GW=10.2.2.1` -- Copy `redis_x86_64-pc-oslab.elf` to `/boot`, then reboot. -- Enter `grub` then boot the PC by Ruxos Redis. -- Connect to Ruxos-Redis server by: - - `redis-cli -p 5555 -h 10.2.2.2` - - `redis-benchmark -p 5555 -h 10.2.2.2` - -## Test Result - -### Qemu - -- 0801 - -``` -PING_INLINE: 54171.18 requests per second -PING_BULK: 69156.30 requests per second -SET: 70274.07 requests per second -GET: 71479.62 requests per second -INCR: 65876.16 requests per second -LPUSH: 53850.30 requests per second -RPUSH: 53908.36 requests per second -LPOP: 67704.80 requests per second -RPOP: 69832.40 requests per second -SADD: 69444.45 requests per second -HSET: 69541.03 requests per second -SPOP: 69492.70 requests per second -ZADD: 53879.31 requests per second -ZPOPMIN: 53908.36 requests per second -LPUSH (needed to benchmark LRANGE): 37216.23 requests per second -LRANGE_100 (first 100 elements): 48123.20 requests per second -LRANGE_300 (first 300 elements): 7577.48 requests per second -LRANGE_500 (first 450 elements): 15288.18 requests per second -LRANGE_600 (first 600 elements): 12371.64 requests per second -MSET (10 keys): 54318.30 requests per second -``` - -### Real Machine - -- 0801 - -``` -PING_INLINE: 71377.59 requests per second -PING_BULK: 74571.22 requests per second -SET: 75642.96 requests per second -GET: 75872.54 requests per second -INCR: 76394.20 requests per second -LPUSH: 75815.01 requests per second -RPUSH: 75930.14 requests per second -LPOP: 75528.70 requests per second -RPOP: 75585.79 requests per second -SADD: 75815.01 requests per second -HSET: 75757.57 requests per second -SPOP: 75930.14 requests per second -ZADD: 75757.57 requests per second -ZPOPMIN: 75757.57 requests per second -LPUSH (needed to benchmark LRANGE): 75471.70 requests per second -LRANGE_100 (first 100 elements): 52438.39 requests per second -LRANGE_300 (first 300 elements): 677.74 requests per second -LRANGE_500 (first 450 elements): 16485.33 requests per second -LRANGE_600 (first 600 elements): 13159.63 requests per second -MSET (10 keys): 72780.20 requests per second -``` - diff --git a/apps/c/redis/axbuild.mk b/apps/c/redis/axbuild.mk deleted file mode 100644 index a6d99fdd9..000000000 --- a/apps/c/redis/axbuild.mk +++ /dev/null @@ -1,34 +0,0 @@ -redis-version := 7.0.12 -redis-dir := $(APP)/redis-$(redis-version) -redis-objs := redis-$(redis-version)/src/redis-server.o - -app-objs := $(redis-objs) - -CFLAGS += -Wno-format - -redis-build-args := \ - CC=$(CC) \ - CFLAGS="$(CFLAGS)" \ - USE_JEMALLOC=no \ - -j - -ifneq ($(V),) - redis-build-args += V=$(V) -endif - -$(redis-dir): - @echo "Download redis source code" - wget https://github.com/redis/redis/archive/$(redis-version).tar.gz -P $(APP) - tar -zxvf $(APP)/$(redis-version).tar.gz -C $(APP) && rm -f $(APP)/$(redis-version).tar.gz - cd $(redis-dir) && git init && git add . - patch -p1 -N -d $(redis-dir) --no-backup-if-mismatch -r - < $(APP)/redis.patch - -$(APP)/$(redis-objs): build_redis - -build_redis: $(redis-dir) - cd $(redis-dir) && $(MAKE) $(redis-build-args) - -clean_c:: - $(MAKE) -C $(redis-dir) distclean - -.PHONY: build_redis clean_c diff --git a/apps/c/redis/features.txt b/apps/c/redis/features.txt deleted file mode 100644 index 71894bdb9..000000000 --- a/apps/c/redis/features.txt +++ /dev/null @@ -1,13 +0,0 @@ -alloc -paging -fp_simd -irq -multitask -fs -blkfs -net -pipe -epoll -poll -virtio-9p -rtc diff --git a/apps/c/redis/redis.conf b/apps/c/redis/redis.conf deleted file mode 100644 index a1ad469b8..000000000 --- a/apps/c/redis/redis.conf +++ /dev/null @@ -1,6 +0,0 @@ -bind 0.0.0.0 -port 5555 -protected-mode no -save "" -appendonly no -ignore-warnings ARM64-COW-BUG diff --git a/apps/c/redis/redis.patch b/apps/c/redis/redis.patch deleted file mode 100644 index 9e95c5f9c..000000000 --- a/apps/c/redis/redis.patch +++ /dev/null @@ -1,82 +0,0 @@ -diff --git a/src/Makefile b/src/Makefile -index e4f7d90..1b41e94 100644 ---- a/src/Makefile -+++ b/src/Makefile -@@ -16,7 +16,7 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh') - uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') - uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not') - OPTIMIZATION?=-O2 --DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram -+DEPENDENCY_TARGETS=hiredis lua hdr_histogram - NODEPS:=clean distclean - - # Default settings -@@ -37,14 +37,7 @@ OPT=$(OPTIMIZATION) - # Detect if the compiler supports C11 _Atomic. - # NUMBER_SIGN_CHAR is a workaround to support both GNU Make 4.3 and older versions. - NUMBER_SIGN_CHAR := \# --C11_ATOMIC := $(shell sh -c 'echo "$(NUMBER_SIGN_CHAR)include " > foo.c; \ -- $(CC) -std=c11 -c foo.c -o foo.o > /dev/null 2>&1; \ -- if [ -f foo.o ]; then echo "yes"; rm foo.o; fi; rm foo.c') --ifeq ($(C11_ATOMIC),yes) -- STD+=-std=c11 --else -- STD+=-std=c99 --endif -+STD+=-std=c99 - - PREFIX?=/usr/local - INSTALL_BIN=$(PREFIX)/bin -@@ -316,6 +309,7 @@ endif - - REDIS_SERVER_NAME=redis-server$(PROG_SUFFIX) - REDIS_SENTINEL_NAME=redis-sentinel$(PROG_SUFFIX) -+REDIS_SERVER_LIB=redis-server.o - REDIS_SERVER_OBJ=adlist.o quicklist.o ae.o anet.o dict.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o eval.o bio.o rio.o rand.o memtest.o syscheck.o crcspeed.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o redis-check-rdb.o redis-check-aof.o geo.o lazyfree.o module.o evict.o expire.o geohash.o geohash_helper.o childinfo.o defrag.o siphash.o rax.o t_stream.o listpack.o localtime.o lolwut.o lolwut5.o lolwut6.o acl.o tracking.o connection.o tls.o sha256.o timeout.o setcpuaffinity.o monotonic.o mt19937-64.o resp_parser.o call_reply.o script_lua.o script.o functions.o function_lua.o commands.o - REDIS_CLI_NAME=redis-cli$(PROG_SUFFIX) - REDIS_CLI_OBJ=anet.o adlist.o dict.o redis-cli.o zmalloc.o release.o ae.o redisassert.o crcspeed.o crc64.o siphash.o crc16.o monotonic.o cli_common.o mt19937-64.o -@@ -323,9 +317,9 @@ REDIS_BENCHMARK_NAME=redis-benchmark$(PROG_SUFFIX) - REDIS_BENCHMARK_OBJ=ae.o anet.o redis-benchmark.o adlist.o dict.o zmalloc.o redisassert.o release.o crcspeed.o crc64.o siphash.o crc16.o monotonic.o cli_common.o mt19937-64.o - REDIS_CHECK_RDB_NAME=redis-check-rdb$(PROG_SUFFIX) - REDIS_CHECK_AOF_NAME=redis-check-aof$(PROG_SUFFIX) --ALL_SOURCES=$(sort $(patsubst %.o,%.c,$(REDIS_SERVER_OBJ) $(REDIS_CLI_OBJ) $(REDIS_BENCHMARK_OBJ))) -+ALL_SOURCES=$(sort $(patsubst %.o,%.c,$(REDIS_SERVER_OBJ))) - --all: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME) -+all: $(REDIS_SERVER_LIB) - @echo "" - @echo "Hint: It's a good idea to run 'make test' ;)" - @echo "" -@@ -373,6 +367,10 @@ endif - $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) - $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a ../deps/hdr_histogram/libhdrhistogram.a $(FINAL_LIBS) - -+# redis-server.o -+$(REDIS_SERVER_LIB): $(REDIS_SERVER_OBJ) -+ $(REDIS_LD) -r -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a ../deps/hdr_histogram/libhdrhistogram.a -+ - # redis-sentinel - $(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME) - $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) -@@ -410,7 +408,7 @@ commands.c: commands/*.json ../utils/generate-command-code.py - endif - - clean: -- rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep -+ rm -rf $(REDIS_SERVER_NAME) $(REDIS_SERVER_LIB) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep - rm -f $(DEP) - - .PHONY: clean -diff --git a/src/server.c b/src/server.c -index b170cbb..a3960ce 100644 ---- a/src/server.c -+++ b/src/server.c -@@ -6900,7 +6900,7 @@ int main(int argc, char **argv) { - - /* We need to initialize our libraries, and the server configuration. */ - #ifdef INIT_SETPROCTITLE_REPLACEMENT -- spt_init(argc, argv); -+ // spt_init(argc, argv); // environment variables is not supported - #endif - setlocale(LC_COLLATE,""); - tzset(); /* Populates 'timezone' global. */ diff --git a/modules/ruxfs/src/mounts.rs b/modules/ruxfs/src/mounts.rs index c5664eff6..300e27e47 100644 --- a/modules/ruxfs/src/mounts.rs +++ b/modules/ruxfs/src/mounts.rs @@ -110,13 +110,21 @@ pub(crate) fn etcfs() -> VfsResult> { let etcfs = fs::ramfs::RamFileSystem::new(); let etc_root = etcfs.root_dir(); - // Create /etc/passwd and /etc/hosts + // Create /etc/passwd, and /etc/hosts etc_root.create("passwd", VfsNodeType::File)?; let file_passwd = etc_root.clone().lookup("passwd")?; - // format: username:password:uid:gid:allname:homedir:shell file_passwd.write_at(0, b"root:x:0:0:root:/root:/bin/bash\n")?; + // Create /etc/group + etc_root.create("group", VfsNodeType::File)?; + let file_group = etc_root.clone().lookup("group")?; + file_group.write_at(0, b"root:x:0:\n")?; + + // Create /etc/localtime + etc_root.create("localtime", VfsNodeType::File)?; + + // Createe /etc/hosts etc_root.create("hosts", VfsNodeType::File)?; let file_hosts = etc_root.clone().lookup("hosts")?; file_hosts.write_at( diff --git a/ulib/ruxlibc/include/fcntl.h b/ulib/ruxlibc/include/fcntl.h index 01e73b223..77f1cd542 100644 --- a/ulib/ruxlibc/include/fcntl.h +++ b/ulib/ruxlibc/include/fcntl.h @@ -23,7 +23,7 @@ #define O_DSYNC 010000 #define O_SYNC 04010000 #define O_RSYNC 04010000 -#define O_DIRECTORY 0200000 +#define O_DIRECTORY 040000 #define O_NOFOLLOW 0400000 #define O_CLOEXEC 02000000 diff --git a/ulib/ruxmusl/Cargo.toml b/ulib/ruxmusl/Cargo.toml index 0406f4386..f45e98462 100644 --- a/ulib/ruxmusl/Cargo.toml +++ b/ulib/ruxmusl/Cargo.toml @@ -40,6 +40,7 @@ select = ["ruxos_posix_api/select"] epoll = ["ruxos_posix_api/epoll"] poll = ["ruxos_posix_api/poll"] rtc = ["ruxfeat/rtc"] +signal = ["ruxos_posix_api/signal"] musl = ["ruxos_posix_api/musl", "tls"] diff --git a/ulib/ruxmusl/src/syscall/mod.rs b/ulib/ruxmusl/src/syscall/mod.rs index 4b3748ce2..691bb1bec 100644 --- a/ulib/ruxmusl/src/syscall/mod.rs +++ b/ulib/ruxmusl/src/syscall/mod.rs @@ -1,6 +1,6 @@ pub mod syscall_id; -use core::ffi::c_int; +use core::ffi::{c_int, c_uint}; use ruxos_posix_api::ctypes; use syscall_id::SyscallId; @@ -86,6 +86,12 @@ pub fn syscall(syscall_id: SyscallId, args: [usize; 6]) -> isize { args[1] as c_int, ) as _, #[cfg(feature = "fs")] + SyscallId::GETDENTS64 => ruxos_posix_api::sys_getdents64( + args[0] as c_uint, + args[1] as *mut ctypes::dirent, + args[2] as c_uint, + ) as _, + #[cfg(feature = "fs")] SyscallId::LSEEK => ruxos_posix_api::sys_lseek( args[0] as c_int, args[1] as ctypes::off_t, @@ -131,6 +137,13 @@ pub fn syscall(syscall_id: SyscallId, args: [usize; 6]) -> isize { args[4] as ctypes::size_t, ) as _, #[cfg(feature = "fs")] + SyscallId::READLINKAT => ruxos_posix_api::sys_readlinkat( + args[0] as c_int, + args[1] as *const core::ffi::c_char, + args[2] as *mut core::ffi::c_char, + args[3] as ctypes::size_t, + ) as _, + #[cfg(feature = "fs")] SyscallId::NEWFSTATAT => ruxos_posix_api::sys_newfstatat( args[0] as c_int, args[1] as *const core::ffi::c_char, @@ -177,12 +190,19 @@ pub fn syscall(syscall_id: SyscallId, args: [usize; 6]) -> isize { args[1] as *mut ctypes::timespec, ) as _, SyscallId::SCHED_YIELD => ruxos_posix_api::sys_sched_yield() as _, + #[cfg(feature = "signal")] + SyscallId::SIGALTSTACK => ruxos_posix_api::sys_sigaltstack( + args[0] as *const core::ffi::c_void, + args[1] as *mut core::ffi::c_void, + ) as _, + #[cfg(feature = "signal")] SyscallId::RT_SIGACTION => ruxos_posix_api::sys_rt_sigaction( args[0] as c_int, args[1] as *const ctypes::sigaction, args[2] as *mut ctypes::sigaction, args[3] as ctypes::size_t, ) as _, + #[cfg(feature = "signal")] SyscallId::RT_SIGPROCMASK => ruxos_posix_api::sys_rt_sigprocmask( args[0] as c_int, args[1] as *const usize, @@ -285,6 +305,14 @@ pub fn syscall(syscall_id: SyscallId, args: [usize; 6]) -> isize { args[0] as *mut core::ffi::c_void, args[1] as ctypes::size_t, ) as _, + #[cfg(feature = "alloc")] + SyscallId::MREMAP => ruxos_posix_api::sys_mremap( + args[0] as *mut core::ffi::c_void, + args[1] as ctypes::size_t, + args[2] as ctypes::size_t, + args[3] as c_int, + args[4] as *mut core::ffi::c_void, + ) as _, #[cfg(feature = "multitask")] SyscallId::CLONE => ruxos_posix_api::sys_clone( args[0] as c_int, @@ -303,6 +331,12 @@ pub fn syscall(syscall_id: SyscallId, args: [usize; 6]) -> isize { args[5] as ctypes::off_t, ) as _, #[cfg(feature = "alloc")] + SyscallId::MADVICE => ruxos_posix_api::sys_madvice( + args[0] as *mut core::ffi::c_void, + args[1] as ctypes::size_t, + args[2] as c_int, + ) as _, + #[cfg(feature = "alloc")] SyscallId::MPROTECT => ruxos_posix_api::sys_mprotect( args[0] as *mut core::ffi::c_void, args[1] as ctypes::size_t, diff --git a/ulib/ruxmusl/src/syscall/syscall_id.rs b/ulib/ruxmusl/src/syscall/syscall_id.rs index 0a739df5a..cbe739a66 100644 --- a/ulib/ruxmusl/src/syscall/syscall_id.rs +++ b/ulib/ruxmusl/src/syscall/syscall_id.rs @@ -38,6 +38,8 @@ pub enum SyscallId { #[cfg(feature = "pipe")] PIPE2 = 59, #[cfg(feature = "fs")] + GETDENTS64 = 61, + #[cfg(feature = "fs")] LSEEK = 62, READ = 63, WRITE = 64, @@ -50,6 +52,8 @@ pub enum SyscallId { #[cfg(feature = "poll")] PPOLL = 73, #[cfg(feature = "fs")] + READLINKAT = 78, + #[cfg(feature = "fs")] NEWFSTATAT = 79, #[cfg(feature = "fs")] FSTAT = 80, @@ -66,7 +70,11 @@ pub enum SyscallId { CLOCK_SETTIME = 112, CLOCK_GETTIME = 113, SCHED_YIELD = 124, + #[cfg(feature = "signal")] + SIGALTSTACK = 132, + #[cfg(feature = "signal")] RT_SIGACTION = 134, + #[cfg(feature = "signal")] RT_SIGPROCMASK = 135, UNAME = 160, GETRLIMIT = 163, @@ -102,11 +110,15 @@ pub enum SyscallId { SENDMSG = 211, #[cfg(feature = "alloc")] MUNMAP = 215, + #[cfg(feature = "alloc")] + MREMAP = 216, #[cfg(feature = "multitask")] CLONE = 220, #[cfg(feature = "alloc")] MMAP = 222, #[cfg(feature = "alloc")] + MADVICE = 233, + #[cfg(feature = "alloc")] MPROTECT = 226, PRLIMIT64 = 261, }