[Crash-utility] [PATCH 1/4] refactor store_context => add_context

Greg Thelen gthelen at google.com
Fri Apr 6 15:15:01 UTC 2018


store_context is always used add entries to the tt->context_array, so
simply the code.  No functional change.

Signed-off-by: Greg Thelen <gthelen at google.com>
---
 task.c | 106 +++++++++++++++------------------------------------------
 1 file changed, 28 insertions(+), 78 deletions(-)

diff --git a/task.c b/task.c
index 6d31699ca209..51aa2a255326 100644
--- a/task.c
+++ b/task.c
@@ -32,7 +32,7 @@ static void refresh_hlist_task_table_v3(void);
 static void refresh_active_task_table(void);
 static int radix_tree_task_callback(ulong);
 static void refresh_radix_tree_task_table(void);
-static struct task_context *store_context(struct task_context *, ulong, char *);
+static struct task_context *add_context(ulong, char *);
 static void refresh_context(ulong, ulong);
 static ulong parent_of(ulong);
 static void parent_list(ulong);
@@ -822,7 +822,6 @@ refresh_fixed_task_table(void)
 {
 	int i;
 	ulong *tlp;
-	struct task_context *tc;
 	ulong curtask;
 	ulong retries;
 	ulong curpid;
@@ -868,8 +867,7 @@ retry:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local, 
-	     tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
                 if (TASK_IN_USE(*tlp)) {
                 	if (!(tp = fill_task_struct(*tlp))) {
@@ -879,10 +877,7 @@ retry:
                         	goto retry;
                 	}
 
-                	if (store_context(tc, *tlp, tp)) {
-                        	tc++;
-                        	tt->running_tasks++;
-                	}
+			add_context(*tlp, tp);
 		}
         }
 
@@ -966,7 +961,6 @@ refresh_unlimited_task_table(void)
 {
 	int i;
 	ulong *tlp;
-	struct task_context *tc;
 	ulong curtask;
 	ulong curpid;
 	struct list_data list_data, *ld;
@@ -1080,8 +1074,7 @@ retry:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local, 
-             tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
 		if (!(*tlp))
 			continue;
@@ -1108,10 +1101,7 @@ retry:
                         goto retry;
                 }
 
-		if (store_context(tc, *tlp, tp)) {
-                	tc++;
-                	tt->running_tasks++;
-		}
+		add_context(*tlp, tp);
 	}
 
 	if (DUMPFILE()) {
@@ -1143,7 +1133,6 @@ refresh_pidhash_task_table(void)
 	char *pidhash, *tp; 
 	ulong *pp, next, pnext;
 	int len, cnt;
-        struct task_context *tc;
         ulong curtask;
         ulong curpid;
         ulong retries;
@@ -1284,8 +1273,7 @@ retry_pidhash:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local, 
-             tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
 		if (!(*tlp))
 			continue;
@@ -1317,10 +1305,7 @@ retry_pidhash:
                         goto retry_pidhash;
                 }
 
-		if (store_context(tc, *tlp, tp)) {
-			tc++;
-			tt->running_tasks++;
-		}
+		add_context(*tlp, tp);
 	}
 
         FREEBUF(pidhash);
@@ -1361,7 +1346,6 @@ refresh_pid_hash_task_table(void)
 	char *tp; 
 	ulong next, pnext;
 	int len, cnt;
-        struct task_context *tc;
         ulong curtask;
         ulong curpid;
         ulong retries;
@@ -1496,8 +1480,7 @@ retry_pid_hash:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local, 
-             tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
 		if (!(*tlp))
 			continue;
@@ -1529,10 +1512,7 @@ retry_pid_hash:
                         goto retry_pid_hash;
                 }
 
-		if (store_context(tc, *tlp, tp)) {
-			tc++;
-			tt->running_tasks++;
-		}
+		add_context(*tlp, tp);
 	}
 
         FREEBUF(pid_hash);
@@ -1565,7 +1545,6 @@ refresh_hlist_task_table(void)
 	char *nodebuf;
 	int plen, len, cnt;
 	long value;
-        struct task_context *tc;
         ulong curtask;
         ulong curpid;
         ulong retries;
@@ -1768,8 +1747,7 @@ retry_pid_hash:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local, 
-             tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
 		if (!(*tlp))
 			continue;
@@ -1801,10 +1779,7 @@ retry_pid_hash:
                         goto retry_pid_hash;
                 }
 
-		if (store_context(tc, *tlp, tp)) {
-			tc++;
-			tt->running_tasks++;
-		}
+		add_context(*tlp, tp);
 	}
 
         FREEBUF(pid_hash);
@@ -1835,7 +1810,6 @@ refresh_hlist_task_table_v2(void)
 	ulong next, pnext, pprev;
 	char *nodebuf;
 	int len, cnt;
-        struct task_context *tc;
         ulong curtask;
         ulong curpid;
         ulong retries;
@@ -2003,8 +1977,7 @@ retry_pid_hash:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local, 
-             tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
 		if (!(*tlp))
 			continue;
@@ -2036,10 +2009,7 @@ retry_pid_hash:
                         goto retry_pid_hash;
                 }
 
