From 7acf99cfe5945bbcacea75baacb2ca5b21509be7 Mon Sep 17 00:00:00 2001 From: "Joseph Chang (bizkit)" Date: Wed, 18 Aug 2010 15:59:24 +0800 Subject: Initial release (v1.0.1) --- native/Android.mk | 26 + native/gl_finish/Android.mk | 34 + native/gl_finish/gl_finish.cpp | 272 +++++ native/hello_bin/Android.mk | 13 + native/hello_bin/hello.c | 106 ++ native/hello_jni/Android.mk | 16 + native/hello_jni/hellolib.c | 11 + native/libMicro-0.4.0/Android.mk | 42 + native/libMicro-0.4.0/Makefile | 95 ++ native/libMicro-0.4.0/Makefile.Aix | 41 + native/libMicro-0.4.0/Makefile.Linux | 43 + native/libMicro-0.4.0/Makefile.SunOS | 61 + native/libMicro-0.4.0/Makefile.benchmarks | 112 ++ native/libMicro-0.4.0/Makefile.com | 127 ++ native/libMicro-0.4.0/OPENSOLARIS.LICENSE | 385 ++++++ native/libMicro-0.4.0/README | 85 ++ native/libMicro-0.4.0/_Android.mk | 13 + native/libMicro-0.4.0/_Executables.mk | 105 ++ native/libMicro-0.4.0/atomic.c | 74 ++ native/libMicro-0.4.0/bench.sh | 482 ++++++++ native/libMicro-0.4.0/benchmark_fini.c | 46 + native/libMicro-0.4.0/benchmark_finibatch.c | 46 + native/libMicro-0.4.0/benchmark_finirun.c | 45 + native/libMicro-0.4.0/benchmark_finiworker.c | 46 + native/libMicro-0.4.0/benchmark_init.c | 46 + native/libMicro-0.4.0/benchmark_initbatch.c | 47 + native/libMicro-0.4.0/benchmark_initrun.c | 45 + native/libMicro-0.4.0/benchmark_initworker.c | 46 + native/libMicro-0.4.0/benchmark_optswitch.c | 46 + native/libMicro-0.4.0/benchmark_result.c | 47 + native/libMicro-0.4.0/bind.c | 163 +++ native/libMicro-0.4.0/cachetocache.c | 222 ++++ native/libMicro-0.4.0/cascade_cond.c | 278 +++++ native/libMicro-0.4.0/cascade_fcntl.c | 232 ++++ native/libMicro-0.4.0/cascade_flock.c | 228 ++++ native/libMicro-0.4.0/cascade_lockf.c | 223 ++++ native/libMicro-0.4.0/cascade_mutex.c | 227 ++++ native/libMicro-0.4.0/chdir.c | 132 +++ native/libMicro-0.4.0/close.c | 141 +++ native/libMicro-0.4.0/close_tcp.c | 241 ++++ native/libMicro-0.4.0/connection.c | 305 +++++ native/libMicro-0.4.0/dup.c | 139 +++ native/libMicro-0.4.0/elided.c | 59 + native/libMicro-0.4.0/exec.c | 101 ++ native/libMicro-0.4.0/exec_bin.c | 65 ++ native/libMicro-0.4.0/exit.c | 160 +++ native/libMicro-0.4.0/exp.c | 73 ++ native/libMicro-0.4.0/fcntl.c | 99 ++ native/libMicro-0.4.0/fcntl_ndelay.c | 100 ++ native/libMicro-0.4.0/file_lock.c | 106 ++ native/libMicro-0.4.0/fork.c | 131 +++ native/libMicro-0.4.0/getcontext.c | 74 ++ native/libMicro-0.4.0/getenv.c | 126 ++ native/libMicro-0.4.0/getpeername.c | 163 +++ native/libMicro-0.4.0/getpid.c | 64 + native/libMicro-0.4.0/getrusage.c | 73 ++ native/libMicro-0.4.0/getsockname.c | 125 ++ native/libMicro-0.4.0/gettimeofday.c | 72 ++ native/libMicro-0.4.0/isatty.c | 110 ++ native/libMicro-0.4.0/libmicro.c | 1612 ++++++++++++++++++++++++++ native/libMicro-0.4.0/libmicro.h | 196 ++++ native/libMicro-0.4.0/libmicro_main.c | 44 + native/libMicro-0.4.0/listen.c | 127 ++ native/libMicro-0.4.0/localtime_r.c | 75 ++ native/libMicro-0.4.0/log.c | 73 ++ native/libMicro-0.4.0/longjmp.c | 65 ++ native/libMicro-0.4.0/lrand48.c | 71 ++ native/libMicro-0.4.0/lseek.c | 130 +++ native/libMicro-0.4.0/malloc.c | 139 +++ native/libMicro-0.4.0/memcpy.c | 160 +++ native/libMicro-0.4.0/memmove.c | 160 +++ native/libMicro-0.4.0/memrand.c | 146 +++ native/libMicro-0.4.0/memset.c | 169 +++ native/libMicro-0.4.0/mk_tarball | 28 + native/libMicro-0.4.0/mktime.c | 112 ++ native/libMicro-0.4.0/mmap.c | 198 ++++ native/libMicro-0.4.0/mprotect.c | 200 ++++ native/libMicro-0.4.0/msync.c | 190 +++ native/libMicro-0.4.0/multiview.sh | 201 ++++ native/libMicro-0.4.0/munmap.c | 192 +++ native/libMicro-0.4.0/mutex.c | 194 ++++ native/libMicro-0.4.0/nop.c | 63 + native/libMicro-0.4.0/open.c | 138 +++ native/libMicro-0.4.0/pipe.c | 566 +++++++++ native/libMicro-0.4.0/poll.c | 218 ++++ native/libMicro-0.4.0/pread.c | 142 +++ native/libMicro-0.4.0/pthread_create.c | 160 +++ native/libMicro-0.4.0/pwrite.c | 154 +++ native/libMicro-0.4.0/read.c | 143 +++ native/libMicro-0.4.0/realpath.c | 85 ++ native/libMicro-0.4.0/recurse.c | 110 ++ native/libMicro-0.4.0/recurse2.c | 46 + native/libMicro-0.4.0/select.c | 214 ++++ native/libMicro-0.4.0/semop.c | 103 ++ native/libMicro-0.4.0/setcontext.c | 67 ++ native/libMicro-0.4.0/setsockopt.c | 99 ++ native/libMicro-0.4.0/sigaction.c | 95 ++ native/libMicro-0.4.0/siglongjmp.c | 69 ++ native/libMicro-0.4.0/signal.c | 100 ++ native/libMicro-0.4.0/sigprocmask.c | 84 ++ native/libMicro-0.4.0/socket.c | 157 +++ native/libMicro-0.4.0/socketpair.c | 118 ++ native/libMicro-0.4.0/stat.c | 88 ++ native/libMicro-0.4.0/strcasecmp.c | 150 +++ native/libMicro-0.4.0/strchr.c | 144 +++ native/libMicro-0.4.0/strcmp.c | 147 +++ native/libMicro-0.4.0/strcpy.c | 145 +++ native/libMicro-0.4.0/strftime.c | 129 +++ native/libMicro-0.4.0/strlen.c | 143 +++ native/libMicro-0.4.0/strtol.c | 67 ++ native/libMicro-0.4.0/system.c | 98 ++ native/libMicro-0.4.0/tattle.c | 154 +++ native/libMicro-0.4.0/time.c | 69 ++ native/libMicro-0.4.0/times.c | 73 ++ native/libMicro-0.4.0/wrapper.sh | 37 + native/libMicro-0.4.0/write.c | 154 +++ native/libMicro-0.4.0/writev.c | 149 +++ 117 files changed, 15995 insertions(+) create mode 100644 native/Android.mk create mode 100644 native/gl_finish/Android.mk create mode 100644 native/gl_finish/gl_finish.cpp create mode 100644 native/hello_bin/Android.mk create mode 100644 native/hello_bin/hello.c create mode 100644 native/hello_jni/Android.mk create mode 100644 native/hello_jni/hellolib.c create mode 100644 native/libMicro-0.4.0/Android.mk create mode 100644 native/libMicro-0.4.0/Makefile create mode 100644 native/libMicro-0.4.0/Makefile.Aix create mode 100644 native/libMicro-0.4.0/Makefile.Linux create mode 100644 native/libMicro-0.4.0/Makefile.SunOS create mode 100644 native/libMicro-0.4.0/Makefile.benchmarks create mode 100644 native/libMicro-0.4.0/Makefile.com create mode 100644 native/libMicro-0.4.0/OPENSOLARIS.LICENSE create mode 100644 native/libMicro-0.4.0/README create mode 100644 native/libMicro-0.4.0/_Android.mk create mode 100644 native/libMicro-0.4.0/_Executables.mk create mode 100644 native/libMicro-0.4.0/atomic.c create mode 100644 native/libMicro-0.4.0/bench.sh create mode 100644 native/libMicro-0.4.0/benchmark_fini.c create mode 100644 native/libMicro-0.4.0/benchmark_finibatch.c create mode 100644 native/libMicro-0.4.0/benchmark_finirun.c create mode 100644 native/libMicro-0.4.0/benchmark_finiworker.c create mode 100644 native/libMicro-0.4.0/benchmark_init.c create mode 100644 native/libMicro-0.4.0/benchmark_initbatch.c create mode 100644 native/libMicro-0.4.0/benchmark_initrun.c create mode 100644 native/libMicro-0.4.0/benchmark_initworker.c create mode 100644 native/libMicro-0.4.0/benchmark_optswitch.c create mode 100644 native/libMicro-0.4.0/benchmark_result.c create mode 100644 native/libMicro-0.4.0/bind.c create mode 100644 native/libMicro-0.4.0/cachetocache.c create mode 100644 native/libMicro-0.4.0/cascade_cond.c create mode 100644 native/libMicro-0.4.0/cascade_fcntl.c create mode 100644 native/libMicro-0.4.0/cascade_flock.c create mode 100644 native/libMicro-0.4.0/cascade_lockf.c create mode 100644 native/libMicro-0.4.0/cascade_mutex.c create mode 100644 native/libMicro-0.4.0/chdir.c create mode 100644 native/libMicro-0.4.0/close.c create mode 100644 native/libMicro-0.4.0/close_tcp.c create mode 100644 native/libMicro-0.4.0/connection.c create mode 100644 native/libMicro-0.4.0/dup.c create mode 100644 native/libMicro-0.4.0/elided.c create mode 100644 native/libMicro-0.4.0/exec.c create mode 100644 native/libMicro-0.4.0/exec_bin.c create mode 100644 native/libMicro-0.4.0/exit.c create mode 100644 native/libMicro-0.4.0/exp.c create mode 100644 native/libMicro-0.4.0/fcntl.c create mode 100644 native/libMicro-0.4.0/fcntl_ndelay.c create mode 100644 native/libMicro-0.4.0/file_lock.c create mode 100644 native/libMicro-0.4.0/fork.c create mode 100644 native/libMicro-0.4.0/getcontext.c create mode 100644 native/libMicro-0.4.0/getenv.c create mode 100644 native/libMicro-0.4.0/getpeername.c create mode 100644 native/libMicro-0.4.0/getpid.c create mode 100644 native/libMicro-0.4.0/getrusage.c create mode 100644 native/libMicro-0.4.0/getsockname.c create mode 100644 native/libMicro-0.4.0/gettimeofday.c create mode 100644 native/libMicro-0.4.0/isatty.c create mode 100644 native/libMicro-0.4.0/libmicro.c create mode 100644 native/libMicro-0.4.0/libmicro.h create mode 100644 native/libMicro-0.4.0/libmicro_main.c create mode 100644 native/libMicro-0.4.0/listen.c create mode 100644 native/libMicro-0.4.0/localtime_r.c create mode 100644 native/libMicro-0.4.0/log.c create mode 100644 native/libMicro-0.4.0/longjmp.c create mode 100644 native/libMicro-0.4.0/lrand48.c create mode 100644 native/libMicro-0.4.0/lseek.c create mode 100644 native/libMicro-0.4.0/malloc.c create mode 100644 native/libMicro-0.4.0/memcpy.c create mode 100644 native/libMicro-0.4.0/memmove.c create mode 100644 native/libMicro-0.4.0/memrand.c create mode 100644 native/libMicro-0.4.0/memset.c create mode 100755 native/libMicro-0.4.0/mk_tarball create mode 100644 native/libMicro-0.4.0/mktime.c create mode 100644 native/libMicro-0.4.0/mmap.c create mode 100644 native/libMicro-0.4.0/mprotect.c create mode 100644 native/libMicro-0.4.0/msync.c create mode 100644 native/libMicro-0.4.0/multiview.sh create mode 100644 native/libMicro-0.4.0/munmap.c create mode 100644 native/libMicro-0.4.0/mutex.c create mode 100644 native/libMicro-0.4.0/nop.c create mode 100644 native/libMicro-0.4.0/open.c create mode 100644 native/libMicro-0.4.0/pipe.c create mode 100644 native/libMicro-0.4.0/poll.c create mode 100644 native/libMicro-0.4.0/pread.c create mode 100644 native/libMicro-0.4.0/pthread_create.c create mode 100644 native/libMicro-0.4.0/pwrite.c create mode 100644 native/libMicro-0.4.0/read.c create mode 100644 native/libMicro-0.4.0/realpath.c create mode 100644 native/libMicro-0.4.0/recurse.c create mode 100644 native/libMicro-0.4.0/recurse2.c create mode 100644 native/libMicro-0.4.0/select.c create mode 100644 native/libMicro-0.4.0/semop.c create mode 100644 native/libMicro-0.4.0/setcontext.c create mode 100644 native/libMicro-0.4.0/setsockopt.c create mode 100644 native/libMicro-0.4.0/sigaction.c create mode 100644 native/libMicro-0.4.0/siglongjmp.c create mode 100644 native/libMicro-0.4.0/signal.c create mode 100644 native/libMicro-0.4.0/sigprocmask.c create mode 100644 native/libMicro-0.4.0/socket.c create mode 100644 native/libMicro-0.4.0/socketpair.c create mode 100644 native/libMicro-0.4.0/stat.c create mode 100644 native/libMicro-0.4.0/strcasecmp.c create mode 100644 native/libMicro-0.4.0/strchr.c create mode 100644 native/libMicro-0.4.0/strcmp.c create mode 100644 native/libMicro-0.4.0/strcpy.c create mode 100644 native/libMicro-0.4.0/strftime.c create mode 100644 native/libMicro-0.4.0/strlen.c create mode 100644 native/libMicro-0.4.0/strtol.c create mode 100644 native/libMicro-0.4.0/system.c create mode 100644 native/libMicro-0.4.0/tattle.c create mode 100644 native/libMicro-0.4.0/time.c create mode 100644 native/libMicro-0.4.0/times.c create mode 100644 native/libMicro-0.4.0/wrapper.sh create mode 100644 native/libMicro-0.4.0/write.c create mode 100644 native/libMicro-0.4.0/writev.c (limited to 'native') diff --git a/native/Android.mk b/native/Android.mk new file mode 100644 index 0000000..ea6ba77 --- /dev/null +++ b/native/Android.mk @@ -0,0 +1,26 @@ +# +# Copyright (C) 2010 0xlab - http://0xlab.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +TOP_LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +include $(TOP_LOCAL_PATH)/hello_jni/Android.mk + +include $(TOP_LOCAL_PATH)/gl_finish/Android.mk +include $(TOP_LOCAL_PATH)/hello_bin/Android.mk + +include $(TOP_LOCAL_PATH)/libMicro-0.4.0/Android.mk diff --git a/native/gl_finish/Android.mk b/native/gl_finish/Android.mk new file mode 100644 index 0000000..820f3ef --- /dev/null +++ b/native/gl_finish/Android.mk @@ -0,0 +1,34 @@ +# +# Copyright (C) 2010 0xlab - http://0xlab.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + gl_finish.cpp + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libEGL \ + libGLESv1_CM \ + libui + +LOCAL_MODULE:= gl_finish_test +LOCAL_MODULE_TAGS := optional + +LOCAL_CFLAGS := -DGL_GLEXT_PROTOTYPES + +include $(BUILD_EXECUTABLE) diff --git a/native/gl_finish/gl_finish.cpp b/native/gl_finish/gl_finish.cpp new file mode 100644 index 0000000..a0d553d --- /dev/null +++ b/native/gl_finish/gl_finish.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2010 0xlab - htpp://0xlab.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include + +using namespace android; + +typedef struct { + int x; + int y; + int w; + int h; + int vertical; + int horizontal; +} Paster; + +static void gl_textures_generate(int texNum, GLuint* texName, + char* texels, + int tex_width, int tex_height); +static void fill_texture(char* dst, + int width, int height, + int space); +static void init_paster(Paster* paster, + int w, int h, + int screen_w, int screen_h); +static void update_pasters(Paster** paster, + int number, + int screen_width, int screen_height); +static void update_paster_position(Paster* paster, + int screen_w, int screen_h); + +static void draw_paster(EGLDisplay dpy, EGLSurface surface, + Paster** paster, int paster_num, int round, + int screen_width, int screen_height, + int depth); + +int main(int argc, char** argv) +{ + EGLint configAttribs[] = { + EGL_DEPTH_SIZE, 0, + EGL_NONE + }; + + EGLint majorVersion; + EGLint minorVersion; + EGLContext context; + EGLConfig config; + EGLSurface surface; + EGLint width, height; + EGLDisplay dpy; + EGLint z = 0; + + int texNum = 1; // how many textures we want to generate + char* texels; // Array for storing texel color + GLuint texName[texNum]; + GLuint tex_width = 300; + GLuint tex_height = 200; + GLuint tex_space = 4; // 4 bytes RGBA + + int paster_num = 10; // how many Paster we want to generate + + int i; // temporary counter for loop + srand(time(NULL)); + setpriority(PRIO_PROCESS, 0, -20); + + /* Initialize window and context */ + EGLNativeWindowType window = android_createDisplaySurface(); + + dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(dpy, &majorVersion, &minorVersion); + + status_t err = EGLUtils::selectConfigForNativeWindow( + dpy, configAttribs, window, &config); + if (err) { + fprintf(stderr, "couldn't find an EGLConfig " + "matching the screen format\n"); + return 0; + } + + surface = eglCreateWindowSurface(dpy, config, window, NULL); + context = eglCreateContext(dpy, config, NULL, NULL); + eglMakeCurrent(dpy, surface, surface, context); + eglQuerySurface(dpy, surface, EGL_WIDTH, &width); + eglQuerySurface(dpy, surface, EGL_HEIGHT, &height); + GLint dim = width < height ? width : height; + + /* fill color into texels and associate texture with texels */ + texels = (char*)malloc(tex_width * tex_height * tex_space); + fill_texture(texels, tex_width, tex_height, tex_space); + gl_textures_generate(texNum, texName, texels, tex_width, tex_height); + + Paster* paster[paster_num]; + for(i = 0; i < paster_num; ++i) { + paster[i] = (Paster *) malloc(sizeof(Paster)); + init_paster(paster[i], tex_width, tex_height, width, height); + } + + draw_paster(dpy, surface, paster, paster_num, 100, width, height, z); + + return 0; +} + +static void gl_textures_generate(int texNum, GLuint* texName, + char* texels, + int tex_width, int tex_height) +{ + GLint crop[4] = { + 0, + tex_width, tex_height, + -1 * tex_width}; + glGenTextures(texNum, texName); + + /* Bind to first texture only */ + glBindTexture(GL_TEXTURE_2D, texName[0]); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(1,1,1,1); + glDisable(GL_DITHER); + glShadeModel(GL_FLAT); + glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + tex_width, tex_height, 0, GL_RGBA, + GL_UNSIGNED_BYTE, texels); +} + +static void fill_texture(char* dst, int width, int height, int space) +{ + int i, j; + int abgr = 0x330000ff; + int *ptr = (int*) dst; + + for (i = 0; i < width; i++) { + for (j = 0; j < height; j++) { + int c = (j * width + i); + *(ptr + c) = abgr; + } + } +} + +static void init_paster(Paster* paster, + int w, int h, + int screen_w, int screen_h) +{ + int offset_w = 0; + int offset_h = 0; + + if (screen_w > w) { + offset_w = screen_w - w; + } + if (screen_h > h) { + offset_h = screen_h - h; + } + + paster->x = rand() % offset_w; + paster->y = rand() % offset_h; + paster->w = w; + paster->h = h; + paster->horizontal = rand() % 3 - 1; + paster->vertical = rand() % 3 - 1; + update_paster_position(paster, screen_w, screen_h); +} + +void update_paster_position(Paster* paster, + int screen_w, int screen_h) +{ + int x = paster->x; + int y = paster->y; + int w = paster->w; + int h = paster->h; + int hV = paster->horizontal; + int vV = paster->vertical; + + if (x + w + hV > screen_w) { + paster->horizontal = -1; + } + if (x + hV < 0) { + paster->horizontal = 1; + } + if (y + h + vV > screen_h) { + paster->vertical = -1; + } + if (y + vV < 0) { + paster->vertical= 1; + } + + paster->x = x + paster->horizontal; + paster->y = y + paster->vertical; +} + +static void update_pasters(Paster** paster, + int number, + int screen_width, int screen_height) +{ + int i = 0; + for (i = 0; i < number; ++i) { + update_paster_position(paster[i], + screen_width, screen_height); + } +} + +static void draw_paster(EGLDisplay dpy, EGLSurface surface, + Paster** paster, + int paster_num, int round, + int screen_width, int screen_height, int depth) +{ + int r = 0; + int i = 0; + + long long start_time; + long long end_time; + long long total_time; + + glClear(GL_COLOR_BUFFER_BIT); + total_time = 0; + + for (r = 0; r < round; r ++) { + glClear(GL_COLOR_BUFFER_BIT); + update_pasters(paster, paster_num, screen_width, screen_height); + + start_time = systemTime(); + for (i = 0; ix, paster[i]->y, + depth, + paster[i]->w, paster[i]->h); + } + glFinish(); + eglSwapBuffers(dpy, surface); + end_time = systemTime(); + total_time += (end_time - start_time); + } + + + long long total_us = total_time / 1000; + printf("Repeat drawing for %d times, spend %llu us, " + "average: %llu us per drawing\n", + round, total_us, total_us/round); + fflush(stdout); + + return; +} + +/* -*- Mode: C; tab-width: 4 -*- */ diff --git a/native/hello_bin/Android.mk b/native/hello_bin/Android.mk new file mode 100644 index 0000000..2c7d201 --- /dev/null +++ b/native/hello_bin/Android.mk @@ -0,0 +1,13 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= hello.c + +LOCAL_MODULE:= hello +LOCAL_MODULE_TAGS := optional + + +LOCAL_C_INCLUDES := \ + $(JNI_H_INCLUDE) + +include $(BUILD_EXECUTABLE) diff --git a/native/hello_bin/hello.c b/native/hello_bin/hello.c new file mode 100644 index 0000000..cd1bc82 --- /dev/null +++ b/native/hello_bin/hello.c @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2010 0xlab - htpp://0xlab.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include +#include + +#define MESSAGE "SOCKET!!\n" +#define SERVERHOST "localhost" +uint16_t PORT = -1; + + +void init_sockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port) +{ + struct hostent *hostinfo; + + name->sin_family = AF_INET; + name->sin_port = htons (port); + hostinfo = gethostbyname (hostname); + if (hostinfo == NULL) { + fprintf (stderr, "Unknown host %s.\n", hostname); + fflush(stderr); + exit (EXIT_FAILURE); + } + name->sin_addr = *(struct in_addr *) hostinfo->h_addr; +} + +int make_socket() +{ + PORT = atoi(getenv("ZXBENCH_PORT")); + + int sock = socket (PF_INET, SOCK_STREAM, 0); + if (sock < 0) { + fprintf(stderr, "cannot create socket.\n"); + fflush(stderr); + exit(EXIT_FAILURE); + } + + /* Disable Nagle buffering algo */ + int flag = 1; + setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); + + struct sockaddr_in servername; + /* Connect to the server. */ + init_sockaddr (&servername, SERVERHOST, PORT); + if ( 0 > connect(sock, (struct sockaddr *) &servername, sizeof (servername)) ) { + fprintf (stderr, "cannot connect to server."); + fflush(stderr); + exit (EXIT_FAILURE); + } + + return sock; +} + +void write_to_server (int socket) +{ + int nbytes; + + nbytes = write (socket, MESSAGE, strlen (MESSAGE)); + if (nbytes < 0) { + fprintf (stderr, "write failed."); + fflush(stderr); + exit (EXIT_FAILURE); + } +} + + +int main(int argc, char** argv) +{ + printf("HHHEEELLLLOOOOOOOO\n"); + + int sock = make_socket(); + + int i; + for (i=0; i<20; i++) { + fprintf(stdout, "stdout %d\n", i); + fflush(stdout); + fprintf(stderr, "srderr %d\n", i); + fflush(stderr); + write_to_server(sock); + sleep(1); + } + + close(sock); + return EXIT_SUCCESS; +} + + +/* -*- Mode: C; tab-width: 4 -*- */ diff --git a/native/hello_jni/Android.mk b/native/hello_jni/Android.mk new file mode 100644 index 0000000..3b6533e --- /dev/null +++ b/native/hello_jni/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH:= $(call my-dir) + +LOCAL_SRC_FILES:= \ + hellolib.c + +LOCAL_C_INCLUDES := \ + $(JNI_H_INCLUDE) + +LOCAL_SHARED_LIBRARIES := \ + libutils + +LOCAL_PRELINK_MODULE := false + +LOCAL_MODULE := libhello + +include $(BUILD_SHARED_LIBRARY) diff --git a/native/hello_jni/hellolib.c b/native/hello_jni/hellolib.c new file mode 100644 index 0000000..f7f6b46 --- /dev/null +++ b/native/hello_jni/hellolib.c @@ -0,0 +1,11 @@ +#include + +#define LOG_TAG "TestLib" +#undef LOG +#include + + +JNIEXPORT void JNICALL Java_org_zeroxlab_benchmark_Benchmark_printHello(JNIEnv * env, jobject jobj) +{ + LOGD("Hello LIB!\n"); +} diff --git a/native/libMicro-0.4.0/Android.mk b/native/libMicro-0.4.0/Android.mk new file mode 100644 index 0000000..c420325 --- /dev/null +++ b/native/libMicro-0.4.0/Android.mk @@ -0,0 +1,42 @@ +# +# Copyright (C) 2010 0xlab - http://0xlab.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_SRC_FILES := \ + libmicro.c \ + libmicro_main.c \ + benchmark_init.c \ + benchmark_fini.c \ + benchmark_finirun.c \ + benchmark_initrun.c \ + benchmark_initbatch.c \ + benchmark_finibatch.c \ + benchmark_initworker.c \ + benchmark_finiworker.c \ + benchmark_optswitch.c \ + benchmark_result.c + +LOCAL_MODULE:= libmicro +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) +include $(LOCAL_PATH)/_Executables.mk + +$(foreach TARGET_MODULE, $(EXEs), $(eval include $(LOCAL_PATH)/_Android.mk)) + + diff --git a/native/libMicro-0.4.0/Makefile b/native/libMicro-0.4.0/Makefile new file mode 100644 index 0000000..aee11a5 --- /dev/null +++ b/native/libMicro-0.4.0/Makefile @@ -0,0 +1,95 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + +include Makefile.benchmarks + +BINS= $(ALL:%=bin/%) bin/tattle + +TARBALL_CONTENTS = \ + Makefile.benchmarks \ + Makefile.SunOS \ + Makefile.Linux \ + Makefile.Aix \ + Makefile.com \ + Makefile \ + $(ALL:%=%.c) \ + elided.c \ + exec_bin.c \ + libmicro.c \ + libmicro_main.c \ + libmicro.h \ + recurse2.c \ + benchmark_finibatch.c \ + benchmark_initbatch.c \ + benchmark_optswitch.c \ + benchmark_fini.c \ + benchmark_init.c \ + benchmark_result.c \ + benchmark_finirun.c \ + benchmark_initrun.c \ + benchmark_initworker.c \ + benchmark_finiworker.c \ + bench \ + bench.sh \ + mk_tarball \ + multiview \ + multiview.sh \ + OPENSOLARIS.LICENSE \ + tattle.c \ + wrapper \ + wrapper.sh \ + README + +default $(ALL) run cstyle lint tattle: $(BINS) + @cp bench.sh bench + @cp multiview.sh multiview + @cp wrapper.sh wrapper + @chmod +x bench multiview wrapper + @mkdir -p bin-`uname -m`; cd bin-`uname -m`; MACH=`uname -m` $(MAKE) -f ../Makefile.`uname -s` UNAME_RELEASE=`uname -r | sed 's/\./_/g'` $@ + +clean: + rm -rf bin bin-* wrapper multiview bench + +bin: + @mkdir -p bin + +$(BINS): bin + @cp wrapper.sh wrapper + @chmod +x wrapper + @ln -sf ../wrapper $@ + + +libMicro.tar: FORCE + @chmod +x ./mk_tarball wrapper + @./mk_tarball $(TARBALL_CONTENTS) + +FORCE: + diff --git a/native/libMicro-0.4.0/Makefile.Aix b/native/libMicro-0.4.0/Makefile.Aix new file mode 100644 index 0000000..9e4dc42 --- /dev/null +++ b/native/libMicro-0.4.0/Makefile.Aix @@ -0,0 +1,41 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + +CFLAGS= -O3 + +CPPFLAGS = -D_REENTRANT + +include ../Makefile.com + +NSLLIB= -lnsl +SOCKLIB= + +.KEEP_STATE: diff --git a/native/libMicro-0.4.0/Makefile.Linux b/native/libMicro-0.4.0/Makefile.Linux new file mode 100644 index 0000000..ca12d15 --- /dev/null +++ b/native/libMicro-0.4.0/Makefile.Linux @@ -0,0 +1,43 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + +CC= gcc + +#CFLAGS= -O -DUSE_SEMOP +CPPFLAGS= -DUSE_SEMOP -D_REENTRANT +MATHLIB= -lm + +ELIDED_BENCHMARKS= \ + cachetocache \ + atomic + + +include ../Makefile.com diff --git a/native/libMicro-0.4.0/Makefile.SunOS b/native/libMicro-0.4.0/Makefile.SunOS new file mode 100644 index 0000000..4fc7269 --- /dev/null +++ b/native/libMicro-0.4.0/Makefile.SunOS @@ -0,0 +1,61 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + +CPPFLAGS= -DUSE_GETHRTIME -D_REENTRANT + +CFLAGS = -O $(extra_CFLAGS) + +# +# These defines allow libmicro to be compiled against older Solaris +# releases by turning off the tests which don't work there. +# +# This is a little contorted-- UNAME_RELEASE is set as an environment +# variable for us by the invoking make process (see Makefile)-- it is +# the output of uname -r | sed 's/\./_/g'. +# +# We couldn't find any other gmake/unix make portable way to make this +# work. +# +ELIDED_BENCHMARKS_5_8=atomic cachetocache +ELIDED_BENCHMARKS_5_9=atomic + +ELIDED_BENCHMARKS_CMN=cascade_flock + +ELIDED_BENCHMARKS=$(ELIDED_BENCHMARKS_CMN) $(ELIDED_BENCHMARKS_$(UNAME_RELEASE)) + +include ../Makefile.com + +NSLLIB= -lnsl +SOCKLIB= -lsocket +UCBLIB= -lc -L/usr/ucblib -lucb -R/usr/ucblib +MATHLIB= -lm + +.KEEP_STATE: diff --git a/native/libMicro-0.4.0/Makefile.benchmarks b/native/libMicro-0.4.0/Makefile.benchmarks new file mode 100644 index 0000000..ed1923a --- /dev/null +++ b/native/libMicro-0.4.0/Makefile.benchmarks @@ -0,0 +1,112 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + +ALL= \ + atomic \ + bind \ + cachetocache \ + cascade_mutex \ + cascade_cond \ + cascade_lockf \ + cascade_fcntl \ + cascade_flock \ + chdir \ + close \ + close_tcp \ + connection \ + dup \ + exec \ + exit \ + exp \ + fcntl \ + fcntl_ndelay \ + file_lock \ + fork \ + getcontext \ + getenv \ + gettimeofday \ + getpeername \ + getpid \ + getrusage \ + getsockname \ + isatty \ + listen \ + localtime_r \ + log \ + longjmp \ + lrand48 \ + lseek \ + malloc \ + memcpy \ + memmove \ + memrand \ + memset \ + mktime \ + mprotect \ + mmap \ + msync \ + munmap \ + mutex \ + nop \ + open \ + pipe \ + poll \ + pread \ + pthread_create \ + pwrite \ + read \ + realpath \ + recurse \ + select \ + semop \ + setcontext \ + setsockopt \ + sigaction \ + siglongjmp \ + signal \ + sigprocmask \ + socket \ + socketpair \ + stat \ + strcasecmp \ + strchr \ + strcmp \ + strcpy \ + strftime \ + strlen \ + strtol \ + system \ + time \ + times \ + write \ + writev + + diff --git a/native/libMicro-0.4.0/Makefile.com b/native/libMicro-0.4.0/Makefile.com new file mode 100644 index 0000000..61f2684 --- /dev/null +++ b/native/libMicro-0.4.0/Makefile.com @@ -0,0 +1,127 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +include ../Makefile.benchmarks + +EXTRA_CFILES= \ + exec_bin.c \ + elided.c \ + tattle.c + +# +# some definitions to make getting compiler versions possible - avoid quotes +# +COMPILER_VERSION_CMD_cc=cc -V 2>&1 | egrep Sun +COMPILER_VERSION_CMD_gcc=gcc -dumpversion +COMPILER_VERSION_CMD=$(COMPILER_VERSION_CMD_$(CC)) + +default: $(ALL) tattle + +cstyle: + for file in $(ALL:%=../%.c) $(EXTRA_CFILES:%=../%) ; \ + do cstyle -p $$file ;\ + done + + +lint: libmicro.ln $(ALL:%=%.lint) $(EXTRA_CFILES:%.c=%.lint) + + +$(EXTRA_CFILES:%.c=%.lint): + $(LINT) ../$(@:%.lint=%.c) -I. -mu -lc libmicro.ln -lm + +%.lint: ../%.c libmicro.ln + $(LINT) -mu $(CPPFLAGS) $< libmicro.ln -lpthread -lsocket -lnsl -lm + +%.o: ../%.c + $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ + +libmicro.ln: ../libmicro.c ../libmicro_main.c ../libmicro.h ../benchmark_*.c + $(LINT) -muc $(CPPFLAGS) ../libmicro.c ../libmicro_main.c ../benchmark_*.c + +CPPFLAGS+= -D_REENTRANT + +bind_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) +cascade_flock_EXTRA_LIBS=$(UCBLIB) +close_tcp_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) +connection_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) +fcntl_ndelay_EXTRA_LIBS=$(SOCKLIB) +getpeername_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) +getsockname_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) +listen_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) +log_EXTRA_LIBS=$(MATHLIB) +pipe_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) +poll_EXTRA_LIBS=$(SOCKLIB) +select_EXTRA_LIBS=$(SOCKLIB) +setsockopt_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB) +socket_EXTRA_LIBS=$(SOCKLIB) +socketpair_EXTRA_LIBS=$(SOCKLIB) + +BENCHMARK_FUNCS= \ + benchmark_init.o \ + benchmark_fini.o \ + benchmark_initrun.o \ + benchmark_finirun.o \ + benchmark_initbatch.o \ + benchmark_finibatch.o \ + benchmark_initworker.o \ + benchmark_finiworker.o \ + benchmark_optswitch.o \ + benchmark_result.o + +recurse_EXTRA_DEPS=recurse2.o + + +recurse: $(recurse_EXTRA_DEPS) + +libmicro.a: libmicro.o libmicro_main.o $(BENCHMARK_FUNCS) + $(AR) -cr libmicro.a libmicro.o libmicro_main.o $(BENCHMARK_FUNCS) + +tattle: ../tattle.c libmicro.a + echo "char * compiler_version = \""`$(COMPILER_VERSION_CMD)`"\";" > tattle.h + echo "char * CC = \""$(CC)"\";" >> tattle.h + echo "char * extra_compiler_flags = \""$(extra_CFLAGS)"\";" >> tattle.h + $(CC) -o tattle $(CFLAGS) -I. ../tattle.c libmicro.a -lrt -lm + +$(ELIDED_BENCHMARKS): ../elided.c + $(CC) -o $(@) ../elided.c + +%: libmicro.a %.o + $(CC) -o $(@) $(@).o $($(@)_EXTRA_DEPS) $(CFLAGS) libmicro.a $($(@)_EXTRA_LIBS) $(EXTRA_LIBS) -lpthread -lm + +exec: exec_bin + +exec_bin: exec_bin.o + $(CC) -o exec_bin $(CFLAGS) exec_bin.o + +FORCE: + + +._KEEP_STATE: + diff --git a/native/libMicro-0.4.0/OPENSOLARIS.LICENSE b/native/libMicro-0.4.0/OPENSOLARIS.LICENSE new file mode 100644 index 0000000..535dec2 --- /dev/null +++ b/native/libMicro-0.4.0/OPENSOLARIS.LICENSE @@ -0,0 +1,385 @@ +Unless otherwise noted, all files in this distribution are released +under the Common Development and Distribution License (CDDL), +Version 1.0 only. Exceptions are noted within the associated +source files. + +-------------------------------------------------------------------- + + +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0 + +1. Definitions. + + 1.1. "Contributor" means each individual or entity that creates + or contributes to the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original + Software, prior Modifications used by a Contributor (if any), + and the Modifications made by that particular Contributor. + + 1.3. "Covered Software" means (a) the Original Software, or (b) + Modifications, or (c) the combination of files containing + Original Software with files containing Modifications, in + each case including portions thereof. + + 1.4. "Executable" means the Covered Software in any form other + than Source Code. + + 1.5. "Initial Developer" means the individual or entity that first + makes Original Software available under this License. + + 1.6. "Larger Work" means a work which combines Covered Software or + portions thereof with code not governed by the terms of this + License. + + 1.7. "License" means this document. + + 1.8. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed + herein. + + 1.9. "Modifications" means the Source Code and Executable form of + any of the following: + + A. Any file that results from an addition to, deletion from or + modification of the contents of a file containing Original + Software or previous Modifications; + + B. Any new file that contains any part of the Original + Software or previous Modifications; or + + C. Any new file that is contributed or otherwise made + available under the terms of this License. + + 1.10. "Original Software" means the Source Code and Executable + form of computer software code that is originally released + under this License. + + 1.11. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, + process, and apparatus claims, in any patent Licensable by + grantor. + + 1.12. "Source Code" means (a) the common form of computer software + code in which modifications are made and (b) associated + documentation included in or with such code. + + 1.13. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms + of, this License. For legal entities, "You" includes any + entity which controls, is controlled by, or is under common + control with You. For purposes of this definition, + "control" means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by + contract or otherwise, or (b) ownership of more than fifty + percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants. + + 2.1. The Initial Developer Grant. + + Conditioned upon Your compliance with Section 3.1 below and + subject to third party intellectual property claims, the Initial + Developer hereby grants You a world-wide, royalty-free, + non-exclusive license: + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer, to use, + reproduce, modify, display, perform, sublicense and + distribute the Original Software (or portions thereof), + with or without Modifications, and/or as part of a Larger + Work; and + + (b) under Patent Claims infringed by the making, using or + selling of Original Software, to make, have made, use, + practice, sell, and offer for sale, and/or otherwise + dispose of the Original Software (or portions thereof). + + (c) The licenses granted in Sections 2.1(a) and (b) are + effective on the date Initial Developer first distributes + or otherwise makes the Original Software available to a + third party under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: (1) for code that You delete from the Original + Software, or (2) for infringements caused by: (i) the + modification of the Original Software, or (ii) the + combination of the Original Software with other software + or devices. + + 2.2. Contributor Grant. + + Conditioned upon Your compliance with Section 3.1 below and + subject to third party intellectual property claims, each + Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor to use, reproduce, + modify, display, perform, sublicense and distribute the + Modifications created by such Contributor (or portions + thereof), either on an unmodified basis, with other + Modifications, as Covered Software and/or as part of a + Larger Work; and + + (b) under Patent Claims infringed by the making, using, or + selling of Modifications made by that Contributor either + alone and/or in combination with its Contributor Version + (or portions of such combination), to make, use, sell, + offer for sale, have made, and/or otherwise dispose of: + (1) Modifications made by that Contributor (or portions + thereof); and (2) the combination of Modifications made by + that Contributor with its Contributor Version (or portions + of such combination). + + (c) The licenses granted in Sections 2.2(a) and 2.2(b) are + effective on the date Contributor first distributes or + otherwise makes the Modifications available to a third + party. + + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: (1) for any code that Contributor has deleted + from the Contributor Version; (2) for infringements caused + by: (i) third party modifications of Contributor Version, + or (ii) the combination of Modifications made by that + Contributor with other software (except as part of the + Contributor Version) or other devices; or (3) under Patent + Claims infringed by Covered Software in the absence of + Modifications made by that Contributor. + +3. Distribution Obligations. + + 3.1. Availability of Source Code. + + Any Covered Software that You distribute or otherwise make + available in Executable form must also be made available in Source + Code form and that Source Code form must be distributed only under + the terms of this License. You must include a copy of this + License with every copy of the Source Code form of the Covered + Software You distribute or otherwise make available. You must + inform recipients of any such Covered Software in Executable form + as to how they can obtain such Covered Software in Source Code + form in a reasonable manner on or through a medium customarily + used for software exchange. + + 3.2. Modifications. + + The Modifications that You create or to which You contribute are + governed by the terms of this License. You represent that You + believe Your Modifications are Your original creation(s) and/or + You have sufficient rights to grant the rights conveyed by this + License. + + 3.3. Required Notices. + + You must include a notice in each of Your Modifications that + identifies You as the Contributor of the Modification. You may + not remove or alter any copyright, patent or trademark notices + contained within the Covered Software, or any notices of licensing + or any descriptive text giving attribution to any Contributor or + the Initial Developer. + + 3.4. Application of Additional Terms. + + You may not offer or impose any terms on any Covered Software in + Source Code form that alters or restricts the applicable version + of this License or the recipients' rights hereunder. You may + choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of + Covered Software. However, you may do so only on Your own behalf, + and not on behalf of the Initial Developer or any Contributor. + You must make it absolutely clear that any such warranty, support, + indemnity or liability obligation is offered by You alone, and You + hereby agree to indemnify the Initial Developer and every + Contributor for any liability incurred by the Initial Developer or + such Contributor as a result of warranty, support, indemnity or + liability terms You offer. + + 3.5. Distribution of Executable Versions. + + You may distribute the Executable form of the Covered Software + under the terms of this License or under the terms of a license of + Your choice, which may contain terms different from this License, + provided that You are in compliance with the terms of this License + and that the license for the Executable form does not attempt to + limit or alter the recipient's rights in the Source Code form from + the rights set forth in this License. If You distribute the + Covered Software in Executable form under a different license, You + must make it absolutely clear that any terms which differ from + this License are offered by You alone, not by the Initial + Developer or Contributor. You hereby agree to indemnify the + Initial Developer and every Contributor for any liability incurred + by the Initial Developer or such Contributor as a result of any + such terms You offer. + + 3.6. Larger Works. + + You may create a Larger Work by combining Covered Software with + other code not governed by the terms of this License and + distribute the Larger Work as a single product. In such a case, + You must make sure the requirements of this License are fulfilled + for the Covered Software. + +4. Versions of the License. + + 4.1. New Versions. + + Sun Microsystems, Inc. is the initial license steward and may + publish revised and/or new versions of this License from time to + time. Each version will be given a distinguishing version number. + Except as provided in Section 4.3, no one other than the license + steward has the right to modify this License. + + 4.2. Effect of New Versions. + + You may always continue to use, distribute or otherwise make the + Covered Software available under the terms of the version of the + License under which You originally received the Covered Software. + If the Initial Developer includes a notice in the Original + Software prohibiting it from being distributed or otherwise made + available under any subsequent version of the License, You must + distribute and make the Covered Software available under the terms + of the version of the License under which You originally received + the Covered Software. Otherwise, You may also choose to use, + distribute or otherwise make the Covered Software available under + the terms of any subsequent version of the License published by + the license steward. + + 4.3. Modified Versions. + + When You are an Initial Developer and You want to create a new + license for Your Original Software, You may create and use a + modified version of this License if You: (a) rename the license + and remove any references to the name of the license steward + (except to note that the license differs from this License); and + (b) otherwise make it clear that the license contains terms which + differ from this License. + +5. DISCLAIMER OF WARRANTY. + + COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" + BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, + INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED + SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR + PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND + PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY + COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE + INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY + NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF + WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS + DISCLAIMER. + +6. TERMINATION. + + 6.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to + cure such breach within 30 days of becoming aware of the breach. + Provisions which, by their nature, must remain in effect beyond + the termination of this License shall survive. + + 6.2. If You assert a patent infringement claim (excluding + declaratory judgment actions) against Initial Developer or a + Contributor (the Initial Developer or Contributor against whom You + assert such claim is referred to as "Participant") alleging that + the Participant Software (meaning the Contributor Version where + the Participant is a Contributor or the Original Software where + the Participant is the Initial Developer) directly or indirectly + infringes any patent, then any and all rights granted directly or + indirectly to You by such Participant, the Initial Developer (if + the Initial Developer is not the Participant) and all Contributors + under Sections 2.1 and/or 2.2 of this License shall, upon 60 days + notice from Participant terminate prospectively and automatically + at the expiration of such 60 day notice period, unless if within + such 60 day period You withdraw Your claim with respect to the + Participant Software against such Participant either unilaterally + or pursuant to a written agreement with Participant. + + 6.3. In the event of termination under Sections 6.1 or 6.2 above, + all end user licenses that have been validly granted by You or any + distributor hereunder prior to termination (excluding licenses + granted to You by any distributor) shall survive termination. + +7. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE + INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF + COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE + LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR + CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT + LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK + STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL + INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT + APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO + NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR + CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT + APPLY TO YOU. + +8. U.S. GOVERNMENT END USERS. + + The Covered Software is a "commercial item," as that term is + defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial + computer software" (as that term is defined at 48 + C.F.R. 252.227-7014(a)(1)) and "commercial computer software + documentation" as such terms are used in 48 C.F.R. 12.212 + (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 + C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all + U.S. Government End Users acquire Covered Software with only those + rights set forth herein. This U.S. Government Rights clause is in + lieu of, and supersedes, any other FAR, DFAR, or other clause or + provision that addresses Government rights in computer software + under this License. + +9. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed + by the law of the jurisdiction specified in a notice contained + within the Original Software (except to the extent applicable law, + if any, provides otherwise), excluding such jurisdiction's + conflict-of-law provisions. Any litigation relating to this + License shall be subject to the jurisdiction of the courts located + in the jurisdiction and venue specified in a notice contained + within the Original Software, with the losing party responsible + for costs, including, without limitation, court costs and + reasonable attorneys' fees and expenses. The application of the + United Nations Convention on Contracts for the International Sale + of Goods is expressly excluded. Any law or regulation which + provides that the language of a contract shall be construed + against the drafter shall not apply to this License. You agree + that You alone are responsible for compliance with the United + States export administration regulations (and the export control + laws and regulation of any other countries) when You use, + distribute or otherwise make available any Covered Software. + +10. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or + indirectly, out of its utilization of rights under this License + and You agree to work with Initial Developer and Contributors to + distribute such responsibility on an equitable basis. Nothing + herein is intended or shall be deemed to constitute any admission + of liability. + +-------------------------------------------------------------------- + +NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND +DISTRIBUTION LICENSE (CDDL) + +For Covered Software in this distribution, this License shall +be governed by the laws of the State of California (excluding +conflict-of-law provisions). + +Any litigation relating to this License shall be subject to the +jurisdiction of the Federal Courts of the Northern District of +California and the state courts of the State of California, with +venue lying in Santa Clara County, California. diff --git a/native/libMicro-0.4.0/README b/native/libMicro-0.4.0/README new file mode 100644 index 0000000..d29768e --- /dev/null +++ b/native/libMicro-0.4.0/README @@ -0,0 +1,85 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +Building the tarball +-------------------- +As long as cc is in your path, (gcc on Linux), + +% tar xf libMicro.tar +% make + +will build the benchmark suite. + +Running the benchmarks +----------------------- + +A set of generic scripts to invoke each micro benchmark +are created in the bin directory; these may be invoked +directly. Note that the actual binaries are created in +OS-specific directories; this allows one to build for +all varients (x86/sparc/Solaris/Linux) in one place. + +To collect a complete set of benchmarks, use the bench +script and redirect its output to a file. + +% ./bench > output + +To compare the output of two or more runs, use multiview in the src +directory: + +% ./multiview reference compare1 compare2 compare2 > compare.html +% + +where the reference and compare files contain the output of different +libmicro runs. + +The compare.html file will allow quick comparisons to be drawn, +allowing a variety of experiments to be quickly analyzed. + +All benchmarks support the following options: + + [-1] (single process; overrides -P > 1) + [-A] (align with clock) + [-B batch-size (default 10)] + [-C minimum number of samples (default 0)] + [-D duration in msecs (default 10s)] + [-E (echo name to stderr)] + [-H] (suppress headers) + [-I] specify approx. time per op in nsecs + [-L] (print argument line) + [-M] (reports mean rather than median) + [-N test-name ] + [-P processes (default 1)] + [-S] (print detailed stats) + [-T threads (default 1)] + [-V] (print the libMicro version and exit) + [-W] (flag possible benchmark problems) + + diff --git a/native/libMicro-0.4.0/_Android.mk b/native/libMicro-0.4.0/_Android.mk new file mode 100644 index 0000000..864f1ee --- /dev/null +++ b/native/libMicro-0.4.0/_Android.mk @@ -0,0 +1,13 @@ +include $(CLEAR_VARS) + +MODULE:= $(TARGET_MODULE) + +LOCAL_CFLAGS:= -D_REENTRANT -D_REENTRANT -lpthread -lm + +LOCAL_SRC_FILES:= $(MODULE).c +LOCAL_STATIC_LIBRARIES:= libmicro +LOCAL_MODULE:= bench_$(MODULE) +LOCAL_MODULE_TAGS := optional + +include $(BUILD_EXECUTABLE) + diff --git a/native/libMicro-0.4.0/_Executables.mk b/native/libMicro-0.4.0/_Executables.mk new file mode 100644 index 0000000..31277f7 --- /dev/null +++ b/native/libMicro-0.4.0/_Executables.mk @@ -0,0 +1,105 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + +EXEs= \ + getpid \ + bind \ + cascade_mutex \ + cascade_fcntl \ + cascade_flock \ + chdir \ + close \ + close_tcp \ + connection \ + dup \ + exec \ + exit \ + exp \ + fcntl \ + fcntl_ndelay \ + file_lock \ + fork \ + getenv \ + gettimeofday \ + getpeername \ + getrusage \ + getsockname \ + isatty \ + listen \ + localtime_r \ + log \ + longjmp \ + lrand48 \ + lseek \ + malloc \ + memcpy \ + memmove \ + memrand \ + memset \ + mktime \ + mprotect \ + mmap \ + msync \ + munmap \ + mutex \ + nop \ + open \ + pipe \ + poll \ + pread \ + pthread_create \ + pwrite \ + read \ + realpath \ + recurse \ + select \ + setsockopt \ + sigaction \ + siglongjmp \ + signal \ + sigprocmask \ + socket \ + socketpair \ + stat \ + strcasecmp \ + strchr \ + strcmp \ + strcpy \ + strftime \ + strlen \ + strtol \ + system \ + time \ + times \ + write \ + writev + + diff --git a/native/libMicro-0.4.0/atomic.c b/native/libMicro-0.4.0/atomic.c new file mode 100644 index 0000000..e005b46 --- /dev/null +++ b/native/libMicro-0.4.0/atomic.c @@ -0,0 +1,74 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmarks atomic add on Solaris - useful for platform comparisons. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "note: measures atomic_add_32_nv()"); + + lm_tsdsize = 0; + + return (0); +} + +static unsigned int value = 0; + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + unsigned int i; + for (i = 0; i < lm_optB; i += 10) { + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + (void) atomic_add_32_nv(&value, 1); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/bench.sh b/native/libMicro-0.4.0/bench.sh new file mode 100644 index 0000000..b700704 --- /dev/null +++ b/native/libMicro-0.4.0/bench.sh @@ -0,0 +1,482 @@ +#!/bin/sh +# +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +bench_version=0.4.0 +libmicro_version=`bin/tattle -V` + +case $libmicro_version in +$bench_version) + ;; +*) + echo "ERROR: libMicro version doesn't match 'bench' script version" + exit 1 +esac + +TMPROOT=/tmp/libmicro.$$ +VARROOT=/var/tmp/libmicro.$$ +mkdir -p $TMPROOT +mkdir -p $VARROOT +trap "rm -rf $TMPROOT $VARROOT" 0 2 + +TFILE=$TMPROOT/data +IFILE=$TMPROOT/ifile +TDIR1=$TMPROOT/0/1/2/3/4/5/6/7/8/9 +TDIR2=$TMPROOT/1/2/3/4/5/6/7/8/9/0 +VFILE=$VARROOT/data +VDIR1=$VARROOT/0/1/2/3/4/5/6/7/8/9 +VDIR2=$VARROOT/1/2/3/4/5/6/7/8/9/0 + + +OPTS="-E -C 200 -L -S -W" + +dd if=/dev/zero of=$TFILE bs=1024k count=10 2>/dev/null +dd if=/dev/zero of=$VFILE bs=1024k count=10 2>/dev/null +mkdir -p $TDIR1 $TDIR2 +mkdir -p $VDIR1 $VDIR2 + +touch $IFILE + +ARCH=`arch -k` + +# produce benchmark header for easier comparisons + +hostname=`uname -n` + +if [ -f /usr/sbin/psrinfo ]; then + p_count=`psrinfo|wc -l` + p_mhz=`psrinfo -v | awk '/operates/{print $6 "MHz"; exit }'` + p_type=`psrinfo -vp 2>/dev/null | awk '{if (NR == 3) {print $0; exit}}'` +fi + +if [ -f /proc/cpuinfo ]; then + p_count=`egrep processor /proc/cpuinfo | wc -l` + p_mhz=`awk -F: '/cpu MHz/{printf("%5.0f00Mhz\n",$2/100); exit}' /proc/cpuinfo` + p_type=`awk -F: '/model name/{print $2; exit}' /proc/cpuinfo` +fi + +printf "!Libmicro_#: %30s\n" $libmicro_version +printf "!Options: %30s\n" "$OPTS" +printf "!Machine_name: %30s\n" $hostname +printf "!OS_name: %30s\n" `uname -s` +printf "!OS_release: %30s\n" `uname -r` +printf "!OS_build: %30.18s\n" "`uname -v`" +printf "!Processor: %30s\n" `uname -m` +printf "!#CPUs: %30s\n" $p_count +printf "!CPU_MHz: %30s\n" $p_mhz +printf "!CPU_NAME: %30s\n" "$p_type" +printf "!IP_address: %30s\n" `getent hosts $hostname | awk '{print $1}'` +printf "!Run_by: %30s\n" $LOGNAME +printf "!Date: %30s\n" "`date '+%D %R'`" +printf "!Compiler: %30s\n" `bin/tattle -c` +printf "!Compiler Ver.:%30s\n" "`bin/tattle -v`" +printf "!sizeof(long): %30s\n" `bin/tattle -s` +printf "!extra_CFLAGS: %30s\n" "`bin/tattle -f`" +printf "!TimerRes: %30s\n" "`bin/tattle -r`" + +mkdir -p $TMPROOT/bin +cp bin-$ARCH/exec_bin $TMPROOT/bin/$A + +while read A B +do + # $A contains the command, $B contains the arguments + # we echo blank lines and comments + # we ship anything which fails to match *$1* (useful + # if we only want to test one case, but a nasty hack) + + case $A in + ""|"#"*) + echo "$A $B" + continue + ;; + *$1*) + ;; + *) + continue + esac + + if [ ! -f $TMPROOT/bin/$A ] + then + cp bin-$ARCH/$A $TMPROOT/bin/$A + fi + (cd $TMPROOT && eval "bin/$A $B") +done <<. +# +# Obligatory null system call: use very short time +# for default since SuSe implements this "syscall" in userland +# +getpid $OPTS -N "getpid" -I 5 + +getenv $OPTS -N "getenv" -s 100 -I 100 +getenv $OPTS -N "getenvT2" -s 100 -I 100 -T 2 + +gettimeofday $OPTS -N "gettimeofday" + +log $OPTS -N "log" -I 20 +exp $OPTS -N "exp" -I 20 +lrand48 $OPTS -N "lrand48" + +memset $OPTS -N "memset_10" -s 10 -I 10 +memset $OPTS -N "memset_256" -s 256 -I 20 +memset $OPTS -N "memset_256_u" -s 256 -a 1 -I 20 +memset $OPTS -N "memset_1k" -s 1k -I 100 +memset $OPTS -N "memset_4k" -s 4k -I 250 +memset $OPTS -N "memset_4k_uc" -s 4k -u -I 400 + +memset $OPTS -N "memset_10k" -s 10k -I 600 +memset $OPTS -N "memset_1m" -s 1m -I 200000 +memset $OPTS -N "memset_10m" -s 10m -I 2000000 +memset $OPTS -N "memsetP2_10m" -s 10m -P 2 -I 2000000 + +memrand $OPTS -N "memrand" -s 128m -B 10000 +cachetocache $OPTS -N "cachetocache" -s 100k -T 2 -I 200 + +isatty $OPTS -N "isatty_yes" +isatty $OPTS -N "isatty_no" -f $IFILE + +malloc $OPTS -N "malloc_10" -s 10 -g 10 -I 50 +malloc $OPTS -N "malloc_100" -s 100 -g 10 -I 50 +malloc $OPTS -N "malloc_1k" -s 1k -g 10 -I 50 +malloc $OPTS -N "malloc_10k" -s 10k -g 10 -I 50 +malloc $OPTS -N "malloc_100k" -s 100k -g 10 -I 2000 + +malloc $OPTS -N "mallocT2_10" -s 10 -g 10 -T 2 -I 200 +malloc $OPTS -N "mallocT2_100" -s 100 -g 10 -T 2 -I 200 +malloc $OPTS -N "mallocT2_1k" -s 1k -g 10 -T 2 -I 200 +malloc $OPTS -N "mallocT2_10k" -s 10k -g 10 -T 2 -I 200 +malloc $OPTS -N "mallocT2_100k" -s 100k -g 10 -T 2 -I 10000 + +close $OPTS -N "close_bad" -B 32 -b +close $OPTS -N "close_tmp" -B 32 -f $TFILE +close $OPTS -N "close_usr" -B 32 -f $VFILE +close $OPTS -N "close_zero" -B 32 -f /dev/zero + +memcpy $OPTS -N "memcpy_10" -s 10 -I 10 +memcpy $OPTS -N "memcpy_1k" -s 1k -I 50 +memcpy $OPTS -N "memcpy_10k" -s 10k -I 800 +memcpy $OPTS -N "memcpy_1m" -s 1m -I 500000 +memcpy $OPTS -N "memcpy_10m" -s 10m -I 5000000 + +strcpy $OPTS -N "strcpy_10" -s 10 -I 5 +strcpy $OPTS -N "strcpy_1k" -s 1k -I 100 + +strlen $OPTS -N "strlen_10" -s 10 -I 5 +strlen $OPTS -N "strlen_1k" -s 1k -I 100 + +strchr $OPTS -N "strchr_10" -s 10 -I 5 +strchr $OPTS -N "strchr_1k" -s 1k -I 200 +strcmp $OPTS -N "strcmp_10" -s 10 -I 10 +strcmp $OPTS -N "strcmp_1k" -s 1k -I 200 + +strcasecmp $OPTS -N "scasecmp_10" -s 10 -I 50 +strcasecmp $OPTS -N "scasecmp_1k" -s 1k -I 20000 + +strtol $OPTS -N "strtol" -I 20 + +getcontext $OPTS -N "getcontext" -I 100 +setcontext $OPTS -N "setcontext" -I 100 + +mutex $OPTS -N "mutex_st" -I 10 +mutex $OPTS -N "mutex_mt" -t -I 10 +mutex $OPTS -N "mutex_T2" -T 2 -I 100 + +longjmp $OPTS -N "longjmp" -I 10 +siglongjmp $OPTS -N "siglongjmp" -I 20 + +getrusage $OPTS -N "getrusage" -I 200 + +times $OPTS -N "times" -I 200 +time $OPTS -N "time" -I 50 +localtime_r $OPTS -N "localtime_r" -I 200 +strftime $OPTS -N "strftime" -I 10000 + +mktime $OPTS -N "mktime" -I 500 +mktime $OPTS -N "mktimeT2" -T 2 -I 1000 + +cascade_mutex $OPTS -N "c_mutex_1" -I 50 +cascade_mutex $OPTS -N "c_mutex_10" -T 10 -I 5000 +cascade_mutex $OPTS -N "c_mutex_200" -T 200 -I 2000000 + +cascade_cond $OPTS -N "c_cond_1" -I 100 +cascade_cond $OPTS -N "c_cond_10" -T 10 -I 3000 +cascade_cond $OPTS -N "c_cond_200" -T 200 -I 2000000 + +cascade_lockf $OPTS -N "c_lockf_1" -I 1000 +cascade_lockf $OPTS -N "c_lockf_10" -P 10 -I 50000 +cascade_lockf $OPTS -N "c_lockf_200" -P 200 -I 5000000 + +cascade_flock $OPTS -N "c_flock" -I 1000 +cascade_flock $OPTS -N "c_flock_10" -P 10 -I 50000 +cascade_flock $OPTS -N "c_flock_200" -P 200 -I 5000000 + +cascade_fcntl $OPTS -N "c_fcntl_1" -I 2000 +cascade_fcntl $OPTS -N "c_fcntl_10" -P 10 -I 20000 +cascade_fcntl $OPTS -N "c_fcntl_200" -P 200 -I 5000000 + +file_lock $OPTS -N "file_lock" -I 1000 + +getsockname $OPTS -N "getsockname" -I 100 +getpeername $OPTS -N "getpeername" -I 100 + +chdir $OPTS -N "chdir_tmp" -I 2000 $TDIR1 $TDIR2 +chdir $OPTS -N "chdir_usr" -I 2000 $VDIR1 $VDIR2 + +chdir $OPTS -N "chgetwd_tmp" -I 3000 -g $TDIR1 $TDIR2 +chdir $OPTS -N "chgetwd_usr" -I 3000 -g $VDIR1 $VDIR2 + +realpath $OPTS -N "realpath_tmp" -I 3000 -f $TDIR1 +realpath $OPTS -N "realpath_usr" -I 3000 -f $VDIR1 + +stat $OPTS -N "stat_tmp" -I 1000 -f $TFILE +stat $OPTS -N "stat_usr" -I 1000 -f $VFILE + +fcntl $OPTS -N "fcntl_tmp" -I 100 -f $TFILE +fcntl $OPTS -N "fcntl_usr" -I 100 -f $VFILE +fcntl_ndelay $OPTS -N "fcntl_ndelay" -I 100 + +lseek $OPTS -N "lseek_t8k" -s 8k -I 50 -f $TFILE +lseek $OPTS -N "lseek_u8k" -s 8k -I 50 -f $VFILE + +open $OPTS -N "open_tmp" -B 256 -f $TFILE +open $OPTS -N "open_usr" -B 256 -f $VFILE +open $OPTS -N "open_zero" -B 256 -f /dev/zero + +dup $OPTS -N "dup" -B 512 + +socket $OPTS -N "socket_u" -B 256 +socket $OPTS -N "socket_i" -B 256 -f PF_INET + +socketpair $OPTS -N "socketpair" -B 256 + +setsockopt $OPTS -N "setsockopt" -I 200 + +bind $OPTS -N "bind" -B 100 + +listen $OPTS -N "listen" -B 100 + +connection $OPTS -N "connection" -B 256 + +poll $OPTS -N "poll_10" -n 10 -I 500 +poll $OPTS -N "poll_100" -n 100 -I 1000 +poll $OPTS -N "poll_1000" -n 1000 -I 5000 + +poll $OPTS -N "poll_w10" -n 10 -I 500 -w 1 +poll $OPTS -N "poll_w100" -n 100 -I 2000 -w 10 +poll $OPTS -N "poll_w1000" -n 1000 -I 40000 -w 100 + +select $OPTS -N "select_10" -n 10 -I 500 +select $OPTS -N "select_100" -n 100 -I 1000 +select $OPTS -N "select_1000" -n 1000 -I 5000 + +select $OPTS -N "select_w10" -n 10 -I 500 -w 1 +select $OPTS -N "select_w100" -n 100 -I 2000 -w 10 +select $OPTS -N "select_w1000" -n 1000 -I 40000 -w 100 + +semop $OPTS -N "semop" -I 200 + +sigaction $OPTS -N "sigaction" -I 100 +signal $OPTS -N "signal" -I 1000 +sigprocmask $OPTS -N "sigprocmask" -I 200 + +pthread_create $OPTS -N "pthread_8" -B 8 +pthread_create $OPTS -N "pthread_32" -B 32 +pthread_create $OPTS -N "pthread_128" -B 128 +pthread_create $OPTS -N "pthread_512" -B 512 + +fork $OPTS -N "fork_10" -B 10 +fork $OPTS -N "fork_100" -B 100 -C 100 +fork $OPTS -N "fork_1000" -B 1000 -C 50 + +exit $OPTS -N "exit_10" -B 10 +exit $OPTS -N "exit_100" -B 100 +exit $OPTS -N "exit_1000" -B 1000 -C 50 + +exit $OPTS -N "exit_10_nolibc" -e -B 10 + +exec $OPTS -N "exec" -B 10 + +system $OPTS -N "system" -I 1000000 + +recurse $OPTS -N "recurse" -B 512 + +read $OPTS -N "read_t1k" -s 1k -f $TFILE +read $OPTS -N "read_t10k" -s 10k -f $TFILE +read $OPTS -N "read_t100k" -s 100k -f $TFILE + +read $OPTS -N "read_u1k" -s 1k -f $VFILE +read $OPTS -N "read_u10k" -s 10k -f $VFILE +read $OPTS -N "read_u100k" -s 100k -f $VFILE + +read $OPTS -N "read_z1k" -s 1k -f /dev/zero +read $OPTS -N "read_z10k" -s 10k -f /dev/zero +read $OPTS -N "read_z100k" -s 100k -f /dev/zero +read $OPTS -N "read_zw100k" -s 100k -w -f /dev/zero + +write $OPTS -N "write_t1k" -s 1k -f $TFILE +write $OPTS -N "write_t10k" -s 10k -f $TFILE +write $OPTS -N "write_t100k" -s 100k -f $TFILE + +write $OPTS -N "write_u1k" -s 1k -f $VFILE +write $OPTS -N "write_u10k" -s 10k -f $VFILE +write $OPTS -N "write_u100k" -s 100k -f $VFILE + +write $OPTS -N "write_n1k" -s 1k -I 100 -B 0 -f /dev/null +write $OPTS -N "write_n10k" -s 10k -I 100 -B 0 -f /dev/null +write $OPTS -N "write_n100k" -s 100k -I 100 -B 0 -f /dev/null + +writev $OPTS -N "writev_t1k" -s 1k -f $TFILE +writev $OPTS -N "writev_t10k" -s 10k -f $TFILE +writev $OPTS -N "writev_t100k" -s 100k -f $TFILE + +writev $OPTS -N "writev_u1k" -s 1k -f $VFILE +writev $OPTS -N "writev_u10k" -s 10k -f $VFILE +writev $OPTS -N "writev_u100k" -s 100k -f $VFILE + +writev $OPTS -N "writev_n1k" -s 1k -I 100 -B 0 -f /dev/null +writev $OPTS -N "writev_n10k" -s 10k -I 100 -B 0 -f /dev/null +writev $OPTS -N "writev_n100k" -s 100k -I 100 -B 0 -f /dev/null + +pread $OPTS -N "pread_t1k" -s 1k -I 300 -f $TFILE +pread $OPTS -N "pread_t10k" -s 10k -I 1000 -f $TFILE +pread $OPTS -N "pread_t100k" -s 100k -I 10000 -f $TFILE + +pread $OPTS -N "pread_u1k" -s 1k -I 300 -f $VFILE +pread $OPTS -N "pread_u10k" -s 10k -I 1000 -f $VFILE +pread $OPTS -N "pread_u100k" -s 100k -I 10000 -f $VFILE + +pread $OPTS -N "pread_z1k" -s 1k -I 300 -f /dev/zero +pread $OPTS -N "pread_z10k" -s 10k -I 1000 -f /dev/zero +pread $OPTS -N "pread_z100k" -s 100k -I 2000 -f /dev/zero +pread $OPTS -N "pread_zw100k" -s 100k -w -I 10000 -f /dev/zero + +pwrite $OPTS -N "pwrite_t1k" -s 1k -I 500 -f $TFILE +pwrite $OPTS -N "pwrite_t10k" -s 10k -I 1000 -f $TFILE +pwrite $OPTS -N "pwrite_t100k" -s 100k -I 10000 -f $TFILE + +pwrite $OPTS -N "pwrite_u1k" -s 1k -I 500 -f $VFILE +pwrite $OPTS -N "pwrite_u10k" -s 10k -I 1000 -f $VFILE +pwrite $OPTS -N "pwrite_u100k" -s 100k -I 20000 -f $VFILE + +pwrite $OPTS -N "pwrite_n1k" -s 1k -I 100 -f /dev/null +pwrite $OPTS -N "pwrite_n10k" -s 10k -I 100 -f /dev/null +pwrite $OPTS -N "pwrite_n100k" -s 100k -I 100 -f /dev/null + +mmap $OPTS -N "mmap_z8k" -l 8k -I 1000 -f /dev/zero +mmap $OPTS -N "mmap_z128k" -l 128k -I 2000 -f /dev/zero +mmap $OPTS -N "mmap_t8k" -l 8k -I 1000 -f $TFILE +mmap $OPTS -N "mmap_t128k" -l 128k -I 1000 -f $TFILE +mmap $OPTS -N "mmap_u8k" -l 8k -I 1000 -f $VFILE +mmap $OPTS -N "mmap_u128k" -l 128k -I 1000 -f $VFILE +mmap $OPTS -N "mmap_a8k" -l 8k -I 200 -f MAP_ANON +mmap $OPTS -N "mmap_a128k" -l 128k -I 200 -f MAP_ANON + + +mmap $OPTS -N "mmap_rz8k" -l 8k -I 2000 -r -f /dev/zero +mmap $OPTS -N "mmap_rz128k" -l 128k -I 2000 -r -f /dev/zero +mmap $OPTS -N "mmap_rt8k" -l 8k -I 2000 -r -f $TFILE +mmap $OPTS -N "mmap_rt128k" -l 128k -I 20000 -r -f $TFILE +mmap $OPTS -N "mmap_ru8k" -l 8k -I 2000 -r -f $VFILE +mmap $OPTS -N "mmap_ru128k" -l 128k -I 20000 -r -f $VFILE +mmap $OPTS -N "mmap_ra8k" -l 8k -I 2000 -r -f MAP_ANON +mmap $OPTS -N "mmap_ra128k" -l 128k -I 20000 -r -f MAP_ANON + +mmap $OPTS -N "mmap_wz8k" -l 8k -I 5000 -w -f /dev/zero +mmap $OPTS -N "mmap_wz128k" -l 128k -I 50000 -w -f /dev/zero +mmap $OPTS -N "mmap_wt8k" -l 8k -I 5000 -w -f $TFILE +mmap $OPTS -N "mmap_wt128k" -l 128k -I 50000 -w -f $TFILE +mmap $OPTS -N "mmap_wu8k" -l 8k -I 5000 -w -f $VFILE +mmap $OPTS -N "mmap_wu128k" -l 128k -I 500000 -w -f $VFILE +mmap $OPTS -N "mmap_wa8k" -l 8k -I 3000 -w -f MAP_ANON +mmap $OPTS -N "mmap_wa128k" -l 128k -I 50000 -w -f MAP_ANON + +munmap $OPTS -N "unmap_z8k" -l 8k -I 500 -f /dev/zero +munmap $OPTS -N "unmap_z128k" -l 128k -I 500 -f /dev/zero +munmap $OPTS -N "unmap_t8k" -l 8k -I 500 -f $TFILE +munmap $OPTS -N "unmap_t128k" -l 128k -I 500 -f $TFILE +munmap $OPTS -N "unmap_u8k" -l 8k -I 500 -f $VFILE +munmap $OPTS -N "unmap_u128k" -l 128k -I 500 -f $VFILE +munmap $OPTS -N "unmap_a8k" -l 8k -I 500 -f MAP_ANON +munmap $OPTS -N "unmap_a128k" -l 128k -I 500 -f MAP_ANON + +munmap $OPTS -N "unmap_rz8k" -l 8k -I 1000 -r -f /dev/zero +munmap $OPTS -N "unmap_rz128k" -l 128k -I 2000 -r -f /dev/zero +munmap $OPTS -N "unmap_rt8k" -l 8k -I 1000 -r -f $TFILE +munmap $OPTS -N "unmap_rt128k" -l 128k -I 3000 -r -f $TFILE +munmap $OPTS -N "unmap_ru8k" -l 8k -I 1000 -r -f $VFILE +munmap $OPTS -N "unmap_ru128k" -l 128k -I 3000 -r -f $VFILE +munmap $OPTS -N "unmap_ra8k" -l 8k -I 1000 -r -f MAP_ANON +munmap $OPTS -N "unmap_ra128k" -l 128k -I 2000 -r -f MAP_ANON + +connection $OPTS -N "conn_connect" -B 256 -c + +munmap $OPTS -N "unmap_wz8k" -l 8k -I 1000 -w -f /dev/zero +munmap $OPTS -N "unmap_wz128k" -l 128k -I 8000 -w -f /dev/zero +munmap $OPTS -N "unmap_wt8k" -l 8k -I 1000 -w -f $TFILE +munmap $OPTS -N "unmap_wt128k" -l 128k -I 10000 -w -f $TFILE +munmap $OPTS -N "unmap_wu8k" -l 8k -I 1000 -w -f $VFILE +munmap $OPTS -N "unmap_wu128k" -l 128k -I 50000 -w -f $VFILE +munmap $OPTS -N "unmap_wa8k" -l 8k -I 1000 -w -f MAP_ANON +munmap $OPTS -N "unmap_wa128k" -l 128k -I 10000 -w -f MAP_ANON + + +mprotect $OPTS -N "mprot_z8k" -l 8k -I 300 -f /dev/zero +mprotect $OPTS -N "mprot_z128k" -l 128k -I 500 -f /dev/zero +mprotect $OPTS -N "mprot_wz8k" -l 8k -I 500 -w -f /dev/zero +mprotect $OPTS -N "mprot_wz128k" -l 128k -I 1000 -w -f /dev/zero +mprotect $OPTS -N "mprot_twz8k" -l 8k -I 1000 -w -t -f /dev/zero +mprotect $OPTS -N "mprot_tw128k" -l 128k -I 2000 -w -t -f /dev/zero +mprotect $OPTS -N "mprot_tw4m" -l 4m -w -t -B 1 -f /dev/zero + +pipe $OPTS -N "pipe_pst1" -s 1 -I 1000 -x pipe -m st +pipe $OPTS -N "pipe_pmt1" -s 1 -I 8000 -x pipe -m mt +pipe $OPTS -N "pipe_pmp1" -s 1 -I 8000 -x pipe -m mp +pipe $OPTS -N "pipe_pst4k" -s 4k -I 1000 -x pipe -m st +pipe $OPTS -N "pipe_pmt4k" -s 4k -I 8000 -x pipe -m mt +pipe $OPTS -N "pipe_pmp4k" -s 4k -I 8000 -x pipe -m mp + +pipe $OPTS -N "pipe_sst1" -s 1 -I 1000 -x sock -m st +pipe $OPTS -N "pipe_smt1" -s 1 -I 8000 -x sock -m mt +pipe $OPTS -N "pipe_smp1" -s 1 -I 8000 -x sock -m mp +pipe $OPTS -N "pipe_sst4k" -s 4k -I 1000 -x sock -m st +pipe $OPTS -N "pipe_smt4k" -s 4k -I 8000 -x sock -m mt +pipe $OPTS -N "pipe_smp4k" -s 4k -I 8000 -x sock -m mp + +pipe $OPTS -N "pipe_tst1" -s 1 -I 1000 -x tcp -m st +pipe $OPTS -N "pipe_tmt1" -s 1 -I 8000 -x tcp -m mt +pipe $OPTS -N "pipe_tmp1" -s 1 -I 8000 -x tcp -m mp +pipe $OPTS -N "pipe_tst4k" -s 4k -I 1000 -x tcp -m st +pipe $OPTS -N "pipe_tmt4k" -s 4k -I 8000 -x tcp -m mt +pipe $OPTS -N "pipe_tmp4k" -s 4k -I 8000 -x tcp -m mp + +connection $OPTS -N "conn_accept" -B 256 -a + +close_tcp $OPTS -N "close_tcp" -B 32 +. diff --git a/native/libMicro-0.4.0/benchmark_fini.c b/native/libMicro-0.4.0/benchmark_fini.c new file mode 100644 index 0000000..4952a9a --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_fini.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_fini + */ + + +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_fini() +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_finibatch.c b/native/libMicro-0.4.0/benchmark_finibatch.c new file mode 100644 index 0000000..482258c --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_finibatch.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_finibatch + */ + +#include +#include +#include + +#include "libmicro.h" + +/*ARGSUSED*/ +int +benchmark_finibatch(void *tsd) +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_finirun.c b/native/libMicro-0.4.0/benchmark_finirun.c new file mode 100644 index 0000000..52a5822 --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_finirun.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_finirun + */ + +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_finirun() +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_finiworker.c b/native/libMicro-0.4.0/benchmark_finiworker.c new file mode 100644 index 0000000..53161ea --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_finiworker.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_finiworker + */ + +#include +#include +#include + +#include "libmicro.h" + +/*ARGSUSED*/ +int +benchmark_finiworker(void *tsd) +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_init.c b/native/libMicro-0.4.0/benchmark_init.c new file mode 100644 index 0000000..83cec2b --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_init.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_init + */ + + +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_initbatch.c b/native/libMicro-0.4.0/benchmark_initbatch.c new file mode 100644 index 0000000..0a8cddd --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_initbatch.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_initbatch + */ + + +#include +#include +#include + +#include "libmicro.h" + +/*ARGSUSED*/ +int +benchmark_initbatch(void *tsd) +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_initrun.c b/native/libMicro-0.4.0/benchmark_initrun.c new file mode 100644 index 0000000..ac437d4 --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_initrun.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_initrun + */ + +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_initrun() +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_initworker.c b/native/libMicro-0.4.0/benchmark_initworker.c new file mode 100644 index 0000000..29b487c --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_initworker.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_initworker + */ + +#include +#include +#include + +#include "libmicro.h" + +/*ARGSUSED*/ +int +benchmark_initworker(void *tsd) +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_optswitch.c b/native/libMicro-0.4.0/benchmark_optswitch.c new file mode 100644 index 0000000..d46ee2f --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_optswitch.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_optswitch + */ + +#include +#include +#include + +#include "libmicro.h" + +/*ARGSUSED*/ +int +benchmark_optswitch(int opt, char *optarg) +{ + return (0); +} diff --git a/native/libMicro-0.4.0/benchmark_result.c b/native/libMicro-0.4.0/benchmark_result.c new file mode 100644 index 0000000..c8ab2f2 --- /dev/null +++ b/native/libMicro-0.4.0/benchmark_result.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * default implementation (nop) of benchmark_result + */ + +#include +#include +#include + +#include "libmicro.h" + +char * +benchmark_result() +{ + static char result = '\0'; + + return (&result); +} diff --git a/native/libMicro-0.4.0/bind.c b/native/libMicro-0.4.0/bind.c new file mode 100644 index 0000000..bd8e43b --- /dev/null +++ b/native/libMicro-0.4.0/bind.c @@ -0,0 +1,163 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmark for bind... keep in mind tcp hash chain effects + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define FIRSTPORT 12345 + +typedef struct { + int *ts_lsns; + struct sockaddr_in *ts_adds; +} tsd_t; + +static int optz = -0; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + lm_defB = 256; + (void) sprintf(lm_optstr, "z"); + + (void) sprintf(lm_usage, + " [-z bind to port 0 rather than seq. number\n" + "notes: measures bind() on TCP"); + + return (0); +} + +int +benchmark_initrun() +{ + (void) setfdlimit(lm_optB * lm_optT + 10); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'z': + optz = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j; + int opt = 1; + struct hostent *host; + int errors = 0; + + ts->ts_lsns = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_lsns == NULL) + errors ++; + + ts->ts_adds = (struct sockaddr_in *)malloc(lm_optB * + sizeof (struct sockaddr_in)); + if (ts->ts_adds == NULL) + errors ++; + + j = FIRSTPORT; + for (i = 0; i < lm_optB; i++) { + if ((ts->ts_lsns[i] = socket(PF_INET, SOCK_STREAM, 0)) == -1) + errors ++; + + if (setsockopt(ts->ts_lsns[i], SOL_SOCKET, SO_REUSEADDR, + &opt, sizeof (int)) == -1) + errors ++; + + if ((host = gethostbyname("localhost")) == NULL) + errors ++; + + (void) memset(&ts->ts_adds[i], 0, + sizeof (struct sockaddr_in)); + ts->ts_adds[i].sin_family = AF_INET; + ts->ts_adds[i].sin_port = (optz ? 0 : htons(j++)); + (void) memcpy(&ts->ts_adds[i].sin_addr.s_addr, + host->h_addr_list[0], sizeof (struct in_addr)); + } + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if ((bind(ts->ts_lsns[i], + (struct sockaddr *)&ts->ts_adds[i], + sizeof (struct sockaddr_in)) != 0) && + (errno != EADDRINUSE)) + res->re_errors ++; + } + res->re_count = i; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) + (void) close(ts->ts_lsns[i]); + return (0); +} diff --git a/native/libMicro-0.4.0/cachetocache.c b/native/libMicro-0.4.0/cachetocache.c new file mode 100644 index 0000000..ffe9ddf --- /dev/null +++ b/native/libMicro-0.4.0/cachetocache.c @@ -0,0 +1,222 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * routine to benchmark cache-to-cache transfer times... uses + * solaris features to find and bind to cpus in the current + * processor set, so not likely to work elsewhere. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +static long opts = 1024*512; + +typedef struct { + long **ts_data; + long ts_result; + pthread_mutex_t ts_lock; +} tsd_t; + +static unsigned int ncpu = 1024; + +static tsd_t *thread_data[1024]; +static processorid_t cpus[1024]; + +int traverse_ptrchain(long **, int, int); + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s:"); + + (void) sprintf(lm_usage, + " [-s size] size of access area in bytes" + " (default %ld)\n" + "notes: measures cache to cache transfer times on Solaris\n", + opts); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 's': + opts = sizetoint(optarg); + break; + default: + return (-1); + } + + return (0); +} + +int +benchmark_initrun() +{ + if (pset_info(PS_MYID, NULL, &ncpu, cpus) < 0) { + perror("pset_info"); + return (1); + } + + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j; + processorid_t cpu; + + ts->ts_data = malloc(opts); + + if (ts->ts_data == NULL) { + return (1); + } + + (void) pthread_mutex_init(&ts->ts_lock, NULL); + + + if (processor_bind(P_LWPID, P_MYID, + cpu = cpus[(pthread_self() - 1) % ncpu], + NULL) < 0) { + perror("processor_bind:"); + return (1); + } + + (void) printf("# thread %d using processor %d\n", pthread_self(), cpu); + + /* + * use lmbench style backwards stride + */ + + for (i = 0; i < opts / sizeof (long); i++) { + j = i - 128; + if (j < 0) + j = j + opts / sizeof (long); + ts->ts_data[i] = (long *)&(ts->ts_data[j]); + } + + thread_data[pthread_self() - 1] = ts; + + return (0); +} + +/* + * here we go in order for each thread, causing inherent serialization + * this is normally not a good idea, but in this case we're trying to + * measure cache-to-cache transfer times, and if we run threads in + * parallel we're likely to see saturation effects rather than cache-to-cache, + * esp. on wimpy memory platforms like P4. + */ + + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts; + int i, j; + int count = opts / 128 / sizeof (long); + + for (j = 0; j < lm_optB; j++) + for (i = 0; i < lm_optT; i++) { + ts = thread_data[i]; + (void) pthread_mutex_lock(&ts->ts_lock); + ts->ts_result += traverse_ptrchain( + (long **)ts->ts_data, count, 0); + (void) pthread_mutex_unlock(&ts->ts_lock); + } + + res->re_count = lm_optB * lm_optT * count; + + return (0); +} + +int +traverse_ptrchain(long **ptr, int count, int value) +{ + int i; + + for (i = 0; i < count; i += 10) { + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + ptr = (long **)*ptr; + *ptr = *ptr + value; + } + return ((int)*ptr); /* bogus return */ +} + + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8ld ", opts); + + + return (result); +} diff --git a/native/libMicro-0.4.0/cascade_cond.c b/native/libMicro-0.4.0/cascade_cond.c new file mode 100644 index 0000000..bf22110 --- /dev/null +++ b/native/libMicro-0.4.0/cascade_cond.c @@ -0,0 +1,278 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * The "cascade" test case is a multiprocess/multithread batten-passing model + * using lock primitives alone for synchronisation. Threads are arranged in a + * ring. Each thread has two locks of its own on which it blocks, and is able + * to manipulate the two locks belonging to the thread which follows it in the + * ring. + * + * The number of threads (nthreads) is specified by the generic libMicro -P/-T + * options. With nthreads == 1 (the default) the uncontended case can be timed. + * + * The main logic is generic and allows any simple blocking API to be tested. + * The API-specific component is clearly indicated. + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + int ts_id; + int ts_us0; /* our lock indices */ + int ts_us1; + int ts_them0; /* their lock indices */ + int ts_them1; +} tsd_t; + +static int nthreads; + +/* + * API-specific code BEGINS here + */ + +static int opto = 0; +static int opts = 0; +static int nlocks; +static pthread_mutex_t *mxs; +static pthread_cond_t *cvs; +static int *conds; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "os"); + + lm_defN = "cscd_cond"; + + (void) sprintf(lm_usage, + " [-o] (do signal outside mutex)\n" + " [-s] (force PTHREAD_PROCESS_SHARED)\n" + "notes: thread cascade using pthread_conds\n"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'o': + opto = 1; + break; + case 's': + opts = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + int i; + int e = 0; + pthread_mutexattr_t ma; + pthread_condattr_t ca; + + nthreads = lm_optP * lm_optT; + nlocks = nthreads * 2; + /*LINTED*/ + mxs = (pthread_mutex_t *)mmap(NULL, + nlocks * sizeof (pthread_mutex_t), + PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, + -1, 0L); + if (mxs == MAP_FAILED) { + return (1); + } + + /*LINTED*/ + cvs = (pthread_cond_t *)mmap(NULL, + nlocks * sizeof (pthread_cond_t), + PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, + -1, 0L); + if (cvs == MAP_FAILED) { + return (1); + } + + /*LINTED*/ + conds = (int *)mmap(NULL, + nlocks * sizeof (pthread_cond_t), + PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, + -1, 0L); + if (conds == MAP_FAILED) { + return (1); + } + + (void) pthread_mutexattr_init(&ma); + (void) pthread_condattr_init(&ca); + if (lm_optP > 1 || opts) { + (void) pthread_mutexattr_setpshared(&ma, + PTHREAD_PROCESS_SHARED); + (void) pthread_condattr_setpshared(&ca, + PTHREAD_PROCESS_SHARED); + } else { + (void) pthread_mutexattr_setpshared(&ma, + PTHREAD_PROCESS_PRIVATE); + (void) pthread_condattr_setpshared(&ca, + PTHREAD_PROCESS_PRIVATE); + } + + for (i = 0; i < nlocks; i++) { + (void) pthread_mutex_init(&mxs[i], &ma); + (void) pthread_cond_init(&cvs[i], &ca); + conds[i] = 0; + } + + return (e); +} + +int +block(int index) +{ + (void) pthread_mutex_lock(&mxs[index]); + while (conds[index] != 0) { + (void) pthread_cond_wait(&cvs[index], &mxs[index]); + } + conds[index] = 1; + (void) pthread_mutex_unlock(&mxs[index]); + + return (0); +} + +int +unblock(int index) +{ + (void) pthread_mutex_lock(&mxs[index]); + conds[index] = 0; + if (opto) { + (void) pthread_mutex_unlock(&mxs[index]); + (void) pthread_cond_signal(&cvs[index]); + } else { + (void) pthread_cond_signal(&cvs[index]); + (void) pthread_mutex_unlock(&mxs[index]); + } + return (0); +} + +/* + * API-specific code ENDS here + */ + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int e = 0; + + if (ts->ts_once == 0) { + int us, them; + + us = (getpindex() * lm_optT) + gettindex(); + them = (us + 1) % (lm_optP * lm_optT); + + ts->ts_id = us; + + /* lock index asignment for us and them */ + ts->ts_us0 = (us * 2); + ts->ts_us1 = (us * 2) + 1; + if (us < nthreads - 1) { + /* straight-thru connection to them */ + ts->ts_them0 = (them * 2); + ts->ts_them1 = (them * 2) + 1; + } else { + /* cross-over connection to them */ + ts->ts_them0 = (them * 2) + 1; + ts->ts_them1 = (them * 2); + } + + ts->ts_once = 1; + } + + /* block their first move */ + e += block(ts->ts_them0); + + return (e); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int e = 0; + + /* wait to be unblocked (id == 0 will not block) */ + e += block(ts->ts_us0); + + for (i = 0; i < lm_optB; i += 2) { + /* allow them to block us again */ + e += unblock(ts->ts_us0); + + /* block their next + 1 move */ + e += block(ts->ts_them1); + + /* unblock their next move */ + e += unblock(ts->ts_them0); + + /* wait for them to unblock us */ + e += block(ts->ts_us1); + + /* repeat with locks reversed */ + e += unblock(ts->ts_us1); + e += block(ts->ts_them0); + e += unblock(ts->ts_them1); + e += block(ts->ts_us0); + } + + /* finish batch with nothing blocked */ + e += unblock(ts->ts_them0); + e += unblock(ts->ts_us0); + + res->re_count = i; + res->re_errors = e; + + return (0); +} diff --git a/native/libMicro-0.4.0/cascade_fcntl.c b/native/libMicro-0.4.0/cascade_fcntl.c new file mode 100644 index 0000000..5b632c6 --- /dev/null +++ b/native/libMicro-0.4.0/cascade_fcntl.c @@ -0,0 +1,232 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * The "cascade" test case is a multiprocess/multithread batten-passing model + * using lock primitives alone for synchronisation. Threads are arranged in a + * ring. Each thread has two locks of its own on which it blocks, and is able + * to manipulate the two locks belonging to the thread which follows it in the + * ring. + * + * The number of threads (nthreads) is specified by the generic libMicro -P/-T + * options. With nthreads == 1 (the default) the uncontended case can be timed. + * + * The main logic is generic and allows any simple blocking API to be tested. + * The API-specific component is clearly indicated. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + int ts_id; + int ts_us0; /* our lock indices */ + int ts_us1; + int ts_them0; /* their lock indices */ + int ts_them1; +} tsd_t; + +static int nthreads; + +/* + * API-specific code BEGINS here + */ + +#define DEFD "/tmp" + +static char *optd = DEFD; +static int file; +static int nlocks; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "d:"); + + lm_defN = "cscd_fcntl"; + + (void) sprintf(lm_usage, + " [-d directory for temp file (default %s)]\n" + "notes: thread cascade using fcntl region locking\n", + DEFD); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'd': + optd = optarg; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + int errors = 0; + char fname[1024]; + + nthreads = lm_optP * lm_optT; + nlocks = nthreads * 2; + + (void) sprintf(fname, "%s/cascade.%ld", optd, getpid()); + + file = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600); + if (file == -1) { + errors++; + } + + if (unlink(fname)) { + errors++; + } + + if (ftruncate(file, nlocks * 3) == -1) { + errors++; + } + + return (errors); +} + +int +block(int index) +{ + struct flock fl; + + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fl.l_start = index; + fl.l_len = 1; + return (fcntl(file, F_SETLKW, &fl) == -1); +} + +int +unblock(int index) +{ + struct flock fl; + + fl.l_type = F_UNLCK; + fl.l_whence = SEEK_SET; + fl.l_start = index; + fl.l_len = 1; + return (fcntl(file, F_SETLK, &fl) == -1); +} + +/* + * API-specific code ENDS here + */ + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int e = 0; + + if (ts->ts_once == 0) { + int us, them; + + us = (getpindex() * lm_optT) + gettindex(); + them = (us + 1) % (lm_optP * lm_optT); + + ts->ts_id = us; + + /* lock index asignment for us and them */ + ts->ts_us0 = (us * 4); + ts->ts_us1 = (us * 4) + 2; + if (us < nthreads - 1) { + /* straight-thru connection to them */ + ts->ts_them0 = (them * 4); + ts->ts_them1 = (them * 4) + 2; + } else { + /* cross-over connection to them */ + ts->ts_them0 = (them * 4) + 2; + ts->ts_them1 = (them * 4); + } + + ts->ts_once = 1; + } + + /* block their first move */ + e += block(ts->ts_them0); + + return (e); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int e = 0; + + /* wait to be unblocked (id == 0 will not block) */ + e += block(ts->ts_us0); + + for (i = 0; i < lm_optB; i += 2) { + /* allow them to block us again */ + e += unblock(ts->ts_us0); + + /* block their next + 1 move */ + e += block(ts->ts_them1); + + /* unblock their next move */ + e += unblock(ts->ts_them0); + + /* wait for them to unblock us */ + e += block(ts->ts_us1); + + /* repeat with locks reversed */ + e += unblock(ts->ts_us1); + e += block(ts->ts_them0); + e += unblock(ts->ts_them1); + e += block(ts->ts_us0); + } + + /* finish batch with nothing blocked */ + e += unblock(ts->ts_them0); + e += unblock(ts->ts_us0); + + res->re_count = i; + res->re_errors = e; + + return (0); +} diff --git a/native/libMicro-0.4.0/cascade_flock.c b/native/libMicro-0.4.0/cascade_flock.c new file mode 100644 index 0000000..27d95d1 --- /dev/null +++ b/native/libMicro-0.4.0/cascade_flock.c @@ -0,0 +1,228 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * The "cascade" test case is a multiprocess/multithread batten-passing model + * using lock primitives alone for synchronisation. Threads are arranged in a + * ring. Each thread has two locks of its own on which it blocks, and is able + * to manipulate the two locks belonging to the thread which follows it in the + * ring. + * + * The number of threads (nthreads) is specified by the generic libMicro -P/-T + * options. With nthreads == 1 (the default) the uncontended case can be timed. + * + * The main logic is generic and allows any simple blocking API to be tested. + * The API-specific component is clearly indicated. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +#ifndef LOCK_EX +#include "/usr/ucbinclude/sys/file.h" +extern int flock(int fd, int operation); +#endif + +typedef struct { + int ts_once; + int ts_id; + int ts_us0; /* our lock indices */ + int ts_us1; + int ts_them0; /* their lock indices */ + int ts_them1; +} tsd_t; + +static int nthreads; + +/* + * API-specific code BEGINS here + */ + +#define DEFD "/tmp" + +static char *optd = DEFD; +static int nfiles; +static int *files; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "d:"); + + lm_defN = "cscd_flock"; + + (void) sprintf(lm_usage, + " [-d directory for temp files (default %s)]\n" + "notes: thread cascade using flock file locking\n", + DEFD); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'd': + optd = optarg; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + int i; + int errors = 0; + char fname[1024]; + + nthreads = lm_optP * lm_optT; + nfiles = nthreads * 2; + (void) setfdlimit(nfiles + 10); + files = (int *)malloc(nfiles * sizeof (int)); + if (files == NULL) { + return (1); + } + + (void) sprintf(fname, "%s/cascade.%ld", optd, getpid()); + + for (i = 0; i < nfiles; i++) { + files[i] = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600); + if (files[i] == -1) { + errors++; + } + if (unlink(fname)) { + errors++; + } + } + + return (errors); +} + +int +block(int index) +{ + return (flock(files[index], LOCK_EX) == -1); +} + +int +unblock(int index) +{ + return (flock(files[index], LOCK_UN) == -1); +} + +/* + * API-specific code ENDS here + */ + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int e = 0; + + if (ts->ts_once == 0) { + int us, them; + + us = (getpindex() * lm_optT) + gettindex(); + them = (us + 1) % (lm_optP * lm_optT); + + ts->ts_id = us; + + /* lock index asignment for us and them */ + ts->ts_us0 = (us * 2); + ts->ts_us1 = (us * 2) + 1; + if (us < nthreads - 1) { + /* straight-thru connection to them */ + ts->ts_them0 = (them * 2); + ts->ts_them1 = (them * 2) + 1; + } else { + /* cross-over connection to them */ + ts->ts_them0 = (them * 2) + 1; + ts->ts_them1 = (them * 2); + } + + ts->ts_once = 1; + } + + /* block their first move */ + e += block(ts->ts_them0); + + return (e); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int e = 0; + + /* wait to be unblocked (id == 0 will not block) */ + e += block(ts->ts_us0); + + for (i = 0; i < lm_optB; i += 2) { + /* allow them to block us again */ + e += unblock(ts->ts_us0); + + /* block their next + 1 move */ + e += block(ts->ts_them1); + + /* unblock their next move */ + e += unblock(ts->ts_them0); + + /* wait for them to unblock us */ + e += block(ts->ts_us1); + + /* repeat with locks reversed */ + e += unblock(ts->ts_us1); + e += block(ts->ts_them0); + e += unblock(ts->ts_them1); + e += block(ts->ts_us0); + } + + /* finish batch with nothing blocked */ + e += unblock(ts->ts_them0); + e += unblock(ts->ts_us0); + + res->re_count = i; + res->re_errors = e; + + return (0); +} diff --git a/native/libMicro-0.4.0/cascade_lockf.c b/native/libMicro-0.4.0/cascade_lockf.c new file mode 100644 index 0000000..2c95582 --- /dev/null +++ b/native/libMicro-0.4.0/cascade_lockf.c @@ -0,0 +1,223 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * The "cascade" test case is a multiprocess/multithread batten-passing model + * using lock primitives alone for synchronisation. Threads are arranged in a + * ring. Each thread has two locks of its own on which it blocks, and is able + * to manipulate the two locks belonging to the thread which follows it in the + * ring. + * + * The number of threads (nthreads) is specified by the generic libMicro -P/-T + * options. With nthreads == 1 (the default) the uncontended case can be timed. + * + * The main logic is generic and allows any simple blocking API to be tested. + * The API-specific component is clearly indicated. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + int ts_id; + int ts_us0; /* our lock indices */ + int ts_us1; + int ts_them0; /* their lock indices */ + int ts_them1; +} tsd_t; + +static int nthreads; + +/* + * API-specific code BEGINS here + */ + +#define DEFD "/tmp" + +static char *optd = DEFD; +static int nfiles; +static int *files; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "d:"); + + lm_defN = "cscd_lockf"; + + (void) sprintf(lm_usage, + " [-d directory for temp files (default %s)]\n" + "notes: thread cascade using lockf file locking\n", + DEFD); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'd': + optd = optarg; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + int i; + int errors = 0; + char fname[1024]; + + nthreads = lm_optP * lm_optT; + nfiles = nthreads * 2; + (void) setfdlimit(nfiles + 10); + files = (int *)malloc(nfiles * sizeof (int)); + if (files == NULL) { + return (1); + } + + (void) sprintf(fname, "%s/cascade.%ld", optd, getpid()); + + for (i = 0; i < nfiles; i++) { + files[i] = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600); + if (files[i] == -1) { + errors++; + } + if (unlink(fname)) { + errors++; + } + } + + return (errors); +} + +int +block(int index) +{ + return (lockf(files[index], F_LOCK, 0) == -1); +} + +int +unblock(int index) +{ + return (lockf(files[index], F_ULOCK, 0) == -1); +} + +/* + * API-specific code ENDS here + */ + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int e = 0; + + if (ts->ts_once == 0) { + int us, them; + + us = (getpindex() * lm_optT) + gettindex(); + them = (us + 1) % (lm_optP * lm_optT); + + ts->ts_id = us; + + /* lock index asignment for us and them */ + ts->ts_us0 = (us * 2); + ts->ts_us1 = (us * 2) + 1; + if (us < nthreads - 1) { + /* straight-thru connection to them */ + ts->ts_them0 = (them * 2); + ts->ts_them1 = (them * 2) + 1; + } else { + /* cross-over connection to them */ + ts->ts_them0 = (them * 2) + 1; + ts->ts_them1 = (them * 2); + } + + ts->ts_once = 1; + } + + /* block their first move */ + e += block(ts->ts_them0); + + return (e); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int e = 0; + + /* wait to be unblocked (id == 0 will not block) */ + e += block(ts->ts_us0); + + for (i = 0; i < lm_optB; i += 2) { + /* allow them to block us again */ + e += unblock(ts->ts_us0); + + /* block their next + 1 move */ + e += block(ts->ts_them1); + + /* unblock their next move */ + e += unblock(ts->ts_them0); + + /* wait for them to unblock us */ + e += block(ts->ts_us1); + + /* repeat with locks reversed */ + e += unblock(ts->ts_us1); + e += block(ts->ts_them0); + e += unblock(ts->ts_them1); + e += block(ts->ts_us0); + } + + /* finish batch with nothing blocked */ + e += unblock(ts->ts_them0); + e += unblock(ts->ts_us0); + + res->re_count = i; + res->re_errors = e; + + return (0); +} diff --git a/native/libMicro-0.4.0/cascade_mutex.c b/native/libMicro-0.4.0/cascade_mutex.c new file mode 100644 index 0000000..ecb38a1 --- /dev/null +++ b/native/libMicro-0.4.0/cascade_mutex.c @@ -0,0 +1,227 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * The "cascade" test case is a multiprocess/multithread batten-passing model + * using lock primitives alone for synchronisation. Threads are arranged in a + * ring. Each thread has two locks of its own on which it blocks, and is able + * to manipulate the two locks belonging to the thread which follows it in the + * ring. + * + * The number of threads (nthreads) is specified by the generic libMicro -P/-T + * options. With nthreads == 1 (the default) the uncontended case can be timed. + * + * The main logic is generic and allows any simple blocking API to be tested. + * The API-specific component is clearly indicated. + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + int ts_id; + int ts_us0; /* our lock indices */ + int ts_us1; + int ts_them0; /* their lock indices */ + int ts_them1; +} tsd_t; + +static int nthreads; + +/* + * API-specific code BEGINS here + */ + +static int opts = 0; +static int nlocks; +static pthread_mutex_t *locks; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s"); + + lm_defN = "cscd_mutex"; + + (void) sprintf(lm_usage, + " [-s] (force PTHREAD_PROCESS_SHARED)\n" + "notes: thread cascade using pthread_mutexes\n"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 's': + opts = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + int i; + int e = 0; + pthread_mutexattr_t ma; + + nthreads = lm_optP * lm_optT; + nlocks = nthreads * 2; + /*LINTED*/ + locks = (pthread_mutex_t *)mmap(NULL, + nlocks * sizeof (pthread_mutex_t), + PROT_READ | PROT_WRITE, + MAP_ANON | MAP_SHARED, + -1, 0L); + if (locks == MAP_FAILED) { + return (1); + } + + (void) pthread_mutexattr_init(&ma); + if (lm_optP > 1 || opts) { + (void) pthread_mutexattr_setpshared(&ma, + PTHREAD_PROCESS_SHARED); + } else { + (void) pthread_mutexattr_setpshared(&ma, + PTHREAD_PROCESS_PRIVATE); + } + + for (i = 0; i < nlocks; i++) { + (void) pthread_mutex_init(&locks[i], &ma); + } + + return (e); +} + +int +block(int index) +{ + return (pthread_mutex_lock(&locks[index]) == -1); +} + +int +unblock(int index) +{ + return (pthread_mutex_unlock(&locks[index]) == -1); +} + +/* + * API-specific code ENDS here + */ + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int e = 0; + + if (ts->ts_once == 0) { + int us, them; + + us = (getpindex() * lm_optT) + gettindex(); + them = (us + 1) % (lm_optP * lm_optT); + + ts->ts_id = us; + + /* lock index asignment for us and them */ + ts->ts_us0 = (us * 2); + ts->ts_us1 = (us * 2) + 1; + if (us < nthreads - 1) { + /* straight-thru connection to them */ + ts->ts_them0 = (them * 2); + ts->ts_them1 = (them * 2) + 1; + } else { + /* cross-over connection to them */ + ts->ts_them0 = (them * 2) + 1; + ts->ts_them1 = (them * 2); + } + + ts->ts_once = 1; + } + + /* block their first move */ + e += block(ts->ts_them0); + + return (e); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int e = 0; + + /* wait to be unblocked (id == 0 will not block) */ + e += block(ts->ts_us0); + + for (i = 0; i < lm_optB; i += 2) { + /* allow them to block us again */ + e += unblock(ts->ts_us0); + + /* block their next + 1 move */ + e += block(ts->ts_them1); + + /* unblock their next move */ + e += unblock(ts->ts_them0); + + /* wait for them to unblock us */ + e += block(ts->ts_us1); + + /* repeat with locks reversed */ + e += unblock(ts->ts_us1); + e += block(ts->ts_them0); + e += unblock(ts->ts_them1); + e += block(ts->ts_us0); + } + + /* finish batch with nothing blocked */ + e += unblock(ts->ts_them0); + e += unblock(ts->ts_us0); + + res->re_count = i; + res->re_errors = e; + + return (0); +} diff --git a/native/libMicro-0.4.0/chdir.c b/native/libMicro-0.4.0/chdir.c new file mode 100644 index 0000000..a9ff379 --- /dev/null +++ b/native/libMicro-0.4.0/chdir.c @@ -0,0 +1,132 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * change directory benchmark + */ + +#include +#include +#include + +#include "libmicro.h" + +#define DEFAULTDIR "/" +#define MAXPATHLEN 1024 + +static int optg = 0; + +static int dircount; +static char ** dirlist; + +int +benchmark_init() +{ + (void) sprintf(lm_optstr, "g"); + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + " [-g] (do getcwd() also)\n" + " directory ... (default = %s)\n" + "notes: measures chdir() and (optionally) getcwd()", + DEFAULTDIR); + + (void) sprintf(lm_header, "%5s %5s", "dirs", "gets"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'g': + optg = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + extern int optind; + int i; + + dircount = lm_argc - optind; + if (dircount <= 0) { + dirlist = (char **)malloc(sizeof (char *)); + dirlist[0] = DEFAULTDIR; + dircount = 1; + } else { + dirlist = (char **)malloc(dircount * sizeof (char *)); + for (i = 0; i < dircount; i++) { + dirlist[i] = lm_argv[optind++]; + } + } + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i, j; + char buf[MAXPATHLEN]; + + j = 0; + for (i = 0; i < lm_optB; i++) { + if (chdir(dirlist[j]) == -1) + res->re_errors++; + j++; + j %= dircount; + + if (optg && (getcwd(buf, MAXPATHLEN) == NULL)) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%5d %5s", dircount, optg ? "y" : "n"); + + return (result); +} diff --git a/native/libMicro-0.4.0/close.c b/native/libMicro-0.4.0/close.c new file mode 100644 index 0000000..6050bcd --- /dev/null +++ b/native/libMicro-0.4.0/close.c @@ -0,0 +1,141 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmark for close + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFF "/dev/null" +static char *optf = DEFF; +static int optb = 0; + +typedef struct { + int *ts_fds; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + lm_defB = 256; + + (void) sprintf(lm_optstr, "f:b"); + + (void) sprintf(lm_usage, + " [-f file-to-close (default %s)]\n" + " [-b] (try to close an unopened fd)\n" + "notes: measures close()", + DEFF); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + case 'b': + optb = 1; + break; + default: + return (-1); + } + + return (0); +} + +int +benchmark_initrun() +{ + (void) setfdlimit(lm_optB * lm_optT + 10); + + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_fds == NULL) { + return (1); + } + return (0); +} + +/* + * don't need a finiworker; we're exiting anyway + */ + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int errors = 0; + + for (i = 0; i < lm_optB; i++) { + ts->ts_fds[i] = ((optb == 0) ? + open(optf, O_RDONLY) : i + 1024); + if (ts->ts_fds[i] == -1) { + errors++; + } + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (close(ts->ts_fds[i]) == -1 && !optb) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/close_tcp.c b/native/libMicro-0.4.0/close_tcp.c new file mode 100644 index 0000000..6bce7a7 --- /dev/null +++ b/native/libMicro-0.4.0/close_tcp.c @@ -0,0 +1,241 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmark to measure time to close a local tcp connection + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define FIRSTPORT 12345 + +typedef struct { + int *ts_lsns; + int *ts_accs; + int *ts_cons; + struct sockaddr_in *ts_adds; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + lm_defB = 256; + + (void) sprintf(lm_usage, + "notes: measures close() on local TCP connections"); + + return (0); +} + +int +benchmark_initrun() +{ + (void) setfdlimit(3 * lm_optB * lm_optT + 10); + + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j; + int opt = 1; + struct hostent *host; + int errors = 0; + + ts->ts_lsns = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_lsns == NULL) { + errors ++; + } + ts->ts_accs = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_accs == NULL) { + errors ++; + } + ts->ts_cons = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_cons == NULL) { + errors ++; + } + ts->ts_adds = (struct sockaddr_in *)malloc(lm_optB * + sizeof (struct sockaddr_in)); + if (ts->ts_adds == NULL) { + errors ++; + } + + j = FIRSTPORT; + for (i = 0; i < lm_optB; i++) { + ts->ts_lsns[i] = socket(AF_INET, SOCK_STREAM, 0); + if (ts->ts_lsns[i] == -1) { + perror("socket"); + errors ++; + } + + if (setsockopt(ts->ts_lsns[i], SOL_SOCKET, SO_REUSEADDR, + &opt, sizeof (int)) == -1) { + perror("setsockopt"); + errors ++; + } + + if ((host = gethostbyname("localhost")) == NULL) { + errors ++; + } + + for (;;) { + (void) memset(&ts->ts_adds[i], 0, + sizeof (struct sockaddr_in)); + ts->ts_adds[i].sin_family = AF_INET; + ts->ts_adds[i].sin_port = htons(j++); + (void) memcpy(&ts->ts_adds[i].sin_addr.s_addr, + host->h_addr_list[0], sizeof (struct in_addr)); + + if (bind(ts->ts_lsns[i], + (struct sockaddr *)&ts->ts_adds[i], + sizeof (struct sockaddr_in)) == 0) { + break; + } + + if (errno != EADDRINUSE) { + perror("bind"); + errors ++; + } + } + + if (listen(ts->ts_lsns[i], 5) == -1) { + perror("listen"); + errors ++; + } + + } + return (errors); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int result; + struct sockaddr_in addr; + socklen_t size; + int errors = 0; + + for (i = 0; i < lm_optB; i++) { + ts->ts_cons[i] = socket(AF_INET, SOCK_STREAM, 0); + if (ts->ts_cons[i] == -1) { + perror("socket"); + errors ++; + continue; + } + + if (fcntl(ts->ts_cons[i], F_SETFL, O_NDELAY) == -1) { + perror("fcnt"); + errors ++; + continue; + } + + result = connect(ts->ts_cons[i], + (struct sockaddr *)&ts->ts_adds[i], + sizeof (struct sockaddr_in)); + + if ((result == -1) && (errno != EINPROGRESS)) { + perror("connect"); + errors ++; + continue; + } + + size = sizeof (struct sockaddr); + result = accept(ts->ts_lsns[i], (struct sockaddr *)&addr, + &size); + if (result == -1) { + perror("accept"); + errors ++; + continue; + } + ts->ts_accs[i] = result; + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (close(ts->ts_accs[i]) == -1) { + res->re_errors ++; + } + } + res->re_count = i; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + (void) close(ts->ts_cons[i]); + } + + return (0); +} + +int +benchmark_finiworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + (void) close(ts->ts_lsns[i]); + } + return (0); +} diff --git a/native/libMicro-0.4.0/connection.c b/native/libMicro-0.4.0/connection.c new file mode 100644 index 0000000..67239f9 --- /dev/null +++ b/native/libMicro-0.4.0/connection.c @@ -0,0 +1,305 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define FIRSTPORT 12345 + +typedef struct { + int ts_once; + int *ts_lsns; + int *ts_accs; + int *ts_cons; + struct sockaddr_in *ts_adds; +} tsd_t; + +static int opta = 0; +static int optc = 0; +static struct hostent *host; + +int +benchmark_init() +{ + lm_defB = 256; + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "ac"); + + (void) sprintf(lm_usage, + " [-a] (measure accept() only)\n" + " [-c] (measure connect() only)\n" + "notes: measures connect()/accept()\n"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'a': + opta = 1; + break; + case 'c': + optc = 1; + break; + default: + return (-1); + } + + if (opta && optc) { + (void) printf("warning: -a overrides -c\n"); + optc = 0; + } + + return (0); +} + +int +benchmark_initrun() +{ + (void) setfdlimit(3 * lm_optB * lm_optT + 10); + + return (0); +} + +int +benchmark_initbatch_once(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j; + + int errors = 0; + + ts->ts_lsns = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_lsns == NULL) { + errors ++; + } + ts->ts_accs = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_accs == NULL) { + errors ++; + } + ts->ts_cons = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_cons == NULL) { + errors ++; + } + ts->ts_adds = + (struct sockaddr_in *)malloc(lm_optB * + sizeof (struct sockaddr_in)); + if (ts->ts_accs == NULL) { + errors ++; + } + + j = FIRSTPORT; + for (i = 0; i < lm_optB; i++) { + ts->ts_lsns[i] = socket(AF_INET, SOCK_STREAM, 0); + if (ts->ts_lsns[i] == -1) { + perror("socket"); + errors ++; + } + + /* + * make accept socket non-blocking so in case of errors + * we don't hang + */ + + if (fcntl(ts->ts_lsns[i], F_SETFL, O_NDELAY) == -1) { + perror("fcntl"); + errors ++; + } + + + if ((host = gethostbyname("localhost")) == NULL) { + errors ++; + } + + for (;;) { + (void) memset(&ts->ts_adds[i], 0, + sizeof (struct sockaddr_in)); + ts->ts_adds[i].sin_family = AF_INET; + ts->ts_adds[i].sin_port = htons(j++); + (void) memcpy(&ts->ts_adds[i].sin_addr.s_addr, + host->h_addr_list[0], sizeof (struct in_addr)); + + if (bind(ts->ts_lsns[i], + (struct sockaddr *)&ts->ts_adds[i], + sizeof (struct sockaddr_in)) == 0) { + break; + } + + if (errno != EADDRINUSE) { + errors ++; + } + } + + if (listen(ts->ts_lsns[i], 5) == -1) { + perror("listen"); + errors ++; + } + } + return (errors); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int errors = 0; + int result; + + if (ts->ts_once++ == 0) { + if (errors += benchmark_initbatch_once(tsd) == -1) { + return (-1); + } + } + + + for (i = 0; i < lm_optB; i++) { + ts->ts_cons[i] = socket(AF_INET, SOCK_STREAM, 0); + if (ts->ts_cons[i] == -1) { + perror("init:socket"); + errors ++; + } + + if (fcntl(ts->ts_cons[i], F_SETFL, O_NDELAY) == -1) { + perror("init:fcntl"); + errors ++; + } + + if (opta) { + result = connect(ts->ts_cons[i], + (struct sockaddr *)&ts->ts_adds[i], + sizeof (struct sockaddr_in)); + if ((result == -1) && (errno != EINPROGRESS)) { + perror("init:connect"); + errors ++; + } + } + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) + + + +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int result; + struct sockaddr_in addr; + socklen_t size; + + for (i = 0; i < lm_optB; i++) { + if (!opta) { + again: + result = connect(ts->ts_cons[i], + (struct sockaddr *)&ts->ts_adds[i], + sizeof (struct sockaddr_in)); + if (result != 0 && errno != EISCONN) { + if (errno == EINPROGRESS) { + struct pollfd pollfd; + if (optc) + continue; + pollfd.fd = ts->ts_cons[i]; + pollfd.events = POLLOUT; + if (poll(&pollfd, 1, -1) == 1) + goto again; + } + + res->re_errors ++; + perror("benchmark:connect"); + continue; + } + } + + if (!optc) { + size = sizeof (struct sockaddr); + for (;;) { + struct pollfd pollfd; + result = accept(ts->ts_lsns[i], + (struct sockaddr *)&addr, &size); + if (result > 0 || (result == -1 && + errno != EAGAIN)) + break; + pollfd.fd = ts->ts_lsns[i]; + pollfd.events = POLLIN; + if (poll(&pollfd, 1, -1) != 1) + break; + } + + ts->ts_accs[i] = result; + if (result == -1) { + res->re_errors ++; + perror("benchmark:accept"); + continue; + } + } + } + res->re_count = i; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + + if (!optc) { + (void) close(ts->ts_accs[i]); + } + (void) close(ts->ts_cons[i]); + } + + return (0); +} diff --git a/native/libMicro-0.4.0/dup.c b/native/libMicro-0.4.0/dup.c new file mode 100644 index 0000000..cdce1f1 --- /dev/null +++ b/native/libMicro-0.4.0/dup.c @@ -0,0 +1,139 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * time dup + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFF "/dev/null" +static char *optf = DEFF; + +static int fd; + +typedef struct { + int ts_once; + int *ts_fds; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + lm_defB = 256; + + (void) sprintf(lm_optstr, "f:"); + + (void) sprintf(lm_usage, + " [-f file-to-dup (default %s)]\n" + "notes: measures dup()\n", + DEFF); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + (void) setfdlimit(lm_optB * lm_optT + 10); + fd = (open(optf, O_RDONLY)); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int errors = 0; + + if (ts->ts_once++ == 0) { + ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_fds == NULL) { + errors ++; + } + for (i = 0; i < lm_optB; i++) { + ts->ts_fds[i] = -1; + } + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + ts->ts_fds[i] = dup(fd); + if (ts->ts_fds[i] == -1) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + (void) close(ts->ts_fds[i]); + } + + return (0); +} diff --git a/native/libMicro-0.4.0/elided.c b/native/libMicro-0.4.0/elided.c new file mode 100644 index 0000000..ab26e6e --- /dev/null +++ b/native/libMicro-0.4.0/elided.c @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * empty benchmark program to substitute for benchmarks + * that don't work/exist on some platforms + */ + +#include +#include +#include +#include + +/*ARGSUSED*/ +int +main(int argc, char *argv[]) +{ + char *tmp = strrchr(argv[0], '/'); + + if (tmp == NULL) + tmp = argv[0]; + else + tmp++; + + (void) printf( + "#\n" + "# benchmark %s not compiled/supported on this platform\n" + "#\n", + tmp); + + return (0); +} diff --git a/native/libMicro-0.4.0/exec.c b/native/libMicro-0.4.0/exec.c new file mode 100644 index 0000000..3110a14 --- /dev/null +++ b/native/libMicro-0.4.0/exec.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * exec benchmark + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +static char exec_path[1024]; +static char *argv[3]; + +int +benchmark_init() +{ + lm_defB = 128; + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + "notes: measures execv time of simple process()\n"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark_initbatch(void *tsd) +{ + char buffer[80]; + + (void) strcpy(exec_path, lm_procpath); + (void) strcat(exec_path, "/exec_bin"); + + (void) sprintf(buffer, "%d", lm_optB); + argv[0] = exec_path; + argv[1] = strdup(buffer); + argv[2] = NULL; + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int c; + int status; + + switch (c = fork()) { + case -1: + res->re_errors++; + break; + default: + if (waitpid(c, &status, 0) < 0) + res->re_errors++; + + if (WIFEXITED(status) && WEXITSTATUS(status) != 0) + res->re_errors++; + break; + case 0: + if (execv(exec_path, argv) < 0) + res->re_errors++; + } + + res->re_count = lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/exec_bin.c b/native/libMicro-0.4.0/exec_bin.c new file mode 100644 index 0000000..4cddfd3 --- /dev/null +++ b/native/libMicro-0.4.0/exec_bin.c @@ -0,0 +1,65 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * time program to recursively test exec time + */ + +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + int left; + + if (argc == 1) { + exit(1); + } + + left = atoi(argv[1]); + + left--; + + if (left <= 0) { + exit(0); + } else { + char buffer[80]; + (void) sprintf(buffer, "%d", left); + argv[1] = buffer; + if (execv(argv[0], argv)) { + exit(2); + } + } + + return (0); +} diff --git a/native/libMicro-0.4.0/exit.c b/native/libMicro-0.4.0/exit.c new file mode 100644 index 0000000..e2aa54d --- /dev/null +++ b/native/libMicro-0.4.0/exit.c @@ -0,0 +1,160 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmark exit + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + int *ts_pids; +} tsd_t; + +static int opte = 0; +static barrier_t *b; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + (void) sprintf(lm_optstr, "e"); + + (void) sprintf(lm_usage, + " [-e] (uses _exit() rather than exit())" + "notes: measures exit()\n"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'e': + opte = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + b = barrier_create(lm_optP * lm_optT * (lm_optB + 1), 0); + + return (0); +} + +int +benchmark_finirun() +{ + (void) barrier_destroy(b); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int errors = 0; + + if (ts->ts_once++ == 0) { + ts->ts_pids = (int *)malloc(lm_optB * sizeof (pid_t)); + if (ts->ts_pids == NULL) { + errors ++; + } + } + + /* + * create processes to exit + */ + + for (i = 0; i < lm_optB; i++) { + ts->ts_pids[i] = fork(); + switch (ts->ts_pids[i]) { + case 0: + (void) barrier_queue(b, NULL); + if (opte) + _exit(0); + exit(0); + break; + case -1: + errors ++; + break; + default: + continue; + } + } + + return (errors); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + /* + * start them all exiting + */ + + (void) barrier_queue(b, NULL); + + /* + * wait for them all to exit + */ + + for (i = 0; i < lm_optB; i++) { + switch (waitpid((pid_t)-1, NULL, 0)) { + case 0: + continue; + case -1: + res->re_errors++; + } + } + + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/exp.c b/native/libMicro-0.4.0/exp.c new file mode 100644 index 0000000..acc81c5 --- /dev/null +++ b/native/libMicro-0.4.0/exp.c @@ -0,0 +1,73 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * test exp performance (should add range check) + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "note: measures exp()"); + lm_nsecs_per_op = 25; + lm_tsdsize = 0; + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i += 10) { + double value = 1.0 / (i + .01); + (void) exp(value); + (void) exp(value); + (void) exp(value); + (void) exp(value); + (void) exp(value); + (void) exp(value); + (void) exp(value); + (void) exp(value); + (void) exp(value); + (void) exp(value); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/fcntl.c b/native/libMicro-0.4.0/fcntl.c new file mode 100644 index 0000000..95099c1 --- /dev/null +++ b/native/libMicro-0.4.0/fcntl.c @@ -0,0 +1,99 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmark fcntl getfl + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFF "/dev/null" + +static char *optf = DEFF; +static int fd = -1; + +int +benchmark_init() +{ + (void) sprintf(lm_optstr, "f:"); + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + " [-f file-to-fcntl (default %s)]\n" + "notes: measures fcntl()\n", + DEFF); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + if ((fd = open(optf, O_RDONLY)) == -1) { + perror("open"); + exit(1); + } + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + int flags; + + for (i = 0; i < lm_optB; i++) { + if (fcntl(fd, F_GETFL, &flags) == -1) + res->re_errors++; + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/fcntl_ndelay.c b/native/libMicro-0.4.0/fcntl_ndelay.c new file mode 100644 index 0000000..3f55a18 --- /dev/null +++ b/native/libMicro-0.4.0/fcntl_ndelay.c @@ -0,0 +1,100 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * measures O_NDELAY on socket + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +static int fd = -1; + +int +benchmark_init() +{ + (void) sprintf(lm_usage, + "notes: measures F_GETFL/F_SETFL O_NDELAY on socket\n"); + + lm_tsdsize = 0; + + return (0); +} + +int +benchmark_initrun() +{ + fd = socket(AF_INET, SOCK_STREAM, 0); + if (fd == -1) { + perror("socket"); + exit(1); + } + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + int flags; + + for (i = 0; i < lm_optB; i += 4) { + if (fcntl(fd, F_GETFL, &flags) < 0) + res->re_errors++; + flags |= O_NDELAY; + + if (fcntl(fd, F_SETFL, &flags) < 0) + res->re_errors++; + + if (fcntl(fd, F_GETFL, &flags) < 0) + res->re_errors++; + flags &= ~O_NDELAY; + + if (fcntl(fd, F_SETFL, &flags) < 0) + res->re_errors++; + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/file_lock.c b/native/libMicro-0.4.0/file_lock.c new file mode 100644 index 0000000..33d8860 --- /dev/null +++ b/native/libMicro-0.4.0/file_lock.c @@ -0,0 +1,106 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * test file locking + */ + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +static int file; + +int +block(int index) +{ + struct flock fl; + + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fl.l_start = index; + fl.l_len = 1; + return (fcntl(file, F_SETLKW, &fl) == -1); +} + +int +unblock(int index) +{ + struct flock fl; + + fl.l_type = F_UNLCK; + fl.l_whence = SEEK_SET; + fl.l_start = index; + fl.l_len = 1; + return (fcntl(file, F_SETLK, &fl) == -1); +} +int +benchmark_init() +{ + char fname[80]; + int errors = 0; + + (void) sprintf(fname, "/tmp/oneflock.%ld", getpid()); + + file = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600); + + if (file == -1) { + errors++; + } + if (unlink(fname)) { + errors++; + } + + lm_tsdsize = 0; + + return (errors); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + int e = 0; + + for (i = 0; i < lm_optB; i ++) { + e += block(0); + e += unblock(0); + } + res->re_count = i; + res->re_errors = e; + + return (0); +} diff --git a/native/libMicro-0.4.0/fork.c b/native/libMicro-0.4.0/fork.c new file mode 100644 index 0000000..d033691 --- /dev/null +++ b/native/libMicro-0.4.0/fork.c @@ -0,0 +1,131 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmark fork + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +static barrier_t *b; + +typedef struct { + int ts_once; + int *ts_pids; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + (void) sprintf(lm_usage, "notes: measures fork()\n"); + + return (0); +} + +int +benchmark_initrun() +{ + b = barrier_create(lm_optP * lm_optT * (lm_optB + 1), 0); + + return (0); +} + +int +benchmark_finirun() +{ + (void) barrier_destroy(b); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int errors = 0; + + if (ts->ts_once++ == 0) { + ts->ts_pids = (int *)malloc(lm_optB * sizeof (pid_t)); + if (ts->ts_pids == NULL) { + errors++; + } + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + ts->ts_pids[i] = fork(); + switch (ts->ts_pids[i]) { + case 0: + (void) barrier_queue(b, NULL); + exit(0); + break; + case -1: + res->re_errors++; + break; + default: + continue; + } + } + res->re_count = lm_optB; + + (void) barrier_queue(b, NULL); + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (ts->ts_pids[i] > 0) { + (void) waitpid(ts->ts_pids[i], NULL, 0); + } + } + + return (0); +} diff --git a/native/libMicro-0.4.0/getcontext.c b/native/libMicro-0.4.0/getcontext.c new file mode 100644 index 0000000..524a016 --- /dev/null +++ b/native/libMicro-0.4.0/getcontext.c @@ -0,0 +1,74 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * getcontext + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "notes: measures getcontext()\n"); + + lm_tsdsize = 0; + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i += 10) { + ucontext_t uc; + (void) getcontext(&uc); + (void) getcontext(&uc); + (void) getcontext(&uc); + (void) getcontext(&uc); + (void) getcontext(&uc); + (void) getcontext(&uc); + (void) getcontext(&uc); + (void) getcontext(&uc); + (void) getcontext(&uc); + (void) getcontext(&uc); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/getenv.c b/native/libMicro-0.4.0/getenv.c new file mode 100644 index 0000000..f75bfd4 --- /dev/null +++ b/native/libMicro-0.4.0/getenv.c @@ -0,0 +1,126 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * test getenv + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFS 100 + +static int opts = DEFS; + +int +benchmark_init() +{ + (void) sprintf(lm_optstr, "s:"); + + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + " [-s search-size (default = %d)]\n" + "notes: measures time to search env for missing string\n", + DEFS); + + lm_nsecs_per_op = 200; + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 's': + opts = atoi(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + extern char ** environ; + int i, j; + + /* count environment strings */ + + for (i = 0; environ[i++]; ) + ; + + /* + * pad to desired count + */ + + if (opts < i) + opts = i; + + for (j = i; j < opts; j++) { + char buf[80]; + (void) sprintf(buf, "VAR_%d=%d", j, j); + (void) putenv(strdup(buf)); + } + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + char *search = "RUMPLSTILTSKIN"; + + for (i = 0; i < lm_optB; i += 10) { + (void) getenv(search); + (void) getenv(search); + (void) getenv(search); + (void) getenv(search); + (void) getenv(search); + (void) getenv(search); + (void) getenv(search); + (void) getenv(search); + (void) getenv(search); + (void) getenv(search); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/getpeername.c b/native/libMicro-0.4.0/getpeername.c new file mode 100644 index 0000000..877215d --- /dev/null +++ b/native/libMicro-0.4.0/getpeername.c @@ -0,0 +1,163 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * getpeername test + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define FIRSTPORT 12345 + +static int sock = -1; + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "notes: measures getpeername()\n"); + lm_tsdsize = 0; + + return (0); +} + +int +benchmark_initrun() +{ + int j; + int opt = 1; + int result; + socklen_t size; + struct hostent *host; + struct sockaddr_in adds; + int sock2, sock3; + + sock2 = socket(AF_INET, SOCK_STREAM, 0); + if (sock2 == -1) { + perror("socket"); + exit(1); + } + + if (setsockopt(sock2, SOL_SOCKET, SO_REUSEADDR, + &opt, sizeof (int)) == -1) { + perror("setsockopt"); + exit(1); + } + + if ((host = gethostbyname("localhost")) == NULL) { + perror("gethostbyname"); + exit(1); + } + + j = FIRSTPORT; + for (;;) { + (void) memset(&adds, 0, sizeof (struct sockaddr_in)); + adds.sin_family = AF_INET; + adds.sin_port = htons(j++); + (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0], + sizeof (struct in_addr)); + + if (bind(sock2, (struct sockaddr *)&adds, + sizeof (struct sockaddr_in)) == 0) { + break; + } + + if (errno != EADDRINUSE) { + perror("bind"); + exit(1); + } + } + + if (listen(sock2, 5) == -1) { + perror("listen"); + exit(1); + } + + sock3 = socket(AF_INET, SOCK_STREAM, 0); + if (sock3 == -1) { + perror("socket"); + exit(1); + } + + if (fcntl(sock3, F_SETFL, O_NDELAY) == -1) { + perror("fcntl"); + exit(1); + } + + result = connect(sock3, (struct sockaddr *)&adds, + sizeof (struct sockaddr_in)); + if ((result == -1) && (errno != EINPROGRESS)) { + perror("connect"); + exit(1); + } + + size = sizeof (struct sockaddr); + sock = accept(sock2, (struct sockaddr *)&adds, &size); + if (sock == -1) { + perror("accept"); + exit(1); + } + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + struct sockaddr_in adds; + socklen_t size; + + for (i = 0; i < lm_optB; i++) { + size = sizeof (struct sockaddr_in); + if (getpeername(sock, (struct sockaddr *)&adds, &size) == -1) { + perror("getpeername"); + exit(1); + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/getpid.c b/native/libMicro-0.4.0/getpid.c new file mode 100644 index 0000000..4ac8165 --- /dev/null +++ b/native/libMicro-0.4.0/getpid.c @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * getpid + */ + + +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "note: measures getpid()"); + + lm_tsdsize = 0; + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i ++) { + (void) getpid(); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/getrusage.c b/native/libMicro-0.4.0/getrusage.c new file mode 100644 index 0000000..2f02213 --- /dev/null +++ b/native/libMicro-0.4.0/getrusage.c @@ -0,0 +1,73 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * getrusage + */ + + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "notes: measures getrusage(RUSAGE_SELF)\n"); + lm_tsdsize = 0; + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + struct rusage u; + + for (i = 0; i < lm_optB; i += 10) { + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + (void) getrusage(RUSAGE_SELF, &u); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/getsockname.c b/native/libMicro-0.4.0/getsockname.c new file mode 100644 index 0000000..e3f7769 --- /dev/null +++ b/native/libMicro-0.4.0/getsockname.c @@ -0,0 +1,125 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * getsockname + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define FIRSTPORT 12345 + +static struct sockaddr_in adds; +static int sock = -1; + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "notes: measures getsockname()()\n"); + lm_tsdsize = 0; + return (0); +} + +int +benchmark_initrun() +{ + int j; + int opt = 1; + struct hostent *host; + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock == -1) { + perror("socket"); + exit(1); + } + + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + &opt, sizeof (int)) == -1) { + perror("setsockopt"); + exit(1); + } + + if ((host = gethostbyname("localhost")) == NULL) { + perror("gethostbyname"); + exit(1); + } + + j = FIRSTPORT; + for (;;) { + (void) memset(&adds, 0, sizeof (struct sockaddr_in)); + adds.sin_family = AF_INET; + adds.sin_port = htons(j++); + (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0], + sizeof (struct in_addr)); + + if (bind(sock, (struct sockaddr *)&adds, + sizeof (struct sockaddr_in)) == 0) { + break; + } + + if (errno != EADDRINUSE) { + perror("bind"); + exit(1); + } + } + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + struct sockaddr_in adds; + socklen_t size; + + for (i = 0; i < lm_optB; i++) { + size = sizeof (struct sockaddr_in); + if (getsockname(sock, (struct sockaddr *)&adds, &size) == -1) + res->re_errors++; + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/gettimeofday.c b/native/libMicro-0.4.0/gettimeofday.c new file mode 100644 index 0000000..a17bf75 --- /dev/null +++ b/native/libMicro-0.4.0/gettimeofday.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * gettimeofday test + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "note: measures gettimeofday()"); + lm_tsdsize = 0; + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + struct timeval t; + + for (i = 0; i < lm_optB; i += 10) { + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + (void) gettimeofday(&t, NULL); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/isatty.c b/native/libMicro-0.4.0/isatty.c new file mode 100644 index 0000000..68aaf85 --- /dev/null +++ b/native/libMicro-0.4.0/isatty.c @@ -0,0 +1,110 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * isatty test + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFF "/dev/tty" +static char *optf = DEFF; +static int optb = 0; + +typedef struct { + int ts_fd; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "f:b"); + + (void) sprintf(lm_usage, + " [-f file-to-isatty (default %s)]\n" + " [-b] (try to isatty an unopened fd)\n" + "notes: measures isatty()", + DEFF); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + case 'b': + optb = 1; + break; + default: + return (-1); + } + + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + ts->ts_fd = ((optb == 0) ? + open(optf, O_RDONLY) : 1024); + if (ts->ts_fd == -1) { + return (1); + } + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (isatty(ts->ts_fd) == -1) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/libmicro.c b/native/libMicro-0.4.0/libmicro.c new file mode 100644 index 0000000..b4e11c2 --- /dev/null +++ b/native/libMicro-0.4.0/libmicro.c @@ -0,0 +1,1612 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmarking routines + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __sun +#include +#endif + +#include "libmicro.h" + +#include +#include +#include +#include + + +/* + * user visible globals + */ + +int lm_argc = 0; +char ** lm_argv = NULL; + +int lm_opt1; +int lm_optA; +int lm_optB; +int lm_optC = 100; +int lm_optD; +int lm_optE; +int lm_optH; +int lm_optI; +int lm_optL = 0; +int lm_optM = 0; +char *lm_optN; +int lm_optP; +int lm_optS; +int lm_optT; +int lm_optW; + +int lm_def1 = 0; +int lm_defB = 0; /* use lm_nsecs_per_op */ +int lm_defD = 10; +int lm_defH = 0; +char *lm_defN = NULL; +int lm_defP = 1; + +int lm_defS = 0; +int lm_defT = 1; + +/* + * default on fast platform, should be overridden by individual + * benchmarks if significantly wrong in either direction. + */ + +int lm_nsecs_per_op = 5; + +char *lm_procpath; +char lm_procname[STRSIZE]; +char lm_usage[STRSIZE]; +char lm_optstr[STRSIZE]; +char lm_header[STRSIZE]; +size_t lm_tsdsize = 0; + + +/* + * Globals we do not export to the user + */ + +static barrier_t *lm_barrier; +static pid_t *pids = NULL; +static pthread_t *tids = NULL; +static int pindex = -1; +static void *tsdseg = NULL; +static size_t tsdsize = 0; + +#ifdef USE_RDTSC +static long long lm_hz = 0; +#endif + + +/* + * Forward references + */ + +static void worker_process(); +static void usage(); +static void print_stats(barrier_t *); +static void print_histo(barrier_t *); +static int remove_outliers(double *, int, stats_t *); +static long long nsecs_overhead; +static long long nsecs_resolution; +static long long get_nsecs_overhead(); +static int crunch_stats(double *, int, stats_t *); +static void compute_stats(barrier_t *); + +#define SERVERHOST "localhost" +uint16_t PORT = -1; +int SOCK = -1; +int socket_on = 0; + +void init_sockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port) +{ + struct hostent *hostinfo; + + name->sin_family = AF_INET; + name->sin_port = htons (port); + hostinfo = gethostbyname (hostname); + if (hostinfo == NULL) { + fprintf (stderr, "Unknown host %s.\n", hostname); + fflush(stderr); + exit (EXIT_FAILURE); + } + name->sin_addr = *(struct in_addr *) hostinfo->h_addr; +} + +int make_socket() +{ + int sock = socket (PF_INET, SOCK_STREAM, 0); + if (sock < 0) { + fprintf(stderr, "cannot create socket.\n"); + fflush(stderr); + exit(EXIT_FAILURE); + } + + /* Disable Nagle buffering algo */ + int flag = 1; + setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)); + + struct sockaddr_in servername; + /* Connect to the server. */ + init_sockaddr (&servername, SERVERHOST, PORT); + if ( 0 > connect(sock, (struct sockaddr *) &servername, sizeof (servername)) ) { + fprintf (stderr, "cannot connect to server."); + fflush(stderr); + exit (EXIT_FAILURE); + } + + return sock; +} + +/* + * main routine; renamed in this file to allow linking with other + * files + */ + +int +actual_main(int argc, char *argv[]) +{ + int i; + int opt; + extern char *optarg; + char *tmp; + char optstr[256]; + barrier_t *b; + long long startnsecs = getnsecs(); + +#ifdef USE_RDTSC + if (getenv("LIBMICRO_HZ") == NULL) { + (void) printf("LIBMICRO_HZ needed but not set\n"); + exit(1); + } + lm_hz = strtoll(getenv("LIBMICRO_HZ"), NULL, 10); +#endif + char *port = getenv("ZXBENCH_PORT"); + if (port != NULL){ + PORT = atoi(port); + socket_on = 1; + } + + lm_argc = argc; + lm_argv = argv; + + /* before we do anything */ + (void) benchmark_init(); + + + nsecs_overhead = get_nsecs_overhead(); + nsecs_resolution = get_nsecs_resolution(); + + /* + * Set defaults + */ + + lm_opt1 = lm_def1; + lm_optB = lm_defB; + lm_optD = lm_defD; + lm_optH = lm_defH; + lm_optN = lm_defN; + lm_optP = lm_defP; + + lm_optS = lm_defS; + lm_optT = lm_defT; + + /* + * squirrel away the path to the current + * binary in a way that works on both + * Linux and Solaris + */ + + if (*argv[0] == '/') { + lm_procpath = strdup(argv[0]); + *strrchr(lm_procpath, '/') = 0; + } else { + char path[1024]; + (void) getcwd(path, 1024); + (void) strcat(path, "/"); + (void) strcat(path, argv[0]); + *strrchr(path, '/') = 0; + lm_procpath = strdup(path); + } + + /* + * name of binary + */ + + if ((tmp = strrchr(argv[0], '/')) == NULL) + (void) strcpy(lm_procname, argv[0]); + else + (void) strcpy(lm_procname, tmp + 1); + + if (lm_optN == NULL) { + lm_optN = lm_procname; + } + + /* + * Parse command line arguments + */ + + (void) sprintf(optstr, "1AB:C:D:EHI:LMN:P:RST:VW?%s", lm_optstr); + while ((opt = getopt(argc, argv, optstr)) != -1) { + switch (opt) { + case '1': + lm_opt1 = 1; + break; + case 'A': + lm_optA = 1; + break; + case 'B': + lm_optB = sizetoint(optarg); + break; + case 'C': + lm_optC = sizetoint(optarg); + break; + case 'D': + lm_optD = sizetoint(optarg); + break; + case 'E': + lm_optE = 1; + break; + case 'H': + lm_optH = 1; + break; + case 'I': + lm_optI = sizetoint(optarg); + break; + case 'L': + lm_optL = 1; + break; + case 'M': + lm_optM = 1; + break; + case 'N': + lm_optN = optarg; + break; + case 'P': + lm_optP = sizetoint(optarg); + break; + case 'S': + lm_optS = 1; + break; + case 'T': + lm_optT = sizetoint(optarg); + break; + case 'V': + (void) printf("%s\n", LIBMICRO_VERSION); + exit(0); + break; + case 'W': + lm_optW = 1; + lm_optS = 1; + break; + case '?': + usage(); + exit(0); + break; + default: + if (benchmark_optswitch(opt, optarg) == -1) { + usage(); + exit(0); + } + } + } + + /* deal with implicit and overriding options */ + if (lm_opt1 && lm_optP > 1) { + lm_optP = 1; + (void) printf("warning: -1 overrides -P\n"); + } + + if (lm_optE) { + (void) fprintf(stderr, "Running:%20s", lm_optN); + (void) fflush(stderr); + } + + if (lm_optB == 0) { + /* + * neither benchmark or user has specified the number + * of cnts/sample, so use computed value + */ + if (lm_optI) + lm_nsecs_per_op = lm_optI; + + lm_optB = nsecs_resolution * 100 / lm_nsecs_per_op; + if (lm_optB == 0) + lm_optB = 1; + } + + /* + * now that the options are set + */ + + if (benchmark_initrun() == -1) { + exit(1); + } + + /* allocate dynamic data */ + pids = (pid_t *)malloc(lm_optP * sizeof (pid_t)); + if (pids == NULL) { + perror("malloc(pids)"); + exit(1); + } + tids = (pthread_t *)malloc(lm_optT * sizeof (pthread_t)); + if (tids == NULL) { + perror("malloc(tids)"); + exit(1); + } + + /* check that the case defines lm_tsdsize before proceeding */ + if (lm_tsdsize == (size_t)-1) { + (void) fprintf(stderr, "error in benchmark_init: " + "lm_tsdsize not set\n"); + exit(1); + } + + /* round up tsdsize to nearest 128 to eliminate false sharing */ + tsdsize = ((lm_tsdsize + 127) / 128) * 128; + + /* allocate sufficient TSD for each thread in each process */ + tsdseg = (void *)mmap(NULL, lm_optT * lm_optP * tsdsize + 8192, + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0L); + if (tsdseg == NULL) { + perror("mmap(tsd)"); + exit(1); + } + + /* initialise worker synchronisation */ + b = barrier_create(lm_optT * lm_optP, DATASIZE); + if (b == NULL) { + perror("barrier_create()"); + exit(1); + } + lm_barrier = b; + b->ba_flag = 1; + + /* need this here so that parent and children can call exit() */ + (void) fflush(stdout); + (void) fflush(stderr); + + // open socket here + if(socket_on ==1) + SOCK = make_socket(); + + /* when we started and when to stop */ + + b->ba_starttime = getnsecs(); + b->ba_deadline = (long long) (b->ba_starttime + (lm_optD * 1000000LL)); + + /* do the work */ + if (lm_opt1) { + /* single process, non-fork mode */ + pindex = 0; + worker_process(); + } else { + /* create worker processes */ + for (i = 0; i < lm_optP; i++) { + pids[i] = fork(); + + switch (pids[i]) { + case 0: + pindex = i; + worker_process(); + if(socket_on ==1) + close(SOCK); + exit(0); + break; + case -1: + perror("fork"); + if(socket_on ==1) + close(SOCK); + exit(1); + break; + default: + continue; + } + } + + /* wait for worker processes */ + for (i = 0; i < lm_optP; i++) { + if (pids[i] > 0) { + (void) waitpid(pids[i], NULL, 0); + } + } + } + + b->ba_endtime = getnsecs(); + + /* compute results */ + + compute_stats(b); + + /* print arguments benchmark was invoked with ? */ + if (lm_optL) { + int l; + (void) printf("# %s ", argv[0]); + for (l = 1; l < argc; l++) { + (void) printf("%s ", argv[l]); + } + (void) printf("\n"); + } + + /* print result header (unless suppressed) */ + if (!lm_optH) { + (void) printf("%12s %3s %3s %12s %12s %8s %8s %s\n", + "", "prc", "thr", + "usecs/call", + "samples", "errors", "cnt/samp", lm_header); + } + + /* print result */ + + (void) printf("%-12s %3d %3d %12.5f %12d %8lld %8d %s\n", + lm_optN, lm_optP, lm_optT, + (lm_optM?b->ba_corrected.st_mean:b->ba_corrected.st_median), + b->ba_batches, b->ba_errors, lm_optB, + benchmark_result()); + + if (lm_optS) { + print_stats(b); + } + + /* just incase something goes awry */ + (void) fflush(stdout); + (void) fflush(stderr); + + /* cleanup by stages */ + (void) benchmark_finirun(); + (void) barrier_destroy(b); + (void) benchmark_fini(); + + if (lm_optE) { + (void) fprintf(stderr, " for %12.5f seconds\n", + (double)(getnsecs() - startnsecs) / + 1.e9); + (void) fflush(stderr); + } + if(socket_on ==1) + close(SOCK); + return (0); +} + +void * +worker_thread(void *arg) +{ + result_t r; + long long last_sleep = 0; + long long t; + + r.re_errors = benchmark_initworker(arg); + + while (lm_barrier->ba_flag) { + r.re_count = 0; + r.re_errors += benchmark_initbatch(arg); + + /* sync to clock */ + + if (lm_optA && ((t = getnsecs()) - last_sleep) > 75000000LL) { + (void) poll(0, 0, 10); + last_sleep = t; + } + /* wait for it ... */ + (void) barrier_queue(lm_barrier, NULL); + + /* time the test */ + r.re_t0 = getnsecs(); + (void) benchmark(arg, &r); + r.re_t1 = getnsecs(); + + /* time to stop? */ + if (r.re_t1 > lm_barrier->ba_deadline && + (!lm_optC || lm_optC < lm_barrier->ba_batches)) { + lm_barrier->ba_flag = 0; + } + + /* record results and sync */ + (void) barrier_queue(lm_barrier, &r); + + (void) benchmark_finibatch(arg); + + r.re_errors = 0; + } + + (void) benchmark_finiworker(arg); + + return (0); +} + +void +worker_process() +{ + int i; + void *tsd; + + for (i = 1; i < lm_optT; i++) { + tsd = gettsd(pindex, i); + if (pthread_create(&tids[i], NULL, worker_thread, tsd) != 0) { + perror("pthread_create"); + exit(1); + } + } + + tsd = gettsd(pindex, 0); + (void) worker_thread(tsd); + + for (i = 1; i < lm_optT; i++) { + (void) pthread_join(tids[i], NULL); + } +} + +void +usage() +{ + (void) printf( + "usage: %s\n" + " [-1] (single process; overrides -P > 1)\n" + " [-A] (align with clock)\n" + " [-B batch-size (default %d)]\n" + " [-C minimum number of samples (default 0)]\n" + " [-D duration in msecs (default %ds)]\n" + " [-E (echo name to stderr)]\n" + " [-H] (suppress headers)\n" + " [-I] nsecs per op (used to compute batch size)" + " [-L] (print argument line)\n" + " [-M] (reports mean rather than median)\n" + " [-N test-name (default '%s')]\n" + " [-P processes (default %d)]\n" + " [-S] (print detailed stats)\n" + " [-T threads (default %d)]\n" + " [-V] (print the libMicro version and exit)\n" + " [-W] (flag possible benchmark problems)\n" + "%s\n", + lm_procname, + lm_defB, lm_defD, lm_procname, lm_defP, lm_defT, + lm_usage); +} + +void +print_warnings(barrier_t *b) +{ + int head = 0; + int increase; + + if (b->ba_quant) { + if (!head++) { + (void) printf("#\n# WARNINGS\n"); + } + increase = (int)(floor((nsecs_resolution * 100.0) / + ((double)lm_optB * b->ba_corrected.st_median * 1000.0)) + + 1.0); + (void) printf("# Quantization error likely;" + "increase batch size (-B option) %dX to avoid.\n", + increase); + } + + /* + * XXX should warn on median != mean by a lot + */ + + if (b->ba_errors) { + if (!head++) { + (void) printf("#\n# WARNINGS\n"); + } + (void) printf("# Errors occured during benchmark.\n"); + } +} + +void +print_stats(barrier_t *b) +{ + (void) printf("#\n"); + (void) printf("# STATISTICS %7s %7s\n", + "usecs/call (raw)", + "usecs/call (outliers removed)"); + + if (b->ba_count == 0) { + (void) printf("zero samples\n"); + return; + } + + (void) printf(" min %7.3f %7.3f\n", + b->ba_raw.st_min, + b->ba_corrected.st_min); + + (void) printf(" max %7.3f %7.3f\n", + b->ba_raw.st_max, + b->ba_corrected.st_max); + (void) printf(" mean %7.3f %7.3f\n", + b->ba_raw.st_mean, + b->ba_corrected.st_mean); + (void) printf(" median %7.3f %7.3f\n", + b->ba_raw.st_median, + b->ba_corrected.st_median); + (void) printf(" stddev %7.3f %7.3f\n", + b->ba_raw.st_stddev, + b->ba_corrected.st_stddev); + (void) printf(" standard error %7.3f %7.3f\n", + b->ba_raw.st_stderr, + b->ba_corrected.st_stderr); + (void) printf(" 99%% conf level %7.3f %7.3f\n", + b->ba_raw.st_99confidence, + b->ba_corrected.st_99confidence); + (void) printf(" skew %7.3f %7.3f\n", + b->ba_raw.st_skew, + b->ba_corrected.st_skew); + (void) printf(" kurtosis %7.3f %7.3f\n", + b->ba_raw.st_kurtosis, + b->ba_corrected.st_kurtosis); + + (void) printf(" T correlation %7.3f %7.3f\n", + b->ba_raw.st_timecorr, + b->ba_corrected.st_timecorr); + (void) printf("#\n"); + + (void) printf("# elasped time %7.3f\n", (b->ba_endtime - + b->ba_starttime) / 1.0e9); + (void) printf("# number of samples %7d\n", b->ba_batches); + (void) printf("# number of outliers %7d\n", b->ba_outliers); + (void) printf("# getnsecs overhead %7d\n", (int)nsecs_overhead); + + (void) printf("#\n"); + (void) printf("# DISTRIBUTION\n"); + + print_histo(b); + + if (lm_optW) { + print_warnings(b); + } +} + +void +update_stats(barrier_t *b, result_t *r) +{ + double time; + double nsecs_per_call; + + if (b->ba_waiters == 0) { + /* first thread only */ + b->ba_t0 = r->re_t0; + b->ba_t1 = r->re_t1; + b->ba_count0 = 0; + b->ba_errors0 = 0; + } else { + /* all but first thread */ + if (r->re_t0 < b->ba_t0) { + b->ba_t0 = r->re_t0; + } + if (r->re_t1 > b->ba_t1) { + b->ba_t1 = r->re_t1; + } + } + + b->ba_count0 += r->re_count; + b->ba_errors0 += r->re_errors; + + if (b->ba_waiters == b->ba_hwm - 1) { + /* last thread only */ + + + time = (double)b->ba_t1 - (double)b->ba_t0 - + (double)nsecs_overhead; + + if (time < 100 * nsecs_resolution) + b->ba_quant++; + + /* + * normalize by procs * threads if not -U + */ + + nsecs_per_call = time / (double)b->ba_count0 * + (double)(lm_optT * lm_optP); + + b->ba_count += b->ba_count0; + b->ba_errors += b->ba_errors0; + + b->ba_data[b->ba_batches % b->ba_datasize] = + nsecs_per_call; + //TODO sock here + if(socket_on == 1) { + char message[64]; + sprintf(message, "%s\t%f\n", lm_optN, nsecs_per_call); + write (SOCK, message, strlen(message)); + } + + b->ba_batches++; + } +} + +#ifdef USE_SEMOP +barrier_t * +barrier_create(int hwm, int datasize) +{ + struct sembuf s[1]; + barrier_t *b; + + /*LINTED*/ + b = (barrier_t *)mmap(NULL, + sizeof (barrier_t) + (datasize - 1) * sizeof (double), + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0L); + if (b == (barrier_t *)MAP_FAILED) { + return (NULL); + } + b->ba_datasize = datasize; + + b->ba_flag = 0; + b->ba_hwm = hwm; + b->ba_semid = semget(IPC_PRIVATE, 3, 0600); + if (b->ba_semid == -1) { + (void) munmap((void *)b, sizeof (barrier_t)); + return (NULL); + } + + /* [hwm - 1, 0, 0] */ + s[0].sem_num = 0; + s[0].sem_op = hwm - 1; + s[0].sem_flg = 0; + if (semop(b->ba_semid, s, 1) == -1) { + perror("semop(1)"); + (void) semctl(b->ba_semid, 0, IPC_RMID); + (void) munmap((void *)b, sizeof (barrier_t)); + return (NULL); + } + + b->ba_waiters = 0; + b->ba_phase = 0; + + b->ba_count = 0; + b->ba_errors = 0; + + return (b); +} + +int +barrier_destroy(barrier_t *b) +{ + (void) semctl(b->ba_semid, 0, IPC_RMID); + (void) munmap((void *)b, sizeof (barrier_t)); + + return (0); +} + +int +barrier_queue(barrier_t *b, result_t *r) +{ + struct sembuf s[2]; + + /* + * {s0(-(hwm-1))} + * if ! nowait {s1(-(hwm-1))} + * (all other threads) + * update shared stats + * {s0(hwm-1), s1(1)} + * {s0(1), s2(-1)} + * else + * (last thread) + * update shared stats + * {s2(hwm-1)} + */ + + s[0].sem_num = 0; + s[0].sem_op = -(b->ba_hwm - 1); + s[0].sem_flg = 0; + if (semop(b->ba_semid, s, 1) == -1) { + perror("semop(2)"); + return (-1); + } + + s[0].sem_num = 1; + s[0].sem_op = -(b->ba_hwm - 1); + s[0].sem_flg = IPC_NOWAIT; + if (semop(b->ba_semid, s, 1) == -1) { + if (errno != EAGAIN) { + perror("semop(3)"); + return (-1); + } + + /* all but the last thread */ + + if (r != NULL) { + update_stats(b, r); + } + + b->ba_waiters++; + + s[0].sem_num = 0; + s[0].sem_op = b->ba_hwm - 1; + s[0].sem_flg = 0; + s[1].sem_num = 1; + s[1].sem_op = 1; + s[1].sem_flg = 0; + if (semop(b->ba_semid, s, 2) == -1) { + perror("semop(4)"); + return (-1); + } + + s[0].sem_num = 0; + s[0].sem_op = 1; + s[0].sem_flg = 0; + s[1].sem_num = 2; + s[1].sem_op = -1; + s[1].sem_flg = 0; + if (semop(b->ba_semid, s, 2) == -1) { + perror("semop(5)"); + return (-1); + } + + } else { + /* the last thread */ + + if (r != NULL) { + update_stats(b, r); + } + + b->ba_waiters = 0; + b->ba_phase++; + + s[0].sem_num = 2; + s[0].sem_op = b->ba_hwm - 1; + s[0].sem_flg = 0; + if (semop(b->ba_semid, s, 1) == -1) { + perror("semop(6)"); + return (-1); + } + } + + return (0); +} + +#else /* USE_SEMOP */ + +barrier_t * +barrier_create(int hwm, int datasize) +{ + pthread_mutexattr_t attr; + pthread_condattr_t cattr; + barrier_t *b; + + /*LINTED*/ + b = (barrier_t *)mmap(NULL, + sizeof (barrier_t) + (datasize - 1) * sizeof (double), + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, -1, 0L); + if (b == (barrier_t *)MAP_FAILED) { + return (NULL); + } + b->ba_datasize = datasize; + + b->ba_hwm = hwm; + b->ba_flag = 0; + + (void) pthread_mutexattr_init(&attr); + (void) pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + + (void) pthread_mutex_init(&b->ba_lock, &attr); + (void) pthread_cond_init(&b->ba_cv, &cattr); + + b->ba_waiters = 0; + b->ba_phase = 0; + + b->ba_count = 0; + b->ba_errors = 0; + + return (b); +} + +int +barrier_destroy(barrier_t *b) +{ + (void) munmap((void *)b, sizeof (barrier_t)); + + return (0); +} + +int +barrier_queue(barrier_t *b, result_t *r) +{ + int phase; + + (void) pthread_mutex_lock(&b->ba_lock); + + if (r != NULL) { + update_stats(b, r); + } + + phase = b->ba_phase; + + b->ba_waiters++; + if (b->ba_hwm == b->ba_waiters) { + b->ba_waiters = 0; + b->ba_phase++; + (void) pthread_cond_broadcast(&b->ba_cv); + } + + while (b->ba_phase == phase) { + (void) pthread_cond_wait(&b->ba_cv, &b->ba_lock); + } + + (void) pthread_mutex_unlock(&b->ba_lock); + return (0); +} +#endif /* USE_SEMOP */ + +int +gettindex() +{ + int i; + + if (tids == NULL) { + return (-1); + } + + for (i = 1; i < lm_optT; i++) { + if (pthread_self() == tids[i]) { + return (i); + } + } + + return (0); +} + +int +getpindex() +{ + return (pindex); +} + +void * +gettsd(int p, int t) +{ + if ((p < 0) || (p >= lm_optP) || (t < 0) || (t >= lm_optT)) + return (NULL); + + return ((void *)((unsigned long)tsdseg + + (((p * lm_optT) + t) * tsdsize))); +} + +#ifdef USE_GETHRTIME +long long +getnsecs() +{ + return (gethrtime()); +} + +long long +getusecs() +{ + return (gethrtime() / 1000); +} + +#elif USE_RDTSC /* USE_GETHRTIME */ + +__inline__ long long +rdtsc(void) +{ + unsigned long long x; + __asm__ volatile(".byte 0x0f, 0x31" : "=A" (x)); + return (x); +} + +long long +getusecs() +{ + return (rdtsc() * 1000000 / lm_hz); +} + +long long +getnsecs() +{ + return (rdtsc() * 1000000000 / lm_hz); +} + +#else /* USE_GETHRTIME */ + +long long +getusecs() +{ + struct timeval tv; + + (void) gettimeofday(&tv, NULL); + + return ((long long)tv.tv_sec * 1000000LL + (long long) tv.tv_usec); +} + +long long +getnsecs() +{ + struct timeval tv; + + (void) gettimeofday(&tv, NULL); + + return ((long long)tv.tv_sec * 1000000000LL + + (long long) tv.tv_usec * 1000LL); +} + +#endif /* USE_GETHRTIME */ + +int +setfdlimit(int limit) +{ + struct rlimit rlimit; + + if (getrlimit(RLIMIT_NOFILE, &rlimit) < 0) { + perror("getrlimit"); + exit(1); + } + + if (rlimit.rlim_cur > limit) + return (0); /* no worries */ + + rlimit.rlim_cur = limit; + + if (rlimit.rlim_max < limit) + rlimit.rlim_max = limit; + + if (setrlimit(RLIMIT_NOFILE, &rlimit) < 0) { + perror("setrlimit"); + exit(3); + } + + return (0); +} + + +#define KILOBYTE 1024 +#define MEGABYTE (KILOBYTE * KILOBYTE) +#define GIGABYTE (KILOBYTE * MEGABYTE) + +long long +sizetoll(const char *arg) +{ + int len = strlen(arg); + int i; + long long mult = 1; + + if (len && isalpha(arg[len - 1])) { + switch (arg[len - 1]) { + + case 'k': + case 'K': + mult = KILOBYTE; + break; + case 'm': + case 'M': + mult = MEGABYTE; + break; + case 'g': + case 'G': + mult = GIGABYTE; + break; + default: + return (-1); + } + + for (i = 0; i < len - 1; i++) + if (!isdigit(arg[i])) + return (-1); + } + + return (mult * strtoll(arg, NULL, 10)); +} + +int +sizetoint(const char *arg) +{ + int len = strlen(arg); + int i; + long long mult = 1; + + if (len && isalpha(arg[len - 1])) { + switch (arg[len - 1]) { + + case 'k': + case 'K': + mult = KILOBYTE; + break; + case 'm': + case 'M': + mult = MEGABYTE; + break; + case 'g': + case 'G': + mult = GIGABYTE; + break; + default: + return (-1); + } + + for (i = 0; i < len - 1; i++) + if (!isdigit(arg[i])) + return (-1); + } + + return (mult * atoi(arg)); +} + +static void +print_bar(long count, long total) +{ + int i; + + (void) putchar_unlocked(count ? '*' : ' '); + for (i = 1; i < (12 * count) / total; i++) + (void) putchar_unlocked('*'); + for (; i < 12; i++) + (void) putchar_unlocked(' '); +} + +static int +doublecmp(const void *p1, const void *p2) +{ + double a = *((double *)p1); + double b = *((double *)p2); + + if (a > b) + return (1); + if (a < b) + return (-1); + return (0); +} + +static void +print_histo(barrier_t *b) +{ + int n; + int i; + int j; + int last; + long long maxcount; + double sum; + long long min; + long long scale; + double x; + long long y; + long long count; + int i95; + double p95; + double r95; + double m95; + histo_t *histo; + + (void) printf("# %12s %12s %32s %12s\n", "counts", "usecs/call", + "", "means"); + + /* calculate how much data we've captured */ + n = b->ba_batches > b->ba_datasize ? b->ba_datasize : b->ba_batches; + + /* find the 95th percentile - index, value and range */ + qsort((void *)b->ba_data, n, sizeof (double), doublecmp); + min = b->ba_data[0] + 0.000001; + i95 = n * 95 / 100; + p95 = b->ba_data[i95]; + r95 = p95 - min + 1; + + /* find a suitable min and scale */ + i = 0; + x = r95 / (HISTOSIZE - 1); + while (x >= 10.0) { + x /= 10.0; + i++; + } + y = x + 0.9999999999; + while (i > 0) { + y *= 10; + i--; + } + min /= y; + min *= y; + scale = y * (HISTOSIZE - 1); + if (scale < (HISTOSIZE - 1)) { + scale = (HISTOSIZE - 1); + } + + /* create and initialise the histogram */ + histo = malloc(HISTOSIZE * sizeof (histo_t)); + for (i = 0; i < HISTOSIZE; i++) { + histo[i].sum = 0.0; + histo[i].count = 0; + } + + /* populate the histogram */ + last = 0; + sum = 0.0; + count = 0; + for (i = 0; i < i95; i++) { + j = (HISTOSIZE - 1) * (b->ba_data[i] - min) / scale; + + if (j >= HISTOSIZE) { + (void) printf("panic!\n"); + j = HISTOSIZE - 1; + } + + histo[j].sum += b->ba_data[i]; + histo[j].count++; + + sum += b->ba_data[i]; + count++; + } + m95 = sum / count; + + /* find the larges bucket */ + maxcount = 0; + for (i = 0; i < HISTOSIZE; i++) + if (histo[i].count > 0) { + last = i; + if (histo[i].count > maxcount) + maxcount = histo[i].count; + } + + /* print the buckets */ + for (i = 0; i <= last; i++) { + (void) printf("%7lld %7.3f |", histo[i].count, + (min + scale * (double)i / (HISTOSIZE - 1))); + + print_bar(histo[i].count, maxcount); + + if (histo[i].count > 0) + (void) printf("%7.3f\n", + histo[i].sum / histo[i].count); + else + (void) printf("%7s\n", "-"); + } + + /* find the mean of values beyond the 95th percentile */ + sum = 0.0; + count = 0; + for (i = i95; i < n; i++) { + sum += b->ba_data[i]; + count++; + } + + /* print the >95% bucket summary */ + (void) printf("\n"); + (void) printf("%7lld %7s |", count, "> 95%"); + print_bar(count, maxcount); + if (count > 0) + (void) printf("%7.3f\n", sum / count); + else + (void) printf("%7s\n", "-"); + (void) printf("\n"); + (void) printf("%7s %7.3f\n", "mean of 95%", m95); + (void) printf("%7s %7.3f\n", "95th %ile", p95); + + /* quantify any buffer overflow */ + if (b->ba_batches > b->ba_datasize) + (void) printf("%7s %7d\n", "data dropped", + b->ba_batches - b->ba_datasize); +} + +static void +compute_stats(barrier_t *b) +{ + int i; + + if (b->ba_batches > b->ba_datasize) + b->ba_batches = b->ba_datasize; + + /* + * convert to usecs/call + */ + + for (i = 0; i < b->ba_batches; i++) + b->ba_data[i] /= 1000.0; + + /* + * do raw stats + */ + + (void) crunch_stats(b->ba_data, b->ba_batches, &b->ba_raw); + + /* + * recursively apply 3 sigma rule to remove outliers + */ + + b->ba_corrected = b->ba_raw; + b->ba_outliers = 0; + + if (b->ba_batches > 40) { /* remove outliers */ + int removed; + + do { + removed = remove_outliers(b->ba_data, b->ba_batches, + &b->ba_corrected); + b->ba_outliers += removed; + b->ba_batches -= removed; + (void) crunch_stats(b->ba_data, b->ba_batches, + &b->ba_corrected); + } while (removed != 0 && b->ba_batches > 40); + } + +} + +/* + * routine to compute various statistics on array of doubles. + */ + +static int +crunch_stats(double *data, int count, stats_t *stats) +{ + double a; + double std; + double diff; + double sk; + double ku; + double mean; + int i; + int bytes; + double *dupdata; + + /* + * first we need the mean + */ + + mean = 0.0; + + for (i = 0; i < count; i++) { + mean += data[i]; + } + + mean /= count; + + stats->st_mean = mean; + + /* + * malloc and sort so we can do median + */ + + dupdata = malloc(bytes = sizeof (double) * count); + (void) memcpy(dupdata, data, bytes); + qsort((void *)dupdata, count, sizeof (double), doublecmp); + stats->st_median = dupdata[count/2]; + + /* + * reuse dupdata to compute time correlation of data to + * detect interesting time-based trends + */ + + for (i = 0; i < count; i++) + dupdata[i] = (double)i; + + (void) fit_line(dupdata, data, count, &a, &stats->st_timecorr); + free(dupdata); + + std = 0.0; + sk = 0.0; + ku = 0.0; + + stats->st_max = -1; + stats->st_min = 1.0e99; /* hard to find portable values */ + + for (i = 0; i < count; i++) { + if (data[i] > stats->st_max) + stats->st_max = data[i]; + if (data[i] < stats->st_min) + stats->st_min = data[i]; + + diff = data[i] - mean; + std += diff * diff; + sk += diff * diff * diff; + ku += diff * diff * diff * diff; + } + + stats->st_stddev = std = sqrt(std/(double)(count - 1)); + stats->st_stderr = std / sqrt(count); + stats->st_99confidence = stats->st_stderr * 2.326; + stats->st_skew = sk / (std * std * std) / (double)(count); + stats->st_kurtosis = ku / (std * std * std * std) / + (double)(count) - 3; + + return (0); +} + +/* + * does a least squares fit to the set of points x, y and + * fits a line y = a + bx. Returns a, b + */ + +int +fit_line(double *x, double *y, int count, double *a, double *b) +{ + double sumx, sumy, sumxy, sumx2; + double denom; + int i; + + sumx = sumy = sumxy = sumx2 = 0.0; + + for (i = 0; i < count; i++) { + sumx += x[i]; + sumx2 += x[i] * x[i]; + sumy += y[i]; + sumxy += x[i] * y[i]; + } + + denom = count * sumx2 - sumx * sumx; + + if (denom == 0.0) + return (-1); + + *a = (sumy * sumx2 - sumx * sumxy) / denom; + + *b = (count * sumxy - sumx * sumy) / denom; + + return (0); +} + +/* + * empty function for measurement purposes + */ + +int +nop() +{ + return (1); +} + +#define NSECITER 1000 + +static long long +get_nsecs_overhead() +{ + long long s; + + double data[NSECITER]; + stats_t stats; + + int i; + int count; + int outliers; + + (void) getnsecs(); /* warmup */ + (void) getnsecs(); /* warmup */ + (void) getnsecs(); /* warmup */ + + i = 0; + + count = NSECITER; + + for (i = 0; i < count; i++) { + s = getnsecs(); + data[i] = getnsecs() - s; + } + + (void) crunch_stats(data, count, &stats); + + while ((outliers = remove_outliers(data, count, &stats)) != 0) { + count -= outliers; + (void) crunch_stats(data, count, &stats); + } + + return ((long long)stats.st_mean); + +} + +long long +get_nsecs_resolution() +{ + long long y[1000]; + + int i, j, nops, res; + long long start, stop; + + /* + * first, figure out how many nops to use + * to get any delta between time measurements. + * use a minimum of one. + */ + + /* + * warm cache + */ + + stop = start = getnsecs(); + + for (i = 1; i < 10000000; i++) { + start = getnsecs(); + for (j = i; j; j--) + ; + stop = getnsecs(); + if (stop > start) + break; + } + + nops = i; + + /* + * now collect data at linearly varying intervals + */ + + for (i = 0; i < 1000; i++) { + start = getnsecs(); + for (j = nops * i; j; j--) + ; + stop = getnsecs(); + y[i] = stop - start; + } + + /* + * find smallest positive difference between samples; + * this is the timer resolution + */ + + res = 1<<30; + + for (i = 1; i < 1000; i++) { + int diff = y[i] - y[i-1]; + + if (diff > 0 && res > diff) + res = diff; + + } + + return (res); +} + +/* + * remove any data points from the array more than 3 sigma out + */ + +static int +remove_outliers(double *data, int count, stats_t *stats) +{ + double outmin = stats->st_mean - 3 * stats->st_stddev; + double outmax = stats->st_mean + 3 * stats->st_stddev; + + int i, j, outliers; + + for (outliers = i = j = 0; i < count; i++) + if (data[i] > outmax || data[i] < outmin) + outliers++; + else + data[j++] = data[i]; + + return (outliers); +} diff --git a/native/libMicro-0.4.0/libmicro.h b/native/libMicro-0.4.0/libmicro.h new file mode 100644 index 0000000..892516d --- /dev/null +++ b/native/libMicro-0.4.0/libmicro.h @@ -0,0 +1,196 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef LIBMICRO_H +#define LIBMICRO_H + +#include + +#define LIBMICRO_VERSION "0.4.0" + +#define STRSIZE 1024 + +typedef struct { + long long re_count; + long long re_errors; + long long re_t0; + long long re_t1; +} result_t; + +typedef struct { + double sum; + long long count; +} histo_t; + +#define HISTOSIZE 32 +#define DATASIZE 100000 + +/* + * stats we compute on data sets + */ + +typedef struct stats { + double st_min; + double st_max; + double st_mean; + double st_median; + double st_stddev; + double st_stderr; + double st_99confidence; + double st_skew; + double st_kurtosis; + double st_timecorr; /* correlation with respect to time */ +} stats_t; + +/* + * Barrier stuff + */ + +typedef struct { + int ba_hwm; /* barrier setpoint */ + int ba_flag; /* benchmark while true */ + long long ba_deadline; /* when to stop */ + int ba_phase; /* number of time used */ + int ba_waiters; /* how many are waiting */ + +#ifdef USE_SEMOP + int ba_semid; +#else + pthread_mutex_t ba_lock; + pthread_cond_t ba_cv; +#endif + + long long ba_count; /* how many ops */ + long long ba_errors; /* how many errors */ + + int ba_quant; /* how many quant errors */ + int ba_batches; /* how many samples */ + + double ba_starttime; /* test time start */ + double ba_endtime; /* test time end */ + +#ifdef NEVER + double ba_tmin; /* min time taken */ + double ba_tmax; /* max time taken */ + double ba_ctmax; /* max after outliers */ + double ba_mean; /* average value */ + double ba_median; /* median value */ + double ba_rawmedian; /* raw median value */ + double ba_stddev; /* standard deviation */ + double ba_stderr; /* standard error */ + double ba_skew; /* skew */ + double ba_kurtosis; /* kurtosis */ +#endif + stats_t ba_raw; /* raw stats */ + stats_t ba_corrected; /* corrected stats */ + + int ba_outliers; /* outlier count */ + + long long ba_t0; /* first thread/proc */ + long long ba_t1; /* time of last thread */ + long long ba_count0; + long long ba_errors0; + + int ba_datasize; /* possible #items data */ + double ba_data[1]; /* start of data ararry */ +} barrier_t; + + +/* + * Barrier interfaces + */ + +barrier_t *barrier_create(int hwm, int datasize); +int barrier_destroy(barrier_t *bar); +int barrier_queue(barrier_t *bar, result_t *res); + + +/* + * Functions that can be provided by the user + */ + +int benchmark(void *tsd, result_t *res); +int benchmark_init(); +int benchmark_fini(); +int benchmark_initrun(); +int benchmark_finirun(); +int benchmark_initworker(); +int benchmark_finiworker(); +int benchmark_initbatch(void *tsd); +int benchmark_finibatch(void *tsd); +int benchmark_optswitch(int opt, char *optarg); +char *benchmark_result(); + + +/* + * Globals exported to the user + */ + +extern int lm_argc; +extern char **lm_argv; + +extern int lm_optB; +extern int lm_optD; +extern int lm_optH; +extern char *lm_optN; +extern int lm_optP; +extern int lm_optS; +extern int lm_optT; + +extern int lm_defB; +extern int lm_defD; +extern int lm_defH; +extern char *lm_defN; +extern int lm_defP; +extern int lm_defS; +extern int lm_defT; +extern int lm_nsecs_per_op; + +extern char *lm_procpath; +extern char lm_procname[STRSIZE]; +extern char lm_usage[STRSIZE]; +extern char lm_optstr[STRSIZE]; +extern char lm_header[STRSIZE]; +extern size_t lm_tsdsize; + + +/* + * Utility functions + */ + +int getpindex(); +int gettindex(); +void *gettsd(int p, int t); +long long getusecs(); +long long getnsecs(); +int setfdlimit(int limit); +long long sizetoll(); +int sizetoint(); +int fit_line(double *, double *, int, double *, double *); +long long get_nsecs_resolution(); + +#endif /* LIBMICRO_H */ diff --git a/native/libMicro-0.4.0/libmicro_main.c b/native/libMicro-0.4.0/libmicro_main.c new file mode 100644 index 0000000..f7bcde1 --- /dev/null +++ b/native/libMicro-0.4.0/libmicro_main.c @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Separate file for main so we can link other programs + * with libmicro + */ + +#include + +extern int actual_main(int, char **); + +int +main(int argc, char *argv[]) +{ + return (actual_main(argc, argv)); +} diff --git a/native/libMicro-0.4.0/listen.c b/native/libMicro-0.4.0/listen.c new file mode 100644 index 0000000..f8730d7 --- /dev/null +++ b/native/libMicro-0.4.0/listen.c @@ -0,0 +1,127 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * listen benchmark + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define FIRSTPORT 12345 + +static struct sockaddr_in adds; +static int sock = -1; + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "notes: measures listen()()\n"); + + lm_tsdsize = 0; + + return (0); +} + +int +benchmark_initrun() +{ + int j; + int opt = 1; + struct hostent *host; + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock == -1) { + perror("socket"); + exit(1); + } + + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, + &opt, sizeof (int)) == -1) { + perror("setsockopt"); + exit(1); + } + + if ((host = gethostbyname("localhost")) == NULL) { + perror("gethostbyname"); + exit(1); + } + + j = FIRSTPORT; + for (;;) { + (void) memset(&adds, 0, sizeof (struct sockaddr_in)); + adds.sin_family = AF_INET; + adds.sin_port = htons(j++); + (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0], + sizeof (struct in_addr)); + + if (bind(sock, (struct sockaddr *)&adds, + sizeof (struct sockaddr_in)) == 0) { + break; + } + + if (errno != EADDRINUSE) { + perror("bind"); + exit(1); + } + } + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i += 2) { + if (listen(sock, 4) == -1) + res->re_errors++; + if (listen(sock, 5) == -1) + res->re_errors++; + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/localtime_r.c b/native/libMicro-0.4.0/localtime_r.c new file mode 100644 index 0000000..8430884 --- /dev/null +++ b/native/libMicro-0.4.0/localtime_r.c @@ -0,0 +1,75 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * localtime benchmark + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "notes: measures localtime_r()\n"); + lm_tsdsize = 0; + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + struct tm tms; + static time_t clock1 = 0L; + static time_t clock2 = 1L; + + for (i = 0; i < lm_optB; i += 10) { + (void) localtime_r(&clock1, &tms); + (void) localtime_r(&clock2, &tms); + (void) localtime_r(&clock1, &tms); + (void) localtime_r(&clock2, &tms); + (void) localtime_r(&clock1, &tms); + (void) localtime_r(&clock2, &tms); + (void) localtime_r(&clock1, &tms); + (void) localtime_r(&clock2, &tms); + (void) localtime_r(&clock1, &tms); + (void) localtime_r(&clock2, &tms); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/log.c b/native/libMicro-0.4.0/log.c new file mode 100644 index 0000000..0b4605f --- /dev/null +++ b/native/libMicro-0.4.0/log.c @@ -0,0 +1,73 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * log benchmark - should do wider range... + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "note: measures log()"); + lm_nsecs_per_op = 75; + lm_tsdsize = 0; + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i += 10) { + double value = i + .01; + (void) log(value); + (void) log(value); + (void) log(value); + (void) log(value); + (void) log(value); + (void) log(value); + (void) log(value); + (void) log(value); + (void) log(value); + (void) log(value); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/longjmp.c b/native/libMicro-0.4.0/longjmp.c new file mode 100644 index 0000000..50f4dbc --- /dev/null +++ b/native/libMicro-0.4.0/longjmp.c @@ -0,0 +1,65 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmark longjmp + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "notes: measures longjmp()\n"); + lm_tsdsize = 0; + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i = 0; + jmp_buf env; + + (void) setjmp(env); + i++; + if (i < lm_optB) + longjmp(env, 0); + + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/lrand48.c b/native/libMicro-0.4.0/lrand48.c new file mode 100644 index 0000000..e82ddfd --- /dev/null +++ b/native/libMicro-0.4.0/lrand48.c @@ -0,0 +1,71 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * lrand48 + */ + +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "note: measures lrand48()"); + lm_nsecs_per_op = 10; + lm_tsdsize = 0; + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i += 10) { + (void) lrand48(); + (void) lrand48(); + (void) lrand48(); + (void) lrand48(); + (void) lrand48(); + (void) lrand48(); + (void) lrand48(); + (void) lrand48(); + (void) lrand48(); + (void) lrand48(); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/lseek.c b/native/libMicro-0.4.0/lseek.c new file mode 100644 index 0000000..6ca4af4 --- /dev/null +++ b/native/libMicro-0.4.0/lseek.c @@ -0,0 +1,130 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * lseek + */ + +#ifdef linux +#define _XOPEN_SOURCE 500 +#endif + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFF "/dev/zero" +#define DEFS 1024 + +static char *optf = DEFF; +static long long opts = DEFS; + +typedef struct { + int ts_once; + int ts_fd; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "f:s:"); + + (void) sprintf(lm_usage, + " [-f file-to-read (default %s)]\n" + " [-s buffer-size (default %d)]\n" + "notes: measures lseek()\n", + DEFF, DEFS); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + if (ts->ts_once++ == 0) { + ts->ts_fd = open(optf, O_RDONLY); + } + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i += 2) { + if (lseek(ts->ts_fd, 0L, SEEK_SET) != 0) { + res->re_errors++; + } + if (lseek(ts->ts_fd, opts, SEEK_SET) != opts) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8lld", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/malloc.c b/native/libMicro-0.4.0/malloc.c new file mode 100644 index 0000000..6ccc52b --- /dev/null +++ b/native/libMicro-0.4.0/malloc.c @@ -0,0 +1,139 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * malloc benchmark (crude) + */ + + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +static int optg = 100; +static int opts[32] = {32}; +static int optscnt = 0; + +typedef struct { + void **ts_glob; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s:g:"); + + (void) sprintf(lm_usage, + " [-g number of mallocs before free (default %d)]\n" + " [-s size to malloc (default %d)." + " Up to 32 sizes accepted\n" + "notes: measures malloc()/free()", + optg, opts[0]); + + (void) sprintf(lm_header, "%6s %6s", "glob", "sizes"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'g': + optg = sizetoint(optarg); + break; + case 's': + opts[optscnt] = sizetoint(optarg); + optscnt = optscnt + 1; + optscnt = optscnt & (31); + break; + default: + return (-1); + } + + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + if (optscnt == 0) + optscnt = 1; + + ts->ts_glob = malloc(sizeof (void *)* optg); + if (ts->ts_glob == NULL) { + return (1); + } + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j, k; + + for (i = 0; i < lm_optB; i++) { + for (k = j = 0; j < optg; j++) { + if ((ts->ts_glob[j] = malloc(opts[k++])) == NULL) + res->re_errors++; + if (k >= optscnt) + k = 0; + } + for (j = 0; j < optg; j++) { + free(ts->ts_glob[j]); + } + } + + res->re_count = i * j; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + int i; + + (void) sprintf(result, "%6d ", optg); + + for (i = 0; i < optscnt; i++) + (void) sprintf(result + strlen(result), "%d ", opts[i]); + return (result); +} diff --git a/native/libMicro-0.4.0/memcpy.c b/native/libMicro-0.4.0/memcpy.c new file mode 100644 index 0000000..9a9448c --- /dev/null +++ b/native/libMicro-0.4.0/memcpy.c @@ -0,0 +1,160 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * memcpy + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFS 8192 +#define DEFR 1 + +static long long opts = DEFS; +static int optf; +static int optt; +static int opta; + +typedef struct { + char *ts_src; + char *ts_dest; + int ts_srcsize; + int ts_destsize; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "a:s:ft"); + + (void) sprintf(lm_usage, + " [-s buffer-size (default %d)]\n" + " [-a relative alignment (default page aligned)]\n" + " [-f (rotate \"from\" buffer to keep it out of cache)]\n" + " [-t (rotate \"to\" buffer to keep it out of cache)]\n" + "notes: measures memcpy()\n", + DEFS); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf++; + break; + case 't': + optt++; + break; + case 's': + opts = sizetoll(optarg); + break; + case 'a': + opta = sizetoint(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + if (optf) + ts->ts_srcsize = 64 * 1024 * 1024; + else + ts->ts_srcsize = opts + opta; + + if (optt) + ts->ts_destsize = 64 * 1024 * 1024; + else + ts->ts_destsize = (int)opts; + + + ts->ts_src = opta + (char *)valloc(ts->ts_srcsize); + ts->ts_dest = valloc(ts->ts_destsize); + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + char *src = ts->ts_src; + char *dest = ts->ts_dest; + + int bump = (int)opts; + + if (bump < 1024) + bump = 1024; /* avoid prefetched area */ + for (i = 0; i < lm_optB; i++) { + (void) memcpy(dest, src, opts); + if (optf) { + src += bump; + if (src + opts > ts->ts_src + ts->ts_srcsize) + src = ts->ts_src; + } + if (optt) { + dest += bump; + if (dest + opts > ts->ts_dest + ts->ts_destsize) + dest = ts->ts_dest; + } + } + + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8lld", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/memmove.c b/native/libMicro-0.4.0/memmove.c new file mode 100644 index 0000000..822c885 --- /dev/null +++ b/native/libMicro-0.4.0/memmove.c @@ -0,0 +1,160 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * memmove + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFS 8192 +#define DEFR 1 + +static long long opts = DEFS; +static int optf; +static int optt; +static int opta; + +typedef struct { + char *ts_src; + char *ts_dest; + int ts_srcsize; + int ts_destsize; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "a:s:ft"); + + (void) sprintf(lm_usage, + " [-s buffer-size (default %d)]\n" + " [-a relative alignment (default page aligned)]\n" + " [-f (rotate \"from\" buffer to keep it out of cache)]\n" + " [-t (rotate \"to\" buffer to keep it out of cache)]\n" + "notes: measures memmove()\n", + DEFS); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf++; + break; + case 't': + optt++; + break; + case 's': + opts = sizetoll(optarg); + break; + case 'a': + opta = sizetoint(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + if (optf) + ts->ts_srcsize = 64 * 1024 * 1024; + else + ts->ts_srcsize = opts + opta; + + if (optt) + ts->ts_destsize = 64 * 1024 * 1024; + else + ts->ts_destsize = (int)opts; + + + ts->ts_src = opta + (char *)valloc(ts->ts_srcsize); + ts->ts_dest = valloc(ts->ts_destsize); + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + char *src = ts->ts_src; + char *dest = ts->ts_dest; + + int bump = (int)opts; + + if (bump < 1024) + bump = 1024; /* avoid prefetched area */ + for (i = 0; i < lm_optB; i++) { + (void) memmove(dest, src, opts); + if (optf) { + src += bump; + if (src + opts > ts->ts_src + ts->ts_srcsize) + src = ts->ts_src; + } + if (optt) { + dest += bump; + if (dest + opts > ts->ts_dest + ts->ts_destsize) + dest = ts->ts_dest; + } + } + + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8lld", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/memrand.c b/native/libMicro-0.4.0/memrand.c new file mode 100644 index 0000000..13b403c --- /dev/null +++ b/native/libMicro-0.4.0/memrand.c @@ -0,0 +1,146 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * memory access time check + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +static long opts = 1024*1024; + +typedef struct { + long **ts_data; + long ts_result; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s:"); + + (void) sprintf(lm_usage, + " [-s size] number of bytes to " + " access (default %ld)\n" + "notes: measures \"random\" memory access times\n", + opts); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 's': + opts = sizetoint(optarg); + break; + default: + return (-1); + } + + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j; + + ts->ts_data = malloc(opts); + + if (ts->ts_data == NULL) { + return (1); + } + + /* + * use lmbench style backwards stride + */ + + for (i = 0; i < opts / sizeof (long); i++) { + j = i - 128; + if (j < 0) + j = j + opts / sizeof (long); + ts->ts_data[i] = (long *)&(ts->ts_data[j]); + } + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + long **ptr = ts->ts_data; + + + + for (i = 0; i < lm_optB; i += 10) { + ptr = (long **)*ptr; + ptr = (long **)*ptr; + ptr = (long **)*ptr; + ptr = (long **)*ptr; + ptr = (long **)*ptr; + ptr = (long **)*ptr; + ptr = (long **)*ptr; + ptr = (long **)*ptr; + ptr = (long **)*ptr; + ptr = (long **)*ptr; + } + + ts->ts_result = (long)*ptr; + + res->re_count = lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8ld ", opts); + + + return (result); +} diff --git a/native/libMicro-0.4.0/memset.c b/native/libMicro-0.4.0/memset.c new file mode 100644 index 0000000..4f28d26 --- /dev/null +++ b/native/libMicro-0.4.0/memset.c @@ -0,0 +1,169 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * memset + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFS 8192 + +static long long opts = DEFS; +static int opta = 0; +static int optu = 0; + +static char *optas = "4k"; + +typedef struct { + char *ts_buff; + int ts_size; + int ts_offset; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "a:us:"); + + (void) sprintf(lm_usage, + " [-s buffer-size (default %d)]\n" + " [-a alignment (force buffer alignment)]\n" + " [-u (try to always use uncached memory)]" + "notes: measures memset()\n", + DEFS); + + (void) sprintf(lm_header, "%8s%16s", "size", "alignment"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'u': + optu = 1; + break; + case 's': + opts = sizetoll(optarg); + break; + case 'a': + opta = sizetoll(optarg); + if (opta > 4096) + opta = 0; + else + optas = optarg; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int errors = 0; + int i; + + if (optu) { + ts->ts_size = 1024 * 1024 * 64; + ts->ts_offset = opta; + } else { + ts->ts_size = opta + opts; + ts->ts_offset = opta; + } + + if ((ts->ts_buff = (char *)valloc(ts->ts_size)) == NULL) + errors++; + + for (i = 0; i < ts->ts_size; i++) + ts->ts_buff[i] = 0; + return (errors); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + + if (optu) { + char *buf = ts->ts_buff + ts->ts_offset; + char *end = ts->ts_buff + ts->ts_size; + int offset = ts->ts_offset; + for (i = 0; i < lm_optB; i ++) { + (void) memset(buf, 0, opts); + buf = (char *)(((unsigned long)buf + opts + 4095) & + ~4095) + offset; + if (buf + opts > end) + buf = ts->ts_buff + offset; + } + } else { + char *buf = ts->ts_buff + ts->ts_offset; + + for (i = 0; i < lm_optB; i += 10) { + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + (void) memset(buf, 0, opts); + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8lld%12s", opts, optas); + + return (result); +} diff --git a/native/libMicro-0.4.0/mk_tarball b/native/libMicro-0.4.0/mk_tarball new file mode 100755 index 0000000..de56210 --- /dev/null +++ b/native/libMicro-0.4.0/mk_tarball @@ -0,0 +1,28 @@ +#!/bin/sh -x +# +# Copyright 2003 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# +# script to make tarball... args are contents to be inserted +# + +libmicro_version=`bin/getpid -V` +case $libmicro_version in +[0-9]*) + ;; +*) + echo "ERROR: cannot determine libMicro version" + exit 1 +esac +dirname="libMicro-$libmicro_version" + +here=`pwd` +target=$here/libMicro.tar +tmpdir=/tmp/libmicro.$$ +mkdir -p $tmpdir/$dirname +cp $* $tmpdir/$dirname +cd $tmpdir +tar cvf $target $dirname +cd $here +rm -rf $tmpdir diff --git a/native/libMicro-0.4.0/mktime.c b/native/libMicro-0.4.0/mktime.c new file mode 100644 index 0000000..615192e --- /dev/null +++ b/native/libMicro-0.4.0/mktime.c @@ -0,0 +1,112 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * mktime + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + struct tm ts_tm1; + struct tm ts_tm2; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_usage, + "notes: measures mktime()\n"); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + time_t clock1; + time_t clock2; + + clock1 = time(NULL); + clock2 = clock1 + 1; + + (void) localtime_r(&clock1, &ts->ts_tm1); + (void) localtime_r(&clock2, &ts->ts_tm2); + + return (0); +} + + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + struct tm t1, t2; + + for (i = 0; i < lm_optB; i += 10) { + t1 = ts->ts_tm1; + t2 = ts->ts_tm2; + (void) mktime(&t1); + (void) mktime(&t2); + + t1 = ts->ts_tm1; + t2 = ts->ts_tm2; + (void) mktime(&t1); + (void) mktime(&t2); + + t1 = ts->ts_tm1; + t2 = ts->ts_tm2; + (void) mktime(&t1); + (void) mktime(&t2); + + t1 = ts->ts_tm1; + t2 = ts->ts_tm2; + (void) mktime(&t1); + (void) mktime(&t2); + + t1 = ts->ts_tm1; + t2 = ts->ts_tm2; + (void) mktime(&t1); + (void) mktime(&t2); + } + res->re_count = lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/mmap.c b/native/libMicro-0.4.0/mmap.c new file mode 100644 index 0000000..44b8b58 --- /dev/null +++ b/native/libMicro-0.4.0/mmap.c @@ -0,0 +1,198 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2002 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef volatile char vchar_t; + +typedef struct { + int ts_once; + vchar_t ** ts_map; + vchar_t ts_foo; +} tsd_t; + +#define DEFF "/dev/zero" +#define DEFL 8192 + +static char *optf = DEFF; +static long long optl = DEFL; +static int optr = 0; +static int opts = 0; +static int optw = 0; +static int fd = -1; +static int anon = 0; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "f:l:rsw"); + + (void) sprintf(lm_usage, + " [-f file-to-map (default %s)]\n" + " [-l mapping-length (default %d)]\n" + " [-r] (read a byte from each page)\n" + " [-w] (write a byte on each page)\n" + " [-s] (use MAP_SHARED)\n" + "notes: measures mmap()\n", + DEFF, DEFL); + + (void) sprintf(lm_header, "%8s %5s", "length", "flags"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + anon = strcmp(optf, "MAP_ANON") == 0; + break; + case 'l': + optl = sizetoll(optarg); + break; + case 'r': + optr = 1; + break; + case 's': + opts = 1; + break; + case 'w': + optw = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + if (!anon) + fd = open(optf, O_RDWR); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int errors = 0; + + if (ts->ts_once++ == 0) { + ts->ts_map = (vchar_t **)malloc(lm_optB * sizeof (void *)); + if (ts->ts_map == NULL) { + errors++; + } + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j; + + for (i = 0; i < lm_optB; i++) { + if (anon) { + ts->ts_map[i] = (vchar_t *)mmap(NULL, optl, + PROT_READ | PROT_WRITE, + MAP_ANON | (opts ? MAP_SHARED : MAP_PRIVATE), + -1, 0L); + } else { + ts->ts_map[i] = (vchar_t *)mmap(NULL, optl, + PROT_READ | PROT_WRITE, + opts ? MAP_SHARED : MAP_PRIVATE, + fd, 0L); + } + + if (ts->ts_map[i] == MAP_FAILED) { + res->re_errors++; + continue; + } + + if (optr) { + for (j = 0; j < optl; j += 4096) { + ts->ts_foo += ts->ts_map[i][j]; + } + } + if (optw) { + for (j = 0; j < optl; j += 4096) { + ts->ts_map[i][j] = 1; + } + } + } + res->re_count = i; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + (void) munmap((void *)ts->ts_map[i], optl); + } + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + char flags[5]; + + flags[0] = anon ? 'a' : '-'; + flags[1] = optr ? 'r' : '-'; + flags[2] = optw ? 'w' : '-'; + flags[3] = opts ? 's' : '-'; + flags[4] = 0; + + (void) sprintf(result, "%8lld %5s", optl, flags); + + return (result); +} diff --git a/native/libMicro-0.4.0/mprotect.c b/native/libMicro-0.4.0/mprotect.c new file mode 100644 index 0000000..5d08b9e --- /dev/null +++ b/native/libMicro-0.4.0/mprotect.c @@ -0,0 +1,200 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef volatile char vchar_t; + +typedef struct { + int ts_batch; + int ts_res; +} tsd_t; + +#define DEFF "/dev/zero" +#define DEFL 8192 + +static char *optf = DEFF; +static long long optl = DEFL; +static int optr = 0; +static int optw = 0; +static int opts = 0; +static int optt = 0; +static int fd = -1; +static int anon = 0; +static int foo = 0; +static vchar_t *seg; +static int pagesize; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "f:l:rstw"); + + (void) sprintf(lm_usage, + " [-f file-to-map (default %s)]\n" + " [-l mapping-length (default %d)]\n" + " [-r] (read a byte from each page)\n" + " [-w] (write a byte on each page)\n" + " [-s] (use MAP_SHARED)\n" + " [-t] (touch each page after restoring permissions)\n" + "notes: measures mprotect()\n", + DEFF, DEFL); + + (void) sprintf(lm_header, "%8s %5s", "size", "flags"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + anon = strcmp(optf, "MAP_ANON") == 0; + break; + case 'l': + optl = sizetoll(optarg); + break; + case 'r': + optr = 1; + break; + case 's': + opts = 1; + break; + case 't': + optt = 1; + break; + case 'w': + optw = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + int flags; + int i; + + if (!anon) + fd = open(optf, O_RDWR); + + flags = opts ? MAP_SHARED : MAP_PRIVATE; + flags |= anon ? MAP_ANON : 0; + + seg = (vchar_t *)mmap(NULL, lm_optB * optl, PROT_READ | PROT_WRITE, + flags, anon ? -1 : fd, 0L); + + if (seg == MAP_FAILED) { + return (-1); + } + + if (optr) { + for (i = 0; i < lm_optB * optl; i += 4096) { + foo += seg[i]; + } + } + + if (optw) { + for (i = 0; i < lm_optB * optl; i += 4096) { + seg[i] = 1; + } + } + + pagesize = getpagesize(); + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int us; + int prot = PROT_NONE; + int j, k; + + us = (getpindex() * lm_optT) + gettindex(); + for (i = 0; i < lm_optB; i++) { + switch ((us + ts->ts_batch + i) % 2) { + case 0: + prot = PROT_NONE; + if (optt) { + for (j = k = 0; j < optl; j += pagesize) + k += seg[i * optl + j]; + ts->ts_res += k; + } + break; + default: + prot = PROT_READ | PROT_WRITE; + break; + } + + if (mprotect((void *)&seg[i * optl], optl, prot) == -1) { + res->re_errors++; + } + } + res->re_count += lm_optB; + ts->ts_batch++; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + char flags[6]; + + flags[0] = anon ? 'a' : '-'; + flags[1] = optr ? 'r' : '-'; + flags[2] = optw ? 'w' : '-'; + flags[3] = opts ? 's' : '-'; + flags[4] = optt ? 't' : '-'; + flags[5] = 0; + + (void) sprintf(result, "%8lld %5s", optl, flags); + + return (result); +} diff --git a/native/libMicro-0.4.0/msync.c b/native/libMicro-0.4.0/msync.c new file mode 100644 index 0000000..48b0510 --- /dev/null +++ b/native/libMicro-0.4.0/msync.c @@ -0,0 +1,190 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + char *ts_map; + int ts_foo; /* defeat optimizers */ +} tsd_t; + +#define DEFF "/dev/zero" +#define DEFL 8192 + +static char *optf = DEFF; +static long long optl = DEFL; +static int optr = 0; +static int opts = 0; +static int optw = 0; +static int opta = MS_SYNC; +static int opti = 0; +static int anon = 0; +static int pagesize; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "af:il:rsw"); + + (void) sprintf(lm_usage, + " [-f file-to-map (default %s)]\n" + " [-l mapping-length (default %d)]\n" + " [-r] (read a byte from each page between msyncs)\n" + " [-w] (write a byte to each page between msyncs)\n" + " [-s] (use MAP_SHARED instead of MAP_PRIVATE)\n" + " [-a (specify MS_ASYNC rather than default MS_SYNC)\n" + " [-i (specify MS_INVALIDATE)\n" + "notes: measures msync()\n", + DEFF, DEFL); + + (void) sprintf(lm_header, "%8s %6s", "length", "flags"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'a': + opta = MS_ASYNC; + break; + + case 'f': + optf = optarg; + break; + + case 'i': + opti = MS_INVALIDATE; + break; + + case 'l': + optl = sizetoll(optarg); + break; + case 'r': + optr = 1; + break; + case 's': + opts = 1; + break; + case 'w': + optw = 1; + break; + default: + return (-1); + } + + pagesize = getpagesize(); + + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + int fd; + + if ((fd = open(optf, O_RDWR)) < 0) { + perror("open:"); + return (1); + } + + (void) ftruncate(fd, optl); + + if ((ts->ts_map = (char *)mmap(NULL, optl, + PROT_READ | PROT_WRITE, opts ? MAP_SHARED : MAP_PRIVATE, + fd, 0L)) == MAP_FAILED) { + perror("mmap:"); + (void) close(fd); + return (1); + } + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j; + + for (i = 0; i < lm_optB; i++) { + + if (msync(ts->ts_map, optl, opta | opti) < 0) { + perror("msync:"); + res->re_errors++; + break; + } + + if (optr) { + for (j = 0; j < optl; j += pagesize) { + ts->ts_foo += ts->ts_map[j]; + } + } + + if (optw) { + for (j = 0; j < optl; j += pagesize) { + ts->ts_map[j] = 1; + } + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + char flags[6]; + + flags[0] = anon ? 'a' : '-'; + flags[1] = optr ? 'r' : '-'; + flags[2] = optw ? 'w' : '-'; + flags[3] = opts ? 's' : '-'; + flags[4] = opti ? 'i' : '-'; + flags[5] = 0; + + (void) sprintf(result, "%8lld %6s", optl, flags); + + return (result); +} diff --git a/native/libMicro-0.4.0/multiview.sh b/native/libMicro-0.4.0/multiview.sh new file mode 100644 index 0000000..75dea4b --- /dev/null +++ b/native/libMicro-0.4.0/multiview.sh @@ -0,0 +1,201 @@ +#!/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# output html comparison of several libmicro output data files +# usage: multiview file1 file2 file3 file4 ... +# +# relative ranking is calculated using first as reference +# color interpolation is done to indicate relative performance; +# the redder the color, the slower the result, the greener the +# faster + +/bin/nawk ' BEGIN { + benchmark_count = 0; + header_count = 0; +} +/^#/ { + continue; + } +/errors/ { + continue; + } +/^\!/ { + split($0, A_header, ":"); + name = substr(A_header[1],2); + headers[name]=name; + header_data[name,FILENAME] = substr($0, length(name) + 3); + if (header_names[name] == 0) { + header_names[name] = ++header_count; + headers[header_count] = name; + } + continue; +} + + { + if(NF >= 7) { + if (benchmark_names[$1] == 0) { + benchmark_names[$1] = ++benchmark_count; + benchmarks[benchmark_count] = $1; + } + if ($6 == 0) + benchmark_data[$1,FILENAME] = $4; + else + benchmark_data[$1,FILENAME] = -1; + } +} + +END { + printf("\n"); + printf("\n"); + printf("\n"); + printf("\n"); + printf("\n"); + printf("multiview comparison\n") + printf("\n"); + printf("\n"); + printf("\n"); + printf("\n"); + printf("\n"); + for(i = 1; i <= header_count; i++) { + hname = headers[i]; + printf("\n", hname); + + for (j = 1; j < ARGC; j++) { + sub("^[\t ]+", "", header_data[hname, ARGV[j]]); + printf("\n", header_data[hname, ARGV[j]]); + } + printf("\n"); + } + printf("\n"); + printf("\n"); + printf("\n"); + + for (i = 2; i < ARGC; i++) + printf("\n"); + + printf("\n"); + for(i = 1; i < benchmark_count; i++) { + for(j = 1; j < benchmark_count; j++) { + if (benchmarks[j] > benchmarks[j + 1]) { + tmp = benchmarks[j]; + benchmarks[j] = benchmarks[j+1]; + benchmarks[j+1] = tmp; + } + } + } + + for(i = 1; i <= benchmark_count; i++) { + name = benchmarks[i]; + a = benchmark_data[name, ARGV[1]]; + + printf("\n"); + printf("\n", name); + if (a > 0) + printf("\n", a); + else { + if (a < 0) + printf("\n", "ERRORS"); + else + printf("\n", "missing"); + + for (j = 2; j < ARGC; j++) + printf("\n", "not computed"); + continue; + } + + for (j = 2; j < ARGC; j++) { + b = benchmark_data[name, ARGV[j]]; + if (b > 0) { + factor = b/a; + bgcolor = colormap(factor); + if (factor > 1) + percentage = -(factor * 100 - 100); + if (factor <= 1) + percentage = 100/factor - 100; + + printf("\n", + bgcolor, b, percentage); + } + + else if (b < 0) + printf("\n", "ERRORS"); + else + printf("\n", "missing"); + + } + printf("\n"); + + } + printf("
%s%s
BENCHMARKUSECSUSECS [percentage]
%s
%f
%s%s%s
%11.5f[%#+7.1f%%]
%s%25s
\n"); + +} + +function colormap(value, bgcolor, r, g, b) +{ + if (value <= .2) + value = .2; + if (value > 5) + value = 5; + + if (value < .9) { + r = colorcalc(.2, value, .9, 0, 255); + g = colorcalc(.2, value, .9, 153, 255); + b = colorcalc(.2, value, .9, 0, 255); + bgcolor=sprintf("#%2.2x%2.2x%2.2x", r, g, b); + } + else if (value < 1.1) + bgcolor="#ffffff"; + else { + r = 255; + g = colorcalc(1.1, value, 5, 255, 0); + b = colorcalc(1.1, value, 5, 255, 0); + bgcolor=sprintf("#%2.2x%2.2x%2.2x", r, g, b); + } + + return (bgcolor); +} + +function colorcalc(min, value, max, mincolor, maxcolor) +{ + return((value - min)/(max-min) * (maxcolor-mincolor) + mincolor); +} + +' "$@" + + diff --git a/native/libMicro-0.4.0/munmap.c b/native/libMicro-0.4.0/munmap.c new file mode 100644 index 0000000..7979dbb --- /dev/null +++ b/native/libMicro-0.4.0/munmap.c @@ -0,0 +1,192 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2002 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef volatile char vchar_t; + +typedef struct { + int ts_once; + vchar_t ** ts_map; + vchar_t ts_foo; +} tsd_t; + +#define DEFF "/dev/zero" +#define DEFL 8192 + +static char *optf = DEFF; +static long long optl = DEFL; +static int optr = 0; +static int optw = 0; +static int opts = 0; +static int fd = -1; +static int anon = 0; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "f:l:rsw"); + + (void) sprintf(lm_usage, + " [-f file-to-map (default %s)]\n" + " [-l mapping-length (default %d)]\n" + " [-r] (read a byte from each page)\n" + " [-w] (write a byte on each page)\n" + " [-s] (use MAP_SHARED)\n" + "notes: measures munmap()\n", + DEFF, DEFL); + + (void) sprintf(lm_header, "%8s %5s", "size", "flags"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + anon = strcmp(optf, "MAP_ANON") == 0; + break; + case 'l': + optl = sizetoll(optarg); + break; + case 'r': + optr = 1; + break; + case 's': + opts = 1; + break; + case 'w': + optw = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + if (!anon) + fd = open(optf, O_RDWR); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i, j; + int errors = 0; + + if (ts->ts_once++ == 0) { + ts->ts_map = (vchar_t **)malloc(lm_optB * sizeof (void *)); + if (ts->ts_map == NULL) { + errors++; + } + } + + for (i = 0; i < lm_optB; i++) { + if (anon) { + ts->ts_map[i] = (vchar_t *)mmap(NULL, optl, + PROT_READ | PROT_WRITE, + MAP_ANON | (opts ? MAP_SHARED : MAP_PRIVATE), + -1, 0L); + } else { + ts->ts_map[i] = (vchar_t *)mmap(NULL, optl, + PROT_READ | PROT_WRITE, + opts ? MAP_SHARED : MAP_PRIVATE, + fd, 0L); + } + + if (ts->ts_map[i] == MAP_FAILED) { + errors++; + continue; + } + if (optr) { + for (j = 0; j < optl; j += 4096) { + ts->ts_foo += ts->ts_map[i][j]; + } + } + if (optw) { + for (j = 0; j < optl; j += 4096) { + ts->ts_map[i][j] = 1; + } + } + } + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (munmap((void *)ts->ts_map[i], optl) == -1) { + res->re_errors++; + } + } + res->re_count += lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + char flags[5]; + + flags[0] = anon ? 'a' : '-'; + flags[1] = optr ? 'r' : '-'; + flags[2] = optw ? 'w' : '-'; + flags[3] = opts ? 's' : '-'; + flags[4] = 0; + + (void) sprintf(result, "%8lld %5s", optl, flags); + + return (result); +} diff --git a/native/libMicro-0.4.0/mutex.c b/native/libMicro-0.4.0/mutex.c new file mode 100644 index 0000000..3c056af --- /dev/null +++ b/native/libMicro-0.4.0/mutex.c @@ -0,0 +1,194 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * mutex + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +static int optt = 0; +static int optp = 0; +static int opth = 0; +static int opto = 0; + +pthread_mutex_t *lock; + +typedef struct { + int ts_once; + pthread_mutex_t *ts_lock; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_usage, + " [-t] (create dummy thread so we are multithreaded)\n" + " [-p] (use inter-process mutex (not support everywhere))\n" + " [-h usecs] (specify mutex hold time (default 0)\n" + "notes: measures uncontended pthread_mutex_[un,]lock\n"); + + (void) sprintf(lm_optstr, "tph:o:"); + + (void) sprintf(lm_header, "%8s", "holdtime"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'p': + optp = 1; + break; + + case 't': + optt = 1; + break; + + case 'h': + opth = sizetoint(optarg); + break; + + case 'o': + opto = sizetoint(optarg); + break; + + default: + return (-1); + } + return (0); +} + +void * +dummy(void *arg) +{ + (void) pause(); + return (arg); +} + +int +benchmark_initrun() +{ + pthread_mutexattr_t attr; + int errors = 0; + + /*LINTED*/ + lock = (pthread_mutex_t *)mmap(NULL, + getpagesize(), + PROT_READ | PROT_WRITE, + optp?(MAP_ANON | MAP_SHARED):MAP_ANON|MAP_PRIVATE, + -1, 0L) + opto; + + if (lock == MAP_FAILED) { + errors++; + } else { + (void) pthread_mutexattr_init(&attr); + if (optp) + (void) pthread_mutexattr_setpshared(&attr, + PTHREAD_PROCESS_SHARED); + + if (pthread_mutex_init(lock, &attr) != 0) + errors++; + } + + return (errors); +} + +int +benchmark_initworker(void *tsd) +{ + int errors = 0; + tsd_t *ts = (tsd_t *)tsd; + + + if (optt) { + pthread_t tid; + + + + if (pthread_create(&tid, NULL, dummy, NULL) != 0) { + errors++; + } + } + + ts->ts_lock = lock; + + return (errors); +} + +void +spinme(int usecs) +{ + long long s = getusecs(); + + while (getusecs() - s < usecs) + ; +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i ++) { + + (void) pthread_mutex_lock(ts->ts_lock); + if (opth) + spinme(opth); + (void) pthread_mutex_unlock(ts->ts_lock); + + } + + res->re_count = lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8d", opth); + + return (result); +} diff --git a/native/libMicro-0.4.0/nop.c b/native/libMicro-0.4.0/nop.c new file mode 100644 index 0000000..815691f --- /dev/null +++ b/native/libMicro-0.4.0/nop.c @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * silly nop benchmark to test infrastructure + */ + + +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "notes: measures nothing()\n"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + int nop(); + + for (i = 0; i < lm_optB; i++) + (void) nop(); /* do nothing but the call */ + + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/open.c b/native/libMicro-0.4.0/open.c new file mode 100644 index 0000000..7cdcd76 --- /dev/null +++ b/native/libMicro-0.4.0/open.c @@ -0,0 +1,138 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * benchmark open + */ + + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + int *ts_fds; +} tsd_t; + +#define DEFF "/dev/null" + +static char *optf = DEFF; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + lm_defB = 256; + + (void) sprintf(lm_usage, + " [-f file-to-open (default %s)]\n" + "notes: measures open()\n", + DEFF); + + (void) sprintf(lm_optstr, "f:"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + (void) setfdlimit(lm_optB * lm_optT + 10); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int errors = 0; + + if (ts->ts_once++ == 0) { + ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_fds == NULL) { + errors++; + } + for (i = 0; i < lm_optB; i++) { + ts->ts_fds[i] = -1; + } + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + ts->ts_fds[i] = open(optf, O_RDONLY); + if (ts->ts_fds[i] < 0) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + (void) close(ts->ts_fds[i]); + } + + return (0); +} diff --git a/native/libMicro-0.4.0/pipe.c b/native/libMicro-0.4.0/pipe.c new file mode 100644 index 0000000..e873d9f --- /dev/null +++ b/native/libMicro-0.4.0/pipe.c @@ -0,0 +1,566 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + pid_t ts_child; + pthread_t ts_thread; + int ts_in; + int ts_out; + int ts_in2; + int ts_out2; + int ts_lsn; + struct sockaddr_in ts_add; +} tsd_t; + +#define FIRSTPORT 12345 + +static char *modes[] = {"st", "mt", "mp", NULL}; +#define MD_SINGLE 0 +#define MD_MULTITHREAD 1 +#define MD_MULTIPROCESS 2 + +static char *xports[] = {"pipe", "fifo", "sock", "tcp", + NULL}; +#define XP_PIPES 0 +#define XP_FIFOS 1 +#define XP_SOCKETPAIR 2 +#define XP_LOCALTCP 3 + +#define DEFM MD_SINGLE +#define DEFS 1024 +#define DEFX XP_PIPES + +static int optm = DEFM; +static size_t opts = DEFS; +static int optx = DEFX; +static void *rbuf = NULL; +static void *wbuf = NULL; + +int readall(int s, void *buf, size_t len); +void *loopback(void *arg); +int prepare_pipes(tsd_t *tsd); +int prepare_fifos(tsd_t *tsd); +int cleanup_fifos(tsd_t *tsd); +int prepare_socketpair(tsd_t *tsd); +int prepare_localtcp(tsd_t *tsd); +int prepare_localtcp_once(tsd_t *tsd); +char *lookupa(int x, char *names[]); +int lookup(char *x, char *names[]); + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "m:s:x:"); + + (void) sprintf(lm_usage, + " [-m mode (st|mt|mp, default %s)]\n" + " [-s buffer-size (default %d)]\n" + " [-x transport (pipe|fifo|sock|tcp, default %s)]\n" + "notes: measures write()/read() across various transports\n", + lookupa(DEFM, modes), DEFS, lookupa(DEFX, xports)); + + (void) sprintf(lm_header, "%2s %4s", "md", "xprt"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + int x; + + switch (opt) { + case 'm': + x = lookup(optarg, modes); + if (x == -1) + return (-1); + optm = x; + break; + case 's': + opts = sizetoll(optarg); + break; + case 'x': + x = lookup(optarg, xports); + if (x == -1) + return (-1); + optx = x; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + if (optx == XP_FIFOS) { + if (geteuid() != 0) { + (void) printf("sorry, must be root to create fifos\n"); + exit(1); + } + } + + (void) setfdlimit(4 * lm_optT + 10); + + rbuf = malloc(opts); + wbuf = malloc(opts); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int result; + pid_t pid; + int i; + + switch (optx) { + case XP_SOCKETPAIR: + result = prepare_socketpair(ts); + break; + case XP_LOCALTCP: + result = prepare_localtcp(ts); + break; + case XP_FIFOS: + result = prepare_fifos(ts); + break; + case XP_PIPES: + default: + result = prepare_pipes(ts); + break; + } + if (result == -1) { + return (1); + } + + switch (optm) { + case MD_MULTITHREAD: + result = pthread_create(&ts->ts_thread, NULL, loopback, tsd); + if (result == -1) { + return (1); + } + break; + case MD_MULTIPROCESS: + pid = fork(); + switch (pid) { + case 0: + (void) loopback(tsd); + exit(0); + break; + case -1: + return (-1); + default: + ts->ts_child = pid; + break; + } + break; + case MD_SINGLE: + default: + break; + } + + /* Prime the loopback */ + if (write(ts->ts_out, wbuf, opts) != opts) { + return (1); + } + if (readall(ts->ts_in, rbuf, opts) != opts) { + return (1); + } + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int n; + + for (i = 0; i < lm_optB; i++) { + if (write(ts->ts_out, wbuf, opts) != opts) { + res->re_errors++; + continue; + } + + n = readall(ts->ts_in, rbuf, opts); + if (n == -1) { + res->re_errors++; + continue; + } + } + res->re_count = i; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + /* Terminate the loopback */ + (void) write(ts->ts_out, wbuf, opts); + (void) readall(ts->ts_in, rbuf, opts); + + switch (optm) { + case MD_MULTITHREAD: + (void) close(ts->ts_in2); + (void) close(ts->ts_out2); + (void) pthread_join(ts->ts_thread, NULL); + break; + case MD_MULTIPROCESS: + (void) close(ts->ts_in2); + (void) close(ts->ts_out2); + (void) waitpid(ts->ts_child, NULL, 0); + break; + case MD_SINGLE: + default: + break; + } + + (void) close(ts->ts_in); + (void) close(ts->ts_out); + + if (optx == XP_FIFOS) { + (void) cleanup_fifos(ts); + } + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%2s %4s", + lookupa(optm, modes), lookupa(optx, xports)); + + return (result); +} + +int +readall(int s, void *buf, size_t len) +{ + size_t n; + size_t total = 0; + + for (;;) { + n = read(s, (void *)((long)buf + total), len - total); + if (n < 1) { + return (-1); + } + total += n; + if (total >= len) { + return (total); + } + } +} + +void * +loopback(void *arg) +{ + tsd_t *ts = (tsd_t *)arg; + int i, n, m; + + /* Include priming and termination */ + m = lm_optB + 2; + + for (i = 0; i < m; i++) { + n = readall(ts->ts_in2, rbuf, opts); + if (n == -1) { + break; + } + if (write(ts->ts_out2, wbuf, opts) != opts) { + break; + } + } + + return (NULL); +} + +int +prepare_localtcp_once(tsd_t *ts) +{ + int j; + int opt = 1; + struct hostent *host; + + j = FIRSTPORT; + + ts->ts_lsn = socket(AF_INET, SOCK_STREAM, 0); + if (ts->ts_lsn == -1) { + return (-1); + } + + if (setsockopt(ts->ts_lsn, SOL_SOCKET, SO_REUSEADDR, + &opt, sizeof (int)) == -1) { + return (-1); + } + + if ((host = gethostbyname("localhost")) == NULL) { + return (-1); + } + + for (;;) { + (void) memset(&ts->ts_add, 0, + sizeof (struct sockaddr_in)); + ts->ts_add.sin_family = AF_INET; + ts->ts_add.sin_port = htons(j++); + (void) memcpy(&ts->ts_add.sin_addr.s_addr, + host->h_addr_list[0], sizeof (struct in_addr)); + + if (bind(ts->ts_lsn, + (struct sockaddr *)&ts->ts_add, + sizeof (struct sockaddr_in)) == 0) { + break; + } + + if (errno != EADDRINUSE) { + return (-1); + } + } + + if (listen(ts->ts_lsn, 5) == -1) { + return (-1); + } + + return (0); +} + +int +prepare_localtcp(tsd_t *ts) +{ + int result; + struct sockaddr_in addr; + int opt = 1; + socklen_t size; + + if (ts->ts_once++ == 0) { + if (prepare_localtcp_once(ts) == -1) { + return (-1); + } + } + + ts->ts_out = socket(AF_INET, SOCK_STREAM, 0); + if (ts->ts_out == -1) { + return (-1); + } + + if (fcntl(ts->ts_out, F_SETFL, O_NDELAY) == -1) { + return (-1); + } + + result = connect(ts->ts_out, (struct sockaddr *)&ts->ts_add, + sizeof (struct sockaddr_in)); + if ((result == -1) && (errno != EINPROGRESS)) { + return (-1); + } + + if (fcntl(ts->ts_out, F_SETFL, 0) == -1) { + return (-1); + } + + size = sizeof (struct sockaddr); + result = accept(ts->ts_lsn, (struct sockaddr *)&addr, &size); + if (result == -1) { + return (-1); + } + ts->ts_out2 = result; + + if (setsockopt(ts->ts_out, IPPROTO_TCP, TCP_NODELAY, + &opt, sizeof (int)) == -1) { + return (-1); + } + + if (setsockopt(ts->ts_out2, IPPROTO_TCP, TCP_NODELAY, + &opt, sizeof (int)) == -1) { + return (-1); + } + + if (optm == MD_SINGLE) { + ts->ts_in = ts->ts_out2; + } else { + ts->ts_in = ts->ts_out; + ts->ts_in2 = ts->ts_out2; + } + + return (0); +} + +int +prepare_socketpair(tsd_t *ts) +{ + int s[2]; + + if (socketpair(PF_UNIX, SOCK_STREAM, 0, s) == -1) { + return (-1); + } + + if (optm == MD_SINGLE) { + ts->ts_in = s[0]; + ts->ts_out = s[1]; + } else { + ts->ts_in = s[0]; + ts->ts_out = s[0]; + ts->ts_in2 = s[1]; + ts->ts_out2 = s[1]; + } + + return (0); +} + +int +prepare_fifos(tsd_t *ts) +{ + char path[64]; + + (void) sprintf(path, "/tmp/pipe_%ld.%dA", + getpid(), pthread_self()); + if (mknod(path, 0600, S_IFIFO) == -1) { + return (-1); + } + + if (optm == MD_SINGLE) { + ts->ts_in = open(path, O_RDONLY); + ts->ts_out = open(path, O_WRONLY); + } else { + ts->ts_in = open(path, O_RDONLY); + ts->ts_out2 = open(path, O_WRONLY); + + (void) sprintf(path, "/tmp/pipe_%ld.%dB", + getpid(), pthread_self()); + if (mknod(path, 0600, S_IFIFO) == -1) { + return (-1); + } + + ts->ts_in2 = open(path, O_RDONLY); + ts->ts_out = open(path, O_WRONLY); + } + + return (0); +} + +/*ARGSUSED*/ +int +cleanup_fifos(tsd_t *ts) +{ + char path[64]; + + (void) sprintf(path, "/tmp/pipe_%ld.%dA", getpid(), pthread_self()); + (void) unlink(path); + (void) sprintf(path, "/tmp/pipe_%ld.%dB", getpid(), pthread_self()); + (void) unlink(path); + + return (0); +} + +int +prepare_pipes(tsd_t *ts) +{ + int p[2]; + + if (optm == MD_SINGLE) { + if (pipe(p) == -1) { + return (-1); + } + ts->ts_in = p[0]; + ts->ts_out = p[1]; + + } else { + if (pipe(p) == -1) { + return (-1); + } + ts->ts_in = p[0]; + ts->ts_out2 = p[1]; + + if (pipe(p) == -1) { + return (-1); + } + ts->ts_in2 = p[0]; + ts->ts_out = p[1]; + } + + return (0); +} + +char * +lookupa(int x, char *names[]) +{ + int i = 0; + + while (names[i] != NULL) { + if (x == i) { + return (names[i]); + } + i++; + } + return (NULL); +} + +int +lookup(char *x, char *names[]) +{ + int i = 0; + + while (names[i] != NULL) { + if (strcmp(names[i], x) == 0) { + return (i); + } + i++; + } + return (-1); +} diff --git a/native/libMicro-0.4.0/poll.c b/native/libMicro-0.4.0/poll.c new file mode 100644 index 0000000..5ef1287 --- /dev/null +++ b/native/libMicro-0.4.0/poll.c @@ -0,0 +1,218 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define MIN(x, y) ((x) > (y) ? (y) : (x)) + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFN 256 + +static int optn = DEFN; +static int optr = 0; +static int optw = 0; +static int optx = 0; +static int *fds; +static int target = 0; + +typedef struct pollfd pfd_t; + +typedef struct { + int ts_once; + pfd_t *ts_pfds; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "n:r:w:x"); + + (void) sprintf(lm_usage, + " [-n fds-per-thread (default %d)]\n" + " [-r readable-fds (default 0)]\n" + " [-w writeable-fds (default 0)]\n" + " [-x] (start -r option with highest fd first; " + "default is lowest first)\n" + "notes: measures poll()\n", + DEFN); + + (void) sprintf(lm_header, "%8s %5s", "nfds", "flags"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'n': + optn = atoi(optarg); + break; + case 'r': + optr = atoi(optarg); + break; + case 'w': + optw = atoi(optarg); + break; + case 'x': + optx = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + int i; + int j; + int pair[2]; + + if (optn % 2 != 0) { + (void) printf("ERROR: -n value must be even\n"); + optn = optr = optw = 0; + return (-1); + } + + if (optn < 0 || optr < 0 || optw < 0) { + (void) printf("ERROR: -n, -r and -w values must be > 0\n"); + optn = optr = optw = 0; + return (-1); + } + + if (optr > optn || optw > optn) { + (void) printf("ERROR: -r and -w values must be <= maxfd\n"); + optn = optr = optw = 0; + return (-1); + } + + fds = (int *)malloc(optn * sizeof (int)); + if (fds == NULL) { + (void) printf("ERROR: malloc() failed\n"); + optn = optr = optw = 0; + return (-1); + } + + (void) setfdlimit(optn + 10); + + + for (i = 0; i < optn; i += 2) { + if (socketpair(PF_UNIX, SOCK_STREAM, 0, pair) == -1) { + (void) printf("ERROR: socketpair() failed\n"); + return (-1); + } + + fds[i] = MIN(pair[0], pair[1]); + fds[i+1] = MAX(pair[0], pair[1]); + } + + if (optx) { + target = MIN(optr + optw, optn); + for (i = 0, j = optn - 1; i < optr; i++, j--) { + (void) write(fds[j+1 - (2*(j%2))], "", 1); + } + } else { + target = MAX(optr, optw); + for (i = 0; i < optr; i++) { + (void) write(fds[i+1 - (2*(i%2))], "", 1); + } + } + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int errors = 0; + + if (ts->ts_once++ == 0) { + ts->ts_pfds = (pfd_t *)malloc(optn * sizeof (pfd_t)); + if (ts->ts_pfds == NULL) { + errors++; + } + + for (i = 0; i < optn; i++) { + ts->ts_pfds[i].fd = fds[i]; + ts->ts_pfds[i].events = POLLIN; + } + + for (i = 0; i < optw; i++) { + ts->ts_pfds[i].events |= POLLOUT; + } + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (poll(ts->ts_pfds, optn, 0) != target) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + char flags[4]; + + flags[0] = optr ? 'r' : '-'; + flags[1] = optw ? 'w' : '-'; + flags[2] = optx ? 'x' : '-'; + flags[3] = 0; + + (void) sprintf(result, "%8d %5s", optn, flags); + + return (result); +} diff --git a/native/libMicro-0.4.0/pread.c b/native/libMicro-0.4.0/pread.c new file mode 100644 index 0000000..51e15d9 --- /dev/null +++ b/native/libMicro-0.4.0/pread.c @@ -0,0 +1,142 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifdef linux +#define _XOPEN_SOURCE 500 +#endif + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + char *ts_buf; +} tsd_t; + +#define DEFF "/dev/zero" +#define DEFS 1024 + +static char *optf = DEFF; +static long long opts = DEFS; +static int optw = 0; +static int fd = -1; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "wf:s:"); + + (void) sprintf(lm_usage, + " [-f file-to-read (default %s)]\n" + " [-s buffer-size (default %d)]\n" + " [-w (write a byte to each page after read)]\n" + "notes: measures pread()\n", + DEFF, DEFS); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'w': + optw = getpagesize(); + break; + case 'f': + optf = optarg; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + fd = open(optf, O_RDONLY); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int errors = 0; + + if (ts->ts_buf == NULL) { + ts->ts_buf = malloc(opts); + } + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int j; + + for (i = 0; i < lm_optB; i++) { + if (pread(fd, ts->ts_buf, opts, 0) != opts) { + res->re_errors++; + } + if (optw) { + for (j = 0; j < opts; j += optw) + ts->ts_buf[j] = 0; + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8lld", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/pthread_create.c b/native/libMicro-0.4.0/pthread_create.c new file mode 100644 index 0000000..340d35c --- /dev/null +++ b/native/libMicro-0.4.0/pthread_create.c @@ -0,0 +1,160 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + pthread_t *ts_threads; + pthread_attr_t *ts_attr; + pthread_mutex_t ts_lock; +} tsd_t; + +static int opts = 0; + +int +benchmark_init() +{ + lm_defN = "pthread"; + + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_usage, + " [-s stacksize] (specify stacksize)\n" + "notes: measures pthread_create\n"); + + (void) sprintf(lm_optstr, "s:"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + + return (0); +} + +int +benchmark_initworker(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int errors = 0; + + ts->ts_threads = calloc(lm_optB, sizeof (pthread_t)); + (void) pthread_mutex_init(&ts->ts_lock, NULL); + + if (opts) { + ts->ts_attr = malloc(sizeof (pthread_attr_t)); + (void) pthread_attr_init(ts->ts_attr); + if ((errors = pthread_attr_setstacksize(ts->ts_attr, opts)) + != 0) { + errno = errors; + perror("pthread_attr_setstacksize"); + } + } else + ts->ts_attr = NULL; + + return (errors?1:0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + (void) pthread_mutex_lock(&ts->ts_lock); + + return (0); +} + + +void * +func(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + (void) pthread_mutex_lock(&ts->ts_lock); + (void) pthread_mutex_unlock(&ts->ts_lock); + + return (tsd); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + int error; + + for (i = 0; i < lm_optB; i++) { + if ((error = pthread_create(ts->ts_threads + i, + ts->ts_attr, func, tsd)) != 0) { + errno = error; + perror("pthread_create"); + ts->ts_threads[i] = 0; + res->re_errors++; + return (0); + } + } + res->re_count = lm_optB; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int errors = 0; + + (void) pthread_mutex_unlock(&ts->ts_lock); + + for (i = 0; i < lm_optB; i++) + if (ts->ts_threads[i] == 0 || + pthread_join(ts->ts_threads[i], NULL) < 0) { + errors++; + } + return (errors); +} diff --git a/native/libMicro-0.4.0/pwrite.c b/native/libMicro-0.4.0/pwrite.c new file mode 100644 index 0000000..ab1374c --- /dev/null +++ b/native/libMicro-0.4.0/pwrite.c @@ -0,0 +1,154 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifdef linux +#define _XOPEN_SOURCE 500 +#endif + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + char *ts_buf; +} tsd_t; + +#define DEFF "/dev/null" +#define DEFS 1024 + +static int optc = 0; +static char *optf = DEFF; +static long long opts = DEFS; +static int fd = -1; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "cf:s:"); + + (void) sprintf(lm_usage, + " [-f file-to-write (default %s)]\n" + " [-s buffer-size (default %d)]\n" + " [-c ] (make sure buffer is in cache)\n" + "notes: measures pwrite()\n", + DEFF, DEFS); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'c': + optc++; + break; + case 'f': + optf = optarg; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + fd = open(optf, O_WRONLY); + if (fd == -1) { + return (-1); + } + + return (0); +} + +int +benchmark_finirun() +{ + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + if (ts->ts_buf == NULL) { + ts->ts_buf = malloc(opts); + + /* + * bring buf into cache if specified. + */ + + if (optc) + for (i = 0; i < opts; i++) + ts->ts_buf[i] = 0; + } + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (pwrite(fd, ts->ts_buf, opts, 0) != opts) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8lld", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/read.c b/native/libMicro-0.4.0/read.c new file mode 100644 index 0000000..32faf05 --- /dev/null +++ b/native/libMicro-0.4.0/read.c @@ -0,0 +1,143 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#ifdef linux +#define _XOPEN_SOURCE 500 +#endif + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + char *ts_buf; + int ts_fd; +} tsd_t; + +#define DEFF "/dev/zero" +#define DEFS 1024 + +static char *optf = DEFF; +static long long opts = DEFS; +int optw = 0; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "f:s:w"); + + (void) sprintf(lm_usage, + " [-f file-to-read (default %s)]\n" + " [-s buffer-size (default %d)]\n" + " [-w (store a byte to each page after read)]\n" + "notes: measures read()\n", + DEFF, DEFS); + + (void) sprintf(lm_header, "%8s", "size"); + + lm_defB = 1; + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'w': + optw = getpagesize(); + break; + case 'f': + optf = optarg; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + if (ts->ts_buf == NULL) { + ts->ts_buf = malloc(opts); + ts->ts_fd = open(optf, O_RDONLY); + } + + (void) lseek(ts->ts_fd, 0, SEEK_SET); + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int j; + for (i = 0; i < lm_optB; i++) { + if (read(ts->ts_fd, ts->ts_buf, opts) != opts) { + res->re_errors++; + } + if (optw) + for (j = 0; j < opts; j += optw) + ts->ts_buf[j] = 0; + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8lld", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/realpath.c b/native/libMicro-0.4.0/realpath.c new file mode 100644 index 0000000..540ebf7 --- /dev/null +++ b/native/libMicro-0.4.0/realpath.c @@ -0,0 +1,85 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#include +#include +#include + +#include "libmicro.h" + +#define DEFF "/" +#define MAXPATHLEN 1024 + +static char *optf = DEFF; + +int +benchmark_init() +{ + (void) sprintf(lm_optstr, "f:"); + + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + " [-f directory (default = %s)]\n" + "notes: measures realpath()\n", + DEFF); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + default: + return (-1); + } + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + char path[MAXPATHLEN]; + + for (i = 0; i < lm_optB; i++) { + if (realpath(optf, path) == NULL) + res->re_errors++; + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/recurse.c b/native/libMicro-0.4.0/recurse.c new file mode 100644 index 0000000..fe0930c --- /dev/null +++ b/native/libMicro-0.4.0/recurse.c @@ -0,0 +1,110 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFD 100 + +static int optd = DEFD; + +int recurse2(int x, int y, char *s); + +/*ARGSUSED*/ +int +recurse1(int x, int y, char *s) +{ + char str[32]; + + if (x < y) { + return (recurse2(x + 1, y, str)); + } + + return (x); +} + +int +recurse2(int x, int y, char *s) +{ + char str[32]; + + if (x < y) { + return (recurse1(x + 1, y, str)); + } + + return (x); +} + +int +benchmark_init() +{ + lm_tsdsize = 0; + + (void) sprintf(lm_optstr, "d:"); + + (void) sprintf(lm_usage, + " [-d depth-limit (default = %d)]\n" + "notes: measures recursion performance\n", + DEFD); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'd': + optd = atoi(optarg); + break; + default: + return (-1); + } + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i++) { + (void) recurse1(0, optd, NULL); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/recurse2.c b/native/libMicro-0.4.0/recurse2.c new file mode 100644 index 0000000..9f22890 --- /dev/null +++ b/native/libMicro-0.4.0/recurse2.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include + +int recurse1(int x, int y, char *s); + +/*ARGSUSED*/ +int +recurse2(int x, int y, char *s) +{ + char str[32]; + + if (x < y) { + return (recurse1(x + 1, y, str)); + } + + return (x); +} diff --git a/native/libMicro-0.4.0/select.c b/native/libMicro-0.4.0/select.c new file mode 100644 index 0000000..5edc37e --- /dev/null +++ b/native/libMicro-0.4.0/select.c @@ -0,0 +1,214 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define MIN(x, y) ((x) > (y) ? (y) : (x)) + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFN 256 + +static int optn = DEFN; +static int optr = 0; +static int optw = 0; +static int optx = 0; +static int *fds; +static fd_set iset; +static fd_set oset; +static int maxfd = 0; +static int target = 0; + +int +benchmark_init() +{ + (void) sprintf(lm_optstr, "n:r:w:x"); + + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + " [-n fds-per-thread (default %d)]\n" + " [-r readable-fds (default 0)]\n" + " [-w writeable-fds (default 0)]\n" + " [-x] (start -r option with highest fd first; " + "default is lowest first)\n" + "notes: measures select()\n", + DEFN); + + (void) sprintf(lm_header, "%8s %5s", "maxfd", "flags"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'n': + optn = atoi(optarg); + break; + case 'r': + optr = atoi(optarg); + break; + case 'w': + optw = atoi(optarg); + break; + case 'x': + optx = 1; + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initrun() +{ + int i; + int j; + int pair[2]; + + if (optn % 2 != 0) { + (void) printf("ERROR: -n value must be even\n"); + optn = optr = optw = 0; + return (-1); + } + + if (optn < 0 || optr < 0 || optw < 0) { + (void) printf("ERROR: -n, -r and -w values must be > 0\n"); + optn = optr = optw = 0; + return (-1); + } + + if (optr > optn || optw > optn) { + (void) printf("ERROR: -r and -w values must be <= maxfd\n"); + optn = optr = optw = 0; + return (-1); + } + + fds = (int *)malloc(optn * sizeof (int)); + if (fds == NULL) { + (void) printf("ERROR: malloc() failed\n"); + optn = optr = optw = 0; + return (-1); + } + + (void) setfdlimit(optn + 10); + + target = optr + optw; + + FD_ZERO(&iset); + FD_ZERO(&oset); + + for (i = 0; i < optn; i += 2) { + if (socketpair(PF_UNIX, SOCK_STREAM, 0, pair) == -1) { + (void) printf("ERROR: socketpair() failed\n"); + return (-1); + } + + fds[i] = MIN(pair[0], pair[1]); + fds[i+1] = MAX(pair[0], pair[1]); + maxfd = fds[i+1] + 1; + + if (maxfd > FD_SETSIZE) { + (void) printf("WARNING: FD_SETSIZE is too small!\n"); + return (-1); + } + + FD_SET(fds[i], &iset); + FD_SET(fds[i+1], &iset); + } + + for (i = 0; i < optw; i++) { + FD_SET(fds[i], &oset); + } + if (optx) { + for (i = 0, j = optn - 1; i < optr; i++, j--) { + (void) write(fds[j+1 - (2*(j%2))], "", 1); + } + } else { + for (i = 0; i < optr; i++) { + (void) write(fds[i+1 - (2*(i%2))], "", 1); + } + } + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + fd_set set1; + fd_set set2; + fd_set *my_iset = &set1; + fd_set *my_oset = NULL; + struct timeval tv = {0, 0}; + + if (optw) { + my_oset = &set2; + } + + for (i = 0; i < lm_optB; i++) { + (void) memcpy(&set1, &iset, sizeof (fd_set)); + (void) memcpy(&set2, &oset, sizeof (fd_set)); + + if (select(maxfd, my_iset, my_oset, NULL, &tv) != target) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + char flags[4]; + + flags[0] = optr ? 'r' : '-'; + flags[1] = optw ? 'w' : '-'; + flags[2] = optx ? 'x' : '-'; + flags[3] = 0; + + (void) sprintf(result, "%8d %5s", optn, flags); + + return (result); +} diff --git a/native/libMicro-0.4.0/semop.c b/native/libMicro-0.4.0/semop.c new file mode 100644 index 0000000..9953a79 --- /dev/null +++ b/native/libMicro-0.4.0/semop.c @@ -0,0 +1,103 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + + +typedef struct { + int ts_semid; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_usage, "notes: measures semop()\n"); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + + tsd_t *ts = (tsd_t *)tsd; + + if ((ts->ts_semid = semget(IPC_PRIVATE, 2, 0600)) == -1) { + return (-1); + } + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + (void) semctl(ts->ts_semid, 0, IPC_RMID); + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + struct sembuf s[1]; + + for (i = 0; i < lm_optB; i++) { + s[0].sem_num = 0; + s[0].sem_op = 1; + s[0].sem_flg = 0; + if (semop(ts->ts_semid, s, 1) == -1) { + res->re_errors++; + } + s[0].sem_num = 0; + s[0].sem_op = -1; + s[0].sem_flg = 0; + if (semop(ts->ts_semid, s, 1) == -1) { + res->re_errors++; + } + } + + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/setcontext.c b/native/libMicro-0.4.0/setcontext.c new file mode 100644 index 0000000..dad2849 --- /dev/null +++ b/native/libMicro-0.4.0/setcontext.c @@ -0,0 +1,67 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + + (void) sprintf(lm_usage, "notes: measures setcontext()\n"); + + lm_tsdsize = 0; + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + volatile int i; + + ucontext_t uc; + + i = 0; + + (void) getcontext(&uc); + + if (i++ < lm_optB) + (void) setcontext(&uc); + + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/setsockopt.c b/native/libMicro-0.4.0/setsockopt.c new file mode 100644 index 0000000..c48672e --- /dev/null +++ b/native/libMicro-0.4.0/setsockopt.c @@ -0,0 +1,99 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_fd; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_usage, "setsockopt(TCP_NODELAY)\n"); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + + tsd_t *ts = (tsd_t *)tsd; + + if ((ts->ts_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) + return (1); + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + (void) close(ts->ts_fd); + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + int opt; + + res->re_errors = 0; + + for (i = 0; i < lm_optB; i++) { + opt = 1 & i; + if (setsockopt(ts->ts_fd, IPPROTO_TCP, TCP_NODELAY, + &opt, sizeof (int)) == -1) { + res->re_errors ++; + } + } + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/sigaction.c b/native/libMicro-0.4.0/sigaction.c new file mode 100644 index 0000000..b0053b3 --- /dev/null +++ b/native/libMicro-0.4.0/sigaction.c @@ -0,0 +1,95 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#ifdef __sun +static void +nop() +{ +} +#else +static void +nop(int sig) +{ +} +#endif + + +typedef struct { + struct sigaction ts_act; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_usage, "notes: measures sigaction()\n"); + + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + + tsd_t *ts = (tsd_t *)tsd; + ts->ts_act.sa_handler = nop; + ts->ts_act.sa_flags = 0; + (void) sigemptyset(&ts->ts_act.sa_mask); + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + struct sigaction oact; + + res->re_errors = 0; + + for (i = 0; i < lm_optB; i++) { + if (sigaction(SIGUSR1, &ts->ts_act, &oact)) + res->re_errors++; + } + + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/siglongjmp.c b/native/libMicro-0.4.0/siglongjmp.c new file mode 100644 index 0000000..b4dfd16 --- /dev/null +++ b/native/libMicro-0.4.0/siglongjmp.c @@ -0,0 +1,69 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + jmp_buf ts_env; +} tsd_t; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + lm_tsdsize = 0; + + (void) sprintf(lm_usage, "notes: measures siglongjmp()\n"); + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + + int i = 0; + + (void) sigsetjmp(ts->ts_env, 1); + + if (i++ < lm_optB) + siglongjmp(ts->ts_env, 0); + + res->re_count = lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/signal.c b/native/libMicro-0.4.0/signal.c new file mode 100644 index 0000000..f172905 --- /dev/null +++ b/native/libMicro-0.4.0/signal.c @@ -0,0 +1,100 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + + +#ifdef __sun +static void +nop() +{ +} +#else +static void +nop(int sig) +{ +} +#endif + +int +benchmark_init() +{ + lm_tsdsize = 0; + + (void) sprintf(lm_usage, "notes: measures signal()\n"); + + return (0); +} + +int +benchmark_initrun() +{ + struct sigaction act; + + act.sa_handler = nop; + act.sa_flags = 0; + + (void) sigemptyset(&act.sa_mask); + (void) sigaction(SIGUSR1, &act, NULL); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + int pid; + + pid = getpid(); + + for (i = 0; i < lm_optB; i += 10) { + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + (void) kill(pid, SIGUSR1); + } + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/sigprocmask.c b/native/libMicro-0.4.0/sigprocmask.c new file mode 100644 index 0000000..de89b46 --- /dev/null +++ b/native/libMicro-0.4.0/sigprocmask.c @@ -0,0 +1,84 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + lm_tsdsize = 0; + + (void) sprintf(lm_usage, "notes: measures sigprocmask()\n"); + + return (0); +} + +int +benchmark_initrun() +{ + sigset_t iset; + + (void) sigemptyset(&iset); + (void) sigprocmask(SIG_SETMASK, &iset, NULL); + + return (0); +} +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + sigset_t set0, set1; + + (void) sigemptyset(&set0); + (void) sigaddset(&set0, SIGTERM); + + for (i = 0; i < lm_optB; i += 10) { + (void) sigprocmask(SIG_SETMASK, &set0, &set1); + (void) sigprocmask(SIG_SETMASK, &set1, &set0); + (void) sigprocmask(SIG_SETMASK, &set0, &set1); + (void) sigprocmask(SIG_SETMASK, &set1, &set0); + (void) sigprocmask(SIG_SETMASK, &set0, &set1); + (void) sigprocmask(SIG_SETMASK, &set1, &set0); + (void) sigprocmask(SIG_SETMASK, &set0, &set1); + (void) sigprocmask(SIG_SETMASK, &set1, &set0); + (void) sigprocmask(SIG_SETMASK, &set0, &set1); + (void) sigprocmask(SIG_SETMASK, &set1, &set0); + } + + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/socket.c b/native/libMicro-0.4.0/socket.c new file mode 100644 index 0000000..496966d --- /dev/null +++ b/native/libMicro-0.4.0/socket.c @@ -0,0 +1,157 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + int *ts_fds; +} tsd_t; + +#define DEFF "PF_UNIX" + +static char *optf = DEFF; +static int family; + +int +lookup_family(char *name) +{ + if (strcmp("PF_UNIX", name) == 0) { + return (PF_UNIX); + } else if (strcmp("PF_INET", name) == 0) { + return (PF_INET); + } else if (strcmp("PF_INET6", name) == 0) { + return (PF_INET6); + } + + return (-1); +} + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + lm_defB = 256; + + (void) sprintf(lm_optstr, "f:n"); + + (void) sprintf(lm_usage, + " [-f socket-family (default %s)]\n" + "notes: measures socket\n", + DEFF); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + default: + return (-1); + } + + return (0); +} + + +int +benchmark_initrun() +{ + (void) setfdlimit(lm_optB * lm_optT + 10); + family = lookup_family(optf); + + return (0); +} + +int +benchmark_finirun() +{ + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + if (ts->ts_once++ == 0) { + ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_fds == NULL) { + return (1); + } + for (i = 0; i < lm_optB; i++) { + ts->ts_fds[i] = -1; + } + } + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + for (i = 0; i < lm_optB; i++) { + ts->ts_fds[i] = socket(family, SOCK_STREAM, 0); + if (ts->ts_fds[i] == -1) { + res->re_errors++; + } + } + res->re_count += lm_optB; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + for (i = 0; i < lm_optB; i++) { + (void) close(ts->ts_fds[i]); + } + + return (0); +} diff --git a/native/libMicro-0.4.0/socketpair.c b/native/libMicro-0.4.0/socketpair.c new file mode 100644 index 0000000..ce880ce --- /dev/null +++ b/native/libMicro-0.4.0/socketpair.c @@ -0,0 +1,118 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + int ts_once; + int *ts_fds; +} tsd_t; + +#define DEFN 256 + + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + lm_defB = 256; + + (void) sprintf(lm_usage, + "notes: measures socketpair\n"); + + return (0); +} + + +int +benchmark_initrun() +{ + (void) setfdlimit(lm_optB * lm_optT + 10); + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + if (ts->ts_once++ == 0) { + ts->ts_fds = (int *)malloc(lm_optB * sizeof (int)); + if (ts->ts_fds == NULL) { + return (1); + } + for (i = 0; i < lm_optB; i++) { + ts->ts_fds[i] = -1; + } + } + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + res->re_count = 0; + res->re_errors = 0; + + for (i = 0; i < lm_optB; i += 2) { + if (socketpair(PF_UNIX, SOCK_STREAM, 0, &ts->ts_fds[i]) + == -1) { + res->re_errors++; + } + } + res->re_count = lm_optB / 2; + + return (0); +} + +int +benchmark_finibatch(void *tsd) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + for (i = 0; i < lm_optB; i++) { + (void) close(ts->ts_fds[i]); + } + + return (0); +} diff --git a/native/libMicro-0.4.0/stat.c b/native/libMicro-0.4.0/stat.c new file mode 100644 index 0000000..cffccee --- /dev/null +++ b/native/libMicro-0.4.0/stat.c @@ -0,0 +1,88 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFF "/dev/null" +static char *optf = DEFF; + +int +benchmark_init() +{ + + (void) sprintf(lm_optstr, "f:"); + + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + " [-f file-to-stat (default %s)]\n" + "notes: measures stat()\n", + DEFF); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + default: + return (-1); + } + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + struct stat sbuf; + + res->re_errors = 0; + + for (i = 0; i < lm_optB; i++) { + if (stat(optf, &sbuf) == -1) + res->re_errors++; + } + + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/strcasecmp.c b/native/libMicro-0.4.0/strcasecmp.c new file mode 100644 index 0000000..edb50af --- /dev/null +++ b/native/libMicro-0.4.0/strcasecmp.c @@ -0,0 +1,150 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + + +static int unaligned = 0; +static int opts = 100; + +typedef struct { + int ts_once; + char *ts_a; + char *ts_b; + int ts_fakegcc; +} tsd_t; + +int +benchmark_init() +{ + + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s:n"); + + (void) sprintf(lm_usage, + " [-s string size (default %d)]\n" + " [-n causes unaligned cmp]\n" + "notes: measures strcasecmp()\n", + opts); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'n': + unaligned = 1; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + static char *demo = + "The quick brown fox jumps over the lazy dog."; + + if (ts->ts_once++ == 0) { + int l = strlen(demo); + int i; + + ts->ts_a = malloc(opts + 1); + ts->ts_b = malloc(opts + 1 + unaligned); + ts->ts_b += unaligned; + + for (i = 0; i < opts; i++) { + ts->ts_a[i] = ts->ts_b[i] = demo[i%l]; + } + ts->ts_a[opts] = 0; + ts->ts_b[opts] = 0; + } + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + char *src = ts->ts_a; + char *src2 = ts->ts_b; + int *sum = &ts->ts_fakegcc; + + res->re_errors = 0; + + for (i = 0; i < lm_optB; i += 10) { + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + *sum += strcasecmp(src, src2); + } + + res->re_count = lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + if (unaligned == 0) + (void) sprintf(result, "%8d", opts); + else + (void) sprintf(result, "%8d ", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/strchr.c b/native/libMicro-0.4.0/strchr.c new file mode 100644 index 0000000..d3050e8 --- /dev/null +++ b/native/libMicro-0.4.0/strchr.c @@ -0,0 +1,144 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +static int unaligned = 0; +static int opts = 100; + +typedef struct { + int ts_once; + char *ts_string; + char *ts_fakegcc; +} tsd_t; + +int +benchmark_init() +{ + + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s:n"); + + (void) sprintf(lm_usage, + " [-s string size (default %d)]\n" + " [-n causes unaligned strchr]\n" + "notes: measures strchr()\n", + opts); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'n': + unaligned = 1; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + static char *demo = + "The quick brown fox jumps over the lazy dog."; + + if (ts->ts_once++ == 0) { + int l = strlen(demo); + int i; + + ts->ts_string = malloc(opts + 1 + unaligned); + ts->ts_string += unaligned; + + + for (i = 0; i < opts; i++) { + ts->ts_string[i] = demo[i%l]; + } + + ts->ts_string[opts] = 0; + + } + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + char *src = ts->ts_string; + + for (i = 0; i < lm_optB; i += 10) { + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + ts->ts_fakegcc = strchr(src, 'X'); + } + + res->re_count = lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + if (unaligned == 0) + (void) sprintf(result, "%8d", opts); + else + (void) sprintf(result, "%8d ", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/strcmp.c b/native/libMicro-0.4.0/strcmp.c new file mode 100644 index 0000000..8f40a87 --- /dev/null +++ b/native/libMicro-0.4.0/strcmp.c @@ -0,0 +1,147 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +static int unaligned = 0; +static int opts = 100; + +typedef struct { + int ts_once; + char *ts_a; + char *ts_b; + int ts_fakegcc; +} tsd_t; + +int +benchmark_init() +{ + + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s:n"); + + (void) sprintf(lm_usage, + " [-s string size (default %d)]\n" + " [-n causes unaligned cmp]\n" + "notes: measures strcmp()\n", + opts); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'n': + unaligned = 1; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + static char *demo = + "The quick brown fox jumps over the lazy dog."; + + if (ts->ts_once++ == 0) { + int l = strlen(demo); + int i; + + ts->ts_a = malloc(opts + 1); + ts->ts_b = malloc(opts + 1 + unaligned); + ts->ts_b += unaligned; + + for (i = 0; i < opts; i++) { + ts->ts_a[i] = ts->ts_b[i] = demo[i%l]; + } + ts->ts_a[opts] = 0; + ts->ts_b[opts] = 0; + } + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + int *sum = &ts->ts_fakegcc; + char *src = ts->ts_a; + char *src2 = ts->ts_b; + + res->re_errors = 0; + + for (i = 0; i < lm_optB; i += 10) { + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + *sum += strcmp(src, src2); + } + + res->re_count = lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + if (unaligned == 0) + (void) sprintf(result, "%8d", opts); + else + (void) sprintf(result, "%8d ", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/strcpy.c b/native/libMicro-0.4.0/strcpy.c new file mode 100644 index 0000000..7c1d479 --- /dev/null +++ b/native/libMicro-0.4.0/strcpy.c @@ -0,0 +1,145 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +static int unaligned = 0; +static int opts = 100; + +typedef struct { + int ts_once; + char *ts_a; + char *ts_b; +} tsd_t; + +int +benchmark_init() +{ + + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s:n"); + + (void) sprintf(lm_usage, + " [-s string size (default %d)]\n" + " [-n causes unaligned cmp]\n" + "notes: measures strcpy()\n", + opts); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'n': + unaligned = 1; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + static char *demo = + "The quick brown fox jumps over the lazy dog."; + + if (ts->ts_once++ == 0) { + int l = strlen(demo); + int i; + + ts->ts_a = malloc(opts + 1); + ts->ts_b = malloc(opts + 1 + unaligned); + ts->ts_b += unaligned; + + for (i = 0; i < opts; i++) { + ts->ts_b[i] = demo[i%l]; + } + ts->ts_b[opts] = 0; + } + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + + char *src = ts->ts_a; + char *src2 = ts->ts_b; + + res->re_errors = 0; + + for (i = 0; i < lm_optB; i += 10) { + (void) strcpy(src, src2); + (void) strcpy(src, src2); + (void) strcpy(src, src2); + (void) strcpy(src, src2); + (void) strcpy(src, src2); + (void) strcpy(src, src2); + (void) strcpy(src, src2); + (void) strcpy(src, src2); + (void) strcpy(src, src2); + (void) strcpy(src, src2); + } + + res->re_count = lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + if (unaligned == 0) + (void) sprintf(result, "%8d", opts); + else + (void) sprintf(result, "%8d ", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/strftime.c b/native/libMicro-0.4.0/strftime.c new file mode 100644 index 0000000..3aeca1c --- /dev/null +++ b/native/libMicro-0.4.0/strftime.c @@ -0,0 +1,129 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +#define DEFF "%c" +#define MAXSIZE 80 + +static char *optf = DEFF; + +typedef struct { + int ts_once; + struct tm ts_tm1; + struct tm ts_tm2; +} tsd_t; + +int +benchmark_init() +{ + + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "f:"); + + (void) sprintf(lm_usage, + " [-f format (default = \"%s\")]\n" + "notes: measures strftime()\n", + DEFF); + + (void) sprintf(lm_header, "%8s", "format"); + + return (0); +} +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + + case 'f': + optf = optarg; + break; + default: + return (-1); + } + return (0); +} + + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8s", optf); + + return (result); +} + + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + + static time_t clock1 = 0L; + static time_t clock2 = 1L; + + (void) localtime_r(&clock1, &ts->ts_tm1); + (void) localtime_r(&clock2, &ts->ts_tm2); + + return (0); +} + + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + char s[MAXSIZE]; + + for (i = 0; i < lm_optB; i += 10) { + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1); + (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2); + } + res->re_count = lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/strlen.c b/native/libMicro-0.4.0/strlen.c new file mode 100644 index 0000000..5806c61 --- /dev/null +++ b/native/libMicro-0.4.0/strlen.c @@ -0,0 +1,143 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +static int unaligned = 0; +static int opts = 100; + +typedef struct { + int ts_once; + char *ts_string; + int ts_fakegcc; +} tsd_t; + +int +benchmark_init() +{ + + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "s:n"); + + (void) sprintf(lm_usage, + " [-s string size (default %d)]\n" + " [-n causes unaligned strlen]\n" + "notes: measures strlen()\n", + opts); + + (void) sprintf(lm_header, "%8s", "size"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'n': + unaligned = 1; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + static char *demo = + "The quick brown fox jumps over the lazy dog."; + + if (ts->ts_once++ == 0) { + int l = strlen(demo); + int i; + + ts->ts_string = malloc(opts + 1 + unaligned); + ts->ts_string += unaligned; + + + for (i = 0; i < opts; i++) { + ts->ts_string[i] = demo[i%l]; + } + + ts->ts_string[opts] = 0; + + } + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + int i; + tsd_t *ts = (tsd_t *)tsd; + char *src = ts->ts_string; + + for (i = 0; i < lm_optB; i += 10) { + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + ts->ts_fakegcc += strlen(src); + } + + res->re_count = lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + if (unaligned == 0) + (void) sprintf(result, "%8d", opts); + else + (void) sprintf(result, "%8d ", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/strtol.c b/native/libMicro-0.4.0/strtol.c new file mode 100644 index 0000000..02f8abc --- /dev/null +++ b/native/libMicro-0.4.0/strtol.c @@ -0,0 +1,67 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + (void) sprintf(lm_usage, "note: measures strtol()"); + lm_tsdsize = 0; + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i += 10) { + (void) strtol("1", NULL, 10); + (void) strtol("11", NULL, 10); + (void) strtol("123", NULL, 10); + (void) strtol("1234", NULL, 10); + (void) strtol("12345", NULL, 10); + (void) strtol("123456", NULL, 10); + (void) strtol("1234567", NULL, 10); + (void) strtol("12345678", NULL, 10); + (void) strtol("123456789", NULL, 10); + (void) strtol("1234567890", NULL, 10); + } + res->re_count = i; + + return (0); +} diff --git a/native/libMicro-0.4.0/system.c b/native/libMicro-0.4.0/system.c new file mode 100644 index 0000000..d70db26 --- /dev/null +++ b/native/libMicro-0.4.0/system.c @@ -0,0 +1,98 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include + +#include "libmicro.h" + +#define DEFB 10 +#define DEFC "A=$$" + +static char *optc = DEFC; + +int +benchmark_init() +{ + lm_tsdsize = 0; + + (void) sprintf(lm_optstr, "c:"); + + (void) sprintf(lm_usage, + " [-c command (default %s)]\n" + "notes: measures system()\n", + DEFC); + + (void) sprintf(lm_header, "%8s", "command"); + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'c': + optc = optarg; + break; + default: + return (-1); + } + + return (0); +} + + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i++) { + if (system(optc) != 0) { + res->re_errors++; + } + } + res->re_count = lm_optB; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8s", optc); + + return (result); +} diff --git a/native/libMicro-0.4.0/tattle.c b/native/libMicro-0.4.0/tattle.c new file mode 100644 index 0000000..59520f8 --- /dev/null +++ b/native/libMicro-0.4.0/tattle.c @@ -0,0 +1,154 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "libmicro.h" +#include + + +#ifdef USE_RDTSC +#ifdef __GNUC__ +#define ENABLE_RDTSC 1 +#endif +#endif + +/* + * dummy so we can link w/ libmicro + */ + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + return (0); +} + +static void +cleanup(char *s) +{ + char *o = s; + char *e; + + while (*s == ' ') + s++; + + if (o != s) + (void) strcpy(o, s); + + e = o; + + while (*e != 0) + e++; + + e--; + + while (*e == ' ' && e > o) + *e-- = 0; + +} + + +int +main(int argc, char *argv[]) +{ + int c; + + if (strlen(compiler_version) > 30) + compiler_version[30] = 0; + + cleanup(compiler_version); + cleanup(extra_compiler_flags); + + while ((c = getopt(argc, argv, "vcfrsVTR")) != -1) { + switch (c) { + case 'V': + (void) printf("%s\n", LIBMICRO_VERSION); + break; + case 'v': + (void) printf("%s\n", compiler_version); + break; + case 'c': + (void) printf("%s\n", CC); + break; + case 'f': + if (strlen(extra_compiler_flags) == 0) + (void) printf("[none]\n"); + else + (void) printf("%s\n", extra_compiler_flags); + break; + + case 's': + (void) printf("%d\n", sizeof (long)); + break; + + case 'r': + + (void) printf("%lld nsecs\n", get_nsecs_resolution()); + break; + + case 'R': +#ifdef ENABLE_RDTSC + { + struct timeval s; + struct timeval f; + long long start_nsecs; + long long end_nsecs; + long elapsed_usecs; + + gettimeofday(&s, NULL); + start_nsecs = rdtsc(); + for (;;) { + gettimeofday(&f, NULL); + elapsed_usecs = (f.tv_sec - s.tv_sec) * + 1000000 + (f.tv_usec - s.tv_usec); + if (elapsed_usecs > 1000000) + break; + } + end_nsecs = rdtsc(); + (void) printf("LIBMICRO_HZ=%lld\n", + (long long)elapsed_usecs * + (end_nsecs - start_nsecs) / 1000000LL); + } +#else + (void) printf("\n"); +#endif + break; + } + } + + exit(0); + return (0); +} diff --git a/native/libMicro-0.4.0/time.c b/native/libMicro-0.4.0/time.c new file mode 100644 index 0000000..d4d0fa8 --- /dev/null +++ b/native/libMicro-0.4.0/time.c @@ -0,0 +1,69 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + "notes: measures time()\n"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + + for (i = 0; i < lm_optB; i += 10) { + (void) time(NULL); + (void) time(NULL); + (void) time(NULL); + (void) time(NULL); + (void) time(NULL); + (void) time(NULL); + (void) time(NULL); + (void) time(NULL); + (void) time(NULL); + (void) time(NULL); + } + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/times.c b/native/libMicro-0.4.0/times.c new file mode 100644 index 0000000..6dc7515 --- /dev/null +++ b/native/libMicro-0.4.0/times.c @@ -0,0 +1,73 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include + +#include "libmicro.h" + +int +benchmark_init() +{ + + lm_tsdsize = 0; + + (void) sprintf(lm_usage, + "notes: measures times()\n"); + + return (0); +} + +/*ARGSUSED*/ +int +benchmark(void *tsd, result_t *res) +{ + int i; + struct tms buf; + + for (i = 0; i < lm_optB; i += 10) { + (void) times(&buf); + (void) times(&buf); + (void) times(&buf); + (void) times(&buf); + (void) times(&buf); + (void) times(&buf); + (void) times(&buf); + (void) times(&buf); + (void) times(&buf); + (void) times(&buf); + } + res->re_count += lm_optB; + + return (0); +} diff --git a/native/libMicro-0.4.0/wrapper.sh b/native/libMicro-0.4.0/wrapper.sh new file mode 100644 index 0000000..791643d --- /dev/null +++ b/native/libMicro-0.4.0/wrapper.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms +# of the Common Development and Distribution License +# (the "License"). You may not use this file except +# in compliance with the License. +# +# You can obtain a copy of the license at +# src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing +# permissions and limitations under the License. +# +# When distributing Covered Code, include this CDDL +# HEADER in each file and include the License file at +# usr/src/OPENSOLARIS.LICENSE. If applicable, +# add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your +# own identifying information: Portions Copyright [yyyy] +# [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + + +BASENAME=`basename $0` +DIRNAME=`dirname $0` +ARCH=`uname -m` + +exec $DIRNAME/../bin-$ARCH/$BASENAME "$@" diff --git a/native/libMicro-0.4.0/write.c b/native/libMicro-0.4.0/write.c new file mode 100644 index 0000000..0780274 --- /dev/null +++ b/native/libMicro-0.4.0/write.c @@ -0,0 +1,154 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifdef linux +#define _XOPEN_SOURCE 500 +#endif + +#include +#include +#include +#include + +#include "libmicro.h" + +typedef struct { + char *ts_buf; + int ts_fd; +} tsd_t; + +#define DEFF "/dev/null" +#define DEFS 1024 + +static int optc = 0; +static char *optf = DEFF; +static long long opts = DEFS; +static int optd; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "cdf:s:"); + + (void) sprintf(lm_usage, + " [-f file-to-write (default %s)]\n" + " [-s buffer-size (default %d)]\n" + " [-c ] (make sure buffer is in cache)\n" +#ifdef __sun + " [-d ] use directio" +#endif + "notes: measures write()\n", + DEFF, DEFS); + + (void) sprintf(lm_header, "%8s", "size"); + + lm_defB = 1; + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + + case 'd': + optd++; + break; + case 'c': + optc++; + break; + case 'f': + optf = optarg; + break; + case 's': + opts = sizetoll(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + if (ts->ts_buf == NULL) { + ts->ts_buf = malloc(opts); + ts->ts_fd = open(optf, O_WRONLY); + +#ifdef __sun + if (optd) + (void) directio(ts->ts_fd, DIRECTIO_ON); +#endif + /* + * bring buf into cache if specified. + */ + + if (optc) + for (i = 0; i < opts; i++) + ts->ts_buf[i] = 0; + } + + (void) lseek(ts->ts_fd, 0, SEEK_SET); + + return (0); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (write(ts->ts_fd, ts->ts_buf, opts) != opts) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8lld", opts); + + return (result); +} diff --git a/native/libMicro-0.4.0/writev.c b/native/libMicro-0.4.0/writev.c new file mode 100644 index 0000000..ac1bf2e --- /dev/null +++ b/native/libMicro-0.4.0/writev.c @@ -0,0 +1,149 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the "License"). You may not use this file except + * in compliance with the License. + * + * You can obtain a copy of the license at + * src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * HEADER in each file and include the License file at + * usr/src/OPENSOLARIS.LICENSE. If applicable, + * add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your + * own identifying information: Portions Copyright [yyyy] + * [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include + +#ifndef IOV_MAX +#define IOV_MAX UIO_MAXIOV +#endif + +#include "libmicro.h" + +typedef struct { + int ts_once; + struct iovec *ts_iov; + int ts_fd; +} tsd_t; + +#define DEFF "/dev/null" +#define DEFS 1024 +#define DEFV 10 + +static char *optf = DEFF; +static int opts = DEFS; +static int optv = DEFV; + +int +benchmark_init() +{ + lm_tsdsize = sizeof (tsd_t); + + (void) sprintf(lm_optstr, "f:s:v:"); + + (void) sprintf(lm_usage, + " [-f file-to-write (default %s)]\n" + " [-s buffer-size (default %d)]\n" + " [-v vector-size (default %d)]\n" + "notes: measures writev()\n" + " IOV_MAX is %d\n" + " SSIZE_MAX is %ld\n", + DEFF, DEFS, DEFV, IOV_MAX, SSIZE_MAX); + + (void) sprintf(lm_header, "%8s %4s", "size", "vec"); + + lm_defB = 1; + + return (0); +} + +int +benchmark_optswitch(int opt, char *optarg) +{ + switch (opt) { + case 'f': + optf = optarg; + break; + case 's': + opts = sizetoint(optarg); + break; + case 'v': + optv = atoi(optarg); + break; + default: + return (-1); + } + return (0); +} + +int +benchmark_initbatch(void *tsd) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + int errors = 0; + + if (ts->ts_once++ == 0) { + ts->ts_fd = open(optf, O_WRONLY); + if (ts->ts_fd == -1) { + errors++; + } + ts->ts_iov = (struct iovec *)malloc( + optv * sizeof (struct iovec)); + for (i = 0; i < optv; i++) { + ts->ts_iov[i].iov_base = malloc(opts); + ts->ts_iov[i].iov_len = opts; + } + } + + (void) lseek(ts->ts_fd, 0, SEEK_SET); + + return (errors); +} + +int +benchmark(void *tsd, result_t *res) +{ + tsd_t *ts = (tsd_t *)tsd; + int i; + + for (i = 0; i < lm_optB; i++) { + if (writev(ts->ts_fd, ts->ts_iov, optv) != opts * optv) { + res->re_errors++; + } + } + res->re_count = i; + + return (0); +} + +char * +benchmark_result() +{ + static char result[256]; + + (void) sprintf(result, "%8d %4d", opts, optv); + + return (result); +} -- cgit v1.2.3