zlogger: rewrite cleanup task to use hash_for_each_safe() 83/281683/3
authorMarek Szyprowski <m.szyprowski@samsung.com>
Tue, 20 Sep 2022 11:14:46 +0000 (13:14 +0200)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Mon, 17 Oct 2022 11:05:07 +0000 (13:05 +0200)
Avoid trying all possible tids combination, instead simply iterate over
the hashtable. Also drop some dead code here and there.

Change-Id: If4d4f1dcd742091c0d367db0294f0ddd9401b89f
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
kernel/zlogger/zlogger.c

index d6cf5d1..5064449 100644 (file)
@@ -137,10 +137,6 @@ static uint16_t get_thread_table(pid_t tid, bool is_stdout)
 {
        struct thread_table_field *ptr = NULL;
 
-       // TODO: Is this needed?
-       if (g_thread_table == NULL)
-               return 0;
-
        hash_for_each_possible(g_thread_table->data, ptr, next, tid) {
                if (ptr->tid == tid && ptr->is_stdout == is_stdout)
                        return ptr->blk;
@@ -153,10 +149,6 @@ static void set_thread_table(pid_t tid, bool is_stdout, uint16_t blk)
 {
        struct thread_table_field *ptr = NULL;
 
-       // TODO: Is this needed?
-       if (g_thread_table == NULL)
-               return;
-
        hash_for_each_possible(g_thread_table->data, ptr, next, tid) {
                if (ptr->tid == tid && ptr->is_stdout == is_stdout) {
                        ptr->blk = blk;
@@ -245,25 +237,24 @@ static inline void queue_push(struct queue *q, uint16_t value)
 
 static int zlog_task(void *user_data)
 {
-       int i;
-       int is_stdout;
-       uint16_t blk;
+       struct thread_table_field *ptr = NULL;
+       struct hlist_node *tmp_iter = NULL;
+       int tmp_bkt;
+       int blk;
 
        do {
-               // TODO: Consider hash_for_each_safe
-               for (i = 1; i <= g_max_thread_id; i++) {
-                       for (is_stdout = 0; is_stdout <= 1; ++is_stdout) {
-                               blk = get_thread_table(i, is_stdout);
-                               // TODO: g_start_time should be under some kind of mutex.
-                               if (blk && get_block(blk)->head.ts < g_start_time) {
-                                       mutex_lock(&g_block_mutex);
-                                       get_block(blk)->head.tid = 0;
-                                       queue_push(&g_free_q, blk);
-                                       set_thread_table(i, is_stdout, 0);
-                                       // TODO: The userspace might very well be using this block right now.
-                                       mutex_unlock(&g_block_mutex);
-                                       g_free_count++;
-                               }
+
+               hash_for_each_safe(g_thread_table->data, tmp_bkt, tmp_iter, ptr, next) {
+                       blk = ptr->blk;
+                       // TODO: g_start_time should be under some kind of mutex.
+                       if (blk && get_block(blk)->head.ts < g_start_time) {
+                               mutex_lock(&g_block_mutex);
+                               get_block(blk)->head.tid = 0;
+                               queue_push(&g_free_q, blk);
+                               ptr->blk = 0;
+                               // TODO: The userspace might very well be using this block right now.
+                               mutex_unlock(&g_block_mutex);
+                               g_free_count++;
                        }
                }