[parsec-users] PARSEC Pin instrumentation Error

Joseph Greathouse jlgreath at umich.edu
Mon Apr 25 14:20:40 EDT 2011


Re: pintools and OpenMP. I'm pretty sure it's possible to trace OpenMP 
thread manipulations in Pin, but it requires a lot of work. You'll 
probably need to follow library calls and know what actions they are 
going to take.

Depending on what you want to keep track of, you may be able to hack 
your way through gathering the data you desire. For instance, I once 
wanted to know the thread number I was in, assuming that at each 
omp_parallel section, OMP_NUM_THREADS new threads were launched 
(Libgomp, instead, launches OMP_NUM_THREADS worker threads when it 
enters the first parallel region and keeps them alive until the program 
ends). Instead of counting threads with PIN_AddThreadStartFunction 
(which would only be called for the first parallel region), I faked this 
by inserting superfluous inline assembly instructions at the beginning 
of each parallel region. I used 'prefetcht0', which was never used 
otherwise in my program, and placed ThreadStartFunction into the 
function called by code like the following:

if (INS_Opcode(ins) == XED_ICLASS_PREFETCHT0) {
    INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)Prefetch0Call, 
IARG_THREAD_ID, IARG_END);
    INS_Delete(ins);
}

Your best bet may be to ask on the pinheads mailing list if you wish to 
do something more complex.

-Joe

On 4/25/2011 1:54 PM, Yungang Bao wrote:
> Hi,
>
> Raytrace uses a threadpool to run task in parallel. Once the threads in the pool are created, they keep alive until receive a THREAD_EXIT signal. I am also curious that it seems that those threads  will never receive the THREAD_EXIT signal. It might be a bug here.
>
> Freqmine uses OpenMP rather than pthread. So for your case, I doubt if Pintool supports monitoring OpenMP thread manipulations.
>
> Best Regards,
> Yungang
>
> ----- Original Message -----
> From: "Sudhanshu Shukla"<sudhan345 at gmail.com>
> To: parsec-users at lists.cs.princeton.edu
> Sent: Sunday, April 24, 2011 11:51:58 PM
> Subject: [parsec-users] PARSEC Pin instrumentation Error
>
>
> Hi All,
>
>
> I have been trying for instrument PARSEC with pin. For initial testing I am using a pintool similar to malloc_mt which just records the thread begin and thread end. The code for the pintool is attached with this mail.
>
>
> On instrumenting raytrace and freqmine application(with 8, 16, 32 threads) with this pintool. I observe that the number of threads created are not equal to the number of threads that end.
>
>
> For all the other application and kernels, the number of threads created is same as number of threads that end.
>
>
> Can somebody please verify this? or is there some problem with my pintool.
>
>
>
> Thanks
>
>
> Sudhanshu Shukla
>
>
>
>
> -------------------------------------------------------Pintool used---------------------------------
>
> #include<stdio.h>
> #include "pin.H"
>
>
> KNOB<string>  KnobOutputFile(KNOB_MODE_WRITEONCE, "pintool",
> "o", "traceThread.out", "specify output file name");
>
>
> FILE * out;
> PIN_LOCK lock;
>
>
> VOID ThreadStart(THREADID threadid, CONTEXT *ctxt, INT32 flags, VOID *v)
> {
> GetLock(&lock, threadid+1);
> fprintf(out, "thread begin %d\n",threadid);
> fflush(out);
> ReleaseLock(&lock);
> }
>
>
> VOID ThreadFini(THREADID threadid, const CONTEXT *ctxt, INT32 code, VOID *v)
> {
> GetLock(&lock, threadid+1);
> fprintf(out, "thread end %d code %d\n",threadid, code);
> fflush(out);
> ReleaseLock(&lock);
> }
>
>
> VOID Fini(INT32 code, VOID *v)
> {
> fclose(out);
> }
>
>
> INT32 Usage()
> {
> PIN_ERROR("This Pintool prints a trace of thread start and thread end in the guest application\n"
> + KNOB_BASE::StringKnobSummary() + "\n");
> return -1;
> }
>
>
> int main(INT32 argc, CHAR **argv)
> {
> // Initialize the pin lock
> InitLock(&lock);
>
> // Initialize pin
> if (PIN_Init(argc, argv)) return Usage();
> PIN_InitSymbols();
>
> out = fopen(KnobOutputFile.Value().c_str(), "w");
>
>
> // Register Analysis routines to be called when a thread begins/ends
> PIN_AddThreadStartFunction(ThreadStart, 0);
> PIN_AddThreadFiniFunction(ThreadFini, 0);
>
>
> // Register Fini to be called when the application exits
> PIN_AddFiniFunction(Fini, 0);
>
> // Never returns
> PIN_StartProgram();
>
> return 0;
> }


More information about the parsec-users mailing list