├── others └── tmi │ ├── llvm │ └── lib │ │ └── Transforms │ │ └── TMI │ │ ├── TMI.exports │ │ └── CMakeLists.txt │ ├── Makefile.am │ ├── xed │ ├── libxed.a │ ├── include │ │ ├── xed-attributes.h │ │ ├── xed-init-pointer-names.h │ │ ├── xed-version.h │ │ ├── xed-operand-ctype-map.h │ │ ├── xed-build-defines.h │ │ ├── xed-init.h │ │ ├── xed-convert-table-init.h │ │ ├── xed-encoder-gen-defs.h │ │ └── xed-isa-set.h │ ├── xed-disas-hex.H │ ├── xed-disas-raw.H │ ├── xed-enc-lang.H │ ├── xed-disas-macho.H │ ├── xed-disas-elf.H │ ├── xed-disas-pecoff.H │ ├── xed-examples-ostreams.H │ └── xed-examples-ostreams.cpp │ ├── autogen.sh │ ├── include │ ├── pagestate.hpp │ ├── Makefile.am │ ├── detector │ │ ├── PCCounterComparer.h │ │ ├── laser_api.h │ │ ├── SharingEventType.h │ │ ├── CategoryCounter.h │ │ ├── Helpers.h │ │ ├── MemRangeBucket.h │ │ └── HotSpotWindow.h │ ├── tmiutil.hpp │ ├── detector.hpp │ ├── funchook.h │ ├── tmi_allocator.hpp │ ├── timers.hpp │ ├── internalmem.hpp │ ├── compiler.h │ ├── tmithread.hpp │ ├── perf.hpp │ ├── tmi.h │ ├── gcc.h │ ├── hooks.hpp │ ├── tramps.h │ └── tmimem.hpp │ ├── benchmarks │ └── leveldb │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── AUTHORS │ │ ├── util │ │ ├── filter_policy.cc │ │ ├── hash.h │ │ ├── options.cc │ │ ├── env_posix_test_helper.h │ │ ├── histogram.h │ │ ├── mutexlock.h │ │ ├── hash.cc │ │ ├── logging.h │ │ ├── crc32c.h │ │ ├── testutil.cc │ │ ├── hash_test.cc │ │ ├── arena_test.cc │ │ ├── testharness.cc │ │ ├── logging.cc │ │ ├── crc32c_test.cc │ │ ├── arena.h │ │ ├── status.cc │ │ ├── arena.cc │ │ ├── testutil.h │ │ ├── env_posix_test.cc │ │ └── random.h │ │ ├── port │ │ ├── README │ │ ├── port.h │ │ ├── win │ │ │ └── stdint.h │ │ ├── thread_annotations.h │ │ └── port_posix.cc │ │ ├── NEWS │ │ ├── TODO │ │ ├── helpers │ │ └── memenv │ │ │ └── memenv.h │ │ ├── db │ │ ├── db_iter.h │ │ ├── log_format.h │ │ ├── builder.h │ │ ├── version_edit_test.cc │ │ ├── log_writer.h │ │ ├── write_batch_internal.h │ │ ├── leveldbutil.cc │ │ ├── snapshot.h │ │ └── table_cache.h │ │ ├── table │ │ ├── merger.h │ │ ├── block.h │ │ ├── two_level_iterator.h │ │ ├── iterator.cc │ │ ├── block_builder.h │ │ └── iterator_wrapper.h │ │ ├── include │ │ └── leveldb │ │ │ ├── dumpfile.h │ │ │ └── write_batch.h │ │ ├── jld.mak │ │ ├── tmi-run-leveldb.mak │ │ ├── LICENSE │ │ ├── CONTRIBUTING.md │ │ └── issues │ │ └── issue200_test.cc │ ├── unittests │ ├── syncsuite.cpp │ ├── Makefile.am │ ├── hooksuite.cpp │ ├── memorysuite.cpp │ └── main.cpp │ ├── configure.ac │ ├── .gitignore │ ├── src │ ├── llalloc.cpp │ ├── tmialloc.cpp │ ├── tmilib.cpp │ ├── Makefile.am │ ├── tmiutil.cpp │ ├── timers.cpp │ └── internalmem.cpp │ ├── tests │ ├── test_fork.cpp │ ├── test.cpp │ ├── test_locks.cpp │ └── test_sync_process.cpp │ └── README ├── .gitmodules ├── AlignMalloc └── CMakeLists.txt ├── Instrumenter └── CMakeLists.txt ├── MemoryAnalysis └── CMakeLists.txt ├── RedirectPtr ├── CMakeLists.txt └── CustomUnrollLoop.h ├── runtime ├── MemArith.h ├── CMakeLists.txt ├── Makefile ├── Segment.h ├── SharedSpinLock.h ├── LibFuncs.h ├── LoggingThread.cpp └── SymbolCache.h ├── sheriffMemoryUsage.sh ├── kmeans_repair ├── compile.sh └── toy.cpp ├── postprocess ├── CMakeLists.txt ├── Makefile ├── Stats.h ├── Utils.cpp ├── Detect.h ├── Repair.h └── main.cpp ├── test_suites ├── atomic_lock │ ├── spinlock.h │ └── sequential.cpp ├── tensor │ ├── benchmark.sh │ ├── cachemiss.sh │ ├── Makefile │ └── tensor_parallel.cpp ├── false │ ├── Makefile │ └── false.c ├── histogram │ └── README ├── boost_test │ └── spinlock.hpp ├── linear_regression │ └── README ├── lu_ncb │ └── run.sh ├── tmi_boost │ └── spinlock │ │ └── stackoverflow.cpp ├── locked │ ├── toy_manual.c │ └── toy.c └── lockless │ ├── toy_manual.c │ └── toy.c ├── .gitignore ├── CMakeLists.txt ├── second_pass └── Makefile ├── run_memory_usage.sh ├── parse_perf_output.py ├── unroll.md └── parse_perf_drop_sigv.py /others/tmi/llvm/lib/Transforms/TMI/TMI.exports: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /others/tmi/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 2 | 3 | SUBDIRS = include src 4 | -------------------------------------------------------------------------------- /others/tmi/xed/libxed.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/efeslab/huron/HEAD/others/tmi/xed/libxed.a -------------------------------------------------------------------------------- /others/tmi/autogen.sh: -------------------------------------------------------------------------------- 1 | # For building 2 | libtoolize 3 | aclocal 4 | autoconf 5 | automake --add-missing 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "others/sheriff"] 2 | path = others/sheriff 3 | url = https://github.com/plasma-umass/sheriff.git 4 | -------------------------------------------------------------------------------- /AlignMalloc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_loadable_module( LLVMAlignMalloc 2 | AlignMalloc.cpp 3 | 4 | PLUGIN_TOOL 5 | opt 6 | ) 7 | -------------------------------------------------------------------------------- /Instrumenter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_loadable_module( LLVMInstrumenter 2 | Instrumenter.cpp 3 | 4 | PLUGIN_TOOL 5 | opt 6 | ) 7 | -------------------------------------------------------------------------------- /others/tmi/include/pagestate.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class pagestate{ 4 | public: 5 | void *_addr; 6 | void *_twin; 7 | bool _active; 8 | }; 9 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/.gitignore: -------------------------------------------------------------------------------- 1 | build_config.mk 2 | *.a 3 | *.o 4 | *.dylib* 5 | *.so 6 | *.so.* 7 | *_test 8 | db_bench 9 | leveldbutil 10 | -------------------------------------------------------------------------------- /others/tmi/unittests/syncsuite.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | TEST(TMISyncSuite, LockUnlock){ 6 | EXPECT_EQ(1,1); 7 | } 8 | -------------------------------------------------------------------------------- /MemoryAnalysis/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_loadable_module( 2 | LLVMMemoryAnalysis 3 | MemoryAnalysis.cpp 4 | PLUGIN_TOOL 5 | opt 6 | ) 7 | -------------------------------------------------------------------------------- /others/tmi/include/Makefile.am: -------------------------------------------------------------------------------- 1 | nobase_include_HEADERS = detector.hpp \ 2 | tmi.h \ 3 | perf.hpp \ 4 | tramps.h \ 5 | compiler.h \ 6 | ll_asm.h \ 7 | ll_list.h 8 | -------------------------------------------------------------------------------- /RedirectPtr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_loadable_module( 2 | LLVMRedirectPtr 3 | CustomUnrollLoop.cpp 4 | RedirectPtr.cpp 5 | PLUGIN_TOOL 6 | opt 7 | ) 8 | -------------------------------------------------------------------------------- /runtime/MemArith.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMARITH_H 2 | #define MEMARITH_H 3 | 4 | typedef unsigned long uintptr_t; 5 | 6 | /* Cache line is 64 (2^6) bytes. */ 7 | const unsigned long cacheline_size_power = 6; 8 | 9 | #endif -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - clang 4 | - gcc 5 | os: 6 | - linux 7 | - osx 8 | sudo: false 9 | before_install: 10 | - echo $LANG 11 | - echo $LC_ALL 12 | script: 13 | - make -j 4 check 14 | -------------------------------------------------------------------------------- /sheriffMemoryUsage.sh: -------------------------------------------------------------------------------- 1 | for (( c=1; c<1001; c+=1 )) 2 | do 3 | ps aux | grep 'a.out' >> log.out 4 | sleep 0.005 5 | done 6 | cat log.out | grep '500MB.txt' > sheriffStringMatch.log 7 | awk -v max=0 '{if($5>max){max=$5}}END{print max} ' sheriffStringMatch.log 8 | rm log.out 9 | -------------------------------------------------------------------------------- /kmeans_repair/compile.sh: -------------------------------------------------------------------------------- 1 | set -x 2 | clang++ -c -emit-llvm toy.cpp -o a.bc 3 | opt -load ~/Documents/llvm/build/lib/LLVMInstrumenter.so -instrumenter < a.bc > a.inst.bc 2> a.log 4 | llc -filetype=obj a.inst.bc -o a.o 5 | g++ a.o -Wl,/home/takh/eigen-optim/libruntime.so -lpthread -o a.out 6 | -------------------------------------------------------------------------------- /others/tmi/include/detector/PCCounterComparer.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class PCCounterComparer 5 | { 6 | public: 7 | bool operator()(const std::pair& first, const std::pair& second) const 8 | { 9 | return first.second > second.second; 10 | } 11 | }; -------------------------------------------------------------------------------- /postprocess/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_FLAGS "-Wall -Wextra") 2 | set(CMAKE_CXX_FLAGS_DEBUG "-g") 3 | set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g") 4 | 5 | add_executable(postprocess main.cpp 6 | Utils.h Utils.cpp 7 | Repair.h 8 | Stats.h 9 | Detect.h Detect.cpp Repair.cpp) 10 | -------------------------------------------------------------------------------- /others/tmi/include/detector/laser_api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | class LaserEvent 11 | { 12 | public: 13 | uint64_t PC; 14 | uint64_t Addr; 15 | }__attribute__((packed)); 16 | -------------------------------------------------------------------------------- /others/tmi/include/tmiutil.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class tmiutil{ 6 | public: 7 | static void init_mutex(pthread_mutex_t *mutex); 8 | static void init_cond(pthread_cond_t *cond); 9 | static void init_spinlock(pthread_spinlock_t *lock); 10 | static void* alignAddressToPage(void *addr); 11 | }; 12 | -------------------------------------------------------------------------------- /others/tmi/include/detector.hpp: -------------------------------------------------------------------------------- 1 | #include "perf.hpp" 2 | 3 | struct Mem_access_type_size 4 | { 5 | bool isStore; 6 | int size; 7 | }; 8 | 9 | extern "C"{ 10 | void detector_init(int window_size, int sample_period); 11 | void detector_handle_record(DataRecord *dr); 12 | void detector_check_false_sharing(); 13 | void detector_do_output(); 14 | } 15 | -------------------------------------------------------------------------------- /others/tmi/include/funchook.h: -------------------------------------------------------------------------------- 1 | #ifndef __AE_FUNCHOOK_H_ 2 | #define __AE_FUNCHOOK_H_ 3 | 4 | typedef void (*func_t)(void); 5 | 6 | // For hooking functions 7 | void hook_function(func_t func, func_t hook, func_t* orig_ptr); 8 | void hook_function_by_name(const char* lib, const char* name, func_t hook, func_t* result); 9 | 10 | #endif // __AE_FUNCHOOK_H_ 11 | -------------------------------------------------------------------------------- /test_suites/atomic_lock/spinlock.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class spinlock { 4 | public: 5 | void lock() { 6 | while (locked.test_and_set(std::memory_order_acquire)) { ; } 7 | } 8 | 9 | void unlock() { 10 | locked.clear(std::memory_order_release); 11 | } 12 | private: 13 | std::atomic_flag locked = ATOMIC_FLAG_INIT; 14 | }; 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDEs 2 | .idea/ 3 | .vscode/ 4 | cmake-build-debug/ 5 | cmake-build-release/ 6 | 7 | # Outputs 8 | *.log 9 | *.csv 10 | *.txt 11 | !CMakeLists.txt 12 | output/ 13 | 14 | # Temp files of NTFS filesystem 15 | .fuse* 16 | 17 | # Built binary and dynamic library 18 | *.so 19 | *.o 20 | *.bc 21 | bin/ 22 | 23 | # Personal compile script 24 | compile.sh 25 | -------------------------------------------------------------------------------- /others/tmi/configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT(tmi,1.0,delozier@cis.upenn.edu) 2 | AC_PREREQ([2.59]) 3 | AM_INIT_AUTOMAKE([foreign]) 4 | 5 | AC_ENABLE_SHARED 6 | AC_DISABLE_STATIC 7 | LT_INIT 8 | 9 | AC_PROG_CC 10 | AC_PROG_CXX 11 | AC_CONFIG_FILES([Makefile 12 | include/Makefile 13 | src/Makefile 14 | unittests/Makefile]) 15 | 16 | AC_OUTPUT 17 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/AUTHORS: -------------------------------------------------------------------------------- 1 | # Names should be added to this file like so: 2 | # Name or Organization 3 | 4 | Google Inc. 5 | 6 | # Initial version authors: 7 | Jeffrey Dean 8 | Sanjay Ghemawat 9 | 10 | # Partial list of contributors: 11 | Kevin Regan 12 | Johan Bilien 13 | -------------------------------------------------------------------------------- /others/tmi/llvm/lib/Transforms/TMI/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # If we don't need RTTI or EH, there's no reason to export anything 2 | # from the hello plugin. 3 | if( NOT LLVM_REQUIRES_RTTI ) 4 | if( NOT LLVM_REQUIRES_EH ) 5 | set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/TMI.exports) 6 | endif() 7 | endif() 8 | 9 | add_llvm_loadable_module( LLVMTMI 10 | TMI.cpp 11 | ) 12 | -------------------------------------------------------------------------------- /test_suites/tensor/benchmark.sh: -------------------------------------------------------------------------------- 1 | set -x 2 | clang++ -c -g -emit-llvm -std=c++11 -I ../eigen/ -DEIGEN_USE_THREADS tensor_parallel.cpp -o tensor.bc 3 | # opt -load ./LLVMInstLoadStore.so -instloadstore -locfile record_output.log < tensor.bc > tensor_inst.bc 2> build_tensor.log 4 | # mv tensor_inst.bc tensor.bc 5 | llc -filetype=obj tensor.bc -o tensor.o 6 | g++ tensor.o -lpthread -o tensor_benchmark 7 | -------------------------------------------------------------------------------- /postprocess/Makefile: -------------------------------------------------------------------------------- 1 | SRCS = Detect.cpp main.cpp Repair.cpp Utils.cpp 2 | 3 | INCS = Detect.h Repair.h Stats.h Utils.h 4 | 5 | DEPS = $(SRCS) $(INCS) 6 | 7 | CXX = clang++ 8 | 9 | CFLAGS = -std=c++1z -g -O3 10 | 11 | TARGETS = postprocess 12 | 13 | all: $(TARGETS) 14 | 15 | postprocess: $(DEPS) 16 | $(CXX) $(CFLAGS) $(SRCS) -o postprocess -lpthread 17 | 18 | clean: 19 | rm -f $(TARGETS) 20 | -------------------------------------------------------------------------------- /test_suites/tensor/cachemiss.sh: -------------------------------------------------------------------------------- 1 | set -x 2 | for (( c=100; c<1600; c+=100 )) 3 | do 4 | # mkdir size$c 5 | # cd size$c 6 | # cp ../postprocess.py ../tensor ../tensor.bc ../LLVMInstLoadStore.so ../second_pass/secondpass.so ../runtime/libruntime.so . 7 | export MSIZE=$c 8 | ocperf.py stat -e cache-misses,mem_load_uops_l3_hit_retired.xsnp_hitm -r 100 ./tensor_benchmark > /dev/null 2>> padded.txt 9 | done 10 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/filter_policy.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/filter_policy.h" 6 | 7 | namespace leveldb { 8 | 9 | FilterPolicy::~FilterPolicy() { } 10 | 11 | } // namespace leveldb 12 | -------------------------------------------------------------------------------- /runtime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCE_FILES LoggingThread.cpp Runtime.cpp LoggingThread.h GetGlobal.h xthread.h MemArith.h MallocInfo.h Segment.h 2 | LibFuncs.h SymbolCache.h SharedSpinLock.h) 3 | add_library(runtime SHARED ${SOURCE_FILES}) 4 | target_link_libraries(runtime dl pthread) 5 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-private-field -DDEBUG -fPIC") 6 | set(CMAKE_CXX_FLAGS_DEBUG "-g") 7 | set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g") 8 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9.6) 2 | set(CMAKE_CXX_STANDARD 17) 3 | project(huron) 4 | 5 | find_package(LLVM REQUIRED CONFIG) 6 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") 7 | include(AddLLVM) 8 | 9 | add_definitions(${LLVM_DEFINITIONS}) 10 | include_directories(${LLVM_INCLUDE_DIRS}) 11 | 12 | add_subdirectory(Instrumenter) 13 | add_subdirectory(RedirectPtr) 14 | add_subdirectory(postprocess) 15 | add_subdirectory(runtime) 16 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/port/README: -------------------------------------------------------------------------------- 1 | This directory contains interfaces and implementations that isolate the 2 | rest of the package from platform details. 3 | 4 | Code in the rest of the package includes "port.h" from this directory. 5 | "port.h" in turn includes a platform specific "port_.h" file 6 | that provides the platform specific implementation. 7 | 8 | See port_posix.h for an example of what must be provided in a platform 9 | specific header file. 10 | 11 | -------------------------------------------------------------------------------- /others/tmi/unittests/Makefile.am: -------------------------------------------------------------------------------- 1 | GOOGLETEST_DIR=/home/delozier/googletest 2 | 3 | CXXFLAGS += -I$(GOOGLETEST_DIR)/include/ -I../include/ -std=c++11 4 | LDFLAGS = -pthread 5 | LIBS = $(GOOGLETEST_DIR)/libgtest.a ../build/lib/libtmiprotect.la 6 | 7 | TESTS = hooktest synctest memorytest 8 | 9 | check_PROGRAMS = hooktest synctest memorytest 10 | 11 | hooktest_SOURCES = hooksuite.cpp main.cpp 12 | synctest_SOURCES = syncsuite.cpp main.cpp 13 | memorytest_SOURCES = memorysuite.cpp main.cpp 14 | -------------------------------------------------------------------------------- /test_suites/false/Makefile: -------------------------------------------------------------------------------- 1 | all: false 2 | 3 | false_bc: false.c 4 | clang -c -emit-llvm false.c -o false.bc 5 | ifndef NOINST 6 | opt -load LLVMInstrumenter.so -instrumenter < false.bc > false_inst.bc 2> build_false.log 7 | endif 8 | 9 | false: false_bc 10 | ifndef NOINST 11 | llc -filetype=obj false_inst.bc -o false.o 12 | gcc false.o -lruntime -lpthread -o false 13 | else 14 | llc -filetype=obj false.bc -o false.o 15 | gcc false.o -lpthread -o false 16 | endif 17 | 18 | clean: 19 | rm -f *.bc *.o false 20 | -------------------------------------------------------------------------------- /others/tmi/unittests/hooksuite.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | TEST(HookSuite, Init){ 7 | init_orig_functions(); 8 | } 9 | 10 | void* testJoin(void *arg){ 11 | return nullptr; 12 | } 13 | 14 | TEST(HookSuite, CreateJoin){ 15 | ASSERT_NE(orig_pthread_create,nullptr); 16 | ASSERT_NE(orig_pthread_join,nullptr); 17 | 18 | pthread_t thread; 19 | orig_pthread_create(&thread,nullptr,testJoin,(void*)10); 20 | orig_pthread_join(thread,nullptr); 21 | } 22 | -------------------------------------------------------------------------------- /others/tmi/include/tmi_allocator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | extern "C" void* tmi_internal_alloc(size_t size); 7 | extern "C" void tmi_internal_dealloc(void *p); 8 | 9 | template class tmi_allocator : public std::allocator{ 10 | public: 11 | inline T* allocate(size_t cnt, const T* hint = 0) 12 | { 13 | return (T*)tmi_internal_alloc(cnt * sizeof(T)); 14 | } 15 | 16 | inline void deallocate( T* p, size_t n ) 17 | { 18 | tmi_internal_dealloc((void*)p); 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /second_pass/Makefile: -------------------------------------------------------------------------------- 1 | SOURCE_DIR = . 2 | INCLUDE_DIR = . 3 | 4 | SRCS = $(SOURCE_DIR)/SecondPass.cpp 5 | 6 | INCS = 7 | 8 | DEPS = $(SRCS) $(INCS) 9 | 10 | CXX = g++ -std=c++11 -g -O2 -I$(INCLUDE_DIR) 11 | 12 | CFLAGS = -fno-omit-frame-pointer -DDEBUG 13 | CFLAGS32 = $(CFLAGS) -m32 -DX86_32BIT # -O3 14 | CFLAGS64 = $(CFLAGS) #-m64 # -O3 15 | 16 | TARGETS = secondpass.so 17 | 18 | all: $(TARGETS) 19 | 20 | secondpass.so: $(DEPS) 21 | $(CXX) $(CFLAGS64) $(INCLUDE_DIRS) -shared -fPIC $(SRCS) -o secondpass.so -ldl -lpthread 22 | 23 | clean: 24 | rm -f $(TARGETS) 25 | -------------------------------------------------------------------------------- /others/tmi/.gitignore: -------------------------------------------------------------------------------- 1 | tests/test 2 | results/ 3 | scratch/ 4 | src/llalloc 5 | src/tmialloc 6 | src/tmidetector 7 | src/tmildr 8 | *.o 9 | depcomp 10 | *.la 11 | *.lo 12 | *~ 13 | Makefile 14 | Makefile.in 15 | aclocal.m4 16 | autom4te.cache/ 17 | build/ 18 | compile 19 | config.guess 20 | config.log 21 | config.status 22 | config.sub 23 | configure 24 | epcomp 25 | include/Makefile 26 | include/Makefile.in 27 | install-sh 28 | libtool 29 | ltmain.sh 30 | missing 31 | src/.deps/ 32 | src/.libs/ 33 | 34 | test-driver 35 | unittests/.deps/ 36 | xed/*.d 37 | xed/xed 38 | .gdbinit 39 | -------------------------------------------------------------------------------- /others/tmi/include/timers.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | typedef std::chrono::high_resolution_clock clock_type; 6 | 7 | class timers{ 8 | static unsigned long *_segvTime; 9 | static unsigned long *_commitTime; 10 | 11 | static clock_type::time_point _startSegv; 12 | static clock_type::time_point _startCommit; 13 | 14 | public: 15 | static const int SEGV = 1; 16 | static const int COMMIT = 2; 17 | 18 | static void initTimer(int name); 19 | static void startTimer(int name); 20 | static void stopTimer(int name); 21 | static void printTimers(); 22 | }; 23 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/NEWS: -------------------------------------------------------------------------------- 1 | Release 1.2 2011-05-16 2 | ---------------------- 3 | 4 | Fixes for larger databases (tested up to one billion 100-byte entries, 5 | i.e., ~100GB). 6 | 7 | (1) Place hard limit on number of level-0 files. This fixes errors 8 | of the form "too many open files". 9 | 10 | (2) Fixed memtable management. Before the fix, a heavy write burst 11 | could cause unbounded memory usage. 12 | 13 | A fix for a logging bug where the reader would incorrectly complain 14 | about corruption. 15 | 16 | Allow public access to WriteBatch contents so that users can easily 17 | wrap a DB. 18 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/TODO: -------------------------------------------------------------------------------- 1 | ss 2 | - Stats 3 | 4 | db 5 | - Maybe implement DB::BulkDeleteForRange(start_key, end_key) 6 | that would blow away files whose ranges are entirely contained 7 | within [start_key..end_key]? For Chrome, deletion of obsolete 8 | object stores, etc. can be done in the background anyway, so 9 | probably not that important. 10 | - There have been requests for MultiGet. 11 | 12 | After a range is completely deleted, what gets rid of the 13 | corresponding files if we do no future changes to that range. Make 14 | the conditions for triggering compactions fire in more situations? 15 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Simple hash function used for internal data structures 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_HASH_H_ 8 | #define STORAGE_LEVELDB_UTIL_HASH_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | 15 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed); 16 | 17 | } 18 | 19 | #endif // STORAGE_LEVELDB_UTIL_HASH_H_ 20 | -------------------------------------------------------------------------------- /run_memory_usage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | "$@" & 3 | pid=$! 4 | #echo $pid 5 | while true; do 6 | line=$(ps auxh -q $pid) 7 | if [ "$line" == "" ]; then 8 | break; 9 | fi 10 | echo $line >> log.out 11 | for child in $(pgrep -P $pid); 12 | do 13 | line=$(ps auxh -q $child) 14 | if [ "$line" == "" ]; then 15 | continue; 16 | fi 17 | echo $line >> log.out 18 | done 19 | sleep 0.005 20 | done 21 | awk 'BEGIN { maxvsz=0; maxrss=0; } \ 22 | { if ($5>maxvsz) {maxvsz=$5}; if ($6>maxrss) {maxrss=$6}; }\ 23 | END { print "vsz=" maxvsz " rss=" maxrss; }' log.out 24 | rm log.out 25 | -------------------------------------------------------------------------------- /others/tmi/include/internalmem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "tmi.h" 4 | 5 | #include 6 | #include 7 | 8 | extern "C" void* tmi_internal_alloc(size_t size); 9 | extern "C" void tmi_internal_dealloc(void *p); 10 | 11 | class internalmemory{ 12 | static char *_start; 13 | static char *_pos; 14 | static char *_end; 15 | 16 | static bool _initialized; 17 | 18 | public: 19 | static const int INTERNAL_HEAP_SIZE = 1073741824; 20 | 21 | static int isInternal(void *addr); 22 | static void init(); 23 | static void cleanup(); 24 | static void initThreads(); 25 | static void* alloc(size_t size); 26 | }; 27 | -------------------------------------------------------------------------------- /others/tmi/unittests/memorysuite.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | TEST(MemorySuite, Init){ 6 | memory::init(); 7 | } 8 | 9 | TEST(MemorySuite, Alloc){ 10 | void *p = memory::adjust_slab_memory(128); 11 | ASSERT_NE(p,nullptr); 12 | 13 | void *m = memory::get_mmap_memory(4096); 14 | ASSERT_NE(m,nullptr); 15 | } 16 | 17 | TEST(MemorySuite, Protect){ 18 | void *p1 = memory::adjust_slab_memory(4096); 19 | void *p2 = memory::adjust_slab_memory(4096); 20 | void *p3 = memory::adjust_slab_memory(512); 21 | 22 | ASSERT_TRUE(memory::protectAddress(p1)); 23 | ASSERT_TRUE(memory::protectAddress(p3)); 24 | } 25 | -------------------------------------------------------------------------------- /test_suites/atomic_lock/sequential.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "spinlock.h" 5 | 6 | using namespace std; 7 | 8 | spinlock lock; 9 | 10 | void thread_print(size_t tid) { 11 | lock.lock(); 12 | cout << "This is thread " << tid << "! Sleeping for 1 second.\n"; 13 | this_thread::sleep_for(chrono::seconds(1)); 14 | cout << "Thread " << tid << " is quitting.\n"; 15 | lock.unlock(); 16 | } 17 | 18 | int main() { 19 | thread th[2]; 20 | th[0] = thread(thread_print, 0); 21 | th[1] = thread(thread_print, 1); 22 | for (thread &t: th) 23 | t.join(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /parse_perf_output.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | regex = r"\s+([\d,]+)\s+cache-misses.+\n\s+([\d,]+)\s+mem_load_uops_l3_hit_retired_xsnp_hitm.+\s+([\d\.]+)" 5 | 6 | test_str = "" 7 | 8 | with open(sys.argv[1], "r") as file: 9 | test_str = file.read() 10 | 11 | matches = re.finditer(regex, test_str, re.MULTILINE) 12 | 13 | for matchNum, match in enumerate(matches): 14 | matchNum = matchNum + 1 15 | # print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) 16 | for groupNum in range(0, len(match.groups())): 17 | groupNum = groupNum + 1 18 | print "{group};".format(group = match.group(groupNum)), 19 | print '' 20 | -------------------------------------------------------------------------------- /postprocess/Stats.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yifanz on 7/11/18. 3 | // 4 | 5 | #ifndef POSTPROCESS_STATS_H 6 | #define POSTPROCESS_STATS_H 7 | 8 | #include 9 | #include 10 | #include "Utils.h" 11 | 12 | class FSRankStat { 13 | public: 14 | explicit FSRankStat(const std::string &path) : stats_stream(path) {} 15 | 16 | void emplace(size_t fs, int mloc) { 17 | fs_mloc_ordering.emplace(fs, mloc); 18 | } 19 | 20 | void print() { 21 | for (auto it = fs_mloc_ordering.rbegin(); it != fs_mloc_ordering.rend(); it++) 22 | stats_stream << '#' << it->first << '@' << it->second << '\n'; 23 | } 24 | 25 | private: 26 | std::map fs_mloc_ordering; 27 | std::ofstream stats_stream; 28 | }; 29 | 30 | #endif //POSTPROCESS_STATS_H 31 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/port/port.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_PORT_H_ 6 | #define STORAGE_LEVELDB_PORT_PORT_H_ 7 | 8 | #include 9 | 10 | // Include the appropriate platform specific file below. If you are 11 | // porting to a new platform, see "port_example.h" for documentation 12 | // of what the new port_.h file must provide. 13 | #if defined(LEVELDB_PLATFORM_POSIX) 14 | # include "port/port_posix.h" 15 | #elif defined(LEVELDB_PLATFORM_CHROMIUM) 16 | # include "port/port_chromium.h" 17 | #endif 18 | 19 | #endif // STORAGE_LEVELDB_PORT_PORT_H_ 20 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/helpers/memenv/memenv.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 6 | #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Env; 11 | 12 | // Returns a new environment that stores its data in memory and delegates 13 | // all non-file-storage tasks to base_env. The caller must delete the result 14 | // when it is no longer needed. 15 | // *base_env must remain live while the result is in use. 16 | Env* NewMemEnv(Env* base_env); 17 | 18 | } // namespace leveldb 19 | 20 | #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 21 | -------------------------------------------------------------------------------- /runtime/Makefile: -------------------------------------------------------------------------------- 1 | SOURCE_DIR = . 2 | INCLUDE_DIR = . 3 | 4 | SRCS = $(SOURCE_DIR)/Runtime.cpp \ 5 | $(SOURCE_DIR)/LoggingThread.cpp 6 | 7 | INCS = $(INCLUDE_DIR)/GetGlobal.h \ 8 | $(INCLUDE_DIR)/LoggingThread.h \ 9 | $(INCLUDE_DIR)/MallocInfo.h \ 10 | $(INCLUDE_DIR)/MemArith.h \ 11 | $(INCLUDE_DIR)/xthread.h \ 12 | $(INCLUDE_DIR)/LibFuncs.h \ 13 | 14 | DEPS = $(SRCS) $(INCS) 15 | 16 | CXX = clang++ -std=c++1z -g -O3 -I$(INCLUDE_DIR) 17 | 18 | CFLAGS = -fno-omit-frame-pointer -DDEBUG 19 | CFLAGS32 = $(CFLAGS) -m32 -DX86_32BIT 20 | CFLAGS64 = $(CFLAGS) 21 | 22 | TARGETS = libruntime.so 23 | 24 | all: $(TARGETS) 25 | 26 | libruntime.so: $(DEPS) 27 | $(CXX) $(CFLAGS64) $(INCLUDE_DIRS) -shared -fPIC $(SRCS) -o libruntime.so -ldl -lpthread 28 | 29 | clean: 30 | rm -f $(TARGETS) 31 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/db_iter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_DB_ITER_H_ 6 | #define STORAGE_LEVELDB_DB_DB_ITER_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | 12 | namespace leveldb { 13 | 14 | class DBImpl; 15 | 16 | // Return a new iterator that converts internal keys (yielded by 17 | // "*internal_iter") that were live at the specified "sequence" number 18 | // into appropriate user keys. 19 | extern Iterator* NewDBIterator( 20 | DBImpl* db, 21 | const Comparator* user_key_comparator, 22 | Iterator* internal_iter, 23 | SequenceNumber sequence, 24 | uint32_t seed); 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_ 29 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/options.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/options.h" 6 | 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/env.h" 9 | 10 | namespace leveldb { 11 | 12 | Options::Options() 13 | : comparator(BytewiseComparator()), 14 | create_if_missing(false), 15 | error_if_exists(false), 16 | paranoid_checks(false), 17 | env(Env::Default()), 18 | info_log(NULL), 19 | write_buffer_size(4<<20), 20 | max_open_files(1000), 21 | block_cache(NULL), 22 | block_size(4096), 23 | block_restart_interval(16), 24 | max_file_size(2<<20), 25 | compression(kSnappyCompression), 26 | reuse_logs(false), 27 | filter_policy(NULL) { 28 | } 29 | 30 | } // namespace leveldb 31 | -------------------------------------------------------------------------------- /postprocess/Utils.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yifanz on 7/29/18. 3 | // 4 | 5 | #include "Utils.h" 6 | 7 | using namespace std; 8 | 9 | size_t to_address(const string_view &str) { 10 | if (!(str.length() > 2 && str[0] == '0' && str[1] == 'x')) 11 | throw invalid_argument("Invalid address format"); 12 | size_t val = 0; 13 | for (size_t i = 2; i < str.size(); i++) 14 | val = val * 16 + (str[i] >= 'a' ? str[i] - 'a' + 10 : str[i] - '0'); 15 | return val; 16 | } 17 | 18 | string insert_suffix(const string &path, const string &suffix) { 19 | size_t slash = path.rfind('/'); 20 | slash = slash == string::npos ? 0 : slash + 1; 21 | string basename = path.substr(slash); 22 | size_t dot = basename.find('.'); 23 | if (dot == string::npos || dot == 0) // hidden file, not extension 24 | return path + suffix; 25 | else { 26 | dot += slash; 27 | return path.substr(0, dot) + suffix + path.substr(dot); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/port/win/stdint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // MSVC didn't ship with this file until the 2010 version. 6 | 7 | #ifndef STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 8 | #define STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 9 | 10 | #if !defined(_MSC_VER) 11 | #error This file should only be included when compiling with MSVC. 12 | #endif 13 | 14 | // Define C99 equivalent types. 15 | typedef signed char int8_t; 16 | typedef signed short int16_t; 17 | typedef signed int int32_t; 18 | typedef signed long long int64_t; 19 | typedef unsigned char uint8_t; 20 | typedef unsigned short uint16_t; 21 | typedef unsigned int uint32_t; 22 | typedef unsigned long long uint64_t; 23 | 24 | #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 25 | -------------------------------------------------------------------------------- /runtime/Segment.h: -------------------------------------------------------------------------------- 1 | #ifndef SEGMENT_H 2 | #define SEGMENT_H 3 | 4 | template 5 | class Segment { 6 | T start, end; 7 | public: 8 | Segment() = default; 9 | 10 | Segment(T _start, T _end): start(_start), end(_end) {} 11 | 12 | void insert(const Segment &rhs) { 13 | start = std::min(start, rhs.start); 14 | end = std::max(end, rhs.end); 15 | } 16 | 17 | void shrink(const Segment &rhs) { 18 | if (rhs.start <= start && rhs.end > start) { 19 | start = rhs.end; 20 | } 21 | else if (rhs.start < end && rhs.end >= start) { 22 | end = rhs.start; 23 | } 24 | } 25 | 26 | inline bool contain(T val) const { 27 | return start <= val && val < end; 28 | } 29 | 30 | T get_start() const { 31 | return start; 32 | } 33 | 34 | T get_size() const { 35 | return end - start; 36 | } 37 | }; 38 | 39 | typedef Segment AddrSeg; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/table/merger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_MERGER_H_ 6 | #define STORAGE_LEVELDB_TABLE_MERGER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Comparator; 11 | class Iterator; 12 | 13 | // Return an iterator that provided the union of the data in 14 | // children[0,n-1]. Takes ownership of the child iterators and 15 | // will delete them when the result iterator is deleted. 16 | // 17 | // The result does no duplicate suppression. I.e., if a particular 18 | // key is present in K child iterators, it will be yielded K times. 19 | // 20 | // REQUIRES: n >= 0 21 | extern Iterator* NewMergingIterator( 22 | const Comparator* comparator, Iterator** children, int n); 23 | 24 | } // namespace leveldb 25 | 26 | #endif // STORAGE_LEVELDB_TABLE_MERGER_H_ 27 | -------------------------------------------------------------------------------- /others/tmi/include/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009, 2010, 2011 Lockless Inc., Steven Von Fuerst. 3 | * 4 | * This library is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* Pick compiler specific details */ 19 | #ifdef __linux__ 20 | #include "gcc.h" 21 | #else 22 | #ifdef _MSC_VER 23 | #include "vs.h" 24 | #else 25 | #include "ming.h" 26 | #endif 27 | #endif 28 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/include/leveldb/dumpfile.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 7 | 8 | #include 9 | #include "leveldb/env.h" 10 | #include "leveldb/status.h" 11 | 12 | namespace leveldb { 13 | 14 | // Dump the contents of the file named by fname in text format to 15 | // *dst. Makes a sequence of dst->Append() calls; each call is passed 16 | // the newline-terminated text corresponding to a single item found 17 | // in the file. 18 | // 19 | // Returns a non-OK result if fname does not name a leveldb storage 20 | // file, or if the file cannot be read. 21 | Status DumpFile(Env* env, const std::string& fname, WritableFile* dst); 22 | 23 | } // namespace leveldb 24 | 25 | #endif // STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 26 | -------------------------------------------------------------------------------- /test_suites/tensor/Makefile: -------------------------------------------------------------------------------- 1 | INST := 1 2 | 3 | all: tensor 4 | 5 | false_bc: false.c 6 | clang -c -emit-llvm false.c -o false.bc 7 | ifdef INST 8 | opt -load ./LLVMInstrumenter.so -instrumenter < false.bc > false_inst.bc 2> build_false.log 9 | mv false_inst.bc false.bc 10 | endif 11 | 12 | false: false_bc 13 | llc -filetype=obj false.bc -o false.o 14 | ifdef INST 15 | gcc false.o -Wl,./libruntime.so -lpthread -o false 16 | else 17 | gcc false.o -lpthread -o false 18 | endif 19 | 20 | tensor_bc: tensor_parallel.cpp 21 | clang++ -c -emit-llvm -std=c++11 -I ../eigen/ -DEIGEN_USE_THREADS tensor_parallel.cpp -o tensor.bc 22 | ifdef INST 23 | opt -load ./LLVMInstrumenter.so -instrumenter < tensor.bc > tensor_inst.bc 2> build_tensor.log 24 | # mv tensor_inst.bc tensor.bc 25 | endif 26 | 27 | tensor: tensor_bc 28 | llc -filetype=obj tensor_inst.bc -o tensor.o 29 | ifdef INST 30 | g++ tensor.o -Wl,./libruntime.so -lpthread -o tensor 31 | else 32 | g++ tensor.o -lpthread -o tensor 33 | endif 34 | 35 | clean: 36 | rm -f *.bc *.o false tensor 37 | -------------------------------------------------------------------------------- /unroll.md: -------------------------------------------------------------------------------- 1 | ## Difficulties with Partial Unrolling 2 | 3 | 1. How can we know where to start the loop and where to end it? `for i = 0 to 100` doesnot create any problem, however, `for i = a[b] to a [c]` will create a problem. How can we identify this start address. 4 | 5 | 2. How can we make thread distributed loops deterministic? For example, 6 | ``` 7 | lock.lock() 8 | for x[next] to x[next+dist] 9 | do something 10 | next = next+dist+1 11 | lock.unlock() 12 | ``` 13 | What happens here due to race condition? Intuitive solution: Assign priorities among threads. 14 | 15 | 3. How to identify non-logged instruction pointers where falsely shared memory address is accessed? We started logging a memory location only when its corresponding cacheline is accessed by at least two threads and one of them is writing to it. So there are some memory accesses to those false shared memory address that was not logged during our first pass. How do we identify them at the second pass. Intuitive solution: Run three pass, on the second pass identify these locations. 16 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/env_posix_test_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 6 | #define STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class EnvPosixTest; 11 | 12 | // A helper for the POSIX Env to facilitate testing. 13 | class EnvPosixTestHelper { 14 | private: 15 | friend class EnvPosixTest; 16 | 17 | // Set the maximum number of read-only files that will be opened. 18 | // Must be called before creating an Env. 19 | static void SetReadOnlyFDLimit(int limit); 20 | 21 | // Set the maximum number of read-only files that will be mapped via mmap. 22 | // Must be called before creating an Env. 23 | static void SetReadOnlyMMapLimit(int limit); 24 | }; 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 29 | -------------------------------------------------------------------------------- /kmeans_repair/toy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define THREAD_COUNT 16 5 | #define TOTAL 1024 6 | #define ITER 1000000 7 | 8 | int *dynMemory; 9 | 10 | void *run(void *ptr) 11 | { 12 | int start = *((int *)ptr); 13 | for(int i = start; i < TOTAL; i+= THREAD_COUNT) 14 | { 15 | for(int j = 0; j < ITER; j++) 16 | { 17 | if(j == 0)dynMemory[i]=0; 18 | else { 19 | if(j%2)dynMemory[i]+=1; 20 | else dynMemory[i]+=2; 21 | } 22 | } 23 | } 24 | pthread_exit(NULL); 25 | } 26 | 27 | int main(void) 28 | { 29 | dynMemory = new int[TOTAL]; 30 | pthread_t threads[THREAD_COUNT]; 31 | int *params = new int[THREAD_COUNT]; 32 | for (int i = 0; i < THREAD_COUNT; i++) 33 | { 34 | params[i]=i; 35 | pthread_create(&threads[i], NULL, run, ((void *)(¶ms[i]))); 36 | } 37 | for (int i = 0; i < THREAD_COUNT; i++) 38 | { 39 | pthread_join(threads[i], NULL); 40 | } 41 | /*for(int i =0; i < TOTAL; i++) 42 | { 43 | printf("%d\n",dynMemory[i]); 44 | }*/ 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /others/tmi/src/llalloc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define TMISO_NAME "src/.libs/libllalloc.so" 8 | 9 | char *period = nullptr; 10 | char *windowSize = nullptr; 11 | char *outputPath = nullptr; 12 | 13 | static void addArg(const char *name, char *value) 14 | { 15 | if(value != nullptr){ 16 | setenv(name,value,1); 17 | } 18 | } 19 | 20 | static int run_child(int argc, char* argv[]) 21 | { 22 | char *prefix = getenv("TMI_PREFIX"); 23 | if (!prefix) 24 | _exit(1); 25 | setenv("LD_PRELOAD", (std::string(prefix) + "/" + TMISO_NAME).c_str(), 1); 26 | 27 | for(int c = 1; c < argc; c++){ 28 | argv[c-1] = argv[c]; 29 | } 30 | argv[argc-1] = nullptr; 31 | 32 | execvp(argv[0], argv); 33 | printf("execvp failed!\n"); 34 | return -1; 35 | } 36 | 37 | int main(int argc, char* argv[]) 38 | { 39 | if(argc < 2) { 40 | printf("Syntax error: %s [args...]\n",argv[0]); 41 | return -1; 42 | } 43 | 44 | return run_child(argc,argv); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /others/tmi/src/tmialloc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define TMISO_NAME "src/.libs/libtmialloc.so" 8 | 9 | char *period = nullptr; 10 | char *windowSize = nullptr; 11 | char *outputPath = nullptr; 12 | 13 | static void addArg(const char *name, char *value) 14 | { 15 | if(value != nullptr){ 16 | setenv(name,value,1); 17 | } 18 | } 19 | 20 | static int run_child(int argc, char* argv[]) 21 | { 22 | char *prefix = getenv("TMI_PREFIX"); 23 | if (!prefix) 24 | _exit(1); 25 | setenv("LD_PRELOAD", (std::string(prefix) + "/" + TMISO_NAME).c_str(), 1); 26 | 27 | for(int c = 1; c < argc; c++){ 28 | argv[c-1] = argv[c]; 29 | } 30 | argv[argc-1] = nullptr; 31 | 32 | execvp(argv[0], argv); 33 | printf("execvp failed!\n"); 34 | return -1; 35 | } 36 | 37 | int main(int argc, char* argv[]) 38 | { 39 | if(argc < 2) { 40 | printf("Syntax error: %s [args...]\n",argv[0]); 41 | return -1; 42 | } 43 | 44 | return run_child(argc,argv); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/log_format.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Log format information shared by reader and writer. 6 | // See ../doc/log_format.md for more detail. 7 | 8 | #ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 9 | #define STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 10 | 11 | namespace leveldb { 12 | namespace log { 13 | 14 | enum RecordType { 15 | // Zero is reserved for preallocated files 16 | kZeroType = 0, 17 | 18 | kFullType = 1, 19 | 20 | // For fragments 21 | kFirstType = 2, 22 | kMiddleType = 3, 23 | kLastType = 4 24 | }; 25 | static const int kMaxRecordType = kLastType; 26 | 27 | static const int kBlockSize = 32768; 28 | 29 | // Header is checksum (4 bytes), length (2 bytes), type (1 byte). 30 | static const int kHeaderSize = 4 + 2 + 1; 31 | 32 | } // namespace log 33 | } // namespace leveldb 34 | 35 | #endif // STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 36 | -------------------------------------------------------------------------------- /others/tmi/src/tmilib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "tmi.h" 10 | 11 | extern "C"{ 12 | void die(const char* msg, ...) 13 | { 14 | va_list ap; 15 | va_start(ap, msg); 16 | vfprintf(stderr, msg, ap); 17 | exit(-1); 18 | } 19 | 20 | pid_t gettid( void ) 21 | { 22 | return syscall( __NR_gettid ); 23 | } 24 | 25 | void sch_write(int fd, SCH_EVT_TYPE type, pid_t mpid, pid_t pid, void* data) 26 | { 27 | int old_errno; 28 | sch_evt_t evt; 29 | evt.type = type; 30 | evt.mpid = mpid; 31 | evt.pid = pid; 32 | evt.data = data; 33 | old_errno = errno; 34 | MUST(write(fd, &evt, sizeof(evt)) == sizeof(evt)); 35 | errno = old_errno; 36 | } 37 | 38 | #define XXX_LIBRARY_CUTOFF 0x100000000000 39 | int is_system_library(void* address) 40 | { 41 | // XXX: should be fixed to a decent impl) 42 | return ((uintptr_t)address) >= XXX_LIBRARY_CUTOFF; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /parse_perf_drop_sigv.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | hitm_name = "mem_load_l3_hit_retired_xsnp_hitm" 5 | regex = r"\s+([\d,]+)\s+cache-misses.+\n\s+([\d,]+)\s+" + hitm_name + r".+\s+([\d\.]+)" 6 | 7 | with open(sys.argv[1], "r") as file: 8 | lines = file.readlines() 9 | valid_lines = [] 10 | i = 0 11 | while i < len(lines): 12 | if 'Segmentation fault' in lines[i]: 13 | i += 8 14 | else: 15 | valid_lines.append(lines[i]) 16 | i += 1 17 | filtered_str = ''.join(valid_lines) 18 | matches = re.finditer(regex, filtered_str, re.MULTILINE) 19 | hitms = [] 20 | times = [] 21 | for match in matches: 22 | _, hitm_str, time_str = match.groups() 23 | hitm_str = hitm_str.replace(",", "") 24 | hitms.append(int(hitm_str)) 25 | times.append(float(time_str)) 26 | hitms = hitms[:200] 27 | times = times[:200] 28 | avg_time = sum(times) / len(hitms) 29 | avg_hitm = sum(hitms) / len(times) 30 | print("samples = %d, avg_time = %.10f, avg_hitm = %d" % (len(hitms), avg_time, avg_hitm)) 31 | -------------------------------------------------------------------------------- /others/tmi/src/Makefile.am: -------------------------------------------------------------------------------- 1 | CFLAGS += -I../include -g -O2 2 | CXXFLAGS += -std=c++11 -I../include/ -g -O2 3 | LIBS += -ldl -lelf -lrt -lpthread 4 | 5 | bin_PROGRAMS = tmildr tmidetector tmialloc llalloc 6 | lib_LTLIBRARIES = libtmi.la libtmiprotect.la libtmialloc.la libllalloc.la 7 | 8 | tmialloc_SOURCES = tmialloc.cpp 9 | 10 | llalloc_SOURCES = llalloc.cpp 11 | 12 | tmildr_SOURCES = tmildr.cpp tmilib.cpp 13 | tmildr_CXXFLAGS = -DTMI_PROTECT 14 | 15 | tmidetector_SOURCES = tmidetector.cpp 16 | 17 | libllalloc_la_SOURCES = ll_alloc_original.c 18 | 19 | libtmi_la_SOURCES = detector.cpp perf.cpp libtmi.cpp tmithread.cpp hooks.cpp tmiutil.cpp tmimem.cpp ll_alloc.c 20 | 21 | libtmiprotect_la_SOURCES = detector.cpp perf.cpp libtmi.cpp tmimem.cpp ll_alloc.c tmithread.cpp tmisync.cpp hooks.cpp tmiutil.cpp internalmem.cpp timers.cpp 22 | #libtmiprotect_la_SOURCES = detector.cpp perf.cpp libtmi.cpp tmimem.cpp ll_alloc.c tmithread.cpp tmiutil.cpp internalmem.cpp 23 | libtmiprotect_la_CXXFLAGS = -DTMI_PROTECT 24 | 25 | libtmialloc_la_SOURCES = tmimem.cpp ll_alloc.c internalmem.cpp tmisync.cpp hooks.cpp tmiutil.cpp 26 | -------------------------------------------------------------------------------- /others/tmi/tests/test_fork.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(){ 8 | char fname[100]; 9 | sprintf(fname,"/tmp/tmi-backing-XXXXXX"); 10 | int backingFd = mkstemp(fname); 11 | if(backingFd == -1){ 12 | perror("Failed to make backing file\n"); 13 | return 1; 14 | } 15 | 16 | int pagesize = getpagesize(); 17 | 18 | if(ftruncate(backingFd,pagesize)){ 19 | perror("ftruncate: "); 20 | return 1; 21 | } 22 | 23 | void *p = malloc(pagesize); 24 | 25 | int *data = (int*)p; 26 | data[0] = 5; 27 | 28 | void* ret = mmap((void*)data,sizeof(int) * 1024, PROT_READ | PROT_WRITE, 29 | MAP_SHARED | MAP_FIXED,backingFd,0); 30 | 31 | if(ret == MAP_FAILED){ 32 | perror("MMAP: "); 33 | return 1; 34 | } 35 | 36 | printf("%p - %p\n",(void*)data,ret); 37 | 38 | if(fork() == 0){ 39 | data[0] = 20; 40 | printf("Changed data[0]\n"); 41 | }else{ 42 | sleep(5); 43 | printf("%d\n",data[0]); 44 | } 45 | 46 | munmap(data,pagesize); 47 | 48 | close(backingFd); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/histogram.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 6 | #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Histogram { 13 | public: 14 | Histogram() { } 15 | ~Histogram() { } 16 | 17 | void Clear(); 18 | void Add(double value); 19 | void Merge(const Histogram& other); 20 | 21 | std::string ToString() const; 22 | 23 | private: 24 | double min_; 25 | double max_; 26 | double num_; 27 | double sum_; 28 | double sum_squares_; 29 | 30 | enum { kNumBuckets = 154 }; 31 | static const double kBucketLimit[kNumBuckets]; 32 | double buckets_[kNumBuckets]; 33 | 34 | double Median() const; 35 | double Percentile(double p) const; 36 | double Average() const; 37 | double StandardDeviation() const; 38 | }; 39 | 40 | } // namespace leveldb 41 | 42 | #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 43 | -------------------------------------------------------------------------------- /others/tmi/tests/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #define N 2000000000 9 | #define I 10 10 | 11 | class data{ 12 | public: 13 | long x; 14 | long y; 15 | long z; 16 | }; 17 | 18 | void* worker1(void *arg){ 19 | data *d = (data*)arg; 20 | for(int i = 0; i < I; i++){ 21 | for(int c = 0; c < N; c++){ 22 | d->x++; 23 | } 24 | } 25 | std::cout << "Iter1: " << d->x << "\n"; 26 | return 0; 27 | } 28 | 29 | void* worker2(void *arg){ 30 | data *d = (data*)arg; 31 | for(int i = 0; i < I; i++){ 32 | for(int c = 0; c < N; c++){ 33 | d->y++; 34 | } 35 | } 36 | std::cout << "Iter2: " << d->y << "\n"; 37 | return 0; 38 | } 39 | 40 | int main(){ 41 | data *d = new data; 42 | d->x = 0; 43 | d->y = 0; 44 | 45 | pthread_t t1, t2; 46 | 47 | pthread_create(&t1,0,worker1,(void*)d); 48 | pthread_create(&t2,0,worker2,(void*)d); 49 | 50 | pthread_join(t1,0); 51 | pthread_join(t2,0); 52 | 53 | d->z = 5; 54 | 55 | std::cout << d->x << "," << d->y << "\n"; 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /others/tmi/include/tmithread.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "perf.hpp" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | class tmi_thread{ 12 | int _tid; // Set using gettid() or getpid() 13 | int _pid; 14 | bool _is_process; 15 | 16 | public: 17 | pthread_t _pthreadid; 18 | void *(*_start_routine)(void*); 19 | void *_arg; 20 | void *_tramp; 21 | 22 | pthread_mutex_t _wait_forever_lock; 23 | pthread_cond_t _wait_forever_cond; 24 | 25 | pthread_mutex_t _wait_lock; 26 | pthread_cond_t _wait_cond; 27 | 28 | sem_t * _wait_sem; 29 | 30 | void *_ret; 31 | 32 | private: 33 | Perf *_perf; 34 | int _sample_period; 35 | 36 | std::atomic _isRunning; 37 | 38 | public: 39 | tmi_thread(void *(start_routine)(void*), void *arg); 40 | 41 | void set_tid(int tid); 42 | int get_tid(); 43 | 44 | bool is_process(); 45 | 46 | bool init_perf(int sample_period); 47 | Perf* get_perf(); 48 | void cleanup_perf_thread(); 49 | 50 | void set_as_process(int new_tid); 51 | 52 | void waitOriginalThread(); 53 | void doExit(int errcode = 0); 54 | bool waitOn(); 55 | }; 56 | -------------------------------------------------------------------------------- /others/tmi/include/perf.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __AE_PERF_HPP__ 2 | #define __AE_PERF_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | #define BUF_BITS 8 8 | #define SAMPLE_PERIOD_DEFAULT 1 9 | #define WINDOW_SIZE_DEFAULT 1000000 10 | #define EVENTID 0x4D2 11 | 12 | struct DataRecord 13 | { 14 | uint64_t time; 15 | void* ip; 16 | void* data; 17 | int tid; 18 | }; 19 | 20 | class Perf 21 | { 22 | public: 23 | Perf(int sample_period); 24 | ~Perf(); 25 | 26 | public: 27 | bool open(bool enable = true); 28 | bool enable(); 29 | bool disable(); 30 | void finalize(); 31 | bool is_done(); 32 | 33 | public: 34 | bool start_iterate(); 35 | bool next(DataRecord* dr); 36 | void abort_iterate(); 37 | 38 | void set_pid(int pid); 39 | int get_pid(); 40 | 41 | private: 42 | friend class PerfIterator; 43 | 44 | int _pid; 45 | unsigned int _page_size, _buf_size, _buf_mask; 46 | int _sample_period; 47 | struct perf_event_attr _attr; 48 | struct perf_event_mmap_page *_mpage; 49 | char *_data, *_data_end; 50 | int _fd; 51 | 52 | int _lost; 53 | 54 | bool _done; 55 | 56 | uint64_t _head, _tail; 57 | }; 58 | 59 | 60 | #endif // __AE_PERF_HPP__ 61 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/table/block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_H_ 7 | 8 | #include 9 | #include 10 | #include "leveldb/iterator.h" 11 | 12 | namespace leveldb { 13 | 14 | struct BlockContents; 15 | class Comparator; 16 | 17 | class Block { 18 | public: 19 | // Initialize the block with the specified contents. 20 | explicit Block(const BlockContents& contents); 21 | 22 | ~Block(); 23 | 24 | size_t size() const { return size_; } 25 | Iterator* NewIterator(const Comparator* comparator); 26 | 27 | private: 28 | uint32_t NumRestarts() const; 29 | 30 | const char* data_; 31 | size_t size_; 32 | uint32_t restart_offset_; // Offset in data_ of restart array 33 | bool owned_; // Block owns data_[] 34 | 35 | // No copying allowed 36 | Block(const Block&); 37 | void operator=(const Block&); 38 | 39 | class Iter; 40 | }; 41 | 42 | } // namespace leveldb 43 | 44 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_ 45 | -------------------------------------------------------------------------------- /test_suites/histogram/README: -------------------------------------------------------------------------------- 1 | Phoenix Project 2 | Historgram Example Application Readme 3 | Last revised 15th April 2007 4 | 5 | 6 | 1. Application Overview 7 | ----------------------- 8 | 9 | The histogram application generates the histogram of frequencies of pixel values 10 | in the red, green and blue channels of a bitmap picture. 11 | 12 | 13 | 2. Provided Files 14 | ----------------- 15 | 16 | hist.c: The version of the file that uses the MapReduce engine 17 | hist-seq.c: The sequential version of the application 18 | hist-pthread.c: The pthread version of the application 19 | stddefines.h: Contains declarations of commonly used functions and constants 20 | MapReduceScheduler.c/h: The MapReduce engine used by the application 21 | Makefile: Compiles all 3 versions of the application 22 | datafiles/*.bmp: Sample bitmap files of varying sizes that can be used as 23 | input to this application 24 | README: This file 25 | 26 | 27 | 3. Running the Application 28 | -------------------------- 29 | 30 | run 'make' to compile all 3 versions of the application. 31 | 32 | ./hist 33 | ./hist-pthread 34 | ./hist-seq 35 | 36 | runs the MapReduce, Pthreads and sequential version of the application 37 | respectively 38 | 39 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_BUILDER_H_ 6 | #define STORAGE_LEVELDB_DB_BUILDER_H_ 7 | 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | 12 | struct Options; 13 | struct FileMetaData; 14 | 15 | class Env; 16 | class Iterator; 17 | class TableCache; 18 | class VersionEdit; 19 | 20 | // Build a Table file from the contents of *iter. The generated file 21 | // will be named according to meta->number. On success, the rest of 22 | // *meta will be filled with metadata about the generated table. 23 | // If no data is present in *iter, meta->file_size will be set to 24 | // zero, and no Table file will be produced. 25 | extern Status BuildTable(const std::string& dbname, 26 | Env* env, 27 | const Options& options, 28 | TableCache* table_cache, 29 | Iterator* iter, 30 | FileMetaData* meta); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_ 35 | -------------------------------------------------------------------------------- /others/tmi/src/tmiutil.cpp: -------------------------------------------------------------------------------- 1 | #include "tmiutil.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | void tmiutil::init_mutex(pthread_mutex_t *mutex) 12 | { 13 | pthread_mutexattr_t attr {0}; 14 | assert(pthread_mutexattr_setpshared(&attr, 15 | PTHREAD_PROCESS_SHARED) 16 | == 0); 17 | assert(orig_pthread_mutex_init(mutex,&attr) == 0); 18 | } 19 | 20 | void tmiutil::init_cond(pthread_cond_t *cond) 21 | { 22 | pthread_condattr_t attr; 23 | assert(pthread_condattr_init(&attr) == 0); 24 | assert(pthread_condattr_setpshared(&attr, 25 | PTHREAD_PROCESS_SHARED) 26 | == 0); 27 | orig_pthread_cond_init(cond,&attr); 28 | } 29 | 30 | void tmiutil::init_spinlock(pthread_spinlock_t *mutex) 31 | { 32 | orig_pthread_spin_init(mutex,PTHREAD_PROCESS_SHARED); 33 | } 34 | 35 | void* tmiutil::alignAddressToPage(void *addr) 36 | { 37 | #ifdef TMI_USING_HUGEPAGES 38 | size_t num = (size_t)addr; 39 | // 0x0000000000200000 40 | // 0x00007faf35c00000 41 | num = num & (0xFFFFFFFFFFC00000); 42 | return (void*)num; 43 | #else 44 | size_t num = (size_t)addr; 45 | num = num & (0xFFFFFFFFFFFFF000); 46 | return (void*)num; 47 | #endif 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/jld.mak: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #time out-static/db_bench --threads=4 --benchmarks=fillbatch,readseq 4 | #time out-static/db_bench --threads=4 --db=/mnt/ramdisk/test.db --benchmarks=fillbatch,readseq 5 | 6 | #time out-static/db_fs_bench-buggy --threads=4 --benchmarks=fillbatch,readseq 7 | #time out-static/db_fs_bench-fixed --threads=4 --benchmarks=fillbatch,readseq 8 | 9 | DB_NAME=/mnt/ramdisk/tmi-benchmark.leveldb 10 | DB_SIZE=--num=10000000 --value_size=2 11 | SEQ_READ_ARGS=--threads=4 --benchmarks=readseq $(DB_SIZE) --use_existing_db=1 12 | 13 | CRC_ARGS=--threads=4 --benchmarks=crc32c 14 | 15 | NUM_TRIALS=15 16 | 17 | #FILTER_OUTPUT=2> /dev/null | tail -n1 18 | FILTER_OUTPUT= 19 | 20 | init: 21 | read -p "delete $(DB_NAME)? " IGNORE_RESULT 22 | rm -rf $(DB_NAME) 23 | out-static/db_fs_bench-fixed $(DB_SIZE) --benchmarks=fillbatch --db=$(DB_NAME) 24 | 25 | tmi: 26 | sudo ~/timen.py --iters $(NUM_TRIALS) --log ~/leveldb.tmi.times ~/tmi/build/bin/tmildr out-static/db_fs_bench-buggy $(CRC_ARGS) $(FILTER_OUTPUT) 27 | 28 | buggy: 29 | ~/timen.py --iters $(NUM_TRIALS) --log ~/leveldb.buggy.times out-static/db_fs_bench-buggy $(CRC_ARGS) $(FILTER_OUTPUT) 30 | 31 | fixed: 32 | ~/timen.py --iters $(NUM_TRIALS) --log ~/leveldb.fixed.times out-static/db_fs_bench-fixed $(CRC_ARGS) $(FILTER_OUTPUT) 33 | -------------------------------------------------------------------------------- /others/tmi/src/timers.cpp: -------------------------------------------------------------------------------- 1 | #include "timers.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | unsigned long *timers::_segvTime = 0; 8 | unsigned long *timers::_commitTime = 0; 9 | 10 | clock_type::time_point timers::_startSegv; 11 | clock_type::time_point timers::_startCommit; 12 | 13 | void timers::initTimer(int name) 14 | { 15 | void *locs = mmap(0,4096,PROT_READ | PROT_WRITE, 16 | MAP_ANONYMOUS | MAP_SHARED,0,0); 17 | 18 | _segvTime = (unsigned long*)locs; 19 | _commitTime = _segvTime + 1; 20 | } 21 | 22 | void timers::startTimer(int name) 23 | { 24 | #ifdef TMI_TIMERS 25 | if(name == 1){ 26 | _startSegv = clock_type::now(); 27 | }else if(name == 2){ 28 | _startCommit = clock_type::now(); 29 | } 30 | #endif 31 | } 32 | 33 | void timers::stopTimer(int name) 34 | { 35 | #ifdef TMI_TIMERS 36 | clock_type::time_point end = clock_type::now(); 37 | 38 | auto t = end - _startSegv; 39 | 40 | if(name == 1){ 41 | *_segvTime += (end - _startSegv).count(); 42 | }else if (name == 2){ 43 | *_commitTime += (end - _startCommit).count(); 44 | } 45 | #endif 46 | } 47 | 48 | void timers::printTimers() 49 | { 50 | #ifdef TMI_TIMERS 51 | fprintf(stderr,"SEGV: %lu\n",*_segvTime); 52 | fprintf(stderr,"COMMIT: %lu\n",*_commitTime); 53 | #endif 54 | } 55 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/mutexlock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 6 | #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 7 | 8 | #include "port/port.h" 9 | #include "port/thread_annotations.h" 10 | 11 | namespace leveldb { 12 | 13 | // Helper class that locks a mutex on construction and unlocks the mutex when 14 | // the destructor of the MutexLock object is invoked. 15 | // 16 | // Typical usage: 17 | // 18 | // void MyClass::MyMethod() { 19 | // MutexLock l(&mu_); // mu_ is an instance variable 20 | // ... some complex code, possibly with multiple return paths ... 21 | // } 22 | 23 | class SCOPED_LOCKABLE MutexLock { 24 | public: 25 | explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu) 26 | : mu_(mu) { 27 | this->mu_->Lock(); 28 | } 29 | ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); } 30 | 31 | private: 32 | port::Mutex *const mu_; 33 | // No copying allowed 34 | MutexLock(const MutexLock&); 35 | void operator=(const MutexLock&); 36 | }; 37 | 38 | } // namespace leveldb 39 | 40 | 41 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 42 | -------------------------------------------------------------------------------- /others/tmi/README: -------------------------------------------------------------------------------- 1 | TMI provides false-sharing detection and protection capabilities for native 2 | applications (C,C++,Assembly). 3 | 4 | For detection only, TMI adds an additional thread and an additional perf object 5 | per thread that tracks the HITM events produced by each thread. 6 | 7 | Build Parameters 8 | ---------- 9 | 10 | TMI_USING_MKSTEMP: Use the mkstemp function to create a shared file instead of 11 | using shm_open. This was found to be necessary for some applications such as 12 | parsec.facesim. 13 | 14 | TMI_PROTECT: Enables the TMI protection mechanisms 15 | 16 | Environment Parameters 17 | ---------- 18 | 19 | TMI_SAMPLE_PERIOD: How frequently events are reported from the Intel 20 | hardware counters back to the TMI false-sharing detector (e.g. 21 | TMI_SAMPLE_PERIOD=1000 means that every 1000th HITM event will be 22 | sent to the detector) 23 | 24 | TMI_WINDOW_SIZE: How frequently the detector state is cleared 25 | (e.g. TMI_WINDOW_SIZE=100 means that every 100th HITM event will 26 | cause the detector's state to be cleared) 27 | 28 | TMI_EXE_NAME: Name of the executable being run (only necessary when 29 | running as an LD_PRELOAD library, otherwise will be detected from 30 | command-line options) (only for detector output purposes) 31 | 32 | TMI_OUTPUT_PATH: Path to output detector results to (defaults to 33 | /scratch/results) -------------------------------------------------------------------------------- /test_suites/boost_test/spinlock.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_DETAIL_SPINLOCK_PT_HPP_INCLUDED 2 | #define BOOST_DETAIL_SPINLOCK_PT_HPP_INCLUDED 3 | 4 | // MS compatible compilers support #pragma once 5 | 6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 7 | # pragma once 8 | #endif 9 | 10 | // 11 | // Copyright (c) 2008 Peter Dimov 12 | // 13 | // Distributed under the Boost Software License, Version 1.0. 14 | // See accompanying file LICENSE_1_0.txt or copy at 15 | // http://www.boost.org/LICENSE_1_0.txt) 16 | // 17 | 18 | #include 19 | 20 | class spinlock 21 | { 22 | std::atomic_flag locked; 23 | 24 | public: 25 | void lock() { 26 | while (locked.test_and_set(std::memory_order_acquire)) { ; } 27 | } 28 | 29 | void unlock() { 30 | locked.clear(std::memory_order_release); 31 | } 32 | 33 | public: 34 | 35 | class scoped_lock 36 | { 37 | private: 38 | 39 | spinlock & sp_; 40 | 41 | scoped_lock( scoped_lock const & ); 42 | scoped_lock & operator=( scoped_lock const & ); 43 | 44 | public: 45 | 46 | explicit scoped_lock( spinlock & sp ): sp_( sp ) 47 | { 48 | sp.lock(); 49 | } 50 | 51 | ~scoped_lock() 52 | { 53 | sp_.unlock(); 54 | } 55 | }; 56 | }; 57 | 58 | #endif // #ifndef BOOST_DETAIL_SPINLOCK_PT_HPP_INCLUDED 59 | -------------------------------------------------------------------------------- /others/tmi/include/detector/SharingEventType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define NumberOfTrackedEvents 4 3 | 4 | enum SharingEventType : int 5 | { 6 | TSWR = 0, 7 | TSWW = 1, 8 | FSWR = 2, 9 | FSWW = 3, 10 | Other = -1 11 | }; 12 | 13 | std::string EventTypeToPrintableName(SharingEventType type) 14 | { 15 | switch (type) 16 | { 17 | case TSWR: 18 | return "TSWR"; 19 | case TSWW: 20 | return "TSWW"; 21 | return "FSRW"; 22 | case FSWR: 23 | return "FSWR"; 24 | case FSWW: 25 | return "FSWW"; 26 | case Other: 27 | return "Other"; 28 | default: 29 | return "!INVALID!"; 30 | } 31 | } 32 | 33 | int EventTypeToIndex(SharingEventType type) 34 | { 35 | switch (type) 36 | { 37 | case SharingEventType::TSWR: 38 | return 0; 39 | case SharingEventType::TSWW: 40 | return 1; 41 | case SharingEventType::FSWR: 42 | return 2; 43 | case SharingEventType::FSWW: 44 | return 3; 45 | default: 46 | return -1; 47 | } 48 | } 49 | 50 | //might need to enable FSRWWR TSRWWR in the future. Retain this fast mapping. 51 | SharingEventType IndexToEventType(int index) 52 | { 53 | switch (index) 54 | { 55 | case 0: 56 | return SharingEventType::TSWR; 57 | case 1: 58 | return SharingEventType::TSWW; 59 | case 2: 60 | return SharingEventType::FSWR; 61 | case 3: 62 | return SharingEventType::FSWW; 63 | default: 64 | return SharingEventType::Other; 65 | } 66 | } -------------------------------------------------------------------------------- /others/tmi/tests/test_locks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #define N 10000000 9 | #define I 10 10 | 11 | pthread_mutex_t lock; 12 | 13 | class data{ 14 | public: 15 | long x; 16 | long y; 17 | long z; 18 | }; 19 | 20 | void* worker1(void *arg){ 21 | data *d = (data*)arg; 22 | for(int i = 0; i < I; i++){ 23 | for(int c = 0; c < N; c++){ 24 | pthread_mutex_lock(&lock); 25 | d->x++; 26 | pthread_mutex_unlock(&lock); 27 | } 28 | } 29 | std::cout << "Iter1: " << d->x << "\n"; 30 | return 0; 31 | } 32 | 33 | void* worker2(void *arg){ 34 | data *d = (data*)arg; 35 | for(int i = 0; i < I; i++){ 36 | for(int c = 0; c < N; c++){ 37 | pthread_mutex_lock(&lock); 38 | d->y++; 39 | pthread_mutex_unlock(&lock); 40 | } 41 | } 42 | std::cout << "Iter2: " << d->y << "\n"; 43 | return 0; 44 | } 45 | 46 | int main(){ 47 | data *d = new data; 48 | d->x = 0; 49 | d->y = 0; 50 | 51 | pthread_mutex_init(&lock,NULL); 52 | 53 | pthread_t t1, t2; 54 | 55 | pthread_create(&t1,0,worker1,(void*)d); 56 | pthread_create(&t2,0,worker2,(void*)d); 57 | 58 | pthread_join(t1,0); 59 | pthread_join(t2,0); 60 | 61 | d->z = 5; 62 | 63 | std::cout << d->x << "," << d->y << "\n"; 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/tmi-run-leveldb.mak: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #time out-static/db_bench --threads=4 --benchmarks=fillbatch,readseq 4 | #time out-static/db_bench --threads=4 --db=/mnt/ramdisk/test.db --benchmarks=fillbatch,readseq 5 | 6 | #time out-static/db_fs_bench-buggy --threads=4 --benchmarks=fillbatch,readseq 7 | #time out-static/db_fs_bench-fixed --threads=4 --benchmarks=fillbatch,readseq 8 | 9 | DB_NAME=/mnt/ramdisk/leveldb/tmi-benchmark.leveldb 10 | DB_SIZE=--num=10000000 --value_size=2 --db=$(DB_NAME) 11 | SEQ_READ_ARGS=--threads=4 --benchmarks=readseq $(DB_SIZE) --use_existing_db=1 12 | 13 | CRC_ARGS=--threads=4 --benchmarks=crc32c 14 | 15 | NUM_TRIALS=15 16 | 17 | #FILTER_OUTPUT=2> /dev/null | tail -n1 18 | FILTER_OUTPUT= 19 | 20 | init: 21 | read -p "delete $(DB_NAME)? " IGNORE_RESULT 22 | rm -rf $(DB_NAME) 23 | out-static/db_fs_bench-fixed $(DB_SIZE) --benchmarks=fillbatch 24 | 25 | tmi: 26 | sudo ~/timen.py --iters $(NUM_TRIALS) --log ~/leveldb-seqread.tmi.times ~/tmi/build/bin/tmildr out-static/db_fs_bench-buggy $(SEQ_READ_ARGS) $(FILTER_OUTPUT) 27 | 28 | buggy: 29 | ~/timen.py --iters $(NUM_TRIALS) --log ~/leveldb-seqread.buggy.times out-static/db_fs_bench-buggy $(SEQ_READ_ARGS) $(FILTER_OUTPUT) 30 | 31 | fixed: 32 | ~/timen.py --iters $(NUM_TRIALS) --log ~/leveldb-seqread.fixed.times out-static/db_fs_bench-fixed $(SEQ_READ_ARGS) $(FILTER_OUTPUT) 33 | -------------------------------------------------------------------------------- /test_suites/linear_regression/README: -------------------------------------------------------------------------------- 1 | Phoenix Project 2 | Linear Regression Example Application Readme 3 | Last revised 15th April 2007 4 | 5 | 6 | 1. Application Overview 7 | ----------------------- 8 | 9 | The linear regression application generates the summary statistics of points to 10 | give the linear approximation of all of the points. It reads the x-y coordinates 11 | sequentially from the specified file. 12 | 13 | 14 | 2. Provided Files 15 | ----------------- 16 | 17 | linear_regression.c: The version of the file that uses the MapReduce engine 18 | linear_regression_serial.c: The sequential version of the application 19 | linear_regression_pthread.c: The pthread version of the application 20 | stddefines.h: Contains declarations of commonly used functions and constants 21 | MapReduceScheduler.c/h: The MapReduce engine used by the application 22 | Makefile: Compiles all 3 versions of the application 23 | datafiles/key_file*.txt: Files of various sizes that contain input coordinates 24 | README: This file 25 | 26 | 27 | 3. Running the Application 28 | -------------------------- 29 | 30 | run 'make' to compile all 3 versions of the application. 31 | 32 | ./lreg 33 | ./lreg-pthread 34 | ./lreg-seq 35 | 36 | runs the MapReduce, Pthreads and sequential version of the application 37 | respectively 38 | 39 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/table/two_level_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | 10 | namespace leveldb { 11 | 12 | struct ReadOptions; 13 | 14 | // Return a new two level iterator. A two-level iterator contains an 15 | // index iterator whose values point to a sequence of blocks where 16 | // each block is itself a sequence of key,value pairs. The returned 17 | // two-level iterator yields the concatenation of all key/value pairs 18 | // in the sequence of blocks. Takes ownership of "index_iter" and 19 | // will delete it when no longer needed. 20 | // 21 | // Uses a supplied function to convert an index_iter value into 22 | // an iterator over the contents of the corresponding block. 23 | extern Iterator* NewTwoLevelIterator( 24 | Iterator* index_iter, 25 | Iterator* (*block_function)( 26 | void* arg, 27 | const ReadOptions& options, 28 | const Slice& index_value), 29 | void* arg, 30 | const ReadOptions& options); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 35 | -------------------------------------------------------------------------------- /postprocess/Detect.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yifanz on 7/29/18. 3 | // 4 | 5 | #ifndef POSTPROCESS_DETECT_H 6 | #define POSTPROCESS_DETECT_H 7 | 8 | #include "Stats.h" 9 | 10 | typedef std::tuple RecT; 11 | 12 | struct MallocOutput { 13 | std::vector accesses; 14 | PC pc; 15 | size_t size; 16 | 17 | MallocOutput(std::vector> &&accesses, 18 | std::pair &&malloc); 19 | 20 | MallocOutput() = default; 21 | 22 | friend std::ostream &operator<<(std::ostream &os, const MallocOutput &mo); 23 | 24 | friend std::istream &operator>>(std::istream &is, MallocOutput &mo); 25 | }; 26 | 27 | class MallocStorageT; 28 | 29 | class DetectPass { 30 | public: 31 | static const char *optionals; 32 | static const size_t n_opt; 33 | 34 | typedef std::vector ApiT; 35 | 36 | DetectPass(const std::string &in, const std::vector &rest); 37 | 38 | void compute(); 39 | 40 | ApiT get_api_output() const; 41 | 42 | void print_result(const std::string &out); 43 | 44 | ~DetectPass(); 45 | 46 | private: 47 | void check_in_files(); 48 | 49 | std::ifstream log_file, malloc_file; 50 | std::ofstream summary_file; 51 | size_t threshold; 52 | FSRankStat fsrStat; 53 | std::map data; 54 | }; 55 | 56 | #endif //POSTPROCESS_DETECT_H 57 | -------------------------------------------------------------------------------- /test_suites/lu_ncb/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Description: 4 | # 5 | # Runs the benchmark with a minimal problem size in a multiprocessor 6 | # simulator. 7 | # 8 | # Usage: 9 | # 10 | # ./run.sh [NUMPROCS] 11 | # 12 | 13 | #Some default values 14 | TARGET=lu_ncb 15 | 16 | #Arguments 17 | if [ -n "$1" ] 18 | then 19 | NUMPROCS="$1" 20 | fi 21 | 22 | if [ -n "$2" ] 23 | then 24 | INPUTSIZE="$2" 25 | fi 26 | 27 | 28 | if [ -n "$3" ] 29 | then 30 | echo "Error: Too many arguments!" 31 | echo 32 | head -n11 $0 | tail -n9 | sed 's/#//' 33 | exit 1 34 | fi 35 | 36 | 37 | #Determine program name, file names & arguments 38 | case "${INPUTSIZE}" in 39 | "test" ) 40 | PROGARGS="-p$NUMPROCS -n512 -b16";; 41 | "simdev" ) 42 | PROGARGS="-p$NUMPROCS -n512 -b16";; 43 | "simsmall" ) 44 | PROGARGS="-p$NUMPROCS -n512 -b16";; 45 | "simmedium" ) 46 | PROGARGS="-p$NUMPROCS -n1024 -b16";; 47 | "simlarge" ) 48 | PROGARGS="-p$NUMPROCS -n2048 -b16";; 49 | "native" ) 50 | PROGARGS="-p$NUMPROCS -n8096 -b32";; 51 | *) 52 | echo "Input size error" 53 | exit 1;; 54 | esac 55 | 56 | PROG="${PARSECDIR}/ext/splash2/kernels/${TARGET}/inst/${PARSECPLAT}/bin/${TARGET}" 57 | 58 | 59 | #Some tests 60 | if [ ! -x "$PROG" ] 61 | then 62 | echo "Error: Binary ${PROG} does not exist!" 63 | exit 1 64 | fi 65 | 66 | 67 | #Execution 68 | echo Generating input file ${INPUTFILE}... 69 | 70 | RUN="$PROG $PROGARGS" 71 | 72 | echo "Running $RUN:" 73 | eval $RUN 74 | 75 | 76 | -------------------------------------------------------------------------------- /test_suites/tensor/tensor_parallel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | /*void printResult() 7 | { 8 | int i,j; 9 | FILE *fp = fopen("tensor.txt", "w"); 10 | for(i=0;i>SIZE; 27 | char const *size_str = getenv("MSIZE"); 28 | int SIZE = size_str ? std::stoi(size_str) : 1000; 29 | //cout << SIZE << '\n'; 30 | 31 | Eigen::Tensor a(SIZE, SIZE); 32 | 33 | Eigen::Tensor b(SIZE, SIZE); 34 | 35 | Eigen::Tensor c(SIZE, SIZE); 36 | 37 | Eigen::array, 1> dimension = {Eigen::IndexPair(1, 0)}; 38 | Eigen::ThreadPool tpi(8); 39 | Eigen::ThreadPoolDevice my_device(&tpi, 8); 40 | // for(int i = 0; i < SIZE; i++) 41 | // { 42 | // for(int j = 0; j < SIZE; j++) 43 | // { 44 | // a(i,j) = i+j; 45 | // b(i,j) = i-j; 46 | // } 47 | // } 48 | c.device(my_device) = a.contract(b, dimension); 49 | //c1 = a1.contract(b1, dimension); 50 | /*cout<maxCnt) 42 | { 43 | maxCnt = Counters[i]; 44 | maxIdx = i; 45 | } 46 | } 47 | if (maxCnt == 0) return SharingEventType::Other; 48 | return IndexToEventType(maxIdx); 49 | } 50 | 51 | CategoryCounter CategoryCounter::Merge(CategoryCounter other) 52 | { 53 | CategoryCounter newCounter; 54 | for (int i = 0; i < NumberOfTrackedEvents; i++) 55 | { 56 | newCounter.Counters[i] = Counters[i] + other.Counters[i]; 57 | } 58 | return newCounter; 59 | } 60 | -------------------------------------------------------------------------------- /postprocess/Repair.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yifanz on 7/10/18. 3 | // 4 | 5 | #ifndef POSTPROCESS_REPAIR_H 6 | #define POSTPROCESS_REPAIR_H 7 | 8 | #include 9 | #include "Utils.h" 10 | #include "Detect.h" 11 | 12 | class AnalysisResult { 13 | public: 14 | AnalysisResult() = default; 15 | 16 | void read_from_file(std::ifstream &is); 17 | 18 | bool empty() const; 19 | 20 | bool get_size_by_pc(PC pc, size_t &size) const; 21 | 22 | bool get_seg_by_pc(PC pc, Segment &seg) const; 23 | 24 | private: 25 | std::unordered_map pc_replace; 26 | std::unordered_map malloc_single_size; 27 | }; 28 | 29 | class RepairPass { 30 | public: 31 | static const char *optionals; 32 | static const size_t n_opt; 33 | 34 | RepairPass(const std::string &in, const std::vector &rest); 35 | 36 | RepairPass(DetectPass::ApiT &&in, const std::vector &rest); 37 | 38 | void compute(); 39 | 40 | void print_result(const std::string &path); 41 | 42 | private: 43 | void read_from_file(std::ifstream &is); 44 | 45 | void print_malloc(std::ofstream &layout_stream); 46 | 47 | void print_layout(std::ofstream &layout_stream); 48 | 49 | std::vector> all_fixed_mallocs; 50 | std::multimap> all_pcs_layout; 51 | int target_thread_count; 52 | DetectPass::ApiT input; 53 | AnalysisResult analysis; 54 | }; 55 | 56 | #endif //POSTPROCESS_REPAIR_H 57 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/version_edit_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "db/version_edit.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | static void TestEncodeDecode(const VersionEdit& edit) { 11 | std::string encoded, encoded2; 12 | edit.EncodeTo(&encoded); 13 | VersionEdit parsed; 14 | Status s = parsed.DecodeFrom(encoded); 15 | ASSERT_TRUE(s.ok()) << s.ToString(); 16 | parsed.EncodeTo(&encoded2); 17 | ASSERT_EQ(encoded, encoded2); 18 | } 19 | 20 | class VersionEditTest { }; 21 | 22 | TEST(VersionEditTest, EncodeDecode) { 23 | static const uint64_t kBig = 1ull << 50; 24 | 25 | VersionEdit edit; 26 | for (int i = 0; i < 4; i++) { 27 | TestEncodeDecode(edit); 28 | edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 29 | InternalKey("foo", kBig + 500 + i, kTypeValue), 30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31 | edit.DeleteFile(4, kBig + 700 + i); 32 | edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33 | } 34 | 35 | edit.SetComparatorName("foo"); 36 | edit.SetLogNumber(kBig + 100); 37 | edit.SetNextFile(kBig + 200); 38 | edit.SetLastSequence(kBig + 1000); 39 | TestEncodeDecode(edit); 40 | } 41 | 42 | } // namespace leveldb 43 | 44 | int main(int argc, char** argv) { 45 | return leveldb::test::RunAllTests(); 46 | } 47 | -------------------------------------------------------------------------------- /others/tmi/src/internalmem.cpp: -------------------------------------------------------------------------------- 1 | #include "internalmem.hpp" 2 | #include "tmiutil.hpp" 3 | #include "hooks.hpp" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | char *internalmemory::_start = nullptr; 12 | char *internalmemory::_pos = nullptr; 13 | char *internalmemory::_end = nullptr; 14 | 15 | bool internalmemory::_initialized = false; 16 | 17 | int internalmemory::isInternal(void *addr) 18 | { 19 | return (size_t)addr >= (size_t)_start && 20 | (size_t)addr < (size_t)_end; 21 | } 22 | 23 | void internalmemory::init() 24 | { 25 | if(_initialized){ 26 | return; 27 | } 28 | 29 | _initialized = true; 30 | 31 | _start = (char*)mmap(0,INTERNAL_HEAP_SIZE,PROT_READ | PROT_WRITE, 32 | MAP_SHARED | MAP_ANONYMOUS,0,0); 33 | 34 | _pos = _start; 35 | _end = _start + INTERNAL_HEAP_SIZE; 36 | 37 | if(_start == MAP_FAILED){ 38 | perror("mmap:"); 39 | } 40 | 41 | fprintf(stderr,"Initialized internal mem\n"); 42 | } 43 | 44 | void internalmemory::cleanup() 45 | { 46 | //fprintf(stderr,"Total internal heap used: %lu\n",(_pos - _start)); 47 | } 48 | 49 | void* internalmemory::alloc(size_t size) 50 | { 51 | if(!_initialized){ 52 | init(); 53 | } 54 | 55 | MUST(_pos + size <= _end); 56 | void *block = (void*)_pos; 57 | _pos += size; 58 | 59 | return block; 60 | } 61 | 62 | extern "C"{ 63 | void * tmi_internal_alloc(size_t size) 64 | { 65 | return internalmemory::alloc(size); 66 | } 67 | 68 | void tmi_internal_dealloc(void *p) 69 | { 70 | // Noop for now 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/hash.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "util/coding.h" 7 | #include "util/hash.h" 8 | 9 | // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through 10 | // between switch labels. The real definition should be provided externally. 11 | // This one is a fallback version for unsupported compilers. 12 | #ifndef FALLTHROUGH_INTENDED 13 | #define FALLTHROUGH_INTENDED do { } while (0) 14 | #endif 15 | 16 | namespace leveldb { 17 | 18 | uint32_t Hash(const char* data, size_t n, uint32_t seed) { 19 | // Similar to murmur hash 20 | const uint32_t m = 0xc6a4a793; 21 | const uint32_t r = 24; 22 | const char* limit = data + n; 23 | uint32_t h = seed ^ (n * m); 24 | 25 | // Pick up four bytes at a time 26 | while (data + 4 <= limit) { 27 | uint32_t w = DecodeFixed32(data); 28 | data += 4; 29 | h += w; 30 | h *= m; 31 | h ^= (h >> 16); 32 | } 33 | 34 | // Pick up remaining bytes 35 | switch (limit - data) { 36 | case 3: 37 | h += static_cast(data[2]) << 16; 38 | FALLTHROUGH_INTENDED; 39 | case 2: 40 | h += static_cast(data[1]) << 8; 41 | FALLTHROUGH_INTENDED; 42 | case 1: 43 | h += static_cast(data[0]); 44 | h *= m; 45 | h ^= (h >> r); 46 | break; 47 | } 48 | return h; 49 | } 50 | 51 | 52 | } // namespace leveldb 53 | -------------------------------------------------------------------------------- /others/tmi/include/tmi.h: -------------------------------------------------------------------------------- 1 | #ifndef __AE_TMI_H__ 2 | #define __AE_TMI_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "tramps.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | // For shared mem communication 16 | typedef enum { SCH_EVT_SIGCHILD, 17 | SCH_EVT_FORCE_FORK, 18 | SCH_EVT_NEW_THREAD, 19 | SCH_EVT_THREAD_EXIT, 20 | SCH_EVT_RESUME, 21 | SCH_EVT_EXIT} SCH_EVT_TYPE; 22 | 23 | typedef struct sch_evt_t 24 | { 25 | SCH_EVT_TYPE type; 26 | pid_t mpid, pid; 27 | void* data; 28 | } sch_evt_t; 29 | 30 | typedef struct thread_context 31 | { 32 | void *(*start_routine)(void*); 33 | void *arg; 34 | int tid; 35 | int pipefd; 36 | INJECT_TRAMPOLINE* tramp; 37 | } thread_context; 38 | 39 | typedef struct tmi_shared_data 40 | { 41 | int child_pipe_fd; 42 | void* child_epaddress; 43 | } tmi_shared_data; 44 | 45 | #define TMI_SHMEM_SIZE sizeof(tmi_shared_data) 46 | #define TMI_SHMEM_NAME "TMI_SHMEM_NAME" 47 | 48 | //#define PAGE_SIZE 4096 49 | #define PAGE_BASE(v) ((void*)(((uintptr_t)(v)) & ~(PAGE_SIZE - 1))) 50 | 51 | void die(const char* msg, ...); 52 | #define MUST(cond) for(;;) { if(cond) break; die("%s failed at %s:%i (errno: %i)\n", #cond, __FILE__, __LINE__, errno); } 53 | 54 | pid_t gettid( void ); 55 | void sch_write(int fd, SCH_EVT_TYPE type, pid_t mpid, pid_t pid, void* data); 56 | int is_system_library(void* address); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | 63 | #endif // __AE_TMI_H__ 64 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Must not be included from any .h files to avoid polluting the namespace 6 | // with macros. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_LOGGING_H_ 9 | #define STORAGE_LEVELDB_UTIL_LOGGING_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Slice; 19 | class WritableFile; 20 | 21 | // Append a human-readable printout of "num" to *str 22 | extern void AppendNumberTo(std::string* str, uint64_t num); 23 | 24 | // Append a human-readable printout of "value" to *str. 25 | // Escapes any non-printable characters found in "value". 26 | extern void AppendEscapedStringTo(std::string* str, const Slice& value); 27 | 28 | // Return a human-readable printout of "num" 29 | extern std::string NumberToString(uint64_t num); 30 | 31 | // Return a human-readable version of "value". 32 | // Escapes any non-printable characters found in "value". 33 | extern std::string EscapeString(const Slice& value); 34 | 35 | // Parse a human-readable number from "*in" into *value. On success, 36 | // advances "*in" past the consumed number and sets "*val" to the 37 | // numeric value. Otherwise, returns false and leaves *in in an 38 | // unspecified state. 39 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 40 | 41 | } // namespace leveldb 42 | 43 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 44 | -------------------------------------------------------------------------------- /runtime/SharedSpinLock.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yifanz on 6/23/18. 3 | // 4 | 5 | #ifndef RUNTIME_SHAREDSPINLOCK_H 6 | #define RUNTIME_SHAREDSPINLOCK_H 7 | 8 | #include 9 | #include 10 | 11 | class SharedSpinLock { 12 | std::atomic readers_count{0}; 13 | char _padding[64]; 14 | std::atomic write_now{false}; 15 | public: 16 | void lock() noexcept { 17 | while (write_now.exchange(true, std::memory_order_acquire)) { 18 | std::this_thread::yield(); 19 | } 20 | 21 | // wait for readers to exit 22 | while (readers_count != 0) { 23 | std::this_thread::yield(); 24 | } 25 | } 26 | 27 | void unlock() noexcept { 28 | write_now.store(false, std::memory_order_release); 29 | } 30 | 31 | void lock_shared() noexcept { 32 | // writers have priority 33 | while (true) { 34 | while (write_now.load(std::memory_order_seq_cst)) { // wait for unlock 35 | std::this_thread::yield(); 36 | } 37 | 38 | readers_count.fetch_add(1, std::memory_order_acquire); 39 | 40 | if (write_now.load(std::memory_order_seq_cst)) { 41 | // locked while transaction? Fallback. Go another round 42 | readers_count.fetch_sub(1, std::memory_order_release); 43 | } else { 44 | // all ok 45 | return; 46 | } 47 | } 48 | } 49 | 50 | void unlock_shared() noexcept { 51 | readers_count.fetch_sub(1, std::memory_order_release); 52 | } 53 | }; 54 | 55 | #endif //RUNTIME_SHAREDSPINLOCK_H 56 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/port/thread_annotations.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 6 | #define STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 7 | 8 | // Some environments provide custom macros to aid in static thread-safety 9 | // analysis. Provide empty definitions of such macros unless they are already 10 | // defined. 11 | 12 | #ifndef EXCLUSIVE_LOCKS_REQUIRED 13 | #define EXCLUSIVE_LOCKS_REQUIRED(...) 14 | #endif 15 | 16 | #ifndef SHARED_LOCKS_REQUIRED 17 | #define SHARED_LOCKS_REQUIRED(...) 18 | #endif 19 | 20 | #ifndef LOCKS_EXCLUDED 21 | #define LOCKS_EXCLUDED(...) 22 | #endif 23 | 24 | #ifndef LOCK_RETURNED 25 | #define LOCK_RETURNED(x) 26 | #endif 27 | 28 | #ifndef LOCKABLE 29 | #define LOCKABLE 30 | #endif 31 | 32 | #ifndef SCOPED_LOCKABLE 33 | #define SCOPED_LOCKABLE 34 | #endif 35 | 36 | #ifndef EXCLUSIVE_LOCK_FUNCTION 37 | #define EXCLUSIVE_LOCK_FUNCTION(...) 38 | #endif 39 | 40 | #ifndef SHARED_LOCK_FUNCTION 41 | #define SHARED_LOCK_FUNCTION(...) 42 | #endif 43 | 44 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION 45 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 46 | #endif 47 | 48 | #ifndef SHARED_TRYLOCK_FUNCTION 49 | #define SHARED_TRYLOCK_FUNCTION(...) 50 | #endif 51 | 52 | #ifndef UNLOCK_FUNCTION 53 | #define UNLOCK_FUNCTION(...) 54 | #endif 55 | 56 | #ifndef NO_THREAD_SAFETY_ANALYSIS 57 | #define NO_THREAD_SAFETY_ANALYSIS 58 | #endif 59 | 60 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 61 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/port/port_posix.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "port/port_posix.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace port { 13 | 14 | static void PthreadCall(const char* label, int result) { 15 | if (result != 0) { 16 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 17 | abort(); 18 | } 19 | } 20 | 21 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 22 | 23 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 24 | 25 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 26 | 27 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 28 | 29 | CondVar::CondVar(Mutex* mu) 30 | : mu_(mu) { 31 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 32 | } 33 | 34 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } 35 | 36 | void CondVar::Wait() { 37 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 38 | } 39 | 40 | void CondVar::Signal() { 41 | PthreadCall("signal", pthread_cond_signal(&cv_)); 42 | } 43 | 44 | void CondVar::SignalAll() { 45 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 46 | } 47 | 48 | void InitOnce(OnceType* once, void (*initializer)()) { 49 | PthreadCall("once", pthread_once(once, initializer)); 50 | } 51 | 52 | } // namespace port 53 | } // namespace leveldb 54 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/crc32c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_ 6 | #define STORAGE_LEVELDB_UTIL_CRC32C_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace crc32c { 13 | 14 | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the 15 | // crc32c of some string A. Extend() is often used to maintain the 16 | // crc32c of a stream of data. 17 | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n); 18 | 19 | // Return the crc32c of data[0,n-1] 20 | inline uint32_t Value(const char* data, size_t n) { 21 | return Extend(0, data, n); 22 | } 23 | 24 | static const uint32_t kMaskDelta = 0xa282ead8ul; 25 | 26 | // Return a masked representation of crc. 27 | // 28 | // Motivation: it is problematic to compute the CRC of a string that 29 | // contains embedded CRCs. Therefore we recommend that CRCs stored 30 | // somewhere (e.g., in files) should be masked before being stored. 31 | inline uint32_t Mask(uint32_t crc) { 32 | // Rotate right by 15 bits and add a constant. 33 | return ((crc >> 15) | (crc << 17)) + kMaskDelta; 34 | } 35 | 36 | // Return the crc whose masked representation is masked_crc. 37 | inline uint32_t Unmask(uint32_t masked_crc) { 38 | uint32_t rot = masked_crc - kMaskDelta; 39 | return ((rot >> 17) | (rot << 15)); 40 | } 41 | 42 | } // namespace crc32c 43 | } // namespace leveldb 44 | 45 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_ 46 | -------------------------------------------------------------------------------- /runtime/LibFuncs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yifanz on 6/14/18. 3 | // 4 | 5 | #ifndef RUNTIME_LIBFUNCS_H 6 | #define RUNTIME_LIBFUNCS_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int __internal_pthread_create(pthread_t *t1, const pthread_attr_t *t2, 15 | void *(*t3)(void *), void *t4) { 16 | typedef int (*p_create_t)(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *); 17 | static p_create_t _pthread_create_ptr; 18 | if (_pthread_create_ptr == nullptr) { 19 | void *lib_handle = dlopen("libpthread.so.0", RTLD_NOW | RTLD_GLOBAL | RTLD_NOLOAD); 20 | if (lib_handle == nullptr) { 21 | fprintf(stderr, "Unable to load libpthread.so.0\n"); 22 | exit(2); 23 | } 24 | _pthread_create_ptr = (p_create_t) dlsym(lib_handle, "pthread_create"); 25 | assert(_pthread_create_ptr); 26 | } 27 | return _pthread_create_ptr(t1, t2, t3, t4); 28 | } 29 | 30 | int __internal_posix_memalign(void **memptr, size_t alignment, size_t size) { 31 | typedef int (*posix_memalign_t)(void **, size_t, size_t); 32 | static posix_memalign_t _posix_memalign_ptr; 33 | if (_posix_memalign_ptr == nullptr) { 34 | _posix_memalign_ptr = (posix_memalign_t) dlsym(RTLD_NEXT, "posix_memalign"); 35 | assert(_posix_memalign_ptr); 36 | } 37 | return _posix_memalign_ptr(memptr, alignment, size); 38 | } 39 | 40 | extern "C" { 41 | void *__libc_malloc(size_t size); 42 | void __libc_free(void *ptr); 43 | void *__libc_realloc(void *ptr, size_t size); 44 | } 45 | 46 | #endif //RUNTIME_LIBFUNCS_H 47 | -------------------------------------------------------------------------------- /RedirectPtr/CustomUnrollLoop.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMLOOPUNROLL_H 2 | #define CUSTOMLOOPUNROLL_H 3 | 4 | #include "llvm/Analysis/AssumptionCache.h" 5 | #include "llvm/Analysis/OptimizationRemarkEmitter.h" 6 | #include "llvm/Analysis/ScalarEvolution.h" 7 | 8 | #include 9 | 10 | /// Represents the result of a \c UnrollLoop invocation. 11 | enum class CustomLoopUnrollResult { 12 | /// The loop was not modified. 13 | Unmodified, 14 | 15 | /// The loop was partially unrolled -- we still have a loop, but with a 16 | /// smaller trip count. We may also have emitted epilogue loop if the loop 17 | /// had a non-constant trip count. 18 | PartiallyUnrolled, 19 | 20 | /// The loop was fully unrolled into straight-line code. We no longer have 21 | /// any back-edges. 22 | FullyUnrolled 23 | }; 24 | 25 | CustomLoopUnrollResult CustomUnrollLoop( 26 | llvm::Loop *L, unsigned Count, unsigned TripCount, bool Force, 27 | bool AllowRuntime, bool AllowExpensiveTripCount, bool PreserveCondBr, 28 | bool PreserveOnlyFirst, unsigned TripMultiple, unsigned PeelCount, 29 | bool UnrollRemainder, llvm::LoopInfo *LI, llvm::ScalarEvolution *SE, 30 | llvm::DominatorTree *DT, llvm::AssumptionCache *AC, 31 | llvm::OptimizationRemarkEmitter *ORE, bool PreserveLCSSA, 32 | std::unordered_map> 33 | &instHooks); 34 | 35 | CustomLoopUnrollResult DefaultUnrollLoop( 36 | llvm::Loop *L, unsigned Count, unsigned TripCount, llvm::LoopInfo *LI, 37 | llvm::AssumptionCache *AC, 38 | std::unordered_map> 39 | &instHooks); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/testutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testutil.h" 6 | 7 | #include "util/random.h" 8 | 9 | namespace leveldb { 10 | namespace test { 11 | 12 | Slice RandomString(Random* rnd, int len, std::string* dst) { 13 | dst->resize(len); 14 | for (int i = 0; i < len; i++) { 15 | (*dst)[i] = static_cast(' ' + rnd->Uniform(95)); // ' ' .. '~' 16 | } 17 | return Slice(*dst); 18 | } 19 | 20 | std::string RandomKey(Random* rnd, int len) { 21 | // Make sure to generate a wide variety of characters so we 22 | // test the boundary conditions for short-key optimizations. 23 | static const char kTestChars[] = { 24 | '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff' 25 | }; 26 | std::string result; 27 | for (int i = 0; i < len; i++) { 28 | result += kTestChars[rnd->Uniform(sizeof(kTestChars))]; 29 | } 30 | return result; 31 | } 32 | 33 | 34 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 35 | size_t len, std::string* dst) { 36 | int raw = static_cast(len * compressed_fraction); 37 | if (raw < 1) raw = 1; 38 | std::string raw_data; 39 | RandomString(rnd, raw, &raw_data); 40 | 41 | // Duplicate the random data until we have filled "len" bytes 42 | dst->clear(); 43 | while (dst->size() < len) { 44 | dst->append(raw_data); 45 | } 46 | dst->resize(len); 47 | return Slice(*dst); 48 | } 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | -------------------------------------------------------------------------------- /postprocess/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Repair.h" 3 | 4 | using namespace std; 5 | 6 | void print_usage(const string &arg0) { 7 | cerr << arg0 << " \"detect\" logfile output " << DetectPass::optionals << endl 8 | << arg0 << " \"repair\" detectfile output " << RepairPass::optionals << endl 9 | << arg0 << " \"all\" logfile output " << DetectPass::optionals 10 | << " " << RepairPass::optionals << endl; 11 | exit(1); 12 | } 13 | 14 | int main(int argc, char *argv[]) { 15 | ios_base::sync_with_stdio(false); 16 | vector args(argv, argv + argc); 17 | if (argc < 4) 18 | print_usage(args[0]); 19 | const auto &subcmd = args[1]; 20 | if (subcmd == "detect") { 21 | DetectPass dpass(args[2], vector(args.begin() + 4, args.end())); 22 | dpass.compute(); 23 | dpass.print_result(args[3]); 24 | } 25 | else if (subcmd == "repair") { 26 | RepairPass rpass(args[2], vector(args.begin() + 4, args.end())); 27 | rpass.compute(); 28 | rpass.print_result(args[3]); 29 | } 30 | else if (subcmd == "all") { 31 | size_t opt1 = min(args.size() - 4, DetectPass::n_opt); 32 | size_t opt2 = min(args.size() - 4 - opt1, RepairPass::n_opt); 33 | auto opt1_begin = args.begin() + 4, opt1_end = opt1_begin + opt1, 34 | opt2_end = opt1_end + opt2; 35 | DetectPass dpass(args[2], vector(opt1_begin, opt1_end)); 36 | dpass.compute(); 37 | RepairPass rpass(dpass.get_api_output(), vector(opt1_end, opt2_end)); 38 | rpass.compute(); 39 | rpass.print_result(args[3]); 40 | } 41 | else print_usage(args[0]); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/log_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_ 6 | #define STORAGE_LEVELDB_DB_LOG_WRITER_H_ 7 | 8 | #include 9 | #include "db/log_format.h" 10 | #include "leveldb/slice.h" 11 | #include "leveldb/status.h" 12 | 13 | namespace leveldb { 14 | 15 | class WritableFile; 16 | 17 | namespace log { 18 | 19 | class Writer { 20 | public: 21 | // Create a writer that will append data to "*dest". 22 | // "*dest" must be initially empty. 23 | // "*dest" must remain live while this Writer is in use. 24 | explicit Writer(WritableFile* dest); 25 | 26 | // Create a writer that will append data to "*dest". 27 | // "*dest" must have initial length "dest_length". 28 | // "*dest" must remain live while this Writer is in use. 29 | Writer(WritableFile* dest, uint64_t dest_length); 30 | 31 | ~Writer(); 32 | 33 | Status AddRecord(const Slice& slice); 34 | 35 | private: 36 | WritableFile* dest_; 37 | int block_offset_; // Current offset in block 38 | 39 | // crc32c values for all supported record types. These are 40 | // pre-computed to reduce the overhead of computing the crc of the 41 | // record type stored in the header. 42 | uint32_t type_crc_[kMaxRecordType + 1]; 43 | 44 | Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length); 45 | 46 | // No copying allowed 47 | Writer(const Writer&); 48 | void operator=(const Writer&); 49 | }; 50 | 51 | } // namespace log 52 | } // namespace leveldb 53 | 54 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 55 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/write_batch_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/write_batch.h" 10 | 11 | namespace leveldb { 12 | 13 | class MemTable; 14 | 15 | // WriteBatchInternal provides static methods for manipulating a 16 | // WriteBatch that we don't want in the public WriteBatch interface. 17 | class WriteBatchInternal { 18 | public: 19 | // Return the number of entries in the batch. 20 | static int Count(const WriteBatch* batch); 21 | 22 | // Set the count for the number of entries in the batch. 23 | static void SetCount(WriteBatch* batch, int n); 24 | 25 | // Return the sequence number for the start of this batch. 26 | static SequenceNumber Sequence(const WriteBatch* batch); 27 | 28 | // Store the specified number as the sequence number for the start of 29 | // this batch. 30 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); 31 | 32 | static Slice Contents(const WriteBatch* batch) { 33 | return Slice(batch->rep_); 34 | } 35 | 36 | static size_t ByteSize(const WriteBatch* batch) { 37 | return batch->rep_.size(); 38 | } 39 | 40 | static void SetContents(WriteBatch* batch, const Slice& contents); 41 | 42 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable); 43 | 44 | static void Append(WriteBatch* dst, const WriteBatch* src); 45 | }; 46 | 47 | } // namespace leveldb 48 | 49 | 50 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 51 | -------------------------------------------------------------------------------- /runtime/LoggingThread.cpp: -------------------------------------------------------------------------------- 1 | #include "LoggingThread.h" 2 | 3 | void Thread::flush_log() { 4 | for (const auto &rw_n: this->outputBuf) 5 | // if (rw_n.second.second) // if is not read-only 6 | rw_n.first.dump(this->buffer_f, this->index, rw_n.second.first, rw_n.second.second); 7 | this->outputBuf.clear(); 8 | } 9 | 10 | void Thread::log_load_store(const LocRecord &rw, bool is_write) { 11 | if (!writing) 12 | return; 13 | if (this->outputBuf.size() == LOG_SIZE) 14 | this->flush_log(); 15 | auto it = this->outputBuf.find(rw); 16 | if (it != this->outputBuf.end()) { 17 | if (is_write) 18 | it->second.second++; 19 | else 20 | it->second.first++; 21 | } else { 22 | auto pair = is_write ? std::make_pair(0, 1) : std::make_pair(1, 0); 23 | this->outputBuf.emplace(rw, pair); 24 | } 25 | } 26 | 27 | std::string Thread::get_filename() { 28 | return "__record__" + std::to_string(this->index) + ".log"; 29 | } 30 | 31 | void Thread::stop_logging() { 32 | *writing = false; 33 | flush_log(); 34 | if (this->buffer_f) 35 | fclose(this->buffer_f); 36 | } 37 | 38 | void Thread::open_buffer() { 39 | auto filename = get_filename(); 40 | this->buffer_f = fopen(filename.c_str(), "a"); 41 | if (!this->buffer_f) { 42 | fprintf(stderr, "Cannot open file!!\n"); 43 | return; 44 | } 45 | *writing = true; 46 | } 47 | 48 | Thread::Thread(int _index, threadFunction _startRoutine, void *_startArg) : 49 | buffer_f(nullptr), startRoutine(_startRoutine), startArg(_startArg), 50 | index(_index), all_hooks_active(false) { 51 | writing = new std::atomic; 52 | this->outputBuf.reserve(LOG_SIZE); 53 | this->open_buffer(); 54 | } 55 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We'd love to accept your code patches! However, before we can take them, we 4 | have to jump a couple of legal hurdles. 5 | 6 | ## Contributor License Agreements 7 | 8 | Please fill out either the individual or corporate Contributor License 9 | Agreement as appropriate. 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then sign an [individual CLA](https://developers.google.com/open-source/cla/individual). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). 15 | 16 | Follow either of the two links above to access the appropriate CLA and 17 | instructions for how to sign and return it. 18 | 19 | ## Submitting a Patch 20 | 21 | 1. Sign the contributors license agreement above. 22 | 2. Decide which code you want to submit. A submission should be a set of changes 23 | that addresses one issue in the [issue tracker](https://github.com/google/leveldb/issues). 24 | Please don't mix more than one logical change per submission, because it makes 25 | the history hard to follow. If you want to make a change 26 | (e.g. add a sample or feature) that doesn't have a corresponding issue in the 27 | issue tracker, please create one. 28 | 3. **Submitting**: When you are ready to submit, send us a Pull Request. Be 29 | sure to include the issue number you fixed and the name you used to sign 30 | the CLA. 31 | 32 | ## Writing Code ## 33 | 34 | If your contribution contains code, please make sure that it follows 35 | [the style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml). 36 | Otherwise we will have to ask you to make changes, and that's no fun for anyone. 37 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/leveldbutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "leveldb/dumpfile.h" 7 | #include "leveldb/env.h" 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | namespace { 12 | 13 | class StdoutPrinter : public WritableFile { 14 | public: 15 | virtual Status Append(const Slice& data) { 16 | fwrite(data.data(), 1, data.size(), stdout); 17 | return Status::OK(); 18 | } 19 | virtual Status Close() { return Status::OK(); } 20 | virtual Status Flush() { return Status::OK(); } 21 | virtual Status Sync() { return Status::OK(); } 22 | }; 23 | 24 | bool HandleDumpCommand(Env* env, char** files, int num) { 25 | StdoutPrinter printer; 26 | bool ok = true; 27 | for (int i = 0; i < num; i++) { 28 | Status s = DumpFile(env, files[i], &printer); 29 | if (!s.ok()) { 30 | fprintf(stderr, "%s\n", s.ToString().c_str()); 31 | ok = false; 32 | } 33 | } 34 | return ok; 35 | } 36 | 37 | } // namespace 38 | } // namespace leveldb 39 | 40 | static void Usage() { 41 | fprintf( 42 | stderr, 43 | "Usage: leveldbutil command...\n" 44 | " dump files... -- dump contents of specified files\n" 45 | ); 46 | } 47 | 48 | int main(int argc, char** argv) { 49 | leveldb::Env* env = leveldb::Env::Default(); 50 | bool ok = true; 51 | if (argc < 2) { 52 | Usage(); 53 | ok = false; 54 | } else { 55 | std::string command = argv[1]; 56 | if (command == "dump") { 57 | ok = leveldb::HandleDumpCommand(env, argv+2, argc-2); 58 | } else { 59 | Usage(); 60 | ok = false; 61 | } 62 | } 63 | return (ok ? 0 : 1); 64 | } 65 | -------------------------------------------------------------------------------- /runtime/SymbolCache.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by yifanz on 6/15/18. 3 | // 4 | 5 | #ifndef RUNTIME_SYMBOLCACHE_H 6 | #define RUNTIME_SYMBOLCACHE_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | class SymbolCache { 16 | std::unordered_map addresses; 17 | 18 | std::string demangle(const char *const symbol) { 19 | std::string symbol_str(symbol); 20 | size_t begin = symbol_str.find('('); 21 | if (begin == std::string::npos) 22 | return symbol; 23 | size_t end = symbol_str.find('+', begin); 24 | if (end == std::string::npos) 25 | return symbol; 26 | symbol_str = symbol_str.substr(begin + 1, end - begin - 1); 27 | const std::unique_ptr demangled( 28 | abi::__cxa_demangle(symbol_str.c_str(), 0, 0, 0), &std::free); 29 | return demangled ? demangled.get() : symbol_str; 30 | } 31 | 32 | public: 33 | void insert_range(const std::vector &bt) { 34 | std::vector not_found; 35 | for (const auto &ptr: bt) { 36 | auto it = addresses.find(ptr); 37 | if (it == addresses.end()) 38 | not_found.push_back(ptr); 39 | } 40 | char **string_bufs = backtrace_symbols(not_found.data(), (int) not_found.size()); 41 | for (size_t i = 0; i < not_found.size(); i++) 42 | addresses.emplace(not_found[i], demangle(string_bufs[i])); 43 | free(string_bufs); 44 | } 45 | 46 | void backtrace_symbols_fd(const std::vector &bt, FILE *file) { 47 | insert_range(bt); 48 | for (const auto &ptr: bt) 49 | fprintf(file, "%s\n", addresses[ptr].c_str()); 50 | } 51 | }; 52 | 53 | #endif //RUNTIME_SYMBOLCACHE_H 54 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/hash_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/hash.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | class HASH { }; 11 | 12 | TEST(HASH, SignedUnsignedIssue) { 13 | const unsigned char data1[1] = {0x62}; 14 | const unsigned char data2[2] = {0xc3, 0x97}; 15 | const unsigned char data3[3] = {0xe2, 0x99, 0xa5}; 16 | const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32}; 17 | const unsigned char data5[48] = { 18 | 0x01, 0xc0, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 22 | 0x14, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x04, 0x00, 24 | 0x00, 0x00, 0x00, 0x14, 25 | 0x00, 0x00, 0x00, 0x18, 26 | 0x28, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 28 | 0x02, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 30 | }; 31 | 32 | ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34); 33 | ASSERT_EQ( 34 | Hash(reinterpret_cast(data1), sizeof(data1), 0xbc9f1d34), 35 | 0xef1345c4); 36 | ASSERT_EQ( 37 | Hash(reinterpret_cast(data2), sizeof(data2), 0xbc9f1d34), 38 | 0x5b663814); 39 | ASSERT_EQ( 40 | Hash(reinterpret_cast(data3), sizeof(data3), 0xbc9f1d34), 41 | 0x323c078f); 42 | ASSERT_EQ( 43 | Hash(reinterpret_cast(data4), sizeof(data4), 0xbc9f1d34), 44 | 0xed21633a); 45 | ASSERT_EQ( 46 | Hash(reinterpret_cast(data5), sizeof(data5), 0x12345678), 47 | 0xf333dabb); 48 | } 49 | 50 | } // namespace leveldb 51 | 52 | int main(int argc, char** argv) { 53 | return leveldb::test::RunAllTests(); 54 | } 55 | -------------------------------------------------------------------------------- /others/tmi/include/gcc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009, 2010, 2011 Lockless Inc., Steven Von Fuerst. 3 | * 4 | * This library is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* Coompiler specific details - gcc */ 19 | #ifndef LL_GCC_H 20 | #define LL_GCC_H 21 | #define _GNU_SOURCE 22 | #include 23 | 24 | #define __thread__ __thread __attribute__ ((tls_model ("initial-exec"))) 25 | 26 | #define HAVE_PTHREADS 27 | #define HAVE_SYS_SELECT 28 | #define HAVE_SYS_SOCKET 29 | #define HAVE_NETINET_IN 30 | #define HAVE_SYS_MMAN 31 | 32 | #define cache_align __attribute__((aligned(64))) 33 | #define noinline __attribute__((__noinline__)) 34 | #define prefetch(x) __builtin_prefetch(x) 35 | #define barrier() asm volatile("": : :"memory") 36 | #define forget(v) asm volatile("": "=m"(v) :"m"(v)) 37 | #define mfence(v) asm volatile("mfence\n": : :"memory") 38 | #define cpu_relax() asm volatile("rep; nop\n": : :"memory") 39 | #define likely(x) __builtin_expect(!!(x), 1) 40 | #define unlikely(x) __builtin_expect(!!(x), 0) 41 | #define gcc_used __attribute__((used)) 42 | #define _hide_ __attribute__((visibility("hidden"))) 43 | #define __pure __attribute__((pure)) 44 | 45 | #define GCC_ASM 46 | 47 | #include 48 | 49 | #endif /* LL_GCC_H */ 50 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-attributes.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | 32 | #if !defined(_XED_ATTRIBUTES_H_) 33 | # define _XED_ATTRIBUTES_H_ 34 | #include "xed-types.h" 35 | 36 | typedef struct { 37 | xed_uint64_t a1; 38 | xed_uint64_t a2; 39 | } xed_attributes_t; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /test_suites/tmi_boost/spinlock/stackoverflow.cpp: -------------------------------------------------------------------------------- 1 | //#include 2 | //#include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "spinlock.hpp" 9 | using namespace std; 10 | 11 | enum { BufferSize = 1<<16, SLsPerCacheLine = 1 }; 12 | 13 | int ibuffer[BufferSize]; 14 | 15 | //using boost::detail::spinlock; 16 | size_t nslp = 41; 17 | spinlock* pslp = 0; 18 | 19 | spinlock& getSpinlock(size_t h) 20 | { 21 | return pslp[ (h%nslp) * SLsPerCacheLine ]; 22 | } 23 | 24 | 25 | void threadFunc(int offset) 26 | { 27 | const size_t mask = BufferSize-1; 28 | for (size_t ii=0, index=(offset&mask); iijoin(); } 60 | 61 | //cout << "Elapsed time: " << timer.elapsed() << endl; 62 | 63 | for (size_t ii=0; ii 31 | 32 | #include 33 | 34 | GTEST_API_ int main(int argc, char **argv) { 35 | printf("Running main() from gtest_main.cc\n"); 36 | testing::InitGoogleTest(&argc, argv); 37 | return RUN_ALL_TESTS(); 38 | } 39 | -------------------------------------------------------------------------------- /others/tmi/xed/xed-disas-raw.H: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | 32 | 33 | #if !defined(_XED_DISAS_RAW_H_) 34 | # define _XED_DISAS_RAW_H_ 35 | 36 | 37 | extern "C" { 38 | #include "xed-interface.h" 39 | #include "xed-examples-util.h" 40 | } 41 | 42 | void 43 | xed_disas_raw(xed_disas_info_t* fi); 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /others/tmi/include/detector/Helpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | 8 | 9 | #define DebugVerboseOutput false 10 | #define DebugOutput(x) do{if(DebugVerboseOutput) x}while(false) 11 | 12 | string uint64ToString(uint64_t value) { 13 | std::ostringstream os; 14 | os << value; 15 | return os.str(); 16 | } 17 | 18 | string longToString(long value) { 19 | std::ostringstream os; 20 | os << value; 21 | return os.str(); 22 | } 23 | 24 | string uint64ToHexString(uint64_t value) 25 | { 26 | std::ostringstream os; 27 | os << "0x" << std::setfill('0') << std::setw(12) << std::hex << value << std::dec; 28 | return os.str(); 29 | } 30 | 31 | template 32 | inline std::string ToString(const T& t) 33 | { 34 | std::stringstream ss; 35 | ss << t; 36 | return ss.str(); 37 | } 38 | 39 | string execArbitraryShellCmd(const char* cmd) 40 | { 41 | #ifdef VISUAL_STUDIO 42 | FILE* pipe = _popen(cmd, "r"); 43 | #else 44 | FILE* pipe = popen(cmd, "r"); 45 | #endif 46 | if (!pipe) return "ERROR"; 47 | char buffer[128]; 48 | string result = ""; 49 | while (!feof(pipe)) { 50 | if (fgets(buffer, 128, pipe) != NULL) 51 | result += buffer; 52 | } 53 | #ifdef VISUAL_STUDIO 54 | _pclose(pipe); 55 | #else 56 | pclose(pipe); 57 | #endif 58 | return result; 59 | } 60 | 61 | uint64_t hexStringToUint64_t(string hexStr) 62 | { 63 | uint64_t result = -1; 64 | stringstream S; 65 | S <>result; 67 | return result; 68 | } 69 | 70 | static vector &split(const string &s, char delim, std::vector &elems) { 71 | stringstream ss(s); 72 | string item; 73 | while (std::getline(ss, item, delim)) { 74 | elems.push_back(item); 75 | } 76 | return elems; 77 | } 78 | 79 | 80 | vector split(const string &s, char delim) { 81 | std::vector elems; 82 | split(s, delim, elems); 83 | return elems; 84 | } 85 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-init-pointer-names.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-init-pointer-names.h 32 | 33 | // This file was automatically generated. 34 | // Do not edit this file. 35 | 36 | #if !defined(_XED_INIT_POINTER_NAMES_H_) 37 | # define _XED_INIT_POINTER_NAMES_H_ 38 | #include "xed-internal-header.h" 39 | #define XED_MAX_POINTER_NAMES 33 40 | #endif 41 | -------------------------------------------------------------------------------- /test_suites/locked/toy_manual.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define THREAD_COUNT 4 6 | #define TOTAL 1024 7 | #define ITER 1000000 8 | 9 | int *dynMemory; 10 | pthread_mutex_t ownThreadLock[THREAD_COUNT*64]; 11 | 12 | void *run(void *ptr) 13 | { 14 | int start = *((int *)ptr); 15 | printf("%d\n",start); 16 | for(int i = start; i < TOTAL; i+= 4*THREAD_COUNT) 17 | { 18 | for(int j = 0; j < ITER; j++) 19 | { 20 | pthread_mutex_lock(&ownThreadLock[start*64]); 21 | int val=dynMemory[64*i]; 22 | if(j == 0)val=0; 23 | else { 24 | if(j%2)val+=1; 25 | else val+=2; 26 | } 27 | dynMemory[64*i]=val; 28 | val=dynMemory[64*(i+THREAD_COUNT)]; 29 | if(j == 0)val=0; 30 | else { 31 | if(j%2)val+=1; 32 | else val+=2; 33 | } 34 | dynMemory[64*(i+THREAD_COUNT)]=val; 35 | val=dynMemory[64*(i+2*THREAD_COUNT)]; 36 | if(j == 0)val=0; 37 | else { 38 | if(j%2)val+=1; 39 | else val+=2; 40 | } 41 | dynMemory[64*(i+2*THREAD_COUNT)]=val; 42 | val=dynMemory[64*(i+3*THREAD_COUNT)]; 43 | if(j == 0)val=0; 44 | else { 45 | if(j%2)val+=1; 46 | else val+=2; 47 | } 48 | dynMemory[64*(i+3*THREAD_COUNT)]=val; 49 | pthread_mutex_unlock(&ownThreadLock[start*64]); 50 | } 51 | } 52 | pthread_exit(NULL); 53 | } 54 | 55 | int main(void) 56 | { 57 | dynMemory = (int *)malloc(64*TOTAL*sizeof(int)); 58 | pthread_t threads[THREAD_COUNT]; 59 | int params[THREAD_COUNT]; 60 | for (int i = 0; i < THREAD_COUNT; i++) 61 | { 62 | params[i]=i; 63 | pthread_mutex_init(&ownThreadLock[i*64], NULL); 64 | } 65 | for (int i = 0; i < THREAD_COUNT; i++) 66 | { 67 | pthread_create(&threads[i], NULL, run, ((void *)(¶ms[i]))); 68 | } 69 | for (int i = 0; i < THREAD_COUNT; i++) 70 | { 71 | pthread_join(threads[i], NULL); 72 | } 73 | return 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/issues/issue200_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // Test for issue 200: when iterator switches direction from backward 6 | // to forward, the current key can be yielded unexpectedly if a new 7 | // mutation has been added just before the current key. 8 | 9 | #include "leveldb/db.h" 10 | #include "util/testharness.h" 11 | 12 | namespace leveldb { 13 | 14 | class Issue200 { }; 15 | 16 | TEST(Issue200, Test) { 17 | // Get rid of any state from an old run. 18 | std::string dbpath = test::TmpDir() + "/leveldb_issue200_test"; 19 | DestroyDB(dbpath, Options()); 20 | 21 | DB *db; 22 | Options options; 23 | options.create_if_missing = true; 24 | ASSERT_OK(DB::Open(options, dbpath, &db)); 25 | 26 | WriteOptions write_options; 27 | ASSERT_OK(db->Put(write_options, "1", "b")); 28 | ASSERT_OK(db->Put(write_options, "2", "c")); 29 | ASSERT_OK(db->Put(write_options, "3", "d")); 30 | ASSERT_OK(db->Put(write_options, "4", "e")); 31 | ASSERT_OK(db->Put(write_options, "5", "f")); 32 | 33 | ReadOptions read_options; 34 | Iterator *iter = db->NewIterator(read_options); 35 | 36 | // Add an element that should not be reflected in the iterator. 37 | ASSERT_OK(db->Put(write_options, "25", "cd")); 38 | 39 | iter->Seek("5"); 40 | ASSERT_EQ(iter->key().ToString(), "5"); 41 | iter->Prev(); 42 | ASSERT_EQ(iter->key().ToString(), "4"); 43 | iter->Prev(); 44 | ASSERT_EQ(iter->key().ToString(), "3"); 45 | iter->Next(); 46 | ASSERT_EQ(iter->key().ToString(), "4"); 47 | iter->Next(); 48 | ASSERT_EQ(iter->key().ToString(), "5"); 49 | 50 | delete iter; 51 | delete db; 52 | DestroyDB(dbpath, options); 53 | } 54 | 55 | } // namespace leveldb 56 | 57 | int main(int argc, char** argv) { 58 | return leveldb::test::RunAllTests(); 59 | } 60 | -------------------------------------------------------------------------------- /test_suites/locked/toy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define THREAD_COUNT 4 6 | #define TOTAL 1024 7 | int ITER = 1000000; 8 | 9 | int *dynMemory; 10 | pthread_mutex_t ownThreadLock[THREAD_COUNT*64]; 11 | 12 | void *run(void *ptr) 13 | { 14 | int start = *((int *)ptr); 15 | printf("%d\n",start); 16 | for(int i = start; i < TOTAL; i+= 4*THREAD_COUNT) 17 | { 18 | for(int j = 0; j < ITER; j++) 19 | { 20 | pthread_mutex_lock(&ownThreadLock[start*64]); 21 | int val=dynMemory[i]; 22 | if(j == 0)val=0; 23 | else { 24 | if(j%2)val+=1; 25 | else val+=2; 26 | } 27 | dynMemory[i]=val; 28 | val=dynMemory[i+THREAD_COUNT]; 29 | if(j == 0)val=0; 30 | else { 31 | if(j%2)val+=1; 32 | else val+=2; 33 | } 34 | dynMemory[i+THREAD_COUNT]=val; 35 | val=dynMemory[i+2*THREAD_COUNT]; 36 | if(j == 0)val=0; 37 | else { 38 | if(j%2)val+=1; 39 | else val+=2; 40 | } 41 | dynMemory[i+2*THREAD_COUNT]=val; 42 | val=dynMemory[i+3*THREAD_COUNT]; 43 | if(j == 0)val=0; 44 | else { 45 | if(j%2)val+=1; 46 | else val+=2; 47 | } 48 | dynMemory[i+3*THREAD_COUNT]=val; 49 | pthread_mutex_unlock(&ownThreadLock[start*64]); 50 | } 51 | } 52 | pthread_exit(NULL); 53 | } 54 | 55 | int main(int argc, char *argv[]) 56 | { 57 | if(argc > 1)ITER=atoi(argv[1]); 58 | dynMemory = (int *)malloc(TOTAL*sizeof(int)); 59 | pthread_t threads[THREAD_COUNT]; 60 | int params[THREAD_COUNT]; 61 | for (int i = 0; i < THREAD_COUNT; i++) 62 | { 63 | params[i]=i; 64 | pthread_mutex_init(&ownThreadLock[i*64], NULL); 65 | } 66 | for (int i = 0; i < THREAD_COUNT; i++) 67 | { 68 | pthread_create(&threads[i], NULL, run, ((void *)(¶ms[i]))); 69 | } 70 | for (int i = 0; i < THREAD_COUNT; i++) 71 | { 72 | pthread_join(threads[i], NULL); 73 | } 74 | return 0; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /test_suites/lockless/toy_manual.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define THREAD_COUNT 4 6 | #define TOTAL 1024*16 7 | #define ITER 1000000 8 | 9 | int *dynMemory; 10 | //pthread_mutex_t ownThreadLock[THREAD_COUNT*64]; 11 | 12 | void *run(void *ptr) 13 | { 14 | int start = *((int *)ptr); 15 | printf("%d\n",start); 16 | for(int i = start; i < TOTAL; i+= 4*THREAD_COUNT) 17 | { 18 | for(int j = 0; j < ITER; j++) 19 | { 20 | //pthread_mutex_lock(&ownThreadLock[start*64]); 21 | int val=dynMemory[64*i]; 22 | if(j == 0)val=0; 23 | else { 24 | if(j%2)val+=1; 25 | else val+=2; 26 | } 27 | dynMemory[64*i]=val; 28 | val=dynMemory[64*(i+THREAD_COUNT)]; 29 | if(j == 0)val=0; 30 | else { 31 | if(j%2)val+=1; 32 | else val+=2; 33 | } 34 | dynMemory[64*(i+THREAD_COUNT)]=val; 35 | val=dynMemory[64*(i+2*THREAD_COUNT)]; 36 | if(j == 0)val=0; 37 | else { 38 | if(j%2)val+=1; 39 | else val+=2; 40 | } 41 | dynMemory[64*(i+2*THREAD_COUNT)]=val; 42 | val=dynMemory[64*(i+3*THREAD_COUNT)]; 43 | if(j == 0)val=0; 44 | else { 45 | if(j%2)val+=1; 46 | else val+=2; 47 | } 48 | dynMemory[64*(i+3*THREAD_COUNT)]=val; 49 | //pthread_mutex_unlock(&ownThreadLock[start*64]); 50 | } 51 | } 52 | pthread_exit(NULL); 53 | } 54 | 55 | int main(void) 56 | { 57 | dynMemory = (int *)malloc(64*TOTAL*sizeof(int)); 58 | pthread_t threads[THREAD_COUNT]; 59 | int params[THREAD_COUNT]; 60 | for (int i = 0; i < THREAD_COUNT; i++) 61 | { 62 | params[i]=i; 63 | //pthread_mutex_init(&ownThreadLock[i*64], NULL); 64 | } 65 | for (int i = 0; i < THREAD_COUNT; i++) 66 | { 67 | pthread_create(&threads[i], NULL, run, ((void *)(¶ms[i]))); 68 | } 69 | for (int i = 0; i < THREAD_COUNT; i++) 70 | { 71 | pthread_join(threads[i], NULL); 72 | } 73 | return 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/arena_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | 7 | #include "util/random.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | class ArenaTest { }; 13 | 14 | TEST(ArenaTest, Empty) { 15 | Arena arena; 16 | } 17 | 18 | TEST(ArenaTest, Simple) { 19 | std::vector > allocated; 20 | Arena arena; 21 | const int N = 100000; 22 | size_t bytes = 0; 23 | Random rnd(301); 24 | for (int i = 0; i < N; i++) { 25 | size_t s; 26 | if (i % (N / 10) == 0) { 27 | s = i; 28 | } else { 29 | s = rnd.OneIn(4000) ? rnd.Uniform(6000) : 30 | (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20)); 31 | } 32 | if (s == 0) { 33 | // Our arena disallows size 0 allocations. 34 | s = 1; 35 | } 36 | char* r; 37 | if (rnd.OneIn(10)) { 38 | r = arena.AllocateAligned(s); 39 | } else { 40 | r = arena.Allocate(s); 41 | } 42 | 43 | for (size_t b = 0; b < s; b++) { 44 | // Fill the "i"th allocation with a known bit pattern 45 | r[b] = i % 256; 46 | } 47 | bytes += s; 48 | allocated.push_back(std::make_pair(s, r)); 49 | ASSERT_GE(arena.MemoryUsage(), bytes); 50 | if (i > N/10) { 51 | ASSERT_LE(arena.MemoryUsage(), bytes * 1.10); 52 | } 53 | } 54 | for (size_t i = 0; i < allocated.size(); i++) { 55 | size_t num_bytes = allocated[i].first; 56 | const char* p = allocated[i].second; 57 | for (size_t b = 0; b < num_bytes; b++) { 58 | // Check the "i"th allocation for the known bit pattern 59 | ASSERT_EQ(int(p[b]) & 0xff, i % 256); 60 | } 61 | } 62 | } 63 | 64 | } // namespace leveldb 65 | 66 | int main(int argc, char** argv) { 67 | return leveldb::test::RunAllTests(); 68 | } 69 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/snapshot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_ 6 | #define STORAGE_LEVELDB_DB_SNAPSHOT_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/db.h" 10 | 11 | namespace leveldb { 12 | 13 | class SnapshotList; 14 | 15 | // Snapshots are kept in a doubly-linked list in the DB. 16 | // Each SnapshotImpl corresponds to a particular sequence number. 17 | class SnapshotImpl : public Snapshot { 18 | public: 19 | SequenceNumber number_; // const after creation 20 | 21 | private: 22 | friend class SnapshotList; 23 | 24 | // SnapshotImpl is kept in a doubly-linked circular list 25 | SnapshotImpl* prev_; 26 | SnapshotImpl* next_; 27 | 28 | SnapshotList* list_; // just for sanity checks 29 | }; 30 | 31 | class SnapshotList { 32 | public: 33 | SnapshotList() { 34 | list_.prev_ = &list_; 35 | list_.next_ = &list_; 36 | } 37 | 38 | bool empty() const { return list_.next_ == &list_; } 39 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 40 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; } 41 | 42 | const SnapshotImpl* New(SequenceNumber seq) { 43 | SnapshotImpl* s = new SnapshotImpl; 44 | s->number_ = seq; 45 | s->list_ = this; 46 | s->next_ = &list_; 47 | s->prev_ = list_.prev_; 48 | s->prev_->next_ = s; 49 | s->next_->prev_ = s; 50 | return s; 51 | } 52 | 53 | void Delete(const SnapshotImpl* s) { 54 | assert(s->list_ == this); 55 | s->prev_->next_ = s->next_; 56 | s->next_->prev_ = s->prev_; 57 | delete s; 58 | } 59 | 60 | private: 61 | // Dummy head of doubly-linked list of snapshots 62 | SnapshotImpl list_; 63 | }; 64 | 65 | } // namespace leveldb 66 | 67 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_ 68 | -------------------------------------------------------------------------------- /test_suites/lockless/toy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define THREAD_COUNT 4 6 | #define TOTAL 1024*16 7 | int ITER = 1000000; 8 | 9 | int *dynMemory; 10 | //pthread_mutex_t ownThreadLock[THREAD_COUNT*64]; 11 | 12 | void *run(void *ptr) 13 | { 14 | int start = *((int *)ptr); 15 | printf("%d\n",start); 16 | for(int i = start; i < TOTAL; i+= 4*THREAD_COUNT) 17 | { 18 | for(int j = 0; j < ITER; j++) 19 | { 20 | //pthread_mutex_lock(&ownThreadLock[start*64]); 21 | int val=dynMemory[i]; 22 | if(j == 0)val=0; 23 | else { 24 | if(j%2)val+=1; 25 | else val+=2; 26 | } 27 | dynMemory[i]=val; 28 | val=dynMemory[i+THREAD_COUNT]; 29 | if(j == 0)val=0; 30 | else { 31 | if(j%2)val+=1; 32 | else val+=2; 33 | } 34 | dynMemory[i+THREAD_COUNT]=val; 35 | val=dynMemory[i+2*THREAD_COUNT]; 36 | if(j == 0)val=0; 37 | else { 38 | if(j%2)val+=1; 39 | else val+=2; 40 | } 41 | dynMemory[i+2*THREAD_COUNT]=val; 42 | val=dynMemory[i+3*THREAD_COUNT]; 43 | if(j == 0)val=0; 44 | else { 45 | if(j%2)val+=1; 46 | else val+=2; 47 | } 48 | dynMemory[i+3*THREAD_COUNT]=val; 49 | //pthread_mutex_unlock(&ownThreadLock[start*64]); 50 | } 51 | } 52 | pthread_exit(NULL); 53 | } 54 | 55 | int main(int argc, char *argv[]) 56 | { 57 | if (argc > 1) 58 | ITER = atoi(argv[1]); 59 | dynMemory = (int *)malloc(TOTAL*sizeof(int)); 60 | pthread_t threads[THREAD_COUNT]; 61 | int params[THREAD_COUNT]; 62 | for (int i = 0; i < THREAD_COUNT; i++) 63 | { 64 | params[i]=i; 65 | //pthread_mutex_init(&ownThreadLock[i*64], NULL); 66 | } 67 | for (int i = 0; i < THREAD_COUNT; i++) 68 | { 69 | pthread_create(&threads[i], NULL, run, ((void *)(¶ms[i]))); 70 | } 71 | for (int i = 0; i < THREAD_COUNT; i++) 72 | { 73 | pthread_join(threads[i], NULL); 74 | } 75 | return 0; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/table/iterator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/iterator.h" 6 | 7 | namespace leveldb { 8 | 9 | Iterator::Iterator() { 10 | cleanup_.function = NULL; 11 | cleanup_.next = NULL; 12 | } 13 | 14 | Iterator::~Iterator() { 15 | if (cleanup_.function != NULL) { 16 | (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2); 17 | for (Cleanup* c = cleanup_.next; c != NULL; ) { 18 | (*c->function)(c->arg1, c->arg2); 19 | Cleanup* next = c->next; 20 | delete c; 21 | c = next; 22 | } 23 | } 24 | } 25 | 26 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { 27 | assert(func != NULL); 28 | Cleanup* c; 29 | if (cleanup_.function == NULL) { 30 | c = &cleanup_; 31 | } else { 32 | c = new Cleanup; 33 | c->next = cleanup_.next; 34 | cleanup_.next = c; 35 | } 36 | c->function = func; 37 | c->arg1 = arg1; 38 | c->arg2 = arg2; 39 | } 40 | 41 | namespace { 42 | class EmptyIterator : public Iterator { 43 | public: 44 | EmptyIterator(const Status& s) : status_(s) { } 45 | virtual bool Valid() const { return false; } 46 | virtual void Seek(const Slice& target) { } 47 | virtual void SeekToFirst() { } 48 | virtual void SeekToLast() { } 49 | virtual void Next() { assert(false); } 50 | virtual void Prev() { assert(false); } 51 | Slice key() const { assert(false); return Slice(); } 52 | Slice value() const { assert(false); return Slice(); } 53 | virtual Status status() const { return status_; } 54 | private: 55 | Status status_; 56 | }; 57 | } // namespace 58 | 59 | Iterator* NewEmptyIterator() { 60 | return new EmptyIterator(Status::OK()); 61 | } 62 | 63 | Iterator* NewErrorIterator(const Status& status) { 64 | return new EmptyIterator(status); 65 | } 66 | 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/table/block_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include "leveldb/slice.h" 12 | 13 | namespace leveldb { 14 | 15 | struct Options; 16 | 17 | class BlockBuilder { 18 | public: 19 | explicit BlockBuilder(const Options* options); 20 | 21 | // Reset the contents as if the BlockBuilder was just constructed. 22 | void Reset(); 23 | 24 | // REQUIRES: Finish() has not been called since the last call to Reset(). 25 | // REQUIRES: key is larger than any previously added key 26 | void Add(const Slice& key, const Slice& value); 27 | 28 | // Finish building the block and return a slice that refers to the 29 | // block contents. The returned slice will remain valid for the 30 | // lifetime of this builder or until Reset() is called. 31 | Slice Finish(); 32 | 33 | // Returns an estimate of the current (uncompressed) size of the block 34 | // we are building. 35 | size_t CurrentSizeEstimate() const; 36 | 37 | // Return true iff no entries have been added since the last Reset() 38 | bool empty() const { 39 | return buffer_.empty(); 40 | } 41 | 42 | private: 43 | const Options* options_; 44 | std::string buffer_; // Destination buffer 45 | std::vector restarts_; // Restart points 46 | int counter_; // Number of entries emitted since restart 47 | bool finished_; // Has Finish() been called? 48 | std::string last_key_; 49 | 50 | // No copying allowed 51 | BlockBuilder(const BlockBuilder&); 52 | void operator=(const BlockBuilder&); 53 | }; 54 | 55 | } // namespace leveldb 56 | 57 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 58 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/testharness.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testharness.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | namespace { 16 | struct Test { 17 | const char* base; 18 | const char* name; 19 | void (*func)(); 20 | }; 21 | std::vector* tests; 22 | } 23 | 24 | bool RegisterTest(const char* base, const char* name, void (*func)()) { 25 | if (tests == NULL) { 26 | tests = new std::vector; 27 | } 28 | Test t; 29 | t.base = base; 30 | t.name = name; 31 | t.func = func; 32 | tests->push_back(t); 33 | return true; 34 | } 35 | 36 | int RunAllTests() { 37 | const char* matcher = getenv("LEVELDB_TESTS"); 38 | 39 | int num = 0; 40 | if (tests != NULL) { 41 | for (size_t i = 0; i < tests->size(); i++) { 42 | const Test& t = (*tests)[i]; 43 | if (matcher != NULL) { 44 | std::string name = t.base; 45 | name.push_back('.'); 46 | name.append(t.name); 47 | if (strstr(name.c_str(), matcher) == NULL) { 48 | continue; 49 | } 50 | } 51 | fprintf(stderr, "==== Test %s.%s\n", t.base, t.name); 52 | (*t.func)(); 53 | ++num; 54 | } 55 | } 56 | fprintf(stderr, "==== PASSED %d tests\n", num); 57 | return 0; 58 | } 59 | 60 | std::string TmpDir() { 61 | std::string dir; 62 | Status s = Env::Default()->GetTestDirectory(&dir); 63 | ASSERT_TRUE(s.ok()) << s.ToString(); 64 | return dir; 65 | } 66 | 67 | int RandomSeed() { 68 | const char* env = getenv("TEST_RANDOM_SEED"); 69 | int result = (env != NULL ? atoi(env) : 301); 70 | if (result <= 0) { 71 | result = 301; 72 | } 73 | return result; 74 | } 75 | 76 | } // namespace test 77 | } // namespace leveldb 78 | -------------------------------------------------------------------------------- /others/tmi/tests/test_sync_process.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #define THREADS 4 8 | #define ITERS 100 9 | 10 | int *count; 11 | 12 | void* do_locks(void *arg){ 13 | pthread_mutex_t *lock = (pthread_mutex_t*)arg; 14 | 15 | for(int c = 0; c < ITERS; c++){ 16 | pthread_mutex_lock(lock); 17 | *count = *count + 1; 18 | pthread_mutex_unlock(lock); 19 | } 20 | 21 | return nullptr; 22 | } 23 | 24 | void* do_barriers(void *arg){ 25 | pthread_barrier_t *barrier = (pthread_barrier_t*)arg; 26 | 27 | for(int c = 0; c < ITERS; c++){ 28 | pthread_barrier_wait(barrier); 29 | } 30 | 31 | return nullptr; 32 | } 33 | 34 | int main(){ 35 | void *region = mmap(0,4096,PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0); 36 | count = (int*)region; 37 | *count = 0; 38 | 39 | pthread_barrier_t process_barrier; 40 | pthread_barrier_init(&process_barrier,NULL,THREADS); 41 | 42 | pthread_barrier_t barrier; 43 | pthread_barrier_init(&barrier,NULL,THREADS); 44 | 45 | pthread_mutex_t *lock2 = new pthread_mutex_t; 46 | pthread_mutexattr_t mutexattr; 47 | pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED); 48 | pthread_mutex_init(lock2,&mutexattr); 49 | 50 | pthread_mutex_lock(lock2); 51 | pthread_mutex_unlock(lock2); 52 | 53 | for(int c = 0; c < THREADS-1; c++){ 54 | int pid = fork(); 55 | 56 | if(pid == 0){ 57 | break; 58 | } 59 | } 60 | 61 | std::cout << "Starting wait on " << getpid() << "\n"; 62 | 63 | pthread_barrier_wait(&process_barrier); 64 | 65 | std::cout << "Starting locks with processes\n"; 66 | do_locks((void*)lock2); 67 | 68 | pthread_barrier_wait(&process_barrier); 69 | std::cout << "Value: " << *count << "\n"; 70 | 71 | std::cout << "Starting barriers with processes\n"; 72 | do_barriers((void*)&barrier); 73 | std::cout << "Done with barriers with processes\n"; 74 | 75 | pthread_barrier_wait(&process_barrier); 76 | 77 | 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /others/tmi/include/hooks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | extern "C" int (*orig_pthread_create)(pthread_t *thread, 7 | const pthread_attr_t *attr, 8 | void *(*start_routine)(void*), 9 | void *arg); 10 | extern "C" int (*orig_pthread_join)(pthread_t thread, void **retval); 11 | extern "C" void (*orig_pthread_exit)(void *arg); 12 | 13 | extern "C" void* (*orig_malloc)(size_t size); 14 | extern "C" void (*orig_free)(void *p); 15 | 16 | extern "C" int (*orig_pthread_mutex_init)(pthread_mutex_t *mutex,const pthread_mutexattr_t *attr); 17 | extern "C" int (*orig_pthread_mutex_destroy)(pthread_mutex_t *mutex); 18 | extern "C" int (*orig_pthread_mutex_lock)(pthread_mutex_t *mutex); 19 | extern "C" int (*orig_pthread_mutex_trylock)(pthread_mutex_t *mutex); 20 | extern "C" int (*orig_pthread_mutex_unlock)(pthread_mutex_t *mutex); 21 | 22 | extern "C" int (*orig_pthread_spin_init)(pthread_spinlock_t *lock, int pshared); 23 | extern "C" int (*orig_pthread_spin_destroy)(pthread_spinlock_t *lock); 24 | extern "C" int (*orig_pthread_spin_lock)(pthread_spinlock_t *mutex); 25 | extern "C" int (*orig_pthread_spin_trylock)(pthread_spinlock_t *mutex); 26 | extern "C" int (*orig_pthread_spin_unlock)(pthread_spinlock_t *mutex); 27 | 28 | extern "C" int (*orig_pthread_cond_init)(pthread_cond_t *cond, const pthread_condattr_t *attr); 29 | extern "C" int (*orig_pthread_cond_destroy)(pthread_cond_t *cond); 30 | extern "C" int (*orig_pthread_cond_wait)(pthread_cond_t *cond, pthread_mutex_t *mutex); 31 | extern "C" int (*orig_pthread_cond_signal)(pthread_cond_t *cond); 32 | extern "C" int (*orig_pthread_cond_broadcast)(pthread_cond_t *cond); 33 | 34 | extern "C" int (*orig_pthread_barrier_init)(pthread_barrier_t *barrier, 35 | const pthread_barrierattr_t *attr, 36 | unsigned int count); 37 | extern "C" int (*orig_pthread_barrier_destroy)(pthread_barrier_t *barrier); 38 | extern "C" int (*orig_pthread_barrier_wait)(pthread_barrier_t *barrier); 39 | 40 | extern "C" void init_orig_functions(); 41 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/logging.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "leveldb/env.h" 12 | #include "leveldb/slice.h" 13 | 14 | namespace leveldb { 15 | 16 | void AppendNumberTo(std::string* str, uint64_t num) { 17 | char buf[30]; 18 | snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num); 19 | str->append(buf); 20 | } 21 | 22 | void AppendEscapedStringTo(std::string* str, const Slice& value) { 23 | for (size_t i = 0; i < value.size(); i++) { 24 | char c = value[i]; 25 | if (c >= ' ' && c <= '~') { 26 | str->push_back(c); 27 | } else { 28 | char buf[10]; 29 | snprintf(buf, sizeof(buf), "\\x%02x", 30 | static_cast(c) & 0xff); 31 | str->append(buf); 32 | } 33 | } 34 | } 35 | 36 | std::string NumberToString(uint64_t num) { 37 | std::string r; 38 | AppendNumberTo(&r, num); 39 | return r; 40 | } 41 | 42 | std::string EscapeString(const Slice& value) { 43 | std::string r; 44 | AppendEscapedStringTo(&r, value); 45 | return r; 46 | } 47 | 48 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { 49 | uint64_t v = 0; 50 | int digits = 0; 51 | while (!in->empty()) { 52 | char c = (*in)[0]; 53 | if (c >= '0' && c <= '9') { 54 | ++digits; 55 | const int delta = (c - '0'); 56 | static const uint64_t kMaxUint64 = ~static_cast(0); 57 | if (v > kMaxUint64/10 || 58 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) { 59 | // Overflow 60 | return false; 61 | } 62 | v = (v * 10) + delta; 63 | in->remove_prefix(1); 64 | } else { 65 | break; 66 | } 67 | } 68 | *val = v; 69 | return (digits > 0); 70 | } 71 | 72 | } // namespace leveldb 73 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-version.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | 32 | #if !defined(_XED_VERSION_H_) 33 | # define _XED_VERSION_H_ 34 | #include "xed-common-hdrs.h" 35 | 36 | ///@ingroup INIT 37 | /// Returns a string representing XED svn commit revision and time stamp. 38 | XED_DLL_EXPORT char const* xed_get_version(void); 39 | ///@ingroup INIT 40 | /// Returns a copyright string. 41 | XED_DLL_EXPORT char const* xed_get_copyright(void); 42 | #endif 43 | -------------------------------------------------------------------------------- /others/tmi/xed/xed-enc-lang.H: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-enc-lang.H 32 | 33 | 34 | 35 | extern "C" { 36 | #include "xed-interface.h" 37 | } 38 | 39 | #include 40 | 41 | 42 | class ascii_encode_request_t 43 | { 44 | public: 45 | ascii_encode_request_t() {} 46 | 47 | xed_state_t dstate; 48 | std::string command; 49 | }; 50 | 51 | 52 | xed_encoder_request_t 53 | parse_encode_request(ascii_encode_request_t& areq); 54 | -------------------------------------------------------------------------------- /others/tmi/xed/xed-disas-macho.H: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-disas-macho.H 32 | #if !defined(_XED_DISAS_MACHO_H_) 33 | # define _XED_DISAS_MACHO_H_ 34 | 35 | #if defined(__APPLE__) 36 | # define XED_MAC_OSX_FILE_READER 37 | #endif 38 | 39 | # if defined(XED_MAC_OSX_FILE_READER) 40 | extern "C" { 41 | # include "xed-interface.h" 42 | # include "xed-examples-util.h" 43 | } 44 | 45 | void 46 | xed_disas_macho(xed_disas_info_t* fi); 47 | 48 | # endif 49 | #endif 50 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/crc32c_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/crc32c.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | namespace crc32c { 10 | 11 | class CRC { }; 12 | 13 | TEST(CRC, StandardResults) { 14 | // From rfc3720 section B.4. 15 | char buf[32]; 16 | 17 | memset(buf, 0, sizeof(buf)); 18 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf))); 19 | 20 | memset(buf, 0xff, sizeof(buf)); 21 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf))); 22 | 23 | for (int i = 0; i < 32; i++) { 24 | buf[i] = i; 25 | } 26 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf))); 27 | 28 | for (int i = 0; i < 32; i++) { 29 | buf[i] = 31 - i; 30 | } 31 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); 32 | 33 | unsigned char data[48] = { 34 | 0x01, 0xc0, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 38 | 0x14, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x04, 0x00, 40 | 0x00, 0x00, 0x00, 0x14, 41 | 0x00, 0x00, 0x00, 0x18, 42 | 0x28, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 44 | 0x02, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 46 | }; 47 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data))); 48 | } 49 | 50 | TEST(CRC, Values) { 51 | ASSERT_NE(Value("a", 1), Value("foo", 3)); 52 | } 53 | 54 | TEST(CRC, Extend) { 55 | ASSERT_EQ(Value("hello world", 11), 56 | Extend(Value("hello ", 6), "world", 5)); 57 | } 58 | 59 | TEST(CRC, Mask) { 60 | uint32_t crc = Value("foo", 3); 61 | ASSERT_NE(crc, Mask(crc)); 62 | ASSERT_NE(crc, Mask(Mask(crc))); 63 | ASSERT_EQ(crc, Unmask(Mask(crc))); 64 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); 65 | } 66 | 67 | } // namespace crc32c 68 | } // namespace leveldb 69 | 70 | int main(int argc, char** argv) { 71 | return leveldb::test::RunAllTests(); 72 | } 73 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-operand-ctype-map.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-operand-ctype-map.h 32 | 33 | // This file was automatically generated. 34 | // Do not edit this file. 35 | 36 | #if !defined(_XED_OPERAND_CTYPE_MAP_H_) 37 | # define _XED_OPERAND_CTYPE_MAP_H_ 38 | #include "xed-internal-header.h" 39 | xed_operand_ctype_enum_t xed_operand_get_ctype(xed_operand_enum_t opname); 40 | unsigned int xed_operand_decider_get_width(xed_operand_enum_t opname); 41 | #endif 42 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/arena.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ARENA_H_ 6 | #define STORAGE_LEVELDB_UTIL_ARENA_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "port/port.h" 13 | 14 | namespace leveldb { 15 | 16 | class Arena { 17 | public: 18 | Arena(); 19 | ~Arena(); 20 | 21 | // Return a pointer to a newly allocated memory block of "bytes" bytes. 22 | char* Allocate(size_t bytes); 23 | 24 | // Allocate memory with the normal alignment guarantees provided by malloc 25 | char* AllocateAligned(size_t bytes); 26 | 27 | // Returns an estimate of the total memory usage of data allocated 28 | // by the arena. 29 | size_t MemoryUsage() const { 30 | return reinterpret_cast(memory_usage_.NoBarrier_Load()); 31 | } 32 | 33 | private: 34 | char* AllocateFallback(size_t bytes); 35 | char* AllocateNewBlock(size_t block_bytes); 36 | 37 | // Allocation state 38 | char* alloc_ptr_; 39 | size_t alloc_bytes_remaining_; 40 | 41 | // Array of new[] allocated memory blocks 42 | std::vector blocks_; 43 | 44 | // Total memory usage of the arena. 45 | port::AtomicPointer memory_usage_; 46 | 47 | // No copying allowed 48 | Arena(const Arena&); 49 | void operator=(const Arena&); 50 | }; 51 | 52 | inline char* Arena::Allocate(size_t bytes) { 53 | // The semantics of what to return are a bit messy if we allow 54 | // 0-byte allocations, so we disallow them here (we don't need 55 | // them for our internal use). 56 | assert(bytes > 0); 57 | if (bytes <= alloc_bytes_remaining_) { 58 | char* result = alloc_ptr_; 59 | alloc_ptr_ += bytes; 60 | alloc_bytes_remaining_ -= bytes; 61 | return result; 62 | } 63 | return AllocateFallback(bytes); 64 | } 65 | 66 | } // namespace leveldb 67 | 68 | #endif // STORAGE_LEVELDB_UTIL_ARENA_H_ 69 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-build-defines.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | #if !defined(_XED_BUILD_DEFINES_H_) 32 | # define _XED_BUILD_DEFINES_H_ 33 | 34 | # if !defined(XED_AMD_ENABLED) 35 | # define XED_AMD_ENABLED 36 | # endif 37 | # if !defined(XED_AVX) 38 | # define XED_AVX 39 | # endif 40 | # if !defined(XED_GIT_VERSION) 41 | # define XED_GIT_VERSION "6.23.0-15-g43cff9b 2014-04-10" 42 | # endif 43 | # if !defined(XED_MPX) 44 | # define XED_MPX 45 | # endif 46 | #endif 47 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-init.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-init.h 32 | /// 33 | 34 | 35 | 36 | 37 | #if !defined(_XED_INIT_H_) 38 | # define _XED_INIT_H_ 39 | 40 | 41 | /// @ingroup INIT 42 | /// This is the call to initialize the XED encode and decode tables. It 43 | /// must be called once before using XED. 44 | void XED_DLL_EXPORT xed_tables_init(void); 45 | 46 | //////////////////////////////////////////////////////////////////////////// 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /others/tmi/xed/xed-disas-elf.H: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-disas-elf.H 32 | 33 | #if !defined(_XED_DISAS_ELF_H_) 34 | # define _XED_DISAS_ELF_H_ 35 | #if defined(__linux) || defined(__linux__) || defined(__FreeBSD__) 36 | # define XED_ELF_READER 37 | #endif 38 | # if defined(XED_ELF_READER) 39 | 40 | extern "C" { 41 | #include "xed-interface.h" 42 | #include "xed-examples-util.h" 43 | } 44 | 45 | void 46 | xed_disas_elf(xed_disas_info_t* fi); 47 | 48 | # endif 49 | #endif 50 | -------------------------------------------------------------------------------- /others/tmi/xed/xed-disas-pecoff.H: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-disas-pecoff.H 32 | 33 | #if defined(_WIN32) 34 | # define XED_PECOFF_FILE_READER 35 | #endif 36 | 37 | #if !defined(_XED_DISAS_PECOFF_H_) 38 | # define _XED_DISAS_PECOFF_H_ 39 | # if defined(XED_PECOFF_FILE_READER) 40 | 41 | extern "C" { 42 | # include "xed-interface.h" 43 | # include "xed-examples-util.h" 44 | } 45 | 46 | void 47 | xed_disas_pecoff(xed_disas_info_t* fi); 48 | 49 | # endif 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/include/leveldb/write_batch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // WriteBatch holds a collection of updates to apply atomically to a DB. 6 | // 7 | // The updates are applied in the order in which they are added 8 | // to the WriteBatch. For example, the value of "key" will be "v3" 9 | // after the following batch is written: 10 | // 11 | // batch.Put("key", "v1"); 12 | // batch.Delete("key"); 13 | // batch.Put("key", "v2"); 14 | // batch.Put("key", "v3"); 15 | // 16 | // Multiple threads can invoke const methods on a WriteBatch without 17 | // external synchronization, but if any of the threads may call a 18 | // non-const method, all threads accessing the same WriteBatch must use 19 | // external synchronization. 20 | 21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 23 | 24 | #include 25 | #include "leveldb/status.h" 26 | 27 | namespace leveldb { 28 | 29 | class Slice; 30 | 31 | class WriteBatch { 32 | public: 33 | WriteBatch(); 34 | ~WriteBatch(); 35 | 36 | // Store the mapping "key->value" in the database. 37 | void Put(const Slice& key, const Slice& value); 38 | 39 | // If the database contains a mapping for "key", erase it. Else do nothing. 40 | void Delete(const Slice& key); 41 | 42 | // Clear all updates buffered in this batch. 43 | void Clear(); 44 | 45 | // Support for iterating over the contents of a batch. 46 | class Handler { 47 | public: 48 | virtual ~Handler(); 49 | virtual void Put(const Slice& key, const Slice& value) = 0; 50 | virtual void Delete(const Slice& key) = 0; 51 | }; 52 | Status Iterate(Handler* handler) const; 53 | 54 | private: 55 | friend class WriteBatchInternal; 56 | 57 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 58 | 59 | // Intentionally copyable 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 65 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-convert-table-init.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-convert-table-init.h 32 | 33 | // This file was automatically generated. 34 | // Do not edit this file. 35 | 36 | #if !defined(_XED_CONVERT_TABLE_INIT_H_) 37 | # define _XED_CONVERT_TABLE_INIT_H_ 38 | #include "xed-internal-header.h" 39 | typedef struct { 40 | 41 | const char** table_name; 42 | 43 | xed_operand_enum_t opnd; 44 | 45 | unsigned int limit; 46 | 47 | } xed_convert_table_t; 48 | extern xed_convert_table_t xed_convert_table[XED_OPERAND_CONVERT_LAST]; 49 | #endif 50 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-encoder-gen-defs.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-encoder-gen-defs.h 32 | 33 | // This file was automatically generated. 34 | // Do not edit this file. 35 | 36 | #if !defined(_XED_ENCODER_GEN_DEFS_H_) 37 | # define _XED_ENCODER_GEN_DEFS_H_ 38 | #define XED_ENCODE_ORDER_MAX_ENTRIES 31 39 | #define XED_ENCODE_ORDER_MAX_OPERANDS 5 40 | #define XED_ENCODE_MAX_FB_PATTERNS 49 41 | #define XED_ENCODE_MAX_EMIT_PATTERNS 101 42 | #define XED_ENCODE_FB_VALUES_TABLE_SIZE 1503 43 | #define XED_ENCODE_MAX_IFORMS 3436 44 | #define XED_ENC_GROUPS 289 45 | #endif 46 | -------------------------------------------------------------------------------- /others/tmi/include/tramps.h: -------------------------------------------------------------------------------- 1 | #ifndef __AE_TRAMPS__H 2 | #define __AE_TRAMPS__H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define PUSH_RAX 0x50 9 | #define PUSH_RCX 0x51 10 | #define PUSH_RDX 0x52 11 | #define PUSH_RSI 0x56 12 | #define PUSH_RDI 0x57 13 | #define PUSH_R8 0x5041 14 | #define PUSH_R9 0x5141 15 | #define PUSH_R10 0x5241 16 | #define PUSH_R11 0x5341 17 | #define POP_RAX 0x58 18 | #define POP_RCX 0x59 19 | #define POP_RDX 0x5a 20 | #define POP_RSI 0x5e 21 | #define POP_RDI 0x5f 22 | #define POP_R8 0x5841 23 | #define POP_R9 0x5941 24 | #define POP_R10 0x5a41 25 | #define POP_R11 0x5b41 26 | 27 | #define MOV_RAX_IMM64 0xb848 28 | #define CALL_RAX 0xd0ff 29 | #define JMP_RAX 0xe0ff 30 | 31 | #define PLACEHOLDER 0x0 32 | 33 | #define packed_struct struct __attribute__((packed)) 34 | 35 | typedef packed_struct 36 | { 37 | uint8_t push_rax; 38 | uint8_t push_rcx; 39 | uint8_t push_rdx; 40 | uint8_t push_rsi; 41 | uint8_t push_rdi; 42 | uint16_t push_r8; 43 | uint16_t push_r9; 44 | uint16_t push_r10; 45 | uint16_t push_r11; 46 | uint16_t mov_rax_imm64_1; 47 | void* address_of_tramp; 48 | uint16_t call_rax_1; 49 | uint16_t pop_r11; 50 | uint16_t pop_r10; 51 | uint16_t pop_r9; 52 | uint16_t pop_r8; 53 | uint8_t pop_rdi; 54 | uint8_t pop_rsi; 55 | uint8_t pop_rdx; 56 | uint8_t pop_rcx; 57 | uint8_t pop_rax; 58 | uint16_t mov_rax_imm64_2; 59 | void* return_address; 60 | uint16_t jmp_rax; 61 | } INJECT_TRAMPOLINE; 62 | 63 | static const INJECT_TRAMPOLINE BASE_INJECT_TRAMPOLINE = 64 | { PUSH_RAX, PUSH_RCX, PUSH_RDX, PUSH_RSI, PUSH_RDI, PUSH_R8, PUSH_R9, PUSH_R10, PUSH_R11, 65 | MOV_RAX_IMM64, PLACEHOLDER, CALL_RAX, 66 | POP_R11, POP_R10, POP_R9, POP_R8, POP_RDI, POP_RSI, POP_RDX, POP_RCX, POP_RAX, 67 | MOV_RAX_IMM64, PLACEHOLDER, JMP_RAX 68 | }; 69 | 70 | typedef packed_struct { 71 | uint16_t mov_rax_imm64; 72 | void* target_address; 73 | uint16_t jmp_rax; 74 | } JUMP_TRAMPOLINE; 75 | 76 | static const JUMP_TRAMPOLINE BASE_JUMP_TRAMPOLINE = 77 | { MOV_RAX_IMM64, PLACEHOLDER, JMP_RAX }; 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif // __AE_TRAMPS__H 83 | -------------------------------------------------------------------------------- /others/tmi/include/detector/MemRangeBucket.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #ifndef Helpers 4 | #define Helpers 5 | #include "Helpers.h" 6 | #endif 7 | using namespace std; 8 | 9 | #define MemRangeAttribute char 10 | #define HeapFlag 1 11 | #define StackFlag 2 12 | #define DefiningApp 4 13 | 14 | 15 | #define Permission char 16 | #define RangeCanRead 1 17 | #define RangeCanWrite 2 18 | #define RangeCanExecute 4 19 | 20 | class MemRangeBucket 21 | { 22 | public: 23 | uint64_t LowerBoundInclusive; 24 | uint64_t UpperBoundExclusive; 25 | uint64_t GetHitCount(); 26 | string GetResidingLibrary(); 27 | void IncrementCount(); 28 | void Initialize(string lowerBoundInclusive, string upperBoundExclusive, string definingLib, MemRangeAttribute flags, Permission permission); 29 | MemRangeBucket(); 30 | bool IsStackRange(); 31 | bool IsHeapRange(); 32 | bool IsInAppRange(); 33 | bool HasPermission(Permission permission); 34 | private: 35 | uint64_t hitCount; 36 | string residingLibrary; 37 | MemRangeAttribute flags; 38 | Permission permissions; 39 | }; 40 | 41 | void MemRangeBucket::Initialize(string lowerBoundInclusive, string upperBoundExclusive, string definingLib, MemRangeAttribute attributes, Permission permission) 42 | { 43 | LowerBoundInclusive = hexStringToUint64_t(lowerBoundInclusive); 44 | UpperBoundExclusive = hexStringToUint64_t(upperBoundExclusive); 45 | residingLibrary = definingLib; 46 | hitCount = 0; 47 | flags = attributes; 48 | permissions = permission; 49 | } 50 | 51 | MemRangeBucket::MemRangeBucket() 52 | { 53 | } 54 | 55 | uint64_t MemRangeBucket::GetHitCount() 56 | { 57 | return hitCount; 58 | } 59 | 60 | void MemRangeBucket::IncrementCount() 61 | { 62 | hitCount++; 63 | } 64 | 65 | bool MemRangeBucket::IsHeapRange() 66 | { 67 | return (flags & HeapFlag) != 0; 68 | } 69 | 70 | bool MemRangeBucket::IsStackRange() 71 | { 72 | return (flags & StackFlag) != 0; 73 | } 74 | 75 | bool MemRangeBucket::IsInAppRange() 76 | { 77 | return (flags & DefiningApp) != 0; 78 | } 79 | 80 | bool MemRangeBucket::HasPermission(Permission permission) 81 | { 82 | return (permission & permissions) == permission; 83 | } 84 | 85 | string MemRangeBucket::GetResidingLibrary() 86 | { 87 | return residingLibrary; 88 | } 89 | -------------------------------------------------------------------------------- /others/tmi/xed/include/xed-isa-set.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-isa-set.h 32 | 33 | 34 | #if !defined(_XED_ISA_SET_H_) 35 | # define _XED_ISA_SET_H_ 36 | 37 | #include "xed-common-hdrs.h" 38 | #include "xed-types.h" 39 | #include "xed-isa-set-enum.h" /* generated */ 40 | #include "xed-chip-enum.h" /* generated */ 41 | 42 | /// @ingroup ISASET 43 | /// return 1 if the isa_set is part included in the specified chip, 0 44 | /// otherwise. 45 | XED_DLL_EXPORT xed_bool_t 46 | xed_isa_set_is_valid_for_chip(xed_isa_set_enum_t isa_set, 47 | xed_chip_enum_t chip); 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /others/tmi/include/detector/HotSpotWindow.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "SharingEventType.h" 5 | #define NumberOfHotSpotPCsToTrack 8000 6 | class HotSpotWindow 7 | { 8 | private: 9 | int eventCounters[NumberOfTrackedEvents]; 10 | public: 11 | uint64_t WindowStartCycle; 12 | uint64_t WindowLengthInCycles; 13 | std::pair TopPCs[NumberOfHotSpotPCsToTrack]; 14 | HotSpotWindow(); 15 | bool WindowReady(); 16 | void IncrementEventCount(SharingEventType eventType); 17 | void Clear(); 18 | int GetEventCount(SharingEventType eventType); 19 | uint64_t GetTotalEventCount(); 20 | static int GetSmallestWindowIndex(HotSpotWindow* windows, int windowCount, SharingEventType eventType); 21 | 22 | }; 23 | 24 | HotSpotWindow::HotSpotWindow() 25 | { 26 | Clear(); 27 | } 28 | 29 | bool HotSpotWindow::WindowReady() 30 | { 31 | return WindowLengthInCycles != 0; 32 | } 33 | 34 | void HotSpotWindow::IncrementEventCount(SharingEventType eventType) 35 | { 36 | eventCounters[EventTypeToIndex(eventType)]++; 37 | } 38 | 39 | void HotSpotWindow::Clear() 40 | { 41 | WindowLengthInCycles = 0; 42 | WindowStartCycle = 0; 43 | for (int i = 0; i < NumberOfTrackedEvents; i++) 44 | { 45 | eventCounters[i] = 0; 46 | } 47 | for (int i = 0; i < NumberOfHotSpotPCsToTrack; i++) 48 | { 49 | TopPCs[i].first = TopPCs[i].second = 0; 50 | } 51 | } 52 | 53 | int HotSpotWindow::GetEventCount(SharingEventType eventType) 54 | { 55 | return eventCounters[EventTypeToIndex(eventType)]; 56 | } 57 | 58 | uint64_t HotSpotWindow::GetTotalEventCount() 59 | { 60 | uint64_t sum = 0; 61 | for (int i = 0; i < NumberOfTrackedEvents; i++) 62 | { 63 | sum += eventCounters[i]; 64 | } 65 | return sum; 66 | } 67 | 68 | int HotSpotWindow::GetSmallestWindowIndex(HotSpotWindow* windows, int windowCount, SharingEventType eventType) 69 | { 70 | int currMinCnt = INT_MAX; 71 | int currMinIndex = -1; 72 | int selectedIndex = EventTypeToIndex(eventType); 73 | for (int i = 0; i < windowCount; i++) 74 | { 75 | if (!windows[i].WindowReady()) continue; 76 | if (windows[i].eventCounters[selectedIndex] < currMinCnt) 77 | { 78 | currMinCnt = windows[i].eventCounters[selectedIndex]; 79 | currMinIndex = i; 80 | } 81 | } 82 | return currMinIndex; 83 | } 84 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/status.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "port/port.h" 7 | #include "leveldb/status.h" 8 | 9 | namespace leveldb { 10 | 11 | const char* Status::CopyState(const char* state) { 12 | uint32_t size; 13 | memcpy(&size, state, sizeof(size)); 14 | char* result = new char[size + 5]; 15 | memcpy(result, state, size + 5); 16 | return result; 17 | } 18 | 19 | Status::Status(Code code, const Slice& msg, const Slice& msg2) { 20 | assert(code != kOk); 21 | const uint32_t len1 = msg.size(); 22 | const uint32_t len2 = msg2.size(); 23 | const uint32_t size = len1 + (len2 ? (2 + len2) : 0); 24 | char* result = new char[size + 5]; 25 | memcpy(result, &size, sizeof(size)); 26 | result[4] = static_cast(code); 27 | memcpy(result + 5, msg.data(), len1); 28 | if (len2) { 29 | result[5 + len1] = ':'; 30 | result[6 + len1] = ' '; 31 | memcpy(result + 7 + len1, msg2.data(), len2); 32 | } 33 | state_ = result; 34 | } 35 | 36 | std::string Status::ToString() const { 37 | if (state_ == NULL) { 38 | return "OK"; 39 | } else { 40 | char tmp[30]; 41 | const char* type; 42 | switch (code()) { 43 | case kOk: 44 | type = "OK"; 45 | break; 46 | case kNotFound: 47 | type = "NotFound: "; 48 | break; 49 | case kCorruption: 50 | type = "Corruption: "; 51 | break; 52 | case kNotSupported: 53 | type = "Not implemented: "; 54 | break; 55 | case kInvalidArgument: 56 | type = "Invalid argument: "; 57 | break; 58 | case kIOError: 59 | type = "IO error: "; 60 | break; 61 | default: 62 | snprintf(tmp, sizeof(tmp), "Unknown code(%d): ", 63 | static_cast(code())); 64 | type = tmp; 65 | break; 66 | } 67 | std::string result(type); 68 | uint32_t length; 69 | memcpy(&length, state_, sizeof(length)); 70 | result.append(state_ + 5, length); 71 | return result; 72 | } 73 | } 74 | 75 | } // namespace leveldb 76 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/db/table_cache.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Thread-safe (provides internal synchronization) 6 | 7 | #ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 8 | #define STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 9 | 10 | #include 11 | #include 12 | #include "db/dbformat.h" 13 | #include "leveldb/cache.h" 14 | #include "leveldb/table.h" 15 | #include "port/port.h" 16 | 17 | namespace leveldb { 18 | 19 | class Env; 20 | 21 | class TableCache { 22 | public: 23 | TableCache(const std::string& dbname, const Options* options, int entries); 24 | ~TableCache(); 25 | 26 | // Return an iterator for the specified file number (the corresponding 27 | // file length must be exactly "file_size" bytes). If "tableptr" is 28 | // non-NULL, also sets "*tableptr" to point to the Table object 29 | // underlying the returned iterator, or NULL if no Table object underlies 30 | // the returned iterator. The returned "*tableptr" object is owned by 31 | // the cache and should not be deleted, and is valid for as long as the 32 | // returned iterator is live. 33 | Iterator* NewIterator(const ReadOptions& options, 34 | uint64_t file_number, 35 | uint64_t file_size, 36 | Table** tableptr = NULL); 37 | 38 | // If a seek to internal key "k" in specified file finds an entry, 39 | // call (*handle_result)(arg, found_key, found_value). 40 | Status Get(const ReadOptions& options, 41 | uint64_t file_number, 42 | uint64_t file_size, 43 | const Slice& k, 44 | void* arg, 45 | void (*handle_result)(void*, const Slice&, const Slice&)); 46 | 47 | // Evict any entry for the specified file number 48 | void Evict(uint64_t file_number); 49 | 50 | private: 51 | Env* const env_; 52 | const std::string dbname_; 53 | const Options* options_; 54 | Cache* cache_; 55 | 56 | Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**); 57 | }; 58 | 59 | } // namespace leveldb 60 | 61 | #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 62 | -------------------------------------------------------------------------------- /others/tmi/xed/xed-examples-ostreams.H: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | /// @file xed-examples-ostreams.H 32 | 33 | #ifndef _XED_EXAMPLES_OSTREAMS_H_ 34 | # define _XED_EXAMPLES_OSTREAMS_H_ 35 | 36 | #include "xed-types.h" 37 | #include "xed-portability.h" 38 | #if defined(__GNUC__) 39 | # if __GNUC__==2 40 | # include 41 | # else 42 | # include 43 | # endif 44 | #else 45 | # include 46 | #endif 47 | 48 | # if defined(XED_MSVC6) 49 | std::ostream& operator<<(std::ostream& o, xed_uint64_t x) ; 50 | std::ostream& operator<<(std::ostream& o, xed_int64_t x) ; 51 | std::ostream& operator<<(std::ostream& o, xed_int32_t x) ; 52 | std::ostream& operator<<(std::ostream& o, xed_uint32_t x) ; 53 | # endif 54 | #endif 55 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/arena.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | #include 7 | 8 | namespace leveldb { 9 | 10 | static const int kBlockSize = 4096; 11 | 12 | Arena::Arena() : memory_usage_(0) { 13 | alloc_ptr_ = NULL; // First allocation will allocate a block 14 | alloc_bytes_remaining_ = 0; 15 | } 16 | 17 | Arena::~Arena() { 18 | for (size_t i = 0; i < blocks_.size(); i++) { 19 | delete[] blocks_[i]; 20 | } 21 | } 22 | 23 | char* Arena::AllocateFallback(size_t bytes) { 24 | if (bytes > kBlockSize / 4) { 25 | // Object is more than a quarter of our block size. Allocate it separately 26 | // to avoid wasting too much space in leftover bytes. 27 | char* result = AllocateNewBlock(bytes); 28 | return result; 29 | } 30 | 31 | // We waste the remaining space in the current block. 32 | alloc_ptr_ = AllocateNewBlock(kBlockSize); 33 | alloc_bytes_remaining_ = kBlockSize; 34 | 35 | char* result = alloc_ptr_; 36 | alloc_ptr_ += bytes; 37 | alloc_bytes_remaining_ -= bytes; 38 | return result; 39 | } 40 | 41 | char* Arena::AllocateAligned(size_t bytes) { 42 | const int align = (sizeof(void*) > 8) ? sizeof(void*) : 8; 43 | assert((align & (align-1)) == 0); // Pointer size should be a power of 2 44 | size_t current_mod = reinterpret_cast(alloc_ptr_) & (align-1); 45 | size_t slop = (current_mod == 0 ? 0 : align - current_mod); 46 | size_t needed = bytes + slop; 47 | char* result; 48 | if (needed <= alloc_bytes_remaining_) { 49 | result = alloc_ptr_ + slop; 50 | alloc_ptr_ += needed; 51 | alloc_bytes_remaining_ -= needed; 52 | } else { 53 | // AllocateFallback always returned aligned memory 54 | result = AllocateFallback(bytes); 55 | } 56 | assert((reinterpret_cast(result) & (align-1)) == 0); 57 | return result; 58 | } 59 | 60 | char* Arena::AllocateNewBlock(size_t block_bytes) { 61 | char* result = new char[block_bytes]; 62 | blocks_.push_back(result); 63 | memory_usage_.NoBarrier_Store( 64 | reinterpret_cast(MemoryUsage() + block_bytes + sizeof(char*))); 65 | return result; 66 | } 67 | 68 | } // namespace leveldb 69 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/testutil.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 6 | #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 7 | 8 | #include "leveldb/env.h" 9 | #include "leveldb/slice.h" 10 | #include "util/random.h" 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | // Store in *dst a random string of length "len" and return a Slice that 16 | // references the generated data. 17 | extern Slice RandomString(Random* rnd, int len, std::string* dst); 18 | 19 | // Return a random key with the specified length that may contain interesting 20 | // characters (e.g. \x00, \xff, etc.). 21 | extern std::string RandomKey(Random* rnd, int len); 22 | 23 | // Store in *dst a string of length "len" that will compress to 24 | // "N*compressed_fraction" bytes and return a Slice that references 25 | // the generated data. 26 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 27 | size_t len, std::string* dst); 28 | 29 | // A wrapper that allows injection of errors. 30 | class ErrorEnv : public EnvWrapper { 31 | public: 32 | bool writable_file_error_; 33 | int num_writable_file_errors_; 34 | 35 | ErrorEnv() : EnvWrapper(Env::Default()), 36 | writable_file_error_(false), 37 | num_writable_file_errors_(0) { } 38 | 39 | virtual Status NewWritableFile(const std::string& fname, 40 | WritableFile** result) { 41 | if (writable_file_error_) { 42 | ++num_writable_file_errors_; 43 | *result = NULL; 44 | return Status::IOError(fname, "fake error"); 45 | } 46 | return target()->NewWritableFile(fname, result); 47 | } 48 | 49 | virtual Status NewAppendableFile(const std::string& fname, 50 | WritableFile** result) { 51 | if (writable_file_error_) { 52 | ++num_writable_file_errors_; 53 | *result = NULL; 54 | return Status::IOError(fname, "fake error"); 55 | } 56 | return target()->NewAppendableFile(fname, result); 57 | } 58 | }; 59 | 60 | } // namespace test 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 64 | -------------------------------------------------------------------------------- /others/tmi/xed/xed-examples-ostreams.cpp: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | Intel Open Source License 3 | 4 | Copyright (c) 2002-2014 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | #include "xed-examples-ostreams.H" 32 | #if defined(XED_MSVC6) 33 | std::ostream& operator<<(std::ostream& o, xed_uint64_t x) 34 | { 35 | o << (unsigned long) x; // No __uint64 IO with MSVS6 (VC98) 36 | return o; 37 | } 38 | std::ostream& operator<<(std::ostream& o, xed_int64_t x) 39 | { 40 | o << (long) x; // No __int64 IO with MSVS6 (VC98) 41 | return o; 42 | } 43 | std::ostream& operator<<(std::ostream& o, xed_int32_t x) 44 | { 45 | o << (long) x; // no __int32 IO with MSVS6 (VC98) 46 | return o; 47 | } 48 | std::ostream& operator<<(std::ostream& o, xed_uint32_t x) 49 | { 50 | o << (unsigned long) x; // no unsigned __int32 IO with MSVS6 (VC98) 51 | return o; 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /test_suites/false/false.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | struct timespec tpBegin2, tpEnd2; 8 | // These are inbuilt structures to store the time related activities 9 | 10 | // computes time in milliseconds given endTime and startTime timespec 11 | // structures. 12 | double compute(struct timespec start, struct timespec end) { 13 | double t; 14 | t = (end.tv_sec - start.tv_sec) * 1000; 15 | t += (end.tv_nsec - start.tv_nsec) * 0.000001; 16 | 17 | return t; 18 | } 19 | 20 | int *array; 21 | 22 | void *expensive_function(void *param) { 23 | int index = *((int *)param); 24 | int i; 25 | for (i = 0; i < 100000; i++) 26 | array[index] += 1; 27 | return NULL; 28 | } 29 | 30 | int main(int argc, char *argv[]) { 31 | array = (int*)malloc(1600 * sizeof(int)); 32 | int first_elem = 0; 33 | int bad_elem = 1; 34 | int good_elem = 99; 35 | int i; 36 | int indexes[16]; 37 | double time1; 38 | double time2; 39 | double time3; 40 | pthread_t threads[16]; 41 | for (i = 0; i < 16; i++) 42 | indexes[i] = i * bad_elem; 43 | 44 | //---------------------------START--------parallel computation with False 45 | // Sharing---------------------------- 46 | 47 | clock_gettime(CLOCK_REALTIME, &tpBegin2); 48 | for (i = 0; i < 16; i++) { 49 | pthread_create(&threads[i], NULL, expensive_function, 50 | (void *)&indexes[i]); 51 | } 52 | for (i = 0; i < 16; i++) { 53 | pthread_join(threads[i], NULL); 54 | } 55 | clock_gettime(CLOCK_REALTIME, &tpEnd2); 56 | 57 | //---------------------------END----------parallel computation with False 58 | // Sharing---------------------------- 59 | 60 | //--------------------------START------------------OUTPUT 61 | // STATS-------------------------------------------- 62 | printf("array[first_element]: %d\t\t array[bad_element]: %d\t\t " 63 | "array[good_element]: %d\n\n\n", 64 | array[first_elem], array[bad_elem], array[good_elem]); 65 | 66 | time2 = compute(tpBegin2, tpEnd2); 67 | printf("Time take with false sharing : %f ms\n", time2); 68 | //--------------------------END------------------OUTPUT 69 | // STATS-------------------------------------------- 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/table/iterator_wrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 6 | #define STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | #include "leveldb/slice.h" 10 | 11 | namespace leveldb { 12 | 13 | // A internal wrapper class with an interface similar to Iterator that 14 | // caches the valid() and key() results for an underlying iterator. 15 | // This can help avoid virtual function calls and also gives better 16 | // cache locality. 17 | class IteratorWrapper { 18 | public: 19 | IteratorWrapper(): iter_(NULL), valid_(false) { } 20 | explicit IteratorWrapper(Iterator* iter): iter_(NULL) { 21 | Set(iter); 22 | } 23 | ~IteratorWrapper() { delete iter_; } 24 | Iterator* iter() const { return iter_; } 25 | 26 | // Takes ownership of "iter" and will delete it when destroyed, or 27 | // when Set() is invoked again. 28 | void Set(Iterator* iter) { 29 | delete iter_; 30 | iter_ = iter; 31 | if (iter_ == NULL) { 32 | valid_ = false; 33 | } else { 34 | Update(); 35 | } 36 | } 37 | 38 | 39 | // Iterator interface methods 40 | bool Valid() const { return valid_; } 41 | Slice key() const { assert(Valid()); return key_; } 42 | Slice value() const { assert(Valid()); return iter_->value(); } 43 | // Methods below require iter() != NULL 44 | Status status() const { assert(iter_); return iter_->status(); } 45 | void Next() { assert(iter_); iter_->Next(); Update(); } 46 | void Prev() { assert(iter_); iter_->Prev(); Update(); } 47 | void Seek(const Slice& k) { assert(iter_); iter_->Seek(k); Update(); } 48 | void SeekToFirst() { assert(iter_); iter_->SeekToFirst(); Update(); } 49 | void SeekToLast() { assert(iter_); iter_->SeekToLast(); Update(); } 50 | 51 | private: 52 | void Update() { 53 | valid_ = iter_->Valid(); 54 | if (valid_) { 55 | key_ = iter_->key(); 56 | } 57 | } 58 | 59 | Iterator* iter_; 60 | bool valid_; 61 | Slice key_; 62 | }; 63 | 64 | } // namespace leveldb 65 | 66 | #endif // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 67 | -------------------------------------------------------------------------------- /others/tmi/include/tmimem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "pagestate.hpp" 4 | #include "tmi_allocator.hpp" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | typedef std::unordered_map, 15 | std::equal_to, 16 | tmi_allocator>> PageStateMap; 17 | 18 | extern "C" void* get_shared(void *base,size_t size,int type); 19 | extern "C" void tmi_commit(); 20 | 21 | extern "C" void* tmi_internal_alloc(size_t size); 22 | extern "C" void tmi_internal_dealloc(void *p); 23 | 24 | template inline T* tmi_get_shared(T* base){ 25 | return (T*)get_shared((void*)base,sizeof(T),0); 26 | } 27 | 28 | template <> 29 | inline pthread_mutex_t* tmi_get_shared(pthread_mutex_t* base){ 30 | return (pthread_mutex_t*)get_shared((void*)base,sizeof(pthread_mutex_t),1); 31 | } 32 | 33 | template <> 34 | inline pthread_cond_t* tmi_get_shared(pthread_cond_t* base){ 35 | return (pthread_cond_t*)get_shared((void*)base,sizeof(pthread_cond_t),2); 36 | } 37 | 38 | template <> 39 | inline pthread_spinlock_t* tmi_get_shared(pthread_spinlock_t* base){ 40 | return (pthread_spinlock_t*)get_shared((void*)base,sizeof(pthread_spinlock_t),3); 41 | } 42 | 43 | class memory{ 44 | static const size_t DEFAULT_TWIN_STATE_SIZE = 4096; 45 | 46 | static char *_persistentMemory; 47 | static char *_slabStart; 48 | static char *_slabEnd; 49 | static char *_slabPos; 50 | static char *_mmapPos; 51 | static char *_mmapPos2; 52 | 53 | static int _backingFd; 54 | 55 | static bool _initialized; 56 | 57 | static pagestate *_states; 58 | 59 | public: 60 | static bool init(); 61 | static void cleanup(); 62 | 63 | // Memory protection mechanisms for preventing false-sharing 64 | static int isProtectable(void *addr); 65 | 66 | static pagestate* getState(void *addr); 67 | static void allocStates(size_t size); 68 | static bool protectAddress(void *addr); 69 | static void protectAll(); 70 | static void handleSegv(int sig, void *addr); 71 | static void commit(int pid); 72 | 73 | // Functions that provide memory to the memory allocator 74 | static void* adjust_slab_memory(size_t size); 75 | static void* get_mmap_memory(size_t size); 76 | 77 | static void* get_shared(void *base, size_t size, int type = 0); 78 | }; 79 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/env_posix_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/env.h" 6 | 7 | #include "port/port.h" 8 | #include "util/testharness.h" 9 | #include "util/env_posix_test_helper.h" 10 | 11 | namespace leveldb { 12 | 13 | static const int kDelayMicros = 100000; 14 | static const int kReadOnlyFileLimit = 4; 15 | static const int kMMapLimit = 4; 16 | 17 | class EnvPosixTest { 18 | public: 19 | Env* env_; 20 | EnvPosixTest() : env_(Env::Default()) { } 21 | 22 | static void SetFileLimits(int read_only_file_limit, int mmap_limit) { 23 | EnvPosixTestHelper::SetReadOnlyFDLimit(read_only_file_limit); 24 | EnvPosixTestHelper::SetReadOnlyMMapLimit(mmap_limit); 25 | } 26 | }; 27 | 28 | TEST(EnvPosixTest, TestOpenOnRead) { 29 | // Write some test data to a single file that will be opened |n| times. 30 | std::string test_dir; 31 | ASSERT_OK(env_->GetTestDirectory(&test_dir)); 32 | std::string test_file = test_dir + "/open_on_read.txt"; 33 | 34 | FILE* f = fopen(test_file.c_str(), "w"); 35 | ASSERT_TRUE(f != NULL); 36 | const char kFileData[] = "abcdefghijklmnopqrstuvwxyz"; 37 | fputs(kFileData, f); 38 | fclose(f); 39 | 40 | // Open test file some number above the sum of the two limits to force 41 | // open-on-read behavior of POSIX Env leveldb::RandomAccessFile. 42 | const int kNumFiles = kReadOnlyFileLimit + kMMapLimit + 5; 43 | leveldb::RandomAccessFile* files[kNumFiles] = {0}; 44 | for (int i = 0; i < kNumFiles; i++) { 45 | ASSERT_OK(env_->NewRandomAccessFile(test_file, &files[i])); 46 | } 47 | char scratch; 48 | Slice read_result; 49 | for (int i = 0; i < kNumFiles; i++) { 50 | ASSERT_OK(files[i]->Read(i, 1, &read_result, &scratch)); 51 | ASSERT_EQ(kFileData[i], read_result[0]); 52 | } 53 | for (int i = 0; i < kNumFiles; i++) { 54 | delete files[i]; 55 | } 56 | ASSERT_OK(env_->DeleteFile(test_file)); 57 | } 58 | 59 | } // namespace leveldb 60 | 61 | int main(int argc, char** argv) { 62 | // All tests currently run with the same read-only file limits. 63 | leveldb::EnvPosixTest::SetFileLimits(leveldb::kReadOnlyFileLimit, 64 | leveldb::kMMapLimit); 65 | return leveldb::test::RunAllTests(); 66 | } 67 | -------------------------------------------------------------------------------- /others/tmi/benchmarks/leveldb/util/random.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_RANDOM_H_ 6 | #define STORAGE_LEVELDB_UTIL_RANDOM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | // A very simple random number generator. Not especially good at 13 | // generating truly random bits, but good enough for our needs in this 14 | // package. 15 | class Random { 16 | private: 17 | uint32_t seed_; 18 | public: 19 | explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) { 20 | // Avoid bad seeds. 21 | if (seed_ == 0 || seed_ == 2147483647L) { 22 | seed_ = 1; 23 | } 24 | } 25 | uint32_t Next() { 26 | static const uint32_t M = 2147483647L; // 2^31-1 27 | static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 28 | // We are computing 29 | // seed_ = (seed_ * A) % M, where M = 2^31-1 30 | // 31 | // seed_ must not be zero or M, or else all subsequent computed values 32 | // will be zero or M respectively. For all other values, seed_ will end 33 | // up cycling through every number in [1,M-1] 34 | uint64_t product = seed_ * A; 35 | 36 | // Compute (product % M) using the fact that ((x << 31) % M) == x. 37 | seed_ = static_cast((product >> 31) + (product & M)); 38 | // The first reduction may overflow by 1 bit, so we may need to 39 | // repeat. mod == M is not possible; using > allows the faster 40 | // sign-bit-based test. 41 | if (seed_ > M) { 42 | seed_ -= M; 43 | } 44 | return seed_; 45 | } 46 | // Returns a uniformly distributed value in the range [0..n-1] 47 | // REQUIRES: n > 0 48 | uint32_t Uniform(int n) { return Next() % n; } 49 | 50 | // Randomly returns true ~"1/n" of the time, and false otherwise. 51 | // REQUIRES: n > 0 52 | bool OneIn(int n) { return (Next() % n) == 0; } 53 | 54 | // Skewed: pick "base" uniformly from range [0,max_log] and then 55 | // return "base" random bits. The effect is to pick a number in the 56 | // range [0,2^max_log-1] with exponential bias towards smaller numbers. 57 | uint32_t Skewed(int max_log) { 58 | return Uniform(1 << Uniform(max_log + 1)); 59 | } 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_ 65 | --------------------------------------------------------------------------------