diff mbox series

[16/35] perf dlfilter: Add machine_pid and vcpu

Message ID 20220711093218.10967-17-adrian.hunter@intel.com (mailing list archive)
State New, archived
Headers show
Series perf intel-pt: Add support for tracing virtual machine user space on the host | expand

Commit Message

Adrian Hunter July 11, 2022, 9:31 a.m. UTC
Add machine_pid and vcpu to struct perf_dlfilter_sample. The 'size' can be
used to determine if the values are present, however machine_pid is zero if
unused in any case. vcpu should be ignored if machine_pid is zero.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/perf-dlfilter.txt | 22 ++++++++++++++++++++++
 tools/perf/include/perf/perf_dlfilter.h    |  8 ++++++++
 tools/perf/util/dlfilter.c                 |  2 ++
 3 files changed, 32 insertions(+)

Comments

Ian Rogers July 20, 2022, 12:42 a.m. UTC | #1
On Mon, Jul 11, 2022 at 2:33 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>
> Add machine_pid and vcpu to struct perf_dlfilter_sample. The 'size' can be
> used to determine if the values are present, however machine_pid is zero if
> unused in any case. vcpu should be ignored if machine_pid is zero.
>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/Documentation/perf-dlfilter.txt | 22 ++++++++++++++++++++++
>  tools/perf/include/perf/perf_dlfilter.h    |  8 ++++++++
>  tools/perf/util/dlfilter.c                 |  2 ++
>  3 files changed, 32 insertions(+)
>
> diff --git a/tools/perf/Documentation/perf-dlfilter.txt b/tools/perf/Documentation/perf-dlfilter.txt
> index 594f5a5a0c9e..fb22e3b31dc5 100644
> --- a/tools/perf/Documentation/perf-dlfilter.txt
> +++ b/tools/perf/Documentation/perf-dlfilter.txt
> @@ -107,9 +107,31 @@ struct perf_dlfilter_sample {
>         __u64 raw_callchain_nr; /* Number of raw_callchain entries */
>         const __u64 *raw_callchain; /* Refer <linux/perf_event.h> */
>         const char *event;
> +       __s32 machine_pid;
> +       __s32 vcpu;
>  };
>  ----
>
> +Note: 'machine_pid' and 'vcpu' are not original members, but were added together later.
> +'size' can be used to determine their presence at run time.
> +PERF_DLFILTER_HAS_MACHINE_PID will be defined if they are present at compile time.
> +For example:
> +[source,c]
> +----
> +#include <perf/perf_dlfilter.h>
> +#include <stddef.h>
> +#include <stdbool.h>
> +
> +static inline bool have_machine_pid(const struct perf_dlfilter_sample *sample)
> +{
> +#ifdef PERF_DLFILTER_HAS_MACHINE_PID
> +       return sample->size >= offsetof(struct perf_dlfilter_sample, vcpu) + sizeof(sample->vcpu);
> +#else
> +       return false;
> +#endif
> +}
> +----
> +
>  The perf_dlfilter_fns structure
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> diff --git a/tools/perf/include/perf/perf_dlfilter.h b/tools/perf/include/perf/perf_dlfilter.h
> index 3eef03d661b4..a26e2f129f83 100644
> --- a/tools/perf/include/perf/perf_dlfilter.h
> +++ b/tools/perf/include/perf/perf_dlfilter.h
> @@ -9,6 +9,12 @@
>  #include <linux/perf_event.h>
>  #include <linux/types.h>
>
> +/*
> + * The following macro can be used to determine if this header defines
> + * perf_dlfilter_sample machine_pid and vcpu.
> + */
> +#define PERF_DLFILTER_HAS_MACHINE_PID
> +
>  /* Definitions for perf_dlfilter_sample flags */
>  enum {
>         PERF_DLFILTER_FLAG_BRANCH       = 1ULL << 0,
> @@ -62,6 +68,8 @@ struct perf_dlfilter_sample {
>         __u64 raw_callchain_nr; /* Number of raw_callchain entries */
>         const __u64 *raw_callchain; /* Refer <linux/perf_event.h> */
>         const char *event;
> +       __s32 machine_pid;
> +       __s32 vcpu;
>  };
>
>  /*
> diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c
> index db964d5a52af..54e4d4495e00 100644
> --- a/tools/perf/util/dlfilter.c
> +++ b/tools/perf/util/dlfilter.c
> @@ -495,6 +495,8 @@ int dlfilter__do_filter_event(struct dlfilter *d,
>         ASSIGN(misc);
>         ASSIGN(raw_size);
>         ASSIGN(raw_data);
> +       ASSIGN(machine_pid);
> +       ASSIGN(vcpu);
>
>         if (sample->branch_stack) {
>                 d_sample.brstack_nr = sample->branch_stack->nr;
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/tools/perf/Documentation/perf-dlfilter.txt b/tools/perf/Documentation/perf-dlfilter.txt
index 594f5a5a0c9e..fb22e3b31dc5 100644
--- a/tools/perf/Documentation/perf-dlfilter.txt
+++ b/tools/perf/Documentation/perf-dlfilter.txt
@@ -107,9 +107,31 @@  struct perf_dlfilter_sample {
 	__u64 raw_callchain_nr;	/* Number of raw_callchain entries */
 	const __u64 *raw_callchain; /* Refer <linux/perf_event.h> */
 	const char *event;
+	__s32 machine_pid;
+	__s32 vcpu;
 };
 ----
 
