perf parse-events: Add default_breakpoint_len helper
authorIan Rogers <irogers@google.com>
Wed, 4 Sep 2024 05:06:04 +0000 (22:06 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 4 Sep 2024 12:49:09 +0000 (09:49 -0300)
The default breakpoint length is "sizeof(long)" however this is
incorrect on platforms like Aarch64 where sizeof(long) is 8 but the
breakpoint length is 4. Add a helper function that can be used to
determine the correct breakpoint length, in this change it just
returns the existing default sizeof(long) value.

Use the helper in the bp_account test so that, when modifying the
event from a watchpoint to a breakpoint, the breakpoint length is
appropriate for the architecture and not just sizeof(long).

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Junhao He <hejunhao3@huawei.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Yang Jihong <yangjihong@bytedance.com>
Link: https://lore.kernel.org/r/20240904050606.752788-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/bp_account.c
tools/perf/tests/bp_signal.c
tools/perf/tests/bp_signal_overflow.c
tools/perf/tests/parse-events.c
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h

index 6f921db33cf90ee2fad936a11d46011597e02028..4cb7d486b5c178c622be4fc7e9c8c5a924df9d9b 100644 (file)
@@ -16,6 +16,7 @@
 #include "tests.h"
 #include "debug.h"
 #include "event.h"
+#include "parse-events.h"
 #include "../perf-sys.h"
 #include "cloexec.h"
 
@@ -50,7 +51,7 @@ static int __event(bool is_x, void *addr, struct perf_event_attr *attr)
        attr->config = 0;
        attr->bp_type = is_x ? HW_BREAKPOINT_X : HW_BREAKPOINT_W;
        attr->bp_addr = (unsigned long) addr;
-       attr->bp_len = sizeof(long);
+       attr->bp_len = is_x ? default_breakpoint_len() : sizeof(long);
 
        attr->sample_period = 1;
        attr->sample_type = PERF_SAMPLE_IP;
@@ -92,6 +93,7 @@ static int bp_accounting(int wp_cnt, int share)
        attr_mod = attr;
        attr_mod.bp_type = HW_BREAKPOINT_X;
        attr_mod.bp_addr = (unsigned long) test_function;
+       attr_mod.bp_len = default_breakpoint_len();
 
        ret = ioctl(fd[0], PERF_EVENT_IOC_MODIFY_ATTRIBUTES, &attr_mod);
        TEST_ASSERT_VAL("failed to modify wp\n", ret == 0);
index 1f2908f02389a83834abcc860971f18eb975a37a..3faeb5b6fe0bb24a9d5d669e85a2d8f7fca0e2d3 100644 (file)
@@ -26,6 +26,7 @@
 #include "tests.h"
 #include "debug.h"
 #include "event.h"
+#include "parse-events.h"
 #include "perf-sys.h"
 #include "cloexec.h"
 
@@ -111,7 +112,7 @@ static int __event(bool is_x, void *addr, int sig)
        pe.config = 0;
        pe.bp_type = is_x ? HW_BREAKPOINT_X : HW_BREAKPOINT_W;
        pe.bp_addr = (unsigned long) addr;
-       pe.bp_len = sizeof(long);
+       pe.bp_len = is_x ? default_breakpoint_len() : sizeof(long);
 
        pe.sample_period = 1;
        pe.sample_type = PERF_SAMPLE_IP;
index 4e897c2cf26b880e8ada210cc8900b4d8c87aeee..ee560e156be6d0042e3ea1cf27e8d842fc0e40c8 100644 (file)
@@ -25,6 +25,7 @@
 #include "tests.h"
 #include "debug.h"
 #include "event.h"
+#include "parse-events.h"
 #include "../perf-sys.h"
 #include "cloexec.h"
 
@@ -88,7 +89,7 @@ static int test__bp_signal_overflow(struct test_suite *test __maybe_unused, int
        pe.config = 0;
        pe.bp_type = HW_BREAKPOINT_X;
        pe.bp_addr = (unsigned long) test_function;
-       pe.bp_len = sizeof(long);
+       pe.bp_len = default_breakpoint_len();
 
        pe.sample_period = THRESHOLD;
        pe.sample_type = PERF_SAMPLE_IP;
index edc2adcf1baed195da2cfa20795f9121d3266ed4..639e65a9bf61801a8174318bea8815ef15695a33 100644 (file)
@@ -5,6 +5,7 @@
 #include <api/fs/fs.h>
 #include "tests.h"
 #include "debug.h"
+#include "parse-events.h"
 #include "pmu.h"
 #include "pmus.h"
 #include <dirent.h>
@@ -262,7 +263,7 @@ static int test__checkevent_breakpoint_x(struct evlist *evlist)
        TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
        TEST_ASSERT_VAL("wrong bp_type",
                        HW_BREAKPOINT_X == evsel->core.attr.bp_type);
-       TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len);
+       TEST_ASSERT_VAL("wrong bp_len", default_breakpoint_len() == evsel->core.attr.bp_len);
        return TEST_OK;
 }
 
index 9c0ce01684c39eb12b244516bf63fb1b6096ee2c..8c837c8a6c8c616d3a5990eeb1371ad16d32c4ca 100644 (file)
@@ -671,6 +671,11 @@ static int add_tracepoint_multi_sys(struct parse_events_state *parse_state,
 }
 #endif /* HAVE_LIBTRACEEVENT */
 
+size_t default_breakpoint_len(void)
+{
+       return sizeof(long);
+}
+
 static int
 parse_breakpoint_type(const char *type, struct perf_event_attr *attr)
 {
@@ -729,7 +734,7 @@ int parse_events_add_breakpoint(struct parse_events_state *parse_state,
        /* Provide some defaults if len is not specified */
        if (!len) {
                if (attr.bp_type == HW_BREAKPOINT_X)
-                       len = sizeof(long);
+                       len = default_breakpoint_len();
                else
                        len = HW_BREAKPOINT_LEN_4;
        }
index b735cd9e0acf514bacfb135080ffd524fa56e3d0..68bfea9ffa7069bd3e2d13731b5e45a59f13bc81 100644 (file)
@@ -286,4 +286,6 @@ static inline bool is_sdt_event(char *str __maybe_unused)
 }
 #endif /* HAVE_LIBELF_SUPPORT */
 
+size_t default_breakpoint_len(void);
+
 #endif /* __PERF_PARSE_EVENTS_H */