irqreturn_t px_timer_isr(unsigned int pid, unsigned int tid, unsigned int pc, unsigned long long ts) { bool buffer_full = false; PXD32_Hotspot_Sample_V2 sample_rec; // disable the interrupt TMR_IERn(timer_group, timer_no) = 0; // clear the interrupt flag TMR_ICRn(timer_group, timer_no) = 1; // set next match TMR_Tn_Mm(timer_group, timer_no, 0) = g_tbs_settings.interval * get_timer_freq() / 1000; //TMR_Tn_Mm(timer_group, timer_no, 0) += g_tbs_settings.interval * get_timer_freq() / 1000; if (tbs_running) { /* write sample record to sample buffer */ sample_rec.pc = pc; sample_rec.pid = pid; sample_rec.tid = tid; sample_rec.registerId = COUNTER_PJ1_OS_TIMER; memcpy(sample_rec.timestamp, &ts, sizeof(sample_rec.timestamp)); buffer_full = write_sample(0, &sample_rec); if (buffer_full) { tbs_running = false; } else { tbs_running = true; } } // enable the interrupt TMR_IERn(timer_group, timer_no) = 1; return IRQ_HANDLED; }
measure_cpu_freq(size_t n) { unsigned long start_mtime, delta_mtime; unsigned long mtime_freq = get_timer_freq(); // Don't start measuruing until we see an mtime tick unsigned long tmp = mtime_lo(); do { start_mtime = mtime_lo(); } while (start_mtime == tmp); unsigned long start_mcycle = read_csr(mcycle); do { delta_mtime = mtime_lo() - start_mtime; } while (delta_mtime < n); unsigned long delta_mcycle = read_csr(mcycle) - start_mcycle; return (delta_mcycle / delta_mtime) * mtime_freq + ((delta_mcycle % delta_mtime) * mtime_freq) / delta_mtime; }
void udelay(unsigned int usecs) { extern void _wait_ticks(unsigned long); unsigned long ticksperusec = get_timer_freq() / 1000000; _wait_ticks(ticksperusec * usecs); }
int start_tbs(bool is_start_paused) { #ifdef HW_TBS int ret; select_timer(); init_ap_timer(); ret = request_irq(get_timer_irq(), px_hotspot_isr, IRQF_TIMER/*|IRQF_DISABLED*/, "CPA Timer", dev_id); if (ret != 0) { printk(KERN_ALERT "[CPA] Failed to request IRQ: %d\n", get_timer_irq()); return ret; } /* Enable interrupt on match0 */ TMR_IERn(timer_group, timer_no) = 1; /* Prime the match register */ TMR_Tn_Mm(timer_group, timer_no, 0) = g_tbs_settings.interval * get_timer_freq() / 1000; if (!is_start_paused) { tbs_running = true; /* Enable the timer */; TMR_CER(timer_group) |= 0x1 << timer_no; } else { tbs_running = false; /* Disable the timer */ //TMR_CER(timer_group) &= ~(0x1 << timer_no); /* Enable the timer */; TMR_CER(timer_group) |= 0x1 << timer_no; } return 0; #else int ret; ktime_t ktime; unsigned long delay_in_ns = g_tbs_settings.interval * NSEC_PER_USEC; if (!is_start_paused) { tbs_running = true; } else { tbs_running = false; } ktime = ktime_set(0, delay_in_ns); hrtimer_init(&hrtimer_for_tbs, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hrtimer_for_tbs.function = hrtimer_func; ret = hrtimer_start(&hrtimer_for_tbs, ktime, HRTIMER_MODE_REL); return 0; #endif }