Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 496 → Rev 497

/shark/trunk/tracer/include/FTrace_OSD.h
0,0 → 1,40
#ifndef __FTRACE_OSD__
#define __FTRACE_OSD__
 
/* OS Dependent functions */
 
#include <FTrace_types.h>
 
#define FTRACE_OSD_CHUNK_HEAD 60
 
#define FTRACE_OSD_NEXT1 1
#define FTRACE_OSD_NEXT2 2
#define FTRACE_OSD_NEXT3 3
 
#define FTrace_printf cprintf
 
void FTrace_OSD_save_event(WORD type, WORD par1);
 
/* OSD Tracer Init */
int FTrace_OSD_init();
 
/* OSD Chunk Init */
int FTrace_OSD_chunk_init(FTrace_Chunk_Ptr c, int normal_size, int emergency_site, FTrace_flags flags);
 
/* OSD Chunk Link */
int FTrace_OSD_chunk_link(FTrace_Chunk_Ptr a, FTrace_Chunk_Ptr b, int osd_flags);
 
/* OSD Save Global Pointers */
int FTrace_OSD_save_pointers();
 
/* OSD Load Global Pointers */
int FTrace_OSD_load_pointers();
 
/* OSD Chunk compress function */
int FTrace_OSD_compress_chunk(int number, void *temp_data, int *data_size);
 
/* OSD Send Chunk out */
int FTrace_OSD_send_chunk(int number, int osd_flags);
 
#endif
 
/shark/trunk/tracer/include/FTrace_chunk.h
0,0 → 1,54
#ifndef __FTRACE_CHUNK__
#define __FTRACE_CHUNK__
 
/* FTrace chunk function header */
 
#include <FTrace_types.h>
 
/* Mutex for FTrace */
void FTrace_lock();
void FTrace_unlock();
 
void FTrace_fsave();
void FTrace_frestore();
 
/* Memory */
void *FTrace_malloc(int size);
void FTrace_free(void *ptr);
 
/* Enable/Disable Tracer */
int FTrace_enable();
int FTrace_disable();
 
/* Create n chunks of specified size (normal/emergency) */
int FTrace_chunk_create(int n, int normal_size, int emergency_size, FTrace_flags flags);
 
/* Delete a Chunk */
int FTrace_chunk_delete(int number);
 
/* Set the chunk flags */
int FTrace_set_chunk_flags(int number, FTrace_flags flags);
 
/* Get the chunk flags */
int FTrace_get_chunk_flags(int number, FTrace_flags *flags);
 
/* Select the actual chunk */
int FTrace_actual_chunk_select(int number);
 
/* Link two chunks */
int FTrace_chunk_link(int chunk_A, int chunk_B, int osd_flags);
 
/* Find the first chunk with specific flags*/
int FTrace_get_first_chunk(FTrace_flags flags);
 
/* Get one chunks status */
FTrace_Chunk_Ptr *FTrace_get_chunk_table();
 
/* Create a new memory region where the compressed data are stored */
int FTrace_compress_chunk(int number, FTrace_flags new_flags);
 
/* Send the chunk out from the memory */
int FTrace_send_chunk(int number, int osd_flags, FTrace_flags new_flags);
 
#endif
 
/shark/trunk/tracer/include/tracer.h
62,128 → 62,18
#include <ll/sys/types.h>
#include <ll/i386/hw-instr.h>
#include "FTrace.h"
#include "FTrace_chunk.h"
#include "FTrace_OSD.h"
 
#define TRACER_NO_OUTPUT 0
#define TRACER_UDP_OUTPUT 1
#define TRACER_NO_OUTPUT 0x00
#define TRACER_UDP_OUTPUT 0x01
 
#define TRACER_LOGEVENT fast_logevent
#define TRACER_LOGEVENT FTrace_safe_ipoint
#define FAST_TRACER_LOGEVENT FTrace_unsafe_ipoint
 
int tracer_initialize(int MemorySize);
void tracer_enable();
void tracer_disable();
void tracer_print_statistics();
void FTrace_unsafe_ipoint(BYTE type, BYTE flags, DWORD par1, DWORD par2);
void FTrace_safe_ipoint(BYTE type, BYTE flags, DWORD par1, DWORD par2);
 
