In the case of the target which supports cpu hotplug, the number of
possible online cpus can be changed and thus __get_cpu_stat can be
failed for offline cpus. At worst case if the last __get_cpu_stat is
resulted in negative, kernel_get_per_cpu_stat can return error even
though it is not actual failure. To prevent this situation, this
ignores the case that __get_cpu_stat returns failure.
Change-Id: I5d33e740b2451e7c644b407c1f92785a1e570585
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
int kernel_get_per_cpu_stat(struct cpu_stat *cpus, int num_possible_cpus,
int *num_online_cpus)
{
+ struct cpu_stat cpu;
FILE *fp;
char buf[BUFF_MAX];
int i, ret = 0, count = 0;
/* Get per-cpu utilization data */
for (i = 0; i < num_possible_cpus; i++) {
- ret = __get_cpu_stat(fp, &cpus[i]);
- if (ret < 0)
- break;
+ if (__get_cpu_stat(fp, &cpu) < 0)
+ continue;
+
+ if (cpu.cpu < 0) {
+ ret = -EINVAL;
+ goto err;
+ }
+
+ memcpy(&cpus[cpu.cpu], &cpu, sizeof(struct cpu_stat));
+
count++;
}
*num_online_cpus = count;