Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
ea5551e7
Commit
ea5551e7
authored
May 02, 2018
by
Nan Xiao
Committed by
Dominic Hamon
May 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Porting into OpenBSD (#582)
parent
62a9d756
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
internal_macros.h
src/internal_macros.h
+2
-0
sysinfo.cc
src/sysinfo.cc
+28
-2
No files found.
src/internal_macros.h
View file @
ea5551e7
...
@@ -51,6 +51,8 @@
...
@@ -51,6 +51,8 @@
#define BENCHMARK_OS_FREEBSD 1
#define BENCHMARK_OS_FREEBSD 1
#elif defined(__NetBSD__)
#elif defined(__NetBSD__)
#define BENCHMARK_OS_NETBSD 1
#define BENCHMARK_OS_NETBSD 1
#elif defined(__OpenBSD__)
#define BENCHMARK_OS_OPENBSD 1
#elif defined(__linux__)
#elif defined(__linux__)
#define BENCHMARK_OS_LINUX 1
#define BENCHMARK_OS_LINUX 1
#elif defined(__native_client__)
#elif defined(__native_client__)
...
...
src/sysinfo.cc
View file @
ea5551e7
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
#include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
#include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
#include <unistd.h>
#include <unistd.h>
#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX || \
#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX || \
defined BENCHMARK_OS_NETBSD
defined BENCHMARK_OS_NETBSD
|| defined BENCHMARK_OS_OPENBSD
#define BENCHMARK_HAS_SYSCTL
#define BENCHMARK_HAS_SYSCTL
#include <sys/sysctl.h>
#include <sys/sysctl.h>
#endif
#endif
...
@@ -136,6 +136,26 @@ struct ValueUnion {
...
@@ -136,6 +136,26 @@ struct ValueUnion {
};
};
ValueUnion
GetSysctlImp
(
std
::
string
const
&
Name
)
{
ValueUnion
GetSysctlImp
(
std
::
string
const
&
Name
)
{
#if defined BENCHMARK_OS_OPENBSD
int
mib
[
2
];
mib
[
0
]
=
CTL_HW
;
if
((
Name
==
"hw.ncpu"
)
||
(
Name
==
"hw.cpuspeed"
)){
ValueUnion
buff
(
sizeof
(
int
));
if
(
Name
==
"hw.ncpu"
)
{
mib
[
1
]
=
HW_NCPU
;
}
else
{
mib
[
1
]
=
HW_CPUSPEED
;
}
if
(
sysctl
(
mib
,
2
,
buff
.
data
(),
&
buff
.
Size
,
nullptr
,
0
)
==
-
1
)
{
return
ValueUnion
();
}
return
buff
;
}
return
ValueUnion
();
#else
size_t
CurBuffSize
=
0
;
size_t
CurBuffSize
=
0
;
if
(
sysctlbyname
(
Name
.
c_str
(),
nullptr
,
&
CurBuffSize
,
nullptr
,
0
)
==
-
1
)
if
(
sysctlbyname
(
Name
.
c_str
(),
nullptr
,
&
CurBuffSize
,
nullptr
,
0
)
==
-
1
)
return
ValueUnion
();
return
ValueUnion
();
...
@@ -144,6 +164,7 @@ ValueUnion GetSysctlImp(std::string const& Name) {
...
@@ -144,6 +164,7 @@ ValueUnion GetSysctlImp(std::string const& Name) {
if
(
sysctlbyname
(
Name
.
c_str
(),
buff
.
data
(),
&
buff
.
Size
,
nullptr
,
0
)
==
0
)
if
(
sysctlbyname
(
Name
.
c_str
(),
buff
.
data
(),
&
buff
.
Size
,
nullptr
,
0
)
==
0
)
return
buff
;
return
buff
;
return
ValueUnion
();
return
ValueUnion
();
#endif
}
}
BENCHMARK_MAYBE_UNUSED
BENCHMARK_MAYBE_UNUSED
...
@@ -488,12 +509,17 @@ double GetCPUCyclesPerSecond() {
...
@@ -488,12 +509,17 @@ double GetCPUCyclesPerSecond() {
constexpr
auto
*
FreqStr
=
constexpr
auto
*
FreqStr
=
#if defined(BENCHMARK_OS_FREEBSD) || defined(BENCHMARK_OS_NETBSD)
#if defined(BENCHMARK_OS_FREEBSD) || defined(BENCHMARK_OS_NETBSD)
"machdep.tsc_freq"
;
"machdep.tsc_freq"
;
#elif defined BENCHMARK_OS_OPENBSD
"hw.cpuspeed"
;
#else
#else
"hw.cpufrequency"
;
"hw.cpufrequency"
;
#endif
#endif
unsigned
long
long
hz
=
0
;
unsigned
long
long
hz
=
0
;
#if defined BENCHMARK_OS_OPENBSD
if
(
GetSysctl
(
FreqStr
,
&
hz
))
return
hz
*
1000000
;
#else
if
(
GetSysctl
(
FreqStr
,
&
hz
))
return
hz
;
if
(
GetSysctl
(
FreqStr
,
&
hz
))
return
hz
;
#endif
fprintf
(
stderr
,
"Unable to determine clock rate from sysctl: %s: %s
\n
"
,
fprintf
(
stderr
,
"Unable to determine clock rate from sysctl: %s: %s
\n
"
,
FreqStr
,
strerror
(
errno
));
FreqStr
,
strerror
(
errno
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment