Altering default behaviour of CPC_OVF_NOTIFY_EMT

Greetings,

I am part of a group at Simon Fraser University who are developing a program to generate reuse-distance profiles across a variety of benchmark applications. We are testing our work on a Sun Fire T2000 server (64-bit SPARC v9 processor @1200MHz).

My job has been to create a program that controls the application that we want to sample. I have used the open-source code for cputrack as a guide, and have been using the cpc and pctx libraries quite extensively.

My program captures a process that is already running by making a call to pctx_capture():

pctx = pctx_capture(opts->pid, NULL, 1, NULL);

Thus I have a controlling process and a controlled process. Eventually we will be using SPEC CPU2000 benchmarks as the controlled processes. But for now, I am just using a very long loop that does some arbitrary calculations.

So far everything is working as it is expected to work, but not as I want it to work. I program the hardware counter to count the number of completed instructions (Instr_cnt) and to send a SIGEMT signal on a counter overflow:

ind1 = cpc_set_add_request(cpc, set, event1, QUICK_OVF, CPC_COUNT_USER | CPC_COUNT_SYSTEM | CPC_OVF_NOTIFY_EMT, 0, NULL);

When the controlled process (my long loop) receives the SIGEMT it exits and creates a core file as per the default system behavior on receiving a SIGEMT signal. However, the behavior we want to achieve is for the SIGEMT signal to be sent to the controlling process which can properly handle it and allow the controlled process to run to it's 'natural' completion.

My question is how can I alter the default behavior of CPC_OVF_NOTIFY_EMT so that a SIGEMT signal is sent to the controlling process and not the controlled process?

Any help or suggestions would be greatly appreciated.

Regards,

James Lang

SFU

[1880 byte] By [jaymiesa] at [2007-11-27 9:03:31]
# 1

Have you seen the following?

cpc(3CPC)

http://docs.sun.com/app/docs/doc/816-5172/6mbb7btdl?a=view

Performance Counters In Other Processes

Though applications can be modified to instrument themselves as demonstrated above, it is frequently useful to be able to examine the behavior of an existing application without changing the source code. A separate library, libpctx, provides a simple set of interfaces that use the facilities of proc(4) to control a target process, and together with functions in libcpc, allow truss-like tools to be constructed to measure the performance counters in other applications. An example of one such application is cputrack(1).

The functions in libpctx are independent of those in libcpc. These functions manage a process using an event-loop paradigm ?that is, the execution of certain system calls by the controlled process cause the library to stop the controlled process and execute callback functions in the context of the controlling process. These handlers can perform various operations on the target process using APIs in libpctx and libcpc that consume pctx_t handles.

horsha at 2007-7-12 21:35:39 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Thank you for the response.

I have a decent understanding of the cpc and pctx libraries. My program uses them to take control of the process that we wish to monitor. Thus, like cputrack, I have a controlling process and a controlled/monitored process. This part of my program seems to work perfectly.

I think my first post probably was not very clear. Let my try to re-state the problem: the cpc library allows me to send a SIGEMT signal on a hardware counter overflow to the process that is being controlled/monitored. I need to divert that signal to the controlling process.

I've been pointed to a solution using /proc/<pid>/ctl, where <pid> is the pid of the controlled/monitored process. According to /proc man pages, I can write a "control message" to /proc/<pid>/ctl that will allow me to alter the behavior of this process. Using the PCSTRACE control message I should be able to STOP the monitored process when it receives the SIGEMT signal. Then, somehow I need to re-direct the SIGEMT signal to the controlling process.

I've been searching the web and forums for examples on how to write to /proc/<pid>/ctl using the PCSTRACE control message. I have not found any clear explanation or examples.

My code fails when I try to write to the ctl file:

[code]

/* Open for writing the /proc/<pid>/ctl file of controlled process. */

(void) sprintf(filename, "/proc/%d/ctl", p);

if ((fd = open(filename, O_WRONLY)) < 0) {

sprintf(msg, "Cannot open %s\n", filename);

log_message(LOG_FILE, msg);

exit(1);

}

/* Build the Control Message */

sigset_t *sigset;

long ctl_msg[2];

ctl_msg[0] = PCSTRACE;

premptyset(&sigset);

praddset(&sigset, SIGEMT);

ctl_msg[1] = (long)sigset;

/* write the control message to the ctl file */

if (write(fd, ctl_msg, 2*sizeof(long)) == -1){

sprintf(msg, "Cannot write to /proc/<pid>/ctl");

log_message(LOG_FILE, msg);

exit(1);

}

[/code]

Any articles that could help explain writing control messages to /proc would be greatly appreciated. I've gone through the /proc man pages, but I need more detail or examples.

Message was edited by:

jaymies

jaymiesa at 2007-7-12 21:35:39 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
The documentation for using /proc is generally poor. You look at the source code of the 'ptools' in OpenSolaris for tips./usr/src/cmd/ptoolsand/usr/src/lib/libproc
ChrisQuenellea at 2007-7-12 21:35:39 > top of Java-index,Development Tools,Solaris and Linux Development Tools...