|
|||
Prex Home / Browse Source - Prex Version: 0.9.0 |
|||
root/usr/sample/bench/bench.c/* [<][>][^][v][top][bottom][index][help] */DEFINITIONSThis source file includes following definitions.1 /* 2 * Copyright (c) 2005-2007, Kohsuke Ohtani 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the author nor the names of any co-contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 /* 31 * bench.c - benchmark program for running many threads 32 */ 33 34 /* 35 * Note: The system must have enough memory to run this program. 36 * At least, 512M bytes of RAM is required to create 100000 threads 37 * with x86-pc. 38 */ 39 40 #include <sys/prex.h> 41 #include <stdio.h> 42 43 /* 44 * Number of threads 45 */ 46 #define NR_THREADS 10000 47 48 static thread_t *thread; 49 50 void 51 null_thread(void) 52 { 53 for (;;) ; 54 } 55 56 int 57 main(int argc, char *argv[]) 58 { 59 struct timerinfo info; 60 task_t task; 61 char stack[16]; 62 u_long start, end; 63 int i, pri, error; 64 65 printf("Benchmark to create/terminate %d threads\n", NR_THREADS); 66 67 sys_info(INFO_TIMER, &info); 68 if (info.hz == 0) 69 panic("can not get timer tick rate"); 70 71 thread_getpri(thread_self(), &pri); 72 thread_setpri(thread_self(), pri - 1); 73 74 task = task_self(); 75 error = vm_allocate(task, (void **)&thread, 76 sizeof(thread_t) * NR_THREADS, 1); 77 if (error) 78 panic("vm_allocate is failed"); 79 80 sys_time(&start); 81 82 /* 83 * Create threads 84 */ 85 for (i = 0; i < NR_THREADS; i++) { 86 if (thread_create(task, &thread[i]) != 0) 87 panic("thread_create is failed"); 88 89 if (thread_load(thread[i], null_thread, &stack) != 0) 90 panic("thread_load is failed"); 91 92 if (thread_resume(thread[i]) != 0) 93 panic("thread_resume is failed"); 94 } 95 96 /* 97 * Teminate threads 98 */ 99 for (i = 0; i < NR_THREADS; i++) 100 thread_terminate(thread[i]); 101 102 sys_time(&end); 103 104 vm_free(task, thread); 105 106 printf("Complete. The score is %d msec (%d ticks).\n", 107 (int)((end - start) * 1000 / info.hz), 108 (int)(end - start)); 109 110 return 0; 111 } /* [<][>][^][v][top][bottom][index][help] */ | |||
Copyright© 2005-2009 Kohsuke Ohtani |