improvements
authorMateusz Majewski <m.majewski2@samsung.com>
Wed, 24 Aug 2022 09:21:07 +0000 (11:21 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 24 Aug 2022 09:21:07 +0000 (11:21 +0200)
Change-Id: Iec1d78153c06e06f4982d734c4e3cd8bf4a21c11

kernel/vlogger/vlogger.c

index 536bcae1768e918683debe0bb9e566580672082c..2e6aed9c12abf7dbd46bd9f8b10a3547d0677afb 100644 (file)
@@ -213,19 +213,14 @@ static inline char *get_shared_memory(int dev_index)
 
 static inline struct block_t *get_block(uint16_t block_index)
 {
-       // TODO: This represents the same 2048 value in three different ways:
-       // 1 << 11, 0x7FF + 1, as well as V_BLOCK_SIZE.
        uint16_t index = block_index - 1;
-       int offset = index & 0x7FF;
-       char *p = get_shared_memory(index >> 11);
+       int offset = index & (V_BLOCK_SIZE - 1);
+       char *p = get_shared_memory(index / V_BLOCK_SIZE);
 
-       if (!p) {
-               pr_err("[INVALID BLOCK] index:%d free:%d err:%d", block_index, g_free_q.count, g_err_count);
-               dump_stack();
-               WARN_ON(1);
-       }
+       if (!p)
+               return NULL;
 
-       return (struct block_t *)(p + (offset << 11));
+       return (struct block_t *)(p + (offset * V_BLOCK_SIZE));
 }
 
 static inline void queue_init(struct queue_t *q, const char *name, uint16_t capacity)
@@ -656,19 +651,18 @@ static const struct file_operations vlogger_fops = {
 static ssize_t status_show(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
-       // int thread_count = 0;
-       // int i;
+       int thread_count = 0;
+       int i;
 
-       // for (i = 0; i < MAX_THREAD; i++) {
-       //      if (g_threads[i].block > 0)
-       //              thread_count ++;
-       // }
+       for (i = 0; i < g_max_thread_id; i++) {
+               if (get_thread_table(i) > 0)
+                       thread_count ++;
+       }
 
-       // return snprintf(buf, PAGE_SIZE,
-       //              "free(%d%%):%d/%d task_on:%d gc_free:%u error:%u tid_max:%d\n",
-       //              BLOCK_RATIO(g_free_q.count), g_free_q.count, (g_free_q.count + thread_count),
-       //              g_task_on, g_free_count, g_err_count, g_max_thread_id);
-       return -ENOTSUPP; // TODO
+       return snprintf(buf, PAGE_SIZE,
+                       "free(%d%%):%d/%d task_on:%d gc_free:%u error:%u tid_max:%d\n",
+                       BLOCK_RATIO(g_free_q.count), g_free_q.count, (g_free_q.count + thread_count),
+                       g_task_on, g_free_count, g_err_count, g_max_thread_id);
 }
 
 static DEVICE_ATTR_RO(status);
@@ -739,8 +733,7 @@ static ssize_t thread_store(struct device *dev,
 static ssize_t thread_show(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
-       // return snprintf(buf, PAGE_SIZE, "[%d] block:%u\n", g_thread, g_threads[g_thread].block);
-       return -ENOTSUPP; // TODO
+       return snprintf(buf, PAGE_SIZE, "[%d] block:%u\n", g_thread, get_thread_table(g_thread));
 }
 
 static DEVICE_ATTR_RW(thread);
@@ -829,11 +822,17 @@ out_free_g_thread_table_g_shm_ptr:
 static void __exit vlogger_exit(void)
 {
        int i;
+       struct thread_table_field *ptr = NULL;
+       struct hlist_node *tmp_iter = NULL;
+       int tmp_bkt;
 
        // TODO: What about the task that is running in the background?
 
        queue_deinit(&g_free_q);
-       kfree(g_thread_table); // TODO: Free innards
+       hash_for_each_safe(g_thread_table->data, tmp_bkt, tmp_iter, ptr, next) {
+               kfree(ptr);
+       }
+       kfree(g_thread_table);
        for (i = 0; i < DEVICE_COUNT; i++)
                kfree(g_shm_ptr[i]);