Lossless performance meas. first example

Harald Hoyer (Hoyer@hot.spotline.de)
Fri, 05 Jun 1998 17:41:52 +0200


Hi,

small measurements of what optimization options can do:

HarryH:[saturn] >gcc testmsr.c -o testmsr
HarryH:[saturn] >./testmsr
instr = 60037
paired= 20003
66.64% paired

HarryH:[saturn] >gcc -O testmsr.c -o testmsr
HarryH:[saturn] >./testmsr
instr = 30015
paired= 10003
66.65% paired

HarryH:[saturn] >gcc -O2 testmsr.c -o testmsr
HarryH:[saturn] >./testmsr
instr = 20012
paired= 10003
99.97% paired

/* Small example program, demonstrating the use of the performance counters
*
* Author: Harald Hoyer mailto:HarryH@Royal.Net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*
*/

#include <stdio.h>
#include <asm/msr.h>

typedef union {
unsigned long long ll;
unsigned long la[2];
} lreg;

main()
{
lreg val[2], pair[2];
int i,j;
char buf[4096];

FILE *fptr;

/* Setup the counter contrl register to measure only in userland */
/* ctr0: number of instructions */
/* ctr1: number of instructions paired */

if(!(fptr = fopen("/proc/self/msr","r+b")))
exit(10);

fprintf(fptr, "%lu,0,0,0,0,0\n", ES0(0x16)|CC0(2)|ES1(0x17)|CC1(2));

fclose(fptr);

/* Read the values the first time */
rdpmc(0, val[0].la[0],val[0].la[1]);
rdpmc(1, pair[0].la[0],pair[0].la[1]);

/* TESTED code segment begins here */

j = 1;

for(i=0;i<10000;i++)j+=i;

/* TESTED code segment ends here */

/* Read the values the second time */

rdpmc(0, val[1].la[0],val[1].la[1]);
rdpmc(1, pair[1].la[0],pair[1].la[1]);

/* Compute difference */
val[1].ll -= val[0].ll;
pair[1].ll -= pair[0].ll;

printf("instr = %Lu\n", val[1].ll);
printf("paired= %Lu\n", pair[1].ll);
printf("%.2lf%% paired\n", 200.0*(double)pair[1].ll / (double)val[1].ll);
printf("\n");
}

-- 
»»»» Harald Hoyer ««»» mailto:HarryH@Royal.Net ««»» http://hot.spotline.de ««««
···············································································
If Machiavelli were a programmer, he'd have worked for AT&T.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu