2 * Copyright (c) 1993, 1994 Barton P. Miller, Jeff Hollingsworth,
3 * Bruce Irvin, Jon Cargille, Krishna Kunchithapadam, Karen
4 * Karavanic, Tia Newhall, Mark Callaghan. All rights reserved.
6 * This software is furnished under the condition that it may not be
7 * provided or otherwise made available to, or used by, any other
8 * person, except as provided for by the terms of applicable license
9 * agreements. No title to or ownership of the software is hereby
10 * transferred. The name of the principals may not be used in any
11 * advertising or publicity related to this software without specific,
12 * written prior authorization. Any use of this software must include
13 * the above copyright notice.
19 /************************************************************************
20 * RTaix.c: clock access functions for aix.
21 ************************************************************************/
24 #include <sys/resource.h>
28 #include "rtinst/h/rtinst.h"
31 static const double NANO_PER_USEC = 1.0e3;
32 static const long int MILLION = 1000000;
34 /************************************************************************
35 * void DYNINSTos_init(void)
37 * os initialization function---currently null.
38 ************************************************************************/
41 DYNINSTos_init(void) {
45 /************************************************************************
46 * time64 DYNINSTgetCPUtime(void)
48 * return value is in usec units.
49 ************************************************************************/
52 DYNINSTgetCPUtime(void) {
54 static time64 previous=0;
58 if (!getrusage(RUSAGE_SELF, &ru)) {
59 now = (time64)ru.ru_utime.tv_sec + (time64)ru.ru_stime.tv_sec;
60 now *= (time64)1000000;
61 now += (time64)ru.ru_utime.tv_usec + (time64)ru.ru_stime.tv_usec;
78 /************************************************************************
79 * time64 DYNINSTgetWalltime(void)
81 * get the total walltime used by the monitored process.
82 * return value is in usec units.
83 ************************************************************************/
85 time64 DYNINSTgetWalltime(void) {
87 register unsigned int timeSec asm("5");
88 register unsigned int timeNano asm("6");
89 register unsigned int timeSec2 asm("7");
91 /* Need to read the first value twice to make sure it doesn't role
92 * over while we are reading it.
95 asm("mfspr 5,4"); /* read high into register 5 - timeSec */
96 asm("mfspr 6,5"); /* read low into register 6 - timeNano */
97 asm("mfspr 7,4"); /* read high into register 7 - timeSec2 */
99 if (timeSec != timeSec2) goto retry;
100 /* convert to correct form. */
101 now = (timer64)timeSec;
102 now *= (timer64)MILLION;
103 now += (timer64)timeNano/(timer64)1000;
109 * Code to trap execvp call and munge command (for SP-2).
112 void DYNINSTexecvp(char *argv[])
124 if (inExecvp) return;
129 /* this only applies to poe on the SP-2 */
130 if (strcmp(cmd, "poe")) return;
132 for (iCount=0; argv[iCount]; iCount++);
134 pdArgs = (char *) getenv("PARADYN_MASTER_INFO");
136 fprintf(stdout, "unable to get PARADYN_MASTER_INFO\n");
141 /* extras for first arg, command, -runme, and null */
142 for (ch=pdArgs, acount=4; *ch; ch++) if (*ch == ' ') acount++;
143 newArgs = calloc(sizeof(char*), iCount+acount);
146 newArgs[1] = "paradynd";
148 /* skip white spave at start */
149 while (*pdArgs && *pdArgs == ' ') pdArgs++;
151 for (ch=pdArgs, acount=3; *ch; ch++) {
154 /* skip over null argument -caused by spaces in environment var */
155 if (!strlen(newArgs[acount-1])) acount--;
156 newArgs[acount++] = ++ch;
159 /* skip over null argument -caused by space at end of environment var */
160 if (!strlen(newArgs[acount-1])) acount--;
162 newArgs[acount++] = "-runme";
163 for (i=1; i < iCount; i++) {
164 newArgs[acount++] = argv[i];
167 newArgs[acount] = "";
169 /* generate an exit record about the process to paradynd */
172 /* Now call execvp with the correct arguments */
173 ret = execvp(cmd, newArgs);
175 fprintf(stderr, "execvp failed\n");
187 * DYNINSTgetRusage(id) - Return the value of various OS stats.
189 * The id is an integer, and when they are changed, any metric that uses
190 * DYNINSTgetRusage will also need to be updated.
193 int DYNINSTgetRusage(int id)
197 struct rusage rusage;
198 struct rusage *DYNINSTrusagePtr;
200 ret = getrusage(RUSAGE_SELF, &rusage);
204 DYNINSTrusagePtr = &rusage;
206 case 0: /* page faults */
207 value = DYNINSTrusagePtr->ru_minflt+DYNINSTrusagePtr->ru_majflt;
210 value = DYNINSTrusagePtr->ru_nswap;
212 case 2: /* signals received */
213 value = DYNINSTrusagePtr->ru_nsignals;
215 case 3: /* max rss */
216 value = DYNINSTrusagePtr->ru_maxrss;
218 case 4: /* context switches */
219 value = DYNINSTrusagePtr->ru_nvcsw + DYNINSTrusagePtr->ru_nivcsw;