1/* 2 * Copyright (c) 2009, 2010, 2011, ETH Zurich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#include <stdlib.h> 11#include <stdio.h> 12#include <assert.h> 13#include <stdint.h> 14#include <omp.h> 15#include <arch/x86/barrelfish_kpi/asm_inlines_arch.h> 16#include <barrelfish/barrelfish.h> 17#include <string.h> 18 19#undef GANG_SCHEDULING 20 21#define PERIOD 2500000000UL 22#define STACK_SIZE (64 * 1024) 23#define ITERATIONS 120 24 25extern uint64_t stuck[64]; 26static uint64_t workcnt[32][ITERATIONS]; 27 28int main(int argc, char *argv[]) 29{ 30 int nthreads = omp_get_max_threads(); 31 32 if(argc == 2) { 33 nthreads = atoi(argv[1]); 34 backend_span_domain(nthreads, STACK_SIZE); 35 bomp_custom_init(NULL); 36 omp_set_num_threads(nthreads); 37 } 38 39 printf("threads %d, CPUs %d\n", nthreads, omp_get_num_procs()); 40 41 volatile uint64_t exittime[ITERATIONS] = { 0 }; 42 43 // Do some work 44#pragma omp parallel 45 { 46#ifdef GANG_SCHEDULING 47 bomp_synchronize(); 48#endif 49 for(int i = 0; i < ITERATIONS; i++) { 50 uint64_t start = rdtsc(); 51 uint64_t workcn = 0; 52 53 for(uint64_t n = 0;; n++) { 54#pragma omp barrier 55 workcn++; 56 57 if(omp_get_thread_num() == 0 && exittime[i] == 0 58 && rdtsc() >= start + PERIOD) { 59 exittime[i] = n + 3; 60 } 61 62 if(exittime[i] != 0 && exittime[i] == n) { 63 n++; 64 break; 65 } 66 } 67 68 /* char buf[64]; */ 69 /* sprintf(buf, "%d: %lu(%lu)\n", omp_get_thread_num(), workcn, */ 70 /* stuck[omp_get_thread_num()]); */ 71 /* sys_print(buf, strlen(buf)); */ 72 /* stuck[omp_get_thread_num()] = 0; */ 73 workcnt[omp_get_thread_num()][i] = workcn; 74 } 75 } 76 77 char buf[64]; 78 for(int i = 0; i < ITERATIONS; i++) { 79 for(int n = 0; n < nthreads; n++) { 80 sprintf(buf, "%lu ", workcnt[n][i]); 81 sys_print(buf, strlen(buf)); 82 } 83 sys_print("\n", 1); 84 } 85 86 /* sys_print("\n", 1); */ 87 88 /* char buf[128], buf1[128]; */ 89 /* sprintf(buf, "iterations in %lu ticks: ", PERIOD); */ 90 /* for(int i = 0; i < nthreads; i++) { */ 91 /* sprintf(buf1, "%lu ", workcnt[i]); */ 92 /* strcat(buf, buf1); */ 93 /* } */ 94 /* sprintf(buf1, "\n"); */ 95 /* strcat(buf, buf1); */ 96 /* sys_print(buf, strlen(buf)); */ 97 /* } */ 98 99 for(;;); 100 return 0; 101} 102