[DTrace-devel] [PATCH v2 3/5] Add -xcpu support to profile provider

Eugene Loh eugene.loh at oracle.com
Thu Jan 11 05:19:20 UTC 2024


Note that patches 3/5 and 4/5 have already been reviewed, but I tweaked 
the associated tests to reduce the chances of a false pass.

On 1/11/24 00:13, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
>
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
>   libdtrace/dt_prov_profile.c              | 13 ++++++++++---
>   test/unittest/options/tst.cpu-profile.sh | 22 ++++++++++++++++++++++
>   test/unittest/options/tst.cpu-tick.sh    | 22 ++++++++++++++++++++++
>   3 files changed, 54 insertions(+), 3 deletions(-)
>   create mode 100755 test/unittest/options/tst.cpu-profile.sh
>   create mode 100755 test/unittest/options/tst.cpu-tick.sh
>
> diff --git a/libdtrace/dt_prov_profile.c b/libdtrace/dt_prov_profile.c
> index 16345d32..0ce541f0 100644
> --- a/libdtrace/dt_prov_profile.c
> +++ b/libdtrace/dt_prov_profile.c
> @@ -33,7 +33,9 @@ static const dtrace_pattr_t	pattr = {
>   { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
>   };
>   
> -#define FDS_CNT(kind)	((kind) == KIND_TICK ? 1 : dtp->dt_conf.num_online_cpus)
> +#define FDS_CNT(kind)	((kind) == KIND_TICK || \
> +			 dtp->dt_options[DTRACEOPT_CPU] != DTRACEOPT_UNSET ? \
> +			 1 : dtp->dt_conf.num_online_cpus)
>   typedef struct profile_probe {
>   	int		kind;
>   	uint64_t	period;
> @@ -274,8 +276,13 @@ static int attach(dtrace_hdl_t *dtp, const dt_probe_t *prp, int bpf_fd)
>   	for (i = 0; i < cnt; i++) {
>   		int j = i, fd;
>   
> -		/* if there is only one fd, place it at random */
> -		if (cnt == 1)
> +		/*
> +		 * If -xcpu is set, use that CPU.
> +		 * If there is only one fd, place it at random.
> +		 */
> +		if (dtp->dt_options[DTRACEOPT_CPU] != DTRACEOPT_UNSET)
> +			j = dtp->dt_options[DTRACEOPT_CPU];
> +		else if (cnt == 1)
>   			j = rand() % dtp->dt_conf.num_online_cpus;
>   
>   		fd = dt_perf_event_open(&attr, -1, dtp->dt_conf.cpus[j].cpu_id,
> diff --git a/test/unittest/options/tst.cpu-profile.sh b/test/unittest/options/tst.cpu-profile.sh
> new file mode 100755
> index 00000000..6c43a2f5
> --- /dev/null
> +++ b/test/unittest/options/tst.cpu-profile.sh
> @@ -0,0 +1,22 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
> +# Licensed under the Universal Permissive License v 1.0 as shown at
> +# http://oss.oracle.com/licenses/upl.
> +#
> +
> +dtrace=$1
> +
> +nerr=0
> +for cpu0 in `awk '/^processor[ 	]*: [0-9]*$/ {print $3}' /proc/cpuinfo`; do
> +	cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'profile-100ms { trace(cpu); exit(0); }'`
> +	echo expected cpu $cpu0 got cpu $cpu
> +	if [ `echo $cpu | wc -w` -ne 1 ]; then
> +		nerr=$(($nerr + 1))
> +	elif [ $(($cpu + 0)) != $cpu0 ]; then
> +		nerr=$(($nerr + 1))
> +	fi
> +done
> +
> +exit $nerr
> diff --git a/test/unittest/options/tst.cpu-tick.sh b/test/unittest/options/tst.cpu-tick.sh
> new file mode 100755
> index 00000000..9463f3ef
> --- /dev/null
> +++ b/test/unittest/options/tst.cpu-tick.sh
> @@ -0,0 +1,22 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
> +# Licensed under the Universal Permissive License v 1.0 as shown at
> +# http://oss.oracle.com/licenses/upl.
> +#
> +
> +dtrace=$1
> +
> +nerr=0
> +for cpu0 in `awk '/^processor[ 	]*: [0-9]*$/ {print $3}' /proc/cpuinfo`; do
> +	cpu=`$dtrace $dt_flags -xcpu=$cpu0 -qn 'tick-100ms { trace(cpu); exit(0); }'`
> +	echo expected cpu $cpu0 got cpu $cpu
> +        if [ `echo $cpu | wc -w` -ne 1 ]; then
> +		nerr=$(($nerr + 1))
> +        elif [ $(($cpu + 0)) != $cpu0 ]; then
> +		nerr=$(($nerr + 1))
> +	fi
> +done
> +
> +exit $nerr



More information about the DTrace-devel mailing list