X-Git-Url: https://rtime.felk.cvut.cz/gitweb/jailhouse.git/blobdiff_plain/8ba81622ba531c71a25b965b999f9f13e1b8112b..1a0880cb726cf46e2d7c311b034090ae6e92771f:/inmates/demos/x86/Membench.c diff --git a/inmates/demos/x86/Membench.c b/inmates/demos/x86/Membench.c index 021030d..4366a30 100644 --- a/inmates/demos/x86/Membench.c +++ b/inmates/demos/x86/Membench.c @@ -30,7 +30,11 @@ CMDLINE_BUFFER(CMDLINE_BUFFER_SIZE); //-----Time-and-and-randomization-overrides------------------------------- static inline unsigned long time(unsigned long * seconds) { - return (*seconds) = tsc_read(); + u64 time_sec = tsc_read(); + if (seconds != NULL){ + (*seconds) = time_sec; + } + return time_sec; } /* @@ -76,6 +80,7 @@ static void srand(unsigned int seed) static inline void __assert(const char *msg, const char *file, int line) { printk("Assertion %s in %s:%s failed.\n", msg, file, line); + exit(-1); } //-END:-Assertion-overrides------------------------------------------------- @@ -163,7 +168,11 @@ struct s { _Static_assert(sizeof(struct s) == 64, "Struct size differs from cacheline size"); +#ifdef JAILHOUSE +#define MAX_CPUS 1 +#else #define MAX_CPUS 8 +#endif #ifdef __aarch64__ #define MRS32(reg) ({ uint32_t v; asm volatile ("mrs %0," # reg : "=r" (v)); v; }) @@ -232,9 +241,10 @@ static void prepare(struct s *array, unsigned size, bool sequential) int count = size / sizeof(struct s); if (sequential) { - for (i = 0; i < count - 1; i++) - array[i].ptr = &array[i+1]; - array[count - 1].ptr = &array[0]; + for (i = 0; i < count - 1; i++){ + array[i].ptr = &array[i+1]; + } + array[count - 1].ptr = &array[0]; } else { memset(array, 0, size); struct s *p = &array[0]; @@ -332,14 +342,17 @@ static void do_write(struct s *array, unsigned accesses, unsigned ofs) struct benchmark_thread { pthread_t id; unsigned cpu; - double result; + uint64_t result_integral; + uint64_t result_fractional; struct cfg *cfg; }; pthread_barrier_t barrier; - +#ifdef JAILHOUSE +struct s array[MAX_CPUS][64*0x100000/sizeof(struct s)] __attribute__ ((aligned (2*1024*1024))) __attribute__ ((section (".bench-array"))); +#else struct s array[MAX_CPUS][64*0x100000/sizeof(struct s)] __attribute__ ((aligned (2*1024*1024))); - +#endif bool print = true; static void *benchmark_thread(void *arg) @@ -348,31 +361,31 @@ static void *benchmark_thread(void *arg) cpu_set_t set; CPU_ZERO(&set); - CPU_SET(me->cpu, &set); + CPU_SET(me->cpu, &set); if (pthread_setaffinity_np(me->id, sizeof(set), &set) != 0) { perror("pthread_setaffinity_np"); exit(1); } - prepare(array[me->cpu], me->cfg->size, me->cfg->sequential); - - pthread_barrier_wait(&barrier); + prepare(array[me->cpu], me->cfg->size, me->cfg->sequential); - if (print) - printf("CPU %d starts measurement\n", me->cpu); + pthread_barrier_wait(&barrier); - uint64_t tic, tac; - tic = get_time(me->cfg); - if (me->cfg->write == false) - do_read(array[me->cpu], me->cfg->read_count); - else - do_write(array[me->cpu], me->cfg->read_count, me->cfg->ofs); + if (print) + printf("CPU %d starts measurement\n", me->cpu); - tac = get_time(me->cfg); - me->result = (double)(tac - tic) / me->cfg->read_count; + uint64_t tic, tac; + tic = get_time(me->cfg); + if (me->cfg->write == false) + do_read(array[me->cpu], me->cfg->read_count); + else + do_write(array[me->cpu], me->cfg->read_count, me->cfg->ofs); - return NULL; + tac = get_time(me->cfg); + me->result_integral = (tac - tic) / me->cfg->read_count; + me->result_fractional = (((tac - tic) * 1000) / me->cfg->read_count) % 1000; + return NULL; } static void run_benchmark(struct cfg *cfg) @@ -407,7 +420,9 @@ static void run_benchmark(struct cfg *cfg) printf("%d", cfg->size); for (i = 0; i < cfg->num_threads; i++) { - printf("\t%#.3g", thread[i].result); + //NOTE: Jailhouse is not able to print doubles. + //printf("\t%#.3g", thread[i].result); + printf("\t%lu.%03u", thread[i].result_integral, thread[i].result_fractional); } printf("\n"); fflush(stdout); @@ -427,24 +442,25 @@ int main(int argc, char *argv[]) .read_count = 0x2000000, .write = false, .ofs = 0, - .use_cycles = false, /* i.e. use nanoseconds */ + .use_cycles = false, // i.e. use nanoseconds / }; - #ifdef JAILHOUSE //initialize UART unsigned long tsc_freq; unsigned int n; - printk_uart_base = UART_BASE; do { for (n = 0; n < UART_IDLE_LOOPS; n++) if (!(inb(UART_BASE + UART_LSR) & UART_LSR_THRE)) break; } while (n < UART_IDLE_LOOPS); + + printk("cmdline opts: '%s'\n", cmdline); + comm_region->pm_timer_address = 0x408; //parse cmdline cfg.read_count = cmdline_parse_int("-c", cfg.read_count); cfg.ofs = cmdline_parse_int("-o", cfg.ofs); - cfg.sequential = cmdline_parse_bool("-r"); + cfg.sequential = !cmdline_parse_bool("-r"); cfg.size = cmdline_parse_int("-s", cfg.size); if (cmdline_parse_bool("-t")) { printk("Threads are not supported. '-t' was ignored.\n"); @@ -458,6 +474,16 @@ int main(int argc, char *argv[]) tsc_freq = tsc_init(); printk("Calibrated TSC frequency: %lu.%03u kHz\n", tsc_freq / 1000, tsc_freq % 1000); + + u8 * start_memreg = (u8 *) array; + + while ( ((u64) start_memreg )< 0x4000000) { + //printk("%p\n",start_memreg); + map_range(start_memreg, HUGE_PAGE_SIZE, MAP_CACHED); + start_memreg += HUGE_PAGE_SIZE; + + } + #else //Linux param's parsing CPU_ZERO(&cfg.cpu_set); @@ -470,7 +496,7 @@ int main(int argc, char *argv[]) case 'o': cfg.ofs = atol(optarg); break; - case 'r': /* random */ + case 'r': // random // cfg.sequential = false; break; case 's': @@ -489,7 +515,7 @@ int main(int argc, char *argv[]) case 'y': cfg.use_cycles = true; break; - default: /* '?' */ + default: // '?' // fprintf(stderr, "Usage: %s ... TODO\n", argv[0]); exit(1); } @@ -509,19 +535,23 @@ int main(int argc, char *argv[]) if (cfg.size != 0) { run_benchmark(&cfg); } else { - unsigned order, size, step; - for (order = 10; order <= 24; order++) { + unsigned order, size, step; + for (order = 10; order <= 24; order++) { for (step = 0; step < 2; step++) { size = 1 << order; if (step == 1) size += size / 2; cfg.size = size; - run_benchmark(&cfg); + run_benchmark(&cfg); } } } + #ifndef JAILHOUSE return 0; +#else + comm_region->cell_state = JAILHOUSE_CELL_SHUT_DOWN; + printk("done!"); #endif }