Cisco Systems Interview Question
Software Engineer / DevelopersAFAIK, disabling interrupt on a single processor on a SMP used to disable interrupts on all processors on Linux kernel 2.2. but it was deprecated in 2.4 and removed in 2.6. I didn't go too deep into what is the implementation in the current kernel. One good way to achieve mutual exclusion is using Anderson spin lock.
Look here for a discussion on alternatives:
www.cs.washington.edu/homes/tom/pubs/spinlock.pdf
OK. Disabling interrupt reporting on a CP via cli is a substitute for locking for an uniprocessor host, as long as it is a non-preemptive kernel, or preemption is disabled.
Cpu-s do not "throw" interrupts. ( Maybe one processor can interrupt another via IPI)
In any case, a cli will suppress reporting any interrupts including IPI. The spinlock link above will probably confuse the average reader as it deals with esoterica of various spinlock implementations (not related to the original question whatsoever) . The questioner is probably looking for to having some form of locking in place to protect shared data in addition to the cli, because another (running) cpu may access such data, despite of interrupts being disabled on the current one.
3) "We know disabling interrupts works only if it is single processor(i.e local disabling of interrupts).
Consider this case where we have a SMP(symmetric multi proc) the processor. Processor-1 wants to perform some critical operation so it disables all the interrupts.
What will happen when processor-2 throws an interrupt"
I think the answer to this is if the two interrupt handlers are not using any synchronization mechanism, it will create problem for critical code of interrupt handler-1.
How can be prevent the critical code from being interfered? Well lets assume if the critical code was to operate on some shared resource then it can be placed under spinlock.
or if the question is trying to ask what if they are not operating on shared resource but we still want that first interrupt service routine should get it's work done without any interruption. I think the only way that could happen would be by disabling the device interrupts. ( by writing to interrupt dsiable register of device)
About 3., one of the question is WHY disabling interrupt only works in single core processor. The reason to disable the interrupt in your case is you want to implement mutual exclusion. Besides memory shared mutex implementation, there is another way to provide mutual exclusion, which is to disable the interrupt. By disabling interrupt, a process will not be context switched out of CPU, if this process doesn't make any system calls which cause process to sleep.
Therefore, on uni-processor system if you disable the interrupt, you will be happily executes your critical section because you can't possibly be preempted. However, it doesn't work in multi-core system, because your process will only hold one core, but at the same moment another thread can execute the critical section your process is working. So in this case this implementation of mutual exclusion fails.
2. calloc beasically puts zeros when allocation memory. The program crashes because it tries to pu in 0s to all the page table entries.
- backbone March 29, 2008So the page table is 4096 bytes(somthing like that).. so wehn all the pages are filled that when the program crashes... It does not crash after allocatiing all the 1gb.
3. Answer: P1 will be interrrupted. So the critical operation might have a problem.
Basically when critical operation needs to be done.. have spin locks.. which exist over both p1 and p2.
but again using spin locks has to be done carefully bcoz... they might end up getting into a deadlock(i dint understand how. kindly someone explain).
Deadlock can be avaided if.. we have a interruot handler.. in p1 which disables the interrupt handler and then graps the spin lock..
these things are complex.. and I have made it even more cryptic... the problem is that i did not completely understand what the interviewer was talking..(my first interview in life)... SO if people could elaborate on these lines... it would be helpful for me and the community...