@@ -55,6 +55,7 @@ enum intel_pt_pkt_state {
55
55
INTEL_PT_STATE_TIP_PGD ,
56
56
INTEL_PT_STATE_FUP ,
57
57
INTEL_PT_STATE_FUP_NO_TIP ,
58
+ INTEL_PT_STATE_RESAMPLE ,
58
59
};
59
60
60
61
static inline bool intel_pt_sample_time (enum intel_pt_pkt_state pkt_state )
@@ -65,6 +66,7 @@ static inline bool intel_pt_sample_time(enum intel_pt_pkt_state pkt_state)
65
66
case INTEL_PT_STATE_ERR_RESYNC :
66
67
case INTEL_PT_STATE_IN_SYNC :
67
68
case INTEL_PT_STATE_TNT_CONT :
69
+ case INTEL_PT_STATE_RESAMPLE :
68
70
return true;
69
71
case INTEL_PT_STATE_TNT :
70
72
case INTEL_PT_STATE_TIP :
@@ -109,6 +111,8 @@ struct intel_pt_decoder {
109
111
bool fixup_last_mtc ;
110
112
bool have_last_ip ;
111
113
bool in_psb ;
114
+ bool hop ;
115
+ bool hop_psb_fup ;
112
116
enum intel_pt_param_flags flags ;
113
117
uint64_t pos ;
114
118
uint64_t last_ip ;
@@ -235,6 +239,7 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
235
239
decoder -> data = params -> data ;
236
240
decoder -> return_compression = params -> return_compression ;
237
241
decoder -> branch_enable = params -> branch_enable ;
242
+ decoder -> hop = params -> quick >= 1 ;
238
243
239
244
decoder -> flags = params -> flags ;
240
245
@@ -275,6 +280,9 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
275
280
intel_pt_log ("timestamp: tsc_ctc_mult %u\n" , decoder -> tsc_ctc_mult );
276
281
intel_pt_log ("timestamp: tsc_slip %#x\n" , decoder -> tsc_slip );
277
282
283
+ if (decoder -> hop )
284
+ intel_pt_log ("Hop mode: decoding FUP and TIPs, but not TNT\n" );
285
+
278
286
return decoder ;
279
287
}
280
288
@@ -1730,8 +1738,14 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)
1730
1738
1731
1739
case INTEL_PT_FUP :
1732
1740
decoder -> pge = true;
1733
- if (decoder -> packet .count )
1741
+ if (decoder -> packet .count ) {
1734
1742
intel_pt_set_last_ip (decoder );
1743
+ if (decoder -> hop ) {
1744
+ /* Act on FUP at PSBEND */
1745
+ decoder -> ip = decoder -> last_ip ;
1746
+ decoder -> hop_psb_fup = true;
1747
+ }
1748
+ }
1735
1749
break ;
1736
1750
1737
1751
case INTEL_PT_MODE_TSX :
@@ -1875,6 +1889,118 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
1875
1889
}
1876
1890
}
1877
1891
1892
+ static int intel_pt_resample (struct intel_pt_decoder * decoder )
1893
+ {
1894
+ decoder -> pkt_state = INTEL_PT_STATE_IN_SYNC ;
1895
+ decoder -> state .type = INTEL_PT_INSTRUCTION ;
1896
+ decoder -> state .from_ip = decoder -> ip ;
1897
+ decoder -> state .to_ip = 0 ;
1898
+ return 0 ;
1899
+ }
1900
+
1901
+ #define HOP_PROCESS 0
1902
+ #define HOP_IGNORE 1
1903
+ #define HOP_RETURN 2
1904
+ #define HOP_AGAIN 3
1905
+
1906
+ /* Hop mode: Ignore TNT, do not walk code, but get ip from FUPs and TIPs */
1907
+ static int intel_pt_hop_trace (struct intel_pt_decoder * decoder , bool * no_tip , int * err )
1908
+ {
1909
+ switch (decoder -> packet .type ) {
1910
+ case INTEL_PT_TNT :
1911
+ return HOP_IGNORE ;
1912
+
1913
+ case INTEL_PT_TIP_PGD :
1914
+ if (!decoder -> packet .count )
1915
+ return HOP_IGNORE ;
1916
+ intel_pt_set_ip (decoder );
1917
+ decoder -> state .type |= INTEL_PT_TRACE_END ;
1918
+ decoder -> state .from_ip = 0 ;
1919
+ decoder -> state .to_ip = decoder -> ip ;
1920
+ return HOP_RETURN ;
1921
+
1922
+ case INTEL_PT_TIP :
1923
+ if (!decoder -> packet .count )
1924
+ return HOP_IGNORE ;
1925
+ intel_pt_set_ip (decoder );
1926
+ decoder -> state .type = INTEL_PT_INSTRUCTION ;
1927
+ decoder -> state .from_ip = decoder -> ip ;
1928
+ decoder -> state .to_ip = 0 ;
1929
+ return HOP_RETURN ;
1930
+
1931
+ case INTEL_PT_FUP :
1932
+ if (!decoder -> packet .count )
1933
+ return HOP_IGNORE ;
1934
+ intel_pt_set_ip (decoder );
1935
+ if (intel_pt_fup_event (decoder ))
1936
+ return HOP_RETURN ;
1937
+ if (!decoder -> branch_enable )
1938
+ * no_tip = true;
1939
+ if (* no_tip ) {
1940
+ decoder -> state .type = INTEL_PT_INSTRUCTION ;
1941
+ decoder -> state .from_ip = decoder -> ip ;
1942
+ decoder -> state .to_ip = 0 ;
1943
+ return HOP_RETURN ;
1944
+ }
1945
+ * err = intel_pt_walk_fup_tip (decoder );
1946
+ if (!* err )
1947
+ decoder -> pkt_state = INTEL_PT_STATE_RESAMPLE ;
1948
+ return HOP_RETURN ;
1949
+
1950
+ case INTEL_PT_PSB :
1951
+ decoder -> last_ip = 0 ;
1952
+ decoder -> have_last_ip = true;
1953
+ decoder -> hop_psb_fup = false;
1954
+ * err = intel_pt_walk_psbend (decoder );
1955
+ if (* err == - EAGAIN )
1956
+ return HOP_AGAIN ;
1957
+ if (* err )
1958
+ return HOP_RETURN ;
1959
+ if (decoder -> hop_psb_fup ) {
1960
+ decoder -> hop_psb_fup = false;
1961
+ decoder -> state .type = INTEL_PT_INSTRUCTION ;
1962
+ decoder -> state .from_ip = decoder -> ip ;
1963
+ decoder -> state .to_ip = 0 ;
1964
+ return HOP_RETURN ;
1965
+ }
1966
+ if (decoder -> cbr != decoder -> cbr_seen ) {
1967
+ decoder -> state .type = 0 ;
1968
+ return HOP_RETURN ;
1969
+ }
1970
+ return HOP_IGNORE ;
1971
+
1972
+ case INTEL_PT_BAD :
1973
+ case INTEL_PT_PAD :
1974
+ case INTEL_PT_TIP_PGE :
1975
+ case INTEL_PT_TSC :
1976
+ case INTEL_PT_TMA :
1977
+ case INTEL_PT_MODE_EXEC :
1978
+ case INTEL_PT_MODE_TSX :
1979
+ case INTEL_PT_MTC :
1980
+ case INTEL_PT_CYC :
1981
+ case INTEL_PT_VMCS :
1982
+ case INTEL_PT_PSBEND :
1983
+ case INTEL_PT_CBR :
1984
+ case INTEL_PT_TRACESTOP :
1985
+ case INTEL_PT_PIP :
1986
+ case INTEL_PT_OVF :
1987
+ case INTEL_PT_MNT :
1988
+ case INTEL_PT_PTWRITE :
1989
+ case INTEL_PT_PTWRITE_IP :
1990
+ case INTEL_PT_EXSTOP :
1991
+ case INTEL_PT_EXSTOP_IP :
1992
+ case INTEL_PT_MWAIT :
1993
+ case INTEL_PT_PWRE :
1994
+ case INTEL_PT_PWRX :
1995
+ case INTEL_PT_BBP :
1996
+ case INTEL_PT_BIP :
1997
+ case INTEL_PT_BEP :
1998
+ case INTEL_PT_BEP_IP :
1999
+ default :
2000
+ return HOP_PROCESS ;
2001
+ }
2002
+ }
2003
+
1878
2004
static int intel_pt_walk_trace (struct intel_pt_decoder * decoder )
1879
2005
{
1880
2006
bool no_tip = false;
@@ -1885,6 +2011,19 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
1885
2011
if (err )
1886
2012
return err ;
1887
2013
next :
2014
+ if (decoder -> hop ) {
2015
+ switch (intel_pt_hop_trace (decoder , & no_tip , & err )) {
2016
+ case HOP_IGNORE :
2017
+ continue ;
2018
+ case HOP_RETURN :
2019
+ return err ;
2020
+ case HOP_AGAIN :
2021
+ goto next ;
2022
+ default :
2023
+ break ;
2024
+ }
2025
+ }
2026
+
1888
2027
switch (decoder -> packet .type ) {
1889
2028
case INTEL_PT_TNT :
1890
2029
if (!decoder -> packet .count )
@@ -1914,6 +2053,12 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
1914
2053
decoder -> state .from_ip = 0 ;
1915
2054
decoder -> state .to_ip = decoder -> ip ;
1916
2055
decoder -> state .type |= INTEL_PT_TRACE_BEGIN ;
2056
+ /*
2057
+ * In hop mode, resample to get the to_ip as an
2058
+ * "instruction" sample.
2059
+ */
2060
+ if (decoder -> hop )
2061
+ decoder -> pkt_state = INTEL_PT_STATE_RESAMPLE ;
1917
2062
return 0 ;
1918
2063
}
1919
2064
@@ -2033,7 +2178,7 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
2033
2178
2034
2179
case INTEL_PT_MODE_TSX :
2035
2180
/* MODE_TSX need not be followed by FUP */
2036
- if (!decoder -> pge ) {
2181
+ if (!decoder -> pge || decoder -> in_psb ) {
2037
2182
intel_pt_update_in_tx (decoder );
2038
2183
break ;
2039
2184
}
@@ -2424,7 +2569,11 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)
2424
2569
if (err )
2425
2570
return err ;
2426
2571
2427
- decoder -> pkt_state = INTEL_PT_STATE_IN_SYNC ;
2572
+ /* In hop mode, resample to get the to_ip as an "instruction" sample */
2573
+ if (decoder -> hop )
2574
+ decoder -> pkt_state = INTEL_PT_STATE_RESAMPLE ;
2575
+ else
2576
+ decoder -> pkt_state = INTEL_PT_STATE_IN_SYNC ;
2428
2577
decoder -> overflow = false;
2429
2578
2430
2579
decoder -> state .from_ip = 0 ;
@@ -2545,7 +2694,14 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)
2545
2694
2546
2695
if (decoder -> ip ) {
2547
2696
decoder -> state .type = 0 ; /* Do not have a sample */
2548
- decoder -> pkt_state = INTEL_PT_STATE_IN_SYNC ;
2697
+ /*
2698
+ * In hop mode, resample to get the PSB FUP ip as an
2699
+ * "instruction" sample.
2700
+ */
2701
+ if (decoder -> hop )
2702
+ decoder -> pkt_state = INTEL_PT_STATE_RESAMPLE ;
2703
+ else
2704
+ decoder -> pkt_state = INTEL_PT_STATE_IN_SYNC ;
2549
2705
} else {
2550
2706
return intel_pt_sync_ip (decoder );
2551
2707
}
@@ -2609,6 +2765,9 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
2609
2765
if (err == - EAGAIN )
2610
2766
err = intel_pt_walk_trace (decoder );
2611
2767
break ;
2768
+ case INTEL_PT_STATE_RESAMPLE :
2769
+ err = intel_pt_resample (decoder );
2770
+ break ;
2612
2771
default :
2613
2772
err = intel_pt_bug (decoder );
2614
2773
break ;
0 commit comments