make log a bit verbose for some useful information
authorLunaixsky <lunaixsky@qq.com>
Tue, 1 Apr 2025 13:30:06 +0000 (14:30 +0100)
committerLunaixsky <lunaixsky@qq.com>
Tue, 1 Apr 2025 13:30:06 +0000 (14:30 +0100)
change the versioing scheme: major.[.minor.patch][.build_seq]

lunaix-os/LConfig
lunaix-os/includes/lunaix/ds/flipbuf.h [new file with mode: 0644]
lunaix-os/kernel/debug/trace.c
lunaix-os/kernel/device/devdb.c
lunaix-os/kernel/kcmd.c
lunaix-os/kernel/kinit.c
lunaix-os/kernel/kprint/kprintf.c
lunaix-os/kernel/mm/pmm.c

index 1c151e3c7ce94dd8b5611b9e488d79998c756093..0e27e4e4e88ac716d243f9deb1fb313f12f6754b 100644 (file)
@@ -1,4 +1,5 @@
 import time
 import time
+from datetime import datetime, date
 
 include("kernel")
 include("arch")
 
 include("kernel")
 include("arch")
@@ -13,8 +14,12 @@ def lunaix_ver():
 
     type(str)
     
 
     type(str)
     
-    seq_num = int(time.time() / 3600)
-    default("%s dev-2024_%d"%(v(arch), seq_num))
+    today = date.today()
+    year = today.year
+    start_of_year = datetime(year, 1, 1).date()
+    seq_num = (today - start_of_year).days
+    
+    default("%s v0.%d%d"%(v(arch), year - 2000, seq_num))
 
 @Collection("Kernel Debug and Testing")
 def debug_and_testing():
 
 @Collection("Kernel Debug and Testing")
 def debug_and_testing():
diff --git a/lunaix-os/includes/lunaix/ds/flipbuf.h b/lunaix-os/includes/lunaix/ds/flipbuf.h
new file mode 100644 (file)
index 0000000..0589f47
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef __LUNAIX_FLIPBUF_H
+#define __LUNAIX_FLIPBUF_H
+
+#include <lunaix/types.h>
+#include <lunaix/spike.h>
+
+struct flipbuf
+{
+    void* buf;
+    void* top;
+    unsigned long half_size;
+};
+
+#define DEFINE_FLIPBUF(name, halfsz, buf_) \
+            struct flipbuf name = { .buf=buf_, .top=buf_, .half_size=halfsz }
+
+static inline void*
+flipbuf_under(struct flipbuf* fbuf)
+{
+    ptr_t off;
+
+    off  = __ptr(fbuf->top);
+    off += fbuf->half_size;
+    off %= fbuf->half_size;
+    off += __ptr(fbuf->buf);
+    
+    return (void*)off;
+}
+
+static inline void*
+flipbuf_top(struct flipbuf* fbuf)
+{
+    return fbuf->top;
+}
+
+static inline void*
+flipbuf_flip(struct flipbuf* fbuf)
+{
+    fbuf->top = flipbuf_under(fbuf);
+    return fbuf->top;
+}
+
+#endif /* __LUNAIX_FLIPBUF_H */
index 77b332081adb652ea71f6f46508ac9fd977499d0..452b3cd1d13855a8878ff7d51b8892aab57fd1d8 100644 (file)
@@ -13,7 +13,7 @@
 
 #define NB_TRACEBACK 16
 
 
 #define NB_TRACEBACK 16
 
-LOG_MODULE("TRACE")
+LOG_MODULE("lkdbg")
 
 extern_autogen(ksymtable);
 
 
 extern_autogen(ksymtable);
 
@@ -34,6 +34,9 @@ void
 trace_modksyms_init(struct boot_handoff* bhctx)
 {
     trace_ctx.ksym_table = autogen(struct ksyms, ksymtable);
 trace_modksyms_init(struct boot_handoff* bhctx)
 {
     trace_ctx.ksym_table = autogen(struct ksyms, ksymtable);
+
+    INFO("symbols loaded: %d @0x%lx", 
+            trace_ctx.ksym_table->ksym_count, trace_ctx.ksym_table->syms);
 }
 
 struct ksym_entry*
 }
 
 struct ksym_entry*
index a2483788069aef3f4ff8b209081df8a696c5b81b..a41364df5557f799da79f3715c65aebf1a223118 100644 (file)
@@ -59,6 +59,8 @@ device_scan_drivers()
 
         llist_append(&dev_registry_flat, &devdef->dev_list);
     }
 
         llist_append(&dev_registry_flat, &devdef->dev_list);
     }
+
+    INFO("%d drivers registered", idx + 1);
 }
 
 static int
 }
 
 static int
index 6860065fa0a5732e9c79130fafff74d7b1d4d0d5..2afe9a035859b4d2debb6990b7e7d672e24ef7c5 100644 (file)
@@ -74,7 +74,12 @@ kcmd_parse_cmdline(char* cmd_line)
 {
     struct extractor ctx = { .cmdline = cmd_line, .pos = 0 };
     
 {
     struct extractor ctx = { .cmdline = cmd_line, .pos = 0 };
     
-    while(extract_next_option(&ctx)) {
+    INFO("active kcmds");
+
+    // first option is always kernel itself
+    extract_next_option(&ctx);
+
+    while (extract_next_option(&ctx)) {
         if (!ctx.key.len) {
             continue;
         }
         if (!ctx.key.len) {
             continue;
         }
@@ -96,6 +101,9 @@ kcmd_parse_cmdline(char* cmd_line)
         
         memcpy(kopt->buf, &cmd_line[ctx.key.pos], ctx.key.len);
         
         
         memcpy(kopt->buf, &cmd_line[ctx.key.pos], ctx.key.len);
         
+        kopt->hashkey = HSTR(kopt->buf, ctx.key.len);
+        hstr_rehash(&kopt->hashkey, HSTR_FULL_HASH);
+
         if (ctx.val.len) {
             kopt->value = &kopt->buf[ctx.key.len + 1];
             size_t max_val_len = maxlen - ctx.key.len;
         if (ctx.val.len) {
             kopt->value = &kopt->buf[ctx.key.len + 1];
             size_t max_val_len = maxlen - ctx.key.len;
@@ -106,11 +114,12 @@ kcmd_parse_cmdline(char* cmd_line)
             }
 
             memcpy(kopt->value, &cmd_line[ctx.val.pos], ctx.val.len);
             }
 
             memcpy(kopt->value, &cmd_line[ctx.val.pos], ctx.val.len);
+            INFO("   %-10s =%s", kopt->hashkey.value, kopt->value);
+        }
+        else {
+            INFO("   %s", kopt->hashkey.value);
         }
         
         }
         
-        kopt->hashkey = HSTR(kopt->buf, ctx.key.len);
-        hstr_rehash(&kopt->hashkey, HSTR_FULL_HASH);
-
         hashtable_hash_in(options, &kopt->node, kopt->hashkey.hash);
     }
 }
         hashtable_hash_in(options, &kopt->node, kopt->hashkey.hash);
     }
 }
index 38804f2f58d0d63dfe665fc04d3989a93bdfbbe8..58a69e9e41f36223510eebb55a20135f699d60a9 100644 (file)
@@ -111,6 +111,16 @@ __remap_and_load_dtb(struct boot_handoff* bhctx)
     return;
 }
 
     return;
 }
 
+static void
+log_bootup_time()
+{
+    datetime_t dt;
+
+    clock_walltime(&dt);
+    INFO("kernel boot at: %d/%d/%d %d:%d:%d", 
+            dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
+}
+
 void
 kernel_bootstrap(struct boot_handoff* bhctx)
 {
 void
 kernel_bootstrap(struct boot_handoff* bhctx)
 {
@@ -123,6 +133,8 @@ kernel_bootstrap(struct boot_handoff* bhctx)
     /* Setup kernel memory layout and services */
     kmem_init(bhctx);
 
     /* Setup kernel memory layout and services */
     kmem_init(bhctx);
 
+    INFO();
+    INFO("Lunaix " CONFIG_LUNAIX_VER " (c) Lunaixsky 2022-2025");
 
     boot_parse_cmdline(bhctx);
 
 
     boot_parse_cmdline(bhctx);
 
@@ -141,6 +153,7 @@ kernel_bootstrap(struct boot_handoff* bhctx)
 
     clock_init();
     timer_init();
 
     clock_init();
     timer_init();
+    log_bootup_time();
 
     initfn_invoke_earlyboot();
 
 
     initfn_invoke_earlyboot();
 
index 02bc0ee9feca75a2cbca921372be3e44db26b0a1..363abc687b5d770113e74fd98f848e529dbe8a7c 100644 (file)
@@ -5,6 +5,7 @@
 #include <lunaix/syslog.h>
 #include <lunaix/device.h>
 #include <lunaix/owloysius.h>
 #include <lunaix/syslog.h>
 #include <lunaix/device.h>
 #include <lunaix/owloysius.h>
+#include <lunaix/ds/flipbuf.h>
 
 #include <hal/term.h>
 
 
 #include <hal/term.h>
 
 
 #include "kp_records.h"
 
 
 #include "kp_records.h"
 
-#define MAX_BUFSZ 512
 #define MAX_BUFSZ_HLF 256
 #define MAX_KPENT_NUM 1024
 
 #define MAX_BUFSZ_HLF 256
 #define MAX_KPENT_NUM 1024
 
-static char tmp_buf[MAX_BUFSZ];
+static char tmp_buf[MAX_BUFSZ_HLF * 2];
+static DEFINE_FLIPBUF(fmtbuf, MAX_BUFSZ_HLF, tmp_buf);
 
 static struct kp_records kprecs = {
     .kp_ents = { .ents = { .next = &kprecs.kp_ents.ents,
 
 static struct kp_records kprecs = {
     .kp_ents = { .ents = { .next = &kprecs.kp_ents.ents,
@@ -40,23 +41,43 @@ shift_level(const char* str, int* level)
 }
 
 static inline void
 }
 
 static inline void
-kprintf_put(int level, const char* buf, size_t sz)
+__put_console(const struct kp_entry* ent)
 {
 {
-    kprec_put(&kprecs, level, buf, sz);
+    char* buf;
+    time_t s, ms;
+    size_t sz;
 
 
-    if (likely(sysconsole)) {
-        sysconsole->ops.write(sysconsole, buf, 0, sz);
+    if (unlikely(!sysconsole)) {
+        return;
     }
     }
+
+    s   = ent->time / 1000;
+    ms  = ent->time % 1000;
+    buf = flipbuf_flip(&fmtbuf);
+    sz  = ksnprintf(buf, MAX_BUFSZ_HLF, 
+                    "[%04d.%03d] %s", s, ms, ent->content);
+    
+    sysconsole->ops.write(sysconsole, buf, 0, sz);
+}
+
+static inline void
+kprintf_put(int level, const char* buf, size_t sz)
+{
+    __put_console(kprec_put(&kprecs, level, buf, sz));
 }
 
 static inline void
 kprintf_ml(const char* component, int level, const char* fmt, va_list args)
 {
 }
 
 static inline void
 kprintf_ml(const char* component, int level, const char* fmt, va_list args)
 {
-    char* buf = &tmp_buf[MAX_BUFSZ_HLF];
+    char* buf;
+    size_t sz;
+
+    buf = flipbuf_top(&fmtbuf);
     ksnprintf(buf, MAX_BUFSZ_HLF, "%s: %s\n", component, fmt);
 
     ksnprintf(buf, MAX_BUFSZ_HLF, "%s: %s\n", component, fmt);
 
-    size_t sz = ksnprintfv(tmp_buf, buf, MAX_BUFSZ_HLF, args);
-    kprintf_put(level, tmp_buf, sz);
+    sz = ksnprintfv(flipbuf_flip(&fmtbuf), buf, MAX_BUFSZ_HLF, args);
+    
+    kprintf_put(level, flipbuf_top(&fmtbuf), sz);
 }
 
 void
 }
 
 void
@@ -112,7 +133,7 @@ kprintf_dump_logs() {
     struct kp_entry *pos, *n;
     llist_for_each(pos, n, kprecs.kp_ent_wp, ents)
     {
     struct kp_entry *pos, *n;
     llist_for_each(pos, n, kprecs.kp_ent_wp, ents)
     {
-        sysconsole->ops.write(sysconsole, pos->content, 0, pos->len);
+        __put_console(pos);
     }
 }
 
     }
 }
 
index f00f9c88cfc3f69a60904c7466ced2098f16bf8f..bc44be7ab6a30eb7b481f700003f1e65b735ff35 100644 (file)
@@ -1,9 +1,13 @@
 #include <lunaix/status.h>
 #include <lunaix/mm/pagetable.h>
 #include <lunaix/spike.h>
 #include <lunaix/status.h>
 #include <lunaix/mm/pagetable.h>
 #include <lunaix/spike.h>
+#include <lunaix/owloysius.h>
+#include <lunaix/syslog.h>
 
 #include "pmm_internal.h"
 
 
 #include "pmm_internal.h"
 
+LOG_MODULE("pmm")
+
 static inline bool
 __check_typemask(struct ppage* page, ppage_type_t typemask)
 {
 static inline bool
 __check_typemask(struct ppage* page, ppage_type_t typemask)
 {
@@ -108,4 +112,24 @@ pmm_declare_pool(int pool, pfn_t start, pfn_t size)
     _pool->pool_start = ppage(start);
 
     return _pool;
     _pool->pool_start = ppage(start);
 
     return _pool;
-}
\ No newline at end of file
+}
+
+static void
+pmm_log_summary()
+{
+    pfn_t len;
+    struct pmem_pool* _pool;
+
+    INFO("init: nr_pages=%ld, gran=0x%lx", memory.list_len, 1 << PAGE_SHIFT);
+
+    for (int i = 0; i < POOL_COUNT; i++)
+    {
+        _pool = &memory.pool[i];
+        len   = ppfn(_pool->pool_end) - ppfn(_pool->pool_start) + 1;
+        
+        INFO("pool #%d (%d), %ld-%ld(0x%lx)", 
+                i , _pool->type, 
+                ppfn(_pool->pool_start), ppfn(_pool->pool_end), len);
+    }
+}
+owloysius_fetch_init(pmm_log_summary, on_sysconf);
\ No newline at end of file