[v10,6/7] riscv: Add ifunc helper method to hwprobe.h

Message ID 20231213211142.1543025-7-evan@rivosinc.com
State Superseded
Headers
Series RISC-V: ifunced memcpy using new kernel hwprobe interface |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed

Commit Message

Evan Green Dec. 13, 2023, 9:11 p.m. UTC
  Add a little helper method so it's easier to fetch a single value from
the hwprobe function when used within an ifunc selector.

Signed-off-by: Evan Green <evan@rivosinc.com>

---

Changes in v10:
 - Avoid implicit comparisons (Adhemerval)

Changes in v9:
 - Use __inline rather than inline so c89 compiles (build-many-glibcs)

Changes in v7:
 - Introduced static inline helper (Richard)

 sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 25 +++++++++++++++++++++
 1 file changed, 25 insertions(+)
  

Comments

Adhemerval Zanella Netto Jan. 8, 2024, 6:53 p.m. UTC | #1
On 13/12/23 18:11, Evan Green wrote:
> Add a little helper method so it's easier to fetch a single value from
> the hwprobe function when used within an ifunc selector.
> 
> Signed-off-by: Evan Green <evan@rivosinc.com>
> 
> ---
> 
> Changes in v10:
>  - Avoid implicit comparisons (Adhemerval)
> 
> Changes in v9:
>  - Use __inline rather than inline so c89 compiles (build-many-glibcs)
> 
> Changes in v7:
>  - Introduced static inline helper (Richard)
> 
>  sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 25 +++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
> index c4e3927667..d85d49cd73 100644
> --- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
> +++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
> @@ -22,6 +22,7 @@
>  
>  #include <features.h>
>  #include <stddef.h>
> +#include <errno.h>
>  #ifdef __has_include
>  # if __has_include (<asm/hwprobe.h>)
>  #  include <asm/hwprobe.h>
> @@ -81,4 +82,28 @@ typedef int (*__riscv_hwprobe_t) (struct riscv_hwprobe *__pairs, size_t __pair_c
>  
>  __END_DECLS
>  
> +/* Helper function usable from ifunc selectors that probes a single key. */
> +static __inline int
> +__riscv_hwprobe_one(__riscv_hwprobe_t hwprobe_func,

Space after function name.

> +                    signed long long int key,

I think you code guidelines says there is no need to add signed for
int.

> +                    unsigned long long int *value)

Any reason why you have declared it outside __BEGIN_DECLS/__END_DECLS? Afaiu,
if the function can no be inlined it would be subject to C++ mangling (not
sure if it would be an issue).  The x86.h defines within the extern 'C'. 

> +{
> +  struct riscv_hwprobe pair;
> +  int rc;
> +
> +  if (hwprobe_func == NULL)
> +    return ENOSYS;
> +
> +  pair.key = key;
> +  rc = hwprobe_func (&pair, 1, 0, NULL, 0);
> +  if (rc != 0)
> +    return rc;
> +
> +  if (pair.key < 0)
> +    return ENOENT;
> +
> +  *value = pair.value;
> +  return 0;
> +}
> +
>  #endif /* sys/hwprobe.h */
  

Patch

diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
index c4e3927667..d85d49cd73 100644
--- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
+++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
@@ -22,6 +22,7 @@ 
 
 #include <features.h>
 #include <stddef.h>
+#include <errno.h>
 #ifdef __has_include
 # if __has_include (<asm/hwprobe.h>)
 #  include <asm/hwprobe.h>
@@ -81,4 +82,28 @@  typedef int (*__riscv_hwprobe_t) (struct riscv_hwprobe *__pairs, size_t __pair_c
 
 __END_DECLS
 
+/* Helper function usable from ifunc selectors that probes a single key. */
+static __inline int
+__riscv_hwprobe_one(__riscv_hwprobe_t hwprobe_func,
+                    signed long long int key,
+                    unsigned long long int *value)
+{
+  struct riscv_hwprobe pair;
+  int rc;
+
+  if (hwprobe_func == NULL)
+    return ENOSYS;
+
+  pair.key = key;
+  rc = hwprobe_func (&pair, 1, 0, NULL, 0);
+  if (rc != 0)
+    return rc;
+
+  if (pair.key < 0)
+    return ENOENT;
+
+  *value = pair.value;
+  return 0;
+}
+
 #endif /* sys/hwprobe.h */