├── .hgignore ├── BUGS ├── Makefile ├── Makefile.Aix ├── Makefile.Linux ├── Makefile.SunOS ├── Makefile.benchmarks ├── Makefile.com ├── OPENSOLARIS.LICENSE ├── README ├── atomic.c ├── bench ├── bench.sh ├── benchmark_fini.c ├── benchmark_finibatch.c ├── benchmark_finirun.c ├── benchmark_finiworker.c ├── benchmark_init.c ├── benchmark_initbatch.c ├── benchmark_initrun.c ├── benchmark_initworker.c ├── benchmark_optswitch.c ├── benchmark_result.c ├── bind.c ├── cachetocache.c ├── cascade_cond.c ├── cascade_fcntl.c ├── cascade_flock.c ├── cascade_lockf.c ├── cascade_mutex.c ├── chdir.c ├── close.c ├── close_tcp.c ├── connection.c ├── dup.c ├── elided.c ├── exec.c ├── exec_bin.c ├── exit.c ├── exp.c ├── fcntl.c ├── fcntl_ndelay.c ├── file_lock.c ├── fork.c ├── getcontext.c ├── getenv.c ├── getpeername.c ├── getpid.c ├── getrusage.c ├── getsockname.c ├── gettimeofday.c ├── isatty.c ├── libmicro.c ├── libmicro.h ├── libmicro_main.c ├── listen.c ├── localtime_r.c ├── log.c ├── longjmp.c ├── lrand48.c ├── lseek.c ├── malloc.c ├── memcpy.c ├── memmove.c ├── memrand.c ├── memset.c ├── mk_tarball ├── mktime.c ├── mmap.c ├── mprotect.c ├── msync.c ├── multiview ├── multiview.sh ├── munmap.c ├── mutex.c ├── nop.c ├── open.c ├── pipe.c ├── poll.c ├── pread.c ├── pthread_create.c ├── pwrite.c ├── read.c ├── realpath.c ├── recurse.c ├── recurse2.c ├── select.c ├── semop.c ├── setcontext.c ├── setsockopt.c ├── sigaction.c ├── siglongjmp.c ├── signal.c ├── sigprocmask.c ├── socket.c ├── socketpair.c ├── stat.c ├── strcasecmp.c ├── strchr.c ├── strcmp.c ├── strcpy.c ├── strftime.c ├── strlen.c ├── strtol.c ├── system.c ├── tattle.c ├── time.c ├── times.c ├── wrapper ├── wrapper.sh ├── write.c └── writev.c /.hgignore: -------------------------------------------------------------------------------- 1 | bin-*/ 2 | bench 3 | multiview 4 | wrapper 5 | libMicro.tar 6 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | 2 | BUGS: 3 | 4 | Tests spin on 32 bit x86 compile with gcc-- longjmp test spins forever. 5 | 6 | CPU_NAME is wrong on earlier (than 10) and later (than 10) versions of Solaris 7 | (parsing psrinfo output is fragile) 8 | 9 | TimerRes detection on some Solaris 8 SPARC systems is wrong and falsely 10 | detects resolution as 1nsec 11 | 12 | TODO: 13 | 14 | .o files should probably be separated from generated binaries (obj-sun4u?) 15 | 16 | Move more of the system info data gathering into tattle 17 | 18 | Would be nice to show the platform name (uname -i) if available 19 | 20 | Multiview's "red" can get a little too bright. 21 | 22 | Consider recoding multiview to use a different performance indicator than 23 | color (smileys and bombs?) -- today a 20% perf difference is hard to 24 | spot (it's very very light pink). 25 | 26 | FreeBSD ports collection has patches to make libmicro work on FreeBSD. 27 | Fold those in (or reimplement) 28 | http://portsmon.freebsd.org/portoverview.py?category=benchmarks&portname=libmicro 29 | 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # CDDL HEADER START 3 | # 4 | # The contents of this file are subject to the terms 5 | # of the Common Development and Distribution License 6 | # (the "License"). You may not use this file except 7 | # in compliance with the License. 8 | # 9 | # You can obtain a copy of the license at 10 | # src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL 16 | # HEADER in each file and include the License file at 17 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | # add the following below this CDDL HEADER, with the 19 | # fields enclosed by brackets "[]" replaced with your 20 | # own identifying information: Portions Copyright [yyyy] 21 | # [name of copyright owner] 22 | # 23 | # CDDL HEADER END 24 | # 25 | 26 | # 27 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | # Use is subject to license terms. 29 | # 30 | 31 | 32 | include Makefile.benchmarks 33 | 34 | BINS= $(ALL:%=bin/%) bin/tattle 35 | 36 | TARBALL_CONTENTS = \ 37 | Makefile.benchmarks \ 38 | Makefile.SunOS \ 39 | Makefile.Linux \ 40 | Makefile.Aix \ 41 | Makefile.com \ 42 | Makefile \ 43 | $(ALL:%=%.c) \ 44 | elided.c \ 45 | exec_bin.c \ 46 | libmicro.c \ 47 | libmicro_main.c \ 48 | libmicro.h \ 49 | recurse2.c \ 50 | benchmark_finibatch.c \ 51 | benchmark_initbatch.c \ 52 | benchmark_optswitch.c \ 53 | benchmark_fini.c \ 54 | benchmark_init.c \ 55 | benchmark_result.c \ 56 | benchmark_finirun.c \ 57 | benchmark_initrun.c \ 58 | benchmark_initworker.c \ 59 | benchmark_finiworker.c \ 60 | bench \ 61 | bench.sh \ 62 | mk_tarball \ 63 | multiview \ 64 | multiview.sh \ 65 | OPENSOLARIS.LICENSE \ 66 | tattle.c \ 67 | wrapper \ 68 | wrapper.sh \ 69 | README 70 | 71 | default $(ALL) run cstyle lint tattle: $(BINS) 72 | @cp bench.sh bench 73 | @cp multiview.sh multiview 74 | @cp wrapper.sh wrapper 75 | @chmod +x bench multiview wrapper 76 | @mkdir -p bin-`uname -m`; cd bin-`uname -m`; MACH=`uname -m` $(MAKE) -f ../Makefile.`uname -s` UNAME_RELEASE=`uname -r | sed 's/\./_/g'` $@ 77 | 78 | clean: 79 | rm -rf bin bin-* wrapper multiview bench 80 | 81 | bin: 82 | @mkdir -p bin 83 | 84 | $(BINS): bin 85 | @cp wrapper.sh wrapper 86 | @chmod +x wrapper 87 | @ln -sf ../wrapper $@ 88 | 89 | 90 | libMicro.tar: FORCE 91 | @chmod +x ./mk_tarball wrapper 92 | @./mk_tarball $(TARBALL_CONTENTS) 93 | 94 | FORCE: 95 | 96 | -------------------------------------------------------------------------------- /Makefile.Aix: -------------------------------------------------------------------------------- 1 | # 2 | # CDDL HEADER START 3 | # 4 | # The contents of this file are subject to the terms 5 | # of the Common Development and Distribution License 6 | # (the "License"). You may not use this file except 7 | # in compliance with the License. 8 | # 9 | # You can obtain a copy of the license at 10 | # src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL 16 | # HEADER in each file and include the License file at 17 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | # add the following below this CDDL HEADER, with the 19 | # fields enclosed by brackets "[]" replaced with your 20 | # own identifying information: Portions Copyright [yyyy] 21 | # [name of copyright owner] 22 | # 23 | # CDDL HEADER END 24 | # 25 | 26 | # 27 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | # Use is subject to license terms. 29 | # 30 | 31 | 32 | CFLAGS= -O3 33 | 34 | CPPFLAGS = -D_REENTRANT 35 | 36 | include ../Makefile.com 37 | 38 | NSLLIB= -lnsl 39 | SOCKLIB= 40 | 41 | .KEEP_STATE: 42 | -------------------------------------------------------------------------------- /Makefile.Linux: -------------------------------------------------------------------------------- 1 | # 2 | # CDDL HEADER START 3 | # 4 | # The contents of this file are subject to the terms 5 | # of the Common Development and Distribution License 6 | # (the "License"). You may not use this file except 7 | # in compliance with the License. 8 | # 9 | # You can obtain a copy of the license at 10 | # src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL 16 | # HEADER in each file and include the License file at 17 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | # add the following below this CDDL HEADER, with the 19 | # fields enclosed by brackets "[]" replaced with your 20 | # own identifying information: Portions Copyright [yyyy] 21 | # [name of copyright owner] 22 | # 23 | # CDDL HEADER END 24 | # 25 | 26 | # 27 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | # Use is subject to license terms. 29 | # 30 | 31 | 32 | CC= gcc 33 | 34 | #CFLAGS= -O -DUSE_SEMOP 35 | CPPFLAGS= -DUSE_SEMOP -D_REENTRANT 36 | MATHLIB= -lm 37 | 38 | ELIDED_BENCHMARKS= \ 39 | cachetocache \ 40 | atomic 41 | 42 | 43 | include ../Makefile.com 44 | -------------------------------------------------------------------------------- /Makefile.SunOS: -------------------------------------------------------------------------------- 1 | # 2 | # CDDL HEADER START 3 | # 4 | # The contents of this file are subject to the terms 5 | # of the Common Development and Distribution License 6 | # (the "License"). You may not use this file except 7 | # in compliance with the License. 8 | # 9 | # You can obtain a copy of the license at 10 | # src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL 16 | # HEADER in each file and include the License file at 17 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | # add the following below this CDDL HEADER, with the 19 | # fields enclosed by brackets "[]" replaced with your 20 | # own identifying information: Portions Copyright [yyyy] 21 | # [name of copyright owner] 22 | # 23 | # CDDL HEADER END 24 | # 25 | 26 | # 27 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | # Use is subject to license terms. 29 | # 30 | 31 | 32 | CPPFLAGS= -DUSE_GETHRTIME -D_REENTRANT 33 | 34 | CFLAGS = -O $(extra_CFLAGS) 35 | 36 | # 37 | # These defines allow libmicro to be compiled against older Solaris 38 | # releases by turning off the tests which don't work there. 39 | # 40 | # This is a little contorted-- UNAME_RELEASE is set as an environment 41 | # variable for us by the invoking make process (see Makefile)-- it is 42 | # the output of uname -r | sed 's/\./_/g'. 43 | # 44 | # We couldn't find any other gmake/unix make portable way to make this 45 | # work. 46 | # 47 | ELIDED_BENCHMARKS_5_8=atomic cachetocache 48 | ELIDED_BENCHMARKS_5_9=atomic 49 | 50 | ELIDED_BENCHMARKS_CMN=cascade_flock 51 | 52 | ELIDED_BENCHMARKS=$(ELIDED_BENCHMARKS_CMN) $(ELIDED_BENCHMARKS_$(UNAME_RELEASE)) 53 | 54 | include ../Makefile.com 55 | 56 | NSLLIB= -lnsl 57 | SOCKLIB= -lsocket 58 | UCBLIB= -lc -L/usr/ucblib -lucb -R/usr/ucblib 59 | MATHLIB= -lm 60 | 61 | .KEEP_STATE: 62 | -------------------------------------------------------------------------------- /Makefile.benchmarks: -------------------------------------------------------------------------------- 1 | # 2 | # CDDL HEADER START 3 | # 4 | # The contents of this file are subject to the terms 5 | # of the Common Development and Distribution License 6 | # (the "License"). You may not use this file except 7 | # in compliance with the License. 8 | # 9 | # You can obtain a copy of the license at 10 | # src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL 16 | # HEADER in each file and include the License file at 17 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | # add the following below this CDDL HEADER, with the 19 | # fields enclosed by brackets "[]" replaced with your 20 | # own identifying information: Portions Copyright [yyyy] 21 | # [name of copyright owner] 22 | # 23 | # CDDL HEADER END 24 | # 25 | 26 | # 27 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | # Use is subject to license terms. 29 | # 30 | 31 | 32 | ALL= \ 33 | atomic \ 34 | bind \ 35 | cachetocache \ 36 | cascade_mutex \ 37 | cascade_cond \ 38 | cascade_lockf \ 39 | cascade_fcntl \ 40 | cascade_flock \ 41 | chdir \ 42 | close \ 43 | close_tcp \ 44 | connection \ 45 | dup \ 46 | exec \ 47 | exit \ 48 | exp \ 49 | fcntl \ 50 | fcntl_ndelay \ 51 | file_lock \ 52 | fork \ 53 | getcontext \ 54 | getenv \ 55 | gettimeofday \ 56 | getpeername \ 57 | getpid \ 58 | getrusage \ 59 | getsockname \ 60 | isatty \ 61 | listen \ 62 | localtime_r \ 63 | log \ 64 | longjmp \ 65 | lrand48 \ 66 | lseek \ 67 | malloc \ 68 | memcpy \ 69 | memmove \ 70 | memrand \ 71 | memset \ 72 | mktime \ 73 | mprotect \ 74 | mmap \ 75 | msync \ 76 | munmap \ 77 | mutex \ 78 | nop \ 79 | open \ 80 | pipe \ 81 | poll \ 82 | pread \ 83 | pthread_create \ 84 | pwrite \ 85 | read \ 86 | realpath \ 87 | recurse \ 88 | select \ 89 | semop \ 90 | setcontext \ 91 | setsockopt \ 92 | sigaction \ 93 | siglongjmp \ 94 | signal \ 95 | sigprocmask \ 96 | socket \ 97 | socketpair \ 98 | stat \ 99 | strcasecmp \ 100 | strchr \ 101 | strcmp \ 102 | strcpy \ 103 | strftime \ 104 | strlen \ 105 | strtol \ 106 | system \ 107 | time \ 108 | times \ 109 | write \ 110 | writev 111 | 112 | 113 | -------------------------------------------------------------------------------- /Makefile.com: -------------------------------------------------------------------------------- 1 | # 2 | # CDDL HEADER START 3 | # 4 | # The contents of this file are subject to the terms 5 | # of the Common Development and Distribution License 6 | # (the "License"). You may not use this file except 7 | # in compliance with the License. 8 | # 9 | # You can obtain a copy of the license at 10 | # src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL 16 | # HEADER in each file and include the License file at 17 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | # add the following below this CDDL HEADER, with the 19 | # fields enclosed by brackets "[]" replaced with your 20 | # own identifying information: Portions Copyright [yyyy] 21 | # [name of copyright owner] 22 | # 23 | # CDDL HEADER END 24 | # 25 | 26 | # 27 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | # Use is subject to license terms. 29 | # 30 | 31 | include ../Makefile.benchmarks 32 | 33 | EXTRA_CFILES= \ 34 | exec_bin.c \ 35 | elided.c \ 36 | tattle.c 37 | 38 | # 39 | # some definitions to make getting compiler versions possible - avoid quotes 40 | # 41 | COMPILER_VERSION_CMD_cc=cc -V 2>&1 | egrep Sun 42 | COMPILER_VERSION_CMD_gcc=gcc -dumpversion 43 | COMPILER_VERSION_CMD=$(COMPILER_VERSION_CMD_$(CC)) 44 | 45 | default: $(ALL) tattle 46 | 47 | cstyle: 48 | for file in $(ALL:%=../%.c) $(EXTRA_CFILES:%=../%) ; \ 49 | do cstyle -p $$file ;\ 50 | done 51 | 52 | 53 | lint: libmicro.ln $(ALL:%=%.lint) $(EXTRA_CFILES:%.c=%.lint) 54 | 55 | 56 | $(EXTRA_CFILES:%.c=%.lint): 57 | $(LINT) ../$(@:%.lint=%.c) -I. -mu -lc libmicro.ln -lm 58 | 59 | %.lint: ../%.c libmicro.ln 60 | $(LINT) -mu $(CPPFLAGS) $< libmicro.ln -lpthread -lsocket -lnsl -lm 61 | 62 | %.o: ../%.c 63 | $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ 64 | 65 | libmicro.ln: ../libmicro.c ../libmicro_main.c ../libmicro.h ../benchmark_*.c 66 | $(LINT) -muc $(CPPFLAGS) ../libmicro.c ../libmicro_main.c ../benchmark_*.c 67 | 68 | CPPFLAGS+= -D_REENTRANT 69 | 70 | bind_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) 71 | cascade_flock_EXTRA_LIBS=$(UCBLIB) 72 | close_tcp_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) 73 | connection_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) 74 | fcntl_ndelay_EXTRA_LIBS=$(SOCKLIB) 75 | getpeername_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) 76 | getsockname_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) 77 | listen_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) 78 | log_EXTRA_LIBS=$(MATHLIB) 79 | pipe_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) 80 | poll_EXTRA_LIBS=$(SOCKLIB) 81 | select_EXTRA_LIBS=$(SOCKLIB) 82 | setsockopt_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) 83 | socket_EXTRA_LIBS=$(SOCKLIB) 84 | socketpair_EXTRA_LIBS=$(SOCKLIB) 85 | 86 | BENCHMARK_FUNCS= \ 87 | benchmark_init.o \ 88 | benchmark_fini.o \ 89 | benchmark_initrun.o \ 90 | benchmark_finirun.o \ 91 | benchmark_initbatch.o \ 92 | benchmark_finibatch.o \ 93 | benchmark_initworker.o \ 94 | benchmark_finiworker.o \ 95 | benchmark_optswitch.o \ 96 | benchmark_result.o 97 | 98 | recurse_EXTRA_DEPS=recurse2.o 99 | 100 | 101 | recurse: $(recurse_EXTRA_DEPS) 102 | 103 | libmicro.a: libmicro.o libmicro_main.o $(BENCHMARK_FUNCS) 104 | $(AR) -cr libmicro.a libmicro.o libmicro_main.o $(BENCHMARK_FUNCS) 105 | 106 | tattle: ../tattle.c libmicro.a 107 | echo "char * compiler_version = \""`$(COMPILER_VERSION_CMD)`"\";" > tattle.h 108 | echo "char * CC = \""$(CC)"\";" >> tattle.h 109 | echo "char * extra_compiler_flags = \""$(extra_CFLAGS)"\";" >> tattle.h 110 | $(CC) -o tattle $(CFLAGS) -I. ../tattle.c libmicro.a -lrt -lm 111 | 112 | $(ELIDED_BENCHMARKS): ../elided.c 113 | $(CC) -o $(@) ../elided.c 114 | 115 | %: libmicro.a %.o 116 | $(CC) -o $(@) $(@).o $($(@)_EXTRA_DEPS) $(CFLAGS) libmicro.a $($(@)_EXTRA_LIBS) $(EXTRA_LIBS) -lpthread -lm 117 | 118 | exec: exec_bin 119 | 120 | exec_bin: exec_bin.o 121 | $(CC) -o exec_bin $(CFLAGS) exec_bin.o 122 | 123 | FORCE: 124 | 125 | 126 | ._KEEP_STATE: 127 | 128 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | # 2 | # CDDL HEADER START 3 | # 4 | # The contents of this file are subject to the terms 5 | # of the Common Development and Distribution License 6 | # (the "License"). You may not use this file except 7 | # in compliance with the License. 8 | # 9 | # You can obtain a copy of the license at 10 | # src/OPENSOLARIS.LICENSE 11 | # or http://www.opensolaris.org/os/licensing. 12 | # See the License for the specific language governing 13 | # permissions and limitations under the License. 14 | # 15 | # When distributing Covered Code, include this CDDL 16 | # HEADER in each file and include the License file at 17 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | # add the following below this CDDL HEADER, with the 19 | # fields enclosed by brackets "[]" replaced with your 20 | # own identifying information: Portions Copyright [yyyy] 21 | # [name of copyright owner] 22 | # 23 | # CDDL HEADER END 24 | # 25 | 26 | # 27 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | # Use is subject to license terms. 29 | # 30 | 31 | Building the tarball 32 | -------------------- 33 | As long as cc is in your path, (gcc on Linux), 34 | 35 | % tar xf libMicro.tar 36 | % make 37 | 38 | will build the benchmark suite. 39 | 40 | Running the benchmarks 41 | ----------------------- 42 | 43 | A set of generic scripts to invoke each micro benchmark 44 | are created in the bin directory; these may be invoked 45 | directly. Note that the actual binaries are created in 46 | OS-specific directories; this allows one to build for 47 | all varients (x86/sparc/Solaris/Linux) in one place. 48 | 49 | To collect a complete set of benchmarks, use the bench 50 | script and redirect its output to a file. 51 | 52 | % ./bench > output 53 | 54 | To compare the output of two or more runs, use multiview in the src 55 | directory: 56 | 57 | % ./multiview reference compare1 compare2 compare2 > compare.html 58 | % 59 | 60 | where the reference and compare files contain the output of different 61 | libmicro runs. 62 | 63 | The compare.html file will allow quick comparisons to be drawn, 64 | allowing a variety of experiments to be quickly analyzed. 65 | 66 | All benchmarks support the following options: 67 | 68 | [-1] (single process; overrides -P > 1) 69 | [-A] (align with clock) 70 | [-B batch-size (default 10)] 71 | [-C minimum number of samples (default 0)] 72 | [-D duration in msecs (default 10s)] 73 | [-E (echo name to stderr)] 74 | [-H] (suppress headers) 75 | [-I] specify approx. time per op in nsecs 76 | [-L] (print argument line) 77 | [-M] (reports mean rather than median) 78 | [-N test-name ] 79 | [-P processes (default 1)] 80 | [-S] (print detailed stats) 81 | [-T threads (default 1)] 82 | [-V] (print the libMicro version and exit) 83 | [-W] (flag possible benchmark problems) 84 | 85 | 86 | -------------------------------------------------------------------------------- /atomic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * benchmarks atomic add on Solaris - useful for platform comparisons. 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "note: measures atomic_add_32_nv()"); 46 | 47 | lm_tsdsize = 0; 48 | 49 | return (0); 50 | } 51 | 52 | static unsigned int value = 0; 53 | 54 | /*ARGSUSED*/ 55 | int 56 | benchmark(void *tsd, result_t *res) 57 | { 58 | unsigned int i; 59 | for (i = 0; i < lm_optB; i += 10) { 60 | (void) atomic_add_32_nv(&value, 1); 61 | (void) atomic_add_32_nv(&value, 1); 62 | (void) atomic_add_32_nv(&value, 1); 63 | (void) atomic_add_32_nv(&value, 1); 64 | (void) atomic_add_32_nv(&value, 1); 65 | (void) atomic_add_32_nv(&value, 1); 66 | (void) atomic_add_32_nv(&value, 1); 67 | (void) atomic_add_32_nv(&value, 1); 68 | (void) atomic_add_32_nv(&value, 1); 69 | (void) atomic_add_32_nv(&value, 1); 70 | } 71 | res->re_count = i; 72 | 73 | return (0); 74 | } 75 | -------------------------------------------------------------------------------- /benchmark_fini.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_fini 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_fini() 44 | { 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /benchmark_finibatch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_finibatch 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | /*ARGSUSED*/ 42 | int 43 | benchmark_finibatch(void *tsd) 44 | { 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /benchmark_finirun.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_finirun 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | int 42 | benchmark_finirun() 43 | { 44 | return (0); 45 | } 46 | -------------------------------------------------------------------------------- /benchmark_finiworker.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_finiworker 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | /*ARGSUSED*/ 42 | int 43 | benchmark_finiworker(void *tsd) 44 | { 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /benchmark_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_init 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /benchmark_initbatch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_initbatch 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | /*ARGSUSED*/ 43 | int 44 | benchmark_initbatch(void *tsd) 45 | { 46 | return (0); 47 | } 48 | -------------------------------------------------------------------------------- /benchmark_initrun.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_initrun 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | int 42 | benchmark_initrun() 43 | { 44 | return (0); 45 | } 46 | -------------------------------------------------------------------------------- /benchmark_initworker.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_initworker 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | /*ARGSUSED*/ 42 | int 43 | benchmark_initworker(void *tsd) 44 | { 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /benchmark_optswitch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_optswitch 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | /*ARGSUSED*/ 42 | int 43 | benchmark_optswitch(int opt, char *optarg) 44 | { 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /benchmark_result.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * default implementation (nop) of benchmark_result 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | char * 42 | benchmark_result() 43 | { 44 | static char result = '\0'; 45 | 46 | return (&result); 47 | } 48 | -------------------------------------------------------------------------------- /bind.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * benchmark for bind... keep in mind tcp hash chain effects 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "libmicro.h" 49 | 50 | #define FIRSTPORT 12345 51 | 52 | typedef struct { 53 | int *ts_lsns; 54 | struct sockaddr_in *ts_adds; 55 | } tsd_t; 56 | 57 | static int optz = -0; 58 | 59 | int 60 | benchmark_init() 61 | { 62 | lm_tsdsize = sizeof (tsd_t); 63 | 64 | lm_defB = 256; 65 | (void) sprintf(lm_optstr, "z"); 66 | 67 | (void) sprintf(lm_usage, 68 | " [-z bind to port 0 rather than seq. number\n" 69 | "notes: measures bind() on TCP"); 70 | 71 | return (0); 72 | } 73 | 74 | int 75 | benchmark_initrun() 76 | { 77 | (void) setfdlimit(lm_optB * lm_optT + 10); 78 | 79 | return (0); 80 | } 81 | 82 | /*ARGSUSED*/ 83 | int 84 | benchmark_optswitch(int opt, char *optarg) 85 | { 86 | switch (opt) { 87 | case 'z': 88 | optz = 1; 89 | break; 90 | default: 91 | return (-1); 92 | } 93 | return (0); 94 | } 95 | 96 | int 97 | benchmark_initbatch(void *tsd) 98 | { 99 | tsd_t *ts = (tsd_t *)tsd; 100 | int i, j; 101 | int opt = 1; 102 | struct hostent *host; 103 | int errors = 0; 104 | 105 | ts->ts_lsns = (int *)malloc(lm_optB * sizeof (int)); 106 | if (ts->ts_lsns == NULL) 107 | errors ++; 108 | 109 | ts->ts_adds = (struct sockaddr_in *)malloc(lm_optB * 110 | sizeof (struct sockaddr_in)); 111 | if (ts->ts_adds == NULL) 112 | errors ++; 113 | 114 | j = FIRSTPORT; 115 | for (i = 0; i < lm_optB; i++) { 116 | if ((ts->ts_lsns[i] = socket(PF_INET, SOCK_STREAM, 0)) == -1) 117 | errors ++; 118 | 119 | if (setsockopt(ts->ts_lsns[i], SOL_SOCKET, SO_REUSEADDR, 120 | &opt, sizeof (int)) == -1) 121 | errors ++; 122 | 123 | if ((host = gethostbyname("localhost")) == NULL) 124 | errors ++; 125 | 126 | (void) memset(&ts->ts_adds[i], 0, 127 | sizeof (struct sockaddr_in)); 128 | ts->ts_adds[i].sin_family = AF_INET; 129 | ts->ts_adds[i].sin_port = (optz ? 0 : htons(j++)); 130 | (void) memcpy(&ts->ts_adds[i].sin_addr.s_addr, 131 | host->h_addr_list[0], sizeof (struct in_addr)); 132 | } 133 | return (errors); 134 | } 135 | 136 | int 137 | benchmark(void *tsd, result_t *res) 138 | { 139 | tsd_t *ts = (tsd_t *)tsd; 140 | int i; 141 | 142 | for (i = 0; i < lm_optB; i++) { 143 | if ((bind(ts->ts_lsns[i], 144 | (struct sockaddr *)&ts->ts_adds[i], 145 | sizeof (struct sockaddr_in)) != 0) && 146 | (errno != EADDRINUSE)) 147 | res->re_errors ++; 148 | } 149 | res->re_count = i; 150 | 151 | return (0); 152 | } 153 | 154 | int 155 | benchmark_finibatch(void *tsd) 156 | { 157 | tsd_t *ts = (tsd_t *)tsd; 158 | int i; 159 | 160 | for (i = 0; i < lm_optB; i++) 161 | (void) close(ts->ts_lsns[i]); 162 | return (0); 163 | } 164 | -------------------------------------------------------------------------------- /chdir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * change directory benchmark 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | #define DEFAULTDIR "/" 42 | #define MAXPATHLEN 1024 43 | 44 | static int optg = 0; 45 | 46 | static int dircount; 47 | static char ** dirlist; 48 | 49 | int 50 | benchmark_init() 51 | { 52 | (void) sprintf(lm_optstr, "g"); 53 | lm_tsdsize = 0; 54 | 55 | (void) sprintf(lm_usage, 56 | " [-g] (do getcwd() also)\n" 57 | " directory ... (default = %s)\n" 58 | "notes: measures chdir() and (optionally) getcwd()", 59 | DEFAULTDIR); 60 | 61 | (void) sprintf(lm_header, "%5s %5s", "dirs", "gets"); 62 | 63 | return (0); 64 | } 65 | 66 | /*ARGSUSED*/ 67 | int 68 | benchmark_optswitch(int opt, char *optarg) 69 | { 70 | switch (opt) { 71 | case 'g': 72 | optg = 1; 73 | break; 74 | default: 75 | return (-1); 76 | } 77 | return (0); 78 | } 79 | 80 | int 81 | benchmark_initrun() 82 | { 83 | extern int optind; 84 | int i; 85 | 86 | dircount = lm_argc - optind; 87 | if (dircount <= 0) { 88 | dirlist = (char **)malloc(sizeof (char *)); 89 | dirlist[0] = DEFAULTDIR; 90 | dircount = 1; 91 | } else { 92 | dirlist = (char **)malloc(dircount * sizeof (char *)); 93 | for (i = 0; i < dircount; i++) { 94 | dirlist[i] = lm_argv[optind++]; 95 | } 96 | } 97 | 98 | return (0); 99 | } 100 | 101 | /*ARGSUSED*/ 102 | int 103 | benchmark(void *tsd, result_t *res) 104 | { 105 | int i, j; 106 | char buf[MAXPATHLEN]; 107 | 108 | j = 0; 109 | for (i = 0; i < lm_optB; i++) { 110 | if (chdir(dirlist[j]) == -1) 111 | res->re_errors++; 112 | j++; 113 | j %= dircount; 114 | 115 | if (optg && (getcwd(buf, MAXPATHLEN) == NULL)) { 116 | res->re_errors++; 117 | } 118 | } 119 | res->re_count = i; 120 | 121 | return (0); 122 | } 123 | 124 | char * 125 | benchmark_result() 126 | { 127 | static char result[256]; 128 | 129 | (void) sprintf(result, "%5d %5s", dircount, optg ? "y" : "n"); 130 | 131 | return (result); 132 | } 133 | -------------------------------------------------------------------------------- /close.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * benchmark for close 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | #define DEFF "/dev/null" 43 | static char *optf = DEFF; 44 | static int optb = 0; 45 | 46 | typedef struct { 47 | int *ts_fds; 48 | } tsd_t; 49 | 50 | int 51 | benchmark_init() 52 | { 53 | lm_tsdsize = sizeof (tsd_t); 54 | 55 | lm_defB = 256; 56 | 57 | (void) sprintf(lm_optstr, "f:b"); 58 | 59 | (void) sprintf(lm_usage, 60 | " [-f file-to-close (default %s)]\n" 61 | " [-b] (try to close an unopened fd)\n" 62 | "notes: measures close()", 63 | DEFF); 64 | 65 | return (0); 66 | } 67 | 68 | int 69 | benchmark_optswitch(int opt, char *optarg) 70 | { 71 | switch (opt) { 72 | case 'f': 73 | optf = optarg; 74 | break; 75 | case 'b': 76 | optb = 1; 77 | break; 78 | default: 79 | return (-1); 80 | } 81 | 82 | return (0); 83 | } 84 | 85 | int 86 | benchmark_initrun() 87 | { 88 | (void) setfdlimit(lm_optB * lm_optT + 10); 89 | 90 | return (0); 91 | } 92 | 93 | int 94 | benchmark_initworker(void *tsd) 95 | { 96 | tsd_t *ts = (tsd_t *)tsd; 97 | 98 | ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); 99 | if (ts->ts_fds == NULL) { 100 | return (1); 101 | } 102 | return (0); 103 | } 104 | 105 | /* 106 | * don't need a finiworker; we're exiting anyway 107 | */ 108 | 109 | int 110 | benchmark_initbatch(void *tsd) 111 | { 112 | tsd_t *ts = (tsd_t *)tsd; 113 | int i; 114 | int errors = 0; 115 | 116 | for (i = 0; i < lm_optB; i++) { 117 | ts->ts_fds[i] = ((optb == 0) ? 118 | open(optf, O_RDONLY) : i + 1024); 119 | if (ts->ts_fds[i] == -1) { 120 | errors++; 121 | } 122 | } 123 | 124 | return (errors); 125 | } 126 | 127 | int 128 | benchmark(void *tsd, result_t *res) 129 | { 130 | tsd_t *ts = (tsd_t *)tsd; 131 | int i; 132 | 133 | for (i = 0; i < lm_optB; i++) { 134 | if (close(ts->ts_fds[i]) == -1 && !optb) { 135 | res->re_errors++; 136 | } 137 | } 138 | res->re_count = i; 139 | 140 | return (0); 141 | } 142 | -------------------------------------------------------------------------------- /dup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * time dup 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | #define DEFF "/dev/null" 43 | static char *optf = DEFF; 44 | 45 | static int fd; 46 | 47 | typedef struct { 48 | int ts_once; 49 | int *ts_fds; 50 | } tsd_t; 51 | 52 | int 53 | benchmark_init() 54 | { 55 | lm_tsdsize = sizeof (tsd_t); 56 | 57 | lm_defB = 256; 58 | 59 | (void) sprintf(lm_optstr, "f:"); 60 | 61 | (void) sprintf(lm_usage, 62 | " [-f file-to-dup (default %s)]\n" 63 | "notes: measures dup()\n", 64 | DEFF); 65 | 66 | return (0); 67 | } 68 | 69 | int 70 | benchmark_optswitch(int opt, char *optarg) 71 | { 72 | switch (opt) { 73 | case 'f': 74 | optf = optarg; 75 | break; 76 | default: 77 | return (-1); 78 | } 79 | return (0); 80 | } 81 | 82 | int 83 | benchmark_initrun() 84 | { 85 | (void) setfdlimit(lm_optB * lm_optT + 10); 86 | fd = (open(optf, O_RDONLY)); 87 | 88 | return (0); 89 | } 90 | 91 | int 92 | benchmark_initbatch(void *tsd) 93 | { 94 | tsd_t *ts = (tsd_t *)tsd; 95 | int i; 96 | int errors = 0; 97 | 98 | if (ts->ts_once++ == 0) { 99 | ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); 100 | if (ts->ts_fds == NULL) { 101 | errors ++; 102 | } 103 | for (i = 0; i < lm_optB; i++) { 104 | ts->ts_fds[i] = -1; 105 | } 106 | } 107 | 108 | return (errors); 109 | } 110 | 111 | int 112 | benchmark(void *tsd, result_t *res) 113 | { 114 | tsd_t *ts = (tsd_t *)tsd; 115 | int i; 116 | 117 | for (i = 0; i < lm_optB; i++) { 118 | ts->ts_fds[i] = dup(fd); 119 | if (ts->ts_fds[i] == -1) { 120 | res->re_errors++; 121 | } 122 | } 123 | res->re_count = i; 124 | 125 | return (0); 126 | } 127 | 128 | int 129 | benchmark_finibatch(void *tsd) 130 | { 131 | tsd_t *ts = (tsd_t *)tsd; 132 | int i; 133 | 134 | for (i = 0; i < lm_optB; i++) { 135 | (void) close(ts->ts_fds[i]); 136 | } 137 | 138 | return (0); 139 | } 140 | -------------------------------------------------------------------------------- /elided.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * empty benchmark program to substitute for benchmarks 33 | * that don't work/exist on some platforms 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | /*ARGSUSED*/ 42 | int 43 | main(int argc, char *argv[]) 44 | { 45 | char *tmp = strrchr(argv[0], '/'); 46 | 47 | if (tmp == NULL) 48 | tmp = argv[0]; 49 | else 50 | tmp++; 51 | 52 | (void) printf( 53 | "#\n" 54 | "# benchmark %s not compiled/supported on this platform\n" 55 | "#\n", 56 | tmp); 57 | 58 | return (0); 59 | } 60 | -------------------------------------------------------------------------------- /exec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * exec benchmark 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | static char exec_path[1024]; 44 | static char *argv[3]; 45 | 46 | int 47 | benchmark_init() 48 | { 49 | lm_defB = 128; 50 | lm_tsdsize = 0; 51 | 52 | (void) sprintf(lm_usage, 53 | "notes: measures execv time of simple process()\n"); 54 | 55 | return (0); 56 | } 57 | 58 | /*ARGSUSED*/ 59 | int 60 | benchmark_initbatch(void *tsd) 61 | { 62 | char buffer[80]; 63 | 64 | (void) strcpy(exec_path, lm_procpath); 65 | (void) strcat(exec_path, "/exec_bin"); 66 | 67 | (void) sprintf(buffer, "%d", lm_optB); 68 | argv[0] = exec_path; 69 | argv[1] = strdup(buffer); 70 | argv[2] = NULL; 71 | 72 | return (0); 73 | } 74 | 75 | /*ARGSUSED*/ 76 | int 77 | benchmark(void *tsd, result_t *res) 78 | { 79 | int c; 80 | int status; 81 | 82 | switch (c = fork()) { 83 | case -1: 84 | res->re_errors++; 85 | break; 86 | default: 87 | if (waitpid(c, &status, 0) < 0) 88 | res->re_errors++; 89 | 90 | if (WIFEXITED(status) && WEXITSTATUS(status) != 0) 91 | res->re_errors++; 92 | break; 93 | case 0: 94 | if (execv(exec_path, argv) < 0) 95 | res->re_errors++; 96 | } 97 | 98 | res->re_count = lm_optB; 99 | 100 | return (0); 101 | } 102 | -------------------------------------------------------------------------------- /exec_bin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * time program to recursively test exec time 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | int 41 | main(int argc, char *argv[]) 42 | { 43 | int left; 44 | 45 | if (argc == 1) { 46 | exit(1); 47 | } 48 | 49 | left = atoi(argv[1]); 50 | 51 | left--; 52 | 53 | if (left <= 0) { 54 | exit(0); 55 | } else { 56 | char buffer[80]; 57 | (void) sprintf(buffer, "%d", left); 58 | argv[1] = buffer; 59 | if (execv(argv[0], argv)) { 60 | exit(2); 61 | } 62 | } 63 | 64 | return (0); 65 | } 66 | -------------------------------------------------------------------------------- /exit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * benchmark exit 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | typedef struct { 44 | int ts_once; 45 | int *ts_pids; 46 | } tsd_t; 47 | 48 | static int opte = 0; 49 | static barrier_t *b; 50 | 51 | int 52 | benchmark_init() 53 | { 54 | lm_tsdsize = sizeof (tsd_t); 55 | (void) sprintf(lm_optstr, "e"); 56 | 57 | (void) sprintf(lm_usage, 58 | " [-e] (uses _exit() rather than exit())" 59 | "notes: measures exit()\n"); 60 | 61 | return (0); 62 | } 63 | 64 | /*ARGSUSED*/ 65 | int 66 | benchmark_optswitch(int opt, char *optarg) 67 | { 68 | switch (opt) { 69 | case 'e': 70 | opte = 1; 71 | break; 72 | default: 73 | return (-1); 74 | } 75 | return (0); 76 | } 77 | 78 | int 79 | benchmark_initrun() 80 | { 81 | b = barrier_create(lm_optP * lm_optT * (lm_optB + 1), 0); 82 | 83 | return (0); 84 | } 85 | 86 | int 87 | benchmark_finirun() 88 | { 89 | (void) barrier_destroy(b); 90 | 91 | return (0); 92 | } 93 | 94 | int 95 | benchmark_initbatch(void *tsd) 96 | { 97 | tsd_t *ts = (tsd_t *)tsd; 98 | int i; 99 | int errors = 0; 100 | 101 | if (ts->ts_once++ == 0) { 102 | ts->ts_pids = (int *)malloc(lm_optB * sizeof (pid_t)); 103 | if (ts->ts_pids == NULL) { 104 | errors ++; 105 | } 106 | } 107 | 108 | /* 109 | * create processes to exit 110 | */ 111 | 112 | for (i = 0; i < lm_optB; i++) { 113 | ts->ts_pids[i] = fork(); 114 | switch (ts->ts_pids[i]) { 115 | case 0: 116 | (void) barrier_queue(b, NULL); 117 | if (opte) 118 | _exit(0); 119 | exit(0); 120 | break; 121 | case -1: 122 | errors ++; 123 | break; 124 | default: 125 | continue; 126 | } 127 | } 128 | 129 | return (errors); 130 | } 131 | 132 | /*ARGSUSED*/ 133 | int 134 | benchmark(void *tsd, result_t *res) 135 | { 136 | int i; 137 | 138 | /* 139 | * start them all exiting 140 | */ 141 | 142 | (void) barrier_queue(b, NULL); 143 | 144 | /* 145 | * wait for them all to exit 146 | */ 147 | 148 | for (i = 0; i < lm_optB; i++) { 149 | switch (waitpid((pid_t)-1, NULL, 0)) { 150 | case 0: 151 | continue; 152 | case -1: 153 | res->re_errors++; 154 | } 155 | } 156 | 157 | res->re_count = i; 158 | 159 | return (0); 160 | } 161 | -------------------------------------------------------------------------------- /exp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * test exp performance (should add range check) 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "note: measures exp()"); 46 | lm_nsecs_per_op = 25; 47 | lm_tsdsize = 0; 48 | return (0); 49 | } 50 | 51 | /*ARGSUSED*/ 52 | int 53 | benchmark(void *tsd, result_t *res) 54 | { 55 | int i; 56 | 57 | for (i = 0; i < lm_optB; i += 10) { 58 | double value = 1.0 / (i + .01); 59 | (void) exp(value); 60 | (void) exp(value); 61 | (void) exp(value); 62 | (void) exp(value); 63 | (void) exp(value); 64 | (void) exp(value); 65 | (void) exp(value); 66 | (void) exp(value); 67 | (void) exp(value); 68 | (void) exp(value); 69 | } 70 | res->re_count = i; 71 | 72 | return (0); 73 | } 74 | -------------------------------------------------------------------------------- /fcntl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * benchmark fcntl getfl 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | #define DEFF "/dev/null" 44 | 45 | static char *optf = DEFF; 46 | static int fd = -1; 47 | 48 | int 49 | benchmark_init() 50 | { 51 | (void) sprintf(lm_optstr, "f:"); 52 | lm_tsdsize = 0; 53 | 54 | (void) sprintf(lm_usage, 55 | " [-f file-to-fcntl (default %s)]\n" 56 | "notes: measures fcntl()\n", 57 | DEFF); 58 | 59 | return (0); 60 | } 61 | 62 | int 63 | benchmark_optswitch(int opt, char *optarg) 64 | { 65 | switch (opt) { 66 | case 'f': 67 | optf = optarg; 68 | break; 69 | default: 70 | return (-1); 71 | } 72 | return (0); 73 | } 74 | 75 | int 76 | benchmark_initrun() 77 | { 78 | if ((fd = open(optf, O_RDONLY)) == -1) { 79 | perror("open"); 80 | exit(1); 81 | } 82 | return (0); 83 | } 84 | 85 | /*ARGSUSED*/ 86 | int 87 | benchmark(void *tsd, result_t *res) 88 | { 89 | int i; 90 | int flags; 91 | 92 | for (i = 0; i < lm_optB; i++) { 93 | if (fcntl(fd, F_GETFL, &flags) == -1) 94 | res->re_errors++; 95 | } 96 | res->re_count = i; 97 | 98 | return (0); 99 | } 100 | -------------------------------------------------------------------------------- /fcntl_ndelay.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * measures O_NDELAY on socket 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "libmicro.h" 49 | 50 | static int fd = -1; 51 | 52 | int 53 | benchmark_init() 54 | { 55 | (void) sprintf(lm_usage, 56 | "notes: measures F_GETFL/F_SETFL O_NDELAY on socket\n"); 57 | 58 | lm_tsdsize = 0; 59 | 60 | return (0); 61 | } 62 | 63 | int 64 | benchmark_initrun() 65 | { 66 | fd = socket(AF_INET, SOCK_STREAM, 0); 67 | if (fd == -1) { 68 | perror("socket"); 69 | exit(1); 70 | } 71 | 72 | return (0); 73 | } 74 | 75 | /*ARGSUSED*/ 76 | int 77 | benchmark(void *tsd, result_t *res) 78 | { 79 | int i; 80 | int flags; 81 | 82 | for (i = 0; i < lm_optB; i += 4) { 83 | if (fcntl(fd, F_GETFL, &flags) < 0) 84 | res->re_errors++; 85 | flags |= O_NDELAY; 86 | 87 | if (fcntl(fd, F_SETFL, &flags) < 0) 88 | res->re_errors++; 89 | 90 | if (fcntl(fd, F_GETFL, &flags) < 0) 91 | res->re_errors++; 92 | flags &= ~O_NDELAY; 93 | 94 | if (fcntl(fd, F_SETFL, &flags) < 0) 95 | res->re_errors++; 96 | } 97 | res->re_count = i; 98 | 99 | return (0); 100 | } 101 | -------------------------------------------------------------------------------- /file_lock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * test file locking 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "libmicro.h" 43 | 44 | static int file; 45 | 46 | int 47 | block(int index) 48 | { 49 | struct flock fl; 50 | 51 | fl.l_type = F_WRLCK; 52 | fl.l_whence = SEEK_SET; 53 | fl.l_start = index; 54 | fl.l_len = 1; 55 | return (fcntl(file, F_SETLKW, &fl) == -1); 56 | } 57 | 58 | int 59 | unblock(int index) 60 | { 61 | struct flock fl; 62 | 63 | fl.l_type = F_UNLCK; 64 | fl.l_whence = SEEK_SET; 65 | fl.l_start = index; 66 | fl.l_len = 1; 67 | return (fcntl(file, F_SETLK, &fl) == -1); 68 | } 69 | int 70 | benchmark_init() 71 | { 72 | char fname[80]; 73 | int errors = 0; 74 | 75 | (void) sprintf(fname, "/tmp/oneflock.%ld", getpid()); 76 | 77 | file = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600); 78 | 79 | if (file == -1) { 80 | errors++; 81 | } 82 | if (unlink(fname)) { 83 | errors++; 84 | } 85 | 86 | lm_tsdsize = 0; 87 | 88 | return (errors); 89 | } 90 | 91 | /*ARGSUSED*/ 92 | int 93 | benchmark(void *tsd, result_t *res) 94 | { 95 | int i; 96 | int e = 0; 97 | 98 | for (i = 0; i < lm_optB; i ++) { 99 | e += block(0); 100 | e += unblock(0); 101 | } 102 | res->re_count = i; 103 | res->re_errors = e; 104 | 105 | return (0); 106 | } 107 | -------------------------------------------------------------------------------- /fork.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * benchmark fork 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | static barrier_t *b; 44 | 45 | typedef struct { 46 | int ts_once; 47 | int *ts_pids; 48 | } tsd_t; 49 | 50 | int 51 | benchmark_init() 52 | { 53 | lm_tsdsize = sizeof (tsd_t); 54 | (void) sprintf(lm_usage, "notes: measures fork()\n"); 55 | 56 | return (0); 57 | } 58 | 59 | int 60 | benchmark_initrun() 61 | { 62 | b = barrier_create(lm_optP * lm_optT * (lm_optB + 1), 0); 63 | 64 | return (0); 65 | } 66 | 67 | int 68 | benchmark_finirun() 69 | { 70 | (void) barrier_destroy(b); 71 | 72 | return (0); 73 | } 74 | 75 | int 76 | benchmark_initbatch(void *tsd) 77 | { 78 | tsd_t *ts = (tsd_t *)tsd; 79 | int errors = 0; 80 | 81 | if (ts->ts_once++ == 0) { 82 | ts->ts_pids = (int *)malloc(lm_optB * sizeof (pid_t)); 83 | if (ts->ts_pids == NULL) { 84 | errors++; 85 | } 86 | } 87 | 88 | return (errors); 89 | } 90 | 91 | int 92 | benchmark(void *tsd, result_t *res) 93 | { 94 | tsd_t *ts = (tsd_t *)tsd; 95 | int i; 96 | 97 | for (i = 0; i < lm_optB; i++) { 98 | ts->ts_pids[i] = fork(); 99 | switch (ts->ts_pids[i]) { 100 | case 0: 101 | (void) barrier_queue(b, NULL); 102 | exit(0); 103 | break; 104 | case -1: 105 | res->re_errors++; 106 | break; 107 | default: 108 | continue; 109 | } 110 | } 111 | res->re_count = lm_optB; 112 | 113 | (void) barrier_queue(b, NULL); 114 | 115 | return (0); 116 | } 117 | 118 | int 119 | benchmark_finibatch(void *tsd) 120 | { 121 | tsd_t *ts = (tsd_t *)tsd; 122 | int i; 123 | 124 | for (i = 0; i < lm_optB; i++) { 125 | if (ts->ts_pids[i] > 0) { 126 | (void) waitpid(ts->ts_pids[i], NULL, 0); 127 | } 128 | } 129 | 130 | return (0); 131 | } 132 | -------------------------------------------------------------------------------- /getcontext.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * getcontext 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "notes: measures getcontext()\n"); 46 | 47 | lm_tsdsize = 0; 48 | 49 | return (0); 50 | } 51 | 52 | /*ARGSUSED*/ 53 | int 54 | benchmark(void *tsd, result_t *res) 55 | { 56 | int i; 57 | 58 | for (i = 0; i < lm_optB; i += 10) { 59 | ucontext_t uc; 60 | (void) getcontext(&uc); 61 | (void) getcontext(&uc); 62 | (void) getcontext(&uc); 63 | (void) getcontext(&uc); 64 | (void) getcontext(&uc); 65 | (void) getcontext(&uc); 66 | (void) getcontext(&uc); 67 | (void) getcontext(&uc); 68 | (void) getcontext(&uc); 69 | (void) getcontext(&uc); 70 | } 71 | res->re_count = i; 72 | 73 | return (0); 74 | } 75 | -------------------------------------------------------------------------------- /getenv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * test getenv 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | #define DEFS 100 44 | 45 | static int opts = DEFS; 46 | 47 | int 48 | benchmark_init() 49 | { 50 | (void) sprintf(lm_optstr, "s:"); 51 | 52 | lm_tsdsize = 0; 53 | 54 | (void) sprintf(lm_usage, 55 | " [-s search-size (default = %d)]\n" 56 | "notes: measures time to search env for missing string\n", 57 | DEFS); 58 | 59 | lm_nsecs_per_op = 200; 60 | 61 | return (0); 62 | } 63 | 64 | int 65 | benchmark_optswitch(int opt, char *optarg) 66 | { 67 | switch (opt) { 68 | case 's': 69 | opts = atoi(optarg); 70 | break; 71 | default: 72 | return (-1); 73 | } 74 | return (0); 75 | } 76 | 77 | int 78 | benchmark_initrun() 79 | { 80 | extern char ** environ; 81 | int i, j; 82 | 83 | /* count environment strings */ 84 | 85 | for (i = 0; environ[i++]; ) 86 | ; 87 | 88 | /* 89 | * pad to desired count 90 | */ 91 | 92 | if (opts < i) 93 | opts = i; 94 | 95 | for (j = i; j < opts; j++) { 96 | char buf[80]; 97 | (void) sprintf(buf, "VAR_%d=%d", j, j); 98 | (void) putenv(strdup(buf)); 99 | } 100 | 101 | return (0); 102 | } 103 | 104 | /*ARGSUSED*/ 105 | int 106 | benchmark(void *tsd, result_t *res) 107 | { 108 | int i; 109 | char *search = "RUMPLSTILTSKIN"; 110 | 111 | for (i = 0; i < lm_optB; i += 10) { 112 | (void) getenv(search); 113 | (void) getenv(search); 114 | (void) getenv(search); 115 | (void) getenv(search); 116 | (void) getenv(search); 117 | (void) getenv(search); 118 | (void) getenv(search); 119 | (void) getenv(search); 120 | (void) getenv(search); 121 | (void) getenv(search); 122 | } 123 | res->re_count = i; 124 | 125 | return (0); 126 | } 127 | -------------------------------------------------------------------------------- /getpeername.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * getpeername test 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "libmicro.h" 50 | 51 | #define FIRSTPORT 12345 52 | 53 | static int sock = -1; 54 | 55 | int 56 | benchmark_init() 57 | { 58 | (void) sprintf(lm_usage, "notes: measures getpeername()\n"); 59 | lm_tsdsize = 0; 60 | 61 | return (0); 62 | } 63 | 64 | int 65 | benchmark_initrun() 66 | { 67 | int j; 68 | int opt = 1; 69 | int result; 70 | socklen_t size; 71 | struct hostent *host; 72 | struct sockaddr_in adds; 73 | int sock2, sock3; 74 | 75 | sock2 = socket(AF_INET, SOCK_STREAM, 0); 76 | if (sock2 == -1) { 77 | perror("socket"); 78 | exit(1); 79 | } 80 | 81 | if (setsockopt(sock2, SOL_SOCKET, SO_REUSEADDR, 82 | &opt, sizeof (int)) == -1) { 83 | perror("setsockopt"); 84 | exit(1); 85 | } 86 | 87 | if ((host = gethostbyname("localhost")) == NULL) { 88 | perror("gethostbyname"); 89 | exit(1); 90 | } 91 | 92 | j = FIRSTPORT; 93 | for (;;) { 94 | (void) memset(&adds, 0, sizeof (struct sockaddr_in)); 95 | adds.sin_family = AF_INET; 96 | adds.sin_port = htons(j++); 97 | (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0], 98 | sizeof (struct in_addr)); 99 | 100 | if (bind(sock2, (struct sockaddr *)&adds, 101 | sizeof (struct sockaddr_in)) == 0) { 102 | break; 103 | } 104 | 105 | if (errno != EADDRINUSE) { 106 | perror("bind"); 107 | exit(1); 108 | } 109 | } 110 | 111 | if (listen(sock2, 5) == -1) { 112 | perror("listen"); 113 | exit(1); 114 | } 115 | 116 | sock3 = socket(AF_INET, SOCK_STREAM, 0); 117 | if (sock3 == -1) { 118 | perror("socket"); 119 | exit(1); 120 | } 121 | 122 | if (fcntl(sock3, F_SETFL, O_NDELAY) == -1) { 123 | perror("fcntl"); 124 | exit(1); 125 | } 126 | 127 | result = connect(sock3, (struct sockaddr *)&adds, 128 | sizeof (struct sockaddr_in)); 129 | if ((result == -1) && (errno != EINPROGRESS)) { 130 | perror("connect"); 131 | exit(1); 132 | } 133 | 134 | size = sizeof (struct sockaddr); 135 | sock = accept(sock2, (struct sockaddr *)&adds, &size); 136 | if (sock == -1) { 137 | perror("accept"); 138 | exit(1); 139 | } 140 | 141 | return (0); 142 | } 143 | 144 | /*ARGSUSED*/ 145 | int 146 | benchmark(void *tsd, result_t *res) 147 | { 148 | int i; 149 | struct sockaddr_in adds; 150 | socklen_t size; 151 | 152 | for (i = 0; i < lm_optB; i++) { 153 | size = sizeof (struct sockaddr_in); 154 | if (getpeername(sock, (struct sockaddr *)&adds, &size) == -1) { 155 | perror("getpeername"); 156 | exit(1); 157 | res->re_errors++; 158 | } 159 | } 160 | res->re_count = i; 161 | 162 | return (0); 163 | } 164 | -------------------------------------------------------------------------------- /getpid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * getpid 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "note: measures getpid()"); 46 | 47 | lm_tsdsize = 0; 48 | 49 | return (0); 50 | } 51 | 52 | /*ARGSUSED*/ 53 | int 54 | benchmark(void *tsd, result_t *res) 55 | { 56 | int i; 57 | 58 | for (i = 0; i < lm_optB; i ++) { 59 | (void) getpid(); 60 | } 61 | res->re_count = i; 62 | 63 | return (0); 64 | } 65 | -------------------------------------------------------------------------------- /getrusage.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * getrusage 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | int 44 | benchmark_init() 45 | { 46 | (void) sprintf(lm_usage, "notes: measures getrusage(RUSAGE_SELF)\n"); 47 | lm_tsdsize = 0; 48 | return (0); 49 | } 50 | 51 | /*ARGSUSED*/ 52 | int 53 | benchmark(void *tsd, result_t *res) 54 | { 55 | int i; 56 | struct rusage u; 57 | 58 | for (i = 0; i < lm_optB; i += 10) { 59 | (void) getrusage(RUSAGE_SELF, &u); 60 | (void) getrusage(RUSAGE_SELF, &u); 61 | (void) getrusage(RUSAGE_SELF, &u); 62 | (void) getrusage(RUSAGE_SELF, &u); 63 | (void) getrusage(RUSAGE_SELF, &u); 64 | (void) getrusage(RUSAGE_SELF, &u); 65 | (void) getrusage(RUSAGE_SELF, &u); 66 | (void) getrusage(RUSAGE_SELF, &u); 67 | (void) getrusage(RUSAGE_SELF, &u); 68 | (void) getrusage(RUSAGE_SELF, &u); 69 | } 70 | res->re_count = i; 71 | 72 | return (0); 73 | } 74 | -------------------------------------------------------------------------------- /getsockname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * getsockname 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "libmicro.h" 49 | 50 | #define FIRSTPORT 12345 51 | 52 | static struct sockaddr_in adds; 53 | static int sock = -1; 54 | 55 | int 56 | benchmark_init() 57 | { 58 | (void) sprintf(lm_usage, "notes: measures getsockname()()\n"); 59 | lm_tsdsize = 0; 60 | return (0); 61 | } 62 | 63 | int 64 | benchmark_initrun() 65 | { 66 | int j; 67 | int opt = 1; 68 | struct hostent *host; 69 | 70 | sock = socket(AF_INET, SOCK_STREAM, 0); 71 | if (sock == -1) { 72 | perror("socket"); 73 | exit(1); 74 | } 75 | 76 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 77 | &opt, sizeof (int)) == -1) { 78 | perror("setsockopt"); 79 | exit(1); 80 | } 81 | 82 | if ((host = gethostbyname("localhost")) == NULL) { 83 | perror("gethostbyname"); 84 | exit(1); 85 | } 86 | 87 | j = FIRSTPORT; 88 | for (;;) { 89 | (void) memset(&adds, 0, sizeof (struct sockaddr_in)); 90 | adds.sin_family = AF_INET; 91 | adds.sin_port = htons(j++); 92 | (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0], 93 | sizeof (struct in_addr)); 94 | 95 | if (bind(sock, (struct sockaddr *)&adds, 96 | sizeof (struct sockaddr_in)) == 0) { 97 | break; 98 | } 99 | 100 | if (errno != EADDRINUSE) { 101 | perror("bind"); 102 | exit(1); 103 | } 104 | } 105 | 106 | return (0); 107 | } 108 | 109 | /*ARGSUSED*/ 110 | int 111 | benchmark(void *tsd, result_t *res) 112 | { 113 | int i; 114 | struct sockaddr_in adds; 115 | socklen_t size; 116 | 117 | for (i = 0; i < lm_optB; i++) { 118 | size = sizeof (struct sockaddr_in); 119 | if (getsockname(sock, (struct sockaddr *)&adds, &size) == -1) 120 | res->re_errors++; 121 | } 122 | res->re_count = i; 123 | 124 | return (0); 125 | } 126 | -------------------------------------------------------------------------------- /gettimeofday.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * gettimeofday test 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "note: measures gettimeofday()"); 46 | lm_tsdsize = 0; 47 | return (0); 48 | } 49 | 50 | /*ARGSUSED*/ 51 | int 52 | benchmark(void *tsd, result_t *res) 53 | { 54 | int i; 55 | struct timeval t; 56 | 57 | for (i = 0; i < lm_optB; i += 10) { 58 | (void) gettimeofday(&t, NULL); 59 | (void) gettimeofday(&t, NULL); 60 | (void) gettimeofday(&t, NULL); 61 | (void) gettimeofday(&t, NULL); 62 | (void) gettimeofday(&t, NULL); 63 | (void) gettimeofday(&t, NULL); 64 | (void) gettimeofday(&t, NULL); 65 | (void) gettimeofday(&t, NULL); 66 | (void) gettimeofday(&t, NULL); 67 | (void) gettimeofday(&t, NULL); 68 | } 69 | res->re_count = i; 70 | 71 | return (0); 72 | } 73 | -------------------------------------------------------------------------------- /isatty.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * isatty test 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | #define DEFF "/dev/tty" 43 | static char *optf = DEFF; 44 | static int optb = 0; 45 | 46 | typedef struct { 47 | int ts_fd; 48 | } tsd_t; 49 | 50 | int 51 | benchmark_init() 52 | { 53 | lm_tsdsize = sizeof (tsd_t); 54 | 55 | (void) sprintf(lm_optstr, "f:b"); 56 | 57 | (void) sprintf(lm_usage, 58 | " [-f file-to-isatty (default %s)]\n" 59 | " [-b] (try to isatty an unopened fd)\n" 60 | "notes: measures isatty()", 61 | DEFF); 62 | 63 | return (0); 64 | } 65 | 66 | int 67 | benchmark_optswitch(int opt, char *optarg) 68 | { 69 | switch (opt) { 70 | case 'f': 71 | optf = optarg; 72 | break; 73 | case 'b': 74 | optb = 1; 75 | break; 76 | default: 77 | return (-1); 78 | } 79 | 80 | return (0); 81 | } 82 | 83 | int 84 | benchmark_initworker(void *tsd) 85 | { 86 | tsd_t *ts = (tsd_t *)tsd; 87 | 88 | ts->ts_fd = ((optb == 0) ? 89 | open(optf, O_RDONLY) : 1024); 90 | if (ts->ts_fd == -1) { 91 | return (1); 92 | } 93 | return (0); 94 | } 95 | 96 | int 97 | benchmark(void *tsd, result_t *res) 98 | { 99 | tsd_t *ts = (tsd_t *)tsd; 100 | int i; 101 | 102 | for (i = 0; i < lm_optB; i++) { 103 | if (isatty(ts->ts_fd) == -1) { 104 | res->re_errors++; 105 | } 106 | } 107 | res->re_count = i; 108 | 109 | return (0); 110 | } 111 | -------------------------------------------------------------------------------- /libmicro_main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * Separate file for main so we can link other programs 33 | * with libmicro 34 | */ 35 | 36 | #include 37 | 38 | extern int actual_main(int, char **); 39 | 40 | int 41 | main(int argc, char *argv[]) 42 | { 43 | return (actual_main(argc, argv)); 44 | } 45 | -------------------------------------------------------------------------------- /listen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * listen benchmark 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "libmicro.h" 50 | 51 | #define FIRSTPORT 12345 52 | 53 | static struct sockaddr_in adds; 54 | static int sock = -1; 55 | 56 | int 57 | benchmark_init() 58 | { 59 | (void) sprintf(lm_usage, "notes: measures listen()()\n"); 60 | 61 | lm_tsdsize = 0; 62 | 63 | return (0); 64 | } 65 | 66 | int 67 | benchmark_initrun() 68 | { 69 | int j; 70 | int opt = 1; 71 | struct hostent *host; 72 | 73 | sock = socket(AF_INET, SOCK_STREAM, 0); 74 | if (sock == -1) { 75 | perror("socket"); 76 | exit(1); 77 | } 78 | 79 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 80 | &opt, sizeof (int)) == -1) { 81 | perror("setsockopt"); 82 | exit(1); 83 | } 84 | 85 | if ((host = gethostbyname("localhost")) == NULL) { 86 | perror("gethostbyname"); 87 | exit(1); 88 | } 89 | 90 | j = FIRSTPORT; 91 | for (;;) { 92 | (void) memset(&adds, 0, sizeof (struct sockaddr_in)); 93 | adds.sin_family = AF_INET; 94 | adds.sin_port = htons(j++); 95 | (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0], 96 | sizeof (struct in_addr)); 97 | 98 | if (bind(sock, (struct sockaddr *)&adds, 99 | sizeof (struct sockaddr_in)) == 0) { 100 | break; 101 | } 102 | 103 | if (errno != EADDRINUSE) { 104 | perror("bind"); 105 | exit(1); 106 | } 107 | } 108 | 109 | return (0); 110 | } 111 | 112 | /*ARGSUSED*/ 113 | int 114 | benchmark(void *tsd, result_t *res) 115 | { 116 | int i; 117 | 118 | for (i = 0; i < lm_optB; i += 2) { 119 | if (listen(sock, 4) == -1) 120 | res->re_errors++; 121 | if (listen(sock, 5) == -1) 122 | res->re_errors++; 123 | } 124 | res->re_count = i; 125 | 126 | return (0); 127 | } 128 | -------------------------------------------------------------------------------- /localtime_r.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * localtime benchmark 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "notes: measures localtime_r()\n"); 46 | lm_tsdsize = 0; 47 | 48 | return (0); 49 | } 50 | 51 | /*ARGSUSED*/ 52 | int 53 | benchmark(void *tsd, result_t *res) 54 | { 55 | int i; 56 | struct tm tms; 57 | static time_t clock1 = 0L; 58 | static time_t clock2 = 1L; 59 | 60 | for (i = 0; i < lm_optB; i += 10) { 61 | (void) localtime_r(&clock1, &tms); 62 | (void) localtime_r(&clock2, &tms); 63 | (void) localtime_r(&clock1, &tms); 64 | (void) localtime_r(&clock2, &tms); 65 | (void) localtime_r(&clock1, &tms); 66 | (void) localtime_r(&clock2, &tms); 67 | (void) localtime_r(&clock1, &tms); 68 | (void) localtime_r(&clock2, &tms); 69 | (void) localtime_r(&clock1, &tms); 70 | (void) localtime_r(&clock2, &tms); 71 | } 72 | res->re_count = i; 73 | 74 | return (0); 75 | } 76 | -------------------------------------------------------------------------------- /log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * log benchmark - should do wider range... 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "note: measures log()"); 46 | lm_nsecs_per_op = 75; 47 | lm_tsdsize = 0; 48 | return (0); 49 | } 50 | 51 | /*ARGSUSED*/ 52 | int 53 | benchmark(void *tsd, result_t *res) 54 | { 55 | int i; 56 | 57 | for (i = 0; i < lm_optB; i += 10) { 58 | double value = i + .01; 59 | (void) log(value); 60 | (void) log(value); 61 | (void) log(value); 62 | (void) log(value); 63 | (void) log(value); 64 | (void) log(value); 65 | (void) log(value); 66 | (void) log(value); 67 | (void) log(value); 68 | (void) log(value); 69 | } 70 | res->re_count = i; 71 | 72 | return (0); 73 | } 74 | -------------------------------------------------------------------------------- /longjmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * benchmark longjmp 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "notes: measures longjmp()\n"); 46 | lm_tsdsize = 0; 47 | return (0); 48 | } 49 | 50 | /*ARGSUSED*/ 51 | int 52 | benchmark(void *tsd, result_t *res) 53 | { 54 | int i = 0; 55 | jmp_buf env; 56 | 57 | (void) setjmp(env); 58 | i++; 59 | if (i < lm_optB) 60 | longjmp(env, 0); 61 | 62 | res->re_count = i; 63 | 64 | return (0); 65 | } 66 | -------------------------------------------------------------------------------- /lrand48.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * lrand48 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "libmicro.h" 40 | 41 | int 42 | benchmark_init() 43 | { 44 | (void) sprintf(lm_usage, "note: measures lrand48()"); 45 | lm_nsecs_per_op = 10; 46 | lm_tsdsize = 0; 47 | return (0); 48 | } 49 | 50 | /*ARGSUSED*/ 51 | int 52 | benchmark(void *tsd, result_t *res) 53 | { 54 | int i; 55 | 56 | for (i = 0; i < lm_optB; i += 10) { 57 | (void) lrand48(); 58 | (void) lrand48(); 59 | (void) lrand48(); 60 | (void) lrand48(); 61 | (void) lrand48(); 62 | (void) lrand48(); 63 | (void) lrand48(); 64 | (void) lrand48(); 65 | (void) lrand48(); 66 | (void) lrand48(); 67 | } 68 | res->re_count = i; 69 | 70 | return (0); 71 | } 72 | -------------------------------------------------------------------------------- /lseek.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * lseek 33 | */ 34 | 35 | #ifdef linux 36 | #define _XOPEN_SOURCE 500 37 | #endif 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "libmicro.h" 45 | 46 | #define DEFF "/dev/zero" 47 | #define DEFS 1024 48 | 49 | static char *optf = DEFF; 50 | static long long opts = DEFS; 51 | 52 | typedef struct { 53 | int ts_once; 54 | int ts_fd; 55 | } tsd_t; 56 | 57 | int 58 | benchmark_init() 59 | { 60 | lm_tsdsize = sizeof (tsd_t); 61 | 62 | (void) sprintf(lm_optstr, "f:s:"); 63 | 64 | (void) sprintf(lm_usage, 65 | " [-f file-to-read (default %s)]\n" 66 | " [-s buffer-size (default %d)]\n" 67 | "notes: measures lseek()\n", 68 | DEFF, DEFS); 69 | 70 | (void) sprintf(lm_header, "%8s", "size"); 71 | 72 | return (0); 73 | } 74 | 75 | int 76 | benchmark_optswitch(int opt, char *optarg) 77 | { 78 | switch (opt) { 79 | case 'f': 80 | optf = optarg; 81 | break; 82 | case 's': 83 | opts = sizetoll(optarg); 84 | break; 85 | default: 86 | return (-1); 87 | } 88 | return (0); 89 | } 90 | 91 | int 92 | benchmark_initbatch(void *tsd) 93 | { 94 | tsd_t *ts = (tsd_t *)tsd; 95 | 96 | if (ts->ts_once++ == 0) { 97 | ts->ts_fd = open(optf, O_RDONLY); 98 | } 99 | 100 | return (0); 101 | } 102 | 103 | int 104 | benchmark(void *tsd, result_t *res) 105 | { 106 | tsd_t *ts = (tsd_t *)tsd; 107 | int i; 108 | 109 | for (i = 0; i < lm_optB; i += 2) { 110 | if (lseek(ts->ts_fd, 0L, SEEK_SET) != 0) { 111 | res->re_errors++; 112 | } 113 | if (lseek(ts->ts_fd, opts, SEEK_SET) != opts) { 114 | res->re_errors++; 115 | } 116 | } 117 | res->re_count = i; 118 | 119 | return (0); 120 | } 121 | 122 | char * 123 | benchmark_result() 124 | { 125 | static char result[256]; 126 | 127 | (void) sprintf(result, "%8lld", opts); 128 | 129 | return (result); 130 | } 131 | -------------------------------------------------------------------------------- /malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * malloc benchmark (crude) 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "libmicro.h" 43 | 44 | static int optg = 100; 45 | static int opts[32] = {32}; 46 | static int optscnt = 0; 47 | 48 | typedef struct { 49 | void **ts_glob; 50 | } tsd_t; 51 | 52 | int 53 | benchmark_init() 54 | { 55 | lm_tsdsize = sizeof (tsd_t); 56 | 57 | (void) sprintf(lm_optstr, "s:g:"); 58 | 59 | (void) sprintf(lm_usage, 60 | " [-g number of mallocs before free (default %d)]\n" 61 | " [-s size to malloc (default %d)." 62 | " Up to 32 sizes accepted\n" 63 | "notes: measures malloc()/free()", 64 | optg, opts[0]); 65 | 66 | (void) sprintf(lm_header, "%6s %6s", "glob", "sizes"); 67 | 68 | return (0); 69 | } 70 | 71 | int 72 | benchmark_optswitch(int opt, char *optarg) 73 | { 74 | switch (opt) { 75 | case 'g': 76 | optg = sizetoint(optarg); 77 | break; 78 | case 's': 79 | opts[optscnt] = sizetoint(optarg); 80 | optscnt = ++optscnt & (31); 81 | break; 82 | default: 83 | return (-1); 84 | } 85 | 86 | return (0); 87 | } 88 | 89 | int 90 | benchmark_initworker(void *tsd) 91 | { 92 | tsd_t *ts = (tsd_t *)tsd; 93 | 94 | if (optscnt == 0) 95 | optscnt = 1; 96 | 97 | ts->ts_glob = malloc(sizeof (void *)* optg); 98 | if (ts->ts_glob == NULL) { 99 | return (1); 100 | } 101 | return (0); 102 | } 103 | 104 | int 105 | benchmark(void *tsd, result_t *res) 106 | { 107 | tsd_t *ts = (tsd_t *)tsd; 108 | int i, j, k; 109 | 110 | for (i = 0; i < lm_optB; i++) { 111 | for (k = j = 0; j < optg; j++) { 112 | if ((ts->ts_glob[j] = malloc(opts[k++])) == NULL) 113 | res->re_errors++; 114 | if (k >= optscnt) 115 | k = 0; 116 | } 117 | for (j = 0; j < optg; j++) { 118 | free(ts->ts_glob[j]); 119 | } 120 | } 121 | 122 | res->re_count = i * j; 123 | 124 | return (0); 125 | } 126 | 127 | char * 128 | benchmark_result() 129 | { 130 | static char result[256]; 131 | int i; 132 | 133 | (void) sprintf(result, "%6d ", optg); 134 | 135 | for (i = 0; i < optscnt; i++) 136 | (void) sprintf(result + strlen(result), "%d ", opts[i]); 137 | return (result); 138 | } 139 | -------------------------------------------------------------------------------- /memcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * memcpy 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | #define DEFS 8192 43 | #define DEFR 1 44 | 45 | static long long opts = DEFS; 46 | static int optf; 47 | static int optt; 48 | static int opta; 49 | 50 | typedef struct { 51 | char *ts_src; 52 | char *ts_dest; 53 | int ts_srcsize; 54 | int ts_destsize; 55 | } tsd_t; 56 | 57 | int 58 | benchmark_init() 59 | { 60 | lm_tsdsize = sizeof (tsd_t); 61 | 62 | (void) sprintf(lm_optstr, "a:s:ft"); 63 | 64 | (void) sprintf(lm_usage, 65 | " [-s buffer-size (default %d)]\n" 66 | " [-a relative alignment (default page aligned)]\n" 67 | " [-f (rotate \"from\" buffer to keep it out of cache)]\n" 68 | " [-t (rotate \"to\" buffer to keep it out of cache)]\n" 69 | "notes: measures memcpy()\n", 70 | DEFS); 71 | 72 | (void) sprintf(lm_header, "%8s", "size"); 73 | 74 | return (0); 75 | } 76 | 77 | int 78 | benchmark_optswitch(int opt, char *optarg) 79 | { 80 | switch (opt) { 81 | case 'f': 82 | optf++; 83 | break; 84 | case 't': 85 | optt++; 86 | break; 87 | case 's': 88 | opts = sizetoll(optarg); 89 | break; 90 | case 'a': 91 | opta = sizetoint(optarg); 92 | break; 93 | default: 94 | return (-1); 95 | } 96 | return (0); 97 | } 98 | 99 | int 100 | benchmark_initworker(void *tsd) 101 | { 102 | tsd_t *ts = (tsd_t *)tsd; 103 | 104 | if (optf) 105 | ts->ts_srcsize = 64 * 1024 * 1024; 106 | else 107 | ts->ts_srcsize = opts + opta; 108 | 109 | if (optt) 110 | ts->ts_destsize = 64 * 1024 * 1024; 111 | else 112 | ts->ts_destsize = (int)opts; 113 | 114 | 115 | ts->ts_src = opta + (char *)valloc(ts->ts_srcsize); 116 | ts->ts_dest = valloc(ts->ts_destsize); 117 | 118 | return (0); 119 | } 120 | 121 | int 122 | benchmark(void *tsd, result_t *res) 123 | { 124 | tsd_t *ts = (tsd_t *)tsd; 125 | int i; 126 | char *src = ts->ts_src; 127 | char *dest = ts->ts_dest; 128 | 129 | int bump = (int)opts; 130 | 131 | if (bump < 1024) 132 | bump = 1024; /* avoid prefetched area */ 133 | for (i = 0; i < lm_optB; i++) { 134 | (void) memcpy(dest, src, opts); 135 | if (optf) { 136 | src += bump; 137 | if (src + opts > ts->ts_src + ts->ts_srcsize) 138 | src = ts->ts_src; 139 | } 140 | if (optt) { 141 | dest += bump; 142 | if (dest + opts > ts->ts_dest + ts->ts_destsize) 143 | dest = ts->ts_dest; 144 | } 145 | } 146 | 147 | res->re_count = i; 148 | 149 | return (0); 150 | } 151 | 152 | char * 153 | benchmark_result() 154 | { 155 | static char result[256]; 156 | 157 | (void) sprintf(result, "%8lld", opts); 158 | 159 | return (result); 160 | } 161 | -------------------------------------------------------------------------------- /memmove.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * memmove 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | #define DEFS 8192 43 | #define DEFR 1 44 | 45 | static long long opts = DEFS; 46 | static int optf; 47 | static int optt; 48 | static int opta; 49 | 50 | typedef struct { 51 | char *ts_src; 52 | char *ts_dest; 53 | int ts_srcsize; 54 | int ts_destsize; 55 | } tsd_t; 56 | 57 | int 58 | benchmark_init() 59 | { 60 | lm_tsdsize = sizeof (tsd_t); 61 | 62 | (void) sprintf(lm_optstr, "a:s:ft"); 63 | 64 | (void) sprintf(lm_usage, 65 | " [-s buffer-size (default %d)]\n" 66 | " [-a relative alignment (default page aligned)]\n" 67 | " [-f (rotate \"from\" buffer to keep it out of cache)]\n" 68 | " [-t (rotate \"to\" buffer to keep it out of cache)]\n" 69 | "notes: measures memmove()\n", 70 | DEFS); 71 | 72 | (void) sprintf(lm_header, "%8s", "size"); 73 | 74 | return (0); 75 | } 76 | 77 | int 78 | benchmark_optswitch(int opt, char *optarg) 79 | { 80 | switch (opt) { 81 | case 'f': 82 | optf++; 83 | break; 84 | case 't': 85 | optt++; 86 | break; 87 | case 's': 88 | opts = sizetoll(optarg); 89 | break; 90 | case 'a': 91 | opta = sizetoint(optarg); 92 | break; 93 | default: 94 | return (-1); 95 | } 96 | return (0); 97 | } 98 | 99 | int 100 | benchmark_initworker(void *tsd) 101 | { 102 | tsd_t *ts = (tsd_t *)tsd; 103 | 104 | if (optf) 105 | ts->ts_srcsize = 64 * 1024 * 1024; 106 | else 107 | ts->ts_srcsize = opts + opta; 108 | 109 | if (optt) 110 | ts->ts_destsize = 64 * 1024 * 1024; 111 | else 112 | ts->ts_destsize = (int)opts; 113 | 114 | 115 | ts->ts_src = opta + (char *)valloc(ts->ts_srcsize); 116 | ts->ts_dest = valloc(ts->ts_destsize); 117 | 118 | return (0); 119 | } 120 | 121 | int 122 | benchmark(void *tsd, result_t *res) 123 | { 124 | tsd_t *ts = (tsd_t *)tsd; 125 | int i; 126 | char *src = ts->ts_src; 127 | char *dest = ts->ts_dest; 128 | 129 | int bump = (int)opts; 130 | 131 | if (bump < 1024) 132 | bump = 1024; /* avoid prefetched area */ 133 | for (i = 0; i < lm_optB; i++) { 134 | (void) memmove(dest, src, opts); 135 | if (optf) { 136 | src += bump; 137 | if (src + opts > ts->ts_src + ts->ts_srcsize) 138 | src = ts->ts_src; 139 | } 140 | if (optt) { 141 | dest += bump; 142 | if (dest + opts > ts->ts_dest + ts->ts_destsize) 143 | dest = ts->ts_dest; 144 | } 145 | } 146 | 147 | res->re_count = i; 148 | 149 | return (0); 150 | } 151 | 152 | char * 153 | benchmark_result() 154 | { 155 | static char result[256]; 156 | 157 | (void) sprintf(result, "%8lld", opts); 158 | 159 | return (result); 160 | } 161 | -------------------------------------------------------------------------------- /memrand.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * memory access time check 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | static long opts = 1024*1024; 44 | 45 | typedef struct { 46 | long **ts_data; 47 | long ts_result; 48 | } tsd_t; 49 | 50 | int 51 | benchmark_init() 52 | { 53 | lm_tsdsize = sizeof (tsd_t); 54 | 55 | (void) sprintf(lm_optstr, "s:"); 56 | 57 | (void) sprintf(lm_usage, 58 | " [-s size] number of bytes to " 59 | " access (default %ld)\n" 60 | "notes: measures \"random\" memory access times\n", 61 | opts); 62 | 63 | (void) sprintf(lm_header, "%8s", "size"); 64 | 65 | return (0); 66 | } 67 | 68 | int 69 | benchmark_optswitch(int opt, char *optarg) 70 | { 71 | switch (opt) { 72 | case 's': 73 | opts = sizetoint(optarg); 74 | break; 75 | default: 76 | return (-1); 77 | } 78 | 79 | return (0); 80 | } 81 | 82 | int 83 | benchmark_initworker(void *tsd) 84 | { 85 | tsd_t *ts = (tsd_t *)tsd; 86 | int i, j; 87 | 88 | ts->ts_data = malloc(opts); 89 | 90 | if (ts->ts_data == NULL) { 91 | return (1); 92 | } 93 | 94 | /* 95 | * use lmbench style backwards stride 96 | */ 97 | 98 | for (i = 0; i < opts / sizeof (long); i++) { 99 | j = i - 128; 100 | if (j < 0) 101 | j = j + opts / sizeof (long); 102 | ts->ts_data[i] = (long *)&(ts->ts_data[j]); 103 | } 104 | return (0); 105 | } 106 | 107 | int 108 | benchmark(void *tsd, result_t *res) 109 | { 110 | tsd_t *ts = (tsd_t *)tsd; 111 | int i; 112 | 113 | long **ptr = ts->ts_data; 114 | 115 | 116 | 117 | for (i = 0; i < lm_optB; i += 10) { 118 | ptr = (long **)*ptr; 119 | ptr = (long **)*ptr; 120 | ptr = (long **)*ptr; 121 | ptr = (long **)*ptr; 122 | ptr = (long **)*ptr; 123 | ptr = (long **)*ptr; 124 | ptr = (long **)*ptr; 125 | ptr = (long **)*ptr; 126 | ptr = (long **)*ptr; 127 | ptr = (long **)*ptr; 128 | } 129 | 130 | ts->ts_result = (long)*ptr; 131 | 132 | res->re_count = lm_optB; 133 | 134 | return (0); 135 | } 136 | 137 | char * 138 | benchmark_result() 139 | { 140 | static char result[256]; 141 | 142 | (void) sprintf(result, "%8ld ", opts); 143 | 144 | 145 | return (result); 146 | } 147 | -------------------------------------------------------------------------------- /memset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * memset 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | #define DEFS 8192 43 | 44 | static long long opts = DEFS; 45 | static int opta = 0; 46 | static int optu = 0; 47 | 48 | static char *optas = "4k"; 49 | 50 | typedef struct { 51 | char *ts_buff; 52 | int ts_size; 53 | int ts_offset; 54 | } tsd_t; 55 | 56 | int 57 | benchmark_init() 58 | { 59 | lm_tsdsize = sizeof (tsd_t); 60 | 61 | (void) sprintf(lm_optstr, "a:us:"); 62 | 63 | (void) sprintf(lm_usage, 64 | " [-s buffer-size (default %d)]\n" 65 | " [-a alignment (force buffer alignment)]\n" 66 | " [-u (try to always use uncached memory)]" 67 | "notes: measures memset()\n", 68 | DEFS); 69 | 70 | (void) sprintf(lm_header, "%8s%16s", "size", "alignment"); 71 | 72 | return (0); 73 | } 74 | 75 | int 76 | benchmark_optswitch(int opt, char *optarg) 77 | { 78 | switch (opt) { 79 | case 'u': 80 | optu = 1; 81 | break; 82 | case 's': 83 | opts = sizetoll(optarg); 84 | break; 85 | case 'a': 86 | opta = sizetoll(optarg); 87 | if (opta > 4096) 88 | opta = 0; 89 | else 90 | optas = optarg; 91 | break; 92 | default: 93 | return (-1); 94 | } 95 | return (0); 96 | } 97 | 98 | int 99 | benchmark_initworker(void *tsd) 100 | { 101 | tsd_t *ts = (tsd_t *)tsd; 102 | int errors = 0; 103 | int i; 104 | 105 | if (optu) { 106 | ts->ts_size = 1024 * 1024 * 64; 107 | ts->ts_offset = opta; 108 | } else { 109 | ts->ts_size = opta + opts; 110 | ts->ts_offset = opta; 111 | } 112 | 113 | if ((ts->ts_buff = (char *)valloc(ts->ts_size)) == NULL) 114 | errors++; 115 | 116 | for (i = 0; i < ts->ts_size; i++) 117 | ts->ts_buff[i] = 0; 118 | return (errors); 119 | } 120 | 121 | /*ARGSUSED*/ 122 | int 123 | benchmark(void *tsd, result_t *res) 124 | { 125 | int i; 126 | tsd_t *ts = (tsd_t *)tsd; 127 | 128 | 129 | if (optu) { 130 | char *buf = ts->ts_buff + ts->ts_offset; 131 | char *end = ts->ts_buff + ts->ts_size; 132 | int offset = ts->ts_offset; 133 | for (i = 0; i < lm_optB; i ++) { 134 | (void) memset(buf, 0, opts); 135 | buf = (char *)(((unsigned long)buf + opts + 4095) & 136 | ~4095) + offset; 137 | if (buf + opts > end) 138 | buf = ts->ts_buff + offset; 139 | } 140 | } else { 141 | char *buf = ts->ts_buff + ts->ts_offset; 142 | 143 | for (i = 0; i < lm_optB; i += 10) { 144 | (void) memset(buf, 0, opts); 145 | (void) memset(buf, 0, opts); 146 | (void) memset(buf, 0, opts); 147 | (void) memset(buf, 0, opts); 148 | (void) memset(buf, 0, opts); 149 | (void) memset(buf, 0, opts); 150 | (void) memset(buf, 0, opts); 151 | (void) memset(buf, 0, opts); 152 | (void) memset(buf, 0, opts); 153 | (void) memset(buf, 0, opts); 154 | } 155 | } 156 | res->re_count = i; 157 | 158 | return (0); 159 | } 160 | 161 | char * 162 | benchmark_result() 163 | { 164 | static char result[256]; 165 | 166 | (void) sprintf(result, "%8lld%12s", opts, optas); 167 | 168 | return (result); 169 | } 170 | -------------------------------------------------------------------------------- /mk_tarball: -------------------------------------------------------------------------------- 1 | #!/bin/sh -x 2 | # 3 | # Copyright 2003 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | # 7 | # script to make tarball... args are contents to be inserted 8 | # 9 | 10 | libmicro_version=`bin/getpid -V` 11 | case $libmicro_version in 12 | [0-9]*) 13 | ;; 14 | *) 15 | echo "ERROR: cannot determine libMicro version" 16 | exit 1 17 | esac 18 | dirname="libMicro-$libmicro_version" 19 | 20 | here=`pwd` 21 | target=$here/libMicro.tar 22 | tmpdir=/tmp/libmicro.$$ 23 | mkdir -p $tmpdir/$dirname 24 | cp $* $tmpdir/$dirname 25 | cd $tmpdir 26 | tar cvf $target $dirname 27 | cd $here 28 | rm -rf $tmpdir 29 | -------------------------------------------------------------------------------- /mktime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * mktime 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | typedef struct { 43 | struct tm ts_tm1; 44 | struct tm ts_tm2; 45 | } tsd_t; 46 | 47 | int 48 | benchmark_init() 49 | { 50 | lm_tsdsize = sizeof (tsd_t); 51 | 52 | (void) sprintf(lm_usage, 53 | "notes: measures mktime()\n"); 54 | 55 | return (0); 56 | } 57 | 58 | int 59 | benchmark_initbatch(void *tsd) 60 | { 61 | tsd_t *ts = (tsd_t *)tsd; 62 | 63 | time_t clock1; 64 | time_t clock2; 65 | 66 | clock1 = time(NULL); 67 | clock2 = clock1 + 1; 68 | 69 | (void) localtime_r(&clock1, &ts->ts_tm1); 70 | (void) localtime_r(&clock2, &ts->ts_tm2); 71 | 72 | return (0); 73 | } 74 | 75 | 76 | int 77 | benchmark(void *tsd, result_t *res) 78 | { 79 | int i; 80 | tsd_t *ts = (tsd_t *)tsd; 81 | struct tm t1, t2; 82 | 83 | for (i = 0; i < lm_optB; i += 10) { 84 | t1 = ts->ts_tm1; 85 | t2 = ts->ts_tm2; 86 | (void) mktime(&t1); 87 | (void) mktime(&t2); 88 | 89 | t1 = ts->ts_tm1; 90 | t2 = ts->ts_tm2; 91 | (void) mktime(&t1); 92 | (void) mktime(&t2); 93 | 94 | t1 = ts->ts_tm1; 95 | t2 = ts->ts_tm2; 96 | (void) mktime(&t1); 97 | (void) mktime(&t2); 98 | 99 | t1 = ts->ts_tm1; 100 | t2 = ts->ts_tm2; 101 | (void) mktime(&t1); 102 | (void) mktime(&t2); 103 | 104 | t1 = ts->ts_tm1; 105 | t2 = ts->ts_tm2; 106 | (void) mktime(&t1); 107 | (void) mktime(&t2); 108 | } 109 | res->re_count = lm_optB; 110 | 111 | return (0); 112 | } 113 | -------------------------------------------------------------------------------- /msync.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "libmicro.h" 39 | 40 | typedef struct { 41 | char *ts_map; 42 | int ts_foo; /* defeat optimizers */ 43 | } tsd_t; 44 | 45 | #define DEFF "/dev/zero" 46 | #define DEFL 8192 47 | 48 | static char *optf = DEFF; 49 | static long long optl = DEFL; 50 | static int optr = 0; 51 | static int opts = 0; 52 | static int optw = 0; 53 | static int opta = MS_SYNC; 54 | static int opti = 0; 55 | static int anon = 0; 56 | static int pagesize; 57 | 58 | int 59 | benchmark_init() 60 | { 61 | lm_tsdsize = sizeof (tsd_t); 62 | 63 | (void) sprintf(lm_optstr, "af:il:rsw"); 64 | 65 | (void) sprintf(lm_usage, 66 | " [-f file-to-map (default %s)]\n" 67 | " [-l mapping-length (default %d)]\n" 68 | " [-r] (read a byte from each page between msyncs)\n" 69 | " [-w] (write a byte to each page between msyncs)\n" 70 | " [-s] (use MAP_SHARED instead of MAP_PRIVATE)\n" 71 | " [-a (specify MS_ASYNC rather than default MS_SYNC)\n" 72 | " [-i (specify MS_INVALIDATE)\n" 73 | "notes: measures msync()\n", 74 | DEFF, DEFL); 75 | 76 | (void) sprintf(lm_header, "%8s %6s", "length", "flags"); 77 | 78 | return (0); 79 | } 80 | 81 | int 82 | benchmark_optswitch(int opt, char *optarg) 83 | { 84 | switch (opt) { 85 | case 'a': 86 | opta = MS_ASYNC; 87 | break; 88 | 89 | case 'f': 90 | optf = optarg; 91 | break; 92 | 93 | case 'i': 94 | opti = MS_INVALIDATE; 95 | break; 96 | 97 | case 'l': 98 | optl = sizetoll(optarg); 99 | break; 100 | case 'r': 101 | optr = 1; 102 | break; 103 | case 's': 104 | opts = 1; 105 | break; 106 | case 'w': 107 | optw = 1; 108 | break; 109 | default: 110 | return (-1); 111 | } 112 | 113 | pagesize = getpagesize(); 114 | 115 | return (0); 116 | } 117 | 118 | int 119 | benchmark_initworker(void *tsd) 120 | { 121 | tsd_t *ts = (tsd_t *)tsd; 122 | 123 | int fd; 124 | 125 | if ((fd = open(optf, O_RDWR)) < 0) { 126 | perror("open:"); 127 | return (1); 128 | } 129 | 130 | (void) ftruncate(fd, optl); 131 | 132 | if ((ts->ts_map = (char *)mmap(NULL, optl, 133 | PROT_READ | PROT_WRITE, opts ? MAP_SHARED : MAP_PRIVATE, 134 | fd, 0L)) == MAP_FAILED) { 135 | perror("mmap:"); 136 | (void) close(fd); 137 | return (1); 138 | } 139 | 140 | return (0); 141 | } 142 | 143 | int 144 | benchmark(void *tsd, result_t *res) 145 | { 146 | tsd_t *ts = (tsd_t *)tsd; 147 | int i, j; 148 | 149 | for (i = 0; i < lm_optB; i++) { 150 | 151 | if (msync(ts->ts_map, optl, opta | opti) < 0) { 152 | perror("msync:"); 153 | res->re_errors++; 154 | break; 155 | } 156 | 157 | if (optr) { 158 | for (j = 0; j < optl; j += pagesize) { 159 | ts->ts_foo += ts->ts_map[j]; 160 | } 161 | } 162 | 163 | if (optw) { 164 | for (j = 0; j < optl; j += pagesize) { 165 | ts->ts_map[j] = 1; 166 | } 167 | } 168 | } 169 | res->re_count = i; 170 | 171 | return (0); 172 | } 173 | 174 | char * 175 | benchmark_result() 176 | { 177 | static char result[256]; 178 | char flags[6]; 179 | 180 | flags[0] = anon ? 'a' : '-'; 181 | flags[1] = optr ? 'r' : '-'; 182 | flags[2] = optw ? 'w' : '-'; 183 | flags[3] = opts ? 's' : '-'; 184 | flags[4] = opti ? 'i' : '-'; 185 | flags[5] = 0; 186 | 187 | (void) sprintf(result, "%8lld %6s", optl, flags); 188 | 189 | return (result); 190 | } 191 | -------------------------------------------------------------------------------- /mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * mutex 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | static int optt = 0; 44 | static int optp = 0; 45 | static int opth = 0; 46 | static int opto = 0; 47 | 48 | pthread_mutex_t *lock; 49 | 50 | typedef struct { 51 | int ts_once; 52 | pthread_mutex_t *ts_lock; 53 | } tsd_t; 54 | 55 | int 56 | benchmark_init() 57 | { 58 | lm_tsdsize = sizeof (tsd_t); 59 | 60 | (void) sprintf(lm_usage, 61 | " [-t] (create dummy thread so we are multithreaded)\n" 62 | " [-p] (use inter-process mutex (not support everywhere))\n" 63 | " [-h usecs] (specify mutex hold time (default 0)\n" 64 | "notes: measures uncontended pthread_mutex_[un,]lock\n"); 65 | 66 | (void) sprintf(lm_optstr, "tph:o:"); 67 | 68 | (void) sprintf(lm_header, "%8s", "holdtime"); 69 | 70 | return (0); 71 | } 72 | 73 | /*ARGSUSED*/ 74 | int 75 | benchmark_optswitch(int opt, char *optarg) 76 | { 77 | switch (opt) { 78 | case 'p': 79 | optp = 1; 80 | break; 81 | 82 | case 't': 83 | optt = 1; 84 | break; 85 | 86 | case 'h': 87 | opth = sizetoint(optarg); 88 | break; 89 | 90 | case 'o': 91 | opto = sizetoint(optarg); 92 | break; 93 | 94 | default: 95 | return (-1); 96 | } 97 | return (0); 98 | } 99 | 100 | void * 101 | dummy(void *arg) 102 | { 103 | (void) pause(); 104 | return (arg); 105 | } 106 | 107 | int 108 | benchmark_initrun() 109 | { 110 | pthread_mutexattr_t attr; 111 | int errors = 0; 112 | 113 | /*LINTED*/ 114 | lock = (pthread_mutex_t *)mmap(NULL, 115 | getpagesize(), 116 | PROT_READ | PROT_WRITE, 117 | optp?(MAP_ANON | MAP_SHARED):MAP_ANON|MAP_PRIVATE, 118 | -1, 0L) + opto; 119 | 120 | if (lock == MAP_FAILED) { 121 | errors++; 122 | } else { 123 | (void) pthread_mutexattr_init(&attr); 124 | if (optp) 125 | (void) pthread_mutexattr_setpshared(&attr, 126 | PTHREAD_PROCESS_SHARED); 127 | 128 | if (pthread_mutex_init(lock, &attr) != 0) 129 | errors++; 130 | } 131 | 132 | return (errors); 133 | } 134 | 135 | int 136 | benchmark_initworker(void *tsd) 137 | { 138 | int errors = 0; 139 | tsd_t *ts = (tsd_t *)tsd; 140 | 141 | 142 | if (optt) { 143 | pthread_t tid; 144 | 145 | 146 | 147 | if (pthread_create(&tid, NULL, dummy, NULL) != 0) { 148 | errors++; 149 | } 150 | } 151 | 152 | ts->ts_lock = lock; 153 | 154 | return (errors); 155 | } 156 | 157 | void 158 | spinme(int usecs) 159 | { 160 | long long s = getusecs(); 161 | 162 | while (getusecs() - s < usecs) 163 | ; 164 | } 165 | 166 | int 167 | benchmark(void *tsd, result_t *res) 168 | { 169 | tsd_t *ts = (tsd_t *)tsd; 170 | int i; 171 | 172 | for (i = 0; i < lm_optB; i ++) { 173 | 174 | (void) pthread_mutex_lock(ts->ts_lock); 175 | if (opth) 176 | spinme(opth); 177 | (void) pthread_mutex_unlock(ts->ts_lock); 178 | 179 | } 180 | 181 | res->re_count = lm_optB; 182 | 183 | return (0); 184 | } 185 | 186 | char * 187 | benchmark_result() 188 | { 189 | static char result[256]; 190 | 191 | (void) sprintf(result, "%8d", opth); 192 | 193 | return (result); 194 | } 195 | -------------------------------------------------------------------------------- /nop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * silly nop benchmark to test infrastructure 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | int 43 | benchmark_init() 44 | { 45 | (void) sprintf(lm_usage, "notes: measures nothing()\n"); 46 | 47 | return (0); 48 | } 49 | 50 | /*ARGSUSED*/ 51 | int 52 | benchmark(void *tsd, result_t *res) 53 | { 54 | int i; 55 | int nop(); 56 | 57 | for (i = 0; i < lm_optB; i++) 58 | (void) nop(); /* do nothing but the call */ 59 | 60 | res->re_count = i; 61 | 62 | return (0); 63 | } 64 | -------------------------------------------------------------------------------- /open.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | /* 32 | * benchmark open 33 | */ 34 | 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | typedef struct { 44 | int ts_once; 45 | int *ts_fds; 46 | } tsd_t; 47 | 48 | #define DEFF "/dev/null" 49 | 50 | static char *optf = DEFF; 51 | 52 | int 53 | benchmark_init() 54 | { 55 | lm_tsdsize = sizeof (tsd_t); 56 | 57 | lm_defB = 256; 58 | 59 | (void) sprintf(lm_usage, 60 | " [-f file-to-open (default %s)]\n" 61 | "notes: measures open()\n", 62 | DEFF); 63 | 64 | (void) sprintf(lm_optstr, "f:"); 65 | 66 | return (0); 67 | } 68 | 69 | int 70 | benchmark_optswitch(int opt, char *optarg) 71 | { 72 | switch (opt) { 73 | case 'f': 74 | optf = optarg; 75 | break; 76 | default: 77 | return (-1); 78 | } 79 | return (0); 80 | } 81 | 82 | int 83 | benchmark_initrun() 84 | { 85 | (void) setfdlimit(lm_optB * lm_optT + 10); 86 | 87 | return (0); 88 | } 89 | 90 | int 91 | benchmark_initbatch(void *tsd) 92 | { 93 | tsd_t *ts = (tsd_t *)tsd; 94 | int i; 95 | int errors = 0; 96 | 97 | if (ts->ts_once++ == 0) { 98 | ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); 99 | if (ts->ts_fds == NULL) { 100 | errors++; 101 | } 102 | for (i = 0; i < lm_optB; i++) { 103 | ts->ts_fds[i] = -1; 104 | } 105 | } 106 | 107 | return (errors); 108 | } 109 | 110 | int 111 | benchmark(void *tsd, result_t *res) 112 | { 113 | tsd_t *ts = (tsd_t *)tsd; 114 | int i; 115 | 116 | for (i = 0; i < lm_optB; i++) { 117 | ts->ts_fds[i] = open(optf, O_RDONLY); 118 | if (ts->ts_fds[i] < 0) { 119 | res->re_errors++; 120 | } 121 | } 122 | res->re_count = i; 123 | 124 | return (0); 125 | } 126 | 127 | int 128 | benchmark_finibatch(void *tsd) 129 | { 130 | tsd_t *ts = (tsd_t *)tsd; 131 | int i; 132 | 133 | for (i = 0; i < lm_optB; i++) { 134 | (void) close(ts->ts_fds[i]); 135 | } 136 | 137 | return (0); 138 | } 139 | -------------------------------------------------------------------------------- /pread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #ifdef linux 32 | #define _XOPEN_SOURCE 500 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | typedef struct { 43 | char *ts_buf; 44 | } tsd_t; 45 | 46 | #define DEFF "/dev/zero" 47 | #define DEFS 1024 48 | 49 | static char *optf = DEFF; 50 | static long long opts = DEFS; 51 | static int optw = 0; 52 | static int fd = -1; 53 | 54 | int 55 | benchmark_init() 56 | { 57 | lm_tsdsize = sizeof (tsd_t); 58 | 59 | (void) sprintf(lm_optstr, "wf:s:"); 60 | 61 | (void) sprintf(lm_usage, 62 | " [-f file-to-read (default %s)]\n" 63 | " [-s buffer-size (default %d)]\n" 64 | " [-w (write a byte to each page after read)]\n" 65 | "notes: measures pread()\n", 66 | DEFF, DEFS); 67 | 68 | (void) sprintf(lm_header, "%8s", "size"); 69 | 70 | return (0); 71 | } 72 | 73 | int 74 | benchmark_optswitch(int opt, char *optarg) 75 | { 76 | switch (opt) { 77 | case 'w': 78 | optw = getpagesize(); 79 | break; 80 | case 'f': 81 | optf = optarg; 82 | break; 83 | case 's': 84 | opts = sizetoll(optarg); 85 | break; 86 | default: 87 | return (-1); 88 | } 89 | return (0); 90 | } 91 | 92 | int 93 | benchmark_initrun() 94 | { 95 | fd = open(optf, O_RDONLY); 96 | 97 | return (0); 98 | } 99 | 100 | int 101 | benchmark_initbatch(void *tsd) 102 | { 103 | tsd_t *ts = (tsd_t *)tsd; 104 | int errors = 0; 105 | 106 | if (ts->ts_buf == NULL) { 107 | ts->ts_buf = malloc(opts); 108 | } 109 | 110 | return (errors); 111 | } 112 | 113 | int 114 | benchmark(void *tsd, result_t *res) 115 | { 116 | tsd_t *ts = (tsd_t *)tsd; 117 | int i; 118 | int j; 119 | 120 | for (i = 0; i < lm_optB; i++) { 121 | if (pread(fd, ts->ts_buf, opts, 0) != opts) { 122 | res->re_errors++; 123 | } 124 | if (optw) { 125 | for (j = 0; j < opts; j += optw) 126 | ts->ts_buf[j] = 0; 127 | } 128 | } 129 | res->re_count = i; 130 | 131 | return (0); 132 | } 133 | 134 | char * 135 | benchmark_result() 136 | { 137 | static char result[256]; 138 | 139 | (void) sprintf(result, "%8lld", opts); 140 | 141 | return (result); 142 | } 143 | -------------------------------------------------------------------------------- /pthread_create.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "libmicro.h" 39 | 40 | typedef struct { 41 | pthread_t *ts_threads; 42 | pthread_attr_t *ts_attr; 43 | pthread_mutex_t ts_lock; 44 | } tsd_t; 45 | 46 | static int opts = 0; 47 | 48 | int 49 | benchmark_init() 50 | { 51 | lm_defN = "pthread"; 52 | 53 | lm_tsdsize = sizeof (tsd_t); 54 | 55 | (void) sprintf(lm_usage, 56 | " [-s stacksize] (specify stacksize)\n" 57 | "notes: measures pthread_create\n"); 58 | 59 | (void) sprintf(lm_optstr, "s:"); 60 | 61 | return (0); 62 | } 63 | 64 | int 65 | benchmark_optswitch(int opt, char *optarg) 66 | { 67 | switch (opt) { 68 | case 's': 69 | opts = sizetoll(optarg); 70 | break; 71 | default: 72 | return (-1); 73 | } 74 | 75 | return (0); 76 | } 77 | 78 | int 79 | benchmark_initworker(void *tsd) 80 | { 81 | tsd_t *ts = (tsd_t *)tsd; 82 | int errors = 0; 83 | 84 | ts->ts_threads = calloc(lm_optB, sizeof (pthread_t)); 85 | (void) pthread_mutex_init(&ts->ts_lock, NULL); 86 | 87 | if (opts) { 88 | ts->ts_attr = malloc(sizeof (pthread_attr_t)); 89 | (void) pthread_attr_init(ts->ts_attr); 90 | if ((errors = pthread_attr_setstacksize(ts->ts_attr, opts)) 91 | != 0) { 92 | errno = errors; 93 | perror("pthread_attr_setstacksize"); 94 | } 95 | } else 96 | ts->ts_attr = NULL; 97 | 98 | return (errors?1:0); 99 | } 100 | 101 | int 102 | benchmark_initbatch(void *tsd) 103 | { 104 | tsd_t *ts = (tsd_t *)tsd; 105 | 106 | (void) pthread_mutex_lock(&ts->ts_lock); 107 | 108 | return (0); 109 | } 110 | 111 | 112 | void * 113 | func(void *tsd) 114 | { 115 | tsd_t *ts = (tsd_t *)tsd; 116 | 117 | (void) pthread_mutex_lock(&ts->ts_lock); 118 | (void) pthread_mutex_unlock(&ts->ts_lock); 119 | 120 | return (tsd); 121 | } 122 | 123 | int 124 | benchmark(void *tsd, result_t *res) 125 | { 126 | int i; 127 | tsd_t *ts = (tsd_t *)tsd; 128 | int error; 129 | 130 | for (i = 0; i < lm_optB; i++) { 131 | if ((error = pthread_create(ts->ts_threads + i, 132 | ts->ts_attr, func, tsd)) != 0) { 133 | errno = error; 134 | perror("pthread_create"); 135 | ts->ts_threads[i] = 0; 136 | res->re_errors++; 137 | return (0); 138 | } 139 | } 140 | res->re_count = lm_optB; 141 | 142 | return (0); 143 | } 144 | 145 | int 146 | benchmark_finibatch(void *tsd) 147 | { 148 | tsd_t *ts = (tsd_t *)tsd; 149 | int i; 150 | int errors = 0; 151 | 152 | (void) pthread_mutex_unlock(&ts->ts_lock); 153 | 154 | for (i = 0; i < lm_optB; i++) 155 | if (ts->ts_threads[i] == 0 || 156 | pthread_join(ts->ts_threads[i], NULL) < 0) { 157 | errors++; 158 | } 159 | return (errors); 160 | } 161 | -------------------------------------------------------------------------------- /pwrite.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #ifdef linux 32 | #define _XOPEN_SOURCE 500 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | typedef struct { 43 | char *ts_buf; 44 | } tsd_t; 45 | 46 | #define DEFF "/dev/null" 47 | #define DEFS 1024 48 | 49 | static int optc = 0; 50 | static char *optf = DEFF; 51 | static long long opts = DEFS; 52 | static int fd = -1; 53 | 54 | int 55 | benchmark_init() 56 | { 57 | lm_tsdsize = sizeof (tsd_t); 58 | 59 | (void) sprintf(lm_optstr, "cf:s:"); 60 | 61 | (void) sprintf(lm_usage, 62 | " [-f file-to-write (default %s)]\n" 63 | " [-s buffer-size (default %d)]\n" 64 | " [-c ] (make sure buffer is in cache)\n" 65 | "notes: measures pwrite()\n", 66 | DEFF, DEFS); 67 | 68 | (void) sprintf(lm_header, "%8s", "size"); 69 | 70 | return (0); 71 | } 72 | 73 | int 74 | benchmark_optswitch(int opt, char *optarg) 75 | { 76 | switch (opt) { 77 | case 'c': 78 | optc++; 79 | break; 80 | case 'f': 81 | optf = optarg; 82 | break; 83 | case 's': 84 | opts = sizetoll(optarg); 85 | break; 86 | default: 87 | return (-1); 88 | } 89 | return (0); 90 | } 91 | 92 | int 93 | benchmark_initrun() 94 | { 95 | fd = open(optf, O_WRONLY); 96 | if (fd == -1) { 97 | return (-1); 98 | } 99 | 100 | return (0); 101 | } 102 | 103 | int 104 | benchmark_finirun() 105 | { 106 | return (0); 107 | } 108 | 109 | int 110 | benchmark_initbatch(void *tsd) 111 | { 112 | tsd_t *ts = (tsd_t *)tsd; 113 | int i; 114 | 115 | if (ts->ts_buf == NULL) { 116 | ts->ts_buf = malloc(opts); 117 | 118 | /* 119 | * bring buf into cache if specified. 120 | */ 121 | 122 | if (optc) 123 | for (i = 0; i < opts; i++) 124 | ts->ts_buf[i] = 0; 125 | } 126 | 127 | return (0); 128 | } 129 | 130 | int 131 | benchmark(void *tsd, result_t *res) 132 | { 133 | tsd_t *ts = (tsd_t *)tsd; 134 | int i; 135 | 136 | for (i = 0; i < lm_optB; i++) { 137 | if (pwrite(fd, ts->ts_buf, opts, 0) != opts) { 138 | res->re_errors++; 139 | } 140 | } 141 | res->re_count = i; 142 | 143 | return (0); 144 | } 145 | 146 | char * 147 | benchmark_result() 148 | { 149 | static char result[256]; 150 | 151 | (void) sprintf(result, "%8lld", opts); 152 | 153 | return (result); 154 | } 155 | -------------------------------------------------------------------------------- /read.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | 32 | #ifdef linux 33 | #define _XOPEN_SOURCE 500 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "libmicro.h" 42 | 43 | typedef struct { 44 | char *ts_buf; 45 | int ts_fd; 46 | } tsd_t; 47 | 48 | #define DEFF "/dev/zero" 49 | #define DEFS 1024 50 | 51 | static char *optf = DEFF; 52 | static long long opts = DEFS; 53 | int optw = 0; 54 | 55 | int 56 | benchmark_init() 57 | { 58 | lm_tsdsize = sizeof (tsd_t); 59 | 60 | (void) sprintf(lm_optstr, "f:s:w"); 61 | 62 | (void) sprintf(lm_usage, 63 | " [-f file-to-read (default %s)]\n" 64 | " [-s buffer-size (default %d)]\n" 65 | " [-w (store a byte to each page after read)]\n" 66 | "notes: measures read()\n", 67 | DEFF, DEFS); 68 | 69 | (void) sprintf(lm_header, "%8s", "size"); 70 | 71 | lm_defB = 1; 72 | 73 | return (0); 74 | } 75 | 76 | int 77 | benchmark_optswitch(int opt, char *optarg) 78 | { 79 | switch (opt) { 80 | case 'w': 81 | optw = getpagesize(); 82 | break; 83 | case 'f': 84 | optf = optarg; 85 | break; 86 | case 's': 87 | opts = sizetoll(optarg); 88 | break; 89 | default: 90 | return (-1); 91 | } 92 | return (0); 93 | } 94 | 95 | int 96 | benchmark_initrun() 97 | { 98 | return (0); 99 | } 100 | 101 | int 102 | benchmark_initbatch(void *tsd) 103 | { 104 | tsd_t *ts = (tsd_t *)tsd; 105 | 106 | if (ts->ts_buf == NULL) { 107 | ts->ts_buf = malloc(opts); 108 | ts->ts_fd = open(optf, O_RDONLY); 109 | } 110 | 111 | (void) lseek(ts->ts_fd, 0, SEEK_SET); 112 | 113 | return (0); 114 | } 115 | 116 | int 117 | benchmark(void *tsd, result_t *res) 118 | { 119 | tsd_t *ts = (tsd_t *)tsd; 120 | int i; 121 | int j; 122 | for (i = 0; i < lm_optB; i++) { 123 | if (read(ts->ts_fd, ts->ts_buf, opts) != opts) { 124 | res->re_errors++; 125 | } 126 | if (optw) 127 | for (j = 0; j < opts; j += optw) 128 | ts->ts_buf[j] = 0; 129 | } 130 | res->re_count = i; 131 | 132 | return (0); 133 | } 134 | 135 | char * 136 | benchmark_result() 137 | { 138 | static char result[256]; 139 | 140 | (void) sprintf(result, "%8lld", opts); 141 | 142 | return (result); 143 | } 144 | -------------------------------------------------------------------------------- /realpath.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | #define DEFF "/" 39 | #define MAXPATHLEN 1024 40 | 41 | static char *optf = DEFF; 42 | 43 | int 44 | benchmark_init() 45 | { 46 | (void) sprintf(lm_optstr, "f:"); 47 | 48 | lm_tsdsize = 0; 49 | 50 | (void) sprintf(lm_usage, 51 | " [-f directory (default = %s)]\n" 52 | "notes: measures realpath()\n", 53 | DEFF); 54 | 55 | return (0); 56 | } 57 | 58 | int 59 | benchmark_optswitch(int opt, char *optarg) 60 | { 61 | switch (opt) { 62 | case 'f': 63 | optf = optarg; 64 | break; 65 | default: 66 | return (-1); 67 | } 68 | return (0); 69 | } 70 | 71 | /*ARGSUSED*/ 72 | int 73 | benchmark(void *tsd, result_t *res) 74 | { 75 | int i; 76 | char path[MAXPATHLEN]; 77 | 78 | for (i = 0; i < lm_optB; i++) { 79 | if (realpath(optf, path) == NULL) 80 | res->re_errors++; 81 | } 82 | res->re_count = i; 83 | 84 | return (0); 85 | } 86 | -------------------------------------------------------------------------------- /recurse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "libmicro.h" 38 | 39 | #define DEFD 100 40 | 41 | static int optd = DEFD; 42 | 43 | int recurse2(int x, int y, char *s); 44 | 45 | /*ARGSUSED*/ 46 | int 47 | recurse1(int x, int y, char *s) 48 | { 49 | char str[32]; 50 | 51 | if (x < y) { 52 | return (recurse2(x + 1, y, str)); 53 | } 54 | 55 | return (x); 56 | } 57 | 58 | int 59 | benchmark_init() 60 | { 61 | lm_tsdsize = 0; 62 | 63 | (void) sprintf(lm_optstr, "d:"); 64 | 65 | (void) sprintf(lm_usage, 66 | " [-d depth-limit (default = %d)]\n" 67 | "notes: measures recursion performance\n", 68 | DEFD); 69 | 70 | return (0); 71 | } 72 | 73 | int 74 | benchmark_optswitch(int opt, char *optarg) 75 | { 76 | switch (opt) { 77 | case 'd': 78 | optd = atoi(optarg); 79 | break; 80 | default: 81 | return (-1); 82 | } 83 | return (0); 84 | } 85 | 86 | /*ARGSUSED*/ 87 | int 88 | benchmark(void *tsd, result_t *res) 89 | { 90 | int i; 91 | 92 | for (i = 0; i < lm_optB; i++) { 93 | (void) recurse1(0, optd, NULL); 94 | } 95 | res->re_count = i; 96 | 97 | return (0); 98 | } 99 | -------------------------------------------------------------------------------- /recurse2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | 33 | int recurse1(int x, int y, char *s); 34 | 35 | /*ARGSUSED*/ 36 | int 37 | recurse2(int x, int y, char *s) 38 | { 39 | char str[32]; 40 | 41 | if (x < y) { 42 | return (recurse1(x + 1, y, str)); 43 | } 44 | 45 | return (x); 46 | } 47 | -------------------------------------------------------------------------------- /semop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "libmicro.h" 39 | 40 | 41 | typedef struct { 42 | int ts_semid; 43 | } tsd_t; 44 | 45 | int 46 | benchmark_init() 47 | { 48 | lm_tsdsize = sizeof (tsd_t); 49 | 50 | (void) sprintf(lm_usage, "notes: measures semop()\n"); 51 | 52 | return (0); 53 | } 54 | 55 | int 56 | benchmark_initbatch(void *tsd) 57 | { 58 | 59 | tsd_t *ts = (tsd_t *)tsd; 60 | 61 | if ((ts->ts_semid = semget(IPC_PRIVATE, 2, 0600)) == -1) { 62 | return (-1); 63 | } 64 | 65 | return (0); 66 | } 67 | 68 | int 69 | benchmark_finibatch(void *tsd) 70 | { 71 | tsd_t *ts = (tsd_t *)tsd; 72 | 73 | (void) semctl(ts->ts_semid, 0, IPC_RMID); 74 | 75 | return (0); 76 | } 77 | 78 | int 79 | benchmark(void *tsd, result_t *res) 80 | { 81 | int i; 82 | tsd_t *ts = (tsd_t *)tsd; 83 | struct sembuf s[1]; 84 | 85 | for (i = 0; i < lm_optB; i++) { 86 | s[0].sem_num = 0; 87 | s[0].sem_op = 1; 88 | s[0].sem_flg = 0; 89 | if (semop(ts->ts_semid, s, 1) == -1) { 90 | res->re_errors++; 91 | } 92 | s[0].sem_num = 0; 93 | s[0].sem_op = -1; 94 | s[0].sem_flg = 0; 95 | if (semop(ts->ts_semid, s, 1) == -1) { 96 | res->re_errors++; 97 | } 98 | } 99 | 100 | res->re_count += lm_optB; 101 | 102 | return (0); 103 | } 104 | -------------------------------------------------------------------------------- /setcontext.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | int 39 | benchmark_init() 40 | { 41 | 42 | (void) sprintf(lm_usage, "notes: measures setcontext()\n"); 43 | 44 | lm_tsdsize = 0; 45 | 46 | return (0); 47 | } 48 | 49 | /*ARGSUSED*/ 50 | int 51 | benchmark(void *tsd, result_t *res) 52 | { 53 | volatile int i; 54 | 55 | ucontext_t uc; 56 | 57 | i = 0; 58 | 59 | (void) getcontext(&uc); 60 | 61 | if (i++ < lm_optB) 62 | (void) setcontext(&uc); 63 | 64 | res->re_count += lm_optB; 65 | 66 | return (0); 67 | } 68 | -------------------------------------------------------------------------------- /setsockopt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "libmicro.h" 45 | 46 | typedef struct { 47 | int ts_fd; 48 | } tsd_t; 49 | 50 | int 51 | benchmark_init() 52 | { 53 | lm_tsdsize = sizeof (tsd_t); 54 | 55 | (void) sprintf(lm_usage, "setsockopt(TCP_NODELAY)\n"); 56 | 57 | return (0); 58 | } 59 | 60 | int 61 | benchmark_initbatch(void *tsd) 62 | { 63 | 64 | tsd_t *ts = (tsd_t *)tsd; 65 | 66 | if ((ts->ts_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 67 | return (1); 68 | return (0); 69 | } 70 | 71 | int 72 | benchmark_finibatch(void *tsd) 73 | { 74 | tsd_t *ts = (tsd_t *)tsd; 75 | 76 | (void) close(ts->ts_fd); 77 | return (0); 78 | } 79 | 80 | int 81 | benchmark(void *tsd, result_t *res) 82 | { 83 | int i; 84 | tsd_t *ts = (tsd_t *)tsd; 85 | int opt; 86 | 87 | res->re_errors = 0; 88 | 89 | for (i = 0; i < lm_optB; i++) { 90 | opt = 1 & i; 91 | if (setsockopt(ts->ts_fd, IPPROTO_TCP, TCP_NODELAY, 92 | &opt, sizeof (int)) == -1) { 93 | res->re_errors ++; 94 | } 95 | } 96 | res->re_count += lm_optB; 97 | 98 | return (0); 99 | } 100 | -------------------------------------------------------------------------------- /sigaction.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "libmicro.h" 38 | 39 | #ifdef __sun 40 | static void 41 | nop() 42 | { 43 | } 44 | #else 45 | static void 46 | nop(int sig) 47 | { 48 | } 49 | #endif 50 | 51 | 52 | typedef struct { 53 | struct sigaction ts_act; 54 | } tsd_t; 55 | 56 | int 57 | benchmark_init() 58 | { 59 | lm_tsdsize = sizeof (tsd_t); 60 | 61 | (void) sprintf(lm_usage, "notes: measures sigaction()\n"); 62 | 63 | return (0); 64 | } 65 | 66 | int 67 | benchmark_initbatch(void *tsd) 68 | { 69 | 70 | tsd_t *ts = (tsd_t *)tsd; 71 | ts->ts_act.sa_handler = nop; 72 | ts->ts_act.sa_flags = 0; 73 | (void) sigemptyset(&ts->ts_act.sa_mask); 74 | 75 | return (0); 76 | } 77 | 78 | int 79 | benchmark(void *tsd, result_t *res) 80 | { 81 | int i; 82 | tsd_t *ts = (tsd_t *)tsd; 83 | struct sigaction oact; 84 | 85 | res->re_errors = 0; 86 | 87 | for (i = 0; i < lm_optB; i++) { 88 | if (sigaction(SIGUSR1, &ts->ts_act, &oact)) 89 | res->re_errors++; 90 | } 91 | 92 | res->re_count += lm_optB; 93 | 94 | return (0); 95 | } 96 | -------------------------------------------------------------------------------- /siglongjmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | typedef struct { 39 | jmp_buf ts_env; 40 | } tsd_t; 41 | 42 | int 43 | benchmark_init() 44 | { 45 | lm_tsdsize = sizeof (tsd_t); 46 | 47 | lm_tsdsize = 0; 48 | 49 | (void) sprintf(lm_usage, "notes: measures siglongjmp()\n"); 50 | 51 | return (0); 52 | } 53 | 54 | int 55 | benchmark(void *tsd, result_t *res) 56 | { 57 | tsd_t *ts = (tsd_t *)tsd; 58 | 59 | int i = 0; 60 | 61 | (void) sigsetjmp(ts->ts_env, 1); 62 | 63 | if (i++ < lm_optB) 64 | siglongjmp(ts->ts_env, 0); 65 | 66 | res->re_count = lm_optB; 67 | 68 | return (0); 69 | } 70 | -------------------------------------------------------------------------------- /signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "libmicro.h" 38 | 39 | 40 | #ifdef __sun 41 | static void 42 | nop() 43 | { 44 | } 45 | #else 46 | static void 47 | nop(int sig) 48 | { 49 | } 50 | #endif 51 | 52 | int 53 | benchmark_init() 54 | { 55 | lm_tsdsize = 0; 56 | 57 | (void) sprintf(lm_usage, "notes: measures signal()\n"); 58 | 59 | return (0); 60 | } 61 | 62 | int 63 | benchmark_initrun() 64 | { 65 | struct sigaction act; 66 | 67 | act.sa_handler = nop; 68 | act.sa_flags = 0; 69 | 70 | (void) sigemptyset(&act.sa_mask); 71 | (void) sigaction(SIGUSR1, &act, NULL); 72 | 73 | return (0); 74 | } 75 | 76 | /*ARGSUSED*/ 77 | int 78 | benchmark(void *tsd, result_t *res) 79 | { 80 | int i; 81 | int pid; 82 | 83 | pid = getpid(); 84 | 85 | for (i = 0; i < lm_optB; i += 10) { 86 | (void) kill(pid, SIGUSR1); 87 | (void) kill(pid, SIGUSR1); 88 | (void) kill(pid, SIGUSR1); 89 | (void) kill(pid, SIGUSR1); 90 | (void) kill(pid, SIGUSR1); 91 | (void) kill(pid, SIGUSR1); 92 | (void) kill(pid, SIGUSR1); 93 | (void) kill(pid, SIGUSR1); 94 | (void) kill(pid, SIGUSR1); 95 | (void) kill(pid, SIGUSR1); 96 | } 97 | res->re_count += lm_optB; 98 | 99 | return (0); 100 | } 101 | -------------------------------------------------------------------------------- /sigprocmask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | int 39 | benchmark_init() 40 | { 41 | lm_tsdsize = 0; 42 | 43 | (void) sprintf(lm_usage, "notes: measures sigprocmask()\n"); 44 | 45 | return (0); 46 | } 47 | 48 | int 49 | benchmark_initrun() 50 | { 51 | sigset_t iset; 52 | 53 | (void) sigemptyset(&iset); 54 | (void) sigprocmask(SIG_SETMASK, &iset, NULL); 55 | 56 | return (0); 57 | } 58 | /*ARGSUSED*/ 59 | int 60 | benchmark(void *tsd, result_t *res) 61 | { 62 | int i; 63 | sigset_t set0, set1; 64 | 65 | (void) sigemptyset(&set0); 66 | (void) sigaddset(&set0, SIGTERM); 67 | 68 | for (i = 0; i < lm_optB; i += 10) { 69 | (void) sigprocmask(SIG_SETMASK, &set0, &set1); 70 | (void) sigprocmask(SIG_SETMASK, &set1, &set0); 71 | (void) sigprocmask(SIG_SETMASK, &set0, &set1); 72 | (void) sigprocmask(SIG_SETMASK, &set1, &set0); 73 | (void) sigprocmask(SIG_SETMASK, &set0, &set1); 74 | (void) sigprocmask(SIG_SETMASK, &set1, &set0); 75 | (void) sigprocmask(SIG_SETMASK, &set0, &set1); 76 | (void) sigprocmask(SIG_SETMASK, &set1, &set0); 77 | (void) sigprocmask(SIG_SETMASK, &set0, &set1); 78 | (void) sigprocmask(SIG_SETMASK, &set1, &set0); 79 | } 80 | 81 | res->re_count += lm_optB; 82 | 83 | return (0); 84 | } 85 | -------------------------------------------------------------------------------- /socket.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "libmicro.h" 38 | 39 | typedef struct { 40 | int ts_once; 41 | int *ts_fds; 42 | } tsd_t; 43 | 44 | #define DEFF "PF_UNIX" 45 | 46 | static char *optf = DEFF; 47 | static int family; 48 | 49 | int 50 | lookup_family(char *name) 51 | { 52 | if (strcmp("PF_UNIX", name) == 0) { 53 | return (PF_UNIX); 54 | } else if (strcmp("PF_INET", name) == 0) { 55 | return (PF_INET); 56 | } else if (strcmp("PF_INET6", name) == 0) { 57 | return (PF_INET6); 58 | } 59 | 60 | return (-1); 61 | } 62 | 63 | int 64 | benchmark_init() 65 | { 66 | lm_tsdsize = sizeof (tsd_t); 67 | 68 | lm_defB = 256; 69 | 70 | (void) sprintf(lm_optstr, "f:n"); 71 | 72 | (void) sprintf(lm_usage, 73 | " [-f socket-family (default %s)]\n" 74 | "notes: measures socket\n", 75 | DEFF); 76 | 77 | return (0); 78 | } 79 | 80 | int 81 | benchmark_optswitch(int opt, char *optarg) 82 | { 83 | switch (opt) { 84 | case 'f': 85 | optf = optarg; 86 | break; 87 | default: 88 | return (-1); 89 | } 90 | 91 | return (0); 92 | } 93 | 94 | 95 | int 96 | benchmark_initrun() 97 | { 98 | (void) setfdlimit(lm_optB * lm_optT + 10); 99 | family = lookup_family(optf); 100 | 101 | return (0); 102 | } 103 | 104 | int 105 | benchmark_finirun() 106 | { 107 | return (0); 108 | } 109 | 110 | int 111 | benchmark_initbatch(void *tsd) 112 | { 113 | int i; 114 | tsd_t *ts = (tsd_t *)tsd; 115 | 116 | if (ts->ts_once++ == 0) { 117 | ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); 118 | if (ts->ts_fds == NULL) { 119 | return (1); 120 | } 121 | for (i = 0; i < lm_optB; i++) { 122 | ts->ts_fds[i] = -1; 123 | } 124 | } 125 | 126 | return (0); 127 | } 128 | 129 | int 130 | benchmark(void *tsd, result_t *res) 131 | { 132 | int i; 133 | tsd_t *ts = (tsd_t *)tsd; 134 | 135 | for (i = 0; i < lm_optB; i++) { 136 | ts->ts_fds[i] = socket(family, SOCK_STREAM, 0); 137 | if (ts->ts_fds[i] == -1) { 138 | res->re_errors++; 139 | } 140 | } 141 | res->re_count += lm_optB; 142 | 143 | return (0); 144 | } 145 | 146 | int 147 | benchmark_finibatch(void *tsd) 148 | { 149 | int i; 150 | tsd_t *ts = (tsd_t *)tsd; 151 | 152 | for (i = 0; i < lm_optB; i++) { 153 | (void) close(ts->ts_fds[i]); 154 | } 155 | 156 | return (0); 157 | } 158 | -------------------------------------------------------------------------------- /socketpair.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "libmicro.h" 38 | 39 | typedef struct { 40 | int ts_once; 41 | int *ts_fds; 42 | } tsd_t; 43 | 44 | #define DEFN 256 45 | 46 | 47 | int 48 | benchmark_init() 49 | { 50 | lm_tsdsize = sizeof (tsd_t); 51 | 52 | lm_defB = 256; 53 | 54 | (void) sprintf(lm_usage, 55 | "notes: measures socketpair\n"); 56 | 57 | return (0); 58 | } 59 | 60 | 61 | int 62 | benchmark_initrun() 63 | { 64 | (void) setfdlimit(lm_optB * lm_optT + 10); 65 | return (0); 66 | } 67 | 68 | int 69 | benchmark_initbatch(void *tsd) 70 | { 71 | int i; 72 | tsd_t *ts = (tsd_t *)tsd; 73 | 74 | if (ts->ts_once++ == 0) { 75 | ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); 76 | if (ts->ts_fds == NULL) { 77 | return (1); 78 | } 79 | for (i = 0; i < lm_optB; i++) { 80 | ts->ts_fds[i] = -1; 81 | } 82 | } 83 | 84 | return (0); 85 | } 86 | 87 | int 88 | benchmark(void *tsd, result_t *res) 89 | { 90 | int i; 91 | tsd_t *ts = (tsd_t *)tsd; 92 | 93 | res->re_count = 0; 94 | res->re_errors = 0; 95 | 96 | for (i = 0; i < lm_optB; i += 2) { 97 | if (socketpair(PF_UNIX, SOCK_STREAM, 0, &ts->ts_fds[i]) 98 | == -1) { 99 | res->re_errors++; 100 | } 101 | } 102 | res->re_count = lm_optB / 2; 103 | 104 | return (0); 105 | } 106 | 107 | int 108 | benchmark_finibatch(void *tsd) 109 | { 110 | int i; 111 | tsd_t *ts = (tsd_t *)tsd; 112 | 113 | for (i = 0; i < lm_optB; i++) { 114 | (void) close(ts->ts_fds[i]); 115 | } 116 | 117 | return (0); 118 | } 119 | -------------------------------------------------------------------------------- /stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "libmicro.h" 38 | 39 | #define DEFF "/dev/null" 40 | static char *optf = DEFF; 41 | 42 | int 43 | benchmark_init() 44 | { 45 | 46 | (void) sprintf(lm_optstr, "f:"); 47 | 48 | lm_tsdsize = 0; 49 | 50 | (void) sprintf(lm_usage, 51 | " [-f file-to-stat (default %s)]\n" 52 | "notes: measures stat()\n", 53 | DEFF); 54 | 55 | return (0); 56 | } 57 | 58 | int 59 | benchmark_optswitch(int opt, char *optarg) 60 | { 61 | switch (opt) { 62 | case 'f': 63 | optf = optarg; 64 | break; 65 | default: 66 | return (-1); 67 | } 68 | return (0); 69 | } 70 | 71 | /*ARGSUSED*/ 72 | int 73 | benchmark(void *tsd, result_t *res) 74 | { 75 | int i; 76 | struct stat sbuf; 77 | 78 | res->re_errors = 0; 79 | 80 | for (i = 0; i < lm_optB; i++) { 81 | if (stat(optf, &sbuf) == -1) 82 | res->re_errors++; 83 | } 84 | 85 | res->re_count += lm_optB; 86 | 87 | return (0); 88 | } 89 | -------------------------------------------------------------------------------- /strcasecmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | 39 | static int unaligned = 0; 40 | static int opts = 100; 41 | 42 | typedef struct { 43 | int ts_once; 44 | char *ts_a; 45 | char *ts_b; 46 | int ts_fakegcc; 47 | } tsd_t; 48 | 49 | int 50 | benchmark_init() 51 | { 52 | 53 | lm_tsdsize = sizeof (tsd_t); 54 | 55 | (void) sprintf(lm_optstr, "s:n"); 56 | 57 | (void) sprintf(lm_usage, 58 | " [-s string size (default %d)]\n" 59 | " [-n causes unaligned cmp]\n" 60 | "notes: measures strcasecmp()\n", 61 | opts); 62 | 63 | (void) sprintf(lm_header, "%8s", "size"); 64 | 65 | return (0); 66 | } 67 | 68 | int 69 | benchmark_optswitch(int opt, char *optarg) 70 | { 71 | switch (opt) { 72 | case 'n': 73 | unaligned = 1; 74 | break; 75 | case 's': 76 | opts = sizetoll(optarg); 77 | break; 78 | default: 79 | return (-1); 80 | } 81 | return (0); 82 | } 83 | 84 | int 85 | benchmark_initbatch(void *tsd) 86 | { 87 | tsd_t *ts = (tsd_t *)tsd; 88 | 89 | static char *demo = 90 | "The quick brown fox jumps over the lazy dog."; 91 | 92 | if (ts->ts_once++ == 0) { 93 | int l = strlen(demo); 94 | int i; 95 | 96 | ts->ts_a = malloc(opts + 1); 97 | ts->ts_b = malloc(opts + 1 + unaligned); 98 | ts->ts_b += unaligned; 99 | 100 | for (i = 0; i < opts; i++) { 101 | ts->ts_a[i] = ts->ts_b[i] = demo[i%l]; 102 | } 103 | ts->ts_a[opts] = 0; 104 | ts->ts_b[opts] = 0; 105 | } 106 | return (0); 107 | } 108 | 109 | int 110 | benchmark(void *tsd, result_t *res) 111 | { 112 | int i; 113 | tsd_t *ts = (tsd_t *)tsd; 114 | 115 | char *src = ts->ts_a; 116 | char *src2 = ts->ts_b; 117 | int *sum = &ts->ts_fakegcc; 118 | 119 | res->re_errors = 0; 120 | 121 | for (i = 0; i < lm_optB; i += 10) { 122 | *sum += strcasecmp(src, src2); 123 | *sum += strcasecmp(src, src2); 124 | *sum += strcasecmp(src, src2); 125 | *sum += strcasecmp(src, src2); 126 | *sum += strcasecmp(src, src2); 127 | *sum += strcasecmp(src, src2); 128 | *sum += strcasecmp(src, src2); 129 | *sum += strcasecmp(src, src2); 130 | *sum += strcasecmp(src, src2); 131 | *sum += strcasecmp(src, src2); 132 | } 133 | 134 | res->re_count = lm_optB; 135 | 136 | return (0); 137 | } 138 | 139 | char * 140 | benchmark_result() 141 | { 142 | static char result[256]; 143 | 144 | if (unaligned == 0) 145 | (void) sprintf(result, "%8d", opts); 146 | else 147 | (void) sprintf(result, "%8d ", opts); 148 | 149 | return (result); 150 | } 151 | -------------------------------------------------------------------------------- /strchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | static int unaligned = 0; 39 | static int opts = 100; 40 | 41 | typedef struct { 42 | int ts_once; 43 | char *ts_string; 44 | char *ts_fakegcc; 45 | } tsd_t; 46 | 47 | int 48 | benchmark_init() 49 | { 50 | 51 | lm_tsdsize = sizeof (tsd_t); 52 | 53 | (void) sprintf(lm_optstr, "s:n"); 54 | 55 | (void) sprintf(lm_usage, 56 | " [-s string size (default %d)]\n" 57 | " [-n causes unaligned strchr]\n" 58 | "notes: measures strchr()\n", 59 | opts); 60 | 61 | (void) sprintf(lm_header, "%8s", "size"); 62 | 63 | return (0); 64 | } 65 | 66 | int 67 | benchmark_optswitch(int opt, char *optarg) 68 | { 69 | switch (opt) { 70 | case 'n': 71 | unaligned = 1; 72 | break; 73 | case 's': 74 | opts = sizetoll(optarg); 75 | break; 76 | default: 77 | return (-1); 78 | } 79 | return (0); 80 | } 81 | 82 | int 83 | benchmark_initbatch(void *tsd) 84 | { 85 | tsd_t *ts = (tsd_t *)tsd; 86 | 87 | static char *demo = 88 | "The quick brown fox jumps over the lazy dog."; 89 | 90 | if (ts->ts_once++ == 0) { 91 | int l = strlen(demo); 92 | int i; 93 | 94 | ts->ts_string = malloc(opts + 1 + unaligned); 95 | ts->ts_string += unaligned; 96 | 97 | 98 | for (i = 0; i < opts; i++) { 99 | ts->ts_string[i] = demo[i%l]; 100 | } 101 | 102 | ts->ts_string[opts] = 0; 103 | 104 | } 105 | return (0); 106 | } 107 | 108 | int 109 | benchmark(void *tsd, result_t *res) 110 | { 111 | int i; 112 | tsd_t *ts = (tsd_t *)tsd; 113 | char *src = ts->ts_string; 114 | 115 | for (i = 0; i < lm_optB; i += 10) { 116 | ts->ts_fakegcc = strchr(src, 'X'); 117 | ts->ts_fakegcc = strchr(src, 'X'); 118 | ts->ts_fakegcc = strchr(src, 'X'); 119 | ts->ts_fakegcc = strchr(src, 'X'); 120 | ts->ts_fakegcc = strchr(src, 'X'); 121 | ts->ts_fakegcc = strchr(src, 'X'); 122 | ts->ts_fakegcc = strchr(src, 'X'); 123 | ts->ts_fakegcc = strchr(src, 'X'); 124 | ts->ts_fakegcc = strchr(src, 'X'); 125 | ts->ts_fakegcc = strchr(src, 'X'); 126 | } 127 | 128 | res->re_count = lm_optB; 129 | 130 | return (0); 131 | } 132 | 133 | char * 134 | benchmark_result() 135 | { 136 | static char result[256]; 137 | 138 | if (unaligned == 0) 139 | (void) sprintf(result, "%8d", opts); 140 | else 141 | (void) sprintf(result, "%8d ", opts); 142 | 143 | return (result); 144 | } 145 | -------------------------------------------------------------------------------- /strcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | static int unaligned = 0; 39 | static int opts = 100; 40 | 41 | typedef struct { 42 | int ts_once; 43 | char *ts_a; 44 | char *ts_b; 45 | int ts_fakegcc; 46 | } tsd_t; 47 | 48 | int 49 | benchmark_init() 50 | { 51 | 52 | lm_tsdsize = sizeof (tsd_t); 53 | 54 | (void) sprintf(lm_optstr, "s:n"); 55 | 56 | (void) sprintf(lm_usage, 57 | " [-s string size (default %d)]\n" 58 | " [-n causes unaligned cmp]\n" 59 | "notes: measures strcmp()\n", 60 | opts); 61 | 62 | (void) sprintf(lm_header, "%8s", "size"); 63 | 64 | return (0); 65 | } 66 | 67 | int 68 | benchmark_optswitch(int opt, char *optarg) 69 | { 70 | switch (opt) { 71 | case 'n': 72 | unaligned = 1; 73 | break; 74 | case 's': 75 | opts = sizetoll(optarg); 76 | break; 77 | default: 78 | return (-1); 79 | } 80 | return (0); 81 | } 82 | 83 | int 84 | benchmark_initbatch(void *tsd) 85 | { 86 | tsd_t *ts = (tsd_t *)tsd; 87 | static char *demo = 88 | "The quick brown fox jumps over the lazy dog."; 89 | 90 | if (ts->ts_once++ == 0) { 91 | int l = strlen(demo); 92 | int i; 93 | 94 | ts->ts_a = malloc(opts + 1); 95 | ts->ts_b = malloc(opts + 1 + unaligned); 96 | ts->ts_b += unaligned; 97 | 98 | for (i = 0; i < opts; i++) { 99 | ts->ts_a[i] = ts->ts_b[i] = demo[i%l]; 100 | } 101 | ts->ts_a[opts] = 0; 102 | ts->ts_b[opts] = 0; 103 | } 104 | return (0); 105 | } 106 | 107 | int 108 | benchmark(void *tsd, result_t *res) 109 | { 110 | int i; 111 | tsd_t *ts = (tsd_t *)tsd; 112 | int *sum = &ts->ts_fakegcc; 113 | char *src = ts->ts_a; 114 | char *src2 = ts->ts_b; 115 | 116 | res->re_errors = 0; 117 | 118 | for (i = 0; i < lm_optB; i += 10) { 119 | *sum += strcmp(src, src2); 120 | *sum += strcmp(src, src2); 121 | *sum += strcmp(src, src2); 122 | *sum += strcmp(src, src2); 123 | *sum += strcmp(src, src2); 124 | *sum += strcmp(src, src2); 125 | *sum += strcmp(src, src2); 126 | *sum += strcmp(src, src2); 127 | *sum += strcmp(src, src2); 128 | *sum += strcmp(src, src2); 129 | } 130 | 131 | res->re_count = lm_optB; 132 | 133 | return (0); 134 | } 135 | 136 | char * 137 | benchmark_result() 138 | { 139 | static char result[256]; 140 | 141 | if (unaligned == 0) 142 | (void) sprintf(result, "%8d", opts); 143 | else 144 | (void) sprintf(result, "%8d ", opts); 145 | 146 | return (result); 147 | } 148 | -------------------------------------------------------------------------------- /strcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | static int unaligned = 0; 39 | static int opts = 100; 40 | 41 | typedef struct { 42 | int ts_once; 43 | char *ts_a; 44 | char *ts_b; 45 | } tsd_t; 46 | 47 | int 48 | benchmark_init() 49 | { 50 | 51 | lm_tsdsize = sizeof (tsd_t); 52 | 53 | (void) sprintf(lm_optstr, "s:n"); 54 | 55 | (void) sprintf(lm_usage, 56 | " [-s string size (default %d)]\n" 57 | " [-n causes unaligned cmp]\n" 58 | "notes: measures strcpy()\n", 59 | opts); 60 | 61 | (void) sprintf(lm_header, "%8s", "size"); 62 | 63 | return (0); 64 | } 65 | 66 | int 67 | benchmark_optswitch(int opt, char *optarg) 68 | { 69 | switch (opt) { 70 | case 'n': 71 | unaligned = 1; 72 | break; 73 | case 's': 74 | opts = sizetoll(optarg); 75 | break; 76 | default: 77 | return (-1); 78 | } 79 | return (0); 80 | } 81 | 82 | int 83 | benchmark_initbatch(void *tsd) 84 | { 85 | tsd_t *ts = (tsd_t *)tsd; 86 | static char *demo = 87 | "The quick brown fox jumps over the lazy dog."; 88 | 89 | if (ts->ts_once++ == 0) { 90 | int l = strlen(demo); 91 | int i; 92 | 93 | ts->ts_a = malloc(opts + 1); 94 | ts->ts_b = malloc(opts + 1 + unaligned); 95 | ts->ts_b += unaligned; 96 | 97 | for (i = 0; i < opts; i++) { 98 | ts->ts_b[i] = demo[i%l]; 99 | } 100 | ts->ts_b[opts] = 0; 101 | } 102 | return (0); 103 | } 104 | 105 | int 106 | benchmark(void *tsd, result_t *res) 107 | { 108 | int i; 109 | tsd_t *ts = (tsd_t *)tsd; 110 | 111 | char *src = ts->ts_a; 112 | char *src2 = ts->ts_b; 113 | 114 | res->re_errors = 0; 115 | 116 | for (i = 0; i < lm_optB; i += 10) { 117 | (void) strcpy(src, src2); 118 | (void) strcpy(src, src2); 119 | (void) strcpy(src, src2); 120 | (void) strcpy(src, src2); 121 | (void) strcpy(src, src2); 122 | (void) strcpy(src, src2); 123 | (void) strcpy(src, src2); 124 | (void) strcpy(src, src2); 125 | (void) strcpy(src, src2); 126 | (void) strcpy(src, src2); 127 | } 128 | 129 | res->re_count = lm_optB; 130 | 131 | return (0); 132 | } 133 | 134 | char * 135 | benchmark_result() 136 | { 137 | static char result[256]; 138 | 139 | if (unaligned == 0) 140 | (void) sprintf(result, "%8d", opts); 141 | else 142 | (void) sprintf(result, "%8d ", opts); 143 | 144 | return (result); 145 | } 146 | -------------------------------------------------------------------------------- /strftime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | #define DEFF "%c" 39 | #define MAXSIZE 80 40 | 41 | static char *optf = DEFF; 42 | 43 | typedef struct { 44 | int ts_once; 45 | struct tm ts_tm1; 46 | struct tm ts_tm2; 47 | } tsd_t; 48 | 49 | int 50 | benchmark_init() 51 | { 52 | 53 | lm_tsdsize = sizeof (tsd_t); 54 | 55 | (void) sprintf(lm_optstr, "f:"); 56 | 57 | (void) sprintf(lm_usage, 58 | " [-f format (default = \"%s\")]\n" 59 | "notes: measures strftime()\n", 60 | DEFF); 61 | 62 | (void) sprintf(lm_header, "%8s", "format"); 63 | 64 | return (0); 65 | } 66 | int 67 | benchmark_optswitch(int opt, char *optarg) 68 | { 69 | switch (opt) { 70 | 71 | case 'f': 72 | optf = optarg; 73 | break; 74 | default: 75 | return (-1); 76 | } 77 | return (0); 78 | } 79 | 80 | 81 | char * 82 | benchmark_result() 83 | { 84 | static char result[256]; 85 | 86 | (void) sprintf(result, "%8s", optf); 87 | 88 | return (result); 89 | } 90 | 91 | 92 | int 93 | benchmark_initbatch(void *tsd) 94 | { 95 | tsd_t *ts = (tsd_t *)tsd; 96 | 97 | static time_t clock1 = 0L; 98 | static time_t clock2 = 1L; 99 | 100 | (void) localtime_r(&clock1, &ts->ts_tm1); 101 | (void) localtime_r(&clock2, &ts->ts_tm2); 102 | 103 | return (0); 104 | } 105 | 106 | 107 | int 108 | benchmark(void *tsd, result_t *res) 109 | { 110 | int i; 111 | tsd_t *ts = (tsd_t *)tsd; 112 | char s[MAXSIZE]; 113 | 114 | for (i = 0; i < lm_optB; i += 10) { 115 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); 116 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); 117 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); 118 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); 119 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); 120 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); 121 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); 122 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); 123 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); 124 | (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); 125 | } 126 | res->re_count = lm_optB; 127 | 128 | return (0); 129 | } 130 | -------------------------------------------------------------------------------- /strlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | static int unaligned = 0; 39 | static int opts = 100; 40 | 41 | typedef struct { 42 | int ts_once; 43 | char *ts_string; 44 | int ts_fakegcc; 45 | } tsd_t; 46 | 47 | int 48 | benchmark_init() 49 | { 50 | 51 | lm_tsdsize = sizeof (tsd_t); 52 | 53 | (void) sprintf(lm_optstr, "s:n"); 54 | 55 | (void) sprintf(lm_usage, 56 | " [-s string size (default %d)]\n" 57 | " [-n causes unaligned strlen]\n" 58 | "notes: measures strlen()\n", 59 | opts); 60 | 61 | (void) sprintf(lm_header, "%8s", "size"); 62 | 63 | return (0); 64 | } 65 | 66 | int 67 | benchmark_optswitch(int opt, char *optarg) 68 | { 69 | switch (opt) { 70 | case 'n': 71 | unaligned = 1; 72 | break; 73 | case 's': 74 | opts = sizetoll(optarg); 75 | break; 76 | default: 77 | return (-1); 78 | } 79 | return (0); 80 | } 81 | 82 | int 83 | benchmark_initbatch(void *tsd) 84 | { 85 | tsd_t *ts = (tsd_t *)tsd; 86 | static char *demo = 87 | "The quick brown fox jumps over the lazy dog."; 88 | 89 | if (ts->ts_once++ == 0) { 90 | int l = strlen(demo); 91 | int i; 92 | 93 | ts->ts_string = malloc(opts + 1 + unaligned); 94 | ts->ts_string += unaligned; 95 | 96 | 97 | for (i = 0; i < opts; i++) { 98 | ts->ts_string[i] = demo[i%l]; 99 | } 100 | 101 | ts->ts_string[opts] = 0; 102 | 103 | } 104 | return (0); 105 | } 106 | 107 | int 108 | benchmark(void *tsd, result_t *res) 109 | { 110 | int i; 111 | tsd_t *ts = (tsd_t *)tsd; 112 | char *src = ts->ts_string; 113 | 114 | for (i = 0; i < lm_optB; i += 10) { 115 | ts->ts_fakegcc += strlen(src); 116 | ts->ts_fakegcc += strlen(src); 117 | ts->ts_fakegcc += strlen(src); 118 | ts->ts_fakegcc += strlen(src); 119 | ts->ts_fakegcc += strlen(src); 120 | ts->ts_fakegcc += strlen(src); 121 | ts->ts_fakegcc += strlen(src); 122 | ts->ts_fakegcc += strlen(src); 123 | ts->ts_fakegcc += strlen(src); 124 | ts->ts_fakegcc += strlen(src); 125 | } 126 | 127 | res->re_count = lm_optB; 128 | 129 | return (0); 130 | } 131 | 132 | char * 133 | benchmark_result() 134 | { 135 | static char result[256]; 136 | 137 | if (unaligned == 0) 138 | (void) sprintf(result, "%8d", opts); 139 | else 140 | (void) sprintf(result, "%8d ", opts); 141 | 142 | return (result); 143 | } 144 | -------------------------------------------------------------------------------- /strtol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "libmicro.h" 37 | 38 | int 39 | benchmark_init() 40 | { 41 | (void) sprintf(lm_usage, "note: measures strtol()"); 42 | lm_tsdsize = 0; 43 | return (0); 44 | } 45 | 46 | /*ARGSUSED*/ 47 | int 48 | benchmark(void *tsd, result_t *res) 49 | { 50 | int i; 51 | 52 | for (i = 0; i < lm_optB; i += 10) { 53 | (void) strtol("1", NULL, 10); 54 | (void) strtol("11", NULL, 10); 55 | (void) strtol("123", NULL, 10); 56 | (void) strtol("1234", NULL, 10); 57 | (void) strtol("12345", NULL, 10); 58 | (void) strtol("123456", NULL, 10); 59 | (void) strtol("1234567", NULL, 10); 60 | (void) strtol("12345678", NULL, 10); 61 | (void) strtol("123456789", NULL, 10); 62 | (void) strtol("1234567890", NULL, 10); 63 | } 64 | res->re_count = i; 65 | 66 | return (0); 67 | } 68 | -------------------------------------------------------------------------------- /system.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "libmicro.h" 36 | 37 | #define DEFB 10 38 | #define DEFC "A=$$" 39 | 40 | static char *optc = DEFC; 41 | 42 | int 43 | benchmark_init() 44 | { 45 | lm_tsdsize = 0; 46 | 47 | (void) sprintf(lm_optstr, "c:"); 48 | 49 | (void) sprintf(lm_usage, 50 | " [-c command (default %s)]\n" 51 | "notes: measures system()\n", 52 | DEFC); 53 | 54 | (void) sprintf(lm_header, "%8s", "command"); 55 | 56 | return (0); 57 | } 58 | 59 | int 60 | benchmark_optswitch(int opt, char *optarg) 61 | { 62 | switch (opt) { 63 | case 'c': 64 | optc = optarg; 65 | break; 66 | default: 67 | return (-1); 68 | } 69 | 70 | return (0); 71 | } 72 | 73 | 74 | /*ARGSUSED*/ 75 | int 76 | benchmark(void *tsd, result_t *res) 77 | { 78 | int i; 79 | 80 | for (i = 0; i < lm_optB; i++) { 81 | if (system(optc) != 0) { 82 | res->re_errors++; 83 | } 84 | } 85 | res->re_count = lm_optB; 86 | 87 | return (0); 88 | } 89 | 90 | char * 91 | benchmark_result() 92 | { 93 | static char result[256]; 94 | 95 | (void) sprintf(result, "%8s", optc); 96 | 97 | return (result); 98 | } 99 | -------------------------------------------------------------------------------- /tattle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "libmicro.h" 39 | #include 40 | 41 | 42 | #ifdef USE_RDTSC 43 | #ifdef __GNUC__ 44 | #define ENABLE_RDTSC 1 45 | #endif 46 | #endif 47 | 48 | /* 49 | * dummy so we can link w/ libmicro 50 | */ 51 | 52 | /*ARGSUSED*/ 53 | int 54 | benchmark(void *tsd, result_t *res) 55 | { 56 | return (0); 57 | } 58 | 59 | static void 60 | cleanup(char *s) 61 | { 62 | char *o = s; 63 | char *e; 64 | 65 | while (*s == ' ') 66 | s++; 67 | 68 | if (o != s) 69 | (void) strcpy(o, s); 70 | 71 | e = o; 72 | 73 | while (*e != 0) 74 | e++; 75 | 76 | e--; 77 | 78 | while (*e == ' ' && e > o) 79 | *e-- = 0; 80 | 81 | } 82 | 83 | 84 | int 85 | main(int argc, char *argv[]) 86 | { 87 | int c; 88 | 89 | if (strlen(compiler_version) > 30) 90 | compiler_version[30] = 0; 91 | 92 | cleanup(compiler_version); 93 | cleanup(extra_compiler_flags); 94 | 95 | while ((c = getopt(argc, argv, "vcfrsVTR")) != -1) { 96 | switch (c) { 97 | case 'V': 98 | (void) printf("%s\n", LIBMICRO_VERSION); 99 | break; 100 | case 'v': 101 | (void) printf("%s\n", compiler_version); 102 | break; 103 | case 'c': 104 | (void) printf("%s\n", CC); 105 | break; 106 | case 'f': 107 | if (strlen(extra_compiler_flags) == 0) 108 | (void) printf("[none]\n"); 109 | else 110 | (void) printf("%s\n", extra_compiler_flags); 111 | break; 112 | 113 | case 's': 114 | (void) printf("%d\n", sizeof (long)); 115 | break; 116 | 117 | case 'r': 118 | 119 | (void) printf("%lld nsecs\n", get_nsecs_resolution()); 120 | break; 121 | 122 | case 'R': 123 | #ifdef ENABLE_RDTSC 124 | { 125 | struct timeval s; 126 | struct timeval f; 127 | long long start_nsecs; 128 | long long end_nsecs; 129 | long elapsed_usecs; 130 | 131 | gettimeofday(&s, NULL); 132 | start_nsecs = rdtsc(); 133 | for (;;) { 134 | gettimeofday(&f, NULL); 135 | elapsed_usecs = (f.tv_sec - s.tv_sec) * 136 | 1000000 + (f.tv_usec - s.tv_usec); 137 | if (elapsed_usecs > 1000000) 138 | break; 139 | } 140 | end_nsecs = rdtsc(); 141 | (void) printf("LIBMICRO_HZ=%lld\n", 142 | (long long)elapsed_usecs * 143 | (end_nsecs - start_nsecs) / 1000000LL); 144 | } 145 | #else 146 | (void) printf("\n"); 147 | #endif 148 | break; 149 | } 150 | } 151 | 152 | exit(0); 153 | return (0); 154 | } 155 | -------------------------------------------------------------------------------- /time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "libmicro.h" 36 | 37 | int 38 | benchmark_init() 39 | { 40 | lm_tsdsize = 0; 41 | 42 | (void) sprintf(lm_usage, 43 | "notes: measures time()\n"); 44 | 45 | return (0); 46 | } 47 | 48 | /*ARGSUSED*/ 49 | int 50 | benchmark(void *tsd, result_t *res) 51 | { 52 | int i; 53 | 54 | for (i = 0; i < lm_optB; i += 10) { 55 | (void) time(NULL); 56 | (void) time(NULL); 57 | (void) time(NULL); 58 | (void) time(NULL); 59 | (void) time(NULL); 60 | (void) time(NULL); 61 | (void) time(NULL); 62 | (void) time(NULL); 63 | (void) time(NULL); 64 | (void) time(NULL); 65 | } 66 | res->re_count += lm_optB; 67 | 68 | return (0); 69 | } 70 | -------------------------------------------------------------------------------- /times.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "libmicro.h" 38 | 39 | int 40 | benchmark_init() 41 | { 42 | 43 | lm_tsdsize = 0; 44 | 45 | (void) sprintf(lm_usage, 46 | "notes: measures times()\n"); 47 | 48 | return (0); 49 | } 50 | 51 | /*ARGSUSED*/ 52 | int 53 | benchmark(void *tsd, result_t *res) 54 | { 55 | int i; 56 | struct tms buf; 57 | 58 | for (i = 0; i < lm_optB; i += 10) { 59 | (void) times(&buf); 60 | (void) times(&buf); 61 | (void) times(&buf); 62 | (void) times(&buf); 63 | (void) times(&buf); 64 | (void) times(&buf); 65 | (void) times(&buf); 66 | (void) times(&buf); 67 | (void) times(&buf); 68 | (void) times(&buf); 69 | } 70 | res->re_count += lm_optB; 71 | 72 | return (0); 73 | } 74 | -------------------------------------------------------------------------------- /wrapper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # CDDL HEADER START 4 | # 5 | # The contents of this file are subject to the terms 6 | # of the Common Development and Distribution License 7 | # (the "License"). You may not use this file except 8 | # in compliance with the License. 9 | # 10 | # You can obtain a copy of the license at 11 | # src/OPENSOLARIS.LICENSE 12 | # or http://www.opensolaris.org/os/licensing. 13 | # See the License for the specific language governing 14 | # permissions and limitations under the License. 15 | # 16 | # When distributing Covered Code, include this CDDL 17 | # HEADER in each file and include the License file at 18 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 19 | # add the following below this CDDL HEADER, with the 20 | # fields enclosed by brackets "[]" replaced with your 21 | # own identifying information: Portions Copyright [yyyy] 22 | # [name of copyright owner] 23 | # 24 | # CDDL HEADER END 25 | # 26 | 27 | # 28 | # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 29 | # Use is subject to license terms. 30 | # 31 | 32 | 33 | BASENAME=`basename $0` 34 | DIRNAME=`dirname $0` 35 | ARCH=`uname -m` 36 | 37 | exec $DIRNAME/../bin-$ARCH/$BASENAME "$@" 38 | -------------------------------------------------------------------------------- /wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # CDDL HEADER START 4 | # 5 | # The contents of this file are subject to the terms 6 | # of the Common Development and Distribution License 7 | # (the "License"). You may not use this file except 8 | # in compliance with the License. 9 | # 10 | # You can obtain a copy of the license at 11 | # src/OPENSOLARIS.LICENSE 12 | # or http://www.opensolaris.org/os/licensing. 13 | # See the License for the specific language governing 14 | # permissions and limitations under the License. 15 | # 16 | # When distributing Covered Code, include this CDDL 17 | # HEADER in each file and include the License file at 18 | # usr/src/OPENSOLARIS.LICENSE. If applicable, 19 | # add the following below this CDDL HEADER, with the 20 | # fields enclosed by brackets "[]" replaced with your 21 | # own identifying information: Portions Copyright [yyyy] 22 | # [name of copyright owner] 23 | # 24 | # CDDL HEADER END 25 | # 26 | 27 | # 28 | # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 29 | # Use is subject to license terms. 30 | # 31 | 32 | 33 | BASENAME=`basename $0` 34 | DIRNAME=`dirname $0` 35 | ARCH=`uname -m` 36 | 37 | exec $DIRNAME/../bin-$ARCH/$BASENAME "$@" 38 | -------------------------------------------------------------------------------- /write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #ifdef linux 32 | #define _XOPEN_SOURCE 500 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "libmicro.h" 41 | 42 | typedef struct { 43 | char *ts_buf; 44 | int ts_fd; 45 | } tsd_t; 46 | 47 | #define DEFF "/dev/null" 48 | #define DEFS 1024 49 | 50 | static int optc = 0; 51 | static char *optf = DEFF; 52 | static long long opts = DEFS; 53 | static int optd; 54 | 55 | int 56 | benchmark_init() 57 | { 58 | lm_tsdsize = sizeof (tsd_t); 59 | 60 | (void) sprintf(lm_optstr, "cdf:s:"); 61 | 62 | (void) sprintf(lm_usage, 63 | " [-f file-to-write (default %s)]\n" 64 | " [-s buffer-size (default %d)]\n" 65 | " [-c ] (make sure buffer is in cache)\n" 66 | #ifdef __sun 67 | " [-d ] use directio" 68 | #endif 69 | "notes: measures write()\n", 70 | DEFF, DEFS); 71 | 72 | (void) sprintf(lm_header, "%8s", "size"); 73 | 74 | lm_defB = 1; 75 | 76 | return (0); 77 | } 78 | 79 | int 80 | benchmark_optswitch(int opt, char *optarg) 81 | { 82 | switch (opt) { 83 | 84 | case 'd': 85 | optd++; 86 | break; 87 | case 'c': 88 | optc++; 89 | break; 90 | case 'f': 91 | optf = optarg; 92 | break; 93 | case 's': 94 | opts = sizetoll(optarg); 95 | break; 96 | default: 97 | return (-1); 98 | } 99 | return (0); 100 | } 101 | 102 | int 103 | benchmark_initbatch(void *tsd) 104 | { 105 | tsd_t *ts = (tsd_t *)tsd; 106 | int i; 107 | 108 | if (ts->ts_buf == NULL) { 109 | ts->ts_buf = malloc(opts); 110 | ts->ts_fd = open(optf, O_WRONLY); 111 | 112 | #ifdef __sun 113 | if (optd) 114 | (void) directio(ts->ts_fd, DIRECTIO_ON); 115 | #endif 116 | /* 117 | * bring buf into cache if specified. 118 | */ 119 | 120 | if (optc) 121 | for (i = 0; i < opts; i++) 122 | ts->ts_buf[i] = 0; 123 | } 124 | 125 | (void) lseek(ts->ts_fd, 0, SEEK_SET); 126 | 127 | return (0); 128 | } 129 | 130 | int 131 | benchmark(void *tsd, result_t *res) 132 | { 133 | tsd_t *ts = (tsd_t *)tsd; 134 | int i; 135 | 136 | for (i = 0; i < lm_optB; i++) { 137 | if (write(ts->ts_fd, ts->ts_buf, opts) != opts) { 138 | res->re_errors++; 139 | } 140 | } 141 | res->re_count = i; 142 | 143 | return (0); 144 | } 145 | 146 | char * 147 | benchmark_result() 148 | { 149 | static char result[256]; 150 | 151 | (void) sprintf(result, "%8lld", opts); 152 | 153 | return (result); 154 | } 155 | -------------------------------------------------------------------------------- /writev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CDDL HEADER START 3 | * 4 | * The contents of this file are subject to the terms 5 | * of the Common Development and Distribution License 6 | * (the "License"). You may not use this file except 7 | * in compliance with the License. 8 | * 9 | * You can obtain a copy of the license at 10 | * src/OPENSOLARIS.LICENSE 11 | * or http://www.opensolaris.org/os/licensing. 12 | * See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | * 15 | * When distributing Covered Code, include this CDDL 16 | * HEADER in each file and include the License file at 17 | * usr/src/OPENSOLARIS.LICENSE. If applicable, 18 | * add the following below this CDDL HEADER, with the 19 | * fields enclosed by brackets "[]" replaced with your 20 | * own identifying information: Portions Copyright [yyyy] 21 | * [name of copyright owner] 22 | * 23 | * CDDL HEADER END 24 | */ 25 | 26 | /* 27 | * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28 | * Use is subject to license terms. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #ifndef IOV_MAX 39 | #define IOV_MAX UIO_MAXIOV 40 | #endif 41 | 42 | #include "libmicro.h" 43 | 44 | typedef struct { 45 | int ts_once; 46 | struct iovec *ts_iov; 47 | int ts_fd; 48 | } tsd_t; 49 | 50 | #define DEFF "/dev/null" 51 | #define DEFS 1024 52 | #define DEFV 10 53 | 54 | static char *optf = DEFF; 55 | static int opts = DEFS; 56 | static int optv = DEFV; 57 | 58 | int 59 | benchmark_init() 60 | { 61 | lm_tsdsize = sizeof (tsd_t); 62 | 63 | (void) sprintf(lm_optstr, "f:s:v:"); 64 | 65 | (void) sprintf(lm_usage, 66 | " [-f file-to-write (default %s)]\n" 67 | " [-s buffer-size (default %d)]\n" 68 | " [-v vector-size (default %d)]\n" 69 | "notes: measures writev()\n" 70 | " IOV_MAX is %d\n" 71 | " SSIZE_MAX is %ld\n", 72 | DEFF, DEFS, DEFV, IOV_MAX, SSIZE_MAX); 73 | 74 | (void) sprintf(lm_header, "%8s %4s", "size", "vec"); 75 | 76 | lm_defB = 1; 77 | 78 | return (0); 79 | } 80 | 81 | int 82 | benchmark_optswitch(int opt, char *optarg) 83 | { 84 | switch (opt) { 85 | case 'f': 86 | optf = optarg; 87 | break; 88 | case 's': 89 | opts = sizetoint(optarg); 90 | break; 91 | case 'v': 92 | optv = atoi(optarg); 93 | break; 94 | default: 95 | return (-1); 96 | } 97 | return (0); 98 | } 99 | 100 | int 101 | benchmark_initbatch(void *tsd) 102 | { 103 | tsd_t *ts = (tsd_t *)tsd; 104 | int i; 105 | int errors = 0; 106 | 107 | if (ts->ts_once++ == 0) { 108 | ts->ts_fd = open(optf, O_WRONLY); 109 | if (ts->ts_fd == -1) { 110 | errors++; 111 | } 112 | ts->ts_iov = (struct iovec *)malloc( 113 | optv * sizeof (struct iovec)); 114 | for (i = 0; i < optv; i++) { 115 | ts->ts_iov[i].iov_base = malloc(opts); 116 | ts->ts_iov[i].iov_len = opts; 117 | } 118 | } 119 | 120 | (void) lseek(ts->ts_fd, 0, SEEK_SET); 121 | 122 | return (errors); 123 | } 124 | 125 | int 126 | benchmark(void *tsd, result_t *res) 127 | { 128 | tsd_t *ts = (tsd_t *)tsd; 129 | int i; 130 | 131 | for (i = 0; i < lm_optB; i++) { 132 | if (writev(ts->ts_fd, ts->ts_iov, optv) != opts * optv) { 133 | res->re_errors++; 134 | } 135 | } 136 | res->re_count = i; 137 | 138 | return (0); 139 | } 140 | 141 | char * 142 | benchmark_result() 143 | { 144 | static char result[256]; 145 | 146 | (void) sprintf(result, "%8d %4d", opts, optv); 147 | 148 | return (result); 149 | } 150 | --------------------------------------------------------------------------------