Showing posts with label solution. Show all posts
Showing posts with label solution. Show all posts

Sunday, January 22, 2023

Difference between POE-PD and POE-PSE, POE vs POE+

  • POE stands for power over ethernet
  • A POE system consists of two components - a POE-PSE (Power sourcing equipment) the device which provides the power, and a POE-PD (Power delivered) equipment which receives the power over ethernet.
  • PSE equipment examples - POE switches, POE injectors, POE media convertors [1]
  • PD equipment examples - APs, IP cameras, other devices.
  • PSE has 4 types based on PSE, PD power ratings with a 90W PSE max allowing a 71W PD draw on a port [2].
  • PD ratings are only based on the power draw limit - max of 71W - class 8 PD [2]
  • Power delivery limits are based on negotiations determined by the 802.3 standard. 802.3at (POE) delivers 15.4W, 802.3af (POE+)  delivers 25.5W. This is the difference between POE and POE+.
labels: POE, ethernet, difference, solution, networking, IP networks, TLDR

Reference

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

Linux: How to move files between perforce changelists cls

 If you have a file opened as part of an existing changelist, how do we move the file to a different changelist.


Say for example you have created a CL234 and you want to move a file that is already present in your default Cl with the name //depot/test/main.c to your CL234.

The command to do this would be:
p4 reopen -c 234 //depot/test/main.c
The -c switch in the above command is used to specify the changelist#.

Friday, May 7, 2021

Linux: What does IRQ save do in Linux?

 ExcerptUse local_irq_save to disable interrupts on the local processor and remember their previous state. The flags can be passed to local_irq_restore to restore the previous interrupt state.

void local_irq_save(unsigned long flags);
void local_irq_restore(unsigned long flags);

The spinlock version will disable interrupts on all the cores*


Monday, May 3, 2021

Linux: Why do we need an executable stack with nested functions in GCC

 

  • The stack needs to be writable because the trampoline code is written on the stack which needs to be executed (to jump to the nested function). 
A nested function has no linkage by itself. So the trampoline code actually ensures two things:
  1. The outer () functions stack frame is available in the nested function
  2. Jump and execute code from the nested function.
Some other notes:
  • Nested functions are not a part of ANSI C, however, they are part of Gnu C.
  • The only reason nested functions are possibly useful because they use common stack variables.

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, April 29, 2021

Linux: Poking the ethernet driver with the ethtool

 1. Get basic information about the interface

[mylinuxbox@mylinuxbox-linux ~]$ ethtool -i eth4
driver: e1000e
version: 2.1.4-k
firmware-version: 0.13-4
bus-info: 0000:00:19.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no


2. Dump all the hardware registers
[root@mylinuxbox-linux mylinuxbox]# ethtool -d eth4
MAC Registers
-------------
0x00000: CTRL (Device control register)  0x18100240
      Endian mode (buffers):             little
      Link reset:                        normal
      Set link up:                       1
      Invert Loss-Of-Signal:             no
      Receive flow control:              enabled
      Transmit flow control:             enabled
      VLAN mode:                         disabled
      Auto speed detect:                 disabled
      Speed select:                      1000Mb/s
      Force speed:                       no
      Force duplex:                      no
0x00008: STATUS (Device status register) 0x00080083
      Duplex:                            full
      Link up:                           link config
      TBI mode:                          disabled
      Link speed:                        1000Mb/s
      Bus type:                          PCI
      Bus speed:                         33MHz
      Bus width:                         32-bit
0x00100: RCTL (Receive control register) 0x04008002
      Receiver:                          enabled
      Store bad packets:                 disabled
      Unicast promiscuous:               disabled
      Multicast promiscuous:             disabled
      Long packet:                       disabled
      Descriptor minimum threshold size: 1/2
      Broadcast accept mode:             accept
      VLAN filter:                       disabled
      Canonical form indicator:          disabled
      Discard pause frames:              filtered
      Pass MAC control frames:           don't pass
      Receive buffer size:               2048
0x02808: RDLEN (Receive desc length)     0x00001000
0x02810: RDH   (Receive desc head)       0x00000051
0x02818: RDT   (Receive desc tail)       0x00000040
0x02820: RDTR  (Receive delay timer)     0x00000000
0x00400: TCTL (Transmit ctrl register)   0x3003F0FA
      Transmitter:                       enabled
      Pad short packets:                 enabled
      Software XOFF Transmission:        disabled
      Re-transmit on late collision:     disabled
0x03808: TDLEN (Transmit desc length)    0x00001000
0x03810: TDH   (Transmit desc head)      0x0000007A
0x03818: TDT   (Transmit desc tail)      0x0000007A
0x03820: TIDV  (Transmit delay timer)    0x00000008
PHY type:                                unknown

Tuesday, April 27, 2021

Latex: Customizing Footnotes for a neater look

There is a simple hack to do this:
\renewcommand{\thefootnote}{\arabic{footnote}}Arabic numerals, e.g., 1, 2, 3...
\renewcommand{\thefootnote}{\roman{footnote}}Roman numerals (lowercase), e.g., i, ii,... 
\renewcommand{\thefootnote}{\Roman{footnote}}Roman numerals (uppercase), e.g., I, II, ... 
\renewcommand{\thefootnote}{\alph{footnote}}Alphabetic (lowercase), e.g., a, b... 
\renewcommand{\thefootnote}{\Alph{footnote}}Alphabetic (uppercase), e.g., A, ... 
\renewcommand{\thefootnote}{\fnsymbol{footnote}}A sequence of nine symbols,

Changed mine to alphabets. Looks much neater now. 

Friday, July 3, 2020

Linux: Track a packet through the system

Problem statement: You want to debug and track a single packet through the entire system and understand delays etc?
Solution: This is a simple trick that can help in the debugging.
  1. Insert a sequence number in the skb so that it is accessible from all layers.
  2. Print timestamp for this one across all layers.
  3. Using this to track and print packets irrespective of protocol headers and sequences inside.
This way the packet can now be tracked through the entire system.

Wednesday, June 3, 2020

Linux: Kernel crash debugging: BUG: scheduling while atomic

Why do you see that print
"Scheduling while atomic" indicates that you've tried to sleep somewhere that you shouldn't - like within a spinlock-protected critical section or an interrupt handler.

Things to check:

1. In this case you should check if you are actually returning from some code that could cause the lock not to be released or actually sleeping in some part of the code.

2. Another error that may be spitted out during such a crash is :
BUG: workqueue leaked lock or atomic
This clearly indicates that you were not unlocking a certain lock, which could be typically caused by returning from a routine before the lock is released.

Monday, June 1, 2020

WiFi: One line difference between delivery enabled and trigger enabled in U-APSD

Excerpt from wikipedia:
Queues may be configured to be trigger enabled, (i.e. a receipt of a data frame corresponding to the queue acts as trigger), and delivery enabled, (i.e. data stored at those queues will be released upon receipt of a frame). Queues refer to the four ACs defined for WMM.

Sunday, January 5, 2020

Linux: Why is the buddy system needed? - To prevent fragmentation

The buddy system is a mechanism for page management in Linux. It is needed to make sure that the free memory does not get fragmented and unusable. For an overview of the buddy system including a simple example of how it works, see this page [2]. From the same page, "In comparison to other simpler techniques such as dynamic allocation, the buddy memory system has little external fragmentation, and allows for compaction of memory with little overhead. The buddy method of freeing memory is fast, with the maximal number of compactions required equal to log2(highest order). Typically the buddy memory allocation system is implemented with the use of a binary tree to represent used or unused split memory blocks. The "buddy" of each block can be found with an exclusive OR of the block's address and the block's size."

An alternative to the buddy system would be to use the memory management unit (MMU) support to rewire or re-arrange blobs of free pages together to construct larger contiguous pages. However, this will not work for DMA systems which bypass the MMU. Also, modifying the virtual address on a continual basis would make the paging process slow.

Debugging on the buddy system can be done by printing the current stats. This is supported under the /proc/buddyinfo file. As described in the guide from centos.org, fragmentation issues can be debugged. A sample output from the same site is as shown below:
cat /proc/buddyinfo

Saturday, October 26, 2019

Apple IOS: How to backup health data to windows or MAC

This is an old post, but keeping it here for archival.

Before starting you need to have email correctly configured on your phone.
  1. Start the health app
  2. Navigate through "Health Data (folder with heart on it)" -> "All" -> Share icon in top right corner (the square box with the arrow on it).
  3. When you do that you will be prompted for confirmation as below:

