1*6b9c0261SThomas FalconIntel Auto Counter Reload Support 2*6b9c0261SThomas Falcon--------------------------------- 3*6b9c0261SThomas FalconSupport for Intel Auto Counter Reload in perf tools 4*6b9c0261SThomas Falcon 5*6b9c0261SThomas FalconAuto counter reload provides a means for software to specify to hardware 6*6b9c0261SThomas Falconthat certain counters, if supported, should be automatically reloaded 7*6b9c0261SThomas Falconupon overflow of chosen counters. By taking a sample only if the rate of 8*6b9c0261SThomas Falconone event exceeds some threshold relative to the rate of another event, 9*6b9c0261SThomas Falconthis feature enables software to sample based on the relative rate of 10*6b9c0261SThomas Falcontwo or more events. To enable this, the user must provide a sample period 11*6b9c0261SThomas Falconterm and a bitmask ("acr_mask") for each relevant event specifying the 12*6b9c0261SThomas Falconcounters in an event group to reload if the event's specified sample 13*6b9c0261SThomas Falconperiod is exceeded. 14*6b9c0261SThomas Falcon 15*6b9c0261SThomas FalconFor example, if the user desires to measure a scenario when IPC > 2, 16*6b9c0261SThomas Falconthe event group might look like the one below: 17*6b9c0261SThomas Falcon 18*6b9c0261SThomas Falcon perf record -e {cpu_atom/instructions,period=200000,acr_mask=0x2/, \ 19*6b9c0261SThomas Falcon cpu_atom/cycles,period=100000,acr_mask=0x3/} -- true 20*6b9c0261SThomas Falcon 21*6b9c0261SThomas FalconIn this case, if the "instructions" counter exceeds the sample period of 22*6b9c0261SThomas Falcon200000, the second counter, "cycles", will be reset and a sample will be 23*6b9c0261SThomas Falcontaken. If "cycles" is exceeded first, both counters in the group will be 24*6b9c0261SThomas Falconreset. In this way, samples will only be taken for cases where IPC > 2. 25*6b9c0261SThomas Falcon 26*6b9c0261SThomas FalconThe acr_mask term is a hexadecimal value representing a bitmask of the 27*6b9c0261SThomas Falconevents in the group to be reset when the period is exceeded. In the 28*6b9c0261SThomas Falconexample above, "instructions" is assigned an acr_mask of 0x2, meaning 29*6b9c0261SThomas Falcononly the second event in the group is reloaded and a sample is taken 30*6b9c0261SThomas Falconfor the first event. "cycles" is assigned an acr_mask of 0x3, meaning 31*6b9c0261SThomas Falconthat both event counters will be reset if the sample period is exceeded 32*6b9c0261SThomas Falconfirst. 33*6b9c0261SThomas Falcon 34*6b9c0261SThomas Falconratio-to-prev Event Term 35*6b9c0261SThomas Falcon------------------------ 36*6b9c0261SThomas FalconTo simplify this, an event term "ratio-to-prev" is provided which is used 37*6b9c0261SThomas Falconalongside the sample period term n or the -c/--count option. This would 38*6b9c0261SThomas Falconallow users to specify the desired relative rate between events as a 39*6b9c0261SThomas Falconratio. Note: Both events compared must belong to the same PMU. 40*6b9c0261SThomas Falcon 41*6b9c0261SThomas FalconThe command above would then become 42*6b9c0261SThomas Falcon 43*6b9c0261SThomas Falcon perf record -e {cpu_atom/instructions/, \ 44*6b9c0261SThomas Falcon cpu_atom/cycles,period=100000,ratio-to-prev=0.5/} -- true 45*6b9c0261SThomas Falcon 46*6b9c0261SThomas Falconratio-to-prev is the ratio of the event using the term relative 47*6b9c0261SThomas Falconto the previous event in the group, which will always be 1, 48*6b9c0261SThomas Falconfor a 1:0.5 or 2:1 ratio. 49*6b9c0261SThomas Falcon 50*6b9c0261SThomas FalconTo sample for IPC < 2 for example, the events need to be reordered: 51*6b9c0261SThomas Falcon 52*6b9c0261SThomas Falcon perf record -e {cpu_atom/cycles/, \ 53*6b9c0261SThomas Falcon cpu_atom/instructions,period=200000,ratio-to-prev=2.0/} -- true 54