Update of /cvsroot/oprofile/oprofile/libop In directory usw-pr-cvs1:/tmp/cvs-serv18755/libop Modified Files: Makefile.in op_events.c op_events.h op_events_desc.c op_events_desc.h op_interface.h Added Files: op_cpu_type.c op_cpu_type.h Log Message: a little refactor --- NEW FILE: op_cpu_type.c --- /** * @file op_cpu_type.c * CPU type determination * * @remark Copyright 2002 OProfile authors * @remark Read the file COPYING * * @author John Levon <mo...@co...> * @author Philippe Elie <ph...@wa...> */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "op_cpu_type.h" /** * op_get_cpu_type - get from /proc/sys/dev/oprofile/cpu_type the cpu type * * returns %CPU_NO_GOOD if the CPU could not be identified */ op_cpu op_get_cpu_type(void) { int cpu_type = CPU_NO_GOOD; char str[10]; FILE * fp; fp = fopen("/proc/sys/dev/oprofile/cpu_type", "r"); if (!fp) { fprintf(stderr, "Unable to open /proc/sys/dev/oprofile/cpu_type for reading\n"); return cpu_type; } fgets(str, 9, fp); sscanf(str, "%d\n", &cpu_type); fclose(fp); return cpu_type; } static char const * cpu_names[MAX_CPU_TYPE] = { "Pentium Pro", "PII", "PIII", "Athlon", "CPU with RTC device" }; /** * op_get_cpu_type_str - get the cpu string. * @param cpu_type the cpu type identifier * * The function always return a valid char const * * the core cpu denomination or "invalid cpu type" if * @cpu_type is not valid. */ char const * op_get_cpu_type_str(op_cpu cpu_type) { if (cpu_type < 0 || cpu_type >= MAX_CPU_TYPE) { return "invalid cpu type"; } return cpu_names[cpu_type]; } --- NEW FILE: op_cpu_type.h --- /** * @file op_cpu_type.h * CPU type determination * * @remark Copyright 2002 OProfile authors * @remark Read the file COPYING * * @author John Levon <mo...@co...> * @author Philippe Elie <ph...@wa...> */ #ifndef OP_CPU_TYPE_H #define OP_CPU_TYPE_H #ifdef __cplusplus extern "C" { #endif /** supported cpu type */ typedef enum { CPU_NO_GOOD = -1, /**< unsupported CPU type */ CPU_PPRO, /**< Pentium Pro */ CPU_PII, /**< Pentium II series */ CPU_PIII, /**< Pentium III series */ CPU_ATHLON, /**< AMD P6 series */ CPU_RTC, /**< other CPU to use the RTC */ MAX_CPU_TYPE } op_cpu; /** * get from /proc/sys/dev/oprofile/cpu_type the cpu type * * returns CPU_NO_GOOD if the CPU could not be identified. * This function can not work if the module is not loaded */ op_cpu op_get_cpu_type(void); /** * get the cpu string. * @param cpu_type the cpu type identifier * * The function always return a valid char const * the core cpu denomination * or "invalid cpu type" if cpu_type is not valid. */ char const * op_get_cpu_type_str(op_cpu cpu_type); #ifdef __cplusplus } #endif #endif /* OP_CPU_TYPE_H */ Index: Makefile.in =================================================================== RCS file: /cvsroot/oprofile/oprofile/libop/Makefile.in,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile.in 6 May 2002 18:00:32 -0000 1.1 +++ Makefile.in 15 Jun 2002 18:52:07 -0000 1.2 @@ -1,10 +1,10 @@ include ../make.common -HEADERS=op_config.h op_hw_config.h op_interface.h op_events.h op_events_desc.h op_mangle.h op_sample_file.h +HEADERS=op_config.h op_hw_config.h op_interface.h op_events.h op_events_desc.h op_cpu_type.h op_mangle.h op_sample_file.h -SOURCES=op_events.c op_events_desc.c op_mangle.c +SOURCES=op_events.c op_events_desc.c op_cpu_type.c op_mangle.c -OBJECTS=op_events.o op_events_desc.o op_mangle.o +OBJECTS=op_events.o op_events_desc.o op_cpu_type.o op_mangle.o TARGET=libop.a Index: op_events.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/libop/op_events.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- op_events.c 14 Jun 2002 03:54:38 -0000 1.6 +++ op_events.c 15 Jun 2002 18:52:07 -0000 1.7 @@ -194,7 +194,7 @@ * * The function returns: * -1 if the value is not allowed, - * 0 if the value is allowed and represent multiple units, + * 0 if the value is allowed and represents multiple units, * > 0 otherwise, in this case allow->um[return value - 1] == um so the * caller can access to the description of the unit_mask. */ @@ -282,7 +282,7 @@ */ int op_check_events(int ctr, u8 ctr_type, u8 ctr_um, op_cpu cpu_type) { - int ret = 0x0; + int ret = OP_OK_EVENT; u32 i = 0; u32 cpu_mask = 1 << cpu_type; u32 ctr_mask = 1 << ctr; @@ -291,18 +291,18 @@ for ( ; i < op_nr_events; i++) { if (op_events[i].val == ctr_type && (op_events[i].cpu_mask & cpu_mask)) { if ((op_events[i].counter_mask & ctr_mask) == 0) - ret |= OP_EVT_CTR_NOT_ALLOWED; + ret |= OP_INVALID_COUNTER; if (op_events[i].unit && op_check_unit_mask(&op_unit_masks[op_events[i].unit], ctr_um) < 0) - ret |= OP_EVT_NO_UM; + ret |= OP_INVALID_UM; break; } } } if (i == op_nr_events) - ret |= OP_EVT_NOT_FOUND; + ret |= OP_INVALID_EVENT; return ret; } Index: op_events.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libop/op_events.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- op_events.h 6 Jun 2002 16:18:14 -0000 1.5 +++ op_events.h 15 Jun 2002 18:52:07 -0000 1.6 @@ -16,7 +16,16 @@ extern "C" { #endif -#include "op_interface.h" +#include "op_types.h" +#include "op_cpu_type.h" + +/** op_check_events() return code */ +enum op_event_check { + OP_OK_EVENT = 0, /**< event is valid and allowed */ + OP_INVALID_EVENT = 1, /**< event number is invalid */ + OP_INVALID_UM = 2, /**< unit mask is invalid */ + OP_INVALID_COUNTER = 4, /**< event is not allowed for the given counter */ +}; /** Describe an event. */ struct op_event { @@ -46,7 +55,6 @@ u8 um[7]; /**< up to seven allowed unit masks */ }; -/* op_events.c */ /** * @param ctr_type event value * @param cpu_type cpu type Index: op_events_desc.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/libop/op_events_desc.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- op_events_desc.c 6 Jun 2002 16:18:14 -0000 1.8 +++ op_events_desc.c 15 Jun 2002 18:52:07 -0000 1.9 @@ -20,58 +20,6 @@ #include "op_events.h" #include "op_events_desc.h" -/** - * op_get_cpu_type - get from /proc/sys/dev/oprofile/cpu_type the cpu type - * - * returns %CPU_NO_GOOD if the CPU could not be identified - */ -op_cpu op_get_cpu_type(void) -{ - int cpu_type = CPU_NO_GOOD; - char str[10]; - - FILE * fp; - - fp = fopen("/proc/sys/dev/oprofile/cpu_type", "r"); - if (!fp) { - fprintf(stderr, "Unable to open /proc/sys/dev/oprofile/cpu_type for reading\n"); - return cpu_type; - } - - fgets(str, 9, fp); - - sscanf(str, "%d\n", &cpu_type); - - fclose(fp); - - return cpu_type; -} - -static char const * cpu_names[MAX_CPU_TYPE] = { - "Pentium Pro", - "PII", - "PIII", - "Athlon", - "CPU with RTC device" -}; - -/** - * op_get_cpu_type_str - get the cpu string. - * @param cpu_type the cpu type identifier - * - * The function always return a valid char const * - * the core cpu denomination or "invalid cpu type" if - * @cpu_type is not valid. - */ -char const * op_get_cpu_type_str(op_cpu cpu_type) -{ - if (cpu_type < 0 || cpu_type >= MAX_CPU_TYPE) { - return "invalid cpu type"; - } - - return cpu_names[cpu_type]; -} - struct op_unit_desc op_unit_descs[] = { { { NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, }, { { "(M)odified cache state", Index: op_events_desc.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libop/op_events_desc.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- op_events_desc.h 6 Jun 2002 16:18:15 -0000 1.7 +++ op_events_desc.h 15 Jun 2002 18:52:07 -0000 1.8 @@ -16,8 +16,8 @@ extern "C" { #endif -#include "op_interface.h" - +#include "op_cpu_type.h" + /** Human readable description for an unit mask. */ struct op_unit_desc { char * desc[7]; @@ -55,23 +55,6 @@ /** the total number of events for all processor type, allowing to iterate * on the op_events[] decription */ extern u32 op_nr_events; - -/** - * get from /proc/sys/dev/oprofile/cpu_type the cpu type - * - * returns CPU_NO_GOOD if the CPU could not be identified. - * This function can not work if the module is not loaded - */ -op_cpu op_get_cpu_type(void); - -/** - * get the cpu string. - * @param cpu_type the cpu type identifier - * - * The function always return a valid char const * the core cpu denomination - * or "invalid cpu type" if cpu_type is not valid. - */ -char const * op_get_cpu_type_str(op_cpu cpu_type); #ifdef __cplusplus } Index: op_interface.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/libop/op_interface.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- op_interface.h 6 Jun 2002 16:18:15 -0000 1.3 +++ op_interface.h 15 Jun 2002 18:52:07 -0000 1.4 @@ -16,27 +16,6 @@ #include "op_config.h" #include "op_types.h" -/*@{\name op_check_events() return code */ -#define OP_EVENTS_OK 0x0 -/** The event number is invalid */ -#define OP_EVT_NOT_FOUND 0x1 -/** The event have no unit mask */ -#define OP_EVT_NO_UM 0x2 -/** The event is not available for the selected counter */ -#define OP_EVT_CTR_NOT_ALLOWED 0x4 -/*@}*/ - -/** supported cpu type */ -typedef enum { - CPU_NO_GOOD = -1, - CPU_PPRO, - CPU_PII, - CPU_PIII, - CPU_ATHLON, - CPU_RTC, - MAX_CPU_TYPE -} op_cpu; - /*@{\name notifications types encoded in op_note::type */ /** fork(),vfork(),clone() */ #define OP_FORK 1 @@ -58,21 +37,25 @@ u32 eip; /**< eip value where occur interrupt */ } __attribute__((__packed__, __aligned__(8))); -/** Data type used by the module to notify daemon of fork/exit/mapping etc. +/** + * Data type used by the module to notify daemon of fork/exit/mapping etc. * Meanings of fields depend on the type of notification encoded in the type * field. - * \sa OP_FORK, OP_EXEC, OP_MAP, OP_DROP_MODULES and OP_EXIT */ + * \sa OP_FORK, OP_EXEC, OP_MAP, OP_DROP_MODULES and OP_EXIT + */ struct op_note { u32 addr; u32 len; u32 offset; u32 hash; u16 pid; - u16 type; /* FIXME how to put a see also to the group OP_FORK etc.*/ + u16 type; }; -/** A path component. Directory name are stored as a stack of path component. - * Note than the name index acts also as an unique identifier */ +/** + * A path component. Directory name are stored as a stack of path components. + * Note than the name index acts also as an unique identifier + */ struct op_hash_index { /** index inside the string pool */ u32 name; |