Showing posts with label interview. Show all posts
Showing posts with label interview. Show all posts

Monday, November 15, 2021

(C++) How to pass a variable type to a function

 E.g If you need to pass info like this:

void foo(type){
    // Other actions based on type
    cout << sizeof(type);
}

This cannot be done i.e. the type cannot be passed as a parameter since it is not a object and they do not exist at run time. They are only used by the compiler for type information building into the code. This can be instead fullfilled by templatinzing the function.

A template behaves in the following way:

template <typename T>

void foo(other_args) {

    // Other relevant data.

    T  somevar;

    cout << sizeof(somevar) << "    " <<sizeof(T);

}

Typenames can be also used to templatize classes in a similar fashion. 



Saturday, May 8, 2021

WiFi: What is phy restart? Why is it important in dense RF environments?

 Phy restart on radio drivers typically means if the hardware (radio) is able to sync to the preamble of a packet which has a stronger signal strength while it is already in the process of decoding a packet.


This is typically useful in noisy environments to achieve a "capture effect", where the stronger packet is finally decoded at the rx. radio. If the radio does not support PHY restart then typically such a reception would result in a collision on the rx-side at the radio.

Monday, April 26, 2021

Linux: Nagle's Algorithm and How to Disable it

 Nagle's algorithm is a TCP optimization in the kernel stack that waits to aggregate small chunks of bytes before sending packets on a TCP connection. This approach optimizes the amount of frame overhead spent in sending very small packets over the network. However, when the data is fairly sporadic, this could also lead to an increase in the average delay experienced.


Nagle's algorithm running on a host can be disabled by:
echo 1 > /proc/sys/net/ipv4/tcp_low_latency

Monday, November 23, 2020

Linux: Comma separated arguments in an If Statement

 What happens when you write code like this:

    if ((x,y) == true) {

Is it even a legal condition to put in? If yes, why would you use it?

We have an example you could try out:

bash-4.1$ cat test.cc 
#include <iostream>
using namespace std;
int main() {
    int x = 1, y =0;
    if ((x,y) == true) {
        cout << “X TRUE PATH" << endl;
    } else {
        cout << “Y FALSE PATH" << endl;
    }
}

Saturday, May 23, 2020

Linux: Where to use packed structures

Not sure if the structure should be packed or not? When to use one vs the other? What is the default behavior? What do they do?

For answering these questions, please download this PDF tutorial.

Typically this stems from the question, "what is the size of this struct"?

struct test_A
{
char a;
int b;
char c;
} x;
PDF Download

Citation:
Gautam Bhanage, "Padding versus Packing in Embedded Systems Programming", Published online at www.bhanage.com. May 2020. [PDF]

Tuesday, February 28, 2017

Linux: Difference between livelocks and deadlocks

Everyone knows what a deadlock [2] is!

Wait for graph as described on wikipedia
Defn Deadlock:
Two or more entities vying to get two or more locks in out of order. This leads to each entity waiting for the other entity to release the lock. Since no one releases their held lock the system is stuck and there is no easy recovery.

What is a livelock then?

Monday, February 20, 2017

What datastructure does the CFS use and why

CFS is the Linux kernels completely fair scheduler. It uses red black (RB) trees. 

Red Black trees - datastructure
Nice notes on understanding red-black trees are here [1] and [2].

Why and How is it used in the scheduler?

Wednesday, February 1, 2017

Code snippet to maintain moving averages

I want to maintain moving averages over a window without keeping individual elements in that window. A simple way to do it?

double approxRunningAverage (double avgres, double new_measurement) {

    avgres -= avgres / N;
    avgres += new_measurement / N;

    return avgres;
}

Sunday, January 29, 2017

To Pin or not to Pin on Symmetric Multiprocessor Systems


This is a nice interview questions as it helps to determine if the candidate is capable of discerning the tradeoffs in SMP system design. The question is pretty simple, consider a system where you have two cores 1 and 2 and two tasks e.g. timer tasks A and B. How would you design the scheduling in the system?


Citation information:
G. Bhanage, "To Pin or not to Pin on Symmetric Multiprocessor Systems", Tech Report GDB2017-003, bhanage.com, January 2017.

Bibtex:
@misc{bhanage2017pin,
  title={To Pin or not to Pin on Symmetric Multiprocessor Systems},
  author={Bhanage, Gautam},
  journal={http://www.bhanage.com/p/publications.html},
  number={Tech Report GDB2017-003},
  year={2017}
}