Changeset a35b458 in mainline for uspace/app/rcubench/rcubench.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/rcubench/rcubench.c
r3061bc1 ra35b458 61 61 size_t nthreads; 62 62 futex_t done_threads; 63 63 64 64 futex_t bench_fut; 65 65 } bench_t; … … 72 72 const size_t iters = bench->iters; 73 73 int val = 0; 74 74 75 75 for (size_t i = 0; i < iters; ++i) { 76 76 __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &val); … … 83 83 const size_t iters = bench->iters; 84 84 futex_t loc_fut = FUTEX_INITIALIZER; 85 85 86 86 for (size_t i = 0; i < iters; ++i) { 87 87 futex_lock(&loc_fut); … … 96 96 const size_t iters = bench->iters; 97 97 futex_t loc_fut = FUTEX_INITIALIZER; 98 98 99 99 for (size_t i = 0; i < iters; ++i) { 100 100 futex_down(&loc_fut); … … 108 108 { 109 109 bench_t *bench = (bench_t*)arg; 110 110 111 111 bench->func(bench); 112 112 113 113 /* Signal another thread completed. */ 114 114 futex_up(&bench->done_threads); … … 118 118 { 119 119 assert(1 <= bench->nthreads); 120 120 121 121 if (2 <= bench->nthreads) { 122 122 printf("Creating %zu additional threads...\n", bench->nthreads - 1); 123 123 } 124 124 125 125 /* Create and run the first nthreads - 1 threads.*/ 126 126 for (size_t k = 1; k < bench->nthreads; ++k) { … … 134 134 thread_detach(tid); 135 135 } 136 136 137 137 /* 138 138 * Run the last thread in place so that we create multiple threads … … 141 141 */ 142 142 thread_func(bench); 143 143 144 144 printf("Waiting for remaining threads to complete.\n"); 145 145 146 146 /* Wait for threads to complete. */ 147 147 for (size_t k = 0; k < bench->nthreads; ++k) { … … 168 168 { 169 169 va_list args; 170 170 171 171 va_start(args, fmt); 172 172 vfprintf(results_fd, fmt, args); 173 173 va_end(args); 174 174 175 175 va_start(args, fmt); 176 176 vprintf(fmt, args); … … 202 202 203 203 futex_initialize(&bench->bench_fut, 1); 204 204 205 205 if (0 == str_cmp(argv[1], "sys-futex")) { 206 206 bench->func = kernel_futex_bench; … … 213 213 return false; 214 214 } 215 215 216 216 bench->name = argv[1]; 217 217 218 218 /* Determine iteration count. */ 219 219 uint32_t iter_cnt = 0; … … 226 226 return false; 227 227 } 228 228 229 229 /* Determine thread count. */ 230 230 uint32_t thread_cnt = 0; … … 237 237 return false; 238 238 } 239 239 240 240 return true; 241 241 } … … 245 245 const char *err = "(error)"; 246 246 bench_t bench; 247 247 248 248 futex_initialize(&bench.done_threads, 0); 249 249 250 250 if (!parse_cmd_line(argc, argv, &bench, &err)) { 251 251 printf("%s\n", err); … … 253 253 return -1; 254 254 } 255 255 256 256 open_results(); 257 257 258 258 print_res("Running '%s' futex bench in '%zu' threads with '%zu' iterations.\n", 259 259 bench.name, bench.nthreads, bench.iters); 260 260 261 261 struct timeval start, end; 262 262 getuptime(&start); 263 263 264 264 run_threads_and_wait(&bench); 265 265 266 266 getuptime(&end); 267 267 int64_t duration = tv_sub_diff(&end, &start); 268 268 269 269 uint64_t secs = (uint64_t)duration / 1000 / 1000; 270 270 uint64_t total_iters = (uint64_t)bench.iters * bench.nthreads; 271 271 uint64_t iters_per_sec = 0; 272 272 273 273 if (0 < duration) { 274 274 iters_per_sec = total_iters * 1000 * 1000 / duration; 275 275 } 276 276 277 277 print_res("Completed %" PRIu64 " iterations in %" PRId64 " usecs (%" PRIu64 278 278 " secs); %" PRIu64 " iters/sec\n", … … 280 280 281 281 close_results(); 282 282 283 283 return 0; 284 284 }
Note:
See TracChangeset
for help on using the changeset viewer.