unsigned long measure_bw_and_set_irq(void) { long r_mbps, w_mbps, mbps; ktime_t ts; unsigned int us; preempt_disable(); ts = ktime_get(); us = ktime_to_us(ktime_sub(ts, prev_ts)); if (!us) us = 1; mon_disable(RD_MON); mon_disable(WR_MON); r_mbps = mon_get_count(RD_MON, prev_r_start_val); r_mbps = beats_to_mbps(r_mbps, us); w_mbps = mon_get_count(WR_MON, prev_w_start_val); w_mbps = beats_to_mbps(w_mbps, us); prev_r_start_val = mon_set_limit_mbyte(RD_MON, to_limit(r_mbps)); prev_w_start_val = mon_set_limit_mbyte(WR_MON, to_limit(w_mbps)); prev_ts = ts; mon_enable(RD_MON); mon_enable(WR_MON); preempt_enable(); mbps = r_mbps + w_mbps; pr_debug("R/W/BW/us = %ld/%ld/%ld/%d\n", r_mbps, w_mbps, mbps, us); return mbps; }
static void measure_bw(void) { int r_mbps, w_mbps, mbps; ktime_t ts; unsigned int us; mutex_lock(&bw_lock); /* * Since we are stopping the counters, we don't want this short work * to be interrupted by other tasks and cause the measurements to be * wrong. Not blocking interrupts to avoid affecting interrupt * latency and since they should be short anyway because they run in * atomic context. */ preempt_disable(); ts = ktime_get(); us = ktime_to_us(ktime_sub(ts, prev_ts)); if (!us) us = 1; mon_disable(0); mon_disable(1); r_mbps = mon_get_mbps(0, prev_r_start_val, us); w_mbps = mon_get_mbps(1, prev_w_start_val, us); prev_r_start_val = mon_set_limit_mbyte(0, to_limit(r_mbps)); prev_w_start_val = mon_set_limit_mbyte(1, to_limit(w_mbps)); mon_enable(0); mon_enable(1); preempt_enable(); mbps = r_mbps + w_mbps; pr_debug("R/W/BW/us = %d/%d/%d/%d\n", r_mbps, w_mbps, mbps, us); compute_bw(mbps); prev_ts = ts; mutex_unlock(&bw_lock); }
unsigned long measure_bw_and_set_irq(void) { long r_mbps, w_mbps, mbps; ktime_t ts; unsigned int us; /* * Since we are stopping the counters, we don't want this short work * to be interrupted by other tasks and cause the measurements to be * wrong. Not blocking interrupts to avoid affecting interrupt * latency and since they should be short anyway because they run in * atomic context. */ preempt_disable(); ts = ktime_get(); us = ktime_to_us(ktime_sub(ts, prev_ts)); if (!us) us = 1; mon_disable(RD_MON); mon_disable(WR_MON); r_mbps = mon_get_count(RD_MON, prev_r_start_val); r_mbps = beats_to_mbps(r_mbps, us); w_mbps = mon_get_count(WR_MON, prev_w_start_val); w_mbps = beats_to_mbps(w_mbps, us); prev_r_start_val = mon_set_limit_mbyte(RD_MON, to_limit(r_mbps)); prev_w_start_val = mon_set_limit_mbyte(WR_MON, to_limit(w_mbps)); prev_ts = ts; mon_enable(RD_MON); mon_enable(WR_MON); preempt_enable(); mbps = r_mbps + w_mbps; pr_debug("R/W/BW/us = %ld/%ld/%ld/%d\n", r_mbps, w_mbps, mbps, us); return mbps; }