OSDN Git Service

(split) LDP: Update original to LDP v3.65
[linuxjm/LDP_man-pages.git] / original / man2 / perf_event_open.2
index f80cf63..5024d58 100644 (file)
@@ -24,7 +24,7 @@
 .\" This document is based on the perf_event.h header file, the
 .\" tools/perf/design.txt file, and a lot of bitter experience.
 .\"
-.TH PERF_EVENT_OPEN 2 2013-02-04 "Linux" "Linux Programmer's Manual"
+.TH PERF_EVENT_OPEN 2 2014-04-17 "Linux" "Linux Programmer's Manual"
 .SH NAME
 perf_event_open \- set up performance monitoring
 .SH SYNOPSIS
@@ -56,7 +56,7 @@ to measure multiple events simultaneously.
 Events can be enabled and disabled in two ways: via
 .BR ioctl (2)
 and via
-.BR prctl (2) .
+.BR prctl (2).
 When an event is disabled it does not count or generate overflows but does
 continue to exist and maintain its count value.
 .PP
@@ -72,57 +72,39 @@ A
 .I sampling
 event periodically writes measurements to a buffer that can then
 be accessed via
-.BR  mmap (2) .
+.BR mmap (2).
 .SS Arguments
 .P
-The argument
-.I pid
-allows events to be attached to processes in various ways.
-If
-.I pid
-is 0, measurements happen on the current thread, if
-.I pid
-is greater than 0, the process indicated by
-.I pid
-is measured, and if
-.I pid
-is \-1, all processes are counted.
-
 The
-.I cpu
-argument allows measurements to be specific to a CPU.
-If
-.I cpu
-is greater than or equal to 0,
-measurements are restricted to the specified CPU;
-if
-.I cpu
-is \-1, the events are measured on all CPUs.
-.P
-Note that the combination of
-.IR pid " == \-1"
-and
-.IR cpu " == \-1"
-is not valid.
-.P
-A
-.IR pid " > 0"
-and
-.IR cpu " == \-1"
-setting measures per-process and follows that process to whatever CPU the
-process gets scheduled to.
-Per-process events can be created by any user.
-.P
-A
-.IR pid " == \-1"
+.I pid
 and
-.IR cpu " >= 0"
-setting is per-CPU and measures all processes on the specified CPU.
-Per-CPU events need the
+.I cpu
+arguments allow specifying which process and CPU to monitor:
+.TP
+.BR "pid == 0" " and " "cpu == \-1"
+This measures the calling process/thread on any CPU.
+.TP
+.BR "pid == 0" " and " "cpu >= 0"
+This measures the calling process/thread only
+when running on the specified CPU.
+.TP
+.BR "pid > 0" " and " "cpu == \-1"
+This measures the specified process/thread on any CPU.
+.TP
+.BR "pid > 0" " and " "cpu >= 0"
+This measures the specified process/thread only
+when running on the specified CPU.
+.TP
+.BR "pid == \-1" " and " "cpu >= 0"
+This measures all processes/threads on the specified CPU.
+This requires
 .B CAP_SYS_ADMIN
 capability or a
 .I /proc/sys/kernel/perf_event_paranoid
 value of less than 1.
+.TP
+.BR "pid == \-1" " and " "cpu == \-1"
+This setting is invalid and will return an error.
 .P
 The
 .I group_fd
@@ -134,21 +116,37 @@ The rest of the group members are created with subsequent
 .BR perf_event_open ()
 calls with
 .IR group_fd
-being set to the fd of the group leader.
+being set to the file descriptor of the group leader.
 (A single event on its own is created with
 .IR group_fd " = \-1"
 and is considered to be a group with only 1 member.)
-An event group is scheduled onto the CPU as a unit: it will only
-be put onto the CPU if all of the events in the group can be put onto
+An event group is scheduled onto the CPU as a unit: it will
+be put onto the CPU only if all of the events in the group can be put onto
 the CPU.
 This means that the values of the member events can be
-meaningfully compared, added, divided (to get ratios), etc., with each
+meaningfully compared\(emadded, divided (to get ratios), and so on\(emwith each
 other, since they have counted events for the same set of executed
 instructions.
 .P
 The
 .I flags
-argument takes one of the following values:
+argument is formed by ORing together zero or more of the following values:
+.TP
+.BR PERF_FLAG_FD_CLOEXEC " (since Linux 3.14)."
+This flag enables the close-on-exec flag for the created
+event file descriptor,
+so that the file descriptor is automatically closed on
+.BR execve (2).
+Setting the close-on-exec flags at creation time, rather than later with
+.BR fcntl (2),
+avoids potential race conditions where the calling thread invokes
+.BR perf_event_open ()
+and
+.BR fcntl (2)
+at the same time as another thread calls
+.BR fork (2)
+then
+.BR execve (2).
 .TP
 .BR PERF_FLAG_FD_NO_GROUP
 .\" FIXME The following sentence is unclear
@@ -158,13 +156,13 @@ It is unclear why this is useful.
 .\" FIXME So, why is it useful?
 .TP
 .BR PERF_FLAG_FD_OUTPUT
-This flag re-routes the output from an event to the group leader.
+This flag reroutes the output from an event to the group leader.
 .TP
-.BR PERF_FLAG_PID_CGROUP " (Since Linux 2.6.39)."
+.BR PERF_FLAG_PID_CGROUP " (since Linux 2.6.39)."
 This flag activates per-container system-wide monitoring.
 A container
-is an abstraction that isolates a set of resources for finer grain
-control (CPUs, memory, etc...).
+is an abstraction that isolates a set of resources for finer-grained
+control (CPUs, memory, etc.).
 In this mode, the event is measured
 only if the thread running on the monitored CPU belongs to the designated
 container (cgroup).
@@ -180,7 +178,7 @@ then a file descriptor opened on
 must be passed as the
 .I pid
 parameter.
-cgroup monitoring is only available
+cgroup monitoring is available only
 for system-wide events and may therefore require extra permissions.
 .P
 The
@@ -191,43 +189,43 @@ for the event being created.
 .in +4n
 .nf
 struct perf_event_attr {
-    __u32     type;         /* Type of event */
-    __u32     size;         /* Size of attribute structure */
-    __u64     config;       /* Type-specific configuration */
+    __u32 type;         /* Type of event */
+    __u32 size;         /* Size of attribute structure */
+    __u64 config;       /* Type-specific configuration */
 
     union {
         __u64 sample_period;    /* Period of sampling */
         __u64 sample_freq;      /* Frequency of sampling */
     };
 
-    __u64     sample_type;  /* Specifies values included in sample */
-    __u64     read_format;  /* Specifies values returned in read */
-
-    __u64     disabled       : 1,   /* off by default */
-              inherit        : 1,   /* children inherit it */
-              pinned         : 1,   /* must always be on PMU */
-              exclusive      : 1,   /* only group on PMU */
-              exclude_user   : 1,   /* don't count user */
-              exclude_kernel : 1,   /* don't count kernel */
-              exclude_hv     : 1,   /* don't count hypervisor */
-              exclude_idle   : 1,   /* don't count when idle */
-              mmap           : 1,   /* include mmap data */
-              comm           : 1,   /* include comm data */
-              freq           : 1,   /* use freq, not period */
-              inherit_stat   : 1,   /* per task counts */
-              enable_on_exec : 1,   /* next exec enables */
-              task           : 1,   /* trace fork/exit */
-              watermark      : 1,   /* wakeup_watermark */
-              precise_ip     : 2,   /* skid constraint */
-              mmap_data      : 1,   /* non-exec mmap data */
-              sample_id_all  : 1,   /* sample_type all events */
-              exclude_host   : 1,   /* don't count in host */
-              exclude_guest  : 1,   /* don't count in guest */
-              exclude_callchain_kernel : 1,
-                                    /* exclude kernel callchains */
-              exclude_callchain_user   : 1,
-                                   /* exclude user callchains */
-              __reserved_1   : 41;
+    __u64 sample_type;  /* Specifies values included in sample */
+    __u64 read_format;  /* Specifies values returned in read */
+
+    __u64 disabled       : 1,   /* off by default */
+          inherit        : 1,   /* children inherit it */
+          pinned         : 1,   /* must always be on PMU */
+          exclusive      : 1,   /* only group on PMU */
+          exclude_user   : 1,   /* don't count user */
+          exclude_kernel : 1,   /* don't count kernel */
+          exclude_hv     : 1,   /* don't count hypervisor */
+          exclude_idle   : 1,   /* don't count when idle */
+          mmap           : 1,   /* include mmap data */
+          comm           : 1,   /* include comm data */
+          freq           : 1,   /* use freq, not period */
+          inherit_stat   : 1,   /* per task counts */
+          enable_on_exec : 1,   /* next exec enables */
+          task           : 1,   /* trace fork/exit */
+          watermark      : 1,   /* wakeup_watermark */
+          precise_ip     : 2,   /* skid constraint */
+          mmap_data      : 1,   /* non-exec mmap data */
+          sample_id_all  : 1,   /* sample_type all events */
+          exclude_host   : 1,   /* don't count in host */
+          exclude_guest  : 1,   /* don't count in guest */
+          exclude_callchain_kernel : 1,
+                                /* exclude kernel callchains */
+          exclude_callchain_user   : 1,
+                                /* exclude user callchains */
+          __reserved_1   : 41;
 
     union {
         __u32 wakeup_events;    /* wakeup every n events */
@@ -245,11 +243,11 @@ struct perf_event_attr {
         __u64 bp_len;           /* breakpoint length */
         __u64 config2;          /* extension of config1 */
     };
-    __u64   branch_sample_type; /* enum perf_branch_sample_type */
-    __u64   sample_regs_user;   /* user regs to dump on samples */
-    __u32   sample_stack_user;  /* size of stack to dump on
+    __u64 branch_sample_type;   /* enum perf_branch_sample_type */
+    __u64 sample_regs_user;     /* user regs to dump on samples */
+    __u32 sample_stack_user;    /* size of stack to dump on
                                    samples */
-    __u32   __reserved_2;       /* Align to u64 */
+    __u32 __reserved_2;         /* Align to u64 */
 
 };
 .fi
@@ -289,7 +287,7 @@ field definition.
 This indicates a "raw" implementation-specific event in the
 .IR config " field."
 .TP
-.BR PERF_TYPE_BREAKPOINT " (Since Linux 2.6.33)"
+.BR PERF_TYPE_BREAKPOINT " (since Linux 2.6.33)"
 This indicates a hardware breakpoint as provided by the CPU.
 Breakpoints can be read/write accesses to an address as well as
 execution of an instruction address.
@@ -304,7 +302,7 @@ field to indicate which PMU to use.
 The value to use can be found in the sysfs filesystem:
 there is a subdirectory per PMU instance under
 .IR /sys/bus/event_source/devices .
-In each sub-directory there is a
+In each subdirectory there is a
 .I type
 file whose content is an integer that can be used in the
 .I type
@@ -379,12 +377,12 @@ to one of the following:
 .TP
 .B PERF_COUNT_HW_CPU_CYCLES
 Total cycles.
-Be wary of what happens during CPU frequency scaling
+Be wary of what happens during CPU frequency scaling.
 .TP
 .B PERF_COUNT_HW_INSTRUCTIONS
 Retired instructions.
 Be careful, these can be affected by various
-issues, most notably hardware interrupt counts
+issues, most notably hardware interrupt counts.
 .TP
 .B PERF_COUNT_HW_CACHE_REFERENCES
 Cache accesses.
@@ -411,13 +409,13 @@ Mispredicted branch instructions.
 .B PERF_COUNT_HW_BUS_CYCLES
 Bus cycles, which can be different from total cycles.
 .TP
-.BR PERF_COUNT_HW_STALLED_CYCLES_FRONTEND " (Since Linux 3.0)"
+.BR PERF_COUNT_HW_STALLED_CYCLES_FRONTEND " (since Linux 3.0)"
 Stalled cycles during issue.
 .TP
-.BR PERF_COUNT_HW_STALLED_CYCLES_BACKEND  " (Since Linux 3.0)"
+.BR PERF_COUNT_HW_STALLED_CYCLES_BACKEND  " (since Linux 3.0)"
 Stalled cycles during retirement.
 .TP
-.BR PERF_COUNT_HW_REF_CPU_CYCLES  " (Since Linux 3.3)"
+.BR PERF_COUNT_HW_REF_CPU_CYCLES  " (since Linux 3.3)"
 Total cycles; not affected by CPU frequency scaling.
 .RE
 .IP
@@ -457,17 +455,24 @@ These did not require disk I/O to handle.
 This counts the number of major page faults.
 These required disk I/O to handle.
 .TP
-.BR PERF_COUNT_SW_ALIGNMENT_FAULTS " (Since Linux 2.6.33)"
+.BR PERF_COUNT_SW_ALIGNMENT_FAULTS " (since Linux 2.6.33)"
 This counts the number of alignment faults.
 These happen when unaligned memory accesses happen; the kernel
 can handle these but it reduces performance.
-This only happens on some architectures (never on x86).
+This happens only on some architectures (never on x86).
 .TP
-.BR PERF_COUNT_SW_EMULATION_FAULTS " (Since Linux 2.6.33)"
+.BR PERF_COUNT_SW_EMULATION_FAULTS " (since Linux 2.6.33)"
 This counts the number of emulation faults.
 The kernel sometimes traps on unimplemented instructions
 and emulates them for user space.
 This can negatively impact performance.
+.TP
+.BR PERF_COUNT_SW_DUMMY " (since Linux 3.12)"
+This is a placeholder event that counts nothing.
+Informational sample record types such as mmap or comm
+must be associated with an active event.
+This dummy event allows gathering such records without requiring
+a counting event.
 .RE
 
 .RS
@@ -522,7 +527,7 @@ for measuring the Instruction TLB
 .B PERF_COUNT_HW_CACHE_BPU
 for measuring the branch prediction unit
 .TP
-.BR PERF_COUNT_HW_CACHE_NODE " (Since Linux 3.0)"
+.BR PERF_COUNT_HW_CACHE_NODE " (since Linux 3.0)"
 for measuring local memory accesses
 .RE
 .P
@@ -594,7 +599,7 @@ field controls what data is recorded on each interrupt.
 
 .I sample_freq
 can be used if you wish to use frequency rather than period.
-In this case you set the
+In this case, you set the
 .I freq
 flag.
 The kernel will adjust the sampling period
@@ -647,21 +652,81 @@ Records a unique ID for the opened event.
 Unlike
 .B PERF_SAMPLE_ID
 the actual ID is returned, not the group leader.
-This ID is the same as the one returned by PERF_FORMAT_ID.
+This ID is the same as the one returned by
+.BR PERF_FORMAT_ID .
 .TP
 .B PERF_SAMPLE_RAW
 Records additional data, if applicable.
 Usually returned by tracepoint events.
 .TP
-.BR PERF_SAMPLE_BRANCH_STACK " (Since Linux 3.4)"
-Records the branch stack.
-See branch_sample_type.
-.TP
-.BR PERF_SAMPLE_REGS_USER " (Since Linux 3.7)"
-Records the current register state.
-.TP
-.BR PERF_SAMPLE_STACK_USER " (Since Linux 3.7)"
-[To be documented]
+.BR PERF_SAMPLE_BRANCH_STACK " (since Linux 3.4)"
+This provides a record of recent branches, as provided
+by CPU branch sampling hardware (such as Intel Last Branch Record).
+Not all hardware supports this feature.
+
+See the
+.I branch_sample_type
+field for how to filter which branches are reported.
+.TP
+.BR PERF_SAMPLE_REGS_USER " (since Linux 3.7)"
+Records the current user-level CPU register state
+(the values in the process before the kernel was called).
+.TP
+.BR PERF_SAMPLE_STACK_USER " (since Linux 3.7)"
+Records the user level stack, allowing stack unwinding.
+.TP
+.BR PERF_SAMPLE_WEIGHT " (since Linux 3.10)"
+Records a hardware provided weight value that expresses how
+costly the sampled event was.
+This allows the hardware to highlight expensive events in
+a profile.
+.TP
+.BR PERF_SAMPLE_DATA_SRC " (since Linux 3.10)"
+Records the data source: where in the memory hierarchy
+the data associated with the sampled instruction came from.
+This is only available if the underlying hardware
+supports this feature.
+.TP
+.BR PERF_SAMPLE_IDENTIFIER " (since Linux 3.12)"
+Places the
+.B SAMPLE_ID
+value in a fixed position in the record,
+either at the beginning (for sample events) or at the end
+(if a non-sample event).
+
+This was necessary because a sample stream may have
+records from various different event sources with different
+.I sample_type
+settings.
+Parsing the event stream properly was not possible because the
+format of the record was needed to find
+.BR SAMPLE_ID ,
+but
+the format could not be found without knowing what
+event the sample belonged to (causing a circular
+dependency).
+
+This new
+.B PERF_SAMPLE_IDENTIFIER
+setting makes the event stream always parsable
+by putting
+.B SAMPLE_ID
+in a fixed location, even though
+it means having duplicate
+.B SAMPLE_ID
+values in records.
+.TP
+.BR PERF_SAMPLE_TRANSACTION " (Since Linux 3.13)"
+Records reasons for transactional memory abort events
+(for example, from Intel TSX transactional memory support).
+
+The
+.I precise_ip
+setting must be greater than 0 and a transactional memory abort
+event must be measured or no values will be recorded.
+Also note that some perf_event measurements, such as sampled
+cycle counting, may cause extraneous aborts (by causing an
+interrupt during a transaction).
 .RE
 .TP
 .IR "read_format"
@@ -702,13 +767,24 @@ If disabled, the event can later be enabled by
 .BR prctl (2),
 or
 .IR enable_on_exec .
+
+When creating an event group, typically the group leader is initialized
+with
+.I disabled
+set to 1 and any child events are initialized with
+.I disabled
+set to 0.
+Despite
+.I disabled
+being 0, the child events will not start until the group leader
+is enabled.
 .TP
 .IR "inherit"
 The
 .I inherit
 bit specifies that this counter should count events of child
 tasks as well as the task specified.
-This only applies to new children, not to any existing children at
+This applies only to new children, not to any existing children at
 the time the counter is created (nor to any new children of
 existing children).
 
@@ -722,7 +798,7 @@ The
 .I pinned
 bit specifies that the counter should always be on the CPU if at all
 possible.
-It only applies to hardware counters and only to group leaders.
+It applies only to hardware counters and only to group leaders.
 If a pinned counter cannot be put onto the CPU (e.g., because there are
 not enough hardware counters or because of a conflict with some other
 event), then the counter goes into an 'error' state, where reads
@@ -738,6 +814,13 @@ it should be the only group using the CPU's counters.
 In the future this may allow monitoring programs to
 support PMU features that need to run alone so that they do not
 disrupt other hardware counters.
+
+Note that many unexpected situations may prevent events with the
+.I exclusive
+bit set from ever running.
+This includes any users running a system-wide
+measurement as well as any kernel use of the performance counters
+(including the commonly enabled NMI Watchdog Timer interface).
 .TP
 .IR "exclude_user"
 If this bit is set, the count excludes events that happen in user space.
@@ -759,15 +842,24 @@ If set, don't count when the CPU is idle.
 .IR "mmap"
 The
 .I mmap
-bit enables recording of exec mmap events.
+bit enables generation of
+.B PERF_RECORD_MMAP
+samples for every
+.BR mmap (2)
+call that has
+.B PROT_EXEC
+set.
+This allows tools to notice new executable code being mapped into
+a program (dynamic shared libraries for example)
+so that addresses can be mapped back to the original code.
 .TP
 .IR "comm"
 The
 .I comm
 bit enables tracking of process command name as modified by the
-.IR exec (2)
+.BR exec (2)
 and
-.IR prctl (PR_SET_NAME)
+.BR prctl (PR_SET_NAME)
 system calls.
 Unfortunately for tools,
 there is no way to distinguish one system call versus the other.
@@ -782,7 +874,7 @@ is used when setting up the sampling interval.
 .IR "inherit_stat"
 This bit enables saving of event counts on context switch for
 inherited tasks.
-This is only meaningful if the
+This is meaningful only if the
 .I inherit
 field is set.
 .TP
@@ -803,7 +895,7 @@ Otherwise interrupts happen after
 .I wakeup_events
 samples.
 .TP
-.IR "precise_ip" " (Since Linux 2.6.35)"
+.IR "precise_ip" " (since Linux 2.6.35)"
 This controls the amount of skid.
 Skid is how many instructions
 execute between an event of interest happening and the kernel
@@ -818,15 +910,15 @@ The values of this are the following:
 .TP
 0 -
 .B SAMPLE_IP
-can have arbitrary skid
+can have arbitrary skid.
 .TP
 1 -
 .B SAMPLE_IP
-must have constant skid
+must have constant skid.
 .TP
 2 -
 .B SAMPLE_IP
-requested to have 0 skid
+requested to have 0 skid.
 .TP
 3 -
 .B SAMPLE_IP
@@ -835,30 +927,57 @@ See also
 .BR PERF_RECORD_MISC_EXACT_IP .
 .RE
 .TP
-.IR "mmap_data" " (Since Linux 2.6.36)"
+.IR "mmap_data" " (since Linux 2.6.36)"
 The counterpart of the
 .I mmap
-field, but enables including data mmap events
-in the ring-buffer.
+field.
+This enables generation of
+.B PERF_RECORD_MMAP
+samples for
+.BR mmap (2)
+calls that do not have
+.B PROT_EXEC
+set (for example data and SysV shared memory).
 .TP
-.IR "sample_id_all" " (Since Linux 2.6.38)"
-If set, then TID, TIME, ID, CPU, and STREAM_ID can
+.IR "sample_id_all" " (since Linux 2.6.38)"
+If set, then TID, TIME, ID, STREAM_ID, and CPU can
 additionally be included in
 .RB non- PERF_RECORD_SAMPLE s
 if the corresponding
 .I sample_type
 is selected.
+
+If
+.B PERF_SAMPLE_IDENTIFIER
+is specified, then an additional ID value is included
+as the last value to ease parsing the record stream.
+This may lead to the
+.I id
+value appearing twice.
+
+The layout is described by this pseudo-structure:
+.in +4n
+.nf
+struct sample_id {
+    { u32 pid, tid; } /* if PERF_SAMPLE_TID set        */
+    { u64 time;     } /* if PERF_SAMPLE_TIME set       */
+    { u64 id;       } /* if PERF_SAMPLE_ID set         */
+    { u64 stream_id;} /* if PERF_SAMPLE_STREAM_ID set  */
+    { u32 cpu, res; } /* if PERF_SAMPLE_CPU set        */
+    { u64 id;       } /* if PERF_SAMPLE_IDENTIFIER set */
+};
+.fi
 .TP
-.IR "exclude_host" " (Since Linux 3.2)"
-Do not measure time spent in VM host
+.IR "exclude_host" " (since Linux 3.2)"
+Do not measure time spent in VM host.
 .TP
-.IR "exclude_guest" " (Since Linux 3.2)"
-Do not measure time spent in VM guest
+.IR "exclude_guest" " (since Linux 3.2)"
+Do not measure time spent in VM guest.
 .TP
-.IR "exclude_callchain_kernel" " (Since Linux 3.7)"
+.IR "exclude_callchain_kernel" " (since Linux 3.7)"
 Do not include kernel callchains.
 .TP
-.IR "exclude_callchain_user" " (Since Linux 3.7)"
+.IR "exclude_callchain_user" " (since Linux 3.7)"
 Do not include user callchains.
 .TP
 .IR "wakeup_events" ", " "wakeup_watermark"
@@ -870,26 +989,36 @@ happen before an overflow signal happens.
 Which one is used is selected by the
 .I watermark
 bitflag.
+
+.I wakeup_events
+only counts
+.B PERF_RECORD_SAMPLE
+record types.
+To  receive a signal for every incoming
+.B PERF_RECORD
+type set
+.I wakeup_watermark
+to 1.
 .TP
-.IR "bp_type" " (Since Linux 2.6.33)"
+.IR "bp_type" " (since Linux 2.6.33)"
 This chooses the breakpoint type.
 It is one of:
 .RS
 .TP
 .BR HW_BREAKPOINT_EMPTY
-no breakpoint
+No breakpoint.
 .TP
 .BR HW_BREAKPOINT_R
-count when we read the memory location
+Count when we read the memory location.
 .TP
 .BR HW_BREAKPOINT_W
-count when we write the memory location
+Count when we write the memory location.
 .TP
 .BR HW_BREAKPOINT_RW
-count when we read or write the memory location
+Count when we read or write the memory location.
 .TP
 .BR HW_BREAKPOINT_X
-count when we execute code at the memory location
+Count when we execute code at the memory location.
 .LP
 The values can be combined via a bitwise or, but the
 combination of
@@ -901,21 +1030,21 @@ with
 is not allowed.
 .RE
 .TP
-.IR "bp_addr" " (Since Linux 2.6.33)"
+.IR "bp_addr" " (since Linux 2.6.33)"
 .I bp_addr
 address of the breakpoint.
 For execution breakpoints this is the memory address of the instruction
 of interest; for read and write breakpoints it is the memory address
 of the memory location of interest.
 .TP
-.IR "config1" " (Since Linux 2.6.39)"
+.IR "config1" " (since Linux 2.6.39)"
 .I config1
 is used for setting events that need an extra register or otherwise
 do not fit in the regular config field.
 Raw OFFCORE_EVENTS on Nehalem/Westmere/SandyBridge use this field
 on 3.3 and later kernels.
 .TP
-.IR "bp_len" " (Since Linux 2.6.33)"
+.IR "bp_len" " (since Linux 2.6.33)"
 .I bp_len
 is the length of the breakpoint being measured if
 .I type
@@ -929,51 +1058,76 @@ Options are
 For an execution breakpoint, set this to
 .IR sizeof(long) .
 .TP
-.IR "config2" " (Since Linux 2.6.39)"
+.IR "config2" " (since Linux 2.6.39)"
 
 .I config2
 is a further extension of the
 .I config1
 field.
 .TP
-.IR "branch_sample_type" " (Since Linux 3.4)"
-This is used with the CPUs hardware branch sampling, if available.
-It can have one of the following values:
+.IR "branch_sample_type" " (since Linux 3.4)"
+If
+.B PERF_SAMPLE_BRANCH_STACK
+is enabled, then this specifies what branches to include
+in the branch record.
+
+The first part of the value is the privilege level, which
+is a combination of one of the following values.
+If the user does not set privilege level explicitly, the kernel
+will use the event's privilege level.
+Event and branch privilege levels do not have to match.
 .RS
 .TP
 .B PERF_SAMPLE_BRANCH_USER
-Branch target is in user space
+Branch target is in user space.
 .TP
 .B PERF_SAMPLE_BRANCH_KERNEL
-Branch target is in kernel space
+Branch target is in kernel space.
 .TP
 .B PERF_SAMPLE_BRANCH_HV
-Branch target is in hypervisor
+Branch target is in hypervisor.
+.TP
+.B PERF_SAMPLE_BRANCH_PLM_ALL
+A convenience value that is the three preceding values ORed together.
+
+.P
+In addition to the privilege value, at least one or more of the
+following bits must be set.
+
 .TP
 .B PERF_SAMPLE_BRANCH_ANY
 Any branch type.
 .TP
 .B PERF_SAMPLE_BRANCH_ANY_CALL
-Any call branch
+Any call branch.
 .TP
 .B PERF_SAMPLE_BRANCH_ANY_RETURN
-Any return branch
+Any return branch.
+.TP
+.B PERF_SAMPLE_BRANCH_IND_CALL
+Indirect calls.
+.TP
+.BR PERF_SAMPLE_BRANCH_ABORT_TX " (since Linux 3.11)"
+Transactional memory aborts.
 .TP
-.BR PERF_SAMPLE_BRANCH_IND_CALL
-Indirect calls
+.BR PERF_SAMPLE_BRANCH_IN_TX " (since Linux 3.11)"
+Branch in transactional memory transaction.
 .TP
-.BR PERF_SAMPLE_BRANCH_PLM_ALL
-User, kernel, and hv
+.BR PERF_SAMPLE_BRANCH_NO_TX " (since Linux 3.11)"
+Branch not in transactional memory transaction.
 .RE
+
 .TP
-.IR "sample_regs_user" " (Since Linux 3.7)"
-This defines the set of user registers to dump on samples.
-See
-.\" FIXME: The following reference seems to be not quite right:
-.IR asm/perf_regs.h .
+.IR "sample_regs_user" " (since Linux 3.7)"
+This bit mask defines the set of user CPU registers to dump on samples.
+The layout of the register mask is architecture-specific and
+described in the kernel header
+.IR arch/ARCH/include/uapi/asm/perf_regs.h .
 .TP
-.IR "sample_stack_user" " (Since Linux 3.7)"
-This defines the size of the user stack to dump on samples.
+.IR "sample_stack_user" " (since Linux 3.7)"
+This defines the size of the user stack to dump if
+.B PERF_SAMPLE_STACK_USER
+is specified.
 .SS Reading results
 Once a
 .BR perf_event_open ()
@@ -1038,10 +1192,10 @@ was specified.
 .IR time_enabled ", " time_running
 Total time the event was enabled and running.
 Normally these are the same.
-If more events are started
-than available counter slots on the PMU, then multiplexing
-happens and events only run part of the time.
-In that case the
+If more events are started,
+then available counter slots on the PMU, then multiplexing
+happens and events run only part of the time.
+In that case, the
 .I time_enabled
 and
 .I time running
@@ -1080,30 +1234,35 @@ The structure of the first metadata mmap page is as follows:
 .in +4n
 .nf
 struct perf_event_mmap_page {
-    __u32 version;          /* version number of this structure */
-    __u32 compat_version;   /* lowest version this is compat with */
-    __u32 lock;             /* seqlock for synchronization */
-    __u32 index;            /* hardware counter identifier */
-    __s64 offset;           /* add to hardware counter value */
-    __u64 time_enabled;     /* time event active */
-    __u64 time_running;     /* time event on CPU */
+    __u32 version;        /* version number of this structure */
+    __u32 compat_version; /* lowest version this is compat with */
+    __u32 lock;           /* seqlock for synchronization */
+    __u32 index;          /* hardware counter identifier */
+    __s64 offset;         /* add to hardware counter value */
+    __u64 time_enabled;   /* time event active */
+    __u64 time_running;   /* time event on CPU */
     union {
         __u64   capabilities;
-        __u64   cap_usr_time  : 1,
-                cap_usr_rdpmc : 1,
+        struct {
+            __u64 cap_usr_time / cap_usr_rdpmc / cap_bit0 : 1,
+                  cap_bit0_is_deprecated : 1,
+                  cap_user_rdpmc         : 1,
+                  cap_user_time          : 1,
+                  cap_user_time_zero     : 1,
+        };
     };
-    __u16   pmc_width;
-    __u16   time_shift;
-    __u32   time_mult;
-    __u64   time_offset;
-    __u64   __reserved[120];   /* Pad to 1k */
-    __u64   data_head;         /* head in the data section */
-    __u64   data_tail;         /* user-space written tail */
+    __u16 pmc_width;
+    __u16 time_shift;
+    __u32 time_mult;
+    __u64 time_offset;
+    __u64 __reserved[120];   /* Pad to 1k */
+    __u64 data_head;         /* head in the data section */
+    __u64 data_tail;         /* user-space written tail */
 }
 .fi
 .in
 
-The following looks at the fields in the
+The following list describes the fields in the
 .I perf_event_mmap_page
 structure in more detail:
 .TP
@@ -1120,8 +1279,9 @@ A seqlock for synchronization.
 A unique hardware counter identifier.
 .TP
 .I offset
-.\" FIXME clarify
-Add this to hardware counter value??
+When using rdpmc for reads this offset value
+must be added to the one returned by rdpmc to get
+the current total event count.
 .TP
 .I time_enabled
 Time the event was active.
@@ -1129,10 +1289,45 @@ Time the event was active.
 .I time_running
 Time the event was running.
 .TP
+.IR cap_usr_time " / " cap_usr_rdpmc " / " cap_bit0 " (since Linux 3.4)"
+There was a bug in the definition of
 .I cap_usr_time
-User time capability
+and
+.I cap_usr_rdpmc
+from Linux 3.4 until Linux 3.11.
+Both bits were defined to point to the same location, so it was
+impossible to know if
+.I cap_usr_time
+or
+.I cap_usr_rdpmc
+were actually set.
+
+Starting with 3.12 these are renamed to
+.I cap_bit0
+and you should use the new
+.I cap_user_time
+and
+.I cap_user_rdpmc
+fields instead.
+
 .TP
+.IR cap_bit0_is_deprecated " (since Linux 3.12)"
+If set, this bit indicates that the kernel supports
+the properly separated
+.I cap_user_time
+and
+.I cap_user_rdpmc
+bits.
+
+If not-set, it indicates an older kernel where
+.I cap_usr_time
+and
 .I cap_usr_rdpmc
+map to the same bit and thus both features should
+be used with caution.
+
+.TP
+.IR cap_user_rdpmc " (since Linux 3.12)"
 If the hardware supports user-space read of performance counters
 without syscall (this is the "rdpmc" instruction on x86), then
 the following code can be used to do a read:
@@ -1142,7 +1337,6 @@ the following code can be used to do a read:
 u32 seq, time_mult, time_shift, idx, width;
 u64 count, enabled, running;
 u64 cyc, time_offset;
-s64 pmc = 0;
 
 do {
     seq = pc\->lock;
@@ -1162,7 +1356,7 @@ do {
 
     if (pc\->cap_usr_rdpmc && idx) {
         width = pc\->pmc_width;
-        pmc = rdpmc(idx \- 1);
+        count += rdpmc(idx \- 1);
     }
 
     barrier();
@@ -1170,6 +1364,16 @@ do {
 .fi
 .in
 .TP
+.I cap_user_time " (since Linux 3.12)"
+This bit indicates the hardware has a constant, nonstop
+timestamp counter (TSC on x86).
+.TP
+.IR cap_user_time_zero " (since Linux 3.12)"
+Indicates the presence of
+.I time_zero
+which allows mapping timestamp values to
+the hardware clock.
+.TP
 .I pmc_width
 If
 .IR cap_usr_rdpmc ,
@@ -1221,22 +1425,48 @@ enabled and possible running (if idx), improving the scaling:
     count = quot * enabled + (rem * enabled) / running;
 .fi
 .TP
+.IR time_zero " (since Linux 3.12)"
+
+If
+.I cap_usr_time_zero
+is set, then the hardware clock (the TSC timestamp counter on x86)
+can be calculated from the
+.IR time_zero ", " time_mult ", and " time_shift " values:"
+
+.nf
+    time = timestamp - time_zero;
+    quot = time / time_mult;
+    rem  = time % time_mult;
+    cyc = (quot << time_shift) + (rem << time_shift) / time_mult;
+.fi
+
+And vice versa:
+
+.nf
+    quot = cyc >> time_shift;
+    rem  = cyc & ((1 << time_shift) - 1);
+    timestamp = time_zero + quot * time_mult +
+        ((rem * time_mult) >> time_shift);
+.fi
+.TP
 .I data_head
 This points to the head of the data section.
 The value continuously increases, it does not wrap.
 The value needs to be manually wrapped by the size of the mmap buffer
 before accessing the samples.
 
-On SMP-capable platforms, after reading the data_head value,
+On SMP-capable platforms, after reading the
+.I data_head
+value,
 user space should issue an rmb().
 .TP
-.I data_tail;
+.I data_tail
 When the mapping is
 .BR PROT_WRITE ,
 the
 .I data_tail
 value should be written by user space to reflect the last read data.
-In this case the kernel will not over-write unread data.
+In this case, the kernel will not overwrite unread data.
 .PP
 The following 2^n ring-buffer pages have the layout described below.
 
@@ -1249,7 +1479,7 @@ an event took place (TID, TIME, ID, CPU, STREAM_ID) described in
 below, it will be stashed just after the
 .I perf_event_header
 and the fields already present for the existing
-fields, i.e., at the end of the payload.
+fields, that  is, at the end of the payload.
 That way a newer perf.data
 file will be supported by older perf tools, with these new optional
 fields being ignored.
@@ -1269,6 +1499,60 @@ struct perf_event_header {
 Below, we describe the
 .I perf_event_header
 fields in more detail.
+For ease of reading,
+the fields with shorter descriptions are presented first.
+.TP
+.I size
+This indicates the size of the record.
+.TP
+.I misc
+The
+.I misc
+field contains additional information about the sample.
+
+The CPU mode can be determined from this value by masking with
+.B PERF_RECORD_MISC_CPUMODE_MASK
+and looking for one of the following (note these are not
+bit masks, only one can be set at a time):
+.RS
+.TP
+.B PERF_RECORD_MISC_CPUMODE_UNKNOWN
+Unknown CPU mode.
+.TP
+.B PERF_RECORD_MISC_KERNEL
+Sample happened in the kernel.
+.TP
+.B PERF_RECORD_MISC_USER
+Sample happened in user code.
+.TP
+.B PERF_RECORD_MISC_HYPERVISOR
+Sample happened in the hypervisor.
+.TP
+.B PERF_RECORD_MISC_GUEST_KERNEL
+Sample happened in the guest kernel.
+.TP
+.B PERF_RECORD_MISC_GUEST_USER
+Sample happened in guest user code.
+.RE
+
+.RS
+In addition, one of the following bits can be set:
+.TP
+.B PERF_RECORD_MISC_MMAP_DATA
+This is set when the mapping is not executable;
+otherwise the mapping is executable.
+.TP
+.B PERF_RECORD_MISC_EXACT_IP
+This indicates that the content of
+.B PERF_SAMPLE_IP
+points
+to the actual instruction that triggered the event.
+See also
+.IR perf_event_attr.precise_ip .
+.TP
+.B PERF_RECORD_MISC_EXT_RESERVED
+This indicates there is extended data available (currently not used).
+.RE
 .TP
 .I type
 The
@@ -1278,6 +1562,7 @@ The values in the corresponding record (that follows the header)
 depend on the
 .I type
 selected as shown.
+
 .RS
 .TP 4
 .B PERF_RECORD_MMAP
@@ -1309,6 +1594,7 @@ struct {
     struct perf_event_header header;
     u64 id;
     u64 lost;
+    struct sample_id sample_id;
 };
 .fi
 .in
@@ -1330,6 +1616,7 @@ struct {
     struct perf_event_header header;
     u32 pid, tid;
     char comm[];
+    struct sample_id sample_id;
 };
 .fi
 .in
@@ -1344,6 +1631,7 @@ struct {
     u32 pid, ppid;
     u32 tid, ptid;
     u64 time;
+    struct sample_id sample_id;
 };
 .fi
 .in
@@ -1358,6 +1646,7 @@ struct {
     u64 time;
     u64 id;
     u64 stream_id;
+    struct sample_id sample_id;
 };
 .fi
 .in
@@ -1372,6 +1661,7 @@ struct {
     u32 pid, ppid;
     u32 tid, ptid;
     u64 time;
+    struct sample_id sample_id;
 };
 .fi
 .in
@@ -1385,6 +1675,7 @@ struct {
     struct perf_event_header header;
     u32 pid, tid;
     struct read_format values;
+    struct sample_id sample_id;
 };
 .fi
 .in
@@ -1396,6 +1687,7 @@ This record indicates a sample.
 .nf
 struct {
     struct perf_event_header header;
+    u64   sample_id;  /* if PERF_SAMPLE_IDENTIFIER */
     u64   ip;         /* if PERF_SAMPLE_IP */
     u32   pid, tid;   /* if PERF_SAMPLE_TID */
     u64   time;       /* if PERF_SAMPLE_TIME */
@@ -1418,9 +1710,22 @@ struct {
     u64   size;       /* if PERF_SAMPLE_STACK_USER */
     char  data[size]; /* if PERF_SAMPLE_STACK_USER */
     u64   dyn_size;   /* if PERF_SAMPLE_STACK_USER */
+    u64   weight;     /* if PERF_SAMPLE_WEIGHT */
+    u64   data_src;   /* if PERF_SAMPLE_DATA_SRC */
+    u64   transaction;/* if PERF_SAMPLE_TRANSACTION */
 };
 .fi
-.RS
+.RS 4
+.TP 4
+.I sample_id
+If
+.B PERF_SAMPLE_IDENTIFIER
+is enabled, a 64-bit unique ID is included.
+This is a duplication of the
+.B PERF_SAMPLE_ID
+.I id
+value, but included at the beginning of the sample
+so parsers can easily obtain the value.
 .TP
 .I ip
 If
@@ -1518,76 +1823,274 @@ is enabled, then a 64-bit value indicating
 the number of records is included, followed by
 .I bnr
 .I perf_branch_entry
-structures.
-These structures have from, to, and flags values indicating
-the from and to addresses from the branches on the callstack.
+structures which each include the fields:
+.RS
+.TP
+.I from
+This indicates the source instruction (may not be a branch).
+.TP
+.I to
+The branch target.
+.TP
+.I mispred
+The branch target was mispredicted.
+.TP
+.I predicted
+The branch target was predicted.
+.TP
+.IR in_tx " (since Linux 3.11)"
+The branch was in a transactional memory transaction.
+.TP
+.IR abort " (since Linux 3.11)"
+The branch was in an aborted transactional memory transaction.
+
+.P
+The entries are from most to least recent, so the first entry
+has the most recent branch.
+
+Support for
+.I mispred
+and
+.I predicted
+is optional; if not supported, both
+values will be 0.
+
+The type of branches recorded is specified by the
+.I branch_sample_type
+field.
+.RE
+
 .TP
 .IR abi ", " regs[weight(mask)]
 If
 .B PERF_SAMPLE_REGS_USER
-is enabled, then
-[to be documented].
+is enabled, then the user CPU registers are recorded.
 
 The
 .I abi
 field is one of
 .BR PERF_SAMPLE_REGS_ABI_NONE ", " PERF_SAMPLE_REGS_ABI_32 " or "
 .BR PERF_SAMPLE_REGS_ABI_64 .
+
+The
+.I regs
+field is an array of the CPU registers that were specified by
+the
+.I sample_regs_user
+attr field.
+The number of values is the number of bits set in the
+.I sample_regs_user
+bit mask.
 .TP
 .IR size ", " data[size] ", " dyn_size
 If
 .B PERF_SAMPLE_STACK_USER
-is enabled, then
-[to be documented].
+is enabled, then record the user stack to enable backtracing.
+.I size
+is the size requested by the user in
+.I stack_user_size
+or else the maximum record size.
+.I data
+is the stack data.
+.I dyn_size
+is the amount of data actually dumped (can be less than
+.IR size ).
+.TP
+.I weight
+If
+.B PERF_SAMPLE_WEIGHT
+is enabled, then a 64-bit value provided by the hardware
+is recorded that indicates how costly the event was.
+This allows expensive events to stand out more clearly
+in profiles.
+.TP
+.I data_src
+If
+.B PERF_SAMPLE_DATA_SRC
+is enabled, then a 64-bit value is recorded that is made up of
+the following fields:
+.RS
+.TP 4
+.I mem_op
+Type of opcode, a bitwise combination of:
+
+.PD 0
+.RS
+.TP 24
+.B PERF_MEM_OP_NA
+Not available
+.TP
+.B PERF_MEM_OP_LOAD
+Load instruction
+.TP
+.B PERF_MEM_OP_STORE
+Store instruction
+.TP
+.B PERF_MEM_OP_PFETCH
+Prefetch
+.TP
+.B PERF_MEM_OP_EXEC
+Executable code
 .RE
+.PD
+.TP
+.I mem_lvl
+Memory hierarchy level hit or miss, a bitwise combination of:
+
+.PD 0
+.RS
+.TP 24
+.B PERF_MEM_LVL_NA
+Not available
+.TP
+.B PERF_MEM_LVL_HIT
+Hit
+.TP
+.B PERF_MEM_LVL_MISS
+Miss
+.TP
+.B PERF_MEM_LVL_L1
+Level 1 cache
+.TP
+.B PERF_MEM_LVL_LFB
+Line fill buffer
+.TP
+.B PERF_MEM_LVL_L2
+Level 2 cache
+.TP
+.B PERF_MEM_LVL_L3
+Level 3 cache
+.TP
+.B PERF_MEM_LVL_LOC_RAM
+Local DRAM
+.TP
+.B PERF_MEM_LVL_REM_RAM1
+Remote DRAM 1 hop
+.TP
+.B PERF_MEM_LVL_REM_RAM2
+Remote DRAM 2 hops
+.TP
+.B PERF_MEM_LVL_REM_CCE1
+Remote cache 1 hop
+.TP
+.B PERF_MEM_LVL_REM_CCE2
+Remote cache 2 hops
+.TP
+.B PERF_MEM_LVL_IO
+I/O memory
+.TP
+.B PERF_MEM_LVL_UNC
+Uncached memory
 .RE
+.PD
 .TP
-.I misc
-The
-.I misc
-field contains additional information about the sample.
+.I mem_snoop
+Snoop mode, a bitwise combination of:
 
-The CPU mode can be determined from this value by masking with
-.B PERF_RECORD_MISC_CPUMODE_MASK
-and looking for one of the following (note these are not
-bit masks, only one can be set at a time):
+.PD 0
 .RS
+.TP 24
+.B PERF_MEM_SNOOP_NA
+Not available
 .TP
-.B PERF_RECORD_MISC_CPUMODE_UNKNOWN
-Unknown CPU mode.
+.B PERF_MEM_SNOOP_NONE
+No snoop
 .TP
-.B PERF_RECORD_MISC_KERNEL
-Sample happened in the kernel.
+.B PERF_MEM_SNOOP_HIT
+Snoop hit
 .TP
-.B PERF_RECORD_MISC_USER
-Sample happened in user code.
+.B PERF_MEM_SNOOP_MISS
+Snoop miss
 .TP
-.B PERF_RECORD_MISC_HYPERVISOR
-Sample happened in the hypervisor.
+.B PERF_MEM_SNOOP_HITM
+Snoop hit modified
+.RE
+.PD
 .TP
-.B PERF_RECORD_MISC_GUEST_KERNEL
-Sample happened in the guest kernel.
+.I mem_lock
+Lock instruction, a bitwise combination of:
+
+.PD 0
+.RS
+.TP 24
+.B PERF_MEM_LOCK_NA
+Not available
 .TP
-.B PERF_RECORD_MISC_GUEST_USER
-Sample happened in guest user code.
+.B PERF_MEM_LOCK_LOCKED
+Locked transaction
 .RE
+.PD
+.TP
+.I mem_dtlb
+TLB access hit or miss, a bitwise combination of:
 
-In addition, one of the following bits can be set:
+.PD 0
 .RS
+.TP 24
+.B PERF_MEM_TLB_NA
+Not available
 .TP
-.B PERF_RECORD_MISC_EXACT_IP
-This indicates that the content of
-.B PERF_SAMPLE_IP
-points
-to the actual instruction that triggered the event.
-See also
-.IR perf_event_attr.precise_ip .
+.B PERF_MEM_TLB_HIT
+Hit
 .TP
-.B PERF_RECORD_MISC_EXT_RESERVED
-This indicates there is extended data available (currently not used).
+.B PERF_MEM_TLB_MISS
+Miss
 .TP
-.I size
-This indicates the size of the record.
+.B PERF_MEM_TLB_L1
+Level 1 TLB
+.TP
+.B PERF_MEM_TLB_L2
+Level 2 TLB
+.TP
+.B PERF_MEM_TLB_WK
+Hardware walker
+.TP
+.B PERF_MEM_TLB_OS
+OS fault handler
+.RE
+.PD
+.RE
+.TP
+.I transaction
+If the
+.B PERF_SAMPLE_TRANSACTION
+flag is set, then a 64-bit field is recorded describing
+the sources of any transactional memory aborts.
+
+The field is a bitwise combination of the following values:
+.RS
+.TP
+.B PERF_TXN_ELISION
+Abort from an elision type transaction (Intel-CPU-specific).
+.TP
+.B PERF_TXN_TRANSACTION
+Abort from a generic transaction.
+.TP
+.B PERF_TXN_SYNC
+Synchronous abort (related to the reported instruction).
+.TP
+.B PERF_TXN_ASYNC
+Asynchronous abort (not related to the reported instruction).
+.TP
+.B PERF_TXN_RETRY
+Retryable abort (retrying the transaction may have succeeded).
+.TP
+.B PERF_TXN_CONFLICT
+Abort due to memory conflicts with other threads.
+.TP
+.B PERF_TXN_CAPACITY_WRITE
+Abort due to write capacity overflow.
+.TP
+.B PERF_TXN_CAPACITY_READ
+Abort due to read capacity overflow.
+.RE
+.IP
+In addition, a user-specified abort code can be obtained from
+the high 32 bits of the field by shifting right by
+.B PERF_TXN_ABORT_SHIFT
+and masking with
+.BR PERF_TXN_ABORT_MASK .
+.RE
 .RE
 .SS Signal overflow
 Events can be set to deliver a signal when a threshold is crossed.
@@ -1601,7 +2104,7 @@ system calls.
 
 To generate signals, sampling must be enabled
 .RI ( sample_period
-must have a non-zero value).
+must have a nonzero value).
 
 There are two ways to generate signals.
 
@@ -1611,7 +2114,7 @@ or
 .I wakeup_watermark
 value that will generate a signal if a certain number of samples
 or bytes have been written to the mmap ring buffer.
-In this case a signal of type
+In this case, a signal of type
 .B POLL_IN
 is sent.
 
@@ -1619,7 +2122,7 @@ The other way is by use of the
 .B PERF_EVENT_IOC_REFRESH
 ioctl.
 This ioctl adds to a counter that decrements each time the event overflows.
-When non-zero, a
+When nonzero, a
 .B POLL_IN
 signal is sent on overflow, but
 once the value reaches 0, a signal is sent of type
@@ -1648,26 +2151,34 @@ to calculate event values can be found in that section.
 .PP
 Various ioctls act on
 .BR perf_event_open ()
-file descriptors
+file descriptors:
 .TP
 .B PERF_EVENT_IOC_ENABLE
-Enables the individual event or event group specified by the
+This enables the individual event or event group specified by the
 file descriptor argument.
 
-The ioctl argument is ignored.
+If the
+.B PERF_IOC_FLAG_GROUP
+bit is set in the ioctl argument, then all events in a group are
+enabled, even if the event specified is not the group leader
+(but see BUGS).
 .TP
 .B PERF_EVENT_IOC_DISABLE
-Disables the individual counter or event group specified by the
+This disables the individual counter or event group specified by the
 file descriptor argument.
 
 Enabling or disabling the leader of a group enables or disables the
 entire group; that is, while the group leader is disabled, none of the
 counters in the group will count.
-Enabling or disabling a member of a group other than the leader only
-affects that counter; disabling a non-leader
+Enabling or disabling a member of a group other than the leader
+affects only that counter; disabling a non-leader
 stops that counter from counting but doesn't affect any other counter.
 
-The ioctl argument is ignored.
+If the
+.B PERF_IOC_FLAG_GROUP
+bit is set in the ioctl argument, then all events in a group are
+disabled, even if the event specified is not the group leader
+(but see BUGS).
 .TP
 .B PERF_EVENT_IOC_REFRESH
 Non-inherited overflow counters can use this
@@ -1685,24 +2196,34 @@ Using an argument of 0 is considered undefined behavior.
 .TP
 .B PERF_EVENT_IOC_RESET
 Reset the event count specified by the
-file descriptor argumentto zero.
-This only resets the counts; there is no way to reset the
+file descriptor argument to zero.
+This resets only the counts; there is no way to reset the
 multiplexing
 .I time_enabled
 or
 .I time_running
 values.
-When sent to a group leader, only
-the leader is reset (child events are not).
 
-The ioctl argument is ignored.
+If the
+.B PERF_IOC_FLAG_GROUP
+bit is set in the ioctl argument, then all events in a group are
+reset, even if the event specified is not the group leader
+(but see BUGS).
 .TP
 .B PERF_EVENT_IOC_PERIOD
-IOC_PERIOD is the command to update the period; it
-does not update the current period but instead defers until next.
+This updates the overflow period for the event.
+
+Since Linux 3.7 (on ARM) and Linux 3.14 (all other architectures),
+the new period takes effect immediately.
+On older kernels, the new period did not take effect until
+after the next overflow.
 
 The argument is a pointer to a 64-bit value containing the
 desired new period.
+
+Prior to Linux 2.6.36 this ioctl always failed due to a bug
+in the kernel.
+
 .TP
 .B PERF_EVENT_IOC_SET_OUTPUT
 This tells the kernel to report event notifications to the specified
@@ -1712,10 +2233,16 @@ The file descriptors must all be on the same CPU.
 The argument specifies the desired file descriptor, or \-1 if
 output should be ignored.
 .TP
-.BR PERF_EVENT_IOC_SET_FILTER " (Since Linux 2.6.33)"
+.BR PERF_EVENT_IOC_SET_FILTER " (since Linux 2.6.33)"
 This adds an ftrace filter to this event.
 
 The argument is a pointer to the desired ftrace filter.
+.TP
+.BR PERF_EVENT_IOC_ID " (since Linux 3.12)"
+This returns the event ID value for the given event file descriptor.
+
+The argument is a pointer to a 64-bit unsigned integer
+to hold the result.
 .SS Using prctl
 A process can enable or disable all the event groups that are
 attached to it using the
@@ -1724,10 +2251,10 @@ attached to it using the
 and
 .B PR_TASK_PERF_EVENTS_DISABLE
 operations.
-This applies to all counters on the current process, whether created by
+This applies to all counters on the calling process, whether created by
 this process or by another, and does not affect any counters that this
 process has created on other processes.
-It only enables or disables
+It enables or disables only
 the group leaders, not any other members in the groups.
 .SS perf_event related configuration files
 Files in
@@ -1739,15 +2266,17 @@ Files in
 The
 .I perf_event_paranoid
 file can be set to restrict access to the performance counters.
-
-2 - only allow user-space measurements
-
-1 - (default) allow both kernel and user measurements
-
-0 - allow access to CPU-specific data but not raw tracepoint samples
-
-\-1 - no restrictions
-
+.RS
+.IP 2 4
+only allow user-space measurements.
+.IP 1
+allow both kernel and user measurements (default).
+.IP 0
+allow access to CPU-specific data but not raw tracepoint samples.
+.IP \-1
+no restrictions.
+.RE
+.IP
 The existence of the
 .I perf_event_paranoid
 file is the official method for determining if a kernel supports
@@ -1764,42 +2293,80 @@ The default value is
 .TP
 .I /proc/sys/kernel/perf_event_mlock_kb
 
-Maximum number of pages an unprivileged user can mlock (2) .
+Maximum number of pages an unprivileged user can
+.BR mlock (2).
 The default is 516 (kB).
+
 .RE
 Files in
 .I /sys/bus/event_source/devices/
 .RS 4
-Since Linux 2.6.34 the kernel supports having multiple PMUs
+Since Linux 2.6.34, the kernel supports having multiple PMUs
 available for monitoring.
 Information on how to program these PMUs can be found under
 .IR /sys/bus/event_source/devices/ .
 Each subdirectory corresponds to a different PMU.
 .TP
-.I /sys/bus/event_source/devices/*/type
+.IR /sys/bus/event_source/devices/*/type " (since Linux 2.6.38)"
 This contains an integer that can be used in the
 .I type
-field of perf_event_attr to indicate you wish to use this PMU.
+field of
+.I perf_event_attr
+to indicate that you wish to use this PMU.
 .TP
-.I /sys/bus/event_source/devices/*/rdpmc
-[To be documented]
+.IR /sys/bus/event_source/devices/*/rdpmc " (since Linux 3.4)"
+If this file is 1, then direct user-space access to the
+performance counter registers is allowed via the rdpmc instruction.
+This can be disabled by echoing 0 to the file.
 .TP
-.I /sys/bus/event_source/devices/*/format/
-This sub-directory contains information on what bits in the
+.IR /sys/bus/event_source/devices/*/format/ " (since Linux 3.4)"
+This subdirectory contains information on the architecture-specific
+subfields available for programming the various
 .I config
-field of perf_event_attr correspond to.
+fields in the
+.I perf_event_attr
+struct.
+
+The content of each file is the name of the config field, followed
+by a colon, followed by a series of integer bit ranges separated by
+commas.
+For example, the file
+.I event
+may contain the value
+.I config1:1,6-10,44
+which indicates that event is an attribute that occupies bits 1,6-10, and 44
+of
+.IR perf_event_attr::config1 .
 .TP
-.I /sys/bus/event_source/devices/*/events/
-This sub-directory contains files with pre-defined events.
+.IR /sys/bus/event_source/devices/*/events/ " (since Linux 3.4)"
+This subdirectory contains files with predefined events.
 The contents are strings describing the event settings
-expressed in terms of the fields found in the
+expressed in terms of the fields found in the previously mentioned
 .I ./format/
 directory.
 These are not necessarily complete lists of all events supported by
 a PMU, but usually a subset of events deemed useful or interesting.
+
+The content of each file is a list of attribute names
+separated by commas.
+Each entry has an optional value (either hex or decimal).
+If no value is specified, then it is assumed to be a single-bit
+field with a value of 1.
+An example entry may look like this:
+.IR event=0x2,inv,ldlat=3 .
 .TP
 .I /sys/bus/event_source/devices/*/uevent
-[To be documented]
+This file is the standard kernel device interface
+for injecting hotplug events.
+.TP
+.IR /sys/bus/event_source/devices/*/cpumask " (since Linux 3.7)"
+The
+.I cpumask
+file contains a comma-separated list of integers that
+indicate a representative CPU number for each socket (package)
+on the motherboard.
+This is needed when setting up uncore or northbridge events, as
+those PMUs present socket-wide events.
 .RE
 .SH RETURN VALUE
 .BR perf_event_open ()
@@ -1808,23 +2375,143 @@ returns the new file descriptor, or \-1 if an error occurred
 .I errno
 is set appropriately).
 .SH ERRORS
+The errors returned by
+.BR perf_event_open ()
+can be inconsistent, and may
+vary across processor architectures and performance monitoring units.
+.TP
+.B E2BIG
+Returned if the
+.I perf_event_attr
+.I size
+value is too small
+(smaller than
+.BR PERF_ATTR_SIZE_VER0 ),
+too big (larger than the page size),
+or larger than the kernel supports and the extra bytes are not zero.
+When
+.B E2BIG
+is returned, the
+.I perf_event_attr
+.I size
+field is overwritten by the kernel to be the size of the structure
+it was expecting.
+.TP
+.B EACCES
+Returned when the requested event requires
+.B CAP_SYS_ADMIN
+permissions (or a more permissive perf_event paranoid setting).
+Some common cases where an unprivileged process
+may encounter this error:
+attaching to a process owned by a different user;
+monitoring all processes on a given CPU (i.e., specifying the
+.I pid
+argument as \-1);
+and not setting
+.I exclude_kernel
+when the paranoid setting requires it.
+.TP
+.B EBADF
+Returned if the
+.I group_fd
+file descriptor is not valid, or, if
+.B PERF_FLAG_PID_CGROUP
+is set,
+the cgroup file descriptor in
+.I pid
+is not valid.
+.TP
+.B EFAULT
+Returned if the
+.I attr
+pointer points at an invalid memory address.
 .TP
 .B EINVAL
-Returned if the specified event is not available.
+Returned if the specified event is invalid.
+There are many possible reasons for this.
+A not-exhaustive list:
+.I sample_freq
+is higher than the maximum setting;
+the
+.I cpu
+to monitor does not exist;
+.I read_format
+is out of range;
+.I sample_type
+is out of range;
+the
+.I flags
+value is out of range;
+.I exclusive
+or
+.I pinned
+set and the event is not a group leader;
+the event
+.I config
+values are out of range or set reserved bits;
+the generic event selected is not supported; or
+there is not enough room to add the selected event.
+.TP
+.B EMFILE
+Each opened event uses one file descriptor.
+If a large number of events are opened the per-user file
+descriptor limit (often 1024) will be hit and no more
+events can be created.
+.TP
+.B ENODEV
+Returned when the event involves a feature not supported
+by the current CPU.
+.TP
+.B ENOENT
+Returned if the
+.I type
+setting is not valid.
+This error is also returned for
+some unsupported generic events.
 .TP
 .B ENOSPC
 Prior to Linux 3.3, if there was not enough room for the event,
 .B ENOSPC
 was returned.
-Linus did not like this, and this was changed to
+In Linux 3.3, this was changed to
 .BR EINVAL .
 .B ENOSPC
-is still returned if you try to read results into
-too small of a buffer.
+is still returned if you try to add more breakpoint events
+than supported by the hardware.
+.TP
+.B ENOSYS
+Returned if
+.B PERF_SAMPLE_STACK_USER
+is set in
+.I sample_type
+and it is not supported by hardware.
+.TP
+.B EOPNOTSUPP
+Returned if an event requiring a specific hardware feature is
+requested but there is no hardware support.
+This includes requesting low-skid events if not supported,
+branch tracing if it is not available, sampling if no PMU
+interrupt is available, and branch stacks for software events.
+.TP
+.B EPERM
+Returned on many (but not all) architectures when an unsupported
+.IR exclude_hv ", " exclude_idle ", " exclude_user ", or " exclude_kernel
+setting is specified.
+
+It can also happen, as with
+.BR EACCES ,
+when the requested event requires
+.B CAP_SYS_ADMIN
+permissions (or a more permissive perf_event paranoid setting).
+This includes setting a breakpoint on a kernel address,
+and (since Linux 3.13) setting a kernel function-trace tracepoint.
+.TP
+.B ESRCH
+Returned if attempting to attach to a process that does not exist.
 .SH VERSION
 .BR perf_event_open ()
 was introduced in Linux 2.6.31 but was called
-.BR perf_counter_open () .
+.BR perf_counter_open ().
 It was renamed in Linux 2.6.32.
 .SH CONFORMING TO
 This
@@ -1849,7 +2536,7 @@ option to
 is needed to properly get overflow signals in threads.
 This was introduced in Linux 2.6.32.
 
-Prior to Linux 2.6.33 (at least for x86) the kernel did not check
+Prior to Linux 2.6.33 (at least for x86), the kernel did not check
 if events could be scheduled together until read time.
 The same happens on all known kernels if the NMI watchdog is enabled.
 This means to see if a given set of events works you have to
@@ -1857,11 +2544,11 @@ This means to see if a given set of events works you have to
 start, then read before you know for sure you
 can get valid measurements.
 
-Prior to Linux 2.6.34 event constraints were not enforced by the kernel.
+Prior to Linux 2.6.34, event constraints were not enforced by the kernel.
 In that case, some events would silently return "0" if the kernel
 scheduled them in an improper counter slot.
 
-Prior to Linux 2.6.34 there was a bug when multiplexing where the
+Prior to Linux 2.6.34, there was a bug when multiplexing where the
 wrong results could be returned.
 
 Kernels from Linux 2.6.35 to Linux 2.6.39 can quickly crash the kernel if
@@ -1880,7 +2567,24 @@ There is a bug in the kernel code between
 Linux 2.6.36 and Linux 3.0 that ignores the
 "watermark" field and acts as if a wakeup_event
 was chosen if the union has a
-non-zero value in it.
+nonzero value in it.
+
+From Linux 2.6.31 to Linux 3.4, the
+.B PERF_IOC_FLAG_GROUP
+ioctl argument was broken and would repeatedly operate
+on the event specified rather than iterating across
+all sibling events in a group.
+
+From Linux 3.4 to Linux 3.11, the mmap
+.I cap_usr_rdpmc
+and
+.I cap_usr_time
+bits mapped to the same location.
+Code should migrate to the new
+.I cap_user_rdpmc
+and
+.I cap_user_time
+fields instead.
 
 Always double-check your results!
 Various generalized events have had wrong values.
@@ -1900,7 +2604,7 @@ instruction count of a call to
 #include <linux/perf_event.h>
 #include <asm/unistd.h>
 
-long
+static long
 perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
                 int cpu, int group_fd, unsigned long flags)
 {
@@ -1951,3 +2655,11 @@ main(int argc, char **argv)
 .BR open (2),
 .BR prctl (2),
 .BR read (2)
+.SH COLOPHON
+This page is part of release 3.65 of the Linux
+.I man-pages
+project.
+A description of the project,
+and information about reporting bugs,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.