mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
cpumf/pai: Add Processor Activity Instrumentation tool
The Processor Activity Instrumentation facility (PAI) uses the perf_event_open system call to report data and the crypto counter values. The data can be inspected with the perf tool in a very generic way using raw data report and a hex dump utility. The pai tool also uses the perf_event_open system call to record the data, but uses specialized event attributes for recording detailed information such as the recording of fork, exit, exec system call events and context switch events. Cryptography counter values are appended as raw data attachments. The pai command can be used for recording and reporting. Also a list of CPUs can be specified. The recording ring buffers are created per CPU and are named paicrypto.XXX where XXX stands for the CPU number. The numbering scheme has leading zeros, such as 007 for CPU number 7. For invocation and possible command line options see the man page. Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
a58460b5c7
commit
d7b1cbad8b
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,6 +22,7 @@ cpacfstats/cpacfstatsd
|
||||
cpumf/chcpumf
|
||||
cpumf/lscpumf
|
||||
cpumf/lshwc
|
||||
cpumf/pai
|
||||
cpuplugd/cpuplugd
|
||||
dasdfmt/dasdfmt
|
||||
dasdinfo/dasdinfo
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
include ../common.mak
|
||||
|
||||
BIN_FILES = lscpumf chcpumf lshwc
|
||||
MAN_FILES = lscpumf.1 chcpumf.8 lshwc.1
|
||||
BIN_FILES = lscpumf chcpumf lshwc pai
|
||||
MAN_FILES = lscpumf.1 chcpumf.8 lshwc.1 pai.1
|
||||
|
||||
all: $(BIN_FILES)
|
||||
|
||||
libs = $(rootdir)/libutil/libutil.a $(rootdir)/libcpumf/libcpumf.a
|
||||
libs = $(rootdir)/libcpumf/libcpumf.a $(rootdir)/libutil/libutil.a
|
||||
|
||||
lscpumf: lscpumf.o $(libs)
|
||||
chcpumf: chcpumf.o $(libs)
|
||||
lshwc: lshwc.o $(libs)
|
||||
pai: pai.o $(libs)
|
||||
|
||||
install: all install-man
|
||||
$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man8
|
||||
|
||||
224
cpumf/man/pai.1
Normal file
224
cpumf/man/pai.1
Normal file
@@ -0,0 +1,224 @@
|
||||
.\" pai.1
|
||||
.\"
|
||||
.\"
|
||||
.\" Copyright IBM Corp. 2022
|
||||
.\" s390-tools is free software; you can redistribute it and/or modify
|
||||
.\" it under the terms of the MIT license. See LICENSE for details.
|
||||
.\" ----------------------------------------------------------------------
|
||||
.ds c \fBpai\fP
|
||||
.
|
||||
.TH \*c "1" "May 2022" "s390-tools" "PAI Management Programs"
|
||||
.
|
||||
.SH NAME
|
||||
\*c \- record and report Processor Activity Instrumentation (PAI) counters
|
||||
.
|
||||
.SH SYNOPSIS
|
||||
\*c
|
||||
.RB [ \-V ][ \-m | \-\-mapsize
|
||||
.IR size ]
|
||||
.RB [ \-i | \-\-interval
|
||||
.IR ms ]
|
||||
.BR \-c | \-\-crypto [ \fIcpulist ][: \fIdata\fR "] [" \fIloops\fP ]
|
||||
.br
|
||||
\*c
|
||||
.RB [ \-V ][ \-H | \-\-humantime ][ \-S | \-\-summary "] " \-r | \-\-report " [" \fIfiles\fP ]
|
||||
.br
|
||||
\*c
|
||||
.BR \-h | \-\-help
|
||||
.br
|
||||
\*c
|
||||
.BR \-v | \-\-version
|
||||
.
|
||||
.
|
||||
.SH DESCRIPTION
|
||||
\*c
|
||||
counters tally calls for specific CPU instructions.
|
||||
The \*c command records PAI counters in a ring buffer.
|
||||
\*c can record counter data for all CPUs or for selected CPUs.
|
||||
The main command options are
|
||||
.B \-c
|
||||
for recording cryptographic CPU instructions and
|
||||
.B \-r
|
||||
for reporting.
|
||||
If both options are omitted, option
|
||||
.B \-r
|
||||
is assumed and a message is printed.
|
||||
Recording stores data, by CPU, in files
|
||||
.I paicrypto.<X>,
|
||||
where <X> specifies the CPU number.
|
||||
The files are created in the working directory,
|
||||
existing files are overwritten.
|
||||
Reporting evaluates files that are created by recording.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BR \-c ", " \-\-crypto "\fR[\fIcpulist\fR][:\fIdata\fR]"
|
||||
Records data for all (default) or a specified list of CPUs.
|
||||
The CPU list is a comma-separated list of CPU numbers and ranges.
|
||||
In a range, a hyphen separates the first CPU number
|
||||
from the last CPU number.
|
||||
By default \*c lists all CPUs.
|
||||
.RS
|
||||
The optional data specification
|
||||
follows the colon
|
||||
and determines additional collection of data.
|
||||
The specification consists of alphabetic
|
||||
characters that can be upper or lower case:
|
||||
.IP c|C
|
||||
Include task rename system calls
|
||||
.B exec
|
||||
and
|
||||
.BR prctl .
|
||||
.IP f|F
|
||||
Include task creation and deletion system calls
|
||||
.B fork
|
||||
and
|
||||
.BR exit .
|
||||
.IP s|S
|
||||
Include context switch records created by the kernel scheduler.
|
||||
.IP k|K
|
||||
Include only PAI cryptographic counters changed during system call
|
||||
execution.
|
||||
.IP u|U
|
||||
Include only PAI cryptographic counters changed during user space
|
||||
execution.
|
||||
.RE
|
||||
.
|
||||
.TP
|
||||
.BR \-r ", " \-\-report
|
||||
Generates a report from the specified files.
|
||||
Files is a list of blank-separated file names.
|
||||
If no files are specified,
|
||||
uses all files named
|
||||
.I paicrypto.<X>,
|
||||
in the working directory, where
|
||||
.I <X>
|
||||
is a CPU number that
|
||||
identifies the CPU for which the data was recorded.
|
||||
.
|
||||
.TP
|
||||
.BR \-h ", " \-\-help
|
||||
Displays help information, then exits.
|
||||
.
|
||||
.TP
|
||||
.BR \-v ", " \-\-version
|
||||
Displays version information, then exits.
|
||||
.
|
||||
.TP
|
||||
.BR \-V ", " \-\-verbose
|
||||
Displays the following information during reporting:
|
||||
the file name and the hexadecimal offset for each sample header.
|
||||
Displays the following information during recording:
|
||||
the read position in the ring buffer,
|
||||
the file name, and the hexadecimal offset for each sample header.
|
||||
.
|
||||
.TP
|
||||
.BR \-H ", " \-\-humantime
|
||||
Changes the time stamp format for sample entries from a hexadecimal
|
||||
number to a human readable <seconds>.<nanoseconds> format.
|
||||
The time stamp specifies the elapsed time since Linux was booted.
|
||||
.
|
||||
.TP
|
||||
.BR \-S ", " \-\-summary
|
||||
Prints a summary of counter names and
|
||||
counter numbers with non-zero values.
|
||||
The summary is the last line in the command output.
|
||||
It shows the sum of the counter values of all processed files.
|
||||
.
|
||||
.TP
|
||||
.BR \-i ", " \-\-interval "\ ms"
|
||||
Specifies the waiting time,
|
||||
in milliseconds,
|
||||
between ring buffer read operations during recording.
|
||||
The default is 1000 milliseconds.
|
||||
Argument
|
||||
.B loops
|
||||
is an integer that specifies the number of
|
||||
read operations during recording. The default is 1.
|
||||
.
|
||||
.TP
|
||||
.BR \-m ", " \-\-mapsize "\ size"
|
||||
Specifies the size of the ring buffer
|
||||
that holds the collected data.
|
||||
The value specifies the number of 4 KB pages
|
||||
to be allocated and must be a power of 2.
|
||||
The default size is 512 pages.
|
||||
The ring buffer is created with the
|
||||
.IR mmap (2)
|
||||
system call.
|
||||
.
|
||||
.SH ARGUMENT
|
||||
The command line options determine how command line
|
||||
arguments are interpreted.
|
||||
For option
|
||||
.B \-c
|
||||
to start recording, the argument specifies
|
||||
the number of read operations.
|
||||
If omitted, the default is one.
|
||||
For option
|
||||
.B \-r
|
||||
to start reporting, the argument specifies
|
||||
the file names to be read.
|
||||
If omitted all files in the current directory
|
||||
with file name
|
||||
.I paicryto.<X>
|
||||
are read.
|
||||
.SH "Concurrency with perf tool"
|
||||
The following concurrency restrictions apply
|
||||
for \*c and the
|
||||
.B perf
|
||||
tool.
|
||||
Both tools use the
|
||||
.IR perf_event_open ()
|
||||
system call and use the same device driver.
|
||||
The device driver supports limited concurrency:
|
||||
.IP Counting:
|
||||
Counting pai events can run in parallel.
|
||||
.IP Sampling:
|
||||
Only one sampling event pai_crypto/CRYPTO_ALL can be active at any one time.
|
||||
If a sampling event is active, no pai counting event can be active.
|
||||
Both tools stop with an error message if they detect a collision
|
||||
reported by the device driver.
|
||||
.SH "EXAMPLES"
|
||||
This example collects cryptographic counter on CPU 0.
|
||||
The program runs for 10 seconds
|
||||
(10 intervals of 1000 milliseconds).
|
||||
.sp 1
|
||||
.nf
|
||||
.ft CW
|
||||
# \*c -c0 10
|
||||
.ft R
|
||||
.fi
|
||||
.sp 1
|
||||
This example displays the data
|
||||
that is collected in the first example.
|
||||
Each data line shows the time stamp in jiffies,
|
||||
followed by the CPU number,
|
||||
the event number,
|
||||
process and thread identifier (pid/tid) separated by slash (/),
|
||||
and a comma-separated list of counter number, colon (:),
|
||||
and the counter value n hexadecimal notation.
|
||||
.sp 1
|
||||
.nf
|
||||
.ft CW
|
||||
# \*c -r
|
||||
0x62a668f2fa 0 event 4096 sample pid 4956/4956 9:0xa7,73:0x8,74:0x18
|
||||
0x6319c75653 0 event 4096 sample pid 4972/4972 32:0x1
|
||||
0x6319e2ddee 0 event 4096 sample pid 4972/4972 32:0x1
|
||||
0x631d3e44f5 0 event 4096 sample pid 4972/4972 32:0x2
|
||||
0x631d4cfc2e 0 event 4096 sample pid 4972/4972 32:0x3
|
||||
0x631d529fdd 0 event 4096 sample pid 4972/4972 32:0x2
|
||||
0x631d84cfa0 0 event 4096 sample pid 4972/4972 73:0x1
|
||||
0x636e9826bc 0 event 4096 sample pid 4984/4984 9:0xa7,73:0x8,74:0x18
|
||||
0x636f81a137 0 event 4096 sample pid 4984/4984 9:0x2,74:0x7
|
||||
0x6378026e54 0 event 4096 sample pid 4984/4984 73:0x2
|
||||
0x637bcdc8da 0 event 4096 sample pid 4984/4984 73:0x2
|
||||
0x637bd426cd 0 event 4096 sample pid 4984/4984 73:0x6
|
||||
0x637c503384 0 event 4096 sample pid 4984/4984 73:0x2
|
||||
0x64991d83ba 0 event 4096 sample pid 5026/5026 9:0xb0,73:0x8,74:0x18
|
||||
#
|
||||
.ft R
|
||||
.fi
|
||||
.sp 1
|
||||
.SH "SEE ALSO"
|
||||
perf(1)
|
||||
1091
cpumf/pai.c
Normal file
1091
cpumf/pai.c
Normal file
File diff suppressed because it is too large
Load Diff
105
cpumf/pai.h
Normal file
105
cpumf/pai.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* pai - Extract CPU Processor Activity Instrumentation (PAI) facility data.
|
||||
*
|
||||
* Copyright IBM Corp. 2022
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef PAI_H
|
||||
#define PAI_H
|
||||
|
||||
#define S390_EVT_PAI_CRYPTO 0x1000
|
||||
|
||||
enum { /* Event attribute specifications */
|
||||
S390_EVTATTR_CTX_SWITCH = 1,
|
||||
S390_EVTATTR_COMM = 2,
|
||||
S390_EVTATTR_FORK = 4,
|
||||
S390_EVTATTR_USERSPACE = 8,
|
||||
S390_EVTATTR_KERNELSPACE = 16
|
||||
};
|
||||
|
||||
struct pai_event {
|
||||
struct util_list_node node; /* List node */
|
||||
struct perf_event_attr attr; /* Perf_event_open(2) attr */
|
||||
int fd; /* Perf event file descriptor */
|
||||
void *map_addr; /* Sampling data mapping address */
|
||||
size_t map_size; /* Sampling size mapping size */
|
||||
char file_name[16]; /* File name of sampled data */
|
||||
int file_fd; /* Map data output file descriptor */
|
||||
int cpu; /* Perf_event_open(2) CPU */
|
||||
unsigned long flags; /* Perf_event_open(2) flags */
|
||||
};
|
||||
|
||||
struct pai_event_out { /* Output for CRYPTO_ALL event */
|
||||
__u32 type; /* Header type, see PERF_RECORD_xxx */
|
||||
__u16 misc; /* Header misc, value depends on type */
|
||||
__u64 time; /* Time stamp valid for all entries */
|
||||
__u32 cpu; /* CPU number valid for all entries */
|
||||
union {
|
||||
/* Fields from PERF_RECORD_FORK|EXIT */
|
||||
struct {
|
||||
__u32 pid, ppid;
|
||||
__u32 tid, ptid;
|
||||
__u64 time;
|
||||
} s_fork;
|
||||
/* Fields from PERF_RECORD_COMM */
|
||||
struct {
|
||||
__u32 pid, tid;
|
||||
__u8 cmd[16];
|
||||
} s_comm;
|
||||
/* Fields from PERF_RECORD_SWITCH_CPU_WIDE */
|
||||
struct {
|
||||
__u32 next_prev_pid, next_prev_tid;
|
||||
} s_cs;
|
||||
/* Fields from PERF_RECORD_LOST_SAMPLES */
|
||||
struct {
|
||||
__u64 lost;
|
||||
} s_lost;
|
||||
/* Relevant fields from PERF_RECORD_SAMPLE, time and cpu
|
||||
* are stored above
|
||||
*/
|
||||
struct {
|
||||
__u64 ip;
|
||||
__u64 period;
|
||||
__u32 pid, tid;
|
||||
} s_sample;
|
||||
/* Fields from PERF_RECORD_[UN]THROTTLE */
|
||||
struct {
|
||||
__u64 time;
|
||||
__u64 id;
|
||||
__u64 stream_id;
|
||||
} s_throttle;
|
||||
} u;
|
||||
/* Information on last context switch out */
|
||||
struct cs_switch {
|
||||
unsigned char valid;
|
||||
__u32 topid, totid;
|
||||
__u32 frompid, fromtid;
|
||||
} cs_switch;
|
||||
void *raw; /* Pointer to key/value array for crypto counters */
|
||||
};
|
||||
|
||||
struct data_pos { /* Perf event mapped ring buffer */
|
||||
__u64 data_head; /* Head in the data section */
|
||||
__u64 data_tail; /* User-space written tail */
|
||||
__u64 data_offset; /* Where the buffer starts */
|
||||
__u64 data_size; /* Data buffer size */
|
||||
};
|
||||
|
||||
struct event_name { /* Event list for number to name xlate */
|
||||
char *name; /* Event name */
|
||||
__u64 config; /* Event config value */
|
||||
__u64 total; /* Total counter value */
|
||||
};
|
||||
|
||||
struct pmu_events { /* Event list for PMU number to name xlate */
|
||||
struct util_list_node node; /* List node */
|
||||
char *name; /* PMU name */
|
||||
int type; /* PMU type */
|
||||
int lstlen; /* # of entries in lst */
|
||||
unsigned long base; /* Base event number */
|
||||
struct event_name *lst; /* List of event names */
|
||||
};
|
||||
#endif /* PAI_H */
|
||||
Reference in New Issue
Block a user