Skip to contentSkip to conversation

stack and scheduler patches

uml-devel Allan Graves 3 participants 6 messages Aug 31, 2005 – Sep 6, 2005 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

Jeff,
Here's the patches. Hope these meet your approval! Allan

arch/um/kernel/process_kern.c +11 -2
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/arch/um/kernel/process_kern.c linux-2.6.13-stack/arch/um/kernel/process_kern.c
@@ -113,8 +113,17 @@
 
 void *_switch_to(void *prev, void *next, void *last)
 {
-	return(CHOOSE_MODE(switch_to_tt(prev, next), 
-			   switch_to_skas(prev, next)));
+        struct task_struct *from=(struct task_struct*)prev;
+        struct task_struct *to=(struct task_struct*)next;
+
+        to->thread.prev_sched = from;
+        set_current(to);
+
+          CHOOSE_MODE(switch_to_tt(prev, next),
+             switch_to_skas(prev, next));
+
+        return(current->thread.prev_sched); 
+
 }
 
 void interrupt_end(void)
arch/um/kernel/skas/include/mode_kern-skas.h +1 -1
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/arch/um/kernel/skas/include/mode_kern-skas.h linux-2.6.13-stack/arch/um/kernel/skas/include/mode_kern-skas.h
@@ -11,7 +11,7 @@
 #include "asm/ptrace.h"
 
 extern void flush_thread_skas(void);
-extern void *switch_to_skas(void *prev, void *next);
+extern int switch_to_skas(void *prev, void *next);
 extern void start_thread_skas(struct pt_regs *regs, unsigned long eip,
 			      unsigned long esp);
 extern int copy_thread_skas(int nr, unsigned long clone_flags,
arch/um/kernel/skas/process_kern.c +2 -4
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/arch/um/kernel/skas/process_kern.c linux-2.6.13-stack/arch/um/kernel/skas/process_kern.c
@@ -24,7 +24,7 @@
 #include "proc_mm.h"
 #include "registers.h"
 
-void *switch_to_skas(void *prev, void *next)
+int switch_to_skas(void *prev, void *next)
 {
 	struct task_struct *from, *to;
 
@@ -35,8 +35,6 @@
 	if(current->pid == 0)
 		switch_timers(0);
 
-	to->thread.prev_sched = from;
-	set_current(to);
 
 	switch_threads(&from->thread.mode.skas.switch_buf, 
 		       to->thread.mode.skas.switch_buf);
@@ -44,7 +42,7 @@
 	if(current->pid == 0)
 		switch_timers(1);
 
-	return(current->thread.prev_sched);
+	return(0);
 }
 
 extern void schedule_tail(struct task_struct *prev);
arch/um/kernel/tt/include/mode_kern-tt.h +1 -1
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/arch/um/kernel/tt/include/mode_kern-tt.h linux-2.6.13-stack/arch/um/kernel/tt/include/mode_kern-tt.h
@@ -11,7 +11,7 @@
 #include "asm/ptrace.h"
 #include "asm/uaccess.h"
 
-extern void *switch_to_tt(void *prev, void *next);
+extern int switch_to_tt(void *prev, void *next);
 extern void flush_thread_tt(void);
 extern void start_thread_tt(struct pt_regs *regs, unsigned long eip,
 			   unsigned long esp);
arch/um/kernel/tt/process_kern.c +2 -4
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/arch/um/kernel/tt/process_kern.c linux-2.6.13-stack/arch/um/kernel/tt/process_kern.c
@@ -26,7 +26,7 @@
 #include "init.h"
 #include "tt.h"
 
-void *switch_to_tt(void *prev, void *next, void *last)
+int switch_to_tt(void *prev, void *next, void *last)
 {
 	struct task_struct *from, *to, *prev_sched;
 	unsigned long flags;
@@ -36,7 +36,6 @@
 	from = prev;
 	to = next;
 
-	to->thread.prev_sched = from;
 
 	cpu = from->thread_info->cpu;
 	if(cpu == 0)
@@ -53,7 +52,6 @@
 	forward_pending_sigio(to->thread.mode.tt.extern_pid);
 
 	c = 0;
-	set_current(to);
 
 	err = os_write_file(to->thread.mode.tt.switch_pipe[1], &c, sizeof(c));
 	if(err != sizeof(c))
@@ -86,7 +84,7 @@
 	flush_tlb_all();
 	local_irq_restore(flags);
 
-	return(current->thread.prev_sched);
+        return(0);
 }
 
 void release_thread_tt(struct task_struct *task)
arch/um/drivers/mconsole_kern.c +50 -0

68 lines not on this page · raw message

arch/um/drivers/mconsole_user.c +1 -0
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/arch/um/drivers/mconsole_user.c linux-2.6.13-stack/arch/um/drivers/mconsole_user.c
@@ -30,6 +30,7 @@
 	{ "go", mconsole_go, MCONSOLE_INTR },
 	{ "log", mconsole_log, MCONSOLE_INTR },
 	{ "proc", mconsole_proc, MCONSOLE_PROC },
+        { "stack", mconsole_stack, MCONSOLE_INTR },
 };
 
 /* Initialized in mconsole_init, which is an initcall */

