Are the Interrupt Stack and the Kernel Stack the same stack? - unix

Or the Interrupt Stack is a special stack cointained in Kernel Stack?
I'm a little bit confused because sometimes my book refers at it with only "stack".

It depends on kernel configuration (CONFIG_4KSTACKS)
Case 1: When CONFIG_4KSTACKS is not set
In this case, kernel stack size per thread is 8K( 2 pages) and ISR will use same kernel stack.
Case 2: When CONFIG_4KSTACKS is set.
In this case, kernel stack size per thread is 4K( 1 page) and ISR will have separate stack of 4k(1 page)
Check http://www.makelinux.net/books/lkd2/ch06lev1sec5 for more updates.

Related

No Stack overflow Exception in Elixir while using regular recursion [duplicate]

-module(demo).
-export([factorial/1]).
factorial(0) -> 1;
factorial(N) ->
N * factorial(N-1).
The factorial is not tail recursive but why is it not overflowing the stack? I am able to get factorial of 100,000 without stack overflow but takes some time to compute.
An Erlang process's "stack" is not stored in the stack given by the system to the process (which is usually a few megabytes) but in the heap. As far as I know, it will grow unbounded until the system refuses to give the VM more memory.
The size includes 233 words for the heap area (which includes the stack). The garbage collector increases the heap as needed.
The main (outer) loop for a process must be tail-recursive. Otherwise, the stack grows until the process terminates.
Source
If you monitor the Erlang VM process in an process monitor like Activity Monitor on OSX or top on other UNIX-like systems, you'll see that the memory usage will keep on increasing until the calculation is complete, at which point a part of the memory (the one where the "stack" is stored) will be released (this happens gradually over a few seconds after the function returns for me).

Dilemma related to function call's increment of SP

In case of push during function call, why the stack pointer moves to a
smaller value by subtracting 4 times the number of registers to be
pushed on the stack?
I got this while reading Understanding the stack
In the same page, it is clearly mentioned about the memory layout of stack :-
It's useful to think of the following aspects of a stack.
stack bottom The largest valid address of a stack. When a stack is initialized, the stack pointer points to the stack bottom.
stack limit The smallest valid address of a stack. If the stack pointer gets smaller than this, then there's a stack overflow (this
should not be confused with overflow from math operations).
Other sections of memory are used for the program and for the heap
(the section of memory used for dynamic memory allocation).
And, talking about the PUSH operation, subtracting 4 times the number of registers to be pushed on the stack is needed because in MIPS architecture, addresses of sequential words differ by 4. And, the registers are 32 bits(4 bytes) for MIPS I instruction set architecture (ISA) and II ISA.
For our stack of 4-byte (full word) data, adding an item means subtracting four from $sp and storing the item in that address.
Here is what that looks like in code. Say that the value to push on the stack is in register $t0:
# PUSH the item in $t0:
subu $sp,$sp,4 # point to the place for the new item,
sw $t0,($sp) # store the contents of $t0 as the new top.
And, so, you can push one or more registers, by setting the stack pointer to a smaller value (usually by subtracting 4 times the number of registers to be pushed on the stack) and copying the registers to the stack.

hardware interrupt on arithmetic overflow?

Those of us who know the Carry and Overflow flag (lets not forget about sign and zero) love them.
My question is, is there a CPU that will interrupt if a carry or overflow flag is set? when it ask it to?
Its way better then having a branch after every arithmetic instruction...
On IA-32 CPUs you have the INTO instruction (that's the letter O, not the number 0) that will go to interrupt handler 4 (#OF) if the overflow flag is set.
There is no equivalent instruction for the carry flag.
Note that this instruction is invalid in 64-bit mode.
The MIPS cpu triggers an exception on overflow.

Getting the start address of the current process's heap?

I am exploring the lower level workings of the system, and was wondering how malloc determines the start address of the heap. Is the heap at a constant offset or is there a call of some sort to get the start address? Does the stack affect the start address of the heap?
sbrk returns the start address of the bytes it adds (or removes). In a fresh process with no heap allocated yet, the first call to sbrk should then return the start address of the "break" section of the heap. If I had to bet, that's what malloc implementations which use brk/sbrk probably do on their first run.
Traditionally, the heap started just above the text section and grew up; stack frames didn't affect start address at all as they grow down towards the unmapped 0 page. However, it's more common these days for
The first address to be randomized, to make it harder for exploits to hit the right address in memory
The heap to be non-contiguous, as malloc() usually just calls mmap() to get an address anywhere in the virtual address space

How do we determine queue and stack size while working on network processor?

While working on a network processor, how can we determine the size of the queue and the stack.
I have mainly used network processor as router while working on BTS development.
Most important thing while determining size is the speed of the processor and the rate at which packets enter/exit the NP.
Also important factor is the parallelism which needs to be maintained.
Like in case of BTS, KPI give a good idea of total voice/GPRS calls that need to be run at load conditions.Based on that calculate total number of queues and decide how many memory LW each queue will take to be properly identified.
Understand that my queue concept does not talk of catering to the actual data; actual voice would be stored in DRAM buffer handles whose other info would be catered by a queue.
Stack size on a NP i dont have much idea of; but again i am not sure if it is a configurable parameter; more to do with the lifetime of total variable along with thier size durign function calls

Resources