From: John L. <mov...@us...> - 2001-09-06 18:13:31
|
Update of /cvsroot/oprofile/oprofile/dae In directory usw-pr-cvs1:/tmp/cvs-serv22397/dae Modified Files: op_start opd_proc.c oprofiled.c Log Message: philippe's cleanup, and several fixes from me. Index: op_start =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/op_start,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- op_start 2001/09/04 17:30:12 1.38 +++ op_start 2001/09/06 18:13:28 1.39 @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # $Id$ # COPYRIGHT (C) 2000 THE VICTORIA UNIVERSITY OF MANCHESTER and John Levon # This program is free software; you can redistribute it and/or modify it @@ -32,18 +32,6 @@ PGRP_FILTER=0 VERBOSE=0 -# PHE FIXME: too many changes needs a redesign. Proposition: -# 1) check for a cpu_type switch, -# 2) stop the daemon -# 3) modprobe oprofile [cpu_type=xx] -# 4) if --cpu-type not given get it from /proc/sys/dev/oprofile/cpu_type -# 5) default init -# 6) parse parameter -# 7) launch the daemon -# this avoid passing cpu_type in the common case and allow in case or module -# misdetect the used core to overwrite it through an init parameters to the -# module - if test -f /proc/cpuinfo; then modelname=`cat /proc/cpuinfo | grep "model\ name\ :" | sed -e 's/ //g' | cut -d':' -f2` case $modelname in @@ -110,7 +98,6 @@ --pgrp-filter=pgrp Only profile process group pgrp Daemon options - --use-cpu=[0|1|2|3] 0: PPro, 1: PII, 2: PIII, 3: AMD Athlon. --ignore-myself=[0|1] ignore samples for oprofiled --log-file=file log file --base-dir=dir base directory of daemon @@ -152,12 +139,15 @@ echo $val > /proc/sys/$dev_name } -# PHE FIXME: assume ctr < 9, how from an awk expr extract the int field? -# probably needs to use bash string manipulation. -# extract the field N from --ctrN-xxxxxx +# extract the integer field N from --ctr[N]-xxxxxxx extract_int() { - echo $1 | awk '{print substr($0, 6, 1)}' + local val=`echo $1 | sed 's,--ctr\([0-9]*\)[-A-Za-z]*,\1,'` + + if (($val >= $OP_MAX_COUNTERS || $val < 0)); then + echo "invalid argument $1: bad counter number" + fi + echo $val } LOG_FILE= @@ -171,15 +161,6 @@ arg=`echo $1 | awk -F= '{print $1}'` val=`echo $1 | awk -F= '{print $2}'` case "$arg" in - # PHE FIXME: this work actually but if the forced cpu type have - # more counter than OP_MAX_COUNTERS only OP_NR_MAX_COUNTERS - # can be used. if less the script do not work and you can - # get many trouble. - --use-cpu) - if [ "$val" != "" ]; then - CPUTYPE=$val - fi - ;; --ignore-myself) if [ "$val" != "" ]; then IGNORE_MYSELF=$val @@ -200,21 +181,20 @@ KERNEL_ONLY=1 fi ;; - # PHE FIXME: see comment at extract_int --ctr*-unit-mask) - CTR_UM[`extract_int $1`]=$val + CTR_UM[`extract_int $arg`]=$val ;; --ctr*-event) - CTR_EVENT[`extract_int $1`]=$val + CTR_EVENT[`extract_int $arg`]=$val ;; --ctr*-count) - CTR_COUNT[`extract_int $1`]=$val + CTR_COUNT[`extract_int $arg`]=$val ;; --ctr*-user) - CTR_USER[`extract_int $1`]=$val + CTR_USER[`extract_int $arg`]=$val ;; --ctr*-kernel) - CTR_KERNEL[`extract_int $1`]=$val + CTR_KERNEL[`extract_int $arg`]=$val ;; --base-dir) DIR=$val @@ -449,7 +429,7 @@ f=$(($f+1)) done -OPD_ARGS="--buffer-size=$BUF_SIZE --use-cpu=$CPUTYPE --ignore-myself=$IGNORE_MYSELF \ +OPD_ARGS="--buffer-size=$BUF_SIZE --ignore-myself=$IGNORE_MYSELF \ --log-file=$LOG_FILE --base-dir=$DIR --samples-dir=$SAMPLES_DIR \ --device-file=$DEVICE_FILE --kernel-only=$KERNEL_ONLY \ --hash-map-device-file=$HASH_MAP_DEVICE_FILE --vmlinux=$VMLINUX" Index: opd_proc.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/opd_proc.c,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- opd_proc.c 2001/09/04 12:50:10 1.67 +++ opd_proc.c 2001/09/06 18:13:28 1.68 @@ -25,6 +25,7 @@ extern int kernel_only; extern int verbose; +extern uint op_nr_counters; extern unsigned long opd_stats[]; extern char *vmlinux; extern char *smpdir; @@ -74,7 +75,7 @@ struct opd_proc *proc; struct opd_proc *next; uint i; - int j; + uint j; for (i = 0; i < nr_images; i++) { struct opd_image* image = &opd_images[i]; @@ -265,7 +266,7 @@ */ static void opd_handle_old_sample_files(const char *image_name, time_t mtime) { - int i; + uint i; char *mangled; mangled = opd_mangle_filename(smpdir, image_name); @@ -295,9 +296,8 @@ */ static void opd_open_image(struct opd_image *image, const char *name, int kernel) { - int i; + uint i; - /* PHE FIXME : store the mangled name ? */ image->name = opd_strdup(name); image->kernel = kernel; image->len = 0; @@ -386,35 +386,14 @@ fprintf(stderr,"oprofiled: open of image sample file \"%s\" failed: %s\n", mangled, strerror(errno)); goto err1; } - - /* PHE FIXME: keep it, I need opinion on the two manner to do the job - * I am unsure if there is no a thrid way to make this */ -#if 0 - /* ugly: mmap needs than fd size is sufficient, bugs in this area - * is difficult to understand, mmap sucess but the returned pointer - * cause a segfault, then the daemon is killed without coredump nor - * message error. PHE FIXME: why this mmap behavior, and why daemon die - * silently ? */ - if (lseek(sample_file->fd, image->len + sizeof(struct opd_footer) - 1, SEEK_SET) == -1) { - fprintf(stderr, "oprofiled: seek failed for \"%s\". %s\n", mangled, strerror(errno)); - goto err2; - } - /* PHE FIXME: this unsparse the file by one memory page size at the - * end of file :( An another way to grow the file ?, 0 write size do - * not work. try a write from the zero page? */ - if (write(sample_file->fd, "", 1) != 1) { - perror("oprofiled: cannot grow sample file. "); - goto err2; - } -#else - /* PHE FIXME: perhaps this is equivalent to the code above other #if - * alternative */ + /* truncate to grow the file is ok on linux, and probably ok in POSIX. + * I am unsure than don't touch the last page and un-sparse a little + * what the samples file */ if (ftruncate(sample_file->fd, image->len + sizeof(struct opd_footer) - 1) == -1) { fprintf(stderr, "oprofiled: ftruncate failed for \"%s\". %s\n", mangled, strerror(errno)); goto err2; } -#endif sample_file->footer = mmap(0, image->len + sizeof(struct opd_footer), PROT_READ|PROT_WRITE, MAP_SHARED, sample_file->fd, 0); @@ -1163,7 +1142,8 @@ opd_stats[OPD_SAMPLES]++; - verbprintf("DO_PUT_SAMPLE: EIP 0x%.8x, pid %.6d, count %.6d\n", sample->eip, sample->pid, sample->count); + verbprintf("DO_PUT_SAMPLE: c%d, EIP 0x%.8x, pid %.6d, count %.6d\n", + opd_get_counter(sample->count), sample->eip, sample->pid, sample->count); if (opd_eip_is_kernel(sample->eip)) { opd_handle_kernel_sample(sample->eip, sample->count); Index: oprofiled.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/oprofiled.c,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- oprofiled.c 2001/09/01 02:03:34 1.40 +++ oprofiled.c 2001/09/06 18:13:28 1.41 @@ -21,6 +21,7 @@ extern u32 ctr_count[OP_MAX_COUNTERS]; extern u8 ctr_event[OP_MAX_COUNTERS]; extern u8 ctr_um[OP_MAX_COUNTERS]; +uint op_nr_counters = 2; static int showvers; int verbose; @@ -51,7 +52,6 @@ static struct poptOption options[] = { { "buffer-size", 'b', POPT_ARG_INT, &opd_buf_size, 0, "nr. of entries in kernel buffer", "num", }, - { "use-cpu", 'p', POPT_ARG_INT, &cpu_type, 0, "0 for PPro, 1 for PII, 2 for PIII, 3 for Athlon", "[0|1|2|3]" }, { "ignore-myself", 'm', POPT_ARG_INT, &ignore_myself, 0, "ignore samples of oprofile driver", "[0|1]"}, { "log-file", 'l', POPT_ARG_STRING, &logfilename, 0, "log file", "file", }, { "base-dir", 'd', POPT_ARG_STRING, &opd_dir, 0, "base directory of daemon", "dir", }, @@ -155,7 +155,8 @@ { poptContext optcon; int ret; - int i, ok; + uint i; + int ok; char c; /* should be sufficient to hold /proc/sys/dev/oprofile/%d/yyyy */ char filename[PATH_MAX + 1]; @@ -165,7 +166,7 @@ c=poptGetNextOpt(optcon); - if (c<-1) { + if (c < -1) { fprintf(stderr, "oprofiled: %s: %s\n", poptBadOption(optcon, POPT_BADOPTION_NOALIAS), poptStrerror(c)); @@ -201,29 +202,24 @@ ctr_um[i]= opd_read_int_from_file(filename); } - cpu_type = opd_read_int_from_file("/proc/sys/dev/oprofile/cpu_type"); - - ok = 1; - /* PHE FIXME : We need to translate cpu_type to a string, see - * cpu_typ_str in op_events.c */ for (i = 0 ; i < op_nr_counters ; ++i) { ret = op_check_events(i, ctr_event[i], ctr_um[i], cpu_type); if (ret & OP_EVT_NOT_FOUND) - fprintf(stderr, "oprofiled: ctr%d: %d: no such event for cpu %d\n", - i, ctr_event[i], cpu_type); + fprintf(stderr, "oprofiled: ctr%d: %d: no such event for cpu %s\n", + i, ctr_event[i], op_get_cpu_type_str(cpu_type)); if (ret & OP_EVT_NO_UM) - fprintf(stderr, "oprofiled: ctr%d: 0x%.2x: invalid unit mask for cpu %d\n", - i, ctr_um[i], cpu_type); + fprintf(stderr, "oprofiled: ctr%d: 0x%.2x: invalid unit mask for cpu %s\n", + i, ctr_um[i], op_get_cpu_type_str(cpu_type)); if (ret & OP_EVT_CTR_NOT_ALLOWED) fprintf(stderr, "oprofiled: ctr%d: %d: can't count event for this counter\n", i, ctr_count[i]); if (ret != OP_EVENTS_OK) - ok = 0; + exit(1); } if (!ok) { @@ -422,6 +418,10 @@ size_t opd_buf_bytesize; struct sigaction act; int i; + + cpu_type = opd_read_int_from_file("/proc/sys/dev/oprofile/cpu_type"); + if (cpu_type == CPU_ATHLON) + op_nr_counters = 4; opd_options(argc, argv); |