Monday, 14 December 2020

Real time OS and Computer architecture questions - part 1

In this post we will try to go through some of the interview questions asked during qualcomm interview :

https://www.geeksforgeeks.org/qualcomm-audio-interview-experience-for-software-engineer/ > 


1) Difference between semaphore , mutex , and spinlock :

mutex =>

This is lock and unlock mechanism.

i.e one thread will lock and same thread can unlock that.

other threads can wait for lock to be released.

This is used for synchronization.


semaphore => 

This can be counting or binary semaphore.

Binary semaphore can be used as mutex.

But mutex cannot be used as binary semaphore.

Other thread will wait for signal.

This is classing producer consumer problem.

Consumers will wait for signal of producer.

This is used for signaling mechanism.


spinlock => 

spinlock is also a locking mechanism like mutex.

Major difference is that in case of simple mutex, it loses quantum of the

processor when some thread is waiting for some lock to be released, i.e that behave similar

to having a sleep() and processor moves to next thread, and come back after a while to see

if that lock is released or not.

spinlock behaves like a checking lock in a while(1) i.e it keeps the quantum of

processor and waits there until that lock is released. spinlock is useful in case of interrupts as 

we can loose the current context for interrupt i.e we can allow preemption of interrupt


2) Provide some crude implementation of a mutex in C :

well I was not able to find some good implementation of mutex in C , But write in comment section if you found any.


3) Provide some crude implementation of a semaphore in C :

https://www.geeksforgeeks.org/producer-consumer-problem-using-semaphores-set-1/ >

static int semphore;

void signal_or_put( )

{

    semphore++;

}

void wait_or_get()

{

    while( semphore <=0 );

        semphore--;

}


4) what is difference between process and thread :

https://www.geeksforgeeks.org/difference-between-process-and-thread/ >

< https://stackoverflow.com/questions/200469/what-is-the-difference-between-a-process-and-a-thread >

https://stackoverflow.com/questions/41632073/do-threads-share-local-variables >

Threads are small executable section of task; a task can have multiple threads.

The process can have the following states like new, ready, running, waiting, terminated, suspended.

A thread has 3 states: running, ready, and blocked.

Threads shares resources of the process like text, data, IO, process id of parent, and the heap.

However, threads have their own stack frame.

Like process ids threads have thread ids.


5) Memory layout of a C program :

https://www.geeksforgeeks.org/memory-layout-of-c-program/ >


6) Inter process communications :

https://www.geeksforgeeks.org/inter-process-communication-ipc/ >

pipe vs message queue :

https://www.tutorialspoint.com/difference-between-pipes-and-message-queues >

pipe vs named pip :

https://www.quora.com/What-is-the-difference-between-named-and-unnamed-pipes-in-Linux-programming >


7) What happens when 2 same priority interrupt occurs :

< https://www.quora.com/What-happens-when-two-interrupts-with-the-same-priority-comes-to-the-CPU-at-the-same-time >

< https://stackoverflow.com/questions/22638062/what-happens-when-two-interrupts-occur-at-the-same-time-in-linux-kernel >

< https://cs.stackexchange.com/questions/29846/can-an-interrupt-handler-be-preempted >


8) Can we call Sleep() inside an interrupt ( linux question )?

< https://www.quora.com/Why-cant-you-sleep-in-an-interrupt-handler-in-the-Linux-kernel-Is-this-true-of-all-OS-kernels >


9) what is interrupt latency and nested vectored interrupt controller ?

https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors >


10) What is priority inversion and what are possible solution for that ??

There are 2 methods to avoid priority inversion :

1) priority inheritance : Low priority task will take the priority of higher priority task , when high priority task is pending on resources.

2) priority celling : resources will have ( highest priority + 1 ) and accessing task will take priority of resource , however this will only occur when when is no pending task on resource.


11) Race condition and critical section :

https://practice.geeksforgeeks.org/problems/race-condition-in-os >

https://www.tutorialspoint.com/race-condition-critical-section-and-semaphore >


12) Deadlocks :

https://www.geeksforgeeks.org/introduction-of-deadlock-in-operating-system/ >

One of the common way to avoid deadlocks is to have preemption in system.


13) What are different type of schedulers available :

A scheduling algorithm is core and heart of any RTOS , there are 2 popular type of scheduler available:

1) preemptive scheduler

2) cooperative scheduler

However most of RTOS you find in real world are not pure preemptive or cooperative , but they are mix of both.


14) What is so "Real Time" in real time operating system |OR| what is difference between a normal OS and RTOS:

https://www.ni.com/en-in/innovations/white-papers/07/what-is-a-real-time-operating-system--rtos--.html >


15) Cache memory related questions :

Read about cache memory and must read about following terminology:

1) Cache hit , cache miss

2) Cache invalidation

3) Locality of Reference.

4) L1, L2, L3 cache.

5) Write through , write back

https://www.webopedia.com/TERM/C/cache.html >

https://www.geeksforgeeks.org/locality-of-reference-and-cache-operation-in-cache-memory/ >


16) What is difference between SRAM and DRAM :

https://www.geeksforgeeks.org/difference-between-sram-and-dram/ >


17) what is FRAM :

https://www.electronics-notes.com/articles/electronic_components/semiconductor-ic-memory/fram-ferroelectric-ram-memory.php >


18) NVMe , SATA , PCIe :

https://www.quora.com/Whats-the-difference-between-an-SSD-and-NVMe >


19) What is need of word alignment in compiler/computer architecture :

https://stackoverflow.com/questions/381244/purpose-of-memory-alignment >


20) What is difference between Static library and Dynamic library ?

Static and Dynamic Libraries | Set 1 - GeeksforGeeks >

https://medium.com/@StueyGK/static-libraries-vs-dynamic-libraries-af78f0b5f1e4 >



1 comment: