Check sample_type in perf_sample_save_brstack() to prevent
saving branch stack data when it isn't required.
Suggested-by: Namhyung Kim <[email protected]>
Signed-off-by: Yabin Cui <[email protected]>
---
arch/x86/events/amd/core.c | 3 +--
arch/x86/events/core.c | 3 +--
arch/x86/events/intel/ds.c | 3 +--
include/linux/perf_event.h | 3 +++
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 985ef3b47919..fb9bf3aa1b42 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -967,8 +967,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
if (!x86_perf_event_set_period(event))
continue;
- if (has_branch_stack(event))
- perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
+ perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
if (perf_event_overflow(event, &data, regs))
x86_pmu_stop(event, 0);
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 5b0dd07b1ef1..ff5577315938 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1702,8 +1702,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs)
perf_sample_data_init(&data, 0, event->hw.last_period);
- if (has_branch_stack(event))
- perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
+ perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL);
if (perf_event_overflow(event, &data, regs))
x86_pmu_stop(event, 0);
diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index c2b5585aa6d1..f25236ffa28f 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -1754,8 +1754,7 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event,
if (x86_pmu.intel_cap.pebs_format >= 3)
setup_pebs_time(event, data, pebs->tsc);
- if (has_branch_stack(event))
- perf_sample_save_brstack(data, event, &cpuc->lbr_stack, NULL);
+ perf_sample_save_brstack(data, event, &cpuc->lbr_stack, NULL);
}
static void adaptive_pebs_save_regs(struct pt_regs *regs,
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 8617815456b0..8cff96782446 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1276,6 +1276,9 @@ static inline void perf_sample_save_brstack(struct perf_sample_data *data,
{
int size = sizeof(u64); /* nr */
+ if (!has_branch_stack(event))
+ return;
+
if (branch_sample_hw_index(event))
size += sizeof(u64);
size += brs->nr * sizeof(struct perf_branch_entry);
--
2.45.0.118.g7fe29c98d7-goog
Hi Yabin,
kernel test robot noticed the following build errors:
[auto build test ERROR on perf-tools-next/perf-tools-next]
[also build test ERROR on tip/perf/core linus/master v6.9-rc7 next-20240510]
[cannot apply to acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yabin-Cui/perf-core-Save-raw-sample-data-conditionally-based-on-sample-type/20240510-083817
base: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
patch link: https://lore.kernel.org/r/20240510002424.1277314-4-yabinc%40google.com
patch subject: [PATCH v3 3/3] perf: core: Check sample_type in perf_sample_save_brstack
config: x86_64-rhel-8.3 (https://download.01.org/0day-ci/archive/20240510/[email protected]/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240510/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/trace_events.h:10,
from include/trace/syscall.h:7,
from include/linux/syscalls.h:93,
from kernel/time/time.c:33:
include/linux/perf_event.h: In function 'perf_sample_save_brstack':
>> include/linux/perf_event.h:1279:14: error: implicit declaration of function 'has_branch_stack' [-Werror=implicit-function-declaration]
1279 | if (!has_branch_stack(event))
| ^~~~~~~~~~~~~~~~
include/linux/perf_event.h: At top level:
>> include/linux/perf_event.h:1671:20: error: conflicting types for 'has_branch_stack'; have 'bool(struct perf_event *)' {aka '_Bool(struct perf_event *)'}
1671 | static inline bool has_branch_stack(struct perf_event *event)
| ^~~~~~~~~~~~~~~~
include/linux/perf_event.h:1279:14: note: previous implicit declaration of 'has_branch_stack' with type 'int()'
1279 | if (!has_branch_stack(event))
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
In file included from include/linux/trace_events.h:10,
from include/trace/syscall.h:7,
from include/linux/syscalls.h:93,
from kernel/time/hrtimer.c:30:
include/linux/perf_event.h: In function 'perf_sample_save_brstack':
>> include/linux/perf_event.h:1279:14: error: implicit declaration of function 'has_branch_stack' [-Werror=implicit-function-declaration]
1279 | if (!has_branch_stack(event))
| ^~~~~~~~~~~~~~~~
include/linux/perf_event.h: At top level:
>> include/linux/perf_event.h:1671:20: error: conflicting types for 'has_branch_stack'; have 'bool(struct perf_event *)' {aka '_Bool(struct perf_event *)'}
1671 | static inline bool has_branch_stack(struct perf_event *event)
| ^~~~~~~~~~~~~~~~
include/linux/perf_event.h:1279:14: note: previous implicit declaration of 'has_branch_stack' with type 'int()'
1279 | if (!has_branch_stack(event))
| ^~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:121:35: warning: initialized field overwritten [-Woverride-init]
121 | [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:121:35: note: (near initialization for 'hrtimer_clock_to_base_table[0]')
kernel/time/hrtimer.c:122:35: warning: initialized field overwritten [-Woverride-init]
122 | [CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC,
| ^~~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:122:35: note: (near initialization for 'hrtimer_clock_to_base_table[1]')
kernel/time/hrtimer.c:123:35: warning: initialized field overwritten [-Woverride-init]
123 | [CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME,
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:123:35: note: (near initialization for 'hrtimer_clock_to_base_table[7]')
kernel/time/hrtimer.c:124:35: warning: initialized field overwritten [-Woverride-init]
124 | [CLOCK_TAI] = HRTIMER_BASE_TAI,
| ^~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:124:35: note: (near initialization for 'hrtimer_clock_to_base_table[11]')
cc1: some warnings being treated as errors
vim +/has_branch_stack +1279 include/linux/perf_event.h
1271
1272 static inline void perf_sample_save_brstack(struct perf_sample_data *data,
1273 struct perf_event *event,
1274 struct perf_branch_stack *brs,
1275 u64 *brs_cntr)
1276 {
1277 int size = sizeof(u64); /* nr */
1278
> 1279 if (!has_branch_stack(event))
1280 return;
1281
1282 if (branch_sample_hw_index(event))
1283 size += sizeof(u64);
1284 size += brs->nr * sizeof(struct perf_branch_entry);
1285
1286 /*
1287 * The extension space for counters is appended after the
1288 * struct perf_branch_stack. It is used to store the occurrences
1289 * of events of each branch.
1290 */
1291 if (brs_cntr)
1292 size += brs->nr * sizeof(u64);
1293
1294 data->br_stack = brs;
1295 data->br_stack_cntr = brs_cntr;
1296 data->dyn_size += size;
1297 data->sample_flags |= PERF_SAMPLE_BRANCH_STACK;
1298 }
1299
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Yabin,
kernel test robot noticed the following build errors:
[auto build test ERROR on perf-tools-next/perf-tools-next]
[also build test ERROR on tip/perf/core linus/master v6.9-rc7 next-20240510]
[cannot apply to acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yabin-Cui/perf-core-Save-raw-sample-data-conditionally-based-on-sample-type/20240510-083817
base: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git perf-tools-next
patch link: https://lore.kernel.org/r/20240510002424.1277314-4-yabinc%40google.com
patch subject: [PATCH v3 3/3] perf: core: Check sample_type in perf_sample_save_brstack
config: x86_64-buildonly-randconfig-001-20240510 (https://download.01.org/0day-ci/archive/20240510/[email protected]/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240510/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/trace_events.h:10,
from include/trace/syscall.h:7,
from include/linux/syscalls.h:93,
from kernel/time/itimer.c:10:
include/linux/perf_event.h: In function 'perf_sample_save_brstack':
>> include/linux/perf_event.h:1279:14: error: implicit declaration of function 'has_branch_stack' [-Werror=implicit-function-declaration]
1279 | if (!has_branch_stack(event))
| ^~~~~~~~~~~~~~~~
include/linux/perf_event.h: At top level:
>> include/linux/perf_event.h:1671:20: error: conflicting types for 'has_branch_stack'; have 'bool(struct perf_event *)' {aka '_Bool(struct perf_event *)'}
1671 | static inline bool has_branch_stack(struct perf_event *event)
| ^~~~~~~~~~~~~~~~
include/linux/perf_event.h:1279:14: note: previous implicit declaration of 'has_branch_stack' with type 'int()'
1279 | if (!has_branch_stack(event))
| ^~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
In file included from include/linux/trace_events.h:10,
from include/trace/syscall.h:7,
from include/linux/syscalls.h:93,
from kernel/time/hrtimer.c:30:
include/linux/perf_event.h: In function 'perf_sample_save_brstack':
>> include/linux/perf_event.h:1279:14: error: implicit declaration of function 'has_branch_stack' [-Werror=implicit-function-declaration]
1279 | if (!has_branch_stack(event))
| ^~~~~~~~~~~~~~~~
include/linux/perf_event.h: At top level:
>> include/linux/perf_event.h:1671:20: error: conflicting types for 'has_branch_stack'; have 'bool(struct perf_event *)' {aka '_Bool(struct perf_event *)'}
1671 | static inline bool has_branch_stack(struct perf_event *event)
| ^~~~~~~~~~~~~~~~
include/linux/perf_event.h:1279:14: note: previous implicit declaration of 'has_branch_stack' with type 'int()'
1279 | if (!has_branch_stack(event))
| ^~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:121:35: warning: initialized field overwritten [-Woverride-init]
121 | [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:121:35: note: (near initialization for 'hrtimer_clock_to_base_table[0]')
kernel/time/hrtimer.c:122:35: warning: initialized field overwritten [-Woverride-init]
122 | [CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC,
| ^~~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:122:35: note: (near initialization for 'hrtimer_clock_to_base_table[1]')
kernel/time/hrtimer.c:123:35: warning: initialized field overwritten [-Woverride-init]
123 | [CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME,
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:123:35: note: (near initialization for 'hrtimer_clock_to_base_table[7]')
kernel/time/hrtimer.c:124:35: warning: initialized field overwritten [-Woverride-init]
124 | [CLOCK_TAI] = HRTIMER_BASE_TAI,
| ^~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:124:35: note: (near initialization for 'hrtimer_clock_to_base_table[11]')
cc1: some warnings being treated as errors
vim +/has_branch_stack +1279 include/linux/perf_event.h
1271
1272 static inline void perf_sample_save_brstack(struct perf_sample_data *data,
1273 struct perf_event *event,
1274 struct perf_branch_stack *brs,
1275 u64 *brs_cntr)
1276 {
1277 int size = sizeof(u64); /* nr */
1278
> 1279 if (!has_branch_stack(event))
1280 return;
1281
1282 if (branch_sample_hw_index(event))
1283 size += sizeof(u64);
1284 size += brs->nr * sizeof(struct perf_branch_entry);
1285
1286 /*
1287 * The extension space for counters is appended after the
1288 * struct perf_branch_stack. It is used to store the occurrences
1289 * of events of each branch.
1290 */
1291 if (brs_cntr)
1292 size += brs->nr * sizeof(u64);
1293
1294 data->br_stack = brs;
1295 data->br_stack_cntr = brs_cntr;
1296 data->dyn_size += size;
1297 data->sample_flags |= PERF_SAMPLE_BRANCH_STACK;
1298 }
1299
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki