Showing posts with label implementation. Show all posts
Showing posts with label implementation. Show all posts

Friday, April 30, 2021

Math: Simple technique to implement moving averages in Java, C or C++

 The oneline solution is:

accumulator = (alpha * new_value) + (1.0 - alpha) * accumulator
Here,

Accummulator - holds the value being tracked
alpha - value between 0 and 1.

The more aggressive the alpha (closer to 1) the  faster the moving average adapts to the recent values. This is an exponential moving average.

Thursday, June 4, 2020

Linux: Why is skb recycling done

Why is this done?
* Saves the cost of allocating and de-allocating memory repeatedly.
* Savings are significant because this is a very frequent operation (usually skb alloc and de-alloc is done on a per-packet basis).

Recent changes to SKB recycling:

"- Make skb recycling available to all drivers, without needing driver
  modifications.

- Allow recycling skbuffs in more cases, by having the recycle check
  in __kfree_skb() instead of in the ethernet driver transmit
  completion routine.  This also allows for example recycling locally
  destined skbuffs, instead of only recycling forwarded skbuffs as
  the transmit completion-time check does.

- Allow more consumers of skbuffs in the system use recycled skbuffs,
  and not just the rx refill process in the driver.

Friday, August 30, 2019

Which Linux Kernel timing or delay APIs to use for what?

I classify the waiting or timing API in the Linux kernel in two categories:
1. Which blocks the current thread of execution.
2. Something which has to be scheduled for later but we want the current thread to continue.
In most cases, the distinction between 1 and 2 is clear, but the techniques used to implement 2 can also be manipulated to behave like 1.


1. Blocking current thread of execution (Inline delays)
The API for 1. in the above case are:

Wednesday, December 6, 2017

Linux: Why use MSI over the GIC mechanism (Brief)

MSIs are implemented as a write from the device rasising the interrupt to a special memory location which causes raising of the MSI.

Two main reasons to consider MSI over PICs:

1. Speed: Pin based PCI interrupts are usually shared across devices and hence we would typically need to invoke each associated interrupt handler. MSIs are not shared so this does not arise.
Another case is that PCI can only support single interrupt per function. In this case drivers have to explicitly check what event happened (e.g. tx done, rx etc for a single MAC interrupt in case of Wifi radios). Using MSI, there could be a dedicated interrupt for each type of event (from the MAC).


2. Consistency: In case of pin based interrupts, the interrupt may be raised before the complete data has arrived in memory. There are ways to work around this. However, in case of MSIs this is not a concern since MSI writes cannot pass data writes on the bus.

Reference:
Linux Kernel Documentation - https://www.kernel.org/doc/Documentation/PCI/MSI-HOWTO.txt

Friday, November 13, 2015

Uplink Airtime Fairness Control

Problem statement:
There is currently no direct way to control uplink airtime usage of wireless clients on a WLAN without actually implementing something on the client. This is not always possible because of multiple reasons:
Diversity in the operating systems and hardware of client devices.
Privacy issues
General aversion to install 3rd party control software.

Abstract of the idea:
In this case, we address the issue of limiting the airtime used the clients in the uplink direction by controlling the TCP window size in the uplink direction. We do this by doing a deep packet inspection of open TCP sessions for every client and then appropriately limiting the advertised TCP window based on bandwidth consumption by the clients.
Download PDF
Download Citation