int tracer_send_logged_events(int NumberOfEvents);
void tracer_flush_sent_events();
 
//UDP
 
int tracer_init_udp(int flag, char *local_ip, char *target_ip);
int tracer_create_udp_task(void *m, int EventsForPeriod);
 
#define TRACER_SERIALIZE
 
/* Save bytes => 1(type) + 4(tsc_high) + 4(tsc_low) + 1(size)
if (flag & 1) + 4(par1)
if (flag & 3) + 4(par2)
* Return 0 -> Success
* Return 1 -> Inactive
* Return 2 -> Error
*/
extern __inline__ int fast_logevent(BYTE type, BYTE flag, DWORD par1, DWORD par2)
{
 
extern void *StartTracerBuffer;
extern void *EndTracerBuffer;
extern void *LastBeforeEndTracerBuffer;
extern void *CurrentTracerBuffer;
extern void *FirstTracerBuffer;
 
extern int TracerActive;
extern unsigned long long TracerEventsRecorded;
extern unsigned int TracerEventsPresent;
 
SYS_FLAGS f;
 
DWORD tsc_low, tsc_high;
BYTE size = 10;
 
f = ll_fsave();
 
if (!TracerActive) {
ll_frestore(f);
return 1;
}
 
#ifdef TRACER_SERIALIZE
__asm__("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
"rdtsc\n\t"
:"=a" (tsc_low), "=d" (tsc_high)
:
:"ebx","ecx");
#else
__asm__("rdtsc\n\t"
:"=a" (tsc_low), "=d" (tsc_high)
::);
#endif
 
if (flag & 1) size += 4;
if (flag & 2) size += 4;
 
// Adjust FirstTracerBuffer
if (FirstTracerBuffer >= CurrentTracerBuffer && TracerEventsPresent != 0) {
while ((CurrentTracerBuffer + size - 1) >= FirstTracerBuffer &&
FirstTracerBuffer != StartTracerBuffer) {
FirstTracerBuffer += *(BYTE *)(FirstTracerBuffer + 9);
if (FirstTracerBuffer >= LastBeforeEndTracerBuffer) FirstTracerBuffer = StartTracerBuffer;
}
} else {
TracerEventsPresent++;
}
 
// Check if we overcome EndTracerBuffer
if ((CurrentTracerBuffer + size - 1) > EndTracerBuffer) {
//Cyclical Buffer implementation
LastBeforeEndTracerBuffer = CurrentTracerBuffer;
CurrentTracerBuffer = StartTracerBuffer;
//Set the First Event
while ((CurrentTracerBuffer + size - 1) >= FirstTracerBuffer) {
FirstTracerBuffer += *(BYTE *)(FirstTracerBuffer + 9);
if (FirstTracerBuffer >= LastBeforeEndTracerBuffer) FirstTracerBuffer = StartTracerBuffer;
}
}
 
// Add the new event
*(BYTE *)CurrentTracerBuffer = type;
CurrentTracerBuffer++;
*(DWORD *)(CurrentTracerBuffer) = tsc_high;
CurrentTracerBuffer+=4;
*(DWORD *)(CurrentTracerBuffer) = tsc_low;
CurrentTracerBuffer+=4;
*(BYTE *)(CurrentTracerBuffer) = size;
CurrentTracerBuffer++;
if (flag & 1) {
*(DWORD *)(CurrentTracerBuffer) = par1;
CurrentTracerBuffer+=4;
}
if (flag & 2) {
*(DWORD *)(CurrentTracerBuffer) = par2;
CurrentTracerBuffer+=4;
}
if (CurrentTracerBuffer > EndTracerBuffer) {
ll_frestore(f);
return 2;
}
 
TracerEventsRecorded++;
 
ll_frestore(f);
return 0;
 
}
 
#else
 
#include "FTrace.h"
/shark/trunk/tracer/include/FTrace_types.h
0,0 → 1,36
#ifndef __FTRACE_TYPES__
#define __FTRACE_TYPES__
 
/* FTrace types and structures */
 
#include <ll/sys/types.h>
#include <ll/i386/mem.h>
#include <ll/math.h>
 
#define FTRACE_CHUNK_ID 0xFFAAFFBB
 
