Skip to content

Commit 70b27c7

Browse files
captain5050acmel
authored andcommitted
perf parse-events: Add default_breakpoint_len helper
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 <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Chaitanya S Prakash <[email protected]> Cc: Colin Ian King <[email protected]> Cc: Dominique Martinet <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Junhao He <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Yang Jihong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent f76e352 commit 70b27c7

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

tools/perf/tests/bp_account.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "tests.h"
1717
#include "debug.h"
1818
#include "event.h"
19+
#include "parse-events.h"
1920
#include "../perf-sys.h"
2021
#include "cloexec.h"
2122

@@ -50,7 +51,7 @@ static int __event(bool is_x, void *addr, struct perf_event_attr *attr)
5051
attr->config = 0;
5152
attr->bp_type = is_x ? HW_BREAKPOINT_X : HW_BREAKPOINT_W;
5253
attr->bp_addr = (unsigned long) addr;
53-
attr->bp_len = sizeof(long);
54+
attr->bp_len = is_x ? default_breakpoint_len() : sizeof(long);
5455

5556
attr->sample_period = 1;
5657
attr->sample_type = PERF_SAMPLE_IP;
@@ -92,6 +93,7 @@ static int bp_accounting(int wp_cnt, int share)
9293
attr_mod = attr;
9394
attr_mod.bp_type = HW_BREAKPOINT_X;
9495
attr_mod.bp_addr = (unsigned long) test_function;
96+
attr_mod.bp_len = default_breakpoint_len();
9597

9698
ret = ioctl(fd[0], PERF_EVENT_IOC_MODIFY_ATTRIBUTES, &attr_mod);
9799
TEST_ASSERT_VAL("failed to modify wp\n", ret == 0);

tools/perf/tests/bp_signal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "tests.h"
2727
#include "debug.h"
2828
#include "event.h"
29+
#include "parse-events.h"
2930
#include "perf-sys.h"
3031
#include "cloexec.h"
3132

@@ -111,7 +112,7 @@ static int __event(bool is_x, void *addr, int sig)
111112
pe.config = 0;
112113
pe.bp_type = is_x ? HW_BREAKPOINT_X : HW_BREAKPOINT_W;
113114
pe.bp_addr = (unsigned long) addr;
114-
pe.bp_len = sizeof(long);
115+
pe.bp_len = is_x ? default_breakpoint_len() : sizeof(long);
115116

116117
pe.sample_period = 1;
117118
pe.sample_type = PERF_SAMPLE_IP;

tools/perf/tests/bp_signal_overflow.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "tests.h"
2626
#include "debug.h"
2727
#include "event.h"
28+
#include "parse-events.h"
2829
#include "../perf-sys.h"
2930
#include "cloexec.h"
3031

@@ -88,7 +89,7 @@ static int test__bp_signal_overflow(struct test_suite *test __maybe_unused, int
8889
pe.config = 0;
8990
pe.bp_type = HW_BREAKPOINT_X;
9091
pe.bp_addr = (unsigned long) test_function;
91-
pe.bp_len = sizeof(long);
92+
pe.bp_len = default_breakpoint_len();
9293

9394
pe.sample_period = THRESHOLD;
9495
pe.sample_type = PERF_SAMPLE_IP;

tools/perf/tests/parse-events.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <api/fs/fs.h>
66
#include "tests.h"
77
#include "debug.h"
8+
#include "parse-events.h"
89
#include "pmu.h"
910
#include "pmus.h"
1011
#include <dirent.h>
@@ -262,7 +263,7 @@ static int test__checkevent_breakpoint_x(struct evlist *evlist)
262263
TEST_ASSERT_VAL("wrong config", test_config(evsel, 0));
263264
TEST_ASSERT_VAL("wrong bp_type",
264265
HW_BREAKPOINT_X == evsel->core.attr.bp_type);
265-
TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->core.attr.bp_len);
266+
TEST_ASSERT_VAL("wrong bp_len", default_breakpoint_len() == evsel->core.attr.bp_len);
266267
return TEST_OK;
267268
}
268269

tools/perf/util/parse-events.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,11 @@ static int add_tracepoint_multi_sys(struct parse_events_state *parse_state,
671671
}
672672
#endif /* HAVE_LIBTRACEEVENT */
673673

674+
size_t default_breakpoint_len(void)
675+
{
676+
return sizeof(long);
677+
}
678+
674679
static int
675680
parse_breakpoint_type(const char *type, struct perf_event_attr *attr)
676681
{
@@ -729,7 +734,7 @@ int parse_events_add_breakpoint(struct parse_events_state *parse_state,
729734
/* Provide some defaults if len is not specified */
730735
if (!len) {
731736
if (attr.bp_type == HW_BREAKPOINT_X)
732-
len = sizeof(long);
737+
len = default_breakpoint_len();
733738
else
734739
len = HW_BREAKPOINT_LEN_4;
735740
}

tools/perf/util/parse-events.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,6 @@ static inline bool is_sdt_event(char *str __maybe_unused)
286286
}
287287
#endif /* HAVE_LIBELF_SUPPORT */
288288

289+
size_t default_breakpoint_len(void);
290+
289291
#endif /* __PERF_PARSE_EVENTS_H */

0 commit comments

Comments
 (0)