wip 77/306877/1
authorMarek Szulc <m.szulc3@samsung.com>
Wed, 28 Feb 2024 16:07:50 +0000 (17:07 +0100)
committerMarek Szulc <m.szulc3@samsung.com>
Wed, 28 Feb 2024 16:24:49 +0000 (17:24 +0100)
Change-Id: Ie085f16cc04174c9ab3bc7866e04bcf41bbe3cdd

include/uapi/linux/zlogger.h
kernel/zlogger/mockup.c [new file with mode: 0644]
kernel/zlogger/zlogger.c

index 2c2e2b4cf3bb4421ddf4c68ff36a972c89007cd2..7e8b73dba649e649c49e1cc0daf66446930d442a 100644 (file)
@@ -32,6 +32,7 @@
 #define ZLOGGER_BLOCK_COUNT (ZLOGGER_BUFFER_SIZE / ZLOGGER_BLOCK_SIZE)
 #define ZLOGGER_BITMAP_SIZE (ZLOGGER_BLOCK_COUNT / 8)
 #define ZLOGGER_DATA_MAX (ZLOGGER_BLOCK_SIZE - sizeof(struct zlogger_header))
+#define ZLOGGER_BLOCK_NUMBER 8192
 
 #define ZLOGGER_TAG_MAX (32)
 #define ZLOGGER_MSG_MAX (140)
diff --git a/kernel/zlogger/mockup.c b/kernel/zlogger/mockup.c
new file mode 100644 (file)
index 0000000..82c1678
--- /dev/null
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_BLOCKS 10000
+#define POOL_SIZE 2
+#define INIT_PROCESSES 5000
+
+struct process_history {
+    pid_t pid;
+    int history[POOL_SIZE]; // last used blocks
+    //int current_index; // which index should be overwritten
+};
+
+size_t history_size = INIT_PROCESSES;
+struct proccess_history *history;
+
+void init() {
+    history = calloc(INIT_PROCESSES, sizeof(struct process_history));
+}
+
+int get_proccess_index(pid_t pid) {
+    for (int i = 0; i < history_size; i++)
+        if (history[i].pid == pid)
+            return i;
+}
+
+void save_new_process(pid_t pid) {
+    for (int i = 0; i < history_size; i++) {
+        if (history[i].pid == 0) {
+            history[i].pid = pid;
+            return;
+        }
+    }
+
+    struct process_history *temp = realloc(history, sizeof(struct process_history)*history_size*2);
+    if (temp != NULL) {
+        history = temp;
+        history_size*=2;
+    }
+}
+
+void delete_process(pid_t pid) {
+    memset(&history[get_proccess_index(pid)], 0, sizeof(struct process_history));
+}
+
+void choose_block(pid_t pid) {
+    int idx = get_proccess_index(pid);
+    // sprawdz czy ktorys z tablicy history[idx] jest wolny, jak nie to przydziel dowolny wolny i nadpisz jeden z blokow w historii
+}
+
+
+
index 804e6f6b18688989eb75285cf9f5897942036997..9916b4e909ba6eac2d5efe5d41a8f24ef8bd3c19 100644 (file)
@@ -119,7 +119,7 @@ static struct miscdevice zlogger_device;
 static struct miscdevice zlogger_dump_device;
 
 static int g_init;
-static char *g_shm_ptr[ZLOGGER_DEVICE_COUNT];
+static char *g_shm_ptr[ZLOGGER_BLOCK_NUMBER];
 static struct thread_table *g_thread_table;
 
 static struct mutex g_block_mutex;
@@ -1105,6 +1105,14 @@ static int zlogger_init(void)
        int g_shm_ptr_i = 0;
        int r = 0;
 
+       unsigned int target_size = 32 * 1024 * 1024; // 32mb
+       unsigned int page_size = 4 * 1024; // 4kb
+
+       unsigned int iterations = target_size / page_size;
+       if (target_size % page_size != 0) {
+               iterations++;
+       }
+
        if (!g_zlog_enable) {
                pr_info("zlog is disable\n");
                return 0;
@@ -1115,8 +1123,8 @@ static int zlogger_init(void)
                return -ENOMEM;
        hash_init(g_thread_table->data);
 
-       for (g_shm_ptr_i = 0; g_shm_ptr_i < ZLOGGER_DEVICE_COUNT; g_shm_ptr_i++) {
-               g_shm_ptr[g_shm_ptr_i] = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, MAP_ORDER);
+       for (g_shm_ptr_i = 0; g_shm_ptr_i < iterations; g_shm_ptr_i++) {
+               g_shm_ptr[g_shm_ptr_i] = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, get_order(page_size));
                if (g_shm_ptr[g_shm_ptr_i] == NULL) {
                        r = -ENOMEM;
                        goto out_free_g_thread_table_g_shm_ptr;