The ROme OpTimistic Simulator  2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
schedule.c File Reference

This is the main source for the Linux Kernel Module which implements a schedule-hook module allowing running a custom function each time a thread is cpu rescheduled. More...

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/errno.h>
#include <linux/device.h>
#include <linux/kprobes.h>
#include <linux/mutex.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/version.h>
#include <linux/interrupt.h>
#include <linux/time.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
#include <linux/preempt.h>
#include <asm/atomic.h>
#include "ld.h"
#include "lend.h"
#include <asm/system.h>
#include "schedule.h"
+ Include dependency graph for schedule.c:

Go to the source code of this file.

Data Structures

struct  backup
 
struct  instr
 

Macros

#define EXPORT_SYMTAB
 
#define X86_CR0_WP   0x00010000
 
#define DEBUG   if(1)
 
#define DEBUG_SCHEDULE_HOOK   if(1)
 
#define PERMISSION_MASK   (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
 
#define PERMISSION_MASK   (S_IRUSR | S_IRGRP | S_IROTH)
 
#define synchronize_all()
 
#define unsynchronize_all()
 

Typedefs

typedef struct backup backup_t
 
typedef struct instr instr_t
 

Functions

 module_param (the_hook, ulong,(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH))
 
 module_param (audit_counter, int,(S_IRUSR|S_IRGRP|S_IROTH))
 
static void synchronize_all_slaves (void *)
 
static int schedule_hook_init (void)
 
static void schedule_unpatch (void)
 
static int schedule_patch (void)
 
static void print_bytes (char *str, unsigned char *ptr, size_t s)
 
void schedule_hook (void)
 
void schedule_hook_2 (void)
 
 MODULE_LICENSE ("GPL")
 
 MODULE_AUTHOR ("Alessandro Pellegrini <pellegrini@dis.uniroma1.it>, Francesco Quaglia <quaglia@dis.uniroma1.it>")
 
 MODULE_DESCRIPTION ("Run time patch of the Linux kernel scheduler to support the execution of a generic custom function upon thread reschedule")
 
 module_init (schedule_hook_init)
 
 module_exit (schedule_unpatch)
 
void schedule_hook_end (void)
 
void schedule_hook_patch_point (void)
 
void schedule_hook_patch_point_2 (void)
 

Variables

unsigned long the_hook = 0
 
unsigned int audit_counter = 0
 
static atomic_t synch_leave
 
static atomic_t synch_enter
 
atomic_t count
 
atomic_t reference_count
 
ulong phase = 0
 
void * finish_task_switch = (void *)FTS_ADDR
 
void * finish_task_switch_next = (void *)FTS_ADDR_NEXT
 
backup_tb
 
unsigned short int backup_count = 0
 

Detailed Description

This is the main source for the Linux Kernel Module which implements a schedule-hook module allowing running a custom function each time a thread is cpu rescheduled.

Copyright (C) 2014-2017 HPDCS Group http://www.dis.uniroma1.it/~hpdcs

This is free software; You can redistribute it and/or modify this file under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this file; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Author
Francesco Quaglia
Alessandro Pellegrini
Emanuele De Santis
Date
October 15, 2015

Definition in file schedule.c.

Macro Definition Documentation

#define synchronize_all ( )
Value:
do { \
printk("cpu %d asking from unpreemptive synchronization\n", smp_processor_id()); \
atomic_set(&synch_enter, num_online_cpus() - 1); \
atomic_set(&synch_leave, 1); \
preempt_disable(); \
smp_call_function_many(cpu_online_mask, synchronize_all_slaves, NULL, false); /* false because we manually synchronize */ \
while(atomic_read(&synch_enter) > 0); \
printk("cpu %d all kernel threads synchronized\n", smp_processor_id()); \
} while(0)
#define atomic_read(v)
Read operation on an atomic counter.
Definition: atomic.h:66
#define atomic_set(v, i)
Set operation on an atomic counter.
Definition: atomic.h:69

Definition at line 149 of file schedule.c.

#define unsynchronize_all ( )
Value:
do { \
printk("cpu %d freeing other kernel threads\n", smp_processor_id()); \
atomic_set(&synch_leave, 0); \
preempt_enable(); \
} while(0)
#define atomic_set(v, i)
Set operation on an atomic counter.
Definition: atomic.h:69

Definition at line 159 of file schedule.c.