Kernel thread stack usage

Alexander Motin mav at FreeBSD.org
Sun Nov 11 09:41:39 PST 2007


> Kostik Belousov wrote:
>>>> The question is: is there correct way to somehow get current kernel
>>>> thread stack usage or just a stack base address?
>>> Digging kernel with a dirty hands I have found the way which looks 
>>> like working. I have briefly tested it on i386.
>>>
>>> printf("%p, %p. Used %d of %d.\n", &var,
>>>   (char *)td->td_kstack + td->td_kstack_pages * PAGE_SIZE,
>>>   (char *)td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
>>>     (char *)&var,
>>>   td->td_kstack_pages * PAGE_SIZE);
>>>
>>> 'var' here is a name of some local variable.
>>>
>>> Can anybody comment correctness of this way or propose another one?
>>
>> Most of the time, you will get the correct value. But, see the
>> vm_thread_new_altstack() in vm/vm_glue.c.

I have seen that. But as I have understood td_altkstack is just a 
temporal storage for original td_kstack value. I don't see how it 
interfere my question.

-- 
Alexander Motin


More information about the freebsd-arch mailing list