[BACK]Return to bench.c CVS log [TXT][DIR] Up to [local] / prex-old / usr / sample / bench

Annotation of prex-old/usr/sample/bench/bench.c, Revision 1.1.1.1

1.1       nbrk        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 i386-pc.
                     38:  */
                     39:
                     40: #include <prex/prex.h>
                     41: #include <stdio.h>
                     42:
                     43: /*
                     44:  * Number of threads
                     45:  */
                     46: #define NR_THREADS 100000
                     47:
                     48: static thread_t *th;
                     49:
                     50: void
                     51: null_thread(void)
                     52: {
                     53:        for (;;) ;
                     54: }
                     55:
                     56: int
                     57: main(int argc, char *argv[])
                     58: {
                     59:        struct info_timer info;
                     60:        task_t task;
                     61:        char stack[16];
                     62:        u_long start, end;
                     63:        int i, prio, err;
                     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_getprio(thread_self(), &prio);
                     72:        thread_setprio(thread_self(), prio - 1);
                     73:
                     74:        task = task_self();
                     75:        err = vm_allocate(task, (void **)&th, sizeof(thread_t) * NR_THREADS, 1);
                     76:        if (err)
                     77:                panic("vm_allocate is failed");
                     78:
                     79:        sys_time(&start);
                     80:
                     81:        /*
                     82:         * Create threads
                     83:         */
                     84:        for (i = 0; i < NR_THREADS; i++) {
                     85:                if (thread_create(task, &th[i]) != 0)
                     86:                        panic("thread_create is failed");
                     87:
                     88:                if (thread_load(th[i], null_thread, &stack) != 0)
                     89:                        panic("thread_load is failed");
                     90:
                     91:                if (thread_resume(th[i]) != 0)
                     92:                        panic("thread_resume is failed");
                     93:        }
                     94:
                     95:        /*
                     96:         * Teminate threads
                     97:         */
                     98:        for (i = 0; i < NR_THREADS; i++)
                     99:                thread_terminate(th[i]);
                    100:
                    101:        sys_time(&end);
                    102:
                    103:        vm_free(task, th);
                    104:
                    105:        printf("Complete. The score is %d msec (%d ticks).\n",
                    106:               (int)((end - start) * 1000 / info.hz),
                    107:               (int)(end - start));
                    108:
                    109:        return 0;
                    110: }

CVSweb