Binary files linux-2.6.13/arch/um/drivers/.mconsole_user.c.swp and linux-2.6.13-stack/arch/um/drivers/.mconsole_user.c.swp differ

arch/um/include/mconsole.h +1 -0
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/arch/um/include/mconsole.h linux-2.6.13-stack/arch/um/include/mconsole.h
@@ -81,6 +81,7 @@
 extern void mconsole_go(struct mc_request *req);
 extern void mconsole_log(struct mc_request *req);
 extern void mconsole_proc(struct mc_request *req);
+extern void mconsole_stack(struct mc_request *req);
 
 extern int mconsole_get_request(int fd, struct mc_request *req);
 extern int mconsole_notify(char *sock_name, int type, const void *data, 
arch/um/kernel/process_kern.c +10 -0
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/arch/um/kernel/process_kern.c linux-2.6.13-stack/arch/um/kernel/process_kern.c
@@ -119,8 +120,18 @@
         to->thread.prev_sched = from;
         set_current(to);
 
+        do 
+        { 
+          current->thread.saved_task = NULL ;
           CHOOSE_MODE(switch_to_tt(prev, next),
              switch_to_skas(prev, next));
+          if(current->thread.saved_task) 
+            show_regs(&(current->thread.regs));
+            next=(void *)current->thread.saved_task;
+            prev=(void*)current;
+        } while(current->thread.saved_task);
+
+
 
         return(current->thread.prev_sched); 
 
include/asm-um/processor-generic.h +1 -0
diff -uNr -x '.dep*' -x '.hdep*' -x '*.[oas]' -x '*~' -x '#*' -x '*CVS*' -x '*.orig' -x '*.rej' -x '*.old' -x '.menu*' -x asm -x local.h -x System.map -x autoconf.h -x compile.h -x version.h -x .version -x defkaymap.c -x uni_hash.tbl linux-2.6.13/include/asm-um/processor-generic.h linux-2.6.13-stack/include/asm-um/processor-generic.h
@@ -21,6 +21,7 @@
 	 * copy_thread) to mark that we are begin called from userspace (fork /
 	 * vfork / clone), and reset to 0 after. It is left to 0 when called
 	 * from kernelspace (i.e. kernel_thread() or fork_idle(), as of 2.6.11). */
+	struct task_struct *saved_task;
 	int forking;
 	int nsyscalls;
 	struct pt_regs regs;
#1 lore raw
Quoted 3 lines · Allan Graves

Jeff,
Here's the patches. Hope these meet your approval! Allan

Some comments - I have these all fixed:

+ struct task_struct *from=(struct task_struct*)prev;
+ struct task_struct *to=(struct task_struct*)next;
There's no need to cast when the source is a void *

+ CHOOSE_MODE(switch_to_tt(prev, next),
+ switch_to_skas(prev, next));
There's a CHOOSE_MODE_PROC which lets you avoid repeating common argument lists, although I was doing this wrong here too.

	+extern int switch_to_skas(void *prev, void *next);
	+extern int switch_to_tt(void *prev, void *next);

Since these can't do anything but return 0, they might as well be void

