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) {
56 getrusage(RUSAGE_SELF, &ru);
57 now = ru.ru_utime.tv_sec;
59 now += ru.ru_utime.tv_usec;
68 /************************************************************************
69 * time64 DYNINSTgetWalltime(void)
71 * get the total walltime used by the monitored process.
72 * return value is in usec units.
73 ************************************************************************/
75 time64 DYNINSTgetWalltime(void) {
77 register unsigned int timeSec asm("5");
78 register unsigned int timeNano asm("6");
79 register unsigned int timeSec2 asm("7");
81 /* Need to read the first value twice to make sure it doesn't role
82 * over while we are reading it.
85 asm("mfspr 5,4"); /* read high into register 5 - timeSec */
86 asm("mfspr 6,5"); /* read low into register 6 - timeNano */
87 asm("mfspr 7,4"); /* read high into register 7 - timeSec2 */
89 if (timeSec != timeSec2) goto retry;
90 /* convert to correct form. */
99 * Code to trap execvp call and munge command (for SP-2).
102 void DYNINSTexecvp(char *argv[])
114 if (inExecvp) return;
119 /* this only applies to poe on the SP-2 */
120 if (strcmp(cmd, "poe")) return;
122 for (iCount=0; argv[iCount]; iCount++);
124 pdArgs = (char *) getenv("PARADYN_MASTER_INFO");
126 fprintf(stdout, "unable to get PARADYN_MASTER_INFO\n");
131 /* extras for first arg, command, -runme, and null */
132 for (ch=pdArgs, acount=4; *ch; ch++) if (*ch == ' ') acount++;
133 newArgs = calloc(sizeof(char*), iCount+acount);
136 newArgs[1] = "paradynd";
138 /* skip white spave at start */
139 while (*pdArgs && *pdArgs == ' ') pdArgs++;
141 for (ch=pdArgs, acount=3; *ch; ch++) {
144 /* skip over null argument -caused by spaces in environment var */
145 if (!strlen(newArgs[acount-1])) acount--;
146 newArgs[acount++] = ++ch;
149 /* skip over null argument -caused by space at end of environment var */
150 if (!strlen(newArgs[acount-1])) acount--;
152 newArgs[acount++] = "-runme";
153 for (i=1; i < iCount; i++) {
154 newArgs[acount++] = argv[i];
157 newArgs[acount] = "";
159 /* generate an exit record about the process to paradynd */
162 /* Now call execvp with the correct arguments */
163 ret = execvp(cmd, newArgs);
165 fprintf(stderr, "execvp failed\n");
177 * DYNINSTgetRusage(id) - Return the value of various OS stats.
179 * The id is an integer, and when they are changed, any metric that uses
180 * DYNINSTgetRusage will also need to be updated.
183 int DYNINSTgetRusage(int id)
187 struct rusage rusage;
188 struct rusage *DYNINSTrusagePtr;
190 ret = getrusage(RUSAGE_SELF, &rusage);
194 DYNINSTrusagePtr = &rusage;
196 case 0: /* page faults */
197 value = DYNINSTrusagePtr->ru_minflt+DYNINSTrusagePtr->ru_majflt;
200 value = DYNINSTrusagePtr->ru_nswap;
202 case 2: /* signals received */
203 value = DYNINSTrusagePtr->ru_nsignals;
205 case 3: /* max rss */
206 value = DYNINSTrusagePtr->ru_maxrss;
208 case 4: /* context switches */
209 value = DYNINSTrusagePtr->ru_nvcsw + DYNINSTrusagePtr->ru_nivcsw;