+Note: 'machine_pid' and 'vcpu' are not original members, but were added together later.
+'size' can be used to determine their presence at run time.
+PERF_DLFILTER_HAS_MACHINE_PID will be defined if they are present at compile time.
+For example:
+[source,c]
+----
+#include <perf/perf_dlfilter.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+static inline bool have_machine_pid(const struct perf_dlfilter_sample *sample)
+{
+#ifdef PERF_DLFILTER_HAS_MACHINE_PID
+	return sample->size >= offsetof(struct perf_dlfilter_sample, vcpu) + sizeof(sample->vcpu);
+#else
+	return false;
+#endif
+}
+----
+
 The perf_dlfilter_fns structure
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/tools/perf/include/perf/perf_dlfilter.h b/tools/perf/include/perf/perf_dlfilter.h
index 3eef03d661b4..a26e2f129f83 100644
--- a/tools/perf/include/perf/perf_dlfilter.h
+++ b/tools/perf/include/perf/perf_dlfilter.h
@@ -9,6 +9,12 @@ 
 #include <linux/perf_event.h>
 #include <linux/types.h>
 
+/*
+ * The following macro can be used to determine if this header defines
+ * perf_dlfilter_sample machine_pid and vcpu.
+ */
+#define PERF_DLFILTER_HAS_MACHINE_PID
+
 /* Definitions for perf_dlfilter_sample flags */
 enum {
 	PERF_DLFILTER_FLAG_BRANCH	= 1ULL << 0,
@@ -62,6 +68,8 @@  struct perf_dlfilter_sample {
 	__u64 raw_callchain_nr;	/* Number of raw_callchain entries */
 	const __u64 *raw_callchain; /* Refer <linux/perf_event.h> */
 	const char *event;
+	__s32 machine_pid;
+	__s32 vcpu;
 };
 
 /*
diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c
index db964d5a52af..54e4d4495e00 100644
--- a/tools/perf/util/dlfilter.c
+++ b/tools/perf/util/dlfilter.c
@@ -495,6 +495,8 @@  int dlfilter__do_filter_event(struct dlfilter *d,
 	ASSIGN(misc);
 	ASSIGN(raw_size);
 	ASSIGN(raw_data);
+	ASSIGN(machine_pid);
+	ASSIGN(vcpu);
 
 	if (sample->branch_stack) {
 		d_sample.brstack_nr = sample->branch_stack->nr;