Merge "riscv64: add <sys/hwprobe.h>." into main am: c4d3867b6c
am: 98f649e224
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2679530 Change-Id: I96098f18a8f61cacd803311c2d233faac8bf58c1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
63043c04ad
7 changed files with 125 additions and 3 deletions
|
@ -62,7 +62,8 @@ New libc functions in V (API level 35):
|
||||||
functions for avoiding $TZ if you need to use multiple timezones in
|
functions for avoiding $TZ if you need to use multiple timezones in
|
||||||
multi-threaded C).
|
multi-threaded C).
|
||||||
* `mbsrtowcs_l` and `wcsrtombs_l` aliases for `mbsrtowcs` and `wcsrtombs`.
|
* `mbsrtowcs_l` and `wcsrtombs_l` aliases for `mbsrtowcs` and `wcsrtombs`.
|
||||||
* New system call wrapper: `__riscv_flush_icache` (`<sys/cachectl.h>`).
|
* New system call wrappers: `__riscv_flush_icache` (`<sys/cachectl.h>`),
|
||||||
|
`__riscv_hwprobe` (`<sys/hwprobe.h>`).
|
||||||
|
|
||||||
New libc functions in U (API level 34):
|
New libc functions in U (API level 34):
|
||||||
* `close_range` and `copy_file_range` (Linux-specific GNU extensions).
|
* `close_range` and `copy_file_range` (Linux-specific GNU extensions).
|
||||||
|
|
|
@ -74,5 +74,3 @@ int recvmmsg_time64(int, mmsghdr*, unsigned int, int, const timespec64*) lp32
|
||||||
int rt_sigtimedwait_time64(const sigset64_t*, siginfo_t*, const timespec64*, size_t) lp32
|
int rt_sigtimedwait_time64(const sigset64_t*, siginfo_t*, const timespec64*, size_t) lp32
|
||||||
int futex_time64(int*, int, int, const timespec64*, int*, int) lp32
|
int futex_time64(int*, int, int, const timespec64*, int*, int) lp32
|
||||||
int sched_rr_get_interval_time64(pid_t, timespec64*) lp32
|
int sched_rr_get_interval_time64(pid_t, timespec64*) lp32
|
||||||
# Since Linux 6.4, not in glibc (https://www.openwall.com/lists/libc-coord/2023/07/13/1).
|
|
||||||
int riscv_hwprobe(riscv_hwprobe*, size_t, size_t, unsigned long*, unsigned) riscv64
|
|
||||||
|
|
|
@ -357,6 +357,7 @@ int cacheflush:__ARM_NR_cacheflush(long start, long end, long flags) arm
|
||||||
|
|
||||||
# riscv64-specific
|
# riscv64-specific
|
||||||
int __riscv_flush_icache:riscv_flush_icache(void*, void*, unsigned long) riscv64
|
int __riscv_flush_icache:riscv_flush_icache(void*, void*, unsigned long) riscv64
|
||||||
|
int __riscv_hwprobe:riscv_hwprobe(riscv_hwprobe*, size_t, size_t, unsigned long*, unsigned) riscv64
|
||||||
|
|
||||||
# x86-specific
|
# x86-specific
|
||||||
int __set_thread_area:set_thread_area(void*) x86
|
int __set_thread_area:set_thread_area(void*) x86
|
||||||
|
|
58
libc/include/sys/hwprobe.h
Normal file
58
libc/include/sys/hwprobe.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 The Android Open Source Project
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if __riscv
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file sys/hwprobe.h
|
||||||
|
* @brief RISC-V hardware probing.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/* Pull in struct riscv_hwprobe and corresponding constants. */
|
||||||
|
#include <asm/hwprobe.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [__riscv_hwprobe(2)](https://docs.kernel.org/riscv/hwprobe.html)
|
||||||
|
* queries hardware characteristics.
|
||||||
|
*
|
||||||
|
* A `__cpu_count` of 0 and null `__cpus` means "all online cpus".
|
||||||
|
*
|
||||||
|
* Returns 0 on success and returns -1 and sets `errno` on failure.
|
||||||
|
*/
|
||||||
|
int __riscv_hwprobe(struct riscv_hwprobe* _Nonnull __pairs, size_t __pair_count, size_t __cpu_count, unsigned long* _Nullable __cpus, unsigned __flags);
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
|
@ -1590,6 +1590,7 @@ LIBC_V { # introduced=VanillaIceCream
|
||||||
mbsrtowcs_l;
|
mbsrtowcs_l;
|
||||||
mktime_z;
|
mktime_z;
|
||||||
__riscv_flush_icache; # riscv64
|
__riscv_flush_icache; # riscv64
|
||||||
|
__riscv_hwprobe; # riscv64
|
||||||
timespec_getres;
|
timespec_getres;
|
||||||
tzalloc;
|
tzalloc;
|
||||||
tzfree;
|
tzfree;
|
||||||
|
|
|
@ -472,6 +472,7 @@ cc_test_library {
|
||||||
"sys_auxv_test.cpp",
|
"sys_auxv_test.cpp",
|
||||||
"sys_cachectl_test.cpp",
|
"sys_cachectl_test.cpp",
|
||||||
"sys_epoll_test.cpp",
|
"sys_epoll_test.cpp",
|
||||||
|
"sys_hwprobe_test.cpp",
|
||||||
"sys_mman_test.cpp",
|
"sys_mman_test.cpp",
|
||||||
"sys_msg_test.cpp",
|
"sys_msg_test.cpp",
|
||||||
"sys_param_test.cpp",
|
"sys_param_test.cpp",
|
||||||
|
|
62
tests/sys_hwprobe_test.cpp
Normal file
62
tests/sys_hwprobe_test.cpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 The Android Open Source Project
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#if __has_include(<sys/hwprobe.h>)
|
||||||
|
#include <sys/hwprobe.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TEST(sys_hwprobe, __riscv_hwprobe) {
|
||||||
|
#if defined(__riscv) && __has_include(<sys/cachectl.h>)
|
||||||
|
riscv_hwprobe probes[] = {{.key = RISCV_HWPROBE_KEY_IMA_EXT_0},
|
||||||
|
{.key = RISCV_HWPROBE_KEY_CPUPERF_0}};
|
||||||
|
ASSERT_EQ(0, __riscv_hwprobe(probes, 2, 0, nullptr, 0));
|
||||||
|
EXPECT_EQ(RISCV_HWPROBE_KEY_IMA_EXT_0, probes[0].key);
|
||||||
|
EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_IMA_FD) != 0);
|
||||||
|
EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_IMA_C) != 0);
|
||||||
|
// TODO: remove #define when our uapi headers are new enough.
|
||||||
|
#define RISCV_HWPROBE_IMA_V (1 << 2)
|
||||||
|
EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_IMA_V) != 0);
|
||||||
|
// TODO: remove #ifs when our kernel is new enough.
|
||||||
|
#if defined(RISCV_HWPROBE_EXT_ZBA)
|
||||||
|
EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_EXT_ZBA) != 0);
|
||||||
|
#endif
|
||||||
|
#if defined(RISCV_HWPROBE_EXT_ZBB)
|
||||||
|
EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_EXT_ZBB) != 0);
|
||||||
|
#endif
|
||||||
|
#if defined(RISCV_HWPROBE_EXT_ZBS)
|
||||||
|
EXPECT_TRUE((probes[0].value & RISCV_HWPROBE_EXT_ZBS) != 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
EXPECT_EQ(RISCV_HWPROBE_KEY_CPUPERF_0, probes[1].key);
|
||||||
|
EXPECT_TRUE((probes[1].value & RISCV_HWPROBE_MISALIGNED_MASK) == RISCV_HWPROBE_MISALIGNED_FAST);
|
||||||
|
#else
|
||||||
|
GTEST_SKIP() << "__riscv_hwprobe requires riscv64";
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in a new issue