Browse Source

feat(timer & syscall): add readv, change tick rate

new tick rate is 100hz
greatbridf 10 months ago
parent
commit
6c586cfd98
3 changed files with 44 additions and 7 deletions
  1. 3 3
      src/kernel/hw/timer.c
  2. 35 2
      src/kernel/syscall.cpp
  3. 6 2
      src/kernel/vfs.cpp

+ 3 - 3
src/kernel/hw/timer.c

@@ -10,9 +10,9 @@ void init_pit(void)
     asm_outb(PORT_PIT_CONTROL, 0x34);
 
     // send interval number
-    // 0x04a9 = 1193 = 1000Hz
-    asm_outb(PORT_PIT_COUNT, 0xa9);
-    asm_outb(PORT_PIT_COUNT, 0x04);
+    // 0x2e9a = 11930 = 100Hz
+    asm_outb(PORT_PIT_COUNT, 0x9a);
+    asm_outb(PORT_PIT_COUNT, 0x2e);
 }
 
 void inc_tick(void)

+ 35 - 2
src/kernel/syscall.cpp

@@ -501,6 +501,38 @@ int _syscall_set_tid_address(interrupt_stack* data)
     return current_thread->tid();
 }
 
+int _syscall_readv(interrupt_stack* data)
+{
+    SYSCALL_ARG1(int, fd);
+    SYSCALL_ARG2(const iovec* __user, iov);
+    SYSCALL_ARG3(int, iovcnt);
+
+    auto* file = current_process->files[fd];
+
+    if (!file)
+        return -EBADF;
+
+    // TODO: fix fake EOF
+    ssize_t totn = 0;
+    for (int i = 0; i < iovcnt; ++i) {
+        ssize_t ret = file->read(
+            (char*)iov[i].iov_base, iov[i].iov_len);
+
+        if (ret < 0)
+            return ret;
+
+        if (ret == 0)
+            break;
+
+        totn += ret;
+
+        if ((size_t)ret != iov[i].iov_len)
+            break;
+    }
+
+    return totn;
+}
+
 // TODO: this operation SHOULD be atomic
 int _syscall_writev(interrupt_stack* data)
 {
@@ -563,8 +595,8 @@ int _syscall_clock_gettime64(interrupt_stack* data)
     }
 
     int time = current_ticks();
-    tp->tv_sec = time / 1000;;
-    tp->tv_nsec = 1000000 * (time % 1000);
+    tp->tv_sec = time / 100;
+    tp->tv_nsec = 10000000 * (time % 100);
 
     return 0;
 }
@@ -1202,6 +1234,7 @@ void init_syscall(void)
     syscall_handlers[0x84] = _syscall_getpgid;
     syscall_handlers[0x8c] = _syscall_llseek;
     syscall_handlers[0x8d] = _syscall_getdents;
+    syscall_handlers[0x91] = _syscall_readv;
     syscall_handlers[0x92] = _syscall_writev;
     syscall_handlers[0x93] = _syscall_getsid;
     syscall_handlers[0xa8] = _syscall_poll;

+ 6 - 2
src/kernel/vfs.cpp

@@ -858,8 +858,10 @@ int fs::pipe::read(char* buf, size_t n)
 
         if (!is_writeable()) {
             size_t orig_n = n;
-            while (!this->buf.empty() && n--)
+            while (!this->buf.empty() && n) {
+                --n;
                 *(buf++) = this->buf.get();
+            }
 
             return orig_n - n;
         }
@@ -871,8 +873,10 @@ int fs::pipe::read(char* buf, size_t n)
 
             if (!is_writeable()) {
                 size_t orig_n = n;
-                while (!this->buf.empty() && n--)
+                while (!this->buf.empty() && n) {
+                    --n;
                     *(buf++) = this->buf.get();
+                }
 
                 return orig_n - n;
             }