1

I am trying to find the data hazards using Pintool. I have written this:

    TRACE_AddInstrumentFunction(Trace, 0); //called in main

class readStore  //This is for both read and write. Named read for historical reasons...
{
 public:
    UINT64 addr;
    std::vector<LEVEL_BASE::REG> vread_regs;
    std::vector<LEVEL_BASE::REG> vwrite_regs;
 };

Function Definition for Trace:

   for(BBL bbl=TRACE_BblHead(trace);BBL_Valid(bbl);bbl= BBL_Next(bbl))
   {
    BBL_InsertCall(bbl, IPOINT_BEFORE, AFUNPTR(docount), IARG_UINT32, BBL_NumIns(bbl), IARG_END);

    for(INS ins = BBL_InsHead(bbl); INS_Valid(ins); ins=INS_Next(ins))
    {
    LEVEL_BASE::REG readReg;
            LEVEL_BASE::REG writeReg;
            readStore *rs_temp= new readStore;

            noRRegs=INS_MaxNumRRegs(ins);   //get count of read regs
            noWRegs=INS_MaxNumWRegs(ins);
            for(UINT32 i=0;i<noRRegs;i++)
            {
                    readReg =INS_RegR(ins,i);   //returns readR type
                    if(REG_is_gr_type(readReg))
                    {
                            rs_temp->vread_regs.push_back(readReg) ;
                    }
                    //may want to add else condition
            }
            for(UINT32 j=0;j<noWRegs;j++)   //store all write regs
            {
                    writeReg= INS_RegW(ins,j);
                    if(REG_is_gr_type(writeReg))
                    {
                            rs_temp->vwrite_regs.push_back(writeReg);
                    }

            }
            rs_temp->addr= INS_Address(ins);
            cout << rs_temp->addr;
            cout << "\n";
            readstore.push_back(*rs_temp);//array of objects with everything in it

My idea was to make a vector where I store all the instruction IP, the registers they write to and the registers they read from. I have done all this in the instrumentation function. Thereafter in the Fini Function, I simply calculate the Hazards using normal if-else conditions.

The problem I am facing is when I try to print the size of read_store vector, I am getting a signficantly small number (around 10000) whereas the total number of instructions are >780K. Could someone tell me where I am going wrong?

Jongware
  • 22,200
  • 8
  • 54
  • 100
  • FYI, Intel CPUs avoid WAR or WAW hazards for registers with out-of-order execution + register renaming (Tomasulo's algorithm). (see https://stackoverflow.com/questions/47276053/while-pipelining-can-you-consecutively-write-mov-to-the-same-register-or-does/47276474#47276474, and https://stackoverflow.com/q/45113527/224132, and https://stackoverflow.com/questions/37361145/deoptimizing-a-program-for-the-pipeline-in-intel-sandybridge-family-cpus). Anyway, that doesn't invalidate your question about how to use PIN to detect load/store addresses, but IDK the answer; I haven't used PIN tools. – Peter Cordes Feb 18 '18 at 04:16
  • And BTW, the same goes for memory locations. The store queue effectively renames memory locations, so only true dependencies (RAW) have to be waited for. e.g. I've tested *independent* store/reload of the same `dword` (with the store *not* dependent on the previous load), and got 1 per clock throughput on Skylake. So multiple store/reloads of the same memory location can be in flight at once. – Peter Cordes Feb 18 '18 at 04:18
  • Yeah. Intel avoids hazards using Tomasulo and using Memory ROB. However, I am simply instrumenting the source code for dynamic instructions so as to characterize my benchmark. Anyways, I found the solution. For anyone who reads this in the future-> the instrument function in Pin is for static code only. For dynamic instructions, you need to put your storage vector in the analysis function. – Yash Karundia Feb 20 '18 at 08:24

0 Answers0