* limitations under the License.
*/
+#include <inttypes.h>
+
#include <pass/log.h>
#include "pass.h"
}
/* RESMON_SRC_CPUHP */
+#define RESMON_SRC_CPUHP_COUNT 20
static int resmon_cpuhp_init(struct resmon *monitor)
{
+ struct resmon_result_src_cpuhp *result;
+ int i;
+
+ if (monitor->result)
+ return 0;
+
+ result = calloc(RESMON_SRC_CPUHP_COUNT, sizeof(*result));
+
+ for (i = 0; i < RESMON_SRC_CPUHP_COUNT; i++) {
+ result[i].load = calloc(RESMON_SRC_CPUHP_COUNT,
+ sizeof(unsigned int));
+ result[i].nr_running = calloc(RESMON_SRC_CPUHP_COUNT,
+ sizeof(unsigned int));
+ result[i].runnable_load = calloc(RESMON_SRC_CPUHP_COUNT,
+ sizeof(unsigned int));
+ }
+
+ monitor->result = result;
+
return 0;
}
static int resmon_cpuhp_exit(struct resmon *monitor)
{
+ struct resmon_result_src_cpuhp *result;
+ int i;
+
+ if (!monitor->result)
+ return 0;
+
+ result = (struct resmon_result_src_cpuhp *)monitor->result;
+ if (!result)
+ return -ENOMEM;
+
+ for (i = 0; i < RESMON_SRC_CPUHP_COUNT; i++) {
+ free(result[i].load);
+ free(result[i].nr_running);
+ free(result[i].runnable_load);
+ }
+
+ free(monitor->result);
+ monitor->result = NULL;
+
return 0;
}
static int resmon_cpuhp_timer_handler(struct resmon *monitor, void *result)
{
+ struct pass_resmon *resmon = monitor->resmon;
+ struct pass_resource *res =
+ container_of(resmon, struct pass_resource, resmon);
+ struct resmon_result_src_cpuhp *cpuhp_result = result;
+ char str[BUFF_MAX];
+ int i, j, ret;
+ FILE *fp = NULL;
+
+ if (!cpuhp_result)
+ return -ENOMEM;
+
+ fp = fopen(res->config_data.path_load_table, "r");
+ if (!fp)
+ return -EIO;
+
+ /* Read the title and drop the buffer because it is not used */
+ if (!fgets(str, BUFF_MAX, fp)) {
+ fclose(fp);
+ return -EIO;
+ }
+
+ for (i = 0; i < RESMON_SRC_CPUHP_COUNT; i++) {
+ ret = fscanf(fp, "%" SCNd64 "%u %u %u",
+ &cpuhp_result[i].time,
+ &cpuhp_result[i].freq,
+ &cpuhp_result[i].freq_new,
+ &cpuhp_result[i].nr_runnings);
+ if (ret < 0) {
+ fclose(fp);
+ return -EIO;
+ }
+
+ for (j = 0; j < res->config_data.num_cpus; j++) {
+ ret = fscanf(fp, "%u", &cpuhp_result[i].load[j]);
+ if (ret < 0) {
+ fclose(fp);
+ return -EIO;
+ }
+ }
+ }
+
+ fclose(fp);
+
return 0;
}
* CPU utilization/frequency/the number of running tasks. But this type
* is using nonstandard linux kernel interface. It should be replaced with
* the linux kernel standard interface.
+ *
+ * Description of result format of resource monitor's source type:
+ * - RESMON_SRC_CPUHP : struct resmon_result_src_cpuhp
*/
enum resmon_src_type {
RESMON_SRC_UNKNOWN = 0x0,
RESMON_SRC_CPUHP = 0x2,
};
+/* Result of RESMON_SRC_CPUHP's resource monitor */
+struct resmon_result_src_cpuhp {
+ int64_t time;
+ unsigned int freq;
+ unsigned int freq_new;
+ unsigned int nr_runnings;
+
+ unsigned int *load;
+ unsigned int *nr_running;
+ unsigned int *runnable_load;
+
+ unsigned int num_busy_cpu;
+ unsigned int avg_load;
+ unsigned int avg_runnable_load;
+ unsigned int avg_thread_load;
+ unsigned int avg_thread_runnable_load;
+};
+
/*
* pass_resmon_register_timer - Register timer-based resource monitor.
*