3 * This file contains the implementation of runtime dynamic instrumentation
4 * functions for a normal Sparc with SUNOS.
7 * Revision 1.4 1994/07/05 03:25:10 hollings
8 * obsereved cost model.
10 * Revision 1.3 1994/02/02 00:46:12 hollings
11 * Changes to make it compile with the new tree.
13 * Revision 1.2 1993/12/13 19:47:52 hollings
14 * corrected rindex parameter error
16 * Revision 1.1 1993/08/26 19:43:28 hollings
19 * Revision 1.1 1993/07/02 21:49:35 hollings
27 #include <sys/resource.h>
30 #include <machine/vmparam.h>
37 #include "../h/rtinst.h"
39 int DYNINSTmappedUarea;
41 static int _kmem = -1;
44 * find out if the uarea is safe for mapping.
45 * If it is, return the address of the uarea.
48 caddr_t DYNINSTprobeUarea()
57 kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
63 p = kvm_getproc(kd, pid);
66 perror("kvm_getproc");
74 kvm_getcmd(kd, p, u, &args, NULL);
75 cmd = (char *) rindex(args[0], '/');
82 if (strcmp(cmd, u->u_comm)) {
83 printf("cmd = %s, u_comm = %s\n", cmd, u->u_comm);
90 return((caddr_t)p->p_uarea);
97 static struct user *u;
99 uAddr = DYNINSTprobeUarea();
102 printf("WARNING: program compiled for wrong version of SPARC chip.\n");
103 printf(" using getrusage for times, this may slow your program down\n");
104 printf(" by a factor of ten or more.\n");
105 printf("
\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\n");
110 _kmem = open("/dev/kmem", O_RDONLY, 0);
115 ret = (int) mmap((caddr_t) 0, sizeof(struct user), PROT_READ,
116 MAP_SHARED, _kmem, (off_t) uAddr);
120 u = (struct user *) ret;
121 _p_1 = (int *) &(u->u_ru.ru_utime.tv_sec);
122 _p_2 = (int *) &(u->u_ru.ru_utime.tv_usec);
128 * Run a nop loop to estimate clock frequency.
132 #define LOOP_LIMIT 50000
133 #define MILLION 1000000
135 float DYNINSTgetClock()
143 startF = DYNINSTgetCPUtime();
144 for (i=0; i < LOOP_LIMIT; i++) {
402 endF = DYNINSTgetCPUtime();
404 elapsed = (endF-startF)/((double) MILLION);
405 clockSpeed = (256*LOOP_LIMIT)/elapsed/MILLION;
407 printf("elapsed = %f\n", elapsed);
408 printf("clockSpeed = %f\n", clockSpeed);