Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, April 16, 2013

Script in bash for compiling a kernel linux

This is a script that helps me in the process of compiling the kernel linux.

I test it on Arch Linux and Ubuntu and works fine if the source of the kernel is in
~/src/linux-KERNEL_VERSION
#!/bin/bash

set -e

if (( $EUID != 0 )); then
 echo "this script must be run as root"
 exit 1
fi

if (( $# != 1 )); then
 echo "pass only the KERNEL_VERSION as parameter"
 exit 1
fi

DISTRO=$(cat /etc/issue | awk '{print $1}')
CORE=$(grep -c processor /proc/cpuinfo)
FLAGS=`expr $CORE + 1`
JFLAGS=-j$FLAGS

cd /home/$SUDO_USER/src/linux-$1

echo "copy the config file"
sleep 1

case $DISTRO in
 "Arch")
  zcat /proc/config.gz > .config
  ;;
 "Ubuntu")
  cp /boot/config* .config
  ;;
esac

KER_NAME=$(cat .config | grep CONFIG_LOCALVERSION | grep -Po '(?<=\")[^)]*(?=\")')

echo "start make"
sleep 1
make $JFLAGS
make modules_install
echo "finish make"
echo "install the kernel"
sleep 1
cp -v arch/x86/boot/bzImage /boot/vmlinuz-$1$KER_NAME
case $DISTRO in
 "Arch")
  mkinitcpio -k $1$KER_NAME -c /etc/mkinitcpio.conf -g /boot/initramfs-$1$KER_NAME.img
  ;;
 "Ubuntu")
  mkinitramfs -o /boot/initrd.img-$1$KER_NAME $1
  ;;
esac

cp System.map /boot/System.map-$1$KER_NAME
echo "updating grub"
sleep 1
cp /boot/grub/grub.cfg /boot/grub/grub.cfg.old
grub-mkconfig -o /boot/grub/grub.cfg

Thursday, October 18, 2012

Multiple forks

This is the code for generate a dynamic number of process (with the system call fork()). The father wait that all the child processes finish.

int main(int argc, char *argv[]){

    if (argc != 2){
        puts("usage prog number_of_process");
        exit(EXIT_FAILURE);
    }

    int num = atoi(argv[1]);
    int i;
    int * pids = malloc(sizeof(int)*num);

    for(i = 0; i < num; i++){

        pids[i] = fork();

        if(pids[i] == 0){
            //This is the code of the child process
            printf("begin %d\n" , i);
            sleep(10); //simulation of work
            printf("finish %d\n", i);
            exit(EXIT_SUCCESS);
        }
    }

    //Waiting the finish of all child processes
    while(wait(NULL)){
        if(errno == ECHILD)
            break;
    }
}

Tuesday, October 9, 2012

Virtual Time

This is a summary of section 1 and 2 of Jefferson's paper of University of Southern California "Virtual Time".

What is Virtual Time?
Virtual time is a paradigm that provides a flexible abstraction of real time in much the same way that virtual memory provides an abstraction of real memory. It is implemented using the Time Warp mechanism.

Programmer's POV: the global virtual clock always progresses forward at an unpredictable rate with respect to real time.
Implementer's POV: there are many local virtual clocks, loosely synchronized, and while all of the virtual clocks tend to go forward toward higher virtual times, they occasionally jump backward.

Event at (x, t) where x is the virtual place and t is the virtual time

Processes communicate only by exchanging messages to any process that it can name.

All messages are stamped with four values:
  • Sender
  • Virtual sender time
  • Receiver
  • Virtual receiver time
Virtual time systems are subject to two fundamental semantic rules:
  1. The virtual send time of each message must be less than its virtual receive time
  2. The virtual time of each event in a process must be less than the virtual time of the next event at that process.
This rule imply:
  • All messages output from any one process are sent in order of virtual send time
  • All messages input to any process are read in order of virtual receive time
The major constraint on the implementation:
If an event A causes event B, then the execution of A and B must be scheduled in real time so that A is completed before B starts.

Monday, September 24, 2012

Raspberry Pi OS

A month ago I bought an ARM GNU/Linux box, the Raspberry PI, it is a small but complete mini-computer.

These are his Specifications:
  • network port
  • GPIO header
  • composite video
  • analogue audio outputs
  • 2 USB port
  • HDMI port
  • mini-USB power
The University of cambridge has produced a free course on building a very simple operating system for the Raspberry Pi in assembly language and I starting to follow it.

Saturday, September 22, 2012

Hello World!!!

Hi, I'm Pasqualino Sorice, I attend the Bachelor of Science in Engineering in Computer Science and Systems (BSE-CSS) at Sapienza of Rome.

I begin this blog in conjunction with the start of works on my bachelor thesis.
I'll try to keep it as update as possible and to include interesting contribution on computer science.

The base of my thesis is a software open source developed by a Sapienza's group of research, the High Performance and Dependable Computing System.

The software is ROOT-Sim (The ROme OpTimistic Simulator).
This is introduction of his website:
The ROme OpTimistic Simulator is an x86-64 Open Source, parallel/distributed simulation platform developed using C/POSIX technology, which is based on a simulation kernel layer that ultimately relies on MPI for data exchange across different kernel instances. The platform transparently supports all the mechanisms associated with parallelization (e.g., mapping of simulation objects on different kernel instances) and optimistic synchronization (e.g., state recoverability).
The programming model supported by ROOT-Sim allows the simulation-model developer to use a simple application-callback function named ProcessEvent() as the event handler, whose parameters determine which simulation object is currently taking control for processing its next event, and where the state of this object is located in memory. In ROOT-Sim, a simulation object is a data structure, whose state can be scattered on dynamically allocated memory chunks, hence the memory address passed to the callback locates a top level data structure implementing the object state-layout.
I'm reading "Parallel and distributed simulation systems" of Richard M. Fujimoto to come into this attractive argument.

I'm sorry for my bad English, but this is the first time I write a post in English.
I hope I haven't made too many grammatical errors.