All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@eu.citrix.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] [Mini-OS] make stack size configurable
Date: Thu, 17 Jan 2008 14:07:18 +0000	[thread overview]
Message-ID: <20080117140718.GG11129@implementation.uk.xensource.com> (raw)

make stack size configurable

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Signed-off-by: Grzegorz Milos <gm281@cam.ac.uk>

# HG changeset patch
# User Samuel Thibault <samuel.thibault@eu.citrix.com>
# Date 1200578738 0
# Node ID 92de8fa028b8e6696fa386b7430537d1cf99e429
# Parent  4d261c3c7c20430433da2d59f3037f34f3598046
make stack size configurable

diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/arch/ia64/sched.c
--- a/extras/mini-os/arch/ia64/sched.c	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/arch/ia64/sched.c	Thu Jan 17 14:05:38 2008 +0000
@@ -40,11 +40,11 @@ arch_create_thread(char *name, void (*fu
 	struct thread* _thread;
 
 	_thread = (struct thread*)_xmalloc(sizeof(struct thread), 16);
-	/* Allocate 2 pages for stack, stack will be 2pages aligned */
-	_thread->stack = (char *)alloc_pages(1);
+	/* Allocate pages for stack, stack will be aligned */
+	_thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER);
 	_thread->name = name;
 	memset((void*)&(_thread->regs), 0, sizeof(_thread->regs));
-	_thread->regs.sp = ((uint64_t)_thread->stack) + 2 * PAGE_SIZE - 16;
+	_thread->regs.sp = ((uint64_t)_thread->stack) + STACK_SIZE - 16;
 	_thread->regs.bsp = ((uint64_t)_thread->stack) + 0x10;
 	_thread->regs.rp = FDESC_FUNC(thread_starter);
 	_thread->regs.pfs = 0x82;
diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/arch/x86/sched.c
--- a/extras/mini-os/arch/x86/sched.c	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/arch/x86/sched.c	Thu Jan 17 14:05:38 2008 +0000
@@ -57,7 +57,7 @@
 
 void dump_stack(struct thread *thread)
 {
-    unsigned long *bottom = (unsigned long *)(thread->stack + 2*4*1024); 
+    unsigned long *bottom = (unsigned long *)(thread->stack + STACK_SIZE); 
     unsigned long *pointer = (unsigned long *)thread->sp;
     int count;
     if(thread == current)
@@ -98,13 +98,13 @@ struct thread* arch_create_thread(char *
     struct thread *thread;
     
     thread = xmalloc(struct thread);
-    /* Allocate 2 pages for stack, stack will be 2pages aligned */
-    thread->stack = (char *)alloc_pages(1);
+    /* We can't use lazy allocation here since the trap handler runs on the stack */
+    thread->stack = (char *)alloc_pages(STACK_SIZE_PAGE_ORDER);
     thread->name = name;
     printk("Thread \"%s\": pointer: 0x%lx, stack: 0x%lx\n", name, thread, 
             thread->stack);
     
-    thread->sp = (unsigned long)thread->stack + 4096 * 2;
+    thread->sp = (unsigned long)thread->stack + STACK_SIZE;
     /* Save pointer to the thread on the stack, used by current macro */
     *((unsigned long *)thread->stack) = (unsigned long)thread;
     
diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/arch/x86/setup.c
--- a/extras/mini-os/arch/x86/setup.c	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/arch/x86/setup.c	Thu Jan 17 14:05:38 2008 +0000
@@ -45,7 +45,7 @@ union start_info_union start_info_union;
  * Just allocate the kernel stack here. SS:ESP is set up to point here
  * in head.S.
  */
-char stack[2*8192];
+char stack[2*STACK_SIZE];
 
 extern char shared_info[PAGE_SIZE];
 
@@ -102,7 +102,7 @@ void
 void
 arch_print_info(void)
 {
-	printk("  stack:      %p-%p\n", stack, stack + 2*8192);
+	printk("  stack:      %p-%p\n", stack, stack + sizeof(stack));
 }
 
 
diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/arch/x86/x86_32.S
--- a/extras/mini-os/arch/x86/x86_32.S	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/arch/x86/x86_32.S	Thu Jan 17 14:05:38 2008 +0000
@@ -1,4 +1,5 @@
 #include <os.h>
+#include <arch_mm.h>
 #include <xen/arch-x86_32.h>
 
 .section __xen_guest
@@ -21,12 +22,12 @@ _start:
 _start:
         cld
         lss stack_start,%esp
-        andl $(~(8192-1)), %esp
+        andl $(~(STACK_SIZE-1)), %esp
         push %esi 
         call start_kernel
 
 stack_start:
-	.long stack+(2*8192), __KERNEL_SS
+	.long stack+(2*STACK_SIZE), __KERNEL_SS
 
         /* Unpleasant -- the PTE that maps this page is actually overwritten */
         /* to map the real shared-info page! :-)                             */
diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/arch/x86/x86_64.S
--- a/extras/mini-os/arch/x86/x86_64.S	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/arch/x86/x86_64.S	Thu Jan 17 14:05:38 2008 +0000
@@ -1,4 +1,5 @@
 #include <os.h>
+#include <arch_mm.h>
 #include <xen/features.h>
 
 .section __xen_guest
@@ -18,12 +19,12 @@ _start:
 _start:
         cld
         movq stack_start(%rip),%rsp
-        andq $(~(8192-1)), %rsp
+        andq $(~(STACK_SIZE-1)), %rsp
         movq %rsi,%rdi
         call start_kernel
 
 stack_start:
-        .quad stack+(2*8192)
+        .quad stack+(2*STACK_SIZE)
 
         /* Unpleasant -- the PTE that maps this page is actually overwritten */
         /* to map the real shared-info page! :-)                             */
diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/include/ia64/arch_mm.h
--- a/extras/mini-os/include/ia64/arch_mm.h	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/include/ia64/arch_mm.h	Thu Jan 17 14:05:38 2008 +0000
@@ -33,4 +33,7 @@
 
 #define virt_to_mfn(x)	virt_to_pfn(x)
 
+#define STACK_SIZE_PAGE_ORDER   1
+#define STACK_SIZE              (PAGE_SIZE * (1 << STACK_SIZE_PAGE_ORDER))
+
 #endif /* __ARCH_MM_H__ */
diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/include/x86/arch_mm.h
--- a/extras/mini-os/include/x86/arch_mm.h	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/include/x86/arch_mm.h	Thu Jan 17 14:05:38 2008 +0000
@@ -25,12 +25,15 @@
 #ifndef _ARCH_MM_H_
 #define _ARCH_MM_H_
 
+#ifndef __ASSEMBLY__
+#include <xen/xen.h>
 #if defined(__i386__)
 #include <xen/arch-x86_32.h>
 #elif defined(__x86_64__)
 #include <xen/arch-x86_64.h>
 #else
 #error "Unsupported architecture"
+#endif
 #endif
 
 #define L1_FRAME                1
@@ -53,7 +56,9 @@
 
 #define NOT_L1_FRAMES           1
 #define PRIpte "08lx"
+#ifndef __ASSEMBLY__
 typedef unsigned long pgentry_t;
+#endif
 
 #else /* defined(CONFIG_X86_PAE) */
 
@@ -76,7 +81,9 @@ typedef unsigned long pgentry_t;
  */
 #define NOT_L1_FRAMES           3
 #define PRIpte "016llx"
+#ifndef __ASSEMBLY__
 typedef uint64_t pgentry_t;
+#endif
 
 #endif /* !defined(CONFIG_X86_PAE) */
 
@@ -102,7 +109,9 @@ typedef uint64_t pgentry_t;
 
 #define NOT_L1_FRAMES           3
 #define PRIpte "016lx"
+#ifndef __ASSEMBLY__
 typedef unsigned long pgentry_t;
+#endif
 
 #endif
 
@@ -146,10 +155,14 @@ typedef unsigned long pgentry_t;
 #define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
 #endif /* __i386__ || __x86_64__ */
 
+#ifdef __ASSEMBLY__
+#define PAGE_SIZE       (1 << L1_PAGETABLE_SHIFT)
+#else
 #ifndef CONFIG_X86_PAE
 #define PAGE_SIZE       (1UL << L1_PAGETABLE_SHIFT)
 #else
 #define PAGE_SIZE       (1ULL << L1_PAGETABLE_SHIFT)
+#endif
 #endif
 #define PAGE_SHIFT      L1_PAGETABLE_SHIFT
 #define PAGE_MASK       (~(PAGE_SIZE-1))
@@ -162,6 +175,10 @@ typedef unsigned long pgentry_t;
 /* to align the pointer to the (next) page boundary */
 #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
 
+#define STACK_SIZE_PAGE_ORDER  1
+#define STACK_SIZE             (PAGE_SIZE * (1 << STACK_SIZE_PAGE_ORDER))
+
+#ifndef __ASSEMBLY__
 /* Definitions for machine and pseudophysical addresses. */
 #ifdef CONFIG_X86_PAE
 typedef unsigned long long paddr_t;
@@ -188,6 +205,7 @@ static __inline__ paddr_t machine_to_phy
 	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
 	return phys;
 }
+#endif
 
 #define VIRT_START                 ((unsigned long)&_text)
 
diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/include/x86/arch_sched.h
--- a/extras/mini-os/include/x86/arch_sched.h	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/include/x86/arch_sched.h	Thu Jan 17 14:05:38 2008 +0000
@@ -2,6 +2,7 @@
 #ifndef __ARCH_SCHED_H__
 #define __ARCH_SCHED_H__
 
+#include <arch_mm.h>
 
 static inline struct thread* get_current(void)
 {
@@ -11,7 +12,7 @@ static inline struct thread* get_current
 #else
     register unsigned long sp asm("rsp");
 #endif 
-    current = (void *)(sp & ~8191UL);
+    current = (void *)(sp & ~(STACK_SIZE-1));
     return *current;
 }
 
diff -r 4d261c3c7c20 -r 92de8fa028b8 extras/mini-os/sched.c
--- a/extras/mini-os/sched.c	Thu Jan 17 13:44:56 2008 +0000
+++ b/extras/mini-os/sched.c	Thu Jan 17 14:05:38 2008 +0000
@@ -139,7 +139,7 @@ void schedule(void)
         if(thread != prev)
         {
             list_del(&thread->thread_list);
-            free_pages(thread->stack, 1);
+            free_pages(thread->stack, STACK_SIZE_PAGE_ORDER);
             xfree(thread);
         }
     }

                 reply	other threads:[~2008-01-17 14:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080117140718.GG11129@implementation.uk.xensource.com \
    --to=samuel.thibault@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.