Skip to contentSkip to conversation

kernel stack size

DISCUSSION ooyama eiichi 5 participants 9 messages Apr 2, 2005

lore
Share & tools
lore
#0 lore raw

Hi all,

How can I know the rest size of the kernel stack.
(in my kernel driver)
Thanks.

#1 lore raw
Quoted 1 line · ooyama eiichi

How can I know the rest size of the kernel stack.

you can't in a platfork-independant way

Quoted 1 line

(in my kernel driver)

*why* do you want to do this?

#2 lore raw

Thanks for your reply.

Quoted 5 lines · ooyama eiichi
Quoted 2 lines

How can I know the rest size of the kernel stack.

you can't in a platfork-independant way

in i386 and ia64.

Quoted 5 lines
Quoted 2 lines

(in my kernel driver)

*why* do you want to do this?

because my driver hungs the machine by an certain ioctl. and it seems to me there is no bad in the code correspond to the ioctl, except for that it is using large auto variables. (some functions are useing ~1KB autos)

#3 lore raw
Quoted 1 line · ooyama eiichi

in i386 and ia64.

search for CONFIG_DEBUG_STACKOVERFLOW in arch/i386/kernel/irq.c

ia64 has fairly large stacks so you probably won't need to check there if you get the above working

Quoted 4 lines

because my driver hungs the machine by an certain ioctl. and it seems to me there is no bad in the code correspond to the ioctl, except for that it is using large auto variables. (some functions are useing ~1KB autos)

don't do that, even if you make it 'apparently' work for you it will just end up being a problem mater on or for someone else

#4 lore raw
Quoted 5 lines · ooyama eiichi
Quoted 2 lines

in i386 and ia64.

search for CONFIG_DEBUG_STACKOVERFLOW in arch/i386/kernel/irq.c

Oh, very good information for me.

Quoted 3 lines

ia64 has fairly large stacks so you probably won't need to check there if you get the above working

in ia64, he works properly.

Quoted 9 lines
Quoted 5 lines

because my driver hungs the machine by an certain ioctl. and it seems to me there is no bad in the code correspond to the ioctl, except for that it is using large auto variables. (some functions are useing ~1KB autos)

don't do that, even if you make it 'apparently' work for you it will just end up being a problem mater on or for someone else

I changed these to using kmalloc().
(but not yet confirmed for my driver to work properly)

Thanks very much.

#5 lore raw
Quoted 11 lines · ooyama eiichi
Quoted 8 lines
Quoted 4 lines

because my driver hungs the machine by an certain ioctl. and it seems to me there is no bad in the code correspond to the ioctl, except for that it is using large auto variables. (some functions are useing ~1KB autos)

don't do that, even if you make it 'apparently' work for you it will just end up being a problem mater on or for someone else

I changed these to using kmalloc().
(but not yet confirmed for my driver to work properly)

You can also use globally static variables too. But this makes for non-reentry code.

Sometimes I don't feel that a kmalloc is worth it, and if the function in question for the driver would seldom have problems with reentry, I use a statically defined global, and protect it with spin_locks. If these can also be used in interrupt context, you need to use the spin_lock_irqsave variants. But don't do this if the critical section has long latencies.

-- Steve

#6 lore raw
Quoted 9 lines · Steven Rostedt

You can also use globally static variables too. But this makes for non-reentry code.

Sometimes I don't feel that a kmalloc is worth it, and if the function in question for the driver would seldom have problems with reentry, I use a statically defined global, and protect it with spin_locks. If these can also be used in interrupt context, you need to use the spin_lock_irqsave variants. But don't do this if the critical section has long latencies.

... and the first time copy_from_user() blocks under your spinlock you will get a nice shiny deadlock.

#7 lore raw
Quoted 11 lines · Al Viro
Quoted 9 lines · Steven Rostedt

You can also use globally static variables too. But this makes for non-reentry code.

Sometimes I don't feel that a kmalloc is worth it, and if the function in question for the driver would seldom have problems with reentry, I use a statically defined global, and protect it with spin_locks. If these can also be used in interrupt context, you need to use the spin_lock_irqsave variants. But don't do this if the critical section has long latencies.

Quoted 2 lines

... and the first time copy_from_user() blocks under your spinlock you will get a nice shiny deadlock.

I forgot that he mentioned that this was for ioctls. I then use semaphores if I need to access userspace. But if it just needs to modify data around areas that only the kernel uses, without access to userspace, than I use spinlocks.

I admit you really need to know what you're doing to use this method. If I believe that a kmalloc would be too expensive, then I use the locking of static variables. But each situation is different and I try to use the best method for the occasion.

-- Steve

#8 lore raw
In reply to ooyama eiichi
Quoted 16 lines · ooyama eiichi

Thanks for your reply.

Quoted 6 lines · ooyama eiichi
Quoted 3 lines

How can I know the rest size of the kernel stack.

you can't in a platfork-independant way

in i386 and ia64.

Quoted 2 lines
Quoted 1 line

(in my kernel driver)

Quoted 7 lines
Quoted 2 lines

*why* do you want to do this?

because my driver hungs the machine by an certain ioctl.
and it seems to me there is no bad in the code correspond to the ioctl, except for that it is using large auto variables. (some functions are useing ~1KB autos)

That's your problem. Use kmalloc instead of large local variables.

--
Brian Gerst