From: Philippe E. <ph...@us...> - 2001-09-08 21:46:06
|
Update of /cvsroot/oprofile/oprofile In directory usw-pr-cvs1:/tmp/cvs-serv13225/oprofile Modified Files: ChangeLog op_events.c op_init.c op_user.h oprofile.c Log Message: centralize cpu type detection Index: ChangeLog =================================================================== RCS file: /cvsroot/oprofile/oprofile/ChangeLog,v retrieving revision 1.103 retrieving revision 1.104 diff -u -d -r1.103 -r1.104 --- ChangeLog 2001/09/06 20:41:48 1.103 +++ ChangeLog 2001/09/08 21:46:03 1.104 @@ -1,3 +1,18 @@ +2001-09-07 Philippe Elie <ph...@cl...> + + * oprofile.c: remove /proc/.../cpu_type. Check if user + mode cpu type detection is identical to module cpu type + * op_events.h: + * op_events.c: add op_get_cpu_type(). script can get cpu_type + by op_help --get-cpu-type + * gui/oprofile: use it + * dae/oprofiled.c: ditto + * dae/op_start: ditto, pass expected_cpu_type to module + * doc/oprofile.sgml: update + * doc/oprofile.1.in: update + * pp/oprofpp.c: get cpu_type from samples file + * pp/opf_filter.cpp: get cpu type from stdin + 2001-09-06 John Levon <mo...@co...> * dae/opd_proc.c: use j not i in msync ! Index: op_events.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/op_events.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- op_events.c 2001/09/06 18:13:28 1.22 +++ op_events.c 2001/09/08 21:46:03 1.23 @@ -429,6 +429,81 @@ return cpu_type_str[cpu_type]; } + +/* module have its own stuff to detect cpu type */ +#ifndef MODULE + +struct op_cpu_type { + const char *cpu_name; + int cpu_type; +}; + +/* string must be in the correct order to not hide a forward string eg. + * order "Pentium II" "Pentium III" is bad because the first hide the second */ +static struct op_cpu_type op_cpu_types[] = { + { "PentiumPro", CPU_PPRO }, + { "Pentium III",CPU_PIII }, + { "Pentium II", CPU_PII }, + { "Pentium III",CPU_PIII }, + { "Athlon", CPU_ATHLON }, + { "Duron", CPU_ATHLON }, + { "K7", CPU_ATHLON }, + { "Celeron", CPU_PII }, + { "Coppermine", CPU_PIII }, +}; + +#define OP_CPU_TYPES_NR (sizeof(op_cpu_types) / sizeof(op_cpu_types[0])) + +/** + * op_get_cpu_type - get from /proc/cpuinfo the cpu type + * + * return DEFAULT_CPU_TYPE if the cpu type is un-recognizable + * FIXME: return -1 + */ +int op_get_cpu_type(void) +{ + int cpu_type; + char line[256]; + char *model_name; + FILE* fp; + uint i; + int found = 0; + + cpu_type = DEFAULT_CPU_TYPE; + + fp = fopen("/proc/cpuinfo", "r"); + if (!fp) { + fprintf(stderr, "Unable to open /proc/cpuinfo for reading\n"); + + return cpu_type; + } + + while (fgets(line, sizeof(line) - 1, fp)) { + if (strncmp(line, "model name\t: ", strlen("model name\t: ")) == 0) { + model_name = line + strlen("model name\t: "); + + for (i = 0; i < OP_CPU_TYPES_NR; i++) { + if (strncmp(model_name, op_cpu_types[i].cpu_name, strlen(op_cpu_types[i].cpu_name)) == 0) { + cpu_type = op_cpu_types[i].cpu_type; + + found = 1; + } + } + } + } + + if (!found) { + /* FIXME: use oprofile mail list adress here ? */ + fprintf(stderr, "Unknown CPU type. Please send /proc/cpuinfo to mo...@co...\n"); + } + + return cpu_type; +} + +#undef OP_CPU_TYPES_NR + +#endif + #ifdef OP_EVENTS_DESC struct op_unit_desc { char *desc[7]; @@ -795,6 +870,8 @@ int cpu_type_mask; int for_gui; + cpu_type = op_get_cpu_type(); + for_gui = 0; for (i = 1 ; i < argc ; ++i) { if (!strcmp(argv[i], "--version")) { @@ -810,7 +887,11 @@ fprintf(stderr, "invalid cpu type %d, default to to %s\n", cpu_type, cpu_type_str[DEFAULT_CPU_TYPE]); cpu_type = DEFAULT_CPU_TYPE; } - } else if (!strcmp(argv[1], "--gui-description")) { + } else if (!strncmp(argv[i], "--get-cpu-type", 11)) { + printf("%d\n", cpu_type); + + exit(EXIT_SUCCESS); + } else if (!strcmp(argv[1], "--gui-description")) { for_gui = 1; } else { cpu_type_mask = 1 << cpu_type; Index: op_init.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/op_init.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- op_init.c 2001/09/06 18:13:28 1.7 +++ op_init.c 2001/09/08 21:46:03 1.8 @@ -19,6 +19,10 @@ EXPORT_NO_SYMBOLS; +MODULE_PARM(expected_cpu_type, "i"); +MODULE_PARM_DESC(expected_cpu_type, "Allow checking of detected hardware from the user space"); +static int expected_cpu_type = -1; + extern int cpu_type; extern uint op_nr_counters; extern int separate_running_bit; @@ -46,6 +50,21 @@ if (cpu_type == CPU_ATHLON) { op_nr_counters = 4; separate_running_bit = 1; + } + + if (expected_cpu_type != -1 && expected_cpu_type != cpu_type) { + + printk("oprofile: user space/module cpu detection mismatch\n"); + + /* FIXME: oprofile list */ + printk("please send the next line and your /proc/cpuinfo to mo...@co...\n"); + + printk("vendor %d step %d model %d, expected_cpu_type %d, cpu_type %d\n", + current_cpu_data.x86_vendor, current_cpu_data.x86, + current_cpu_data.x86_model, expected_cpu_type, + cpu_type); + + return CPU_NO_GOOD; } return cpu_type; } Index: op_user.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/op_user.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- op_user.h 2001/09/06 18:13:28 1.5 +++ op_user.h 2001/09/08 21:46:03 1.6 @@ -169,5 +169,6 @@ /* not used currently */ int op_check_events_str(int ctr, char *ctr_type, u8 ctr_um, int cpu_type, u8 *ctr_t); void op_get_event_desc(int cpu_type, u8 type, u8 um, char **typenamep, char **typedescp, char **umdescp); +int op_get_cpu_type(void); #endif /* OP_USER_H */ Index: oprofile.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/oprofile.c,v retrieving revision 1.82 retrieving revision 1.83 diff -u -d -r1.82 -r1.83 --- oprofile.c 2001/09/06 18:13:28 1.82 +++ oprofile.c 2001/09/08 21:46:03 1.83 @@ -1153,7 +1153,7 @@ return err; } -static int nr_oprof_static = 7; +static int nr_oprof_static = 6; static ctl_table oprof_table[] = { { 1, "bufsize", &op_buf_size, sizeof(int), 0600, NULL, &lproc_dointvec, NULL, }, @@ -1162,7 +1162,6 @@ { 1, "kernel_only", &kernel_only, sizeof(int), 0600, NULL, &lproc_dointvec, NULL, }, { 1, "pid_filter", &pid_filter, sizeof(pid_t), 0600, NULL, &lproc_dointvec, NULL, }, { 1, "pgrp_filter", &pgrp_filter, sizeof(pid_t), 0600, NULL, &lproc_dointvec, NULL, }, - { 1, "cpu_type", &cpu_type, sizeof(int), 0400, NULL, &lproc_dointvec, NULL, }, { 0, }, { 0, }, { 0, }, { 0, }, { 0, }, }; |