Wednesday, 24 August 2016

Linux



Q: What is shared memory?



This is the fastest of all IPC schemes. The memory to be shared is mapped into the address space of the processes (that are sharing). The speed achieved is attributed to the fact that there is no kernel involvement. But this scheme needs synchronization.
Various forms of synchronisation are mutexes, condition-variables, read-write locks, record-locks, and semaphores.

Q: Condition variables?

conditional variables allow you to wait for certain condition to occur. In practice your thread may sleep on conditional variable and other thread wakes it up.
/* in thread 1 */
pthread_mutex_lock(mx); /* protecting state access */
if (state == GOOD) {
pthread_cond_wait(cond, mx); /* unlocks the mutex and sleeps, then locks it back */
}
pthread_mutex_unlock(mx);
/* in thread 2 */
pthread_mutex_lock(mx); /* protecting state access */
state = GOOD;
pthread_cond_signal(cond); /* expecting to wake thread 1 up */
pthread_mutex_unlock(mx);

Q:  smp_affinity?

smp_affinity is a bitmask, in which you can specify which CPUs can handle the IRQ, you can set it by doing:
echo 1 > /proc/irq/10/smp_affinity


This means that only the first CPU will handle the IRQ, but you can also echo 5 which means that only the first and fourth CPU can handle the IRQ.


No comments:

Post a Comment