#define MAX_CHUNK 256
 
#define FTRACE_CHUNK_FLAG_FREE 0x01 /* Chunk is free */
#define FTRACE_CHUNK_FLAG_FULL 0x02 /* Chunk is full */
#define FTRACE_CHUNK_FLAG_CYC 0x00 /* Mode: Cyclical */
#define FTRACE_CHUNK_FLAG_JTN 0x04 /* Mode: Jump To Next */
#define FTRACE_CHUNK_FLAG_STOP 0x08 /* MOde: Stop if full */
#define FTRACE_CHUNK_FLAG_BUSY 0x10 /* Chunk is busy */
#define FTRACE_CHUNK_FLAG_NODEL 0x20 /* Chunk is protected from delete */
#define FTRACE_CHUNK_FLAG_COMPR 0x40 /* Chunk is compressed */
 
typedef BYTE FTrace_flags;
 
struct FTrace_Chunk {
DWORD id;
DWORD number;
FTrace_flags flags;
DWORD size;
DWORD sizemask;
DWORD osd;
};
 
typedef struct FTrace_Chunk *FTrace_Chunk_Ptr;
 
#endif
/shark/trunk/tracer/newtrace/FTrace.c
0,0 → 1,559
#include <FTrace_chunk.h>
#include <FTrace_types.h>
#include <FTrace_OSD.h>
 
#define FTRACE_DEBUG
 
/* Globals */
 
FTrace_Chunk_Ptr ChunkTable[MAX_CHUNK]; /* Chunk array */
FTrace_Chunk_Ptr ActualChunk = NULL; /* Actual Chunk */
 
/* Global Pointers */
BYTE OSD_pointers[FTRACE_OSD_CHUNK_HEAD];
 
int FTraceInit = 0;
int FTraceEnable = 0;
 
/* Init a chunk with default value */
static int FTrace_chunk_init(FTrace_Chunk_Ptr c, int number, int size, FTrace_flags flags)
{
 
c->id = FTRACE_CHUNK_ID; /* Std ID */
c->number = number; /* Chunk number */
c->flags = flags; /* Chunk flags */
c->size = size; /* Chunk real size */
c->sizemask = size - 1; /* Chunk data size mask */
c->osd = (DWORD)((DWORD)(c) + sizeof(struct FTrace_Chunk));
return FTrace_OSD_chunk_init(c, size, flags);
 
}
 
/* Find a free slot in ChunkTable */
static int FTrace_find_free_slot()
{
 
int i;
 
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
return -1;
}
 
for (i = 0;i < MAX_CHUNK;i++)
if (ChunkTable[i] == NULL)
return i;
 
return -1;
}
 
/* Init the FTrace */
static int FTrace_Init()
{
 
int i,err;
 
/* Check if it's just initialized */
if (FTraceInit == 1)
return 0;
 
FTrace_lock();
 
memset(OSD_pointers,0,sizeof(OSD_pointers));
 
for (i = 0;i < MAX_CHUNK;i++)
ChunkTable[i] = NULL;
 
/* Init System Dependet Part */
err = FTrace_OSD_init();
if (err != 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace OSD not initialized\n");
#endif
FTrace_unlock();
return -1;
}
 
FTraceInit = 1;
 
FTrace_unlock();
 
return 0;
 
}
 
/* Enable Tracer */
int FTrace_enable()
{
 
if (FTraceInit == 0 || ActualChunk == NULL) return -1;
 
FTrace_fsave();
FTraceEnable = 1;
FTrace_frestore();
 
return 0;
 
}
 
/* Disable Tracer */
int FTrace_disable()
{
if (FTraceInit == 0) return -1;
FTrace_fsave();
FTraceEnable = 0;
FTrace_frestore();
return 0;
}
 
