diff options
author | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2014-12-29 09:22:23 +0200 |
---|---|---|
committer | Tuukka Tikkanen <tuukka.tikkanen@linaro.org> | 2014-12-29 10:05:37 +0200 |
commit | 9364b59a8cb8dc60db5cbe2a365d877d5c079a7a (patch) | |
tree | 0b7d27eaa2a340c64e87b11be578173042a35938 /idlestat.c | |
parent | 1b4211cbbdadd22759f07ded97f74aa5ad0992a4 (diff) |
Idlestat: Prevent alloc_pstate from creating duplicate entries
The existing version of alloc_pstate() can create duplicate
entries for the same pstate if called with a frequency
value that already exists. Change the semantics so that
in case the frequency already exists in the array, the
index returned is for the existing frequency.
This change allows removal of (now) obsolete function
get_current_pstate and merging of pstate entries between
main trace and baseline trace for comparison report purposes.
Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
Diffstat (limited to 'idlestat.c')
-rw-r--r-- | idlestat.c | 38 |
1 files changed, 15 insertions, 23 deletions
@@ -489,12 +489,16 @@ static void output_pstates(FILE *f, struct init_pstates *initp, int nrcpus, } /** - * alloc_pstate - allocate, sort, and initialize pstate struct to maintain - * statistics of P-state transitions + * alloc_pstate - allocate and initialize a cpufreq_pstate struct if needed * @pstates: per-CPU P-state statistics struct - * @freq: frequency for which the newly pstate is allocated + * @freq: frequency for which the new pstate should be allocated * - * Return: the index of the newly allocated pstate struct + * This function checks the array of struct cpufreq_pstate in @pstates + * for an entry for @freq. If one if found, the index for this entry + * is returned. If not, a new entry is inserted into the array so that + * the frequencies are in decreasing order and the index for the new + * entry is returned. + * @return: the index of the existing or newly allocated pstate struct */ static int alloc_pstate(struct cpufreq_pstates *pstates, unsigned int freq) { @@ -504,6 +508,12 @@ static int alloc_pstate(struct cpufreq_pstates *pstates, unsigned int freq) pstate = pstates->pstate; nrfreq = pstates->max; + for (i = 0; i < nrfreq && freq <= pstate[i].freq; i++) { + if (pstate[i].freq == freq) + return i; + } + next = i; + tmp = realloc(pstate, sizeof(*pstate) * (nrfreq + 1)); if (!tmp) { perror(__func__); @@ -513,10 +523,6 @@ static int alloc_pstate(struct cpufreq_pstates *pstates, unsigned int freq) pstates->pstate = tmp; pstates->max = nrfreq + 1; - for (i = 0; i < nrfreq && freq <= pstate[i].freq; i++) - ; - - next = i; memmove(pstate + next + 1, pstate + next, sizeof(*pstate) * (nrfreq - next)); memset(pstate + next, 0, sizeof(*pstate)); for (i = nrfreq; i > next; i--) @@ -606,18 +612,6 @@ static int get_current_pstate(struct cpuidle_datas *datas, int cpu, return ps->idle; } -static int freq_to_pstate_index(struct cpufreq_pstates *ps, unsigned int freq) -{ - int i; - - /* find frequency in table of P-states */ - for (i = 0; i < ps->max && freq != ps->pstate[i].freq; i++) - /* just search */; - - /* if not found, return -1 */ - return i >= ps->max ? -1 : ps->pstate[i].id; -} - static void open_current_pstate(struct cpufreq_pstates *ps, double time) { ps->time_enter = time; @@ -659,9 +653,7 @@ void cpu_change_pstate(struct cpuidle_datas *datas, int cpu, int cur, next; cur = get_current_pstate(datas, cpu, &ps, &p); - next = freq_to_pstate_index(ps, freq); - if (next < 0) - next = alloc_pstate(ps, freq); + next = alloc_pstate(ps, freq); assert (next >= 0); switch (cur) { |