未验证 提交 e7a4942b 编写于 作者: O openharmony_ci 提交者: Gitee

!960 Add Benchmarks

Merge pull request !960 from yinchuang/Add_hot_case_benchmark
......@@ -432,7 +432,7 @@ if (is_lite_system && current_os == "ohos") {
deps = [ "libc-test:musl_libc_test" ]
}
group("benchmark_musl") {
deps = [ "Benchmark:benchmark_musl_group" ]
group("benchmark-musl") {
deps = [ "Benchmark/musl:benchmark_musl_group" ]
}
}
......@@ -12,7 +12,6 @@
# limitations under the License.
import("//build/ohos.gni")
import("//third_party/musl/musl_config.gni")
group("benchmark_musl_group") {
deps = [
......@@ -30,6 +29,7 @@ ohos_executable("musl_benchmark") {
"libc_errno.cpp",
"libc_fcntl.cpp",
"libc_fenv.cpp",
"libc_ioctl.cpp",
"libc_linker.cpp",
"libc_locale.cpp",
"libc_malloc.cpp",
......@@ -37,8 +37,10 @@ ohos_executable("musl_benchmark") {
"libc_mman.cpp",
"libc_network.cpp",
"libc_pthread.cpp",
"libc_random.cpp",
"libc_sched.cpp",
"libc_select.cpp",
"libc_signal.cpp",
"libc_stat.cpp",
"libc_stdio.cpp",
"libc_stdlib.cpp",
......@@ -46,14 +48,17 @@ ohos_executable("musl_benchmark") {
"libc_syscall.cpp",
"libc_time.cpp",
"libc_unistd.cpp",
"socket_test.cpp",
"util.cpp",
]
deps = [ "//third_party/benchmark:benchmark" ]
deps = [
"//third_party/benchmark:benchmark",
"//third_party/cJSON:cjson",
]
defines = []
if (defined(non_current_interface) && non_current_interface) {
defines += [ "ONO_CURRENT_INTERFACE" ]
if (current_cpu == "arm") {
defines = ["SYSTEM_32_BIT"]
}
part_name = "musl"
......@@ -63,6 +68,10 @@ ohos_executable("musl_benchmark") {
ohos_executable("musl_dlopen") {
sources = [ "libc_dlopen.cpp" ]
if (current_cpu == "arm") {
defines = ["SYSTEM_32_BIT"]
}
part_name = "musl"
subsystem_name = "thirdparty"
}
......@@ -30,6 +30,10 @@
#include "util.h"
extern "C" {
#include "cJSON.h"
}
static const std::vector<int> commonArgs {
8,
16,
......@@ -44,23 +48,14 @@ static const std::vector<int> commonArgs {
128 * K,
};
static const std::vector<int> limitSizes{
1,
2,
3,
4,
5,
6,
7,
};
std::map<std::string, std::pair<benchmark_func, std::string>> g_allBenchmarks;
std::map<std::string, std::pair<BenchmarkFunc, std::string>> g_allBenchmarks;
std::mutex g_benchmarkLock;
typedef std::vector<std::vector<int64_t>> args_vector;
static struct option g_benchmarkLongOptions[] = {
{"musl_cpu", required_argument, nullptr, 'c'},
{"musl_iterations", required_argument, nullptr, 'i'},
{"musl_json", required_argument, nullptr, 'j'},
{"help", no_argument, nullptr, 'h'},
{nullptr, 0, nullptr, 0},
};
......@@ -70,6 +65,7 @@ void PrintUsageAndExit()
printf("Usage:\n");
printf("musl_benchmarks [--musl_cpu=<cpu_to_isolate>]\n");
printf(" [--musl_iterations=<num_iter>]\n");
printf(" [--musl_json=<path_to_json>]\n");
printf(" [<original benchmark flags>]\n");
printf("benchmark flags:\n");
......@@ -109,7 +105,7 @@ bench_opts_t ParseOptions(int argc, char **argv)
extern int opterr;
opterr = 0; // Don't show unrecognized option error.
while ((opt = getopt_long(argc, argv, "c:i:a:h", g_benchmarkLongOptions, 0)) != -1) {
while ((opt = getopt_long(argc, argv, "c:i:j:h", g_benchmarkLongOptions, 0)) != -1) {
switch (opt) {
case 'c':
if (*optarg) {
......@@ -135,6 +131,14 @@ bench_opts_t ParseOptions(int argc, char **argv)
PrintUsageAndExit();
}
break;
case 'j':
if (*optarg) {
opts.jsonPath = optarg;
} else {
printf("ERROR: no argument specified for musl_json\n");
PrintUsageAndExit();
}
break;
case 'h':
PrintUsageAndExit();
break;
......@@ -147,7 +151,7 @@ bench_opts_t ParseOptions(int argc, char **argv)
return opts;
}
void LockAndRun(benchmark::State &state, benchmark_func func, int cpuNum)
void LockAndRun(benchmark::State &state, BenchmarkFunc func, int cpuNum)
{
if (cpuNum >= 0) {
cpu_set_t cpuset;
......@@ -212,45 +216,40 @@ static args_vector GetArgs(const std::vector<int> &sizes, int value1, int value2
return args;
}
static args_vector GetArgs(const std::vector<int> &sizes, const std::vector<int> &limits, int value)
{
args_vector args;
for (int size : sizes) {
for (int limit : limits) {
args.push_back({size, limit, value});
}
}
return args;
}
std::map<std::string, args_vector> GetPresetArgs()
{
std::map<std::string, args_vector> presetArgs {
{"COMMON_ARGS", GetArgs(commonArgs)},
{"ALIGNED_ONEBUF", GetArgs(commonArgs, 0)},
{"ALIGNED_TWOBUF", GetArgs(commonArgs, 0, 0)},
{"STRING_LIMIT", GetArgs(commonArgs, limitSizes, 0)},
{"MATH_COMMON", args_vector{{0}, {1}, {2}, {3}, {4}, {5}}},
{"BENCHMARK_VARIABLE", args_vector{{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}}},
{"REALPATH_VARIABLE", args_vector{{0}, {1}, {2}, {3}, {4}}},
{"MMAP_SIZE", args_vector{{8}, {16}, {32}, {64}, {128}, {512}}},
{"BENCHMARK_5", args_vector{{0}, {1}, {2}, {3}, {4}}},
{"BENCHMARK_8", args_vector{{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}}},
};
return presetArgs;
}
void RegisterSingleBenchmark(bench_opts_t opts, const std::string &funcName, args_vector *runArgs)
void RegisterSingleBenchmark(bench_opts_t optsFromJson, bench_opts_t optsFromCommandLine,
const std::string &funcName, args_vector *runArgs)
{
if (g_allBenchmarks.find(funcName) == g_allBenchmarks.end()) {
errx(1, "ERROR: No benchmark for function %s", funcName.c_str());
}
benchmark_func func = g_allBenchmarks.at(funcName).first;
long iterNum = optsFromCommandLine.iterNum ? optsFromCommandLine.iterNum : optsFromJson.iterNum;
int cpuNum = -1;
if (optsFromCommandLine.cpuNum >= 0) {
cpuNum = optsFromCommandLine.cpuNum;
} else if (optsFromJson.cpuNum >= 0) {
cpuNum = optsFromJson.cpuNum;
}
BenchmarkFunc func = g_allBenchmarks.at(funcName).first;
for (const std::vector<int64_t> &args : (*runArgs)) {
// It will call LockAndRun(func, opts.cpuNum).
auto registration = benchmark::RegisterBenchmark(funcName.c_str(), LockAndRun, func, opts.cpuNum)->Args(args);
if (opts.iterNum > 0) {
registration->Iterations(opts.iterNum);
auto registration = benchmark::RegisterBenchmark(funcName.c_str(), LockAndRun, func, cpuNum)->Args(args);
if (iterNum > 0) {
registration->Iterations(iterNum);
}
}
}
......@@ -259,10 +258,96 @@ void RegisterAllBenchmarks(const bench_opts_t &opts, std::map<std::string, args_
{
for (auto &entry : g_allBenchmarks) {
auto &funcInfo = entry.second;
args_vector arg_vector;
args_vector *runArgs = ResolveArgs(&arg_vector, funcInfo.second, presetArgs);
RegisterSingleBenchmark(opts, entry.first, runArgs);
args_vector argVector;
args_vector *runArgs = ResolveArgs(&argVector, funcInfo.second, presetArgs);
RegisterSingleBenchmark(bench_opts_t(), opts, entry.first, runArgs);
}
}
std::string Trim(const std::string& str)
{
size_t first = str.find_first_not_of(' ');
if (std::string::npos == first) {
return "";
}
size_t last = str.find_last_not_of(' ');
return str.substr(first, (last - first + 1));
}
int RegisterJsonBenchmarks(const bench_opts_t &opts, std::map<std::string, args_vector> &presetArgs)
{
char *file = nullptr;
cJSON *json = nullptr;
// Read JSON string from file
file = ReadJsonFile(opts.jsonPath.c_str());
if (file == nullptr) {
printf("fail to read file or no data read.\n");
return JOSN_ERROR_FILE_READ_FAILED;
}
// Load JSON data
json = cJSON_Parse(file);
if (json == nullptr) {
printf("JSON parsing failed, incorrect JSON format.\n");
return JOSN_ERROR_JSON_FORMAT;
}
// Parsing Fields
cJSON *item = cJSON_GetObjectItem(json, "InterfaceUsecases");
if (item) {
int arraySize = cJSON_GetArraySize(item); // Get the size of the array
// Parsing each member in an array and register the functions.
for (int i = 0; i < arraySize; i++) {
cJSON *arrayItem = cJSON_GetArrayItem(item, i); // Extract array subscript object
if (arrayItem == nullptr) {
continue;
}
// Parsing data
cJSON *obj = cJSON_GetObjectItem(arrayItem, "name");
std::string fnName;
if (obj != nullptr) {
fnName = std::string(obj->valuestring);
} else {
printf("missing name element or error parsing name text\n");
}
obj = cJSON_GetObjectItem(arrayItem, "args");
std::string jsonArgs;
args_vector argVector;
args_vector *runArgs = nullptr;
if (obj != nullptr) {
jsonArgs = std::string(obj->valuestring);
runArgs = ResolveArgs(&argVector, Trim(jsonArgs), presetArgs);
} else {
runArgs = ResolveArgs(&argVector, "", presetArgs);
}
bench_opts_t jsonOpts{};
obj = cJSON_GetObjectItem(arrayItem, "iterations");
if (obj != nullptr) {
jsonOpts.iterNum = obj->valueint;
}
obj = cJSON_GetObjectItem(arrayItem, "cpu");
if (obj != nullptr) {
jsonOpts.cpuNum = obj->valueint;
}
RegisterSingleBenchmark(jsonOpts, opts, fnName, runArgs);
}
}
if (json != nullptr) {
cJSON_Delete(json);
}
return JSON_SUCCESS;
}
static bool IsRegularFileExists(const std::string& file)
{
struct stat st;
return stat(file.c_str(), &st) != -1 && S_ISREG(st.st_mode);
}
int main(int argc, char **argv)
......@@ -271,11 +356,28 @@ int main(int argc, char **argv)
bench_opts_t opts = ParseOptions(argc, argv);
std::vector<char *> argvAfterShift(argc);
ShiftOptions(argc, argv, &argvAfterShift);
RegisterAllBenchmarks(opts, presetArgs);
if (opts.jsonPath.empty()) {
RegisterAllBenchmarks(opts, presetArgs);
} else if (!IsRegularFileExists(opts.jsonPath)) {
std::string file("suites" + opts.jsonPath);
if (opts.jsonPath[0] == '/' || !IsRegularFileExists(file)) {
printf("Cannot find json file %s: does not exist or is not a file.\n", opts.jsonPath.c_str());
return 1;
}
opts.jsonPath = file;
}
if (!opts.jsonPath.empty()) {
if (int err = RegisterJsonBenchmarks(opts, presetArgs)) {
return err;
}
}
if (setpriority(PRIO_PROCESS, 0, -20)) {
perror("Set priority of process failed.\n");
}
int argcAfterShift = argvAfterShift.size();
benchmark::Initialize(&argcAfterShift, argvAfterShift.data());
benchmark::RunSpecifiedBenchmarks();
}
}
\ No newline at end of file
......@@ -49,6 +49,64 @@ static void Bm_function_Tolower_all_ascii(benchmark::State &state)
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Isspace_space(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(isspace(' '));
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Isspace_all_ascii(benchmark::State &state)
{
for (auto _ : state) {
for(int i = 0; i < TOTAL_COMMON_CHARACTERS; i++) {
benchmark::DoNotOptimize(isspace(i));
}
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Isalnum_a(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(isalnum('a'));
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Isalnum_A(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(isalnum('A'));
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Isalnum_0(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(isalnum('0'));
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Isalnum_all_ascii(benchmark::State &state)
{
for (auto _ : state) {
for(int i = 0; i < TOTAL_COMMON_CHARACTERS; i++) {
benchmark::DoNotOptimize(isalnum(i));
}
}
state.SetItemsProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_Tolower_a);
MUSL_BENCHMARK(Bm_function_Tolower_A);
MUSL_BENCHMARK(Bm_function_Tolower_all_ascii);
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Tolower_all_ascii);
MUSL_BENCHMARK(Bm_function_Isspace_space);
MUSL_BENCHMARK(Bm_function_Isspace_all_ascii);
MUSL_BENCHMARK(Bm_function_Isalnum_a);
MUSL_BENCHMARK(Bm_function_Isalnum_A);
MUSL_BENCHMARK(Bm_function_Isalnum_0);
MUSL_BENCHMARK(Bm_function_Isalnum_all_ascii);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "sys/types.h"
#include "dirent.h"
......@@ -36,5 +35,4 @@ static void Bm_function_Opendir(benchmark::State &state)
}
}
MUSL_BENCHMARK(Bm_function_Opendir);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Opendir);
\ No newline at end of file
......@@ -13,16 +13,15 @@
* limitations under the License.
*/
#include "util.h"
#include <dlfcn.h>
#include <sys/time.h>
#include <stdio.h>
#include <iostream>
#define LIBACE_PATH "system/lib64/libace.z.so"
class ScopeTime {
public:
explicit ScopeTime() : cost(0)
explicit ScopeTime(const char *name) : cost(0), soName(name)
{
gettimeofday(&timeStart, nullptr);
}
......@@ -33,23 +32,24 @@ public:
gettimeofday(&timeCurrent, nullptr);
cost = (timeCurrent.tv_sec - timeStart.tv_sec) * 1000.0 +
(double)(timeCurrent.tv_usec - timeStart.tv_usec) / 1000.0;
printf("current cost %f ms.\n", cost);
printf("%s current cost %f ms.\n", soName, cost);
}
~ScopeTime()
{
gettimeofday(&timeEnd, nullptr);
cost = (timeEnd.tv_sec - timeStart.tv_sec) * 1000.0 + (double)(timeEnd.tv_usec - timeStart.tv_usec) / 1000.0;
printf("dlopen cost %f ms.\n", cost);
printf("dlopen %s cost %f ms.\n", soName, cost);
}
private:
struct timeval timeStart, timeEnd;
double cost;
const char *soName;
};
static void DoDlopen(const char *fileName, int flags)
{
ScopeTime st;
ScopeTime st = ScopeTime(fileName);
void *handle = dlopen(fileName, flags);
if (handle == nullptr) {
printf("dlopen error: %s", dlerror());
......
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include <sys/epoll.h>
#include <errno.h>
......@@ -28,19 +27,19 @@
using namespace std;
#define EVENTSIZE 10
struct epoll_event events[EVENTSIZE], event;
struct epoll_event g_events[EVENTSIZE], g_event;
// Used to create an epoll object to record events for files to be listened to
static void Bm_function_Epoll_createl(benchmark::State &state)
{
for (auto _ : state) {
int epoll_fd = epoll_create1(0);
if (epoll_fd == -1) {
int epollFd = epoll_create1(0);
if (epollFd == -1) {
perror("epoll_createl");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(epoll_fd);
close(epoll_fd);
benchmark::DoNotOptimize(epollFd);
close(epollFd);
}
state.SetBytesProcessed(state.iterations());
......@@ -49,22 +48,22 @@ static void Bm_function_Epoll_createl(benchmark::State &state)
// Used to add, modify, or delete events to an epoll object
static void Bm_function_Epoll_ctl(benchmark::State &state)
{
int epoll_fd = epoll_create1(0);
if (epoll_fd == -1) {
int epollFd = epoll_create1(0);
if (epollFd == -1) {
perror("epoll_createl");
exit(EXIT_FAILURE);
}
int fd = open("/dev/zero", O_RDONLY);
int fd = open("/dev/zero", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("open epoll_ctl");
exit(EXIT_FAILURE);
}
event.events = EPOLLIN | EPOLLET;
event.data.fd = fd;
g_event.events = EPOLLIN | EPOLLET;
g_event.data.fd = fd;
for (auto _ : state) {
benchmark::DoNotOptimize(epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &event));
benchmark::DoNotOptimize(epoll_ctl(epollFd, EPOLL_CTL_ADD, fd, &g_event));
}
close(epoll_fd);
close(epollFd);
close(fd);
state.SetBytesProcessed(state.iterations());
}
......@@ -72,29 +71,28 @@ static void Bm_function_Epoll_ctl(benchmark::State &state)
// Used to wait for the file descriptor in the epoll object to appear for the event
static void Bm_function_Epoll_wait(benchmark::State &state)
{
int epoll_fd = epoll_create1(0);
if (epoll_fd == -1) {
int epollFd = epoll_create1(0);
if (epollFd == -1) {
perror("epoll_createl");
exit(EXIT_FAILURE);
}
int fd = open("/dev/zero", O_RDONLY);
int fd = open("/dev/zero", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("open epoll_wait");
exit(EXIT_FAILURE);
}
event.events = EPOLLIN | EPOLLET;
event.data.fd = fd;
g_event.events = EPOLLIN | EPOLLET;
g_event.data.fd = fd;
for (auto _ : state) {
epoll_wait(epoll_fd, events, EVENTSIZE, 0);
epoll_wait(epollFd, g_events, EVENTSIZE, 0);
}
close(epoll_fd);
close(epollFd);
close(fd);
state.SetBytesProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_Epoll_createl);
MUSL_BENCHMARK(Bm_function_Epoll_ctl);
MUSL_BENCHMARK(Bm_function_Epoll_wait);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Epoll_wait);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "errno.h"
#include "util.h"
......@@ -101,5 +100,4 @@ MUSL_BENCHMARK(Bm_function_Strerror_eacces);
MUSL_BENCHMARK(Bm_function_Strerror_eexist);
MUSL_BENCHMARK(Bm_function_Strerror_einval);
MUSL_BENCHMARK(Bm_function_Strerror_erofs);
MUSL_BENCHMARK(Bm_function_Strerror_etimeout);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Strerror_etimeout);
\ No newline at end of file
......@@ -23,10 +23,10 @@
using namespace std;
#ifdef ONO_CURRENT_INTERFACE
#define LOCK_SIZE 10
static void Bm_function_Fcntl_getfl(benchmark::State &state)
{
int fd = open("/etc/passwd", O_RDONLY);
int fd = open("/etc/passwd", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("open fcntl_getfl");
exit(EXIT_FAILURE);
......@@ -45,7 +45,7 @@ static void Bm_function_Fcntl_getfl(benchmark::State &state)
static void Bm_function_Fcntl_setfl(benchmark::State &state)
{
int flags = fcntl(STDIN_FILENO, F_GETFL);
int flags = fcntl(STDIN_FILENO, F_GETFL, 0);
if (flags < 0) {
perror("fcntl_setfl F_GETFL");
exit(EXIT_FAILURE);
......@@ -58,31 +58,39 @@ static void Bm_function_Fcntl_setfl(benchmark::State &state)
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(ret);
state.PauseTiming();
flags &= ~O_NONBLOCK;
if (fcntl(STDOUT_FILENO, F_SETFL, flags) < -1) {
perror("fcntl_setfl proc");
exit(EXIT_FAILURE);
}
state.ResumeTiming();
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Fcntl_setlkw(benchmark::State &state)
{
int fd = open("/dev/zero", O_RDWR);
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open fcntl_setlkw");
exit(EXIT_FAILURE);
}
struct flock f_lock;
struct flock fdLock;
for (auto _ : state) {
state.PauseTiming();
f_lock.l_type = F_WRLCK;
f_lock.l_whence = SEEK_SET;
f_lock.l_start = 0;
f_lock.l_len = 0;
if (fcntl(fd, F_SETLKW, &f_lock) < 0) {
fdLock.l_type = F_WRLCK;
fdLock.l_whence = SEEK_SET;
fdLock.l_start = 0;
fdLock.l_len = LOCK_SIZE;
if (fcntl(fd, F_SETLKW, &fdLock) < 0) {
perror("fcntl_setlkw F_WRLCK");
exit(EXIT_FAILURE);
}
f_lock.l_type = F_UNLCK;
fdLock.l_type = F_UNLCK;
state.ResumeTiming();
int ret = fcntl(fd, F_SETLKW, &f_lock);
int ret = fcntl(fd, F_SETLKW, &fdLock);
if (ret < 0) {
perror("fcntl_setlkw proc");
exit(EXIT_FAILURE);
......@@ -95,7 +103,7 @@ static void Bm_function_Fcntl_setlkw(benchmark::State &state)
static void Bm_function_Fcntl_dupfd(benchmark::State &state)
{
int fd = open("/etc/passwd", O_RDONLY);
int fd = open("/etc/passwd", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("open fcntl_dupfd");
exit(EXIT_FAILURE);
......@@ -117,25 +125,25 @@ static void Bm_function_Fcntl_dupfd(benchmark::State &state)
static void Bm_function_Fcntl_setlk(benchmark::State &state)
{
int fd = open("/dev/zero", O_RDWR);
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open fcntl_setlk");
exit(EXIT_FAILURE);
}
struct flock f_lock;
struct flock fdLock;
for (auto _ : state) {
state.PauseTiming();
f_lock.l_type = F_WRLCK;
f_lock.l_whence = SEEK_SET;
f_lock.l_start = 0;
f_lock.l_len = 0;
if (fcntl(fd, F_SETLK, &f_lock) < 0) {
fdLock.l_type = F_WRLCK;
fdLock.l_whence = SEEK_SET;
fdLock.l_start = 0;
fdLock.l_len = LOCK_SIZE;
if (fcntl(fd, F_SETLK, &fdLock) < 0) {
perror("fcntl_setlk F_WRLCK");
exit(EXIT_FAILURE);
}
f_lock.l_type = F_UNLCK;
fdLock.l_type = F_UNLCK;
state.ResumeTiming();
int ret = fcntl(fd, F_SETLK, &f_lock);
int ret = fcntl(fd, F_SETLK, &fdLock);
if (ret < 0) {
perror("fcntl_setlk proc");
exit(EXIT_FAILURE);
......@@ -148,20 +156,20 @@ static void Bm_function_Fcntl_setlk(benchmark::State &state)
static void Bm_function_Fcntl_getlk(benchmark::State &state)
{
int fd = open("/dev/zero", O_RDWR);
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open fcntl_getlk");
exit(EXIT_FAILURE);
}
struct flock f_lock;
struct flock fdLock;
for (auto _ : state) {
state.PauseTiming();
f_lock.l_type = F_RDLCK;
f_lock.l_whence = SEEK_SET;
f_lock.l_start = 0;
f_lock.l_len = 0;
fdLock.l_type = F_RDLCK;
fdLock.l_whence = SEEK_SET;
fdLock.l_start = 0;
fdLock.l_len = LOCK_SIZE;
state.ResumeTiming();
int ret = fcntl(fd, F_GETLK, &f_lock);
int ret = fcntl(fd, F_GETLK, &fdLock);
if (ret < 0) {
perror("fcntl_getlk proc");
exit(EXIT_FAILURE);
......@@ -174,7 +182,7 @@ static void Bm_function_Fcntl_getlk(benchmark::State &state)
static void Bm_function_Fcntl_getfd(benchmark::State &state)
{
int fd = open("/dev/zero", O_RDWR);
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open fcntl_getfd");
exit(EXIT_FAILURE);
......@@ -193,7 +201,7 @@ static void Bm_function_Fcntl_getfd(benchmark::State &state)
static void Bm_function_Fcntl_setfd(benchmark::State &state)
{
int fd = open("/dev/zero", O_RDWR);
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open fcntl_setfd");
exit(EXIT_FAILURE);
......@@ -213,17 +221,24 @@ static void Bm_function_Fcntl_setfd(benchmark::State &state)
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(ret);
state.PauseTiming();
flags &= ~FD_CLOEXEC;
if (fcntl(fd, F_SETFD, flags) < -1) {
perror("fcntl_setfd F_SETFD");
exit(EXIT_FAILURE);
}
state.ResumeTiming();
}
close(fd);
state.SetBytesProcessed(state.iterations());
}
#endif
static void Bm_function_Open_rdonly(benchmark::State &state)
{
const char *filename = "/proc/self/cmdline";
for (auto _ : state) {
int fd = open(filename, O_RDONLY);
int fd = open(filename, O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("open_rdonly proc");
exit(EXIT_FAILURE);
......@@ -240,7 +255,7 @@ static void Bm_function_Open_rdwr(benchmark::State &state)
{
const char *filename = "/dev/zero";
for (auto _ : state) {
int fd = open(filename, O_RDWR);
int fd = open(filename, O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open_rdwr proc");
exit(EXIT_FAILURE);
......@@ -257,7 +272,7 @@ static void Bm_function_Open_creat_rdwr(benchmark::State &state)
{
const char *filename = "/data/log/hiview/sys_event_logger/event.db";
for (auto _ : state) {
int fd = open(filename, O_RDWR | O_CREAT);
int fd = open(filename, O_RDWR | O_CREAT, OPEN_MODE);
if (fd == -1) {
perror("open_creat_rdwr proc");
exit(EXIT_FAILURE);
......@@ -270,7 +285,6 @@ static void Bm_function_Open_creat_rdwr(benchmark::State &state)
state.SetItemsProcessed(state.iterations());
}
#ifdef ONO_CURRENT_INTERFACE
MUSL_BENCHMARK(Bm_function_Fcntl_getfl);
MUSL_BENCHMARK(Bm_function_Fcntl_setfl);
MUSL_BENCHMARK(Bm_function_Fcntl_setlkw);
......@@ -279,8 +293,6 @@ MUSL_BENCHMARK(Bm_function_Fcntl_setlk);
MUSL_BENCHMARK(Bm_function_Fcntl_getlk);
MUSL_BENCHMARK(Bm_function_Fcntl_getfd);
MUSL_BENCHMARK(Bm_function_Fcntl_setfd);
#endif
MUSL_BENCHMARK(Bm_function_Open_rdonly);
MUSL_BENCHMARK(Bm_function_Open_rdwr);
MUSL_BENCHMARK(Bm_function_Open_creat_rdwr);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "fenv.h"
#include "util.h"
......@@ -27,5 +26,4 @@ static void Bm_function_Fegetround(benchmark::State &state)
state.SetBytesProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_Fegetround);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Fegetround);
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <benchmark/benchmark.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include "util.h"
#define DEVICE_FILE "/dev/tty"
// Used to perform control operations on device files
// set baud rate
static void Bm_function_Ioctl_baudrate(benchmark::State &state)
{
struct termios ttydev;
int ret;
int fd = open(DEVICE_FILE, O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open ioctl");
exit(EXIT_FAILURE);
}
ret = tcgetattr(fd, &ttydev);
if (ret == -1) {
perror("Property fetch failed");
exit(EXIT_FAILURE);
}
int speed = cfgetospeed(&ttydev);
cfsetospeed(&ttydev, B19200);
cfsetispeed(&ttydev, B19200);
for (auto _ : state) {
ret = ioctl(fd, TCSETS, &ttydev);
if (ret < 0) {
perror("ioctl");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(ret);
}
cfsetospeed(&ttydev, speed);
cfsetispeed(&ttydev, speed);
ret = ioctl(fd, TCSETS, &ttydev);
if (ret == -1) {
perror("Failed to restore baud rate");
exit(EXIT_FAILURE);
}
close(fd);
}
MUSL_BENCHMARK(Bm_function_Ioctl_baudrate);
\ No newline at end of file
......@@ -20,8 +20,7 @@
using namespace std;
#define LIBGLES_MALI_PATH "/vendor/lib64/chipsetsdk/libGLES_mali.so"
#if (!defined(SYSTEM_32_BIT))
static vector<string> syms = {
"eglGetProcAddress",
"eglChooseConfig",
......@@ -518,5 +517,5 @@ static void Bm_function_dlsym_libGLES_mali(benchmark::State &state)
DoDlsym(handle);
}
}
MUSL_BENCHMARK(Bm_function_dlsym_libGLES_mali);
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_dlsym_libGLES_mali);
#endif
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include <locale.h>
#include <langinfo.h>
......@@ -38,7 +37,7 @@ using namespace std;
static void Bm_function_Setlocale_All(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(setlocale(LC_ALL, NULL));
benchmark::DoNotOptimize(setlocale(LC_ALL, nullptr));
}
state.SetBytesProcessed(state.iterations());
}
......@@ -62,7 +61,7 @@ static void Bm_function_Setlocale_All2(benchmark::State &state)
static void Bm_function_Setlocale_Collate(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(setlocale(LC_COLLATE, NULL));
benchmark::DoNotOptimize(setlocale(LC_COLLATE, nullptr));
}
state.SetBytesProcessed(state.iterations());
}
......@@ -70,7 +69,7 @@ static void Bm_function_Setlocale_Collate(benchmark::State &state)
static void Bm_function_Setlocale_Ctype(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(setlocale(LC_CTYPE, NULL));
benchmark::DoNotOptimize(setlocale(LC_CTYPE, nullptr));
}
state.SetBytesProcessed(state.iterations());
}
......@@ -78,7 +77,7 @@ static void Bm_function_Setlocale_Ctype(benchmark::State &state)
static void Bm_function_Setlocale_Time(benchmark::State &state)
{
for (auto _ : state) {
benchmark::DoNotOptimize(setlocale(LC_TIME, NULL));
benchmark::DoNotOptimize(setlocale(LC_TIME, nullptr));
}
state.SetBytesProcessed(state.iterations());
}
......@@ -89,6 +88,7 @@ static void Bm_function_Locale_nl_langinfo(benchmark::State &state)
benchmark::DoNotOptimize(nl_langinfo(CODESET));
}
}
static void Bm_function_Locale_localeconv(benchmark::State &state)
{
for (auto _ : state) {
......@@ -96,6 +96,17 @@ static void Bm_function_Locale_localeconv(benchmark::State &state)
}
}
static void Bm_function_Uselocale(benchmark::State &state)
{
locale_t oldLocale;
locale_t newLocale = newlocale(LC_ALL_MASK, "zh_CN.UTF-8", nullptr);
for (auto _ : state) {
oldLocale = uselocale(newLocale);
newLocale = uselocale(oldLocale);
}
state.SetBytesProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_Setlocale_All);
MUSL_BENCHMARK(Bm_function_Setlocale_All1);
MUSL_BENCHMARK(Bm_function_Setlocale_All2);
......@@ -104,4 +115,4 @@ MUSL_BENCHMARK(Bm_function_Setlocale_Ctype);
MUSL_BENCHMARK(Bm_function_Setlocale_Time);
MUSL_BENCHMARK(Bm_function_Locale_nl_langinfo);
MUSL_BENCHMARK(Bm_function_Locale_localeconv);
#endif
MUSL_BENCHMARK(Bm_function_Uselocale);
......@@ -19,76 +19,98 @@
using namespace std;
#ifdef ONO_CURRENT_INTERFACE
#define PI 3.14159265
#define FLT_MIN 1.175494351e-38F
static const double DOUBLE_VALUES[] = { 0.1, 10.0, -100.0, 0.0001, 5.14e11, -0.0001, 10000000.0, -100000000.0 };
static const double COSSIN_VALUES[] = { -334.143, -2.0, -1.0, 0.0, 0.5, 1.0, 243.01, 3.14 };
static const long double DIVIDEND_VALUES[] = { 10.5L, -10.5L, 2.71L, -2.71L, 3.14159265358979323846L,
-3.14159265358979323846L, 1.0 / 3.0L, -1.0 / 3.0L };
static const long double DIVISOR_VALUES[] = { 3.0L, -3.0L, 1.414L, -1.414L, 0.5L, -0.5L,
2.7182818284590452354L, -2.7182818284590452354L };
// The function generates a value that has the size of the parameter x and the symbol of the parameter y
static void Bm_function_Copysignl(benchmark::State &state)
static void Bm_function_Copysignl_Allpositive(benchmark::State &state)
{
long double x = 2417851639229258349412352.000000;
long double y = 6051711999279104.000000;
for (auto _ : state) {
// x is the result, y is the symbol
benchmark::DoNotOptimize(copysignl(x, y));
}
state.SetItemsProcessed(state.iterations());
}
// remainder
static void Bm_function_Copysignl_Allnegative(benchmark::State &state)
{
long double x = -2417851639229258349412352.000000;
long double y = -6051711999279104.000000;
for (auto _ : state) {
benchmark::DoNotOptimize(copysignl(x, y));
}
}
static void Bm_function_Copysignl_Np(benchmark::State &state)
{
long double x = -2417851639229258349412352.000000;
long double y = 6051711999279104.000000;
for (auto _ : state) {
benchmark::DoNotOptimize(copysignl(x, y));
}
}
static void Bm_function_Copysignl_Pn(benchmark::State &state)
{
long double x = 2417851639229258349412352.000000;
long double y = -6051711999279104.000000;
for (auto _ : state) {
benchmark::DoNotOptimize(copysignl(x, y));
}
}
// remainder(long doubel)
static void Bm_function_Fmodl(benchmark::State &state)
{
long double x = 6051711999279104.000000;
long double y = 536870912.000000;
long double x = DIVIDEND_VALUES[state.range(0)];
long double y = DIVISOR_VALUES[state.range(0)];
for (auto _ : state) {
benchmark::DoNotOptimize(fmodl(x, y));
}
state.SetItemsProcessed(state.iterations());
}
#endif
// The 3.14th power of e
static void Bm_function_Exp(benchmark::State &state)
{
double x = 3.14;
double x = DOUBLE_VALUES[state.range(0)];
for (auto _ : state) {
benchmark::DoNotOptimize(exp(x));
}
state.SetItemsProcessed(state.iterations());
}
#ifdef ONO_CURRENT_INTERFACE
// The logarithm of base e and x
static void Bm_function_Log(benchmark::State &state)
{
double x = 3.14;
double x = DOUBLE_VALUES[state.range(0)];
for (auto _ : state) {
benchmark::DoNotOptimize(log(x));
}
state.SetItemsProcessed(state.iterations());
}
// Returns the cosine of the radian angle x
static void Bm_function_Cos(benchmark::State &state)
{
double x = 6.302892;
double x = COSSIN_VALUES[state.range(0)];
double val = PI / 180.0;
for (auto _ : state) {
benchmark::DoNotOptimize(cos(x * val));
}
state.SetItemsProcessed(state.iterations());
}
// Break floating point number into mantissa and exponent
static void Bm_function_Frexpl(benchmark::State &state)
{
long double x = 1024.0020;
long double x = DIVIDEND_VALUES[state.range(0)];
int e;
for (auto _ : state) {
benchmark::DoNotOptimize(frexpl(x, &e));
}
state.SetItemsProcessed(state.iterations());
}
// x * 2 ^ n
......@@ -182,24 +204,64 @@ static void Bm_function_Scalbnl4(benchmark::State &state)
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Scalbnf1(benchmark::State &state)
{
float x = 3.8;
int n = 1024;
for (auto _ : state) {
benchmark::DoNotOptimize(scalbnf(x, n));
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Scalbnf2(benchmark::State &state)
{
float x = 10.9;
int n = -1023;
for (auto _ : state) {
benchmark::DoNotOptimize(scalbnf(x, n));
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Scalbnf3(benchmark::State &state)
{
float x = -3.8;
int n = 1024;
for (auto _ : state) {
benchmark::DoNotOptimize(scalbnf(x, n));
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Scalbnf4(benchmark::State &state)
{
float x = -10.9;
int n = -1023;
for (auto _ : state) {
benchmark::DoNotOptimize(scalbnf(x, n));
}
state.SetItemsProcessed(state.iterations());
}
// remainder
static void Bm_function_Fmod(benchmark::State &state)
{
double x = 10.5;
double y = 3.2;
double x = (double)DIVIDEND_VALUES[state.range(0)];
double y = (double)DIVISOR_VALUES[state.range(0)];
for (auto _ : state) {
benchmark::DoNotOptimize(fmod(x, y));
}
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_sin(benchmark::State &state)
// Returns the sine of the radian angle x
static void Bm_function_Sin(benchmark::State &state)
{
double x = 45.0;
double x = COSSIN_VALUES[state.range(0)];
double val = PI / 180.0;
for (auto _ : state) {
benchmark::DoNotOptimize(sin(x*val));
}
state.SetItemsProcessed(state.iterations());
}
// FP_INFINITE The specified value is positive or negative infinity
......@@ -242,11 +304,23 @@ static void Bm_function_fpclassifyl3(benchmark::State &state)
state.SetItemsProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_Copysignl);
MUSL_BENCHMARK(Bm_function_Fmodl);
MUSL_BENCHMARK(Bm_function_Log);
MUSL_BENCHMARK(Bm_function_Cos);
MUSL_BENCHMARK(Bm_function_Frexpl);
static void Bm_function_Expm1(benchmark::State &state)
{
double x = DOUBLE_VALUES[state.range(0)];
for (auto _ : state) {
benchmark::DoNotOptimize(expm1(x));
}
state.SetItemsProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_Copysignl_Allpositive);
MUSL_BENCHMARK(Bm_function_Copysignl_Allnegative);
MUSL_BENCHMARK(Bm_function_Copysignl_Np);
MUSL_BENCHMARK(Bm_function_Copysignl_Pn);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Fmodl, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Log, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Cos, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Frexpl, "BENCHMARK_8");
MUSL_BENCHMARK(Bm_function_Scalbn1);
MUSL_BENCHMARK(Bm_function_Scalbn2);
MUSL_BENCHMARK(Bm_function_Scalbn3);
......@@ -255,12 +329,15 @@ MUSL_BENCHMARK(Bm_function_Scalbnl1);
MUSL_BENCHMARK(Bm_function_Scalbnl2);
MUSL_BENCHMARK(Bm_function_Scalbnl3);
MUSL_BENCHMARK(Bm_function_Scalbnl4);
MUSL_BENCHMARK(Bm_function_Fmod);
MUSL_BENCHMARK(Bm_function_sin);
MUSL_BENCHMARK(Bm_function_Scalbnf1);
MUSL_BENCHMARK(Bm_function_Scalbnf2);
MUSL_BENCHMARK(Bm_function_Scalbnf3);
MUSL_BENCHMARK(Bm_function_Scalbnf4);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Fmod, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Sin, "BENCHMARK_8");
MUSL_BENCHMARK(Bm_function_fpclassifyl);
MUSL_BENCHMARK(Bm_function_fpclassifyl1);
MUSL_BENCHMARK(Bm_function_fpclassifyl2);
MUSL_BENCHMARK(Bm_function_fpclassifyl3);
#endif
MUSL_BENCHMARK(Bm_function_Exp);
\ No newline at end of file
MUSL_BENCHMARK_WITH_ARG(Bm_function_Expm1, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Exp, "BENCHMARK_8");
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "sys/types.h"
#include "sys/stat.h"
......@@ -21,20 +20,84 @@
#include "sys/mman.h"
#include "unistd.h"
#include "stdio.h"
#include "malloc.h"
#include "util.h"
using namespace std;
static void Bm_function_Mmap_1(benchmark::State &state)
static const vector<int> mmapFlags = {
MAP_PRIVATE | MAP_ANONYMOUS,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGE_2MB,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGE_1GB,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGE_2MB | MAP_POPULATE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGE_1GB | MAP_POPULATE,
};
static const vector<int> mmapLength {
8,
16,
64,
1 * K,
4 * K,
64 * K,
256 * K,
1 * M,
4 * M,
64 * M,
256 * M,
1 * G,
};
static const vector<int> mdviseType {
MADV_NORMAL,
MADV_RANDOM,
MADV_SEQUENTIAL,
MADV_WILLNEED,
MADV_DONTNEED,
MADV_FREE,
MADV_REMOVE,
MADV_HUGEPAGE,
MADV_SOFT_OFFLINE
};
static const vector<int> mprotectLength {
1,
2,
4,
32,
1 * K,
4 * K,
32 * K,
1 * M,
};
static void PrepareArgs(benchmark::internal::Benchmark* b)
{
int fd = open("/data/data/my_mmap1.txt", O_RDWR | O_CREAT);
if (fd == -1) {
perror("open mmap1");
exit(EXIT_FAILURE);
for (auto l : mmapLength) {
for (auto f : mmapFlags) {
b->Args({l, f});
}
}
}
static void PrepareArgsInMdvise(benchmark::internal::Benchmark* b)
{
for (auto l : mmapLength) {
for (auto t : mdviseType) {
b->Args({l, t});
}
}
}
static void Bm_function_Mmap_anonymous(benchmark::State &state)
{
size_t length = state.range(0);
int flags = state.range(1);
for (auto _ : state) {
char* mem = (char *)mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0);
char* mem = (char *)mmap(nullptr, length, PROT_READ | PROT_WRITE, flags, -1, 0);
if (mem != MAP_FAILED) {
benchmark::DoNotOptimize(mem);
state.PauseTiming();
......@@ -42,43 +105,36 @@ static void Bm_function_Mmap_1(benchmark::State &state)
state.ResumeTiming();
}
}
close(fd);
remove("/data/data/my_mmap1.txt");
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Mmap_2(benchmark::State &state)
static void Bm_function_Munmap_anonymous(benchmark::State &state)
{
int fd = open("/data/data/my_mmap2.txt", O_RDWR | O_CREAT);
if (fd == -1) {
perror("open mmap2");
exit(EXIT_FAILURE);
}
size_t length = state.range(0);
int flags = state.range(1);
for (auto _ : state) {
char* mem = (char *)mmap(NULL, length, PROT_READ | PROT_EXEC, MAP_FIXED | MAP_PRIVATE, fd, 0);
state.PauseTiming();
char* mem = (char *)mmap(nullptr, length, PROT_READ | PROT_WRITE, flags, -1, 0);
state.ResumeTiming();
if (mem != MAP_FAILED) {
benchmark::DoNotOptimize(mem);
state.PauseTiming();
munmap(mem, length);
state.ResumeTiming();
}
}
close(fd);
remove("/data/data/my_mmap2.txt");
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Mmap_3(benchmark::State &state)
static void Bm_function_Mmap_fd(benchmark::State &state)
{
int fd = open("/data/data/my_mmap3.txt", O_RDWR | O_CREAT);
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open mmap3");
perror("open /dev/zero failed.");
exit(EXIT_FAILURE);
}
size_t length = state.range(0);
int flags = state.range(1);
for (auto _ : state) {
char* mem = (char *)mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, fd, 0);
char* mem = (char *)mmap(nullptr, length, PROT_READ | PROT_WRITE, flags, fd, 0);
if (mem != MAP_FAILED) {
benchmark::DoNotOptimize(mem);
state.PauseTiming();
......@@ -87,75 +143,60 @@ static void Bm_function_Mmap_3(benchmark::State &state)
}
}
close(fd);
remove("/data/data/my_mmap3.txt");
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Munmap(benchmark::State &state)
static void Bm_function_Munmap_fd(benchmark::State &state)
{
int fd = open("/data/data/my_munmap.txt", O_RDWR | O_CREAT);
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open munmap");
perror("open /dev/zero failed.");
exit(EXIT_FAILURE);
}
size_t length = state.range(0);
int flags = state.range(1);
for (auto _ : state) {
state.PauseTiming();
char* mem = (char*)mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
char* mem = (char *)mmap(nullptr, length, PROT_READ | PROT_WRITE, flags, fd, 0);
state.ResumeTiming();
if (mem != MAP_FAILED) {
state.ResumeTiming();
benchmark::DoNotOptimize(munmap(mem, length));
benchmark::DoNotOptimize(mem);
munmap(mem, length);
}
}
close(fd);
remove("/data/data/my_munmap.txt");
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Mmap_anonymous(benchmark::State &state)
static void Bm_function_Madvise(benchmark::State &state)
{
int fd = open("/data/data/my_mmap_anonymous.txt", O_RDWR | O_CREAT);
if (fd == -1) {
perror("open anonymous mmap");
exit(EXIT_FAILURE);
}
size_t length = state.range(0);
int type = state.range(1);
int *addr = (int*)mmap(nullptr, length, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
for (auto _ : state) {
int *addr = (int*)mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
if (addr != MAP_FAILED) {
benchmark::DoNotOptimize(addr);
state.PauseTiming();
munmap(addr, length);
state.ResumeTiming();
}
benchmark::DoNotOptimize(madvise(addr, length, type));
}
close(fd);
remove("/data/data/my_mmap_anonymous.txt");
state.SetItemsProcessed(state.iterations());
madvise(addr, length, MADV_NORMAL);
munmap(addr, length);
}
static void Bm_function_Madvise(benchmark::State &state)
static void Bm_function_mprotect(benchmark::State &state)
{
int fd = open("/data/data/my_mmap_anonymous.txt", O_RDWR | O_CREAT);
if (fd == -1) {
perror("open anonymous mmap");
exit(EXIT_FAILURE);
}
size_t length = state.range(0);
int *addr = (int*)mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
size_t pagesize = sysconf(_SC_PAGE_SIZE);
size_t size = pagesize * mprotectLength[state.range(0)];
void *pages = memalign(pagesize, size);
for (auto _ : state) {
benchmark::DoNotOptimize(madvise(addr, length, 0));
benchmark::DoNotOptimize(mprotect(pages, size, PROT_READ | PROT_WRITE));
}
munmap(addr, length);
close(fd);
remove("/data/data/my_mmap_anonymous.txt");
state.SetItemsProcessed(state.iterations());
free(pages);
}
MUSL_BENCHMARK_WITH_ARG(Bm_function_Mmap_1, "MMAP_SIZE");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Mmap_2, "MMAP_SIZE");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Mmap_3, "MMAP_SIZE");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Munmap, "MMAP_SIZE");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Mmap_anonymous, "MMAP_SIZE");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Madvise, "MMAP_SIZE");
#endif
\ No newline at end of file
BENCHMARK(Bm_function_Mmap_anonymous)->Apply(PrepareArgs);
BENCHMARK(Bm_function_Munmap_anonymous)->Apply(PrepareArgs);
BENCHMARK(Bm_function_Mmap_fd)->Apply(PrepareArgs);
BENCHMARK(Bm_function_Munmap_fd)->Apply(PrepareArgs);
BENCHMARK(Bm_function_Madvise)->Apply(PrepareArgsInMdvise);
MUSL_BENCHMARK_WITH_ARG(Bm_function_mprotect, "BENCHMARK_8");
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "sys/types.h"
#include "sys/socket.h"
......@@ -54,6 +53,110 @@ static void Bm_function_Getaddrinfo_intranet1(benchmark::State &state)
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_Getaddrinfo_intranet2(benchmark::State &state)
{
struct addrinfo hint;
struct addrinfo *res;
bzero(&hint, sizeof(struct addrinfo));
hint.ai_flags = AI_ALL; // Find IPv4 and IPV6
hint.ai_family = AF_UNSPEC; // not specified
for (auto _ : state) {
int n = getaddrinfo("127.0.0.1", nullptr, &hint, &res);
if (n != 0) {
perror("getaddrinfo intranet2");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(n);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_Getaddrinfo_intranet3(benchmark::State &state)
{
struct addrinfo hint;
struct addrinfo *res;
bzero(&hint, sizeof(struct addrinfo));
hint.ai_flags = AI_V4MAPPED; // If IPV6 is not found, return IPv4 mapped in ipv6 format
hint.ai_family = AF_INET6; // IPv6 Internet Domain
for (auto _ : state) {
int n = getaddrinfo("127.0.0.1", nullptr, &hint, &res);
if (n != 0) {
perror("getaddrinfo intranet3");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(n);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_Getaddrinfo_intranet4(benchmark::State &state)
{
struct addrinfo hint;
struct addrinfo *res;
bzero(&hint, sizeof(struct addrinfo));
hint.ai_flags = AI_V4MAPPED; // If IPV6 is not found, return IPv4 mapped in ipv6 format
hint.ai_family = AF_UNSPEC; // not specified
for (auto _ : state) {
int n = getaddrinfo("127.0.0.1", nullptr, &hint, &res);
if (n != 0) {
perror("getaddrinfo intranet4");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(n);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_Getaddrinfo_intranet5(benchmark::State &state)
{
struct addrinfo hint;
struct addrinfo *res;
bzero(&hint, sizeof(struct addrinfo));
hint.ai_flags = AI_ADDRCONFIG; // Query the configured address type IPV4 or IPV6
hint.ai_family = AF_UNSPEC; // not specified
for (auto _ : state) {
int n = getaddrinfo("127.0.0.1", nullptr, &hint, &res);
if (n != 0) {
perror("getaddrinfo intranet5");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(n);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_Getaddrinfo_intranet6(benchmark::State &state)
{
struct addrinfo hint;
struct addrinfo *res;
bzero(&hint, sizeof(struct addrinfo));
hint.ai_flags = AI_NUMERICSERV;
hint.ai_family = AF_UNSPEC;
for (auto _ : state) {
int n = getaddrinfo("127.0.0.1", nullptr, &hint, &res);
if (n != 0) {
perror("getaddrinfo intranet6");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(n);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_Getaddrinfo_intranet7(benchmark::State &state)
{
struct addrinfo *res;
for (auto _ : state) {
int n = getaddrinfo("127.0.0.1", nullptr, nullptr, &res);
if (n != 0) {
perror("getaddrinfo intranet7");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(n);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_Network_ntohs(benchmark::State &state)
{
uint16_t srcPort = 5060;
......@@ -61,7 +164,13 @@ static void Bm_function_Network_ntohs(benchmark::State &state)
benchmark::DoNotOptimize(ntohs(srcPort));
}
}
MUSL_BENCHMARK(Bm_function_Getaddrinfo_external_network);
MUSL_BENCHMARK(Bm_function_Getaddrinfo_intranet1);
MUSL_BENCHMARK(Bm_function_Network_ntohs);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Getaddrinfo_intranet2);
MUSL_BENCHMARK(Bm_function_Getaddrinfo_intranet3);
MUSL_BENCHMARK(Bm_function_Getaddrinfo_intranet4);
MUSL_BENCHMARK(Bm_function_Getaddrinfo_intranet5);
MUSL_BENCHMARK(Bm_function_Getaddrinfo_intranet6);
MUSL_BENCHMARK(Bm_function_Getaddrinfo_intranet7);
MUSL_BENCHMARK(Bm_function_Network_ntohs);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "pthread.h"
#include "semaphore.h"
......@@ -24,23 +23,23 @@
static void Bm_function_pthread_mutexattr_settype(benchmark::State &state)
{
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
while (state.KeepRunning()) {
benchmark::DoNotOptimize(pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_NORMAL));
benchmark::DoNotOptimize(pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_NORMAL));
}
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutexattr_destroy(&mutexAttr);
}
static void Bm_function_pthread_mutex_trylock_fast(benchmark::State &state)
{
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_NORMAL);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_NORMAL);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
......@@ -49,13 +48,13 @@ static void Bm_function_pthread_mutex_trylock_fast(benchmark::State &state)
static void Bm_function_pthread_mutex_trylock_errchk(benchmark::State &state)
{
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
......@@ -64,13 +63,13 @@ static void Bm_function_pthread_mutex_trylock_errchk(benchmark::State &state)
static void Bm_function_pthread_mutex_trylock_rec(benchmark::State &state)
{
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
......@@ -79,13 +78,13 @@ static void Bm_function_pthread_mutex_trylock_rec(benchmark::State &state)
static void Bm_function_pthread_mutex_trylock_pi_fast(benchmark::State &state)
{
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_NORMAL);
pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_NORMAL);
pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
......@@ -94,13 +93,13 @@ static void Bm_function_pthread_mutex_trylock_pi_fast(benchmark::State &state)
static void Bm_function_pthread_mutex_trylock_pi_errorcheck(benchmark::State &state)
{
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
......@@ -109,13 +108,13 @@ static void Bm_function_pthread_mutex_trylock_pi_errorcheck(benchmark::State &st
static void Bm_function_pthread_mutex_trylock_pi_rec(benchmark::State &state)
{
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);
......@@ -126,12 +125,12 @@ static void Bm_function_pthread_mutex_timedlock_fast(benchmark::State &state)
{
struct timespec ts = {.tv_sec = 1, .tv_nsec = 0};
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_NORMAL);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_NORMAL);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_timedlock(&mutex, &ts);
pthread_mutex_unlock(&mutex);
......@@ -142,13 +141,13 @@ static void Bm_function_pthread_mutex_timedlock_errchk(benchmark::State &state)
{
struct timespec ts = {.tv_sec = 1, .tv_nsec = 0};
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_timedlock(&mutex, &ts);
pthread_mutex_unlock(&mutex);
......@@ -159,13 +158,13 @@ static void Bm_function_pthread_mutex_timedlock_rec(benchmark::State &state)
{
struct timespec ts = {.tv_sec = 1, .tv_nsec = 0};
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_timedlock(&mutex, &ts);
pthread_mutex_unlock(&mutex);
......@@ -176,13 +175,13 @@ static void Bm_function_pthread_mutex_timedlock_pi_fast(benchmark::State &state)
{
struct timespec ts = {.tv_sec = 1, .tv_nsec = 0};
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_NORMAL);
pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_NORMAL);
pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_timedlock(&mutex, &ts);
pthread_mutex_unlock(&mutex);
......@@ -193,13 +192,13 @@ static void Bm_function_pthread_mutex_timedlock_pi_errchk(benchmark::State &stat
{
struct timespec ts = {.tv_sec = 1, .tv_nsec = 0};
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK);
pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_timedlock(&mutex, &ts);
pthread_mutex_unlock(&mutex);
......@@ -210,13 +209,13 @@ static void Bm_function_pthread_mutex_timedlock_pi_rec(benchmark::State &state)
{
struct timespec ts = {.tv_sec = 1, .tv_nsec = 0};
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutexattr_setprotocol(&mutex_attr, PTHREAD_PRIO_INHERIT);
pthread_mutexattr_t mutexAttr;
pthread_mutexattr_init(&mutexAttr);
pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
pthread_mutex_init(&mutex, &mutexAttr);
pthread_mutexattr_destroy(&mutexAttr);
while (state.KeepRunning()) {
pthread_mutex_timedlock(&mutex, &ts);
pthread_mutex_unlock(&mutex);
......@@ -244,6 +243,37 @@ static void Bm_function_pthread_mutex_init(benchmark::State &state)
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_pthread_mutex_init_destroy(benchmark::State &state)
{
pthread_mutex_t mutex;
for (auto _ : state) {
pthread_mutex_init(&mutex, nullptr);
pthread_mutex_destroy(&mutex);
}
}
static void Bm_function_pthread_cond_init(benchmark::State &state)
{
pthread_cond_t cond;
for (auto _ : state) {
pthread_cond_init(&cond, nullptr);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_pthread_cond_init_destroy(benchmark::State &state)
{
pthread_cond_t cond;
for (auto _ : state) {
pthread_cond_init(&cond, nullptr);
pthread_cond_destroy(&cond);
}
state.SetBytesProcessed(state.iterations());
}
static void BM_pthread_rwlock_tryread(benchmark::State& state)
{
pthread_rwlock_t lock;
......@@ -325,8 +355,8 @@ static void Bm_function_pthread_cond_timedwait(benchmark::State &state)
{
pthread_mutex_t mutex;
pthread_cond_t cond;
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
pthread_mutex_init(&mutex, nullptr);
pthread_cond_init(&cond, nullptr);
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 1;
......@@ -340,32 +370,32 @@ static void Bm_function_pthread_cond_timedwait(benchmark::State &state)
state.SetBytesProcessed(state.iterations());
}
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
void* thread_task1(void* arg)
pthread_cond_t g_cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t g_mutex1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t g_mutex2 = PTHREAD_MUTEX_INITIALIZER;
void* ThreadTaskOne(void* arg)
{
pthread_mutex_lock(&mutex1);
pthread_cond_wait(&cond, &mutex1);
pthread_mutex_lock(&g_mutex1);
pthread_cond_wait(&g_cond, &g_mutex1);
sleep(1);
pthread_mutex_unlock(&mutex1);
pthread_mutex_unlock(&g_mutex1);
return nullptr;
}
void* thread_task2(void* arg)
void* ThreadTaskTwo(void* arg)
{
pthread_mutex_lock(&mutex2);
pthread_cond_wait(&cond, &mutex2);
pthread_mutex_lock(&g_mutex2);
pthread_cond_wait(&g_cond, &g_mutex2);
sleep(1);
pthread_mutex_unlock(&mutex2);
pthread_mutex_unlock(&g_mutex2);
return nullptr;
}
void* broadcastNotifyMutex(void* arg)
void* BroadcastNotifyMutex(void* arg)
{
benchmark::State *statePtr = (benchmark::State *)arg;
statePtr->ResumeTiming();
benchmark::DoNotOptimize(pthread_cond_broadcast(&cond));
benchmark::DoNotOptimize(pthread_cond_broadcast(&g_cond));
statePtr->PauseTiming();
return nullptr;
}
......@@ -374,14 +404,14 @@ static void Bm_function_pthread_cond_broadcast(benchmark::State &state)
{
while (state.KeepRunning()) {
state.PauseTiming();
pthread_t thread_1, thread_2, thread_3;
pthread_create(&thread_1, nullptr, thread_task1, nullptr);
pthread_create(&thread_2, nullptr, thread_task2, nullptr);
pthread_t threadOne, threadTwo, threadThree;
pthread_create(&threadOne, nullptr, ThreadTaskOne, nullptr);
pthread_create(&threadTwo, nullptr, ThreadTaskTwo, nullptr);
sleep(3);
pthread_create(&thread_3, nullptr, broadcastNotifyMutex, &state);
pthread_join(thread_1, nullptr);
pthread_join(thread_2, nullptr);
pthread_join(thread_3, nullptr);
pthread_create(&threadThree, nullptr, BroadcastNotifyMutex, &state);
pthread_join(threadOne, nullptr);
pthread_join(threadTwo, nullptr);
pthread_join(threadThree, nullptr);
}
state.SetBytesProcessed(state.iterations());
}
......@@ -416,7 +446,7 @@ static void Bm_function_Sem_post_wait(benchmark::State &state)
static void Bm_function_pthread_cond_signal(benchmark::State &state)
{
pthread_cond_t cond;
pthread_cond_init(&cond, NULL);
pthread_cond_init(&cond, nullptr);
while (state.KeepRunning())
{
pthread_cond_signal(&cond);
......@@ -432,6 +462,14 @@ static void Bm_function_Sigaddset(benchmark::State &state)
for (auto _ : state) {
benchmark::DoNotOptimize(sigaddset(&set, SIGUSR1));
}
}
static void Bm_function_pthread_setcancelstate(benchmark::State &state)
{
while (state.KeepRunning()) {
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, nullptr);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr);
}
state.SetBytesProcessed(state.iterations());
}
......@@ -452,6 +490,9 @@ MUSL_BENCHMARK(Bm_function_pthread_mutex_timedlock_pi_errchk);
MUSL_BENCHMARK(Bm_function_pthread_mutex_timedlock_pi_rec);
MUSL_BENCHMARK(Bm_function_pthread_rwlock_tryrdlock);
MUSL_BENCHMARK(Bm_function_pthread_mutex_init);
MUSL_BENCHMARK(Bm_function_pthread_mutex_init_destroy);
MUSL_BENCHMARK(Bm_function_pthread_cond_init);
MUSL_BENCHMARK(Bm_function_pthread_cond_init_destroy);
MUSL_BENCHMARK(BM_pthread_rwlock_tryread);
MUSL_BENCHMARK(BM_pthread_rwlock_trywrite);
MUSL_BENCHMARK(Bm_function_tss_get);
......@@ -461,4 +502,4 @@ MUSL_BENCHMARK(Bm_function_pthread_cond_timedwait);
MUSL_BENCHMARK(Bm_function_pthread_cond_broadcast);
MUSL_BENCHMARK(Bm_function_Sem_timewait);
MUSL_BENCHMARK(Bm_function_Sem_post_wait);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_pthread_setcancelstate);
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <benchmark/benchmark.h>
#include "sys/random.h"
#include "util.h"
static void Bm_function_Getrandom(benchmark::State &state)
{
unsigned int i;
for (auto _state: state) {
benchmark::DoNotOptimize(getrandom(&i, sizeof(i), 0));
}
}
MUSL_BENCHMARK(Bm_function_Getrandom);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "sched.h"
#include "util.h"
......@@ -25,5 +24,4 @@ static void Bm_function_sched_yield(benchmark::State &state)
}
}
MUSL_BENCHMARK(Bm_function_sched_yield);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_sched_yield);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "sys/select.h"
#include "sys/time.h"
......@@ -38,5 +37,4 @@ static void Bm_function_Select(benchmark::State &state)
state.SetItemsProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_Select);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Select);
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <benchmark/benchmark.h>
#include "signal.h"
#include "util.h"
static void SignalHandler(int i) {}
static void Bm_function_Sigaction(benchmark::State &state)
{
struct sigaction sa;
sa.sa_flags = 0;
sa.sa_handler = SignalHandler;
for (auto _ : state) {
benchmark::DoNotOptimize(sigaction(SIGUSR1, &sa, nullptr));
}
}
MUSL_BENCHMARK(Bm_function_Sigaction);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "sys/stat.h"
#include "sys/types.h"
......@@ -75,7 +74,7 @@ static void Bm_function_Fstatat_absolutepath(benchmark::State &state)
static void Bm_function_Fstat64(benchmark::State &state)
{
struct stat buf;
int fd = open("/etc/passwd", O_RDONLY);
int fd = open("/etc/passwd", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("open fstat64");
exit(EXIT_FAILURE);
......@@ -103,5 +102,4 @@ MUSL_BENCHMARK(Bm_function_Fstatat_relativepath);
MUSL_BENCHMARK(Bm_function_Fstatat_symbollink);
MUSL_BENCHMARK(Bm_function_Fstatat_absolutepath);
MUSL_BENCHMARK(Bm_function_Fstat64);
MUSL_BENCHMARK(Bm_function_Mkdir);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Mkdir);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "stdio.h"
#include "stdlib.h"
......@@ -28,9 +27,9 @@ using namespace std;
#define SSCANF_SIZE 32
#define BUFFERSIZE 100
char buffer[BUFFERSIZE];
char g_buffer[BUFFERSIZE];
int MyPrintf1(FILE *stream, const char *format, ...)
int MyPrintfVf(FILE *stream, const char *format, ...)
{
va_list args;
int ret;
......@@ -40,22 +39,22 @@ int MyPrintf1(FILE *stream, const char *format, ...)
return (ret);
}
int MyPrintf2(const char *format, ...)
int MyPrintfVs(const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
ret = vsprintf(buffer, format, args);
ret = vsprintf(g_buffer, format, args);
va_end(args);
return (ret);
}
int MyPrintf3(const char *format, ...)
int MyPrintfVsn(const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
ret = vsnprintf(buffer, BUFFERSIZE, format, args);
ret = vsnprintf(g_buffer, BUFFERSIZE, format, args);
va_end(args);
return (ret);
}
......@@ -280,13 +279,14 @@ static void Bm_function_Fclose(benchmark::State &state)
}
}
// Used to convert a file descriptor to a file pointer
static void Bm_function_Fdopen(benchmark::State &state)
{
for (auto _ : state) {
int fp = open("/dev/zero", O_RDONLY);
int fp = open("/dev/zero", O_RDONLY, OPEN_MODE);
FILE *fd = fdopen(fp, "r");
if (fd == NULL) {
perror("fdopen test");
if (fd == nullptr) {
perror("fdopen");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(fd);
......@@ -304,7 +304,7 @@ static void Bm_function_Vfprintf_str(benchmark::State &state)
const char *arr1 = "hello";
const char *arr2 = "world";
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf1(fp, "Set parameter %s %s success", arr1, arr2));
benchmark::DoNotOptimize(MyPrintfVf(fp, "Set parameter %s %s success", arr1, arr2));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
......@@ -317,7 +317,7 @@ static void Bm_function_Vfprintf_int(benchmark::State &state)
int arr1 = 233;
int arr2 = 322;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf1(fp, "Set parameter %d %d success", arr1, arr2));
benchmark::DoNotOptimize(MyPrintfVf(fp, "Set parameter %d %d success", arr1, arr2));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
......@@ -330,7 +330,7 @@ static void Bm_function_Vfprintf_float(benchmark::State &state)
float i = 22.33f;
float j = 33.22f;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf1(fp, "Set parameter %f %f success", i, j));
benchmark::DoNotOptimize(MyPrintfVf(fp, "Set parameter %f %f success", i, j));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
......@@ -343,7 +343,7 @@ static void Bm_function_Vfprintf_longdouble(benchmark::State &state)
long double i = 2250996946.3365252546L;
long double j = 9583454321234.226342465121L;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf1(fp, "Set parameter %Lf %Lf success", i, j));
benchmark::DoNotOptimize(MyPrintfVf(fp, "Set parameter %Lf %Lf success", i, j));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
......@@ -356,7 +356,7 @@ static void Bm_function_Vfprintf_unsigned(benchmark::State &state)
unsigned int i = 4294967295U;
unsigned int j = 3456264567U;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf1(fp, "Set parameter %u %u success", i, j));
benchmark::DoNotOptimize(MyPrintfVf(fp, "Set parameter %u %u success", i, j));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
......@@ -369,7 +369,7 @@ static void Bm_function_Vfprintf_long(benchmark::State &state)
long i = 1234567890L;
long j = 954611731L;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf1(fp, "Set parameter %ld %ld success", i, j));
benchmark::DoNotOptimize(MyPrintfVf(fp, "Set parameter %ld %ld success", i, j));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
......@@ -382,7 +382,7 @@ static void Bm_function_Vfprintf_short(benchmark::State &state)
short i = 32767;
short j = -32768;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf1(fp, "Set parameter %hd %hd success", i, j));
benchmark::DoNotOptimize(MyPrintfVf(fp, "Set parameter %hd %hd success", i, j));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
......@@ -395,7 +395,7 @@ static void Bm_function_Vfprintf_char(benchmark::State &state)
char i = 'n';
char j = 'Z';
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf1(fp, "Set parameter %c %c success", i, j));
benchmark::DoNotOptimize(MyPrintfVf(fp, "Set parameter %c %c success", i, j));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
......@@ -407,7 +407,7 @@ static void Bm_function_Vsprintf_str(benchmark::State &state)
{
const char *arr = "signal_stack";
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf2("%s", arr));
benchmark::DoNotOptimize(MyPrintfVs("%s", arr));
}
state.SetBytesProcessed(state.iterations());
......@@ -418,7 +418,7 @@ static void Bm_function_Vsprintf_int(benchmark::State &state)
{
int i = 2233;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf2("%d", i));
benchmark::DoNotOptimize(MyPrintfVs("%d", i));
}
state.SetBytesProcessed(state.iterations());
......@@ -429,7 +429,7 @@ static void Bm_function_Vsprintf_float(benchmark::State &state)
{
float i = 22.33;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf2("%f", i));
benchmark::DoNotOptimize(MyPrintfVs("%f", i));
}
state.SetBytesProcessed(state.iterations());
......@@ -440,7 +440,7 @@ static void Bm_function_Vsprintf_longdouble(benchmark::State &state)
{
long double i = 9583454321234.226342465121L;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf2("%Lf", i));
benchmark::DoNotOptimize(MyPrintfVs("%Lf", i));
}
state.SetBytesProcessed(state.iterations());
......@@ -451,7 +451,7 @@ static void Bm_function_Vsprintf_unsigned(benchmark::State &state)
{
unsigned int u = 4294967295U;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf2("%u", u));
benchmark::DoNotOptimize(MyPrintfVs("%u", u));
}
state.SetBytesProcessed(state.iterations());
......@@ -462,7 +462,7 @@ static void Bm_function_Vsprintf_long(benchmark::State &state)
{
long l = 1234567890L;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf2("%ld", l));
benchmark::DoNotOptimize(MyPrintfVs("%ld", l));
}
state.SetBytesProcessed(state.iterations());
......@@ -473,7 +473,7 @@ static void Bm_function_Vsprintf_short(benchmark::State &state)
{
short s = 32767;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf2("%hd", s));
benchmark::DoNotOptimize(MyPrintfVs("%hd", s));
}
state.SetBytesProcessed(state.iterations());
......@@ -484,7 +484,7 @@ static void Bm_function_Vsprintf_char(benchmark::State &state)
{
char c = 'Z';
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf2("%c", c));
benchmark::DoNotOptimize(MyPrintfVs("%c", c));
}
state.SetBytesProcessed(state.iterations());
......@@ -496,7 +496,7 @@ static void Bm_function_Vsnprintf_str(benchmark::State &state)
{
const char *i = "holy";
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf3("Error loading shared library %s", i));
benchmark::DoNotOptimize(MyPrintfVsn("Error loading shared library %s", i));
}
state.SetBytesProcessed(state.iterations());
......@@ -507,7 +507,7 @@ static void Bm_function_Vsnprintf_int(benchmark::State &state)
{
int i = 2233;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf3("Error loading shared library %d", i));
benchmark::DoNotOptimize(MyPrintfVsn("Error loading shared library %d", i));
}
state.SetBytesProcessed(state.iterations());
......@@ -518,7 +518,7 @@ static void Bm_function_Vsnprintf_float(benchmark::State &state)
{
float i = 22.33;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf3("Error loading shared library %f", i));
benchmark::DoNotOptimize(MyPrintfVsn("Error loading shared library %f", i));
}
state.SetBytesProcessed(state.iterations());
......@@ -529,7 +529,7 @@ static void Bm_function_Vsnprintf_longdouble(benchmark::State &state)
{
long double i = 23423523.769563665L;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf3("Error loading shared library %Lf", i));
benchmark::DoNotOptimize(MyPrintfVsn("Error loading shared library %Lf", i));
}
state.SetBytesProcessed(state.iterations());
......@@ -540,7 +540,7 @@ static void Bm_function_Vsnprintf_unsigned(benchmark::State &state)
{
unsigned int u = 4294967295U;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf3("Error loading shared library %u", u));
benchmark::DoNotOptimize(MyPrintfVsn("Error loading shared library %u", u));
}
state.SetBytesProcessed(state.iterations());
......@@ -551,7 +551,7 @@ static void Bm_function_Vsnprintf_long(benchmark::State &state)
{
long l = 1234567890L;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf3("Error loading shared library %ld", l));
benchmark::DoNotOptimize(MyPrintfVsn("Error loading shared library %ld", l));
}
state.SetBytesProcessed(state.iterations());
......@@ -562,7 +562,7 @@ static void Bm_function_Vsnprintf_short(benchmark::State &state)
{
short s = 32767;
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf3("Error loading shared library %hd", s));
benchmark::DoNotOptimize(MyPrintfVsn("Error loading shared library %hd", s));
}
state.SetBytesProcessed(state.iterations());
......@@ -573,7 +573,7 @@ static void Bm_function_Vsnprintf_char(benchmark::State &state)
{
char s = 'R';
for (auto _ : state) {
benchmark::DoNotOptimize(MyPrintf3("Error loading shared library %c", s));
benchmark::DoNotOptimize(MyPrintfVsn("Error loading shared library %c", s));
}
state.SetBytesProcessed(state.iterations());
......@@ -584,7 +584,7 @@ static void Bm_function_Vsnprintf_char(benchmark::State &state)
static void Bm_function_Flock_Funlockfile(benchmark::State &state)
{
FILE *fp = fopen("/dev/zero", "r");
if (fp == NULL) {
if (fp == nullptr) {
perror("fopen funlockfile");
exit(EXIT_FAILURE);
}
......@@ -715,6 +715,16 @@ int MyScanf1(FILE *stream, const char *format, ...)
return (ret);
}
int MyVfscanf(const char* str, const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
ret = vsscanf(str, format, args);
va_end(args);
return (ret);
}
static void Bm_function_Vfscanf_str(benchmark::State &state)
{
FILE *stream = fopen("/data/data/vfscanf_str.txt", "w+");
......@@ -1207,13 +1217,26 @@ static void Bm_function_Fseek_fflush(benchmark::State &state)
static void Bm_function_Sscanf_vsscanf_int(benchmark::State &state)
{
int year, month, day;
const char* src = "20230515";
for (auto _ : state) {
va_list ap;
benchmark::DoNotOptimize(vsscanf("20230515", "%04d%02d%02d", ap));
benchmark::DoNotOptimize(MyVfscanf(src, "%04d%02d%02d", &year, &month, &day));
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_Feof(benchmark::State &state)
{
FILE *fp = fopen("/dev/zero", "r");
if (fp == nullptr) {
perror("feof");
exit(EXIT_FAILURE);
}
for (auto _ : state) {
benchmark::DoNotOptimize(feof(fp));
}
fclose(fp);
state.SetBytesProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_Fopen_read);
MUSL_BENCHMARK(Bm_function_Fopen_write);
......@@ -1290,4 +1313,4 @@ MUSL_BENCHMARK(Bm_function_Vfscanf_lluformat);
MUSL_BENCHMARK(Bm_function_Fileno_unlocked);
MUSL_BENCHMARK(Bm_function_Fseek_fflush);
MUSL_BENCHMARK(Bm_function_Sscanf_vsscanf_int);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Feof);
......@@ -16,31 +16,67 @@
#include <benchmark/benchmark.h>
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "util.h"
using namespace std;
#define BUFFER 100
#ifdef ONO_CURRENT_INTERFACE
int compare(const void *a, const void *b)
typedef struct {
char name[20];
int age;
} Nier;
int CompareInt(const void *a, const void *b)
{
int num1 = *(int *)a;
int num2 = *(int *)b;
if (num1 < num2) {
int c = *(int *)a;
int d = *(int *)b;
if (c < d) {
return -1;
} else if (num1 > num2) {
} else if (c > d) {
return 1;
} else {
return 0;
}
}
int CompareDouble(const void *a, const void *b)
{
double c = *(double *)a;
double d = *(double *)b;
if (c == d) {
return 0;
} else if (c > d) {
return 1;
} else {
return -1;
}
}
int CompareString(const void *a, const void *b)
{
const char* c = (char *)a;
const char* d = (char *)b;
return strcmp(c, d);
}
int CompareStruct(const void *a, const void *b)
{
return strcmp(((Nier *)a)->name, ((Nier *)b)->name);
}
void InitRandomArray(int *arr, size_t n)
{
for (size_t i = 0; i < n; i++) {
arr[i] = rand() % (2 * n);
}
}
// Convert the string pointed to by str to floating point
static void Bm_function_Strtod(benchmark::State &state)
{
const char *var[] = {"+2.86500000e+01", "3.1415", "29",
"-123.456", "1.23e5", "0x1.2p3",
"-inf", "123foo"};
const char *var[] = { "+2.86500000e+01", "3.1415", "29",
"-123.456", "1.23e5", "0x1.2p3",
"-inf", "123foo" };
const char *str = var[state.range(0)];
char *ptr;
for (auto _ : state) {
......@@ -51,8 +87,8 @@ static void Bm_function_Strtod(benchmark::State &state)
static void Bm_function_Strtof(benchmark::State &state)
{
const char *var[] = {"+2.86500000e+01", "3.1415", "29",
"-123.456", "1.23e5", "0x1.2p3",
"-inf", "123foo"};
"-123.456", "1.23e5", "0x1.2p3",
"-inf", "123foo"};
const char *str = var[state.range(0)];
char *ptr;
for (auto _ : state) {
......@@ -63,24 +99,80 @@ static void Bm_function_Strtof(benchmark::State &state)
static void Bm_function_Strtold(benchmark::State &state)
{
const char *var[] = {"+2.86500000e+01", "3.1415", "29",
"-123.456", "1.23e5", "0x1.2p3",
"-inf", "123foo"};
"-123.456", "1.23e5", "0x1.2p3",
"-inf", "123foo"};
const char *str = var[state.range(0)];
char *ptr;
for (auto _ : state) {
benchmark::DoNotOptimize(strtold(str, &ptr));
}
}
// Used to sort elements in an array
static void Bm_function_Qsort(benchmark::State &state)
// int type
static void Bm_function_Qsortint(benchmark::State &state)
{
int arr[] = {5, 3, 7, 1, 9};
int n = sizeof(arr) / sizeof(arr[0]);
for (auto _ : state) {
qsort(arr, n, sizeof(int), compare);
int arr[] = { 12, 89, 5, 3, 7, 1, 9, 2, 6 };
int n = sizeof(arr) / sizeof(arr[0]);
qsort(arr, n, sizeof(int), CompareInt);
}
}
#endif
// double type
static void Bm_function_Qsortdouble(benchmark::State &state)
{
for (auto _ : state) {
double arr[] = { 34.541, 5.32, 3.56, 7.897, 1.2324, 9.34543, 5.324, 98.543, 34.665 };
int n = sizeof(arr) / sizeof(arr[0]);
qsort(arr, n, sizeof(double), CompareDouble);
}
}
// string type
static void Bm_function_Qsortstring(benchmark::State &state)
{
for (auto _ : state) {
const char *arr[] = { "nihuangela", "xiaozhenhuniang", "our story",
"a language", "love", "qluhanagala",
"for elun", "sakuruwuma", "benchmark_musl" };
int n = sizeof(arr) / sizeof(arr[0]);
qsort(arr, n, sizeof(char *), CompareString);
}
}
// struct type
static void Bm_function_Qsortstruct(benchmark::State &state)
{
const int len = 9;
for (auto _ : state) {
Nier nidate[len] = { {"Meihuagao", 23}, {"Sdifenzhou", 68}, {"Amusterlang", 99},
{"elun", 56}, {"yishinuala", 120}, {"huajiahaochi", 22},
{"lunala", 66}, {"cocolou", 77}, {"xinnoqikala", 55} };
qsort(nidate, len, sizeof(Nier), CompareStruct);
}
}
static void Bm_function_Qsort_random(benchmark::State &state)
{
srand(1);
int n = state.range(0);
int *arr1 = new int[n];
int *arr2 = new int[n];
InitRandomArray(arr1, n);
for (auto _ : state)
{
state.PauseTiming();
memcpy(arr2, arr1, n);
state.ResumeTiming();
qsort(arr2, n, sizeof(int), CompareInt);
}
delete[] arr1;
delete[] arr2;
}
static void Bm_function_Getenv_TZ(benchmark::State &state)
{
......@@ -117,25 +209,27 @@ static void Bm_function_Getenv_LOGNAME(benchmark::State &state)
}
}
#ifdef ONO_CURRENT_INTERFACE
// Converts any relative path to an absolute path
static void Bm_function_Realpath(benchmark::State &state)
{
const char *realpathvariable[] = {"./log", "../dev", "log/hilog", "../dev/zero", "/dev"};
const int bufferLen = 4096;
const char *realpathvariable[] = { "./log", "../dev", "log/hilog", "../dev/zero", "/dev" };
const char *path = realpathvariable[state.range(0)];
char resolved_path[BUFFER];
char resolvedPath[bufferLen];
for (auto _ : state) {
benchmark::DoNotOptimize(realpath(path, resolved_path));
benchmark::DoNotOptimize(realpath(path, resolvedPath));
}
}
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtod, "BENCHMARK_VARIABLE");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtof, "BENCHMARK_VARIABLE");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtold, "BENCHMARK_VARIABLE");
MUSL_BENCHMARK(Bm_function_Qsort);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Realpath, "REALPATH_VARIABLE");
#endif
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtod, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtof, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strtold, "BENCHMARK_8");
MUSL_BENCHMARK(Bm_function_Qsortint);
MUSL_BENCHMARK(Bm_function_Qsortdouble);
MUSL_BENCHMARK(Bm_function_Qsortstring);
MUSL_BENCHMARK(Bm_function_Qsortstruct);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Qsort_random, "COMMON_ARGS");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Realpath, "BENCHMARK_5");
MUSL_BENCHMARK(Bm_function_Getenv_TZ);
MUSL_BENCHMARK(Bm_function_Getenv_LD_LIBRARY_PATH);
MUSL_BENCHMARK(Bm_function_Getenv_LD_PRELOAD);
......
......@@ -21,6 +21,39 @@
using namespace std;
static const std::vector<int> bufferSizes {
8,
16,
32,
64,
512,
1 * K,
8 * K,
16 * K,
32 * K,
64 * K,
128 * K,
};
static const std::vector<int> limitSizes{
1,
2,
3,
4,
5,
6,
7,
};
static void StringtestArgs(benchmark::internal::Benchmark* b)
{
for (auto l : bufferSizes) {
for (auto f : limitSizes) {
b->Args({l, f, 0});
}
}
}
// Searches for the first occurrence of the character x in the first n bytes of the selected string
static void Bm_function_Memchr(benchmark::State &state)
{
......@@ -38,21 +71,25 @@ static void Bm_function_Memchr(benchmark::State &state)
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
}
#ifdef ONO_CURRENT_INTERFACE
// Search for the last occurrence of the character 'm' in the string pointed to by the parameter test
// Finds the last occurrence of the specified character in a string and returns a pointer to that position
static void Bm_function_Strrchr(benchmark::State &state)
{
const char test[] = "com.ohos.mms";
const char ch = 'm';
const void *ret;
const char *strrchrtestsrc[] = { "com.ohos.launcher", "/system/lib/libfilemgmt_libhilog.z.so",
"/system/lib/libstatic_subscriber_extension.z.so",
"../../base/startup/init/services/param/base/param_base.c",
"/system/lib/libwallpapermanager.z.so",
"/system/lib/libwallpaperextension.z.so",
"/system/lib/module/libaccessibility.z.so",
"/../base/startup/init/services/param/base/param_trie.c" };
const char strrchrtesttag[] = { 'm', 'l', 's', 'o', 'z', 't', 'i', 'c', '\0' };
const char *test = strrchrtestsrc[state.range(0)];
const char ch = strrchrtesttag[state.range(0)];
for (auto _ : state) {
ret = strrchr(test, ch);
benchmark::DoNotOptimize(ret);
benchmark::DoNotOptimize(strrchr(test, ch));
}
state.SetBytesProcessed(state.iterations());
}
#endif
// The selected range calculates the length
static void Bm_function_Strnlen(benchmark::State &state)
......@@ -92,7 +129,25 @@ static void Bm_function_Stpncpy(benchmark::State &state)
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
}
#ifdef ONO_CURRENT_INTERFACE
static void Bm_function_Strncpy(benchmark::State &state)
{
const size_t nbytes = state.range(0);
const size_t limitsize = state.range(1);
const size_t srcAlignment = state.range(2);
const size_t dstAlignment = state.range(2);
vector<char> src;
vector<char> dst;
char *srcAligned = GetAlignedPtrFilled(&src, srcAlignment, nbytes, 'z');
char *dstAligned = GetAlignedPtr(&dst, dstAlignment, nbytes);
srcAligned[nbytes - 1] = '\0';
while (state.KeepRunning()) {
stpncpy(dstAligned, srcAligned, limitsize);
}
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
}
// Comparing whether two binary blocks of data are equal is functionally similar to MEMCMP
static void Bm_function_Bcmp(benchmark::State &state)
{
......@@ -116,10 +171,14 @@ static void Bm_function_Bcmp(benchmark::State &state)
// Find the first character in a given string that matches any character in another specified string
static void Bm_function_Strpbrk(benchmark::State &state)
{
const char test1[] = "open.harmony";
const char test2[] = "enh";
const char *strpbrktestsrc[] = { "method", "setTimeout", "open.harmony",
"libfilemgmt_libhilog", "libwallpaperextension",
"startup", "libwallpapermanager", "param_trie" };
const char *strpbrktesttag[] = { "th", "me", "enh", "lo", "en", "tu", "ag", "pa" };
const char *src = strpbrktestsrc[state.range(0)];
const char *tag = strpbrktesttag[state.range(0)];
for (auto _ : state) {
benchmark::DoNotOptimize(strpbrk(test1, test2));
benchmark::DoNotOptimize(strpbrk(src, tag));
}
}
......@@ -155,21 +214,19 @@ static void Bm_function_Wmemcpy(benchmark::State &state)
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
}
#endif
// Returns the index value of the first successful match
static void Bm_function_Strcspn(benchmark::State &state)
{
const char *var1[] = {"system/lib64", "system/lib64/chipset-pub-sdk", "vendor/lib64/chipsetsdk",
"system/lib64/ndk", "system/lib64/platformsdk", "system/lib64/priv-platformsdk",
"system/lib64/module/data", "tem/lib64/module/security"};
const char *var2[] = {"vendor/lib64", "/system/lib64/chipset-sdk", "/system/lib64/ndk",
"lib64/chipset-pub-sdk", "priv-platformsdk", "/system/lib64/priv-module",
"/system/lib64/module/multimedia", "/system/lib"};
const char *test1 = var1[state.range(0)];
const char *test2 = var2[state.range(0)];
const char *strcspnsrc[] = { "system/lib64", "system/lib64/chipset-pub-sdk", "vendor/lib64/chipsetsdk",
"system/lib64/ndk", "system/lib64/platformsdk", "system/lib64/priv-platformsdk",
"system/lib64/module/data", "tem/lib64/module/security" };
const char *strcspntag[] = { "vendor/lib64", "/system/lib64/chipset-sdk", "/system/lib64/ndk",
"lib64/chipset-pub-sdk", "priv-platformsdk", "/system/lib64/priv-module",
"/system/lib64/module/multimedia", "/system/lib" };
const char *src = strcspnsrc[state.range(0)];
const char *tag = strcspntag[state.range(0)];
for (auto _ : state) {
benchmark::DoNotOptimize(strcspn(test1, test2));
benchmark::DoNotOptimize(strcspn(src, tag));
}
}
......@@ -304,10 +361,12 @@ static void Bm_function_Strncat(benchmark::State &state)
}
state.SetBytesProcessed(uint64_t(state.iterations()) * uint64_t(nbytes));
}
MUSL_BENCHMARK_WITH_ARG(Bm_function_Memchr, "STRING_LIMIT");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strnlen, "STRING_LIMIT");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Stpncpy, "STRING_LIMIT");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strcspn, "BENCHMARK_VARIABLE");
BENCHMARK(Bm_function_Memchr)->Apply(StringtestArgs);
BENCHMARK(Bm_function_Strnlen)->Apply(StringtestArgs);
BENCHMARK(Bm_function_Stpncpy)->Apply(StringtestArgs);
BENCHMARK(Bm_function_Strncpy)->Apply(StringtestArgs);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strcspn, "BENCHMARK_8");
MUSL_BENCHMARK(Bm_function_Strchrnul_exist);
MUSL_BENCHMARK(Bm_function_Strchrnul_noexist);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strchrnul, "ALIGNED_ONEBUF");
......@@ -317,13 +376,10 @@ MUSL_BENCHMARK(Bm_function_Strcasecmp_equal);
MUSL_BENCHMARK(Bm_function_Strcasecmp_not_equal);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strcasecmp, "ALIGNED_TWOBUF");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strncasecmp, "ALIGNED_TWOBUF");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strdup, "ALIGNED_ONEBUF");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strncat, "ALIGNED_ONEBUF");
#ifdef ONO_CURRENT_INTERFACE
MUSL_BENCHMARK(Bm_function_Strrchr);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strrchr, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Bcmp, "ALIGNED_TWOBUF");
MUSL_BENCHMARK(Bm_function_Strpbrk);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strpbrk, "BENCHMARK_8");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Wmemset, "ALIGNED_ONEBUF");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Wmemcpy, "ALIGNED_TWOBUF");
#endif
\ No newline at end of file
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strdup, "ALIGNED_ONEBUF");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Strncat, "ALIGNED_ONEBUF");
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include <sys/syscall.h>
#include <string.h>
......@@ -32,6 +31,7 @@
#include "util.h"
using namespace std;
#define BYTES_WRITTEN 8
#define BUFSIZE 10
......@@ -58,18 +58,18 @@ static void Bm_function_Syscall_gettid(benchmark::State &state)
// Used to read the kernel time
static void Bm_function_Syscall_adjtimex(benchmark::State &state)
{
struct timex time_info;
struct timex timeInfo;
for (auto _ : state) {
benchmark::DoNotOptimize(syscall(SYS_adjtimex, &time_info));
benchmark::DoNotOptimize(syscall(SYS_adjtimex, &timeInfo));
}
}
// Writes the contents of the file of the user buffer to the corresponding location of the file on disk
static void Bm_function_Syscall_write(benchmark::State &state)
{
int fp = open("/dev/zero", O_RDWR);
int fp = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fp == -1) {
perror("open sys_write");
perror("open SYS_write");
exit(EXIT_FAILURE);
}
for (auto _ : state) {
......@@ -82,15 +82,15 @@ static void Bm_function_Syscall_write(benchmark::State &state)
static void Bm_function_Syscall_read(benchmark::State &state)
{
char buf[BUFSIZE];
int fd = open("/dev/zero", O_RDONLY);
int fd = open("/dev/zero", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("syscall read");
perror("open SYS_read");
exit(EXIT_FAILURE);
}
for (auto _ : state) {
ssize_t ret = syscall(SYS_read, fd, buf, BUFSIZE);
if (ret < 0) {
perror("syscall read");
perror("STS_read");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(ret);
......@@ -102,15 +102,15 @@ static void Bm_function_Syscall_read(benchmark::State &state)
static void Bm_function_Syscall_fcntl(benchmark::State &state)
{
long int ret;
int fd = open("/dev/zero", O_RDONLY);
int fd = open("/dev/zero", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("syscall_fcntl open");
perror("open SYS_fcntl");
exit(EXIT_FAILURE);
}
for (auto _ : state) {
ret = syscall(SYS_fcntl, fd, F_GETFL);
if (ret == -1) {
perror("syscall_fcntl fail");
perror("SYS_fcntl");
exit(EXIT_FAILURE);
}
benchmark::DoNotOptimize(ret);
......@@ -153,5 +153,4 @@ MUSL_BENCHMARK(Bm_function_Syscall_write);
MUSL_BENCHMARK(Bm_function_Syscall_read);
MUSL_BENCHMARK(Bm_function_Syscall_fcntl);
MUSL_BENCHMARK(Bm_function_Syscall_getrusage);
MUSL_BENCHMARK(Bm_function_Syscall_uname);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Syscall_uname);
\ No newline at end of file
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
#ifdef ONO_CURRENT_INTERFACE
#include <benchmark/benchmark.h>
#include "time.h"
#include "util.h"
......@@ -115,6 +114,18 @@ static void Bm_function_Clock_nanosleep_boottime(benchmark::State &state)
}
}
#define BUFFER_SIZE 32
static void Bm_function_Strftime(benchmark::State &state)
{
time_t rawTime = time(nullptr);
struct tm *localTime = localtime(&rawTime);
char buf[BUFFER_SIZE];
while (state.KeepRunning()) {
benchmark::DoNotOptimize(strftime(buf, BUFFER_SIZE, "%Y-%m-%d %H:%M:%S", localTime));
}
}
MUSL_BENCHMARK(Bm_function_Nanosleep_0ns);
MUSL_BENCHMARK(Bm_function_Nanosleep_10ns);
MUSL_BENCHMARK(Bm_function_Nanosleep_100ns);
......@@ -126,4 +137,4 @@ MUSL_BENCHMARK(Bm_function_Clock_nanosleep_monotonic);
MUSL_BENCHMARK(Bm_function_Clock_nanosleep_monotonic_raw);
MUSL_BENCHMARK(Bm_function_Clock_nanosleep_monotonic_coarse);
MUSL_BENCHMARK(Bm_function_Clock_nanosleep_boottime);
#endif
\ No newline at end of file
MUSL_BENCHMARK(Bm_function_Strftime);
......@@ -29,12 +29,13 @@
#include "util.h"
using namespace std;
#define BUFFER 1024
void ReadWriteTest(benchmark::State& state, bool isRead)
{
size_t chunkSize = state.range(0);
int fd = open("/dev/zero", O_RDWR);
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
if (fd == -1) {
perror("open ReadWriteTest");
exit(EXIT_FAILURE);
......@@ -63,13 +64,11 @@ void ReadWriteTest(benchmark::State& state, bool isRead)
close(fd);
}
#ifdef ONO_CURRENT_INTERFACE
template <typename Fn>
void PreadWriteTest(benchmark::State &state, Fn f, bool buffered)
{
size_t chunkSize = state.range(0);
int fp = open("/dev/zero", O_RDWR);
int fp = open("/dev/zero", O_RDWR, OPEN_MODE);
char *buf = new char[chunkSize];
off64_t offset = 0;
while (state.KeepRunning()) {
......@@ -108,7 +107,7 @@ static void Bm_function_Close(benchmark::State &state)
{
for (auto _ : state) {
state.PauseTiming();
int fd = open("/dev/zero", O_RDONLY);
int fd = open("/dev/zero", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("open Close");
exit(EXIT_FAILURE);
......@@ -180,14 +179,12 @@ static void Bm_function_Read(benchmark::State &state)
{
ReadWriteTest(state, true);
}
#endif
static void Bm_function_Write(benchmark::State &state)
{
ReadWriteTest(state, false);
}
#ifdef ONO_CURRENT_INTERFACE
static void Bm_function_Access_exist(benchmark::State &state)
{
const char *filename = "/data";
......@@ -224,21 +221,21 @@ static void Bm_function_Access_execute(benchmark::State &state)
state.SetBytesProcessed(state.iterations());
}
static const char *writevvariable1[] = {"Pretend inferiority and", "hello,",
"non sa module libtoken_sync_manager_service.z.so",
"The variable device_company was",
"but never appeared in a",
"The build continued as if",
"product_name=rk3568", "build/toolchain/ohos:"};
static const char *writevvariable2[] = {"encourage others arrogance!", "world!", ":token_sync_manager_service",
"set as a build argument", "declare_args() block in any buildfile",
"that argument was unspecified", "ohos_build_type=", "ohos_clang_arm64"};
static const char *g_writevvariable1[] = {"Pretend inferiority and", "hello,",
"non sa module libtoken_sync_manager_service.z.so",
"The variable device_company was",
"but never appeared in a",
"The build continued as if",
"product_name=rk3568", "build/toolchain/ohos:"};
static const char *g_writevvariable2[] = {"encourage others arrogance!", "world!", ":token_sync_manager_service",
"set as a build argument", "declare_args() block in any buildfile",
"that argument was unspecified", "ohos_build_type=", "ohos_clang_arm64"};
// Write the contents of multiple buffers to the file descriptor at once
static void Bm_function_Writev(benchmark::State &state)
{
int fd = open("/dev/zero", O_RDWR);
const char *str1 = writevvariable1[state.range(0)];
const char *str2 = writevvariable2[state.range(0)];
int fd = open("/dev/zero", O_RDWR, OPEN_MODE);
const char *str1 = g_writevvariable1[state.range(0)];
const char *str2 = g_writevvariable2[state.range(0)];
struct iovec iov[2];
ssize_t nwritten;
iov[0].iov_base = (void *)str1;
......@@ -262,6 +259,38 @@ static void Bm_function_Uname(benchmark::State &state)
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Lseek(benchmark::State &state)
{
int fd = open("/etc/passwd", O_RDONLY, OPEN_MODE);
if (fd == -1) {
perror("open lseek");
exit(EXIT_FAILURE);
}
for (auto _ : state) {
lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
}
close(fd);
state.SetItemsProcessed(state.iterations());
}
static void Bm_function_Dup(benchmark::State &state)
{
int fd = -1;
for (auto _ : state) {
fd = dup(STDOUT_FILENO);
if (fd == -1) {
perror("dup");
exit(EXIT_FAILURE);
}
state.PauseTiming();
close(fd);
state.ResumeTiming();
}
}
MUSL_BENCHMARK(Bm_function_Getpid);
MUSL_BENCHMARK(Bm_function_Geteuid);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Pwrite64, "COMMON_ARGS");
......@@ -276,8 +305,8 @@ MUSL_BENCHMARK(Bm_function_Access_exist);
MUSL_BENCHMARK(Bm_function_Access_read);
MUSL_BENCHMARK(Bm_function_Access_write);
MUSL_BENCHMARK(Bm_function_Access_execute);
MUSL_BENCHMARK_WITH_ARG(Bm_function_Writev, "BENCHMARK_VARIABLE");
MUSL_BENCHMARK_WITH_ARG(Bm_function_Writev, "BENCHMARK_8");
MUSL_BENCHMARK(Bm_function_Uname);
#endif
MUSL_BENCHMARK_WITH_ARG(Bm_function_Write, "COMMON_ARGS");
\ No newline at end of file
MUSL_BENCHMARK_WITH_ARG(Bm_function_Write, "BENCHMARK_8");
MUSL_BENCHMARK(Bm_function_Lseek);
MUSL_BENCHMARK(Bm_function_Dup);
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <benchmark/benchmark.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include "util.h"
#define PORT 1500 // port
#define BACKLOG 5
static void Bm_function_socket_server(benchmark::State &state)
{
struct sockaddr_in serverAddr;
memset(&serverAddr, 0, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_addr.s_addr = htonl(INADDR_ANY); // Any IP address of this host
serverAddr.sin_port = htons(PORT);
bzero(&(serverAddr.sin_zero), 8); // Set other attributes to 0
for (auto _ : state) {
int serverFd = socket(AF_INET, SOCK_STREAM, 0);
if (serverFd == -1) {
printf("socket failed:%d", errno);
break;
}
close(serverFd);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_socketpair_sendmsg_recvmsg(benchmark::State &state)
{
int ret;
int socks[2];
struct msghdr msg;
struct iovec iov[1];
char sendBuf[100] = "it is a test";
struct msghdr msgr;
struct iovec iovr[1];
char recvBuf[100];
for (auto _ : state) {
ret = socketpair(AF_LOCAL, SOCK_STREAM, 0, socks);
if (ret == -1) {
printf("socketpair err\n");
break;
}
bzero(&msg, sizeof(msg));
msg.msg_name = NULL;
msg.msg_namelen = 0;
iov[0].iov_base = sendBuf;
iov[0].iov_len = sizeof(sendBuf);
msg.msg_iov = iov;
msg.msg_iovlen = 1;
ret = sendmsg(socks[1], &msg, 0);
if (ret == -1) {
printf("sendmsg err\n");
close(socks[0]);
close(socks[1]);
break;
}
bzero(&msg, sizeof(msg));
msgr.msg_name = NULL;
msgr.msg_namelen = 0;
iovr[0].iov_base = &recvBuf;
iovr[0].iov_len = sizeof(recvBuf);
msgr.msg_iov = iovr;
msgr.msg_iovlen = 1;
ret = recvmsg(socks[0], &msgr, 0);
if (ret == -1) {
printf("recvmsg err\n");
}
close(socks[0]);
close(socks[1]);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_getsockopt(benchmark::State &state)
{
int optVal;
socklen_t optLen = sizeof(optVal);
for (auto _ : state) {
int sockFd = socket(AF_INET, SOCK_STREAM, 0);
if (getsockopt(sockFd, SOL_SOCKET, SO_SNDBUF, &optVal, &optLen) < 0) {
printf("fail to getsockopt");
}
close(sockFd);
}
state.SetBytesProcessed(state.iterations());
}
static void Bm_function_setsockopt(benchmark::State &state)
{
for (auto _ : state) {
int nRecvBuf = 32*1024; // Set to 32K
int sockFd = socket(AF_INET, SOCK_STREAM, 0);
if (setsockopt(sockFd, SOL_SOCKET, SO_RCVBUF, (const char*)&nRecvBuf, sizeof(int)) < 0) {
printf("fail to setsockopt");
}
close(sockFd);
}
state.SetBytesProcessed(state.iterations());
}
MUSL_BENCHMARK(Bm_function_socket_server);
MUSL_BENCHMARK(Bm_function_socketpair_sendmsg_recvmsg);
MUSL_BENCHMARK(Bm_function_getsockopt);
MUSL_BENCHMARK(Bm_function_setsockopt);
\ No newline at end of file
{
"InterfaceUsecases": [{
"name": "Bm_function_Fmodl",
"args": "BENCHMARK_8"
}, {
"name": "Bm_function_Vfscanf_str"
}, {
"name": "Bm_function_Vfscanf_int"
}, {
"name": "Bm_function_Vfscanf_double"
}, {
"name": "Bm_function_Vfscanf_float"
}, {
"name": "Bm_function_Vfscanf_char"
}, {
"name": "Bm_function_Vfscanf_iformat"
}, {
"name": "Bm_function_Vfscanf_oformat"
}, {
"name": "Bm_function_Vfscanf_uformat"
}, {
"name": "Bm_function_Vfscanf_xformat"
}, {
"name": "Bm_function_Vfscanf_Xformat"
}, {
"name": "Bm_function_Vfscanf_eformat"
}, {
"name": "Bm_function_Vfscanf_gformat"
}, {
"name": "Bm_function_Vfscanf_ldformat"
}, {
"name": "Bm_function_Vfscanf_luformat"
}, {
"name": "Bm_function_Vfscanf_lxformat"
}, {
"name": "Bm_function_Vfscanf_loformat"
}, {
"name": "Bm_function_Vfscanf_hdformat"
}, {
"name": "Bm_function_Vfscanf_huformat"
}, {
"name": "Bm_function_Vfscanf_hhuformat"
}, {
"name": "Bm_function_Vfscanf_hhxformat"
}, {
"name": "Bm_function_Vfscanf_llxformat"
}, {
"name": "Bm_function_Vfscanf_lldformat"
}, {
"name": "Bm_function_Vfscanf_lluformat"
}, {
"name": "Bm_function_Vfprintf_str"
}, {
"name": "Bm_function_Vfprintf_int"
}, {
"name": "Bm_function_Vfprintf_float"
}, {
"name": "Bm_function_Vfprintf_longdouble"
}, {
"name": "Bm_function_Vfprintf_unsigned"
}, {
"name": "Bm_function_Vfprintf_long"
}, {
"name": "Bm_function_Vfprintf_short"
}, {
"name": "Bm_function_Vfprintf_char"
}, {
"name": "Bm_function_Getenv_TZ"
}, {
"name": "Bm_function_Getenv_LD_LIBRARY_PATH"
}, {
"name": "Bm_function_Getenv_LD_PRELOAD"
}, {
"name": "Bm_function_Getenv_LC_ALL"
}, {
"name": "Bm_function_Getenv_LOGNAME"
}, {
"name": "Bm_function_Cos",
"args": "BENCHMARK_8"
}, {
"name": "Bm_function_Strcspn",
"args": "BENCHMARK_8"
}, {
"name": "Bm_function_Fopen_read"
}, {
"name": "Bm_function_Fopen_write"
}, {
"name": "Bm_function_Fopen_append"
}, {
"name": "Bm_function_Fopen_rplus"
}, {
"name": "Bm_function_Fopen_wplus"
}, {
"name": "Bm_function_Fopen_append_plus"
}, {
"name": "Bm_function_Fopen_rb"
}, {
"name": "Bm_function_Fopen_wb"
}, {
"name": "Bm_function_Fopen_ab"
}, {
"name": "Bm_function_Fopen_rb_plus"
}, {
"name": "Bm_function_Fopen_wb_plus"
}, {
"name": "Bm_function_Fopen_ab_plus"
}, {
"name": "Bm_function_Copysignl_Allpositive"
}, {
"name": "Bm_function_Copysignl_Allnegative"
}, {
"name": "Bm_function_Copysignl_Np"
}, {
"name": "Bm_function_Copysignl_Pn"
}, {
"name": "Bm_function_Syscall_getpid"
}, {
"name": "Bm_function_Syscall_gettid"
}, {
"name": "Bm_function_Syscall_adjtimex"
}, {
"name": "Bm_function_Syscall_write"
}, {
"name": "Bm_function_Syscall_read"
}, {
"name": "Bm_function_Syscall_fcntl"
}, {
"name": "Bm_function_Syscall_getrusage"
}, {
"name": "Bm_function_Syscall_uname"
}, {
"name": "Bm_function_Sscanf_int"
}, {
"name": "Bm_function_Sscanf_double"
}, {
"name": "Bm_function_Sscanf_str"
}, {
"name": "Bm_function_Sscanf_str1"
}, {
"name": "Bm_function_Sscanf_char"
}, {
"name": "Bm_function_Sscanf_char1"
}, {
"name": "Bm_function_realloc_twice"
}, {
"name": "Bm_function_realloc_half"
}, {
"name": "Bm_function_realloc_equal"
}, {
"name": "Bm_function_malloc_usable_size"
}, {
"name": "Bm_function_Strtod",
"args": "BENCHMARK_8"
}, {
"name": "Bm_function_Write",
"args": "BENCHMARK_8"
}, {
"name": "Bm_function_pthread_mutex_trylock_fast"
}, {
"name": "Bm_function_pthread_mutex_trylock_errchk"
}, {
"name": "Bm_function_pthread_mutex_trylock_rec"
}, {
"name": "Bm_function_pthread_mutex_trylock_pi_fast"
}, {
"name": "Bm_function_pthread_mutex_trylock_pi_errorcheck"
}, {
"name": "Bm_function_pthread_mutex_trylock_pi_rec"
}, {
"name": "Bm_function_Vsnprintf_str"
}, {
"name": "Bm_function_Vsnprintf_int"
}, {
"name": "Bm_function_Vsnprintf_float"
}, {
"name": "Bm_function_Vsnprintf_longdouble"
}, {
"name": "Bm_function_Vsnprintf_unsigned"
}, {
"name": "Bm_function_Vsnprintf_long"
}, {
"name": "Bm_function_Vsnprintf_short"
}, {
"name": "Bm_function_Vsnprintf_char"
}, {
"name": "Bm_function_pthread_mutex_timedlock_fast"
}, {
"name": "Bm_function_pthread_mutex_timedlock_errchk"
}, {
"name": "Bm_function_pthread_mutex_timedlock_rec"
}, {
"name": "Bm_function_pthread_mutex_timedlock_pi_fast"
}, {
"name": "Bm_function_pthread_mutex_timedlock_pi_errchk"
}, {
"name": "Bm_function_pthread_mutex_timedlock_pi_rec"
}, {
"name": "Bm_function_sched_yield"
}, {
"name": "Bm_function_Tolower_a"
}, {
"name": "Bm_function_Tolower_A"
}, {
"name": "Bm_function_Tolower_all_ascii"
}, {
"name": "Bm_function_fpclassifyl"
}, {
"name": "Bm_function_fpclassifyl1"
}, {
"name": "Bm_function_fpclassifyl2"
}, {
"name": "Bm_function_fpclassifyl3"
}, {
"name": "Bm_function_Strchrnul_exist"
}, {
"name": "Bm_function_Strchrnul_noexist"
}, {
"name": "Bm_function_Strchrnul",
"args": "ALIGNED_ONEBUF"
}, {
"name": "Bm_function_pthread_rwlock_tryrdlock"
}, {
"name": "Bm_function_Scalbnl1"
}, {
"name": "Bm_function_Scalbnl2"
}, {
"name": "Bm_function_Scalbnl3"
}, {
"name": "Bm_function_Scalbnl4"
}, {
"name": "Bm_function_Scalbn1"
}, {
"name": "Bm_function_Scalbn2"
}, {
"name": "Bm_function_Scalbn3"
}, {
"name": "Bm_function_Scalbn4"
}, {
"name": "Bm_function_Strcasecmp_capital_equal"
}, {
"name": "Bm_function_Strcasecmp_small_equal"
}, {
"name": "Bm_function_Strcasecmp_equal"
}, {
"name": "Bm_function_Strcasecmp_not_equal"
}, {
"name": "Bm_function_Strcasecmp",
"args": "ALIGNED_TWOBUF"
}, {
"name": "Bm_function_Qsortint"
}, {
"name": "Bm_function_Qsortdouble"
}, {
"name": "Bm_function_Qsortstring"
}, {
"name": "Bm_function_Qsortstruct"
}, {
"name": "Bm_function_Fdopen"
}, {
"name": "Bm_function_Ioctl_baudrate"
}, {
"name": "Bm_function_Select"
}, {
"name": "Bm_function_Fmod",
"args": "BENCHMARK_8"
}, {
"name": "Bm_function_Epoll_wait"
}, {
"name": "Bm_function_Fstatat_relativepath"
}, {
"name": "Bm_function_Fstatat_symbollink"
}, {
"name": "Bm_function_Fstatat_absolutepath"
}, {
"name": "Bm_function_pthread_cond_timedwait"
}, {
"name": "Bm_function_Open_rdonly"
}, {
"name": "Bm_function_Open_rdwr"
}, {
"name": "Bm_function_Open_creat_rdwr"
}, {
"name": "Bm_function_dlsym_libGLES_mali"
}]
}
......@@ -57,7 +57,53 @@ char* GetAlignedPtrFilled(std::vector<char>* buf, size_t alignment, size_t nbyte
wchar_t* GetAlignedPtrFilled(std::vector<wchar_t>* buf, size_t alignment, size_t nbytes, wchar_t fillByte)
{
wchar_t* bufAligned = GetAlignedPtr(buf, alignment, nbytes);
wmemset(bufAligned, fillByte, nbytes);
return bufAligned;
wchar_t* bufAligned = GetAlignedPtr(buf, alignment, nbytes);
wmemset(bufAligned, fillByte, nbytes);
return bufAligned;
}
char* ReadJsonFile(const char *fileName)
{
FILE *jsonFile = nullptr;
char *contentBuffer = nullptr;
long jsonFileLength = 0;
size_t readFileContent = 0;
jsonFile = fopen(fileName, "rb");
if (jsonFile == nullptr) {
return nullptr;
}
/* get the length */
if (fseek(jsonFile, 0, SEEK_END) != 0) {
fclose(jsonFile);
return nullptr;
}
jsonFileLength = ftell(jsonFile);
if (jsonFileLength < 0) {
fclose(jsonFile);
return nullptr;
}
if (fseek(jsonFile, 0, SEEK_SET) != 0) {
fclose(jsonFile);
return nullptr;
}
contentBuffer = (char*)malloc((size_t)jsonFileLength + sizeof(""));
if (contentBuffer == nullptr) {
fclose(jsonFile);
return nullptr;
}
/* read the json file into memory */
readFileContent = fread(contentBuffer, sizeof(char), (size_t)jsonFileLength, jsonFile);
if ((long)readFileContent != jsonFileLength) {
free(contentBuffer);
contentBuffer = nullptr;
fclose(jsonFile);
return contentBuffer;
}
contentBuffer[readFileContent] = '\0';
return contentBuffer;
}
\ No newline at end of file
......@@ -23,14 +23,23 @@
#include <utility>
#include <vector>
typedef void (*benchmark_func) (void);
#ifdef SYSTEM_32_BIT
#define LIBACE_PATH "system/lib/platformsdk/libace.z.so"
#define LIBGLES_PATH "/system/lib/libGLESv3.so"
#else
#define LIBACE_PATH "system/lib64/platformsdk/libace.z.so"
#define LIBGLES_PATH "/vendor/lib64/chipsetsdk/libGLESv3.so"
#define LIBGLES_MALI_PATH "/vendor/lib64/chipsetsdk/libGLES_mali.so"
#endif
typedef void (*BenchmarkFunc) (void);
extern std::mutex g_benchmarkLock;
extern std::map<std::string, std::pair<benchmark_func, std::string>> g_allBenchmarks;
extern std::map<std::string, std::pair<BenchmarkFunc, std::string>> g_allBenchmarks;
static int __attribute__((unused)) AddBenchmark(const std::string& funcName,
benchmark_func funcPtr, const std::string& arg = "")
BenchmarkFunc funcPtr, const std::string& arg = "")
{
g_benchmarkLock.lock();
g_allBenchmarks.emplace(std::string(funcName), std::make_pair(funcPtr, arg));
......@@ -40,18 +49,20 @@ static int __attribute__((unused)) AddBenchmark(const std::string& funcName,
#define MUSL_BENCHMARK(n) \
int _musl_benchmark_##n __attribute__((unused)) = AddBenchmark(std::string(#n), \
reinterpret_cast<benchmark_func>(n))
reinterpret_cast<BenchmarkFunc>(n))
#define MUSL_BENCHMARK_WITH_ARG(n, arg) \
int _musl_benchmark_##n __attribute__((unused)) = AddBenchmark(std::string(#n), \
reinterpret_cast<benchmark_func>(n), arg)
reinterpret_cast<BenchmarkFunc>(n), arg)
constexpr auto K = 1024;
constexpr auto M = 1024 * 1024;
constexpr auto G = 1024 * 1024 * 1024;
typedef struct bench_opts_t
{
int cpuNum = -1;
long iterNum = 0;
std::string jsonPath;
} BENCH_OPTS_T;
char* AlignUpMemoy(char* origPtr, size_t alignment);
......@@ -62,4 +73,13 @@ wchar_t* GetAlignedPtr(std::vector<wchar_t>* buf, size_t alignment, size_t nbyte
char* GetAlignedPtrFilled(std::vector<char>* buf, size_t alignment, size_t nbytes, char fillByte);
wchar_t* GetAlignedPtrFilled(std::vector<wchar_t>* buf, size_t alignment, size_t nbytes, wchar_t fillByte);
\ No newline at end of file
wchar_t* GetAlignedPtrFilled(std::vector<wchar_t>* buf, size_t alignment, size_t nbytes, wchar_t fillByte);
char* ReadJsonFile(const char *fileName);
enum JSONError {
JSON_SUCCESS = 0,
JOSN_ERROR_FILE_READ_FAILED,
JOSN_ERROR_JSON_FORMAT,
};
#define OPEN_MODE 0666
\ No newline at end of file
#!/bin/bash
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
HDC='/home/yinchuang/Task/dlopen/toolchains//hdc_std -s 10.121.251.143:8710 '
function lock_cpu() {
$HDC shell "mount -o rw,remount /vendor"
$HDC shell "rm -rf /vendor/etc/soc_perf/*"
$HDC shell "echo 1700000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq"
$HDC shell "echo 2343000 > /sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq"
$HDC shell "echo 3130000 > /sys/devices/system/cpu/cpu7/cpufreq/scaling_min_freq"
$HDC shell "echo 4-7 > /dev/cpuset/top-app/cpuset.cpus"
$HDC shell "echo 4-7 > /dev/cpuset/graphic/cpuset.cpus"
echo "current freqency: "
$HDC shell "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
$HDC shell "cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq"
$HDC shell "cat /sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq"
$HDC shell "cat /sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq"
$HDC shell "cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq"
$HDC shell "cat /sys/devices/system/cpu/cpu5/cpufreq/scaling_cur_freq"
$HDC shell "cat /sys/devices/system/cpu/cpu6/cpufreq/scaling_cur_freq"
$HDC shell "cat /sys/devices/system/cpu/cpu7/cpufreq/scaling_cur_freq"
$HDC shell power-shell setmode 602
}
function usage() {
echo "usage: $0 -r {the number of runs} -p {case path in phone}"
exit 1
}
REPS=50
CASE_PATH="/data/local/tmp/musl_dlopen"
while getopts "hp:r:" OPT
do
case "$OPT" in
p) CASE_PATH=$OPTARG;;
r) REPS=$OPTARG;;
h) usage;;
*)
echo "unknown options $opt"
usage
exit 1
;;
esac
done
echo REPS:$REPS
echo CASE_PATH:$CASE_PATH
time=$(date "+%Y%m%d-%H%M%S")
result_file="dlopen_cost_${time}.txt"
lock_cpu
for((i=1;i<=${REPS};i++));
do
$HDC shell $CASE_PATH | grep "dlopen" >> ${result_file}
done
echo "save results to dlopen_cost_${time}.txt"
err=$(cat ${result_file} | grep "dlopen error" | wc -l )
if [ $err -gt 0 ];
then
echo "dlopen failed!!!"
exit 1
fi
cat ${result_file} | awk 'BEGIN{ave=0; num=0} {ave+=$4;num++} END{print "dlopen cost(ave): " ave/num "(ms)", "num:" num}'
......@@ -18,12 +18,15 @@
"subsystem": "thirdparty",
"syscap": [],
"features": [],
"adapted_system_type": [],
"adapted_system_type": ["mini", "small", "standard"],
"rom": "",
"ram": "",
"deps": {
"components": [],
"third_party": []
"third_party": [
"thirdparty_benchmark",
"cjson"
]
},
"build": {
"sub_component": [],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册