/* Create n chunks of specified size, where size = 2^bits */
int FTrace_chunk_create(int n, int bits, FTrace_flags flags)
{
 
FTrace_Chunk_Ptr FT_temp;
int i, number, err, size;
 
FTrace_lock();
 
if (FTraceInit == 0) {
err = FTrace_Init();
if (err != 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Initialization fail\n");
#endif
FTrace_unlock();
return -1;
}
}
 
/* Get size */
size = 1 << bits;
 
for (i = 0;i < n;i++) {
 
number = FTrace_find_free_slot();
if (number == -1) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: cannot find free slot for chunk\n");
#endif
FTrace_unlock();
return -1;
}
 
FT_temp = (FTrace_Chunk_Ptr)FTrace_malloc(sizeof(struct FTrace_Chunk) + FTRACE_OSD_CHUNK_HEAD + size);
if (FT_temp == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: cannot allocate memory for chunk\n");
#endif
FTrace_unlock();
return -1;
}
 
err = FTrace_chunk_init(FT_temp, number, size, flags);
if (err != 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: cannot initialized the new chunk\n");
#endif
FTrace_unlock();
return -1;
}
 
/* Set the ChunkTable */
ChunkTable[number] = FT_temp;
 
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Debug: Chunk %d created at addr %x\n",number,(int)FT_temp);
#endif
 
}
 
FTrace_unlock();
return 0;
 
}
 
/* Delete a Chunk */
int FTrace_chunk_delete(int number)
{
 
FTrace_Chunk_Ptr FT_temp = ChunkTable[number];
 
FTrace_lock();
 
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
FTrace_unlock();
return -1;
}
 
if (FT_temp == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk not present\n");
#endif
FTrace_unlock();
return -1;
}
 
if (FT_temp->flags & FTRACE_CHUNK_FLAG_NODEL) {
FTrace_unlock();
return 0;
}
 
FTrace_free(FT_temp);
ChunkTable[number] = NULL;
 
FTrace_unlock();
return 0;
 
}
 
/* Set the chunk flags */
int FTrace_set_chunk_flags(int number, FTrace_flags flags)
{
FTrace_Chunk_Ptr FT_temp = ChunkTable[number];
FTrace_lock();
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
FTrace_unlock();
return -1;
}
if (FT_temp == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk not present\n");
#endif
FTrace_unlock();
return -1;
}
 
FT_temp->flags = flags;
 
return 0;
 
}
 
/* Get the chunk flags */
int FTrace_get_chunk_flags(int number, FTrace_flags *flags)
{
FTrace_Chunk_Ptr FT_temp = ChunkTable[number];
FTrace_lock();
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
FTrace_unlock();
return -1;
}
if (FT_temp == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk not present\n");
#endif
FTrace_unlock();
return -1;
}
*flags = FT_temp->flags;
return 0;
}
 
/* Select the actual chunk */
int FTrace_actual_chunk_select(int number)
{
 
FTrace_Chunk_Ptr FT_temp = ChunkTable[number];
FTrace_lock();
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
FTrace_unlock();
return -1;
}
if (FT_temp == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk not present\n");
#endif
FTrace_unlock();
return -1;
}
 
if (FT_temp->flags & FTRACE_CHUNK_FLAG_FREE) {
 
/* Set as used */
FT_temp->flags &= ~FTRACE_CHUNK_FLAG_FREE;
 
/* Update the actual_chunk and OSD_pointers */
FTrace_fsave();
FTrace_OSD_save_pointers();
ActualChunk = FT_temp;
FTrace_OSD_load_pointers();
FTrace_frestore();
 
} else {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk is not free\n");
#endif
FTrace_unlock();
return -1;
}
FTrace_unlock();
 
return 0;
 
}
 
/* Find the first chunk with specific flags*/
int FTrace_get_first_chunk(FTrace_flags flags) {
 
int i;
 
FTrace_lock();
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
FTrace_unlock();
return -1;
}
for (i = 0;i < MAX_CHUNK;i++) {
 
if (ChunkTable[i]->flags & flags) {
FTrace_unlock();
return i;
}
 
}
 
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Free chunk not found\n");
#endif
FTrace_unlock();
 
return -1;
 
}
 
/* Get chunk table */
FTrace_Chunk_Ptr *FTrace_get_chunk_table()
{
return ChunkTable;
}
 
/* Link two chunks */
int FTrace_chunk_link(int chunk_A, int chunk_B, int osd_flags)
{
 
FTrace_Chunk_Ptr ckA = ChunkTable[chunk_A];
FTrace_Chunk_Ptr ckB = ChunkTable[chunk_B];
 
int err;
FTrace_lock();
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
FTrace_unlock();
return -1;
}
if (ckA == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk A not present\n");
#endif
FTrace_unlock();
return -1;
}
 
