edit · history · print

Labs.KernelModules History

Hide minor edits - Show changes to output

Changed lines 97-98 from:
gcc -c -I${KERNELDIR}/include -D__KERNEL__ -DMODULE Myclock.o
to:
@@gcc -c -I${KERNELDIR}/include -D__KERNEL__ -DMODULE Myclock.o@@
Changed lines 17-18 from:
(934380108 184263)
to:
@@934380108 184263@@
Changed lines 9-100 from:
*[[http://tldp.org/LDP/lkmpg/index.html|The Linux Kernel Module Programming Guide]]
to:
*[[http://tldp.org/LDP/lkmpg/index.html|The Linux Kernel Module Programming Guide]]

!!!Problem Statement
Design and construct a module that implements a clock file in /proc. The file
should support only the file read() operation. When read() is called, it
should return a single ASCII string with two numerical substrings separated by
a single space. For example, it must return a string of the form

(934380108 184263)

if the system time variable, xtime, was set to
[@
xtime.tv_sec = 934380108
xtime.tv_usec = 184263
@]

Also provide an application program that demonstrates your module. As one
particular test of your program, write a tight loop of the following form.
[@
#include <stdio.h>
#include <sys/time.h>
#define N...

struct timeval gtodTimes[N];
char *procClockTimes[N];
...
my_clock = fopen("/proc/...", "r");
for( i = 0; i < N; i++ )
{
gettimeofday(&gtodTimes[i], 0);
fgets(procClockTime[i], LENGTH, my_clock);
}

for( i = 0; i < N; i++ )
{
printf("...", gtodTimes[i], procClockTime[i]);
}
@]

Use gettimeofday() to determine the apparent resolution of the clock values
that you read and of the values read from the kernel variable. Explain why
gettimeofday() has a much finer resolution that the 10 millisecond time
between timer interrupts.

!!!Attacking the problem
There is no difference in writing a mudule for UML and for normal kernel. The module interface in the 2.4 kernel looks like:
[@
#include <linux/kernel.h>
#include <linux/module.h>

#include <linux/proc_fs.h>
#include <linux/time.h>

int clock_read(char *buffer,
char **buffer_loc,
off_t offset,
int buffer_length,
int *eof,
void *data)
{
......
}

/* registers with the proc fs. */
int init_func(void)
{
......
create_proc_read_entry("Myclock",
0, /* dafault mode */
NULL, /* parent dir */
clock_read,
NULL); /* client data */
......
}

/* unregisters with the proc fs. */
void exit_func(void)
{
......
remove_proc_entry("Myclock", NULL);
......
}

module_init(init_func);
module_exit(exit_func);
@]

!!!Compiling your module
gcc -c -I${KERNELDIR}/include -D__KERNEL__ -DMODULE Myclock.o

!!!How to submit your assignment
Please submit your module source code, module object, test code, a Makefile, and a README under your "~/Uml/lab3" directory on elgate.
Changed lines 1-9 from:
a
to:
!!Kernel Modules Lab

!!!Objective
You will study the "module", a mechanism unique to Linux. Modules can be used to dynamically add functionality to the kernel. You will write a module that executes as a kernel-space extension of Linux to report the values of the kernel's "xtime" variable.

!!!Background
You should read the ULK book appendix B or LKP book chapter 9. Online resources include
*[[http://www.xml.com/ldd/chapter/book/ch02.html| Chapter 2 Building and Running Modules, Linux Device Drivers, 2nd Edition]]
*[[http://tldp.org/LDP/lkmpg/index.html|The Linux Kernel Module Programming Guide]]
Added line 1:
a
edit · history · print
Page last modified on August 18, 2006, at 09:15 AM EST