unsigned long long native_read_tsc(void) { return __native_read_tsc(); }
/* void ReadEIP(PEIP_RECORD pRecord) { W32 high, low, i, top; rdmsr(0x1da, low, high); top = low; for(i = 0; i < MAX_EIP_NUM; i++) { top = (top+i) % MAX_EIP_NUM; rdmsr(0x680+top, low, high); pRecord->eipFrom[i] = ((W64)high << 32) | low; rdmsr(0x6c0+top, low, high); pRecord->eipTo[i] = ((W64)high << 32) | low; } } */ int CollectSampling(void) { int cpuId; //W32 low, high; SAMPLE_RECORD record; PROFILING_RECORD profiling; unsigned long irqFlags; #ifdef DBG W32 i; #endif W64 *pointer; //if (counterPackage.eipNum > 0) //{ //stop branch recording // rdmsr(0x1d9, low, high); // low &= 0xfffffffe; // wrmsr(0x1d9, low, high); // //} cpuId = smp_processor_id(); #ifdef DBG printk("collect sampling on core %d\n", cpuId); #endif StopCounter(&counterPackage); //rdtsc(low, high); //record.sampleHeader.rdtsc = (((W64)high)<<32) | low; record.sampleHeader.rdtsc = __native_read_tsc(); record.sampleHeader.sampleId = sampleId; record.sampleHeader.cpuId = cpuId; ReadCounter(&counterPackage, &record); #ifdef DBG pointer = (W64*)(current->thread.sp0); printk("a-------------------------------------------------------------\n"); for(i = 0; i < 8; i++) { //eipRecord.eipFrom[i] = (*pointer); printk("Addr %p: %p\n", pointer, (*pointer)); pointer--; //eipRecord.eipTo[i] = (*pointer); printk("Addr %p: %p\n", pointer, (*pointer)); pointer--; } printk("b-------------------------------------------------------------\n"); //printk("rsp: %p\n",curThread.rsp); //printk("rsp0: %p\n",curThread.rsp0); #endif if (counterPackage.profiling > 0) { pointer = (W64*)(current->thread.sp0); profiling.pid = (W64)current->pid; pointer -= 5; profiling.eip = (*pointer); /* if(sampleId == 0) { printk("cpuId: %d eip: %p\n", cpuId, profiling.eip); printk("pid: %u\n", profiling.pid); } */ } spin_lock_irqsave(&buffer_lock, irqFlags); #ifdef DBG printk("%d cpu get spinlock and write %d bytes to buffer\n", cpuId, sizeof(SAMPLE_HEADER) + sizeof(W64) * counterPackage.usedNum); #endif AddSampleToBuff(&record, sizeof(SAMPLE_HEADER) + sizeof(W64) * counterPackage.usedNum); if (counterPackage.profiling > 0) { AddSampleToBuff(&profiling, sizeof(PROFILING_RECORD)); } spin_unlock_irqrestore(&buffer_lock, irqFlags); //start branch recording //rdmsr(0x1d9, low, high); //low |= 1; //wrmsr(0x1d9, low, high); // #ifdef USE_NMI WRITEMSR(INS_FIXED_COUNTER, COUNTER_OVERFLOW); #endif StartCounter(&counterPackage); return 0; }