public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: liyu <liyu@ccoss.com.cn>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [Question] one question about 'current' in scheduler_tick()
Date: Tue, 18 Oct 2005 09:58:51 +0800	[thread overview]
Message-ID: <435456DB.70404@ccoss.com.cn> (raw)
In-Reply-To: <Pine.LNX.4.58.0510170519540.5859@localhost.localdomain>

Steven Rostedt wrote:

>On Mon, 17 Oct 2005, liyu wrote:
>
>  
>
>>Hi Steve, Thanks once again :)
>>
>>    I searched arch/i386/kernel/irq.c, and got this line of code:
>>
>>    irqctx->tinfo.task = curctx->tinfo.task;
>>
>>    I think it just is answer that I want to get. It seem interrupt
>>stack is
>>created at top of the original kernel stack. Are my words right?
>>    
>>
>
>Not with 4KSTACK.  With 4KSTACK defined, the interrupts have their own
>stack.  So lets look at how current works (for x86).
>
>static inline struct task_struct * get_current(void)
>{
>	return current_thread_info()->task;
>}
>
>#define current get_current()
>
>OK, current is really a MACRO that calls get_current, which then calls
>current_thread_info to get the task structure.
>
>Now current_thread_info is
>
>/* how to get the thread information struct from C */
>static inline struct thread_info *current_thread_info(void)
>{
>	struct thread_info *ti;
>	__asm__("andl %%esp,%0; ":"=r" (ti) : "0" (~(THREAD_SIZE - 1)));
>	return ti;
>}
>
>
>Where THREAD_SIZE is really the size of the kernel stack:
>
>#ifdef CONFIG_4KSTACKS
>#define THREAD_SIZE            (4096)
>#else
>#define THREAD_SIZE		(8192)
>#endif
>
>4K when CONFIG_4KSTACKS is defined, and 8K otherwise.  Since 4K is half of
>8K (obviously) you need to be more carefull not to overflow the stack.  So
>to help with this, we give interrupts there own stacks.  When
>CONFIG_4KSTACKS is _not_ defined, interrupts just use the stack of the
>current running thread.
>
>So the thread_info is really just placed on the bottom (or top, depending
>on your view of where things get added).  This memory used for the stack
>is _always_ page aligned and always a multiple of pages. So the kernel
>takes advantage of this. By placing the thread_info at the bottom of the
>stack, you only need to mask off the bits on the stack pointer to find the
>thread_info.
>
>  
>
>>    In passing, How 'current' work in this case when we disable 4KSTACK?
>>I just found these code only be compiled when we define CONFIG_4KSTACK,
>>but cann't found #else branch relevantly.
>>
>>    
>>
>
>You don't need to do this copy when CONFIG_4KSTACKS is not defined,
>because it is already there.  Since the thread_info is on the threads
>stack, and the interrupts also use the current thread's stack (when
>CONFIG_4KSTACKS is not defined), there's no need to copy.
>
>Now when you do define CONFIG_4KSTACKS, which make the interrupts use
>their own stack, you must copy the thread_info to the interrupt stack
>otherwise current will not work for interrupts.
>
>-- Steve
>
>  
>
Hi, Steve:

    I read carefully code about it in arch/i386/kernel/irq.c. Follow is
my understand on it:

    When we disabled/undefined CONFIG_4KSTACK, IOW, we use more bigger 
kernel stack,
the interrupt handler will use kernel stack of current task quietly at 
this time,
elsewise, the the interrupt handler will use 
&hardirq_stack[current_cpu_num*THREAD_SIZE]
as its kernel stack, and beacause of interrupt is disabled when one 
interrupt is
handling (on i386 architecture at least), so although this kernel stack 
of interrupt is
static allocated, we still do not need care we only have one this stack.

    Of course, our kernel stack at all time is page aligned. so current 
macro can work
normally.

    While I already thanks Steve N times :) , I still send my thanks to 
him again.

-liyu



      reply	other threads:[~2005-10-18  1:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-17  8:05 [Question] one question about 'current' in scheduler_tick() liyu
2005-10-17  8:24 ` Steven Rostedt
2005-10-17  9:02   ` liyu
2005-10-17  9:32     ` Steven Rostedt
2005-10-18  1:58       ` liyu [this message]

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=435456DB.70404@ccoss.com.cn \
    --to=liyu@ccoss.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox