Index: perfctr25/CHANGES =================================================================== RCS file: /home/mikpe/CvsRoot/perfctr/CHANGES,v retrieving revision 1.94 retrieving revision 1.95 diff -u -r1.94 -r1.95 --- perfctr25/CHANGES 23 Mar 2003 02:24:47 -0000 1.94 +++ perfctr25/CHANGES 30 Mar 2003 12:32:31 -0000 1.95 @@ -1,10 +1,16 @@ -$Id: CHANGES,v 1.94 2003/03/23 02:24:47 mikpe Exp $ +$Id: CHANGES,v 1.95 2003/03/30 12:32:31 mikpe Exp $ CHANGES ======= [High-level changes in reverse chronological order. Detailed driver changes are in linux/drivers/perfctr/RELEASE-NOTES.] + +- Fixes to user-space library implementation of remote-control + virtual performance counters: open() failed due to a missing + return; avoid potential buffer overflow error; fix the "read + counters" procedure for the case where the remote process is + sampling the time-stamp counter but no performance counters. Version 2.5.1, 2003-03-23 - Fixed initialisation on hyper-threading capable P4s in Index: perfctr25/usr.lib/virtual.c =================================================================== RCS file: /home/mikpe/CvsRoot/perfctr/usr.lib/virtual.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- perfctr25/usr.lib/virtual.c 10 Mar 2003 22:07:58 -0000 1.11 +++ perfctr25/usr.lib/virtual.c 30 Mar 2003 12:31:36 -0000 1.12 @@ -1,4 +1,4 @@ -/* $Id: virtual.c,v 1.11 2003/03/10 22:07:58 mikpe Exp $ +/* $Id: virtual.c,v 1.12 2003/03/30 12:31:36 mikpe Exp $ * Library interface to virtual per-process performance counters. * * Copyright (C) 1999-2003 Mikael Pettersson @@ -137,10 +137,32 @@ return kstate->cpu_state.sum.pmc[i]; } +static void vperfctr_read_ctrs_slow(const struct vperfctr *vperfctr, + struct perfctr_sum_ctrs *sum) +{ + unsigned int tsc0, tsc1; + unsigned int cstatus, nrctrs; + volatile const struct vperfctr_state *kstate; + unsigned int i; + + ioctl(vperfctr->fd, VPERFCTR_SAMPLE, NULL); + kstate = vperfctr->kstate; + cstatus = kstate->cpu_state.cstatus; + nrctrs = perfctr_cstatus_nrctrs(cstatus); + tsc1 = kstate->cpu_state.start.tsc; + do { + tsc0 = tsc1; + sum->tsc = kstate->cpu_state.sum.tsc; + for(i = 0; i < nrctrs; ++i) + sum->pmc[i] = kstate->cpu_state.sum.pmc[i]; + tsc1 = kstate->cpu_state.start.tsc; + } while( tsc1 != tsc0 ); +} + void vperfctr_read_ctrs(const struct vperfctr *self, struct perfctr_sum_ctrs *sum) { - unsigned int tsc0, tsc1, now; + unsigned int tsc0, now; unsigned int cstatus, nrctrs; volatile const struct vperfctr_state *kstate; int i; @@ -164,15 +186,7 @@ return; goto retry; } - ioctl(self->fd, VPERFCTR_SAMPLE, NULL); - tsc1 = kstate->cpu_state.start.tsc; - do { - tsc0 = tsc1; - sum->tsc = kstate->cpu_state.sum.tsc; - for(i = 0; i < nrctrs; ++i) - sum->pmc[i] = kstate->cpu_state.sum.pmc[i]; - tsc1 = kstate->cpu_state.start.tsc; - } while( tsc1 != tsc0 ); + vperfctr_read_ctrs_slow(self, sum); } int vperfctr_read_state(const struct vperfctr *self, struct perfctr_sum_ctrs *sum, @@ -247,13 +261,12 @@ char filename[64]; struct rvperfctr *rvperfctr; - sprintf(filename, "/proc/%d/perfctr", pid); + snprintf(filename, sizeof filename, "/proc/%d/perfctr", pid); rvperfctr = malloc(sizeof(*rvperfctr)); if( rvperfctr ) { if( vperfctr_open_name(filename, &rvperfctr->vperfctr) == 0 ) { rvperfctr->pid = pid; - /* clear have_rdpmc to ensure read_ctrs() avoids fast path */ - rvperfctr->vperfctr.have_rdpmc = 0; + return rvperfctr; } free(rvperfctr); } @@ -273,7 +286,7 @@ void rvperfctr_read_ctrs(const struct rvperfctr *rvperfctr, struct perfctr_sum_ctrs *sum) { - return vperfctr_read_ctrs(&rvperfctr->vperfctr, sum); + return vperfctr_read_ctrs_slow(&rvperfctr->vperfctr, sum); } int rvperfctr_read_state(const struct rvperfctr *rvperfctr,