struct membw_read_format {
__u64 value; /* The value of the event */
__u64 time_enabled; /* if PERF_FORMAT_TOTAL_TIME_ENABLED */
__u64 time_running; /* if PERF_FORMAT_TOTAL_TIME_RUNNING */
__u64 id; /* if PERF_FORMAT_ID */
};
/* Get type and config of an iMC counter's read event. */ staticint read_from_imc_dir(char *imc_dir, int count)
{ char cas_count_cfg[1024], imc_counter_cfg[1024], imc_counter_type[1024];
FILE *fp;
/* Get type of iMC counter */
sprintf(imc_counter_type, "%s%s", imc_dir, "type");
fp = fopen(imc_counter_type, "r"); if (!fp) {
ksft_perror("Failed to open iMC counter type file");
return -1;
} if (fscanf(fp, "%u", &imc_counters_config[count].type) <= 0) {
ksft_perror("Could not get iMC type");
fclose(fp);
return -1;
}
fclose(fp);
/* Get read config */
sprintf(imc_counter_cfg, "%s%s", imc_dir, READ_FILE_NAME);
fp = fopen(imc_counter_cfg, "r"); if (!fp) {
ksft_perror("Failed to open iMC config file");
return -1;
} if (fscanf(fp, "%1023s", cas_count_cfg) <= 0) {
ksft_perror("Could not get iMC cas count read");
fclose(fp);
fp = fopen(mbm_bw_file, "r"); if (!fp)
ksft_perror("Failed to open total memory bandwidth file");
return fp;
}
/* *GetMBMLocalbytesasreportedbyresctrlFS
*/ staticint get_mem_bw_resctrl(FILE *fp, unsignedlong *mbm_total)
{ if (fscanf(fp, "%lu\n", mbm_total) <= 0) {
ksft_perror("Could not get MBM local bytes"); return -1;
} return0;
}
static pid_t bm_pid;
void ctrlc_handler(int signum, siginfo_t *info, void *ptr)
{ /* Only kill child after bm_pid is set after fork() */ if (bm_pid)
kill(bm_pid, SIGKILL);
umount_resctrlfs(); if (current_test && current_test->cleanup)
current_test->cleanup();
ksft_print_msg("Ending\n\n");
exit(EXIT_SUCCESS);
}
/* *RegisterCTRL-Chandlerforparent,asithastokill *childprocessbeforeexiting.
*/ int signal_handler_register(conststruct resctrl_test *test)
{ struct sigaction sigact = {}; int ret = 0;
/* *resctrl_val:executebenchmarkandmeasurememorybandwidthon *thebenchmark *@test:testinformationstructure *@uparams:usersuppliedparameters *@param:parameterspassedtoresctrl_val() * *Return:0whenthetestwasrun,<0onerror.
*/ int resctrl_val(conststruct resctrl_test *test, conststruct user_params *uparams, struct resctrl_val_param *param)
{ unsignedchar *buf = NULL;
cpu_set_t old_affinity; int domain_id; int ret = 0;
pid_t ppid;
if (strcmp(param->filename, "") == 0)
sprintf(param->filename, "stdio");
ret = get_domain_id(test->resource, uparams->cpu, &domain_id); if (ret < 0) {
ksft_print_msg("Could not get domain ID\n"); return ret;
}
ppid = getpid();
/* Taskset test to specified CPU. */
ret = taskset_benchmark(ppid, uparams->cpu, &old_affinity); if (ret) return ret;
/* Write test to specified control & monitoring group in resctrl FS. */
ret = write_bm_pid_to_resctrl(ppid, param->ctrlgrp, param->mongrp); if (ret) goto reset_affinity;
if (param->init) {
ret = param->init(param, domain_id); if (ret) goto reset_affinity;
}
/* *Ifnotrunninguserprovidedbenchmark,runthedefault *"fill_buf".Firstphaseof"fill_buf"istopreparethe *bufferthatthebenchmarkwilloperateon.Nomeasurements *areneededduringthisphaseandpreparedmemorywillbe *passedtonextpartofbenchmarkviacopy-on-writethus *noimpactonthebenchmarkthatreliesonreadingfrom *memoryonly.
*/ if (param->fill_buf) {
buf = alloc_buffer(param->fill_buf->buf_size,
param->fill_buf->memflush); if (!buf) {
ret = -ENOMEM; goto reset_affinity;
}
}
fflush(stdout);
bm_pid = fork(); if (bm_pid == -1) {
ret = -errno;
ksft_perror("Unable to fork"); goto free_buf;
}
/* Give benchmark enough time to fully run. */
sleep(1);
/* Test runs until the callback setup() tells the test to stop. */ while (1) {
ret = param->setup(test, uparams, param); if (ret == END_OF_TESTS) {
ret = 0; break;
} if (ret < 0) break;
ret = param->measure(uparams, param, bm_pid); if (ret) break;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.16Bemerkung:
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.