From 77ff82d0f21f784c3a4bbf129cceae37da73f616 Mon Sep 17 00:00:00 2001 From: tqcq Date: Mon, 21 Oct 2024 03:20:38 +0000 Subject: [PATCH] update --- hammersuite/src/include/params.h | 2 +- hammersuite/src/main.c | 1 - hammersuite/src/params.c | 346 +++++++++++++++---------------- 3 files changed, 172 insertions(+), 177 deletions(-) diff --git a/hammersuite/src/include/params.h b/hammersuite/src/include/params.h index 2409f71..4b19970 100644 --- a/hammersuite/src/include/params.h +++ b/hammersuite/src/include/params.h @@ -19,7 +19,7 @@ #define PATT_LEN 1024 #define AGGR_std 2 -// #define HUGE_YES +#define HUGE_YES typedef struct ProfileParams { uint64_t g_flags = 0; diff --git a/hammersuite/src/main.c b/hammersuite/src/main.c index 981f34f..ee61173 100644 --- a/hammersuite/src/main.c +++ b/hammersuite/src/main.c @@ -89,7 +89,6 @@ main(int argc, char **argv) .size = p->m_size, .align = p->m_align, .flags = p->g_flags & MEM_MASK}; - if (mem.flags & F_ALLOC_HUGE) { mem.flags &= ~F_ALLOC_HUGE; } alloc_buffer(&mem); set_physmap(&mem); diff --git a/hammersuite/src/params.c b/hammersuite/src/params.c index ec78da8..ae8c565 100644 --- a/hammersuite/src/params.c +++ b/hammersuite/src/params.c @@ -19,200 +19,196 @@ #include "include/params.h" #include "include/utils.h" -#include -#include +#include #include -#include -#include +#include #include #include -#include -#include +#include +#include +#include +#include -void print_usage(char *bin_name) +void +print_usage(char *bin_name) { - fprintf(stderr, - "[ HELP ] - Usage ./%s [-h] [-r rounds] [-a aggr] [-o o_file] [-v] [--mem mem_size] [--[huge/HUGE] f_name] [--conf f_name] [--align val] [--off val] [--no-overwrite] [--fuzzing]\n", - bin_name); - fprintf(stderr, "\t-h\t\t\t= this help message\n"); - fprintf(stderr, "\t-v\t\t\t= verbose\n\n"); - fprintf(stderr, "\t-r rounds\t\t= number of rounds per tuple\t\t\t(default: %d)\n", ROUNDS_std); - fprintf(stderr, "\t-a --aggr\t\t= number of aggressors\t\t\t\t(default: %d)\n", AGGR_std); - fprintf(stderr, "\t-o --o_file_prefix\t= prefix for output files\t\t\t(default: %s)\n", O_FILE_std); - fprintf(stderr, "\t--mem mem_size\t\t= allocation size\t\t\t\t(default: %ld)\n", - (uint64_t) ALLOC_SIZE); - fprintf(stderr, "\t--huge f_name\t\t= hugetlbfs entry (1GB if HUGE)\t\t\t(default: %s)\n", - HUGETLB_std); - fprintf(stderr, "\t--conf f_name\t\t= SessionConfig file\t\t\t\t(default: %s)\n", - CONFIG_NAME_std); - fprintf(stderr, "\t--align val\t\t= alignment of the buffer\t\t\t(default: %ld)\n", - (uint64_t) ALIGN_std); - fprintf(stderr, "\t--off val\t\t= offset from first row\t\t\t\t(default: 0)\n"); - fprintf(stderr, "\t--no-overwrite\t\t= don't overwrite previous file\n"); - fprintf(stderr, "\t-V --victim-pattern\t= hex value for the victim patter\n"); - fprintf(stderr, "\t-T --target-pattern\t= hex value for the target pattern\n"); - fprintf(stderr, "\t-f --fuzzing\t\t= Start fuzzing (--aggr will be ignored)\n"); - fprintf(stderr, "\t-t --threshold\t\t= Align the hammering to refresh ops,\n\t\t\t\t looking at the memory latency in CPU cycles.\t(default: 0)\n"); + fprintf(stderr, + "[ HELP ] - Usage ./%s [-h] [-r rounds] [-a aggr] [-o o_file] [-v] [--mem mem_size] [--[huge/HUGE] f_name] " + "[--conf f_name] [--align val] [--off val] [--no-overwrite] [--fuzzing]\n", + bin_name); + fprintf(stderr, "\t-h\t\t\t= this help message\n"); + fprintf(stderr, "\t-v\t\t\t= verbose\n\n"); + fprintf(stderr, "\t-r rounds\t\t= number of rounds per tuple\t\t\t(default: %d)\n", ROUNDS_std); + fprintf(stderr, "\t-a --aggr\t\t= number of aggressors\t\t\t\t(default: %d)\n", AGGR_std); + fprintf(stderr, "\t-o --o_file_prefix\t= prefix for output files\t\t\t(default: %s)\n", O_FILE_std); + fprintf(stderr, "\t--mem mem_size\t\t= allocation size\t\t\t\t(default: %ld)\n", (uint64_t) ALLOC_SIZE); + fprintf(stderr, "\t--huge f_name\t\t= hugetlbfs entry (1GB if HUGE)\t\t\t(default: %s)\n", HUGETLB_std); + fprintf(stderr, "\t--conf f_name\t\t= SessionConfig file\t\t\t\t(default: %s)\n", CONFIG_NAME_std); + fprintf(stderr, "\t--align val\t\t= alignment of the buffer\t\t\t(default: %ld)\n", (uint64_t) ALIGN_std); + fprintf(stderr, "\t--off val\t\t= offset from first row\t\t\t\t(default: 0)\n"); + fprintf(stderr, "\t--no-overwrite\t\t= don't overwrite previous file\n"); + fprintf(stderr, "\t-V --victim-pattern\t= hex value for the victim patter\n"); + fprintf(stderr, "\t-T --target-pattern\t= hex value for the target pattern\n"); + fprintf(stderr, "\t-f --fuzzing\t\t= Start fuzzing (--aggr will be ignored)\n"); + fprintf(stderr, + "\t-t --threshold\t\t= Align the hammering to refresh ops,\n\t\t\t\t looking at the memory latency in CPU " + "cycles.\t(default: 0)\n"); } -static int str2pat(const char *str, char **pat) +static int +str2pat(const char *str, char **pat) { - char *endp = NULL; - char tmp[3]; - char *p; - tmp[2] = '\0'; - size_t len = strlen(str); - if (len % 2) { - return EINVAL; - } - len /= 2; + char *endp = NULL; + char tmp[3]; + char *p; + tmp[2] = '\0'; + size_t len = strlen(str); + if (len % 2) { return EINVAL; } + len /= 2; - p = (char *)malloc(len); - for (size_t i = 0; i < len; i++) { - tmp[0] = str[2 * i]; - tmp[1] = str[2 * i + 1]; - errno = 0; - ((uint8_t *) p)[i] = (uint8_t) strtol(tmp, &endp, 16); - if (errno) { - free(p); - return errno; - } - if (*endp != '\0') { - free(p); - return EINVAL; - } - } - *pat = p; - return 0; + p = (char *) malloc(len); + for (size_t i = 0; i < len; i++) { + tmp[0] = str[2 * i]; + tmp[1] = str[2 * i + 1]; + errno = 0; + ((uint8_t *) p)[i] = (uint8_t) strtol(tmp, &endp, 16); + if (errno) { + free(p); + return errno; + } + if (*endp != '\0') { + free(p); + return EINVAL; + } + } + *pat = p; + return 0; } -int process_argv(int argc, char *argv[], ProfileParams *p) +int +process_argv(int argc, char *argv[], ProfileParams *p) { - /* Default */ - p->g_flags = 0; - p->tpat = (char *)NULL; - p->vpat = (char *)NULL; - p->threshold = 0; - p->fuzzing = 0; // start fuzzing!! - p->m_size = ALLOC_SIZE; - p->m_align = ALIGN_std; - p->rounds = ROUNDS_std; - p->base_off = 0; - p->huge_file = (char *)HUGETLB_std; - p->conf_file = (char *)CONFIG_NAME_std; - p->aggr = AGGR_std; + /* Default */ + p->g_flags = 0; + p->tpat = (char *) NULL; + p->vpat = (char *) NULL; + p->threshold = 0; + p->fuzzing = 0;// start fuzzing!! + p->m_size = ALLOC_SIZE; + p->m_align = ALIGN_std; + p->rounds = ROUNDS_std; + p->base_off = 0; + p->huge_file = (char *) HUGETLB_std; + p->conf_file = (char *) CONFIG_NAME_std; + p->aggr = AGGR_std; + const struct option long_options[] = { + /* These options set a flag. */ + {"mem", required_argument, 0, 0 }, + {"align", required_argument, 0, 0 }, + {"huge", optional_argument, 0, 0 }, + {"HUGE", optional_argument, 0, 0 }, + {"conf", optional_argument, 0, 0 }, + {"off", required_argument, 0, 0 }, + {"no-overwrite", no_argument, 0, 0 }, + {.name = "target-pattern", .has_arg = required_argument, .flag = NULL, .val = 'T'}, + {.name = "victim-pattern", .has_arg = required_argument, .flag = NULL, .val = 'V'}, + {.name = "aggr", .has_arg = required_argument, .flag = NULL, .val = 'a'}, + {.name = "fuzzing", .has_arg = no_argument, .flag = &p->fuzzing, .val = 1 }, + {.name = "threshold", .has_arg = required_argument, .flag = NULL, .val = 't'}, + {0, 0, 0, 0 } + }; - const struct option long_options[] = { - /* These options set a flag. */ - {"mem", required_argument, 0, 0}, - {"align", required_argument, 0, 0}, - {"huge", optional_argument, 0, 0}, - {"HUGE", optional_argument, 0, 0}, - {"conf", optional_argument, 0, 0}, - {"off", required_argument, 0, 0}, - {"no-overwrite", no_argument, 0, 0}, - {.name = "target-pattern",.has_arg = required_argument,.flag = NULL,.val='T'}, - {.name = "victim-pattern",.has_arg = required_argument,.flag = NULL,.val = 'V'}, - {.name = "aggr",.has_arg = required_argument,.flag = NULL,.val='a'}, - {.name = "fuzzing",.has_arg = no_argument,.flag = &p->fuzzing,.val = 1}, - {.name = "threshold",.has_arg = required_argument,.flag = NULL,.val = 't'}, - {0, 0, 0, 0} - }; + p->g_out_prefix = (char *) O_FILE_std; + p->g_flags |= F_POPULATE; - p->g_out_prefix = (char *)O_FILE_std; - p->g_flags |= F_POPULATE; + while (1) { + int this_option_optind = optind ? optind : 1; + int option_index = 0; + int arg = getopt_long(argc, argv, "o:d:r:hvV:T:a:ft:", long_options, &option_index); - while (1) { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - int arg = getopt_long(argc, argv, "o:d:r:hvV:T:a:ft:", - long_options, &option_index); + if (arg == -1) break; - if (arg == -1) - break; - - switch (arg) { - case 0: - switch (option_index) { - case 0: - p->m_size = atoi(optarg); - break; - case 1: - p->m_align = atoi(optarg); - break; - case 2: - p->g_flags |= F_ALLOC_HUGE_2M; - case 3: - p->huge_file = (char *)malloc(sizeof(char) * strlen(optarg)); - strncpy(p->huge_file, optarg, strlen(optarg)); - p->g_flags |= F_ALLOC_HUGE_1G; - break; - case 4: - p->g_flags |= F_CONFIG; - if (!optarg) - break; - p->conf_file = (char *)malloc(sizeof(char) * strlen(optarg)); - strncpy(p->conf_file, optarg, strlen(optarg)); - break; - case 5: - p->base_off = atoi(optarg); - break; - case 6: - p->g_flags |= F_NO_OVERWRITE; - break; - default: - break; - } - break; - case 'o': - p->g_out_prefix = (char *)malloc(sizeof(char) * strlen(optarg)); - strncpy(p->g_out_prefix, optarg, strlen(optarg)); - p->g_flags |= F_EXPORT; - break; - case 'r': - p->rounds = atoi(optarg); - break; - case 'v': - p->g_flags |= F_VERBOSE; - break; - case 'a': - p->aggr = atoi(optarg); - break; - case 'T': - if (str2pat(optarg, &(p->vpat))) { - fprintf(stderr, "Invalid target fill pattern: %s\n", optarg); - return -1; - } - break; - case 'V': - if (str2pat(optarg, &(p->tpat))) { - fprintf(stderr, "Invalid victim fill pattern: %s\n", optarg); - return -1; - } - break; - case 'f': - p->fuzzing = 1; - break; - case 't': - p->threshold = atoi(optarg); - break; - case 'h': - default: - print_usage(argv[0]); - return -1; - } - } + switch (arg) { + case 0: + switch (option_index) { + case 0: + p->m_size = atoi(optarg); + break; + case 1: + p->m_align = atoi(optarg); + break; + case 2: + p->g_flags |= F_ALLOC_HUGE_2M; + case 3: + p->huge_file = (char *) malloc(sizeof(char) * strlen(optarg)); + strncpy(p->huge_file, optarg, strlen(optarg)); + p->g_flags |= F_ALLOC_HUGE_1G; + break; + case 4: + p->g_flags |= F_CONFIG; + if (!optarg) break; + p->conf_file = (char *) malloc(sizeof(char) * strlen(optarg)); + strncpy(p->conf_file, optarg, strlen(optarg)); + break; + case 5: + p->base_off = atoi(optarg); + break; + case 6: + p->g_flags |= F_NO_OVERWRITE; + break; + default: + break; + } + break; + case 'o': + p->g_out_prefix = (char *) malloc(sizeof(char) * strlen(optarg)); + strncpy(p->g_out_prefix, optarg, strlen(optarg)); + p->g_flags |= F_EXPORT; + break; + case 'r': + p->rounds = atoi(optarg); + break; + case 'v': + p->g_flags |= F_VERBOSE; + break; + case 'a': + p->aggr = atoi(optarg); + break; + case 'T': + if (str2pat(optarg, &(p->vpat))) { + fprintf(stderr, "Invalid target fill pattern: %s\n", optarg); + return -1; + } + break; + case 'V': + if (str2pat(optarg, &(p->tpat))) { + fprintf(stderr, "Invalid victim fill pattern: %s\n", optarg); + return -1; + } + break; + case 'f': + p->fuzzing = 1; + break; + case 't': + p->threshold = atoi(optarg); + break; + case 'h': + default: + print_usage(argv[0]); + return -1; + } + } #ifdef HUGE_YES - p->g_flags |= F_ALLOC_HUGE_1G; + p->g_flags |= F_ALLOC_HUGE_1G; #endif - if (p->g_flags & (F_ALLOC_HUGE_2M | F_ALLOC_HUGE_1G)) { - if ((p->huge_fd = open(p->huge_file, O_CREAT | O_RDWR, 0755)) == -1) { - perror("[ERROR] - Unable to open hugetlbfs"); - return -1; - } - } - return 0; + if (p->g_flags & (F_ALLOC_HUGE_2M | F_ALLOC_HUGE_1G)) { + if ((p->huge_fd = open(p->huge_file, O_CREAT | O_RDWR, 0755)) == -1) { + perror("[ERROR] - Unable to open hugetlbfs"); + return -1; + } + } + return 0; }