Skip to contentSkip to conversation

UML - Implement get_wchan

PATCH In review Jeff Dike 2 participants 3 messages Oct 30, 2007 User-mode Linux (UML)

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 3/4 UML - Implement get_wchan

Implement get_wchan - the algorithm is similar to x86. It starts with the stack pointer of the process in question and looks above that for addresses that are kernel text. The second one which isn't in the scheduler is the one that's returned. The first one is ignored because that will be UML's own context switching routine.

---
 arch/um/kernel/process.c           |   37 +++++++++++++++++++++++++++++++++++++
 include/asm-um/processor-generic.h |    2 +-
 2 files changed, 38 insertions(+), 1 deletion(-)
arch/um/kernel/process.c +37 -0
Index: linux-2.6.22/arch/um/kernel/process.c
===================================================================
@@ -459,3 +459,40 @@ unsigned long arch_align_stack(unsigned 
 	return sp & ~0xf;
 }
 #endif
+
+unsigned long get_wchan(struct task_struct *p)
+{
+	unsigned long stack_page, sp, ip, count = 0;
+
+	if ((p == NULL) || (p == current) || (p->state == TASK_RUNNING))
+		return 0;
+
+	stack_page = (unsigned long) task_stack_page(p);
+	/* Bail if the process has no kernel stack for some reason */
+	if (stack_page == 0)
+		return 0;
+
+	sp = p->thread.switch_buf->JB_SP;
+	/*
+	 * Bail if the stack pointer is below the bottom of the kernel
+	 * stack for some reason
+	 */
+	if (sp < stack_page)
+		return 0;
+
+	while (sp < stack_page + THREAD_SIZE) {
+		ip = *((unsigned long *) sp);
+		if (kernel_text_address(ip) && !in_sched_functions(ip)) {
+			/*
+			 * Skip one valid IP, which will be the low-level UML
+			 * context switcher.
+			 */
+			if (count++ == 1)
+				return ip;
+		}
+
+		sp += sizeof(unsigned long);
+	}
+
+	return 0;
+}
include/asm-um/processor-generic.h +1 -1
Index: linux-2.6.22/include/asm-um/processor-generic.h
===================================================================
@@ -128,6 +128,6 @@ extern struct cpuinfo_um cpu_data[];
 
 
 #define KSTK_REG(tsk, reg) get_thread_reg(reg, &tsk->thread.switch_buf)
-#define get_wchan(p) (0)
+extern unsigned long get_wchan(struct task_struct *p);
 
 #endif

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 465

Quoted 3 lines · Jeff Dike
arch/um/kernel/process.c +3 -0
+unsigned long get_wchan(struct task_struct *p)
+{
+	unsigned long stack_page, sp, ip, count = 0;

Perhaps instead of unsigned long?

bool skipped_ip; //delayed initialization

Quoted 7 lines
arch/um/kernel/process.c +7 -0
+
+	if ((p == NULL) || (p == current) || (p->state == TASK_RUNNING))
+		return 0;
+
+	stack_page = (unsigned long) task_stack_page(p);
+	/* Bail if the process has no kernel stack for some reason */
+	if (stack_page == 0)

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 482

Quoted 10 lines
arch/um/kernel/process.c +10 -0
+		return 0;
+
+	sp = p->thread.switch_buf->JB_SP;
+	/*
+	 * Bail if the stack pointer is below the bottom of the kernel
+	 * stack for some reason
+	 */
+	if (sp < stack_page)
+		return 0;
+
	skipped_ip = false;

arch/um/kernel/process.c unsigned long arch_align_stack(unsigned · line 491

Quoted 9 lines
arch/um/kernel/process.c +9 -0
+	while (sp < stack_page + THREAD_SIZE) {
+		ip = *((unsigned long *) sp);
+		if (kernel_text_address(ip) && !in_sched_functions(ip)) {
+			/*
+			 * Skip one valid IP, which will be the low-level UML
+			 * context switcher.
+			 */
+			if (count++ == 1)
+				return ip;
			if (skipped_ip)
				return ip;
			skipped_ip = true;
Quoted 5 lines
arch/um/kernel/process.c +4 -0
+		}
+
+		sp += sizeof(unsigned long);
+	}
author
#2 lore raw
Quoted 3 lines · Joe Perches

Perhaps instead of unsigned long?

bool skipped_ip; //delayed initialization

Ooh, I forgot we had bool. I'll fix that in a later patch.

Jeff

Signature · 11 lines
Work email - jdike at linux dot intel dot com

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel