/* Get the load_table of each resource to estimate the system load. */
int pass_get_cpu_stats(struct pass_policy *policy)
{
- struct pass_cpu_stats *stats = policy->pass_cpu_stats;
- struct pass_resource *pass_res = to_pass_resource(policy);
+ struct pass_cpu_stats *stats;
+ struct pass_resource *pass_res;
char str[BUFF_MAX];
FILE *fp_stats = NULL;
int i, j, ret;
+ if (!policy)
+ return -EINVAL;
+
+ stats = policy->pass_cpu_stats;
+ pass_res = to_pass_resource(policy);
- if (!policy || !pass_res->cdata.path_load_table || !stats) {
+ if (!stats) {
_E("invalid parameter of structure pass_cpu_stats");
return -EINVAL;
}
return -EIO;
/* Read the title and drop the buffer because it is not used */
- if (!fgets(str, BUFF_MAX, fp_stats))
+ if (!fgets(str, BUFF_MAX, fp_stats)) {
+ fclose(fp_stats);
return -EIO;
+ }
for (i = 0; i < policy->num_pass_cpu_stats; i++) {
ret = fscanf(fp_stats, "%lld %d %d %d",
&stats[i].freq,
&stats[i].freq_new,
&stats[i].nr_runnings);
- if (ret < 0)
+ if (ret < 0) {
+ fclose(fp_stats);
return -EIO;
+ }
for (j = 0; j < pass_res->cdata.num_cpus; j++) {
ret = fscanf(fp_stats, "%d", &stats[i].load[j]);
- if (ret < 0)
+ if (ret < 0) {
+ fclose(fp_stats);
return -EIO;
+ }
}
}
+
fclose(fp_stats);
return 0;
gettimeofday(&now, NULL);
- return (int64_t)(now.tv_sec * 1000 + now.tv_usec / 1000);
+ return ((int64_t) now.tv_sec * 1000 + (int64_t) now.tv_usec / 1000);
}