Académique Documents
Professionnel Documents
Culture Documents
LAB
INSTRUCTIONS TO CANDIDATES:
December 2009
Table of Content
Day 1
Part 1: Basic Commands
Part 2: The readelf utility
Day 2
Part 1: Linux source
Part 2: Toolchain building and Linux Porting on ARM
Day 3
Part 1: Linux Kernel Module
Day 4
Part 1: Linux Multitasking
Part 2: Linux Thread Programming
Part 3: Kernel module for tasklist
Day 5
Part 1: Cmosram device driver
Day 6
Part 1: Files
Part 2: System call Implementation
Day 7
Part 1: Memory management
Part 2: Memory management system calls
Day 8
Part 1: UART Device Driver Module
Part 2: The stash device driver
Part 3: Race condition and concurrency management
Day 9
Part 1: Interrupt handling
Part 2: TTY driver in Linux
Day 10
Part 1: Kernel timer system calls
Part 2: Kernel timer
Part 3: PCI driver
Part 4: Signal in Linux
Day 1: Basics of Linux Go back to Content
Part 1: Basic Commands
Read the slides given for this lab. Understand and execute the commands.
Part 2: The readelf utility
Write a program to print “hello world”. Create the executable using gcc compiler. Study
the ELF format file for it using readelf utility in Linux.
After finishing this lab session students must be able to answer following questions.
1. What is fork system call is going to do?
2. What is the return value of the fork system call?
3. What is value of pid's of parent and child process.
4. What are the properties inherited by child process from parent.
5. What happens if the fork is called three times in a program?
6. If the process invokes fork system call infinite times, what is the effect on the system
performance?
7. After the fork system call, we have two identical processes parent and child. Now the
CPU has to execute either parent or child. Which process it executes. Why?
8. What are the return values of following system calls getpid(), getppid(), getuid(),
geteuid(), getgid(), getegid()
9. Study the sys/types.h header for pid_t data type. Why we have to use such data types.
10. What is the function of execl system call?
11. Try to use all the exec family of system calls.
12. After invoking execl system call, it will never return to original process. Why?
13. After invoking execl system call, what is the value of process id?
14. What is the function of the wait system call?
15. What is zombie and orphan process?
16. How to avoid zombies in a system?
17. Who will be the parent of orphan process?
18. Zombie process will not consume any system resources. How?
Exercise: Combine error.c pathalloc.c and create static library mylib.a, link this library at
compile time.
.long SYMBOL_NAME(sysSum)
If you don't match number and name in both files, you will get an ``undefined reference to
sysSum'' error message. If you have a working kernel, you have to be careful only about
incrementing the numbers by one and correctly writing your function name. At this point,
you have added your system call; now you should get the new kernel with it.
4. Compile the kernel using the same steps as you followed in day 2 and reboot the system
using this newly created kernel to invoke the system call from a user program.
5. This simple program tests the newly created system call:
#include <linux/unistd.h>
_syscall2(int, sysSum, int,a,int,b)
main(){
printf("the sum of 4+3 is %d\n",sysSum(4,3));
}
The include line indicates where the _syscall definition is located. The next line says our
system call has a return type of int and two arguments of type int.
6. To compile, use the command
gcc -I ~/linux/include
to instruct the compiler to use our include file. After execution, you will see messages: first
the one from sysSum, then the one from the test program.
Day 7 Go back to Content
Part 1: Memory management
1. Learn the given cr3.c module which displays the value of cr3 and cr4 registers in proc
file named cr3. Compile and run it. Observe the result.
2. Learn the given pgdir.c module which creates a pseudo-file that lets users see a visual
depiction of the CPU’s current ‘map’ of ‘virtual memory’. Compile and run it. Observe
the result.
3. Learn the given dram.c device driver module which implements a Linux character-
mode device-driver for the processor's installed physical memory. Compile and run it.
Observe the result.
4. Learn the given mm.c module which allows users to see values stored in some of the
‘mm_struct’ object’s important fields. Compile and run it. Observe the result.
5. Learn the given vma.c module which lets user see the list of VMAs for a task. Compile
and run it. Observe the result.
6. Compare vma demo to ‘/proc/self/maps’
7. Try running the given ‘domalloc.c’ demo. It lets you see how a call to the ‘malloc()’
function would affect an application list of ‘vm_area_struct’ objects. Compile and run it.
Observe the result. NOTE: Install our ‘vma.ko’ kernel-object before running
‘domalloc’
1. What is dangling pointer and memory leak concepts? By using this concepts implement
the programs?
2. Write a program by using memory allocation functions?
Day 8 Go back to Content
Part 1: UART Device Driver Module
1. Study the UART device driver module. Compile and run it. Observe the result.
Part 2: The stash device driver
2. Learn the stash.c device driver. Compile and run it. Observe the result.
3. Add a ‘get_info()’ function to stash driver to create a pseudo-file (named ‘/proc/stash’)
that will show the current contents of the ringbuffer (if any) and the current values for
the ‘head’ and ‘tail’ buffer-indices. Don’t forget: use ‘create_proc_read_entry()’ in your
‘init_module()’ function, and use ‘remove_proc_entry()’ during ‘cleanup’
Part 3: Race condition and concurrency management
1. Observe the problems with the stash device by concurrently accessing it from different
terminals.
2. Learn the given newstash.c driver which removes the concurrency problem of stash
device driver. Compile and run it. Observe the result
3. Learn the given con1.c multithreaded program. Compile and run it. Observe the result -
synchronization problem between the threads of the process.
4. Learn the given con2.c multithreaded program which has spinlock mechanism for
synchronizing between the threads of the process. Compile and run it. Observe the
result - no synchronization problem between the threads of the process but more time.
5. Learn the given con3.c multithreaded program which has nanosleep mechanism.
Compile and run it. Observe the result. Use the Linux ‘time’ command to compare the
performance of ‘con3’ and ‘con2’
6. Revise the ‘con3.c’ program so that a thread will ‘yield’ if it cannot immediately
acquire the mutex.
7. Identify the 'race conditions' that are present in the original 'cmosram.c' driver-code,
and eliminate them from your revised driver, by using the 'rtc_cmos_read()' and
'rtc_cmos_write()' functions (prototyped in the <asm/mc146818rtc.h> header-file).
Day 9 Go back to Content
Part 1: Interrupt handling
1. Learn the given showidt.c program which displays the 126 IDT entries of Pentium PC.
Compile and run it. Observe the result.
2. Learn the given smpinfo.c program which lets users view the MP Floating Pointer and
MP Configuration Table data-structures in the workstation’s ROM-BIOS memory.
Compile and run it. Observe the result.
3. Determine how many ‘buses’ are present in the machines? HINT: Use ‘smpinfo.c’
kernel module and the fact that each bus is described by an entry of type 1 in the MP
Configuration Table
4. Learn the given ioapic.c module which lets users view the current contents of the I/O
APIC Redirection-Table registers. Compile and run it. Observe the result.
5. The keyboard’s interrupt is ‘routed’ by the I/O-APIC Redirection Table’s second entry
(i.e., entry number 1). Determine its interrupt ID-number on the Linux systems? HINT:
Use ‘ioapic.c’ kernel-module
6. Learn the given ioremap.c module which asks the kernel to set up a ‘mapping’ of the
page at physical address 0xFEE00000 into the kernel’s virtual address-space. This is
the page where each processor’s Local-APIC resides. Compile, run and observe result.
7. Try modifying the ‘ioremap.c’ module so it accesses the Local-APIC Identification
Register using a C assignment-statement instead of calling the ‘ioread32()’ function.
Example: int id_register; // declare local ‘int’ variable
register = *(int *)(lapic+0x20); // input value
8. Examine the effect on page-table entries when the ‘ioremap_nocache()’ function
replaces the ‘ioremap()’ function in the ‘ioremap.c’ module
After finishing this lab session student must be able to answer the following questions.
1. What are signals?
2. What are links? Discuss and use different types of links?
3. How do you determine the type of the file?
4. What is the difference between read and execute permission of a directory?