blob: c8c39e3156645cc2cc75697b4d08431d73a07672 [file] [log] [blame]
Anders Lewisf4447b92017-06-23 15:53:59 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _BIONIC_BENCHMARKS_UTIL_H_
18#define _BIONIC_BENCHMARKS_UTIL_H_
19
Anders Lewisa7b0f882017-07-24 20:01:13 -070020#include <map>
21#include <mutex>
22#include <string>
Anders Lewisf4447b92017-06-23 15:53:59 -070023#include <vector>
24
Anders Lewisa7b0f882017-07-24 20:01:13 -070025typedef void (*benchmark_func_t) (void);
26
27extern std::mutex g_map_lock;
28
29extern std::map<std::string, benchmark_func_t> g_str_to_func;
30
31static int __attribute__((unused)) EmplaceBenchmark (std::string fn_name, benchmark_func_t fn_ptr) {
32 g_map_lock.lock();
33 g_str_to_func.emplace(std::string(fn_name), fn_ptr);
34 g_map_lock.unlock();
35 return 0;
36}
37
38#define BIONIC_BENCHMARK(n) \
39 int _bionic_benchmark_##n __attribute__((unused)) = EmplaceBenchmark(std::string(#n), reinterpret_cast<benchmark_func_t>(n))
40
41constexpr auto KB = 1024;
42
43typedef struct {
44 long cpu_to_lock;
45 long num_iterations;
46 std::string xmlpath;
47 std::vector<std::string> extra_benchmarks;
48} bench_opts_t;
49
Anders Lewisf4447b92017-06-23 15:53:59 -070050// This function returns a pointer less than 2 * alignment + or_mask bytes into the array.
Anders Lewisa7b0f882017-07-24 20:01:13 -070051char* GetAlignedMemory(char* orig_ptr, size_t alignment, size_t or_mask);
Anders Lewisf4447b92017-06-23 15:53:59 -070052
Anders Lewisa7b0f882017-07-24 20:01:13 -070053char* GetAlignedPtr(std::vector<char>* buf, size_t alignment, size_t nbytes);
Anders Lewisf4447b92017-06-23 15:53:59 -070054
Anders Lewisa7b0f882017-07-24 20:01:13 -070055char* GetAlignedPtrFilled(std::vector<char>* buf, size_t alignment, size_t nbytes, char fill_byte);
Anders Lewisf4447b92017-06-23 15:53:59 -070056
Anders Lewisa7b0f882017-07-24 20:01:13 -070057bool LockToCPU(long cpu_to_lock);
Anders Lewisf4447b92017-06-23 15:53:59 -070058
59#endif // _BIONIC_BENCHMARKS_UTIL_H