static int mp_decision(void) { static bool first_call = true; int new_state = TEGRA_HP_IDLE; int nr_cpu_online; int index; unsigned int rq_depth; static cputime64_t total_time = 0; static cputime64_t last_time; cputime64_t current_time; cputime64_t this_time = 0; current_time = ktime_to_ms(ktime_get()); if (first_call) { first_call = false; } else { this_time = current_time - last_time; } total_time += this_time; rq_depth = get_rq_info(); nr_cpu_online = num_online_cpus(); mutex_lock(&tegra3_mp_lock); if (nr_cpu_online) { index = (nr_cpu_online - 1) * 2; if ((nr_cpu_online < 4) && (rq_depth >= NwNs_Threshold[index])) { if (total_time >= TwTs_Threshold[index]) { new_state = TEGRA_HP_UP; } } else if (rq_depth <= NwNs_Threshold[index+1]) { if (total_time >= TwTs_Threshold[index+1] ) { new_state = TEGRA_HP_DOWN; } } else { total_time = 0; } } else { total_time = 0; } mutex_unlock(&tegra3_mp_lock); if (new_state != TEGRA_HP_IDLE) { total_time = 0; } last_time = ktime_to_ms(ktime_get()); return new_state; }
static void update_rq_stats_state(void) { static bool first_call = true; unsigned int rq_depth; unsigned int nr_cpu_online; unsigned int max_cpus = tegra_cpq_max_cpus(); unsigned int min_cpus = tegra_cpq_min_cpus(); static cputime64_t total_time = 0; static cputime64_t last_time; cputime64_t current_time; cputime64_t this_time = 0; int index; if (rq_stats_state == DISABLED) return; current_time = ktime_to_ms(ktime_get()); if (current_time <= start_delay){ rq_stats_state = IDLE; return; } if (first_call) { first_call = false; } else { this_time = current_time - last_time; } total_time += this_time; rq_depth = get_rq_info(); nr_cpu_online = num_online_cpus(); rq_stats_state = IDLE; if (nr_cpu_online) { index = (nr_cpu_online - 1) * 2; if ((nr_cpu_online < CONFIG_NR_CPUS) && (rq_depth >= NwNs_Threshold[index])) { if (total_time >= TwTs_Threshold[index]) { if (nr_cpu_online < max_cpus){ #if DEBUG pr_info(RQ_STATS_TAG "UP rq_depth=%d total_time=%lld NwNs_Threshold[index]=%d TwTs_Threshold[index]=%d nr_cpu_online=%d min_cpus=%d max_cpus=%d\n", rq_depth, total_time, NwNs_Threshold[index], TwTs_Threshold[index], nr_cpu_online, min_cpus, max_cpus); #endif rq_stats_state = UP; } } } else if (rq_depth <= NwNs_Threshold[index+1]) { if (total_time >= TwTs_Threshold[index+1] ) { if ((nr_cpu_online > 1) && (nr_cpu_online > min_cpus)){ #if DEBUG pr_info(RQ_STATS_TAG "DOWN rq_depth=%d total_time=%lld NwNs_Threshold[index+1]=%d TwTs_Threshold[index+1]=%d nr_cpu_online=%d min_cpus=%d max_cpus=%d\n", rq_depth, total_time, NwNs_Threshold[index+1], TwTs_Threshold[index+1], nr_cpu_online, min_cpus, max_cpus); #endif rq_stats_state = DOWN; } } } else { rq_stats_state = IDLE; total_time = 0; } } else { total_time = 0; } if (rq_stats_state != IDLE) { total_time = 0; } last_time = ktime_to_ms(ktime_get()); }