RE: [PATCH 2/2] selftests/bpf: Add test for bpf_rdtsc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tero Kristo wrote:
> Add selftest for bpf_rdtsc() which reads the TSC (Time Stamp Counter) on
> x86_64 architectures. The test reads the TSC from both userspace and the
> BPF program, and verifies the TSC values are in incremental order as
> expected. The test is automatically skipped on architectures that do not
> support the feature.
> 
> Signed-off-by: Tero Kristo <tero.kristo@xxxxxxxxxxxxxxx>
> ---
>  .../selftests/bpf/prog_tests/test_rdtsc.c     | 67 +++++++++++++++++++
>  .../testing/selftests/bpf/progs/test_rdtsc.c  | 21 ++++++
>  2 files changed, 88 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/test_rdtsc.c
>  create mode 100644 tools/testing/selftests/bpf/progs/test_rdtsc.c
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_rdtsc.c b/tools/testing/selftests/bpf/prog_tests/test_rdtsc.c
> new file mode 100644
> index 000000000000..2b26deb5b35a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/test_rdtsc.c
> @@ -0,0 +1,67 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright(c) 2023 Intel Corporation */
> +
> +#include "test_progs.h"
> +#include "test_rdtsc.skel.h"
> +
> +#ifdef __x86_64__
> +
> +static inline u64 _rdtsc(void)
> +{
> +	u32 low, high;
> +
> +	__asm__ __volatile__("rdtscp" : "=a" (low), "=d" (high));

I think its ok but note this could fail if user doesn't have
access to rdtscp and iirc that can be restricted?

> +	return ((u64)high << 32) | low;
> +}




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux