Re: [patch] Real-Time Preemption, -RT-2.6.13-rc4-V0.7.52-01

George Anzinger
2005-08-03T01:14:32Z

Steven Rostedt wrote:
> On Tue, 2005-08-02 at 16:38 -0700, Daniel Walker wrote:
>
>>Couldn't you just do some math off current->timestamp to see how long
>>the task has been running? This per arch stuff seems a bit invasive..
>
>
> The thing is, I'm tracking how long the task is running in the kernel
> without doing a schedule. That's actually easy, but I don't want to
> count when the task is in userspace. The per-arch is only updating so
> that we don't count user space, otherwise the count could be in the
> task_struct. If there is an arch-independent way to tell if a task is
> running in user-space or kernel when an interrupt goes off then I would
> use it. The per arch is actually easy, and I would write it, but I
> don't have the hardware now to test it. I could at least do PPC and
> MIPS since I'm quite familiar with both, but I don't currently have a
> cross compiler to compile it.
>
> I understand your point, I would really prefer an arch independent
> solution, but the timestamp from current just wont cut it. Have another
> idea, I'm all open for it.

How about something like:
if (current + THREAD_SIZE/sizeof(long) - (regs + sizeof(pt_regs)) > MAGIC)

The idea is that an interrupt from user space will be the ONLY thing on
the stack while an interrupt from the kernel will have kernel stack
under it. Current is the bottom end of the kernel stack and regs +
sizeof(pt_regs) is where the interrupt context started. Assumptions a)
stack grows down, b) no switch stack at interrupt.
MAGIC is some small number. For x86 user it is actually zero, don't
know about others but the saved context should be the first thing on the
stack so a minimun frame size should do.

--
George Anzinger george@mvista.com
HRT (High-res-timers): http://sourceforge.net/projects/high-res-timers/