* [PATCH 3/4] UML - Implement get_wchan
@ 2007-10-30 17:28 Jeff Dike
2007-10-30 17:40 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Dike @ 2007-10-30 17:28 UTC (permalink / raw)
To: Andrew Morton; +Cc: LKML, uml-devel
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.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
---
arch/um/kernel/process.c | 37 +++++++++++++++++++++++++++++++++++++
include/asm-um/processor-generic.h | 2 +-
2 files changed, 38 insertions(+), 1 deletion(-)
Index: linux-2.6.22/arch/um/kernel/process.c
===================================================================
--- linux-2.6.22.orig/arch/um/kernel/process.c 2007-10-29 15:28:25.000000000 -0400
+++ linux-2.6.22/arch/um/kernel/process.c 2007-10-29 15:49:43.000000000 -0400
@@ -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;
+}
Index: linux-2.6.22/include/asm-um/processor-generic.h
===================================================================
--- linux-2.6.22.orig/include/asm-um/processor-generic.h 2007-10-29 15:28:25.000000000 -0400
+++ linux-2.6.22/include/asm-um/processor-generic.h 2007-10-29 15:28:57.000000000 -0400
@@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 3/4] UML - Implement get_wchan
2007-10-30 17:28 [PATCH 3/4] UML - Implement get_wchan Jeff Dike
@ 2007-10-30 17:40 ` Joe Perches
2007-10-30 17:56 ` Jeff Dike
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2007-10-30 17:40 UTC (permalink / raw)
To: Jeff Dike; +Cc: Andrew Morton, LKML, uml-devel
On Tue, 2007-10-30 at 13:28 -0400, Jeff Dike wrote:
> +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
> +
> + 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;
> +
skipped_ip = false;
> + 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;
>
> + }
> +
> + sp += sizeof(unsigned long);
> + }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 3/4] UML - Implement get_wchan
2007-10-30 17:40 ` Joe Perches
@ 2007-10-30 17:56 ` Jeff Dike
0 siblings, 0 replies; 3+ messages in thread
From: Jeff Dike @ 2007-10-30 17:56 UTC (permalink / raw)
To: Joe Perches; +Cc: Andrew Morton, LKML, uml-devel
On Tue, Oct 30, 2007 at 10:40:46AM -0700, Joe Perches wrote:
> 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
--
Work email - jdike at linux dot intel dot com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-10-30 17:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-30 17:28 [PATCH 3/4] UML - Implement get_wchan Jeff Dike
2007-10-30 17:40 ` Joe Perches
2007-10-30 17:56 ` Jeff Dike
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox