Thursday, December 19, 2013

Comparison between kprobes, kretprobes and jprobes

kprobes are the basic structure which are used for debugging. 

kretprobes and jprobes are the two structures which work as wrappers around the kprobes structure providing additional information.

Structure of jprobes is as follows:
struct jprobe {
        struct kprobe kp;
        void *entry;    /* probe handling code to jump to */
};

Jprobes allow you to register a function at the *entry pointer which has the same arguments as jprobe.kp.addr = <func add looked up from kallsyms> or jprobe.kp.symbol_name=<func name> for example jprobe.kp.symbol_name = do_fork.
Jprobes are useful in finding out if the arguments passed to the function we are interested in inspecting are correct?

kretprobes on the other hand are a wrapper around kprobes that allow us to register a function handler that is invoked when the function we are interested in returns.
184 struct kretprobe {
185 struct kprobe kp;
186 kretprobe_handler_t handler;
187 kretprobe_handler_t entry_handler;
188 int maxactive;
189 int nmissed;
190 size_t data_size;
191 struct hlist_head free_instances;
192 raw_spinlock_t lock;
193 };

Linux: Example of per CPU variables

In any kernel module that you are building, try this out. Depending on which core the function is invoked from, different variables will get incremented, changing the prints.

#include <linux/percpu.h>
DEFINE_PER_CPU(int, mypcint);
int test_percpu(void);
/* Increments the counter only on the current valid CPU */
int test_percpu()
{
    int i;
    per_cpu(mypcint, smp_processor_id()) = 0;
    per_cpu(mypcint, smp_processor_id())++;
    printk("%s(%d):===================================== \n", __FUNCTION__, __LINE__);
    for (i = 0; i <2; i++)
        printk("CPU %d | mycpint: %d ", i, per_cpu(mypcint, i));
    return 0;
}
This example can be invoked from any kernel module.

Wednesday, December 18, 2013

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.