Home

News

About

Download

 Current version

Documentation

 Module timers

 HOWTO: Module usage

 Performances

References

Credits

Contributing


Author's homepage

APIC timer Module for Linux
Documentation


HOWTO: Usage of the APIC timer module.

Author: Vincent Oberle

Purpose:

This document shows how to use the APIC timer module. The test module from the distribution is an example.

Content

Preliminary
Timer functions
Without pointers
With pointers

Preliminary

Of course, include uka_apic_timer.h

#include "uka_apic_timer.h"

To programm a timer, you will need to give it a value of the TSC register. To read the TSC register, include asm/msr.h and:

	unsigned long eax, edx;
	unsigned long long offset;

	rdtsc(eax, edx);
	offset = TO_ULL(edx, eax);

TO_ULL is a macro in uka_apic_timer.h to convert the high and the low 32-bits part into a 64-bits number.

Timer functions

The function that is called by a timer when it is issued must have the following definition:

void timer_fn (unsigned long long exp, unsigned long data)
{
	/* Body */
}

The exp parameter is the value of the expires field of the timer, and data the one of the data field.

Without pointers

The first thing to do in order to create and program a timer is to create a apic_timer_list structure.

One solution is to use a structur directly, without pointer.

	static struct apic_timer_list timer;

Note the use of the keyword static, otherwise the structur will be freed from the end of the block.

The second step is to initialize the timer, first by calling init_apic_timer and then by initializing the function and the expires fields.

	init_apic_timer(&timer);
	timer.function = (void*)a_fn;
	timer.expires = an_expires;

And finally, call the add_apic_timer:

	add_apic_timer(&timer);

With pointers

The second solution is to create a dynamic apic_timer_list structur.

Declar a pointer:

	struct apic_timer_list *timer;

And initialize it with kmalloc. You need to include linux/malloc.h.

	timer = (struct apic_timer_list *)kmalloc(sizeof(struct apic_timer_list), 
	                                          GFP_KERNEL);

Then initialize the structur and add it.

	init_apic_timer(timer);
	timer->function = (void*)a_fn;
	timer->expires = an_expires;

	add_apic_timer(timer);

vincent at oberle dot org