-		if (store_context(tc, *tlp, tp)) {
-			tc++;
-			tt->running_tasks++;
-		}
+		add_context(*tlp, tp);
 	}
 
         FREEBUF(pid_hash);
@@ -2070,7 +2040,6 @@ refresh_hlist_task_table_v3(void)
 	ulong upid;
 	char *nodebuf;
 	int len, cnt;
-        struct task_context *tc;
         ulong curtask;
         ulong curpid;
         ulong retries;
@@ -2266,8 +2235,7 @@ chain_next:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local, 
-             tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
 		if (!(*tlp))
 			continue;
@@ -2299,10 +2267,7 @@ chain_next:
                         goto retry_pid_hash;
                 }
 
-		if (store_context(tc, *tlp, tp)) {
-			tc++;
-			tt->running_tasks++;
-		}
+		add_context(*tlp, tp);
 	}
 
         FREEBUF(pid_hash);
@@ -2341,7 +2306,6 @@ refresh_radix_tree_task_table(void)
 	ulong *tlp;
 	char *tp;
 	struct radix_tree_pair rtp;
-	struct task_context *tc;
 	char *pidbuf;
 
 	if (DUMPFILE() && (tt->flags & TASK_INIT_DONE))   /* impossible */
@@ -2494,8 +2458,7 @@ retry_radix_tree:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local,
-             tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
 		if (!(*tlp))
 			continue;
@@ -2527,10 +2490,7 @@ retry_radix_tree:
 			goto retry_radix_tree;
 		}
 
-		if (store_context(tc, *tlp, tp)) {
-			tc++;
-			tt->running_tasks++;
-		}
+		add_context(*tlp, tp);
 	}
 
 	FREEBUF(pidbuf);
@@ -2549,7 +2509,6 @@ refresh_active_task_table(void)
 	int i;
 	char *tp; 
 	int cnt;
-        struct task_context *tc;
         ulong curtask;
         ulong curpid;
         ulong retries;
@@ -2610,8 +2569,7 @@ retry_active:
 
 	clear_task_cache();
 
-        for (i = 0, tlp = (ulong *)tt->task_local, 
-             tt->running_tasks = 0, tc = tt->context_array;
+        for (i = 0, tlp = (ulong *)tt->task_local, tt->running_tasks = 0;
              i < tt->max_tasks; i++, tlp++) {
 		if (!(*tlp))
 			continue;
@@ -2643,10 +2601,7 @@ retry_active:
                         goto retry_active;
                 }
 
-		if (store_context(tc, *tlp, tp)) {
-			tc++;
-			tt->running_tasks++;
-		} else if (DUMPFILE())
+		if (!add_context(*tlp, tp) && DUMPFILE())
 			error(WARNING, "corrupt/invalid active task: %lx\n",
 				*tlp);
 	}
@@ -2667,11 +2622,11 @@ retry_active:
 }
 
 /*
- *  Fill a task_context structure with the data from a task.  If a NULL
- *  task_context pointer is passed in, use the next available one.
+ *  Initialize and return a new task_context structure with data from a task.
+ *  NULL is returned on error.
  */
 static struct task_context *
-store_context(struct task_context *tc, ulong task, char *tp)
+add_context(ulong task, char *tp)
 {
         pid_t *pid_addr, *tgid_addr;
         char *comm_addr;
@@ -2680,6 +2635,7 @@ store_context(struct task_context *tc, ulong task, char *tp)
         ulong *mm_addr;
         int has_cpu;
 	int do_verify;
+	struct task_context *tc;
 	struct tgid_context *tg;
 
 	processor_addr = NULL;
@@ -2699,8 +2655,7 @@ store_context(struct task_context *tc, ulong task, char *tp)
 	else
 		do_verify = 0;
 
-	if (!tc)
-		tc = tt->context_array + tt->running_tasks;
+	tc = tt->context_array + tt->running_tasks;
 
         pid_addr = (pid_t *)(tp + OFFSET(task_struct_pid));
 	tgid_addr = (pid_t *)(tp + OFFSET(task_struct_tgid));
@@ -2755,6 +2710,7 @@ store_context(struct task_context *tc, ulong task, char *tp)
         if (has_cpu && (tt->flags & POPULATE_PANIC))
                 tt->panic_threads[tc->processor] = tc->task;
 
+	tt->running_tasks++;
 	return tc;
 }
 
@@ -5907,12 +5863,8 @@ get_panic_context(void)
 			error(WARNING, 
 			  "active task %lx on cpu %d not found in PID hash\n\n",
 				task, i);
-			if ((tp = fill_task_struct(task))) {
-				if ((tc = store_context(NULL, task, tp))) 
-					tt->running_tasks++;
-				else
-					continue;
-			}
+			if ((tp = fill_task_struct(task)))
+				add_context(task, tp);
 		}
 	}
 
@@ -7180,10 +7132,8 @@ found_panic_task:
 		 *  If the task list was corrupted, add this one in.
 		 */
                 if ((tp = fill_task_struct(lasttask))) {
-			if ((tc = store_context(NULL, lasttask, tp))) {
-				tt->running_tasks++;
+			if ((tc = add_context(lasttask, tp)))
 				return tc;
-			}
 		}
 	} 
 
-- 
2.17.0.484.g0c8726318c-goog




More information about the Crash-utility mailing list