Thursday 25 June 2015

A quick guide to git clone

I have source code for my project which I want to share with team.

How to create a repository?

In the server,
git init <src directory>


I have created a repository in a folder. If I move source code to another folder will it create any problem?  No



How do I checkout the source code?

Using clone. Every version of every file for the history of the project is pulled down by default when you run git clone.

For example copy the url of linux kernel code,

Check out using:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
 
 
 
 
 This downloads to the folder linux-stable. Optionally you can specify the folder in which you want the code to be downloaded.

git clone http://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/  <dir_name>

 

Monday 15 June 2015

Introduction to process scheduling in linux

Process scheduler divides the processor time between runnable processes in the system.Scheduler decides which process runs next.(Source code: kernel/sched)

Linux kernel implements priority based scheduling using two schemes:

1. Based on nice values

nice value is a number from -20 to 19 with a default of 0.When nice value is more the process is nicer (i.e) gives up for other processes. In other words, lesser nice value implies higher priority.

For example RFCOMM (used to setup and maintain bluetooth configuration of in the Linux kernel) sets the nice value of -10 using the function call:


                               set_user_nice(current, -10);  [1]

root@ramapriya:/home/devel/linux-4.0.5# ps -el | grep rfcomm
F S   UID   PID  PPID  C PRI  NI   ADDR SZ WCHAN  TTY          TIME   CMD
5 S     0      723     2     0  70   -10    -         0    rfcomm    ?        00:00:00 krfcommd


As seen above nice value is set to -10 for rfcomm.

Processes with small nice value(high priority) receive a larger proportion of processor timeslice (a slice of processor's time).


Nice value can also be set from the command line while execution. Refer to this link:
http://www.thegeekstuff.com/2013/08/nice-renice-command-examples/

2. Based on real-time priority

Default range is 0 to 99. Higher real time priority value indicate greater priority(Unlike nice values, where small nice value indicate high priority).


Great!! Now how how does the scheduler allocate time slice on the basis of nice/real time priority values?


Scheduler thread removes the highest priority context on the runqueue and schedules it.

        new = grab_runnable_context(ctx->prio + 1, spu->node);
        if (new)
                spu_schedule(spu, new);


spu_schedule() calls spu_set_timeslice to set the time slice using the formula: 
max(x * (MAX_PRIO - prio) / (MAX_USER_PRIO / 2), MIN_SPU_TIMESLICE) [2]

user-nice values [ -20 ... 0 ... 19 ] are scaled to time slice values [800ms ... 100ms ... 5ms]


[Note: In kernel 4.0.5, time slice values are: Minimum timeslice is 5 msecs, default timeslice is 100 msecs, maximum timeslice is 800 msecs. (Note: values are taken from sched.c)]


(kernel version: 4.0.5)

[1] net/bluetooth/rfcomm/core.c
[2] include/linux/sched/prio.h