/* A module using sysctl to configure a  busy looping thread */

#define __KERNEL__
#define MODULE
#include <linux/module.h>

#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/timer.h>
#include <linux/sysctl.h>

void busy_loop(void)
{}

#define KERN_BUSY 434 /* a random number, high enough */
enum {BUSY_ON=1, BUSY_OFF};

int busy_ontime = 0;   /* loop 0 ticks */
int busy_offtime = HZ; /* every second */

/* two integer items */
static ctl_table busy_table[] = {
	{BUSY_ON, "ontime", &busy_ontime, sizeof(int), 0644,
	NULL, &proc_dointvec, &sysctl_intvec, /* fill with 0's */},
	{BUSY_ON, "offtime", &busy_offtime, sizeof(int), 0644,
	NULL, &proc_dointvec, &sysctl_intvec, /* fill with 0's */},
	{0}
	};

/* a directory */
static ctl_table busy_kern_table[] = {
	{KERN_BUSY, "busy", NULL, 0, 0555, busy_table},
	{0}
	};

/* the kernel directory */
static ctl_table busy_root_table[] = {
	{CTL_KERN, "kernel", NULL, 0, 0555, busy_kern_table},
	{0}
	};

static struct ctl_table_header *busy_table_header;


int init_module(void) 
{
	busy_table_header = register_sysctl_table(busy_root_table, 0);
	if (!busy_table_header)
		return -ENOMEM;
	busy_loop();
	return 0;
}

void cleanup_module(void)
{
	unregister_sysctl_table(busy_table_header);
}