+ if (0==sscanf(ptr, "%d", &pid_requested) || pid_requested==-1) {
The pid_requested==-1 is redundant - if sscanf failed, we just want to bail out

+ if((!to) || (pid_requested == 0)) {
Why the check against 0?

	+		next=(void *)current->thread.saved_task;
	+		prev=(void*)current;

No need to cast when the target is a void * either

Also, OK for me to add a Signed-off-by: you?

Jeff

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw
Quoted 3 lines · Jeff Dike
Quoted 2 lines · Allan Graves

Jeff,
Here's the patches. Hope these meet your approval!

Could you please write a proper changelog? Reading a patch is possible, but needs time which I don't have in the very moment.

Also, what is the difference between your "stack trace" patch, which adds a member to thread_struct, for each process, so I'd like a minimum of justification, and one of the sysrq options which does exactly this?

Apart that the second is currently buggy, and is global, as in what you plan here:

/* Would be nice:
+ 1) Send showregs output to mconsole.
+ 2) Add a way to stack dump all pids.
+ */

Sorry if these questions seem bad - but that's why changelogs are used.

Quoted 1 line
Quoted 1 line

Allan

Signature · 23 lines
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade

	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#3 lore raw

[uml-devel] sched and stack patch changelogs.

BB: Sorry I hadn't included a changelog, Jeff and I had talked about this a lot, I forgot that other people would be reading them. :)

Author: Allan Graves<[email protected]>
Scheduler Cleanup Patch:
This patch moves code that is in both switch_to_tt and switch_to_skas to the top level _switch_to function, keeping us from duplicating code. It is required for the stack trace patch to work properly.

Stack Trace Patch:
This patch implements a stack trace for a thread, not unlike sysrq-t does. The advantage to this is that a break point can be placed on showreqs, so that upon showing the stack, you jump immediately into the debugger. While sysrq-t does the same thing, sysrq-t shows *all* threads stacks. It also doesn't work right now. In the future, I thought it might be acceptable to make this show all pids stacks, but perhaps leaving well enough alone and just using sysrq-t would be okay. For now, upon receiving the stack command, UML switches context to that thread, dumps its registers, and then switches context back to the original thread. Since UML compacts all threads into one of 4 host threads, this sort of mechanism could be expanded in the future to include other debugging helpers that sysrq does not cover.

Quoted 21 lines · Blaisorblade
Quoted 7 lines · Jeff Dike
Quoted 4 lines · Allan Graves

Jeff,
Here's the patches. Hope these meet your approval!

Could you please write a proper changelog? Reading a patch is possible, but needs time which I don't have in the very moment.

Also, what is the difference between your "stack trace" patch, which adds a member to thread_struct, for each process, so I'd like a minimum of justification, and one of the sysrq options which does exactly this?

Apart that the second is currently buggy, and is global, as in what you plan here:

/* Would be nice:

arch/um/drivers/mconsole_kern.c +3 -0
+           1) Send showregs output to mconsole.
+           2) Add a way to stack dump all pids.
+        */
Quoted 9 lines

Sorry if these questions seem bad - but that's why changelogs are used.

Quoted 3 lines
Quoted 3 lines

Allan

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#4 lore raw
In reply to Blaisorblade
Quoted 3 lines · Blaisorblade

Also, what is the difference between your "stack trace" patch, which adds a member to thread_struct, for each process, so I'd like a minimum of justification, and one of the sysrq options which does exactly this?

What this does, and sysrq t doesn't, is allow you to put a breakpoint on that show_regs call and force a particular thread back into context. Then you can poke around the stack with gdb. You could so this in tt mode, but not previously in skas mode, and people have missed this.

Jeff

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#5 lore raw
In reply to Jeff Dike

Void casting: my compiler gave me a warning, and I don't like that.
pid=-1, leftover from error checking that i didn't need, my fault.
pid=0, find_task_by_pid(0) will return a valid pointer, but it doesn't seem to really be a good task. This seems to be related to the kernel idle task. If you pass 0, it will seg fault w\o the check. I'm not sure what a signed off-by does, but long as i can get bb to agree with this.... i'm okay with it. :)
Allan

Quoted 30 lines · Jeff Dike
Quoted 5 lines · Allan Graves

Jeff,
Here's the patches. Hope these meet your approval! Allan

Some comments - I have these all fixed:

+ struct task_struct *from=(struct task_struct*)prev;
+ struct task_struct *to=(struct task_struct*)next;
There's no need to cast when the source is a void *

+ CHOOSE_MODE(switch_to_tt(prev, next),
+ switch_to_skas(prev, next));
There's a CHOOSE_MODE_PROC which lets you avoid repeating common argument lists, although I was doing this wrong here too.

	+extern int switch_to_skas(void *prev, void *next);
	+extern int switch_to_tt(void *prev, void *next);

Since these can't do anything but return 0, they might as well be void

+ if (0==sscanf(ptr, "%d", &pid_requested) || pid_requested==-1) {
The pid_requested==-1 is redundant - if sscanf failed, we just want to bail out

+ if((!to) || (pid_requested == 0)) {
Why the check against 0?

Quoted 9 lines
	+		next=(void *)current->thread.saved_task;
	+		prev=(void*)current;

No need to cast when the target is a void * either

Also, OK for me to add a Signed-off-by: you?

Jeff

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel