| 1 |
/* -*- linux-c -*- |
| 2 |
* Systemtap Test Module 1 |
| 3 |
* Copyright (C) 2007 Red Hat Inc. |
| 4 |
* |
| 5 |
* This file is part of systemtap, and is free software. You can |
| 6 |
* redistribute it and/or modify it under the terms of the GNU General |
| 7 |
* Public License (GPL); either version 2, or (at your option) any |
| 8 |
* later version. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <linux/kernel.h> |
| 12 |
#include <linux/init.h> |
| 13 |
#include <linux/module.h> |
| 14 |
#include <linux/timer.h> |
| 15 |
#include <linux/jiffies.h> |
| 16 |
|
| 17 |
/* |
| 18 |
* The purpose of this module is to provide a function that can be |
| 19 |
* triggered from user context via a /proc file. Systemtap scripts |
| 20 |
* set probes on the function and run tests to see if the expected |
| 21 |
* output is received. This is better than using the kernel's modules |
| 22 |
* because kernel internals frequently change. |
| 23 |
*/ |
| 24 |
|
| 25 |
/************ Below are the functions to create this module ************/ |
| 26 |
|
| 27 |
struct timer_list simple_timer; |
| 28 |
static const int timer_interval = 5; |
| 29 |
|
| 30 |
static void simple_timer_function(struct timer_list *timer) |
| 31 |
{ |
| 32 |
static int count; |
| 33 |
mod_timer (&simple_timer, jiffies + ( msecs_to_jiffies(timer_interval))); |
| 34 |
if (count) { |
| 35 |
count = 0; |
| 36 |
} |
| 37 |
else { |
| 38 |
count = 1; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
int init_module(void) |
| 43 |
{ |
| 44 |
timer_setup (&simple_timer, simple_timer_function,0); |
| 45 |
mod_timer (&simple_timer, jiffies + msecs_to_jiffies(timer_interval)); |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
void cleanup_module(void) |
| 50 |
{ |
| 51 |
del_timer (&simple_timer); |
| 52 |
} |
| 53 |
|
| 54 |
MODULE_DESCRIPTION("systemtap test module"); |
| 55 |
MODULE_LICENSE("GPL"); |