@@ -7046,12 +7046,21 @@ static void perf_aux_sample_output(struct perf_event *event,
7046
7046
ring_buffer_put (rb );
7047
7047
}
7048
7048
7049
+ /*
7050
+ * A set of common sample data types saved even for non-sample records
7051
+ * when event->attr.sample_id_all is set.
7052
+ */
7053
+ #define PERF_SAMPLE_ID_ALL (PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \
7054
+ PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
7055
+ PERF_SAMPLE_CPU | PERF_SAMPLE_IDENTIFIER)
7056
+
7049
7057
static void __perf_event_header__init_id (struct perf_event_header * header ,
7050
7058
struct perf_sample_data * data ,
7051
7059
struct perf_event * event ,
7052
7060
u64 sample_type )
7053
7061
{
7054
7062
data -> type = event -> attr .sample_type ;
7063
+ data -> sample_flags |= data -> type & PERF_SAMPLE_ID_ALL ;
7055
7064
header -> size += event -> id_header_size ;
7056
7065
7057
7066
if (sample_type & PERF_SAMPLE_TID ) {
@@ -7554,6 +7563,11 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs)
7554
7563
return callchain ?: & __empty_callchain ;
7555
7564
}
7556
7565
7566
+ static __always_inline u64 __cond_set (u64 flags , u64 s , u64 d )
7567
+ {
7568
+ return d * !!(flags & s );
7569
+ }
7570
+
7557
7571
void perf_prepare_sample (struct perf_event_header * header ,
7558
7572
struct perf_sample_data * data ,
7559
7573
struct perf_event * event ,
@@ -7569,14 +7583,24 @@ void perf_prepare_sample(struct perf_event_header *header,
7569
7583
header -> misc |= perf_misc_flags (regs );
7570
7584
7571
7585
/*
7572
- * Clear the sample flags that have already been done by the
7573
- * PMU driver.
7586
+ * Add the sample flags that are dependent to others. And clear the
7587
+ * sample flags that have already been done by the PMU driver.
7574
7588
*/
7575
- filtered_sample_type = sample_type & ~data -> sample_flags ;
7589
+ filtered_sample_type = sample_type ;
7590
+ filtered_sample_type |= __cond_set (sample_type , PERF_SAMPLE_CODE_PAGE_SIZE ,
7591
+ PERF_SAMPLE_IP );
7592
+ filtered_sample_type |= __cond_set (sample_type , PERF_SAMPLE_DATA_PAGE_SIZE |
7593
+ PERF_SAMPLE_PHYS_ADDR , PERF_SAMPLE_ADDR );
7594
+ filtered_sample_type |= __cond_set (sample_type , PERF_SAMPLE_STACK_USER ,
7595
+ PERF_SAMPLE_REGS_USER );
7596
+ filtered_sample_type &= ~data -> sample_flags ;
7597
+
7576
7598
__perf_event_header__init_id (header , data , event , filtered_sample_type );
7577
7599
7578
- if (sample_type & ( PERF_SAMPLE_IP | PERF_SAMPLE_CODE_PAGE_SIZE ))
7600
+ if (filtered_sample_type & PERF_SAMPLE_IP ) {
7579
7601
data -> ip = perf_instruction_pointer (regs );
7602
+ data -> sample_flags |= PERF_SAMPLE_IP ;
7603
+ }
7580
7604
7581
7605
if (filtered_sample_type & PERF_SAMPLE_CALLCHAIN )
7582
7606
perf_sample_save_callchain (data , event , regs );
@@ -7593,10 +7617,15 @@ void perf_prepare_sample(struct perf_event_header *header,
7593
7617
data -> sample_flags |= PERF_SAMPLE_BRANCH_STACK ;
7594
7618
}
7595
7619
7596
- if (sample_type & ( PERF_SAMPLE_REGS_USER | PERF_SAMPLE_STACK_USER ) )
7620
+ if (filtered_sample_type & PERF_SAMPLE_REGS_USER )
7597
7621
perf_sample_regs_user (& data -> regs_user , regs );
7598
7622
7599
- if (sample_type & PERF_SAMPLE_REGS_USER ) {
7623
+ /*
7624
+ * It cannot use the filtered_sample_type here as REGS_USER can be set
7625
+ * by STACK_USER (using __cond_set() above) and we don't want to update
7626
+ * the dyn_size if it's not requested by users.
7627
+ */
7628
+ if ((sample_type & ~data -> sample_flags ) & PERF_SAMPLE_REGS_USER ) {
7600
7629
/* regs dump ABI info */
7601
7630
int size = sizeof (u64 );
7602
7631
@@ -7606,9 +7635,10 @@ void perf_prepare_sample(struct perf_event_header *header,
7606
7635
}
7607
7636
7608
7637
data -> dyn_size += size ;
7638
+ data -> sample_flags |= PERF_SAMPLE_REGS_USER ;
7609
7639
}
7610
7640
7611
- if (sample_type & PERF_SAMPLE_STACK_USER ) {
7641
+ if (filtered_sample_type & PERF_SAMPLE_STACK_USER ) {
7612
7642
/*
7613
7643
* Either we need PERF_SAMPLE_STACK_USER bit to be always
7614
7644
* processed as the last one or have additional check added
@@ -7631,23 +7661,30 @@ void perf_prepare_sample(struct perf_event_header *header,
7631
7661
7632
7662
data -> stack_user_size = stack_size ;
7633
7663
data -> dyn_size += size ;
7664
+ data -> sample_flags |= PERF_SAMPLE_STACK_USER ;
7634
7665
}
7635
7666
7636
- if (filtered_sample_type & PERF_SAMPLE_WEIGHT_TYPE )
7667
+ if (filtered_sample_type & PERF_SAMPLE_WEIGHT_TYPE ) {
7637
7668
data -> weight .full = 0 ;
7669
+ data -> sample_flags |= PERF_SAMPLE_WEIGHT_TYPE ;
7670
+ }
7638
7671
7639
- if (filtered_sample_type & PERF_SAMPLE_DATA_SRC )
7672
+ if (filtered_sample_type & PERF_SAMPLE_DATA_SRC ) {
7640
7673
data -> data_src .val = PERF_MEM_NA ;
7674
+ data -> sample_flags |= PERF_SAMPLE_DATA_SRC ;
7675
+ }
7641
7676
7642
- if (filtered_sample_type & PERF_SAMPLE_TRANSACTION )
7677
+ if (filtered_sample_type & PERF_SAMPLE_TRANSACTION ) {
7643
7678
data -> txn = 0 ;
7679
+ data -> sample_flags |= PERF_SAMPLE_TRANSACTION ;
7680
+ }
7644
7681
7645
- if (sample_type & ( PERF_SAMPLE_ADDR | PERF_SAMPLE_PHYS_ADDR | PERF_SAMPLE_DATA_PAGE_SIZE ) ) {
7646
- if ( filtered_sample_type & PERF_SAMPLE_ADDR )
7647
- data -> addr = 0 ;
7682
+ if (filtered_sample_type & PERF_SAMPLE_ADDR ) {
7683
+ data -> addr = 0 ;
7684
+ data -> sample_flags |= PERF_SAMPLE_ADDR ;
7648
7685
}
7649
7686
7650
- if (sample_type & PERF_SAMPLE_REGS_INTR ) {
7687
+ if (filtered_sample_type & PERF_SAMPLE_REGS_INTR ) {
7651
7688
/* regs dump ABI info */
7652
7689
int size = sizeof (u64 );
7653
7690
@@ -7660,19 +7697,22 @@ void perf_prepare_sample(struct perf_event_header *header,
7660
7697
}
7661
7698
7662
7699
data -> dyn_size += size ;
7700
+ data -> sample_flags |= PERF_SAMPLE_REGS_INTR ;
7663
7701
}
7664
7702
7665
- if (sample_type & PERF_SAMPLE_PHYS_ADDR &&
7666
- filtered_sample_type & PERF_SAMPLE_PHYS_ADDR )
7703
+ if (filtered_sample_type & PERF_SAMPLE_PHYS_ADDR ) {
7667
7704
data -> phys_addr = perf_virt_to_phys (data -> addr );
7705
+ data -> sample_flags |= PERF_SAMPLE_PHYS_ADDR ;
7706
+ }
7668
7707
7669
7708
#ifdef CONFIG_CGROUP_PERF
7670
- if (sample_type & PERF_SAMPLE_CGROUP ) {
7709
+ if (filtered_sample_type & PERF_SAMPLE_CGROUP ) {
7671
7710
struct cgroup * cgrp ;
7672
7711
7673
7712
/* protected by RCU */
7674
7713
cgrp = task_css_check (current , perf_event_cgrp_id , 1 )-> cgroup ;
7675
7714
data -> cgroup = cgroup_id (cgrp );
7715
+ data -> sample_flags |= PERF_SAMPLE_CGROUP ;
7676
7716
}
7677
7717
#endif
7678
7718
@@ -7681,13 +7721,17 @@ void perf_prepare_sample(struct perf_event_header *header,
7681
7721
* require PERF_SAMPLE_ADDR, kernel implicitly retrieve the data->addr,
7682
7722
* but the value will not dump to the userspace.
7683
7723
*/
7684
- if (sample_type & PERF_SAMPLE_DATA_PAGE_SIZE )
7724
+ if (filtered_sample_type & PERF_SAMPLE_DATA_PAGE_SIZE ) {
7685
7725
data -> data_page_size = perf_get_page_size (data -> addr );
7726
+ data -> sample_flags |= PERF_SAMPLE_DATA_PAGE_SIZE ;
7727
+ }
7686
7728
7687
- if (sample_type & PERF_SAMPLE_CODE_PAGE_SIZE )
7729
+ if (filtered_sample_type & PERF_SAMPLE_CODE_PAGE_SIZE ) {
7688
7730
data -> code_page_size = perf_get_page_size (data -> ip );
7731
+ data -> sample_flags |= PERF_SAMPLE_CODE_PAGE_SIZE ;
7732
+ }
7689
7733
7690
- if (sample_type & PERF_SAMPLE_AUX ) {
7734
+ if (filtered_sample_type & PERF_SAMPLE_AUX ) {
7691
7735
u64 size ;
7692
7736
7693
7737
header -> size += sizeof (u64 ); /* size */
@@ -7705,6 +7749,7 @@ void perf_prepare_sample(struct perf_event_header *header,
7705
7749
7706
7750
WARN_ON_ONCE (size + header -> size > U16_MAX );
7707
7751
data -> dyn_size += size + sizeof (u64 ); /* size above */
7752
+ data -> sample_flags |= PERF_SAMPLE_AUX ;
7708
7753
}
7709
7754
7710
7755
header -> size += data -> dyn_size ;
0 commit comments