Wednesday, October 23, 2019

Linux: Easy solution vim caught deadly signal segv vim preserving files vim finished

Ran into this irritating problem when everything was initially working fine on my system.

I had copy pasted something into the command window by mistake which caused vi to crash and keep spitting this out. I am using a Fedora version.

Thing that I tried which did not work:
1. Rebooting
2. Uninstalling and reinstalling vi

Solution: Under your home directory there is a file .viminfo which contains all the cached vi information. Delete this file. It will get recreated afresh the  next time vi starts. Just deleting this file fixed the problem for me.

Tuesday, October 22, 2019

Linux: Solution Unknown symbol “__aeabi_ldivmod”

You might notice that while compiling for your 32bit platforms your kernel module compiles. However, when you are inserting it we see a failure (either at boot or while explicitly doing an insmod or modprobe).

The reason this "Unknown symbol in module" is seen is because you are in some instruction trying to do a 64bit division in the Linux kernel for an ARM platform (32bit).

Why is the symbol missing though if everything compiles. The compiler wants to do the 64bit div with slow library functions which Linux does not implement. So when the code is run, the symbol (__aeabi_ldivmod) is not found.

The solution to this problem is to use do_div() while including <asm/div64.h>.

Monday, October 21, 2019

Linux: Solution Fatal section header offset is bigger than file size

The error I was seeing while recompiling a driver:
fatal section header offset 32425246532452 in file 'vmlinux' is bigger than filesize=35524847

What helped was trying from scratch:
sudo make distclean
make menuconfig
make modules
sudo make modules_install

Friday, October 18, 2019

Perforce: Protected namespace access denied

I ran into this error when I was creating a new clientspec and tried to checkout a new tree with this clientspec. I was using
p4 sync ...
Protected namespace ... access denied

Found out through debugging that this error was not being generated due to a problem with the permissions on the local directory but rather because the clientspec was incorrectly pointing to a non-existing path on the repository. You are trying to access some part of the repo that is not setup or you dont have permissions to access. Run p4 client and fix the clientspec, and things should work.

Fix the client spec and things work.

Wednesday, October 16, 2019

p4 shelve equivalent in Git with an example

The equivalent of p4 shelve on GIT is stashing.

Say I have modified the file on my repository and I see the following:
techmuser@gw2:~/repositories/softlockup_repo/scripts$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
        modified:   vimrc
no changes added to commit (use "git add" and/or "git commit -a")
Now to shelve these changes, 
techmuser@gw2:~/repositories/softlockup_repo/scripts$ git stash
Saved working directory and index state WIP on master: 80e892a Track git aliases.       modified:   generic_aliases
HEAD is now at 80e892a Track git aliases.

Tuesday, October 15, 2019

Windows: Creating a disk catalog for your external hard drive

On my windows machine, I wanted to create a disk catalog that I could use to see the movies I already had watched or downloaded from my provider.
  1. I found that the easiest way to do this is by creating a text file which has a list of all files on the external drive from that directory and saving that info to a file.
  2. When needed, search the text file which is used as a catalog.

Creation of the catalog is very easy. For your destination path (on the external drive),  do the following:
  1. From the windows start menu, type and search for "cmd"
  2. This will launch the command window.
  3. In the command window run the following command:
DIR "F:\path\to\dir" /s > "C:\List.txt"
This command assumes that F:\path\to\dir is the directory which you are planning to list. The catalog file is the C:\List.txt file which can be read and searched like a normal text file.

For making a catalog from any directory use something like this in a .bat file:
DIR /s > "Catalog.txt"

Sunday, October 13, 2019

Thought Experiment: Why not have multiple woofers for each channel

Ever wondered why there is a single subwoofer and multiple small speakers for higher frequencies?
Because the human hear can only distinguish the higher frequencies spatially. Why?
Because of the wavelength. The base (subwoofer) is the lower frequency sound which is usually a few HZ which would typically have a wavelength of the order of 10s of feet. Hence in this case, the two human ears which are placed less than a feet apart on our head cant differentiate between base sound  from different channels. Hence we only have one subwoofer for the base sounds and multiple smaller  speakers (5.1 or 2.1 stereo) for the higher frequency sounds.