Implement interface for bionic benchmarks.

Test: Unit tests.
Change-Id: Ic61932f61ddd572e2f045b601f9da6e090cdc45d
diff --git a/benchmarks/util.h b/benchmarks/util.h
index bd3d515..c8c39e3 100644
--- a/benchmarks/util.h
+++ b/benchmarks/util.h
@@ -17,15 +17,43 @@
 #ifndef _BIONIC_BENCHMARKS_UTIL_H_
 #define _BIONIC_BENCHMARKS_UTIL_H_
 
+#include <map>
+#include <mutex>
+#include <string>
 #include <vector>
 
+typedef void (*benchmark_func_t) (void);
+
+extern std::mutex g_map_lock;
+
+extern std::map<std::string, benchmark_func_t> g_str_to_func;
+
+static int  __attribute__((unused)) EmplaceBenchmark (std::string fn_name, benchmark_func_t fn_ptr) {
+  g_map_lock.lock();
+  g_str_to_func.emplace(std::string(fn_name), fn_ptr);
+  g_map_lock.unlock();
+  return 0;
+}
+
+#define BIONIC_BENCHMARK(n) \
+  int _bionic_benchmark_##n __attribute__((unused)) = EmplaceBenchmark(std::string(#n), reinterpret_cast<benchmark_func_t>(n))
+
+constexpr auto KB = 1024;
+
+typedef struct {
+  long cpu_to_lock;
+  long num_iterations;
+  std::string xmlpath;
+  std::vector<std::string> extra_benchmarks;
+} bench_opts_t;
+
 // This function returns a pointer less than 2 * alignment + or_mask bytes into the array.
-char *GetAlignedMemory(char *orig_ptr, size_t alignment, size_t or_mask);
+char* GetAlignedMemory(char* orig_ptr, size_t alignment, size_t or_mask);
 
-char *GetAlignedPtr(std::vector<char>* buf, size_t alignment, size_t nbytes);
+char* GetAlignedPtr(std::vector<char>* buf, size_t alignment, size_t nbytes);
 
-char *GetAlignedPtrFilled(std::vector<char>* buf, size_t alignment, size_t nbytes, char fill_byte);
+char* GetAlignedPtrFilled(std::vector<char>* buf, size_t alignment, size_t nbytes, char fill_byte);
 
-bool LockToCPU(int cpu_to_lock);
+bool LockToCPU(long cpu_to_lock);
 
 #endif // _BIONIC_BENCHMARKS_UTIL_H