upenn-acg / ocolos-public

Ocolos is the first online code layout optimization system for unmodified applications written in unmanaged languages.
BSD 2-Clause "Simplified" License
49 stars 14 forks source link

Ocolos: Online COde Layout OptimizationS

Ocolos is the first online code layout optimization system for unmodified applications written in unmanaged languages. Ocolos allows profile-guided optimization to be performed on a running process, instead of being performed offline and requiring the application to be re-launched. A description of how we implemented Ocolos and experimental results on MySQL-sysbench workloads are in MICRO'22 paper.

For the demonstration purpose, we integrate MySQL and sysbench to Ocolos, so this version of Ocolos ONLY works with MySQL.

Prerequisites

Please refer instructions from links or directly run commands listed below to install prerequisites:

Download ocolos for mysql

> git clone git@github.com:upenn-acg/ocolos-public.git

Install BOLT

To use llvm-bolt and perf2bolt utilities, BOLT needs to be installed. \ Please follow the commands below to install BOLT

> mkdir BOLT && cd BOLT
> git clone git@github.com:upenn-acg/BOLT.git llvm-bolt
> cd llvm-bolt
> git checkout ocolos/cont-opt
> cd ..
> mkdir build && cd build
> cmake -G "Unix Makefiles" ../llvm-bolt/llvm -DLLVM_TARGETS_TO_BUILD="X86;AArch64" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS="clang;lld;bolt"
> make -j

Build MySQL from source

> git clone https://github.com/mysql/mysql-server.git 
> cd mysql-server 
> git checkout 6846e6b2f72931991cc9fd589dc9946ea2ab58c9 

In CMakeList.txt, at line 580, please add [^2]: [^2]: If the mysqld binary compiled by gcc generates callq instructions rather than call instructions, please refer to the solution discussed in this page.

STRING_APPEND(CMAKE_C_FLAGS  " -fno-jump-tables")
STRING_APPEND(CMAKE_CXX_FLAGS " -fno-jump-tables")
STRING_APPEND(CMAKE_C_FLAGS " -no-pie")
STRING_APPEND(CMAKE_CXX_FLAGS " -no-pie")

Also, in CMakeList.txt, turn off ld.gold linker: \ change OPTION(USE_LD_GOLD "Use GNU gold linker" ON) to be OPTION(USE_LD_GOLD "Use GNU gold linker" OFF)

Then build mysqld from source:

> export CC=gcc 
> export CXX=g++
> mkdir build && cd build 
> cmake .. -DWITH_BOOST={path of the boost_1_73_0 directory} -DCMAKE_CXX_LINK_FLAGS=-Wl,--emit-relocs -DCMAKE_C_LINK_FLAGS=-Wl,--emit-relocs -DBUILD_CONFIG=mysql_release 
> make -j
> make install

To initialize MySQL, run:

> chown -R {user} {path to MySQL directory}
> {path to MySQL directory}/bin/mysqld --initialize-insecure --user=root --datadir={your data dir path of MySQL} 
> {path to MySQL directory}/bin/mysqld --user=root --port=3306 --datadir={your data dir path of MySQL}

In another terminal, run:

> mysql -u root
> CREATE USER 'ocolos'@'localhost';
> GRANT ALL PRIVILEGES ON *.* TO 'ocolos'@'localhost' WITH GRANT OPTION;
> CREATE DATABASE ocolos_db;
> QUIT;
> mysqladmin -u root shutdown

Note:

  1. {path to MySQL directory} is normally /usr/local/mysql unless otherwise specified during MySQL server's installation.
  2. {user} should be your linux user name.

Build Sysbench

> sudo apt-get update 
> sudo apt-get install sysbench

Or if you prefer to build sysbench from source, please refer instructions in the following webpage:\ https://github.com/akopytov/sysbench

Build & run Ocolos

> make
> ./extract_call_sites
> ./tracer

UPDATES: Continuous Optimization - use profile from C1 to build new BOLTed binary

UPDATES: Support for the AArch64 platform

Miscellaneous (notes about how to debug Ocolos)

In Makefile's CXXFLAGS,

If the code replacement runs into a failure, you may want to do the following things to fix this problem