if (ckB == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk B not present\n");
#endif
FTrace_unlock();
return -1;
}
 
if (!(ckB->flags & FTRACE_CHUNK_FLAG_FREE)) {
ckB->flags &= ~FTRACE_CHUNK_FLAG_FREE;
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk B is not free\n");
#endif
FTrace_unlock();
return -1;
}
 
/* FTrace Low Level Blocking Part */
FTrace_fsave();
FTrace_OSD_save_pointers();
 
err = FTrace_OSD_chunk_link(ckA,ckB,osd_flags);
if (err != 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Cannot link the chunks\n");
#endif
return -1;
}
 
FTrace_OSD_load_pointers();
FTrace_frestore();
 
FTrace_unlock();
 
return 0;
 
}
 
/* Create a new memory region where the compressed data are stored */
int FTrace_compress_chunk(int number, FTrace_flags new_flags)
{
void *temp_data;
FTrace_Chunk_Ptr FT_temp = ChunkTable[number];
int err, data_size;
FTrace_Chunk_Ptr New_chunk;
 
FTrace_lock();
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
FTrace_unlock();
return -1;
}
 
if (FT_temp == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk not present\n");
#endif
FTrace_unlock();
return -1;
}
 
FT_temp->flags |= FTRACE_CHUNK_FLAG_BUSY;
 
FTrace_unlock();
 
/* Alloc temp memory for */
temp_data = (void *)FTrace_malloc(FT_temp->sizemask+1);
if (temp_data == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Cannot allocate memory\n");
#endif
return -1;
}
 
/* Compress the chunk. Temp_data are a temporary region where
store the compressed chunk. Data_size is the size of compressed
data */
err = FTrace_OSD_compress_chunk(number,temp_data,&data_size);
if (err != 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: OSD Compressing function failed\n");
#endif
return -1;
}
 
New_chunk = (FTrace_Chunk_Ptr)FTrace_malloc(sizeof(struct FTrace_Chunk) + FTRACE_OSD_CHUNK_HEAD + data_size);
if (New_chunk == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Cannot allocate memory\n");
#endif
return -1;
}
 
memcpy(New_chunk,temp_data,data_size);
 
FTrace_free(temp_data);
 
FTrace_lock();
 
/* Free the memory of the old chunk */
FTrace_free(FT_temp);
 
/* Set the new chunk flags and update the main table */
New_chunk->flags = new_flags;
New_chunk->flags |= FTRACE_CHUNK_FLAG_COMPR;
ChunkTable[number] = New_chunk;
FTrace_unlock();
 
return 0;
 
}
 
/* Send the chunk out from the memory */
int FTrace_send_chunk(int number, int osd_flags, FTrace_flags new_flags)
{
FTrace_Chunk_Ptr FT_temp = ChunkTable[number];
int err;
FTrace_lock();
if (FTraceInit == 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: FTrace not initialized\n");
#endif
FTrace_unlock();
return -1;
}
if (FT_temp == NULL) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Chunk not present\n");
#endif
FTrace_unlock();
return -1;
}
 
FT_temp->flags |= FTRACE_CHUNK_FLAG_BUSY;
 
FTrace_unlock();
 
err = FTrace_OSD_send_chunk(number, osd_flags);
if (err != 0) {
#ifdef FTRACE_DEBUG
FTrace_printf("FTrace Error: Cannot send the chunk\n");
#endif
return -1;
}
 
FTrace_lock();
/* Set the new chunk flags */
FT_temp->flags = new_flags;
FTrace_unlock();
return 0;
 
}
/shark/trunk/tracer/makefile
16,7 → 16,7
# Object files
 
ifeq ($(findstring NEW,$(TRACER)) , NEW)
OBJS = newtrace/tracer.o newtrace/udp.o
OBJS = newtrace/FTrace.o newtrace/FTrace_OSD.c newtrace/FTrace_OSD_ll.o
CFG_OPT += -D__NEW_TRACER__
endif
ifeq ($(findstring OLD,$(TRACER)) , OLD)