Introduce threaded trace streaming for basic perf record operation
v12 cover Introduce threaded trace streaming for basic perf record operation
Changes in v12:
- fixed nr_threads=1 cases
- fixed "Woken up %ld times" message
- removed unnecessary record__fini_thread_masks function
- moved bytes written/compressed statistics to struct record_thread
- moved all unnecessary debug messages to verbose=2 level
- renamed "socket" option to "package" for consistency with util/cputopo.h
- excluded single trace file reading patches
v11: https://lore.kernel.org/lkml/[email protected]/
Changes in v11:
- removed python dependency on zstd (perf test 19)
- captured tags from Riccardo Mancini
v10: https://lore.kernel.org/lkml/[email protected]/
Changes in v10:
- renamed fdarray__clone to fdarray__dup_entry_from
- captured Acked-by: tags by Namhyung Kim for 09/24
v9: https://lore.kernel.org/lkml/[email protected]/
Changes in v9:
- fixes in [v9 01/24]:
- move 'nr_threads' to before 'thread_masks'
- combined decl+assign into one line in record__thread_mask_alloc
- releasing masks inplace in record__alloc_thread_masks
- split patch [v8 02/22] to [v9 02/24] and [v9 03/24]
- fixes in [v9 03/24]:
- renamed 'struct thread_data' to 'struct record_thread'
- moved nr_mmaps after ctlfd_pos
- releasing resources inplace in record__thread_data_init_maps
- initializing pipes by -1 value
- added temporary gettid() wrapper
- split patch [v8 03/22] to [v9 04/24] and [v9 05/24]
- removed upstreamed [v8 09/22]
- split [v8 10/22] to [v9 12/24] and [v9 13/24]
- moved --threads documentation to the related patches
- fixed output of written/compressed stats in [v9 10/24]
- split patch [v8 12/22] to [v9 15/24] and [v9 16/24]
- fixed order of error checking for decompressed events in [v9 16/24]
- merged patch [v8 21/22] with [v9 23/24] and [v9 24/24]
- moved patch [v8 22/22] to [v9 09/24]
- added max reader size constant in [v9 24/24]
v8: https://lore.kernel.org/lkml/[email protected]/
Changes in v8:
- captured Acked-by: tags by Namhyung Kim
- merged with origin/perf/core
- added patch 21/22 introducing READER_NODATA state
- added patch 22/22 fixing --max-size option
v7: https://lore.kernel.org/lkml/[email protected]/
Changes in v7:
- fixed possible crash after out_free_threads label
- added missing pthread_attr_destroy() call
- added check of correctness of user masks
- fixed zsts_data finalization
v6: https://lore.kernel.org/lkml/[email protected]/
Changes in v6:
- fixed leaks and possible double free in record__thread_mask_alloc()
- fixed leaks in record__init_thread_user_masks()
- fixed final mmaps flushing for threads id > 0
- merged with origin/perf/core
v5: https://lore.kernel.org/lkml/[email protected]/
Changes in v5:
- fixed leaks in record__init_thread_masks_spec()
- fixed leaks after failed realloc
- replaced "%m" to strerror()
- added masks examples to the documentation
- captured Acked-by: tags by Andi Kleen
- do not allow --thread option for full_auxtrace mode
- split patch 06/12 to 06/20 and 07/20
- split patch 08/12 to 09/20 and 10/20
- split patches 11/12 and 11/12 to 13/20-20/20
v4: https://lore.kernel.org/lkml/[email protected]/
Changes in v4:
- renamed 'comm' structure to 'pipes'
- moved thread fd/maps messages to verbose=2
- fixed leaks during allocation of thread_data structures
- fixed leaks during allocation of thread masks
- fixed possible fails when releasing thread masks
v3: https://lore.kernel.org/lkml/[email protected]/
Changes in v3:
- avoided skipped redundant patch 3/15
- applied "data file" and "data directory" terms allover the patch set
- captured Acked-by: tags by Namhyung Kim
- avoided braces where don't needed
- employed thread local variable for serial trace streaming
- added specs for --thread option - core, socket, numa and user defined
- added parallel loading of data directory files similar to the prototype [1]
v2: https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- explicitly added credit tags to patches 6/15 and 15/15, additionally to cites [1], [2]
- updated description of 3/15 to explicitly mention the reason to open data directories in read access mode (e.g. for perf report)
- implemented fix for compilation error of 2/15
- explicitly elaborated on found issues to be resolved for threaded AUX trace capture
v1: https://lore.kernel.org/lkml/[email protected]/
Patch set provides parallel threaded trace streaming mode for basic perf record operation. Provided mode mitigates profiling data losses and resolves scalability issues of serial and asynchronous (--aio) trace streaming modes on multicore server systems. The design and implementation are based on the prototype [1], [2].
Parallel threaded mode executes trace streaming threads that read kernel data buffers and write captured data into several data files located at data directory. Layout of trace streaming threads and their mapping to data buffers to read can be configured using a value of --thread command line option. Specification value provides masks separated by colon so the masks define cpus to be monitored by one thread and thread affinity mask is separated by slash. <cpus mask 1>/<affinity mask 1>:<cpu mask 2>/<affinity mask 2> specifies parallel threads layout that consists of two threads with corresponding assigned cpus to be monitored. Specification value can be a string e.g. "cpu", "core" or "socket" meaning creation of data streaming thread for monitoring every cpu, whole core or socket. The option provided with no or empty value defaults to "cpu" layout creating data streaming thread for every cpu being monitored. Specification masks are filtered by the mask provided via -C option.
Parallel streaming mode is compatible with Zstd compression/decompression (--compression-level) and external control commands (--control). The mode is not enabled for pipe mode. The mode is not enabled for AUX area tracing, related and derived modes like --snapshot or --aux-sample. --switch-output-* and --timestamp-filename options are not enabled for parallel streaming. Initial intent to enable AUX area tracing faced the need to define some optimal way to store index data in data directory. --switch-output-* and --timestamp-filename use cases are not clear for data directories. Asynchronous(--aio) trace streaming and affinity (--affinity) modes are mutually exclusive to parallel streaming mode.
Basic analysis of data directories is provided in perf report mode. Raw dump and aggregated reports are available for data directories, still with no memory consumption optimizations.
Tested:
tools/perf/perf record -o prof.data --threads -- matrix.gcc.g.O3tools/perf/perf record -o prof.data --threads= -- matrix.gcc.g.O3tools/perf/perf record -o prof.data --threads=cpu -- matrix.gcc.g.O3tools/perf/perf record -o prof.data --threads=core -- matrix.gcc.g.O3tools/perf/perf record -o prof.data --threads=socket -- matrix.gcc.g.O3tools/perf/perf record -o prof.data --threads=numa -- matrix.gcc.g.O3tools/perf/perf record -o prof.data --threads=0-3/3:4-7/4 -- matrix.gcc.g.O3tools/perf/perf record -o prof.data -C 2,5 --threads=0-3/3:4-7/4 -- matrix.gcc.g.O3 tools/perf/perf record -o prof.data -C 3,4 --threads=0-3/3:4-7/4 -- matrix.gcc.g.O3 tools/perf/perf record -o prof.data -C 0,4,2,6 --threads=core -- matrix.gcc.g.O3 tools/perf/perf record -o prof.data -C 0,4,2,6 --threads=numa -- matrix.gcc.g.O3 tools/perf/perf record -o prof.data --threads -g --call-graph dwarf,4096 -- matrix.gcc.g.O3 tools/perf/perf record -o prof.data --threads -g --call-graph dwarf,4096 --compression-level=3 -- matrix.gcc.g.O3 tools/perf/perf record -o prof.data --threads -atools/perf/perf record -D -1 -e cpu-cycles -a --control fd:10,11 -- sleep 30tools/perf/perf record --threads -D -1 -e cpu-cycles -a --control fd:10,11 -- sleep 30
tools/perf/perf report -i prof.data tools/perf/perf report -i prof.data --call-graph=callee tools/perf/perf report -i prof.data --stdio --header tools/perf/perf report -i prof.data -D --header
[1] git clone https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git -b perf/record_threads
[2] https://lore.kernel.org/lkml/[email protected]/
Alexey Bayduraev (16):
perf record: Introduce thread affinity and mmap masks tools lib: Introduce fdarray duplicate function
perf record: Introduce thread specific data array perf record: Introduce function to propagate control commands perf record: Introduce thread local variable
perf record: Stop threads in the end of trace streaming perf record: Start threads in the beginning of trace streaming perf record: Introduce data file at mmap buffer object perf record: Introduce bytes written stats
perf record: Introduce compressor at mmap buffer object perf record: Introduce data transferred and compressed stats perf record: Introduce --threads command line option perf record: Extend --threads command line option perf record: Implement compatibility checks
perf session: Load data directory files for analysis perf report: Output data file name in raw trace dump
tools/lib/api/fd/array.c | 17 + tools/lib/api/fd/array.h | 1 + tools/perf/Documentation/perf-record.txt | 30 + tools/perf/builtin-inject.c | 3 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-record.c | 1167 ++++++++++++++++++++-- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/evlist.c | 16 + tools/perf/util/evlist.h | 1 + tools/perf/util/mmap.c | 10 + tools/perf/util/mmap.h | 3 + tools/perf/util/ordered-events.c | 3 +- tools/perf/util/ordered-events.h | 3 +- tools/perf/util/record.h | 2 + tools/perf/util/session.c | 208 +++- tools/perf/util/session.h | 3 +- tools/perf/util/tool.h | 3 +- 18 files changed, 1370 insertions(+), 106 deletions(-)
Signature · 1 line
2.19.0
PATCH v12 1/16 perf record: Introduce thread affinity and mmap masks
Introduce affinity and mmap thread masks. Thread affinity mask defines cpus that a thread is allowed to run on. Thread maps mask defines mmap data buffers the thread serves to stream profiling data from.
--- tools/perf/builtin-record.c | 129 ++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+)
tools/perf/builtin-record.c +129 -0
@@ -87,6 +87,11 @@ struct switch_output {int cur_file; }; +struct thread_mask { +struct mmap_cpu_mask maps; +struct mmap_cpu_mask affinity; +}; +struct record {struct perf_tool tool;struct record_opts opts;
@@ -111,6 +116,8 @@ struct record {unsigned long long samples;struct mmap_cpu_mask affinity_mask;unsigned long output_max_size;/* = 0: unlimited */ +int nr_threads; +struct thread_mask *thread_masks; };static volatile int done;
@@ -2197,6 +2204,54 @@ static int record__parse_affinity(const struct option *opt, const char *str, intreturn 0 ; } +static int record__mmap_cpu_mask_alloc (struct mmap_cpu_mask *mask,int nr_bits) +{ + mask->nbits = nr_bits; + mask->bits =bitmap_zalloc (mask->nbits); +if (!mask->bits) { +pr_err ("Failed to allocate mmap_cpu mask\n" ); +return -ENOMEM ; + } + +return 0 ; +} + +static void record__mmap_cpu_mask_free (struct mmap_cpu_mask *mask) +{ +bitmap_free (mask->bits); + mask->nbits =0 ; +} + +static void record__thread_mask_clear (struct thread_mask *mask) +{ +bitmap_zero (mask->maps.bits, mask->maps.nbits); +bitmap_zero (mask->affinity.bits, mask->affinity.nbits); +} + +static int record__thread_mask_alloc (struct thread_mask *mask,int nr_bits) +{ +int ret =record__mmap_cpu_mask_alloc (&mask->maps, nr_bits); + +if (ret) { + mask->affinity.bits =NULL ; +return ret; + } + + ret =record__mmap_cpu_mask_alloc (&mask->affinity, nr_bits); +if (ret) { +record__mmap_cpu_mask_free (&mask->maps); + mask->maps.bits =NULL ; + } + +return ret; +} + +static void record__thread_mask_free (struct thread_mask *mask) +{ +record__mmap_cpu_mask_free (&mask->maps); +record__mmap_cpu_mask_free (&mask->affinity); +} +static int parse_output_max_size (const struct option *opt,const char *str,int unset) {
@@ -2668,6 +2723,72 @@ static struct option __record_options[] = {struct option *record_options = __record_options; +static void record__mmap_cpu_mask_init (struct mmap_cpu_mask *mask,struct perf_cpu_map *cpus) +{ +int c; + +for (c =0 ; c < cpus->nr; c++) +set_bit (cpus->map[c], mask->bits); +} + +static void record__free_thread_masks (struct record *rec,int nr_threads) +{ +int t; + +if (rec->thread_masks) +for (t =0 ; t < nr_threads; t++) +record__thread_mask_free (&rec->thread_masks[t]); + +zfree (&rec->thread_masks); +} + +static int record__alloc_thread_masks (struct record *rec,int nr_threads,int nr_bits) +{ +int t, ret; + + rec->thread_masks =zalloc (nr_threads *sizeof (*(rec->thread_masks))); +if (!rec->thread_masks) { +pr_err ("Failed to allocate thread masks\n" ); +return -ENOMEM ; + } + +for (t =0 ; t < nr_threads; t++) { + ret =record__thread_mask_alloc (&rec->thread_masks[t], nr_bits); +if (ret) + goto out_free; +record__thread_mask_clear (&rec->thread_masks[t]); + } + +return 0 ; + +out_free: +record__free_thread_masks (rec, nr_threads); + +return ret; +} + +static int record__init_thread_default_masks (struct record *rec,struct perf_cpu_map *cpus) +{ +int ret; + + ret =record__alloc_thread_masks (rec,1 ,cpu__max_cpu ()); +if (ret) +return ret; + +record__mmap_cpu_mask_init (&rec->thread_masks->maps, cpus); + + rec->nr_threads =1 ; + +return 0 ; +} + +static int record__init_thread_masks (struct record *rec) +{ +struct perf_cpu_map *cpus = rec->evlist->core.cpus; + +return record__init_thread_default_masks (rec, cpus); +} +int cmd_record (int argc,const char **argv) {int err;
@@ -2927,6 +3048,12 @@ int cmd_record(int argc, const char **argv) goto out; } + err =record__init_thread_masks (rec); +if (err) { +pr_err ("record__init_thread_masks failed, error %d\n" , err); + goto out; + } +if (rec->opts.nr_cblocks > nr_cblocks_max) rec->opts.nr_cblocks = nr_cblocks_max;pr_debug ("nr_cblocks: %d\n" , rec->opts.nr_cblocks);
@@ -2945,6 +3072,8 @@ int cmd_record(int argc, const char **argv)symbol__exit ();auxtrace_record__free (rec->itr); out_opts: +record__free_thread_masks (rec, rec->nr_threads); + rec->nr_threads =0 ;evlist__close_control (rec->opts.ctl_fd, rec->opts.ctl_fd_ack, &rec->opts.ctl_fd_close);return err; }
Signature · 1 line
2.19.0
Re: [PATCH v12 01/16] perf record: Introduce thread affinity and mmap masks
On Tue, Nov 23, 2021 at 05:07:57PM +0300, Alexey Bayduraev wrote:
SNIP
Quoted 24 lines
tools/perf/builtin-record.c +24
-0+static void record__mmap_cpu_mask_init (struct mmap_cpu_mask *mask,struct perf_cpu_map *cpus) +{ +int c; + +for (c =0 ; c < cpus->nr; c++) +set_bit (cpus->map[c], mask->bits); +} + +static void record__free_thread_masks (struct record *rec,int nr_threads) +{ +int t; + +if (rec->thread_masks) +for (t =0 ; t < nr_threads; t++) +record__thread_mask_free (&rec->thread_masks[t]); + +zfree (&rec->thread_masks); +} + +static int record__alloc_thread_masks (struct record *rec,int nr_threads,int nr_bits) +{ +int t, ret; + + rec->thread_masks =zalloc (nr_threads *sizeof (*(rec->thread_masks)));
tools/perf/builtin-record.c static struct option __record_options[] = { · line 2759
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+if (!rec->thread_masks) { +pr_err ("Failed to allocate thread masks\n" ); +return -ENOMEM ; + } + +for (t =0 ; t < nr_threads; t++) { + ret =record__thread_mask_alloc (&rec->thread_masks[t], nr_bits); +if (ret) + goto out_free; +record__thread_mask_clear (&rec->thread_masks[t]);
nit, is this clear needed?
jirka
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+ } + +return 0 ; + +out_free: +record__free_thread_masks (rec, nr_threads); + +return ret; +} +
SNIP
Re: [PATCH v12 01/16] perf record: Introduce thread affinity and mmap masks
Quoted 32 lines · Jiri Olsa
On Tue, Nov 23, 2021 at 05:07:57PM +0300, Alexey Bayduraev wrote:
SNIP
Quoted 28 lines
tools/perf/builtin-record.c +28
-0+static void record__mmap_cpu_mask_init (struct mmap_cpu_mask *mask,struct perf_cpu_map *cpus) +{ +int c; + +for (c =0 ; c < cpus->nr; c++) +set_bit (cpus->map[c], mask->bits); +} + +static void record__free_thread_masks (struct record *rec,int nr_threads) +{ +int t; + +if (rec->thread_masks) +for (t =0 ; t < nr_threads; t++) +record__thread_mask_free (&rec->thread_masks[t]); + +zfree (&rec->thread_masks); +} + +static int record__alloc_thread_masks (struct record *rec,int nr_threads,int nr_bits) +{ +int t, ret; + + rec->thread_masks =zalloc (nr_threads *sizeof (*(rec->thread_masks))); +if (!rec->thread_masks) { +pr_err ("Failed to allocate thread masks\n" ); +return -ENOMEM ; + }
Quoted 8 lines
tools/perf/builtin-record.c static struct option __record_options[] = { · line 2759
Quoted 6 lines
tools/perf/builtin-record.c +6
-0+ +for (t =0 ; t < nr_threads; t++) { + ret =record__thread_mask_alloc (&rec->thread_masks[t], nr_bits); +if (ret) + goto out_free; +record__thread_mask_clear (&rec->thread_masks[t]);nit, is this clear needed?
Hi,
You are right, since all elements of mask->bits is set to zero after bitmap_zalloc in record__thread_mask_alloc, calling record__thread_mask_clear after record__thread_mask_alloc is redundant.
I will remove it here and in [PATCH v12 13/16].
Thanks,
Alexey
Quoted 16 lines
jirka
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+ } + +return 0 ; + +out_free: +record__free_thread_masks (rec, nr_threads); + +return ret; +} +SNIP
PATCH v12 2/16 tools lib: Introduce fdarray duplicate function
In reply to Alexey BayduraevIntroduce a function to duplicate an existing file descriptor in the fdarray structure. The function returns the position of the duplicated file descriptor.
--- tools/lib/api/fd/array.c | 17 +++++++++++++++++ tools/lib/api/fd/array.h | 1 + 2 files changed, 18 insertions(+)
tools/lib/api/fd/array.c +17 -0
@@ -88,6 +88,23 @@ int fdarray__add(struct fdarray *fda, int fd, short revents, enum fdarray_flagsreturn pos; } +int fdarray__dup_entry_from (struct fdarray *fda,int pos,struct fdarray *from) +{ +struct pollfd *entry; +int npos; + +if (pos >= from->nr) +return -EINVAL ; + + entry = &from->entries[pos]; + + npos =fdarray__add (fda, entry->fd, entry->events, from->priv[pos].flags); +if (npos >=0 ) + fda->priv[npos] = from->priv[pos]; + +return npos; +} +int fdarray__filter (struct fdarray *fda,short revents,void (*entry_destructor)(struct fdarray *fda,int fd,void *arg),void *arg)
tools/lib/api/fd/array.h +1 -0
@@ -42,6 +42,7 @@ struct fdarray *fdarray__new(int nr_alloc, int nr_autogrow);void fdarray__delete (struct fdarray *fda);int fdarray__add (struct fdarray *fda,int fd,short revents,enum fdarray_flags flags); +int fdarray__dup_entry_from (struct fdarray *fda,int pos,struct fdarray *from);int fdarray__poll (struct fdarray *fda,int timeout); int fdarray__filter(struct fdarray *fda, short revents, void (*entry_destructor)(struct fdarray *fda, int fd, void *arg),
Signature · 1 line
2.19.0
PATCH v12 3/16 perf record: Introduce thread specific data array
In reply to Alexey BayduraevIntroduce thread specific data object and array of such objects to store and manage thread local data. Implement functions to allocate, initialize, finalize and release thread specific data.
Thread local maps and overwrite_maps arrays keep pointers to mmap buffer objects to serve according to maps thread mask. Thread local pollfd array keeps event fds connected to mmaps buffers according to maps thread mask.
Thread control commands are delivered via thread local comm pipes and ctlfd_pos fd. External control commands (--control option) are delivered via evlist ctlfd_pos fd and handled by the main tool thread.
--- tools/perf/builtin-record.c | 252 +++++++++++++++++++++++++++++++++++- 1 file changed, 249 insertions(+), 3 deletions(-)
tools/perf/builtin-record.c +249 -3
@@ -58,6 +58,7 @@#include <poll.h> #include <pthread.h> #include <unistd.h> +#include <syscall.h> #include <sched.h> #include <signal.h> #ifdef HAVE_EVENTFD_SUPPORT
@@ -92,6 +93,21 @@ struct thread_mask {struct mmap_cpu_mask affinity; }; +struct record_thread { +pid_t tid; +struct thread_mask *mask; +struct { +int msg[2 ]; +int ack[2 ]; + } pipes; +struct fdarray pollfd; +int ctlfd_pos; +int nr_mmaps; +struct mmap **maps; +struct mmap **overwrite_maps; +struct record *rec; +}; +struct record {struct perf_tool tool;struct record_opts opts;
@@ -118,6 +134,7 @@ struct record {unsigned long output_max_size;/* = 0: unlimited */ int nr_threads;struct thread_mask *thread_masks; +struct record_thread *thread_data; };static volatile int done;
@@ -130,6 +147,13 @@ static const char *affinity_tags[PERF_AFFINITY_MAX] = {"SYS" ,"NODE" ,"CPU" }; +#ifndef HAVE_GETTID +static inline pid_t gettid (void ) +{ +return (pid_t )syscall (__NR_gettid); +} +#endif +static bool switch_output_signal (struct record *rec) { return rec->switch_output.signal &&
@@ -847,9 +871,225 @@ static int record__kcore_copy(struct machine *machine, struct perf_data *data)return kcore_copy (from_dir, kcore_dir); } +static void record__thread_data_init_pipes (struct record_thread *thread_data) +{ + thread_data->pipes.msg[0 ] =-1 ; + thread_data->pipes.msg[1 ] =-1 ; + thread_data->pipes.ack[0 ] =-1 ; + thread_data->pipes.ack[1 ] =-1 ; +} + +static int record__thread_data_open_pipes (struct record_thread *thread_data) +{ +if (pipe (thread_data->pipes.msg)) { +pr_err ("Failed to create thread msg communication pipe: %s\n" ,strerror (errno)); +return -ENOMEM ; + } + +if (pipe (thread_data->pipes.ack)) { +pr_err ("Failed to create thread ack communication pipe: %s\n" ,strerror (errno)); +close (thread_data->pipes.msg[0 ]); + thread_data->pipes.msg[0 ] =-1 ; +close (thread_data->pipes.msg[1 ]); + thread_data->pipes.msg[1 ] =-1 ; +return -ENOMEM ; + } + +pr_debug2 ("thread_data[%p]: msg=[%d,%d], ack=[%d,%d]\n" , thread_data, + thread_data->pipes.msg[0 ], thread_data->pipes.msg[1 ], + thread_data->pipes.ack[0 ], thread_data->pipes.ack[1 ]); + +return 0 ; +} + +static void record__thread_data_close_pipes (struct record_thread *thread_data) +{ +if (thread_data->pipes.msg[0 ] !=-1 ) { +close (thread_data->pipes.msg[0 ]); + thread_data->pipes.msg[0 ] =-1 ; + } +if (thread_data->pipes.msg[1 ] !=-1 ) { +close (thread_data->pipes.msg[1 ]); + thread_data->pipes.msg[1 ] =-1 ; + } +if (thread_data->pipes.ack[0 ] !=-1 ) { +close (thread_data->pipes.ack[0 ]); + thread_data->pipes.ack[0 ] =-1 ; + } +if (thread_data->pipes.ack[1 ] !=-1 ) { +close (thread_data->pipes.ack[1 ]); + thread_data->pipes.ack[1 ] =-1 ; + } +} + +static int record__thread_data_init_maps (struct record_thread *thread_data,struct evlist *evlist) +{ +int m, tm, nr_mmaps = evlist->core.nr_mmaps; +struct mmap *mmap = evlist->mmap; +struct mmap *overwrite_mmap = evlist->overwrite_mmap; +struct perf_cpu_map *cpus = evlist->core.cpus; + + thread_data->nr_mmaps =bitmap_weight (thread_data->mask->maps.bits, + thread_data->mask->maps.nbits); +if (mmap) { + thread_data->maps =zalloc (thread_data->nr_mmaps *sizeof (struct mmap *)); +if (!thread_data->maps) { +pr_err ("Failed to allocate thread maps\n" ); +return -ENOMEM ; + } + } +if (overwrite_mmap) { + thread_data->overwrite_maps =zalloc (thread_data->nr_mmaps *sizeof (struct mmap *)); +if (!thread_data->overwrite_maps) { +pr_err ("Failed to allocate thread overwrite maps\n" ); +zfree (&thread_data->maps); +return -ENOMEM ; + } + } +pr_debug2 ("thread_data[%p]: nr_mmaps=%d, maps=%p, ow_maps=%p\n" , thread_data, + thread_data->nr_mmaps, thread_data->maps, thread_data->overwrite_maps); + +for (m =0 , tm =0 ; m < nr_mmaps && tm < thread_data->nr_mmaps; m++) { +if (test_bit (cpus->map[m], thread_data->mask->maps.bits)) { +if (thread_data->maps) { + thread_data->maps[tm] = &mmap[m]; +pr_debug2 ("thread_data[%p]: maps[%d] -> mmap[%d], cpus[%d]\n" , + thread_data, tm, m, cpus->map[m]); + } +if (thread_data->overwrite_maps) { + thread_data->overwrite_maps[tm] = &overwrite_mmap[m]; +pr_debug2 ("thread_data[%p]: ow_maps[%d] -> ow_mmap[%d], cpus[%d]\n" , + thread_data, tm, m, cpus->map[m]); + } + tm++; + } + } + +return 0 ; +} + +static int record__thread_data_init_pollfd (struct record_thread *thread_data,struct evlist *evlist) +{ +int f, tm, pos; +struct mmap *map, *overwrite_map; + +fdarray__init (&thread_data->pollfd,64 ); + +for (tm =0 ; tm < thread_data->nr_mmaps; tm++) { + map = thread_data->maps ? thread_data->maps[tm] :NULL ; + overwrite_map = thread_data->overwrite_maps ? + thread_data->overwrite_maps[tm] :NULL ; + +for (f =0 ; f < evlist->core.pollfd.nr; f++) { +void *ptr = evlist->core.pollfd.priv[f].ptr; + +if ((map && ptr == map) || (overwrite_map && ptr == overwrite_map)) { + pos =fdarray__dup_entry_from (&thread_data->pollfd, f, + &evlist->core.pollfd); +if (pos <0 ) { +pr_err ("Failed to duplicate descriptor in thread pollfd\n" ); +return pos; + } +pr_debug2 ("thread_data[%p]: pollfd[%d] <- event_fd=%d\n" , + thread_data, pos, evlist->core.pollfd.entries[f].fd); + } + } + } + +return 0 ; +} + +static void record__free_thread_data (struct record *rec) +{ +int t; +struct record_thread *thread_data = rec->thread_data; + +if (thread_data ==NULL ) +return ; + +for (t =0 ; t < rec->nr_threads; t++) { +record__thread_data_close_pipes (&thread_data[t]); +zfree (&thread_data[t].maps); +zfree (&thread_data[t].overwrite_maps); +fdarray__exit (&thread_data[t].pollfd); + } + +zfree (&rec->thread_data); +} + +static int record__alloc_thread_data (struct record *rec,struct evlist *evlist) +{ +int t, ret; +struct record_thread *thread_data; + + rec->thread_data =zalloc (rec->nr_threads *sizeof (*(rec->thread_data))); +if (!rec->thread_data) { +pr_err ("Failed to allocate thread data\n" ); +return -ENOMEM ; + } + thread_data = rec->thread_data; + +for (t =0 ; t < rec->nr_threads; t++) +record__thread_data_init_pipes (&thread_data[t]); + +for (t =0 ; t < rec->nr_threads; t++) { + thread_data[t].rec = rec; + thread_data[t].mask = &rec->thread_masks[t]; + ret =record__thread_data_init_maps (&thread_data[t], evlist); +if (ret) + goto out_free; + ret =record__thread_data_init_pollfd (&thread_data[t], evlist); +if (ret) { +pr_err ("Failed to initialize thread pollfd\n" ); + goto out_free; + } +if (t) { + thread_data[t].tid =-1 ; + ret =record__thread_data_open_pipes (&thread_data[t]); +if (ret) + goto out_free; + thread_data[t].ctlfd_pos =fdarray__add (&thread_data[t].pollfd, + thread_data[t].pipes.msg[0 ], +POLLIN |POLLERR |POLLHUP , + fdarray_flag__nonfilterable); +if (thread_data[t].ctlfd_pos <0 ) { +pr_err ("Failed to add descriptor to thread pollfd\n" ); + ret = -ENOMEM ; + goto out_free; + } +pr_debug2 ("thread_data[%p]: pollfd[%d] <- ctl_fd=%d\n" , + thread_data, thread_data[t].ctlfd_pos, + thread_data[t].pipes.msg[0 ]); + }else { + thread_data[t].tid =gettid (); +if (evlist->ctl_fd.pos ==-1 ) +continue ; + thread_data[t].ctlfd_pos =fdarray__dup_entry_from (&thread_data[t].pollfd, + evlist->ctl_fd.pos, + &evlist->core.pollfd); +if (thread_data[t].ctlfd_pos <0 ) { +pr_err ("Failed to duplicate descriptor in thread pollfd\n" ); + ret = -ENOMEM ; + goto out_free; + } +pr_debug2 ("thread_data[%p]: pollfd[%d] <- ctl_fd=%d\n" , + thread_data, thread_data[t].ctlfd_pos, + evlist->core.pollfd.entries[evlist->ctl_fd.pos].fd); + } + } + +return 0 ; + +out_free: +record__free_thread_data (rec); + +return ret; +} +static int record__mmap_evlist (struct record *rec,struct evlist *evlist) { +int ret;struct record_opts *opts = &rec->opts;bool auxtrace_overwrite = opts->auxtrace_snapshot_mode || opts->auxtrace_sample_mode;
@@ -880,6 +1120,14 @@ static int record__mmap_evlist(struct record *rec,return -EINVAL ; } } + +if (evlist__initialize_ctlfd (evlist, opts->ctl_fd, opts->ctl_fd_ack)) +return -1 ; + + ret =record__alloc_thread_data (rec, evlist); +if (ret) +return ret; +return 0 ; }
@@ -1861,9 +2109,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)evlist__start_workload (rec->evlist); } -if (evlist__initialize_ctlfd (rec->evlist, opts->ctl_fd, opts->ctl_fd_ack)) - goto out_child; -if (opts->initial_delay) {pr_info (EVLIST_DISABLED_MSG );if (opts->initial_delay >0 ) {
@@ -2021,6 +2266,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) out_child:evlist__finalize_ctlfd (rec->evlist);record__mmap_read_all (rec, true); +record__free_thread_data (rec);record__aio_mmap_read_sync (rec);if (rec->session->bytes_transferred && rec->session->bytes_compressed) {
Signature · 1 line
2.19.0
PATCH v12 4/16 perf record: Introduce function to propagate control commands
In reply to Alexey BayduraevIntroduce evlist__ctlfd_update() function to propagate external control commands to global evlist object.
--- tools/perf/util/evlist.c | 16 ++++++++++++++++ tools/perf/util/evlist.h | 1 + 2 files changed, 17 insertions(+)
tools/perf/util/evlist.c +16 -0
@@ -2115,6 +2115,22 @@ int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd)return err; } +int evlist__ctlfd_update (struct evlist *evlist,struct pollfd *update) +{ +int ctlfd_pos = evlist->ctl_fd.pos; +struct pollfd *entries = evlist->core.pollfd.entries; + +if (!evlist__ctlfd_initialized (evlist)) +return 0 ; + +if (entries[ctlfd_pos].fd != update->fd || + entries[ctlfd_pos].events != update->events) +return -1 ; + + entries[ctlfd_pos].revents = update->revents; +return 0 ; +} +struct evsel *evlist__find_evsel (struct evlist *evlist,int idx) {struct evsel *evsel;
tools/perf/util/evlist.h +1 -0
@@ -372,6 +372,7 @@ void evlist__close_control(int ctl_fd, int ctl_fd_ack, bool *ctl_fd_close);int evlist__initialize_ctlfd (struct evlist *evlist,int ctl_fd,int ctl_fd_ack);int evlist__finalize_ctlfd (struct evlist *evlist);bool evlist__ctlfd_initialized (struct evlist *evlist); +int evlist__ctlfd_update (struct evlist *evlist,struct pollfd *update);int evlist__ctlfd_process (struct evlist *evlist,enum evlist_ctl_cmd *cmd);int evlist__ctlfd_ack (struct evlist *evlist);
Signature · 1 line
2.19.0
PATCH v12 5/16 perf record: Introduce thread local variable
In reply to Alexey BayduraevIntroduce thread local variable and use it for threaded trace streaming. Use thread affinity mask instead or record affinity mask in affinity modes. Move waking and sample statistic to struct record_thread and introduce record__waking function to calculate the total number of wakes.
--- tools/perf/builtin-record.c | 140 ++++++++++++++++++++++++------------ 1 file changed, 94 insertions(+), 46 deletions(-)
tools/perf/builtin-record.c +94 -46
@@ -106,8 +106,12 @@ struct record_thread {struct mmap **maps;struct mmap **overwrite_maps;struct record *rec; +unsigned long long samples; +unsigned long waking; }; +static __threadstruct record_thread *thread; +struct record {struct perf_tool tool;struct record_opts opts;
@@ -130,7 +134,6 @@ struct record {bool timestamp_boundary;struct switch_output switch_output;unsigned long long samples; -struct mmap_cpu_mask affinity_mask;unsigned long output_max_size;/* = 0: unlimited */ int nr_threads;struct thread_mask *thread_masks;
@@ -572,7 +575,7 @@ static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size) bf = map->data; } - rec->samples++; + thread->samples++;return record__write (rec, map, bf, size); }
@@ -1319,15 +1322,17 @@ static struct perf_event_header finished_round_event = {static void record__adjust_affinity (struct record *rec,struct mmap *map) {if (rec->opts.affinity !=PERF_AFFINITY_SYS && - !bitmap_equal (rec->affinity_mask.bits, map->affinity_mask.bits, - rec->affinity_mask.nbits)) { -bitmap_zero (rec->affinity_mask.bits, rec->affinity_mask.nbits); -bitmap_or (rec->affinity_mask.bits, rec->affinity_mask.bits, - map->affinity_mask.bits, rec->affinity_mask.nbits); -sched_setaffinity (0 ,MMAP_CPU_MASK_BYTES (&rec->affinity_mask), - (cpu_set_t *)rec->affinity_mask.bits); -if (verbose ==2 ) -mmap_cpu_mask__scnprintf (&rec->affinity_mask,"thread" ); + !bitmap_equal (thread->mask->affinity.bits, map->affinity_mask.bits, + thread->mask->affinity.nbits)) { +bitmap_zero (thread->mask->affinity.bits, thread->mask->affinity.nbits); +bitmap_or (thread->mask->affinity.bits, thread->mask->affinity.bits, + map->affinity_mask.bits, thread->mask->affinity.nbits); +sched_setaffinity (0 ,MMAP_CPU_MASK_BYTES (&thread->mask->affinity), + (cpu_set_t *)thread->mask->affinity.bits); +if (verbose ==2 ) { +pr_debug ("threads[%d]: running on cpu=%d\n" , thread->tid,sched_getcpu ()); +mmap_cpu_mask__scnprintf (&thread->mask->affinity,"thread" ); + } } }
@@ -1368,14 +1373,17 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,u64 bytes_written = rec->bytes_written;int i;int rc =0 ; -struct mmap *maps; +int nr_mmaps; +struct mmap **maps;int trace_fd = rec->data.file.fd;off_t off =0 ;if (!evlist)return 0 ; - maps = overwrite ? evlist->overwrite_mmap : evlist->mmap; + nr_mmaps = thread->nr_mmaps; + maps = overwrite ? thread->overwrite_maps : thread->maps; +if (!maps)return 0 ;
@@ -1385,9 +1393,9 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,if (record__aio_enabled (rec)) off =record__aio_get_pos (trace_fd); -for (i =0 ; i < evlist->core.nr_mmaps; i++) { +for (i =0 ; i < nr_mmaps; i++) {u64 flush =0 ; -struct mmap *map = &maps[i]; +struct mmap *map = maps[i];if (map->core.base) {record__adjust_affinity (rec, map);
@@ -1450,6 +1458,15 @@ static int record__mmap_read_all(struct record *rec, bool synch)return record__mmap_read_evlist (rec, rec->evlist, true, synch); } +static void record__thread_munmap_filtered (struct fdarray *fda,int fd, +void *arg__maybe_unused ) +{ +struct perf_mmap *map = fda->priv[fd].ptr; + +if (map) +perf_mmap__put (map); +} +static void record__init_features (struct record *rec) {struct perf_session *session = rec->session;
@@ -1873,11 +1890,44 @@ static void record__uniquify_name(struct record *rec) } } +static int record__start_threads (struct record *rec) +{ +struct record_thread *thread_data = rec->thread_data; + + thread = &thread_data[0 ]; + +pr_debug ("threads[%d]: started on cpu=%d\n" , thread->tid,sched_getcpu ()); + +return 0 ; +} + +static int record__stop_threads (struct record *rec) +{ +int t; +struct record_thread *thread_data = rec->thread_data; + +for (t =0 ; t < rec->nr_threads; t++) + rec->samples += thread_data[t].samples; + +return 0 ; +} + +static unsigned long record__waking (struct record *rec) +{ +int t; +unsigned long waking =0 ; +struct record_thread *thread_data = rec->thread_data; + +for (t =0 ; t < rec->nr_threads; t++) + waking += thread_data[t].waking; + +return waking; +} +static int __cmd_record (struct record *rec,int argc,const char **argv) {int err;int status =0 ; -unsigned long waking =0 ;const bool forks = argc >0 ;struct perf_tool *tool = &rec->tool;struct record_opts *opts = &rec->opts;
@@ -1981,7 +2031,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)if (record__open (rec) !=0 ) { err =-1 ; - goto out_child; + goto out_free_threads; } session->header.env.comp_mmap_len = session->evlist->core.mmap_len;
@@ -1989,7 +2039,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) err =record__kcore_copy (&session->machines.host, data);if (err) {pr_err ("ERROR: Failed to copy kcore\n" ); - goto out_child; + goto out_free_threads; } }
@@ -2000,7 +2050,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)bpf__strerror_apply_obj_config (err, errbuf,sizeof (errbuf));pr_err ("ERROR: Apply config to BPF failed: %s\n" , errbuf); - goto out_child; + goto out_free_threads; }/*
@@ -2018,11 +2068,11 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)if (data->is_pipe) { err =perf_header__write_pipe (fd);if (err <0 ) - goto out_child; + goto out_free_threads; }else { err =perf_session__write_header (session, rec->evlist, fd, false);if (err <0 ) - goto out_child; + goto out_free_threads; } err =-1 ;
@@ -2030,16 +2080,16 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) && !perf_header__has_feat(&session->header, HEADER_BUILD_ID)) {pr_err ("Couldn't generate buildids. " "Use --no-buildid to profile anyway.\n" ); - goto out_child; + goto out_free_threads; } err =record__setup_sb_evlist (rec);if (err) - goto out_child; + goto out_free_threads; err =record__synthesize (rec, false);if (err <0 ) - goto out_child; + goto out_free_threads;if (rec->realtime_prio) {struct sched_param param;
@@ -2048,10 +2098,13 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)if (sched_setscheduler (0 ,SCHED_FIFO , ¶m)) {pr_err ("Could not set realtime priority.\n" ); err =-1 ; - goto out_child; + goto out_free_threads; } } +if (record__start_threads (rec)) + goto out_free_threads; +/* * When perf is starting the traced process, all the events * (apart from group members) have enable_on_exec=1 set,
@@ -2122,7 +2175,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)trigger_ready (&switch_output_trigger);perf_hooks__invoke_record_start ();for (;;) { -unsigned long long hits = rec->samples; +unsigned long long hits = thread->samples;/* * rec->evlist->bkw_mmap_state is possible to be
@@ -2176,8 +2229,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)if (!quiet)fprintf (stderr,"[ perf record: dump data: Woken up %ld times ]\n" , - waking); - waking =0 ; +record__waking (rec)); + thread->waking =0 ; fd =record__switch_output (rec, false);if (fd <0 ) {pr_err ("Failed to switch to new file\n" );
@@ -2191,20 +2244,24 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)alarm (rec->switch_output.time); } -if (hits == rec->samples) { +if (hits == thread->samples) {if (done || draining)break ; - err =evlist__poll (rec->evlist,-1 ); + err =fdarray__poll (&thread->pollfd,-1 );/* * Propagate error, only if there's any. Ignore positive * number of returned events and interrupt error. */ if (err >0 || (err <0 && errno ==EINTR )) err =0 ; - waking++; + thread->waking++; -if (evlist__filter_pollfd (rec->evlist,POLLERR |POLLHUP ) ==0 ) +if (fdarray__filter (&thread->pollfd,POLLERR |POLLHUP , + record__thread_munmap_filtered,NULL ) ==0 ) draining = true; + +evlist__ctlfd_update (rec->evlist, + &thread->pollfd.entries[thread->ctlfd_pos]); }if (evlist__ctlfd_process (rec->evlist, &cmd) >0 ) {
@@ -2258,15 +2315,18 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) }if (!quiet) -fprintf (stderr,"[ perf record: Woken up %ld times to write data ]\n" , waking); +fprintf (stderr,"[ perf record: Woken up %ld times to write data ]\n" , +record__waking (rec));if (target__none (&rec->opts.target))record__synthesize_workload (rec, true); out_child: -evlist__finalize_ctlfd (rec->evlist); +record__stop_threads (rec);record__mmap_read_all (rec, true); +out_free_threads:record__free_thread_data (rec); +evlist__finalize_ctlfd (rec->evlist);record__aio_mmap_read_sync (rec);if (rec->session->bytes_transferred && rec->session->bytes_compressed) {
@@ -3158,17 +3218,6 @@ int cmd_record(int argc, const char **argv)symbol__init (NULL ); -if (rec->opts.affinity !=PERF_AFFINITY_SYS ) { - rec->affinity_mask.nbits =cpu__max_cpu (); - rec->affinity_mask.bits =bitmap_zalloc (rec->affinity_mask.nbits); -if (!rec->affinity_mask.bits) { -pr_err ("Failed to allocate thread mask for %zd cpus\n" , rec->affinity_mask.nbits); - err = -ENOMEM ; - goto out_opts; - } -pr_debug2 ("thread mask[%zd]: empty\n" , rec->affinity_mask.nbits); - } - err =record__auxtrace_init (rec);if (err) goto out;
@@ -3313,7 +3362,6 @@ int cmd_record(int argc, const char **argv) err =__cmd_record (&record, argc, argv); out: -bitmap_free (rec->affinity_mask.bits);evlist__delete (rec->evlist);symbol__exit ();auxtrace_record__free (rec->itr);
Signature · 1 line
2.19.0
Re: [PATCH v12 05/16] perf record: Introduce thread local variable
On Tue, Nov 23, 2021 at 05:08:01PM +0300, Alexey Bayduraev wrote:
SNIP
Quoted 43 lines
tools/perf/builtin-record.c +8
-5+if (record__start_threads (rec)) + goto out_free_threads; +/* * When perf is starting the traced process, all the events * (apart from group members) have enable_on_exec=1 set, @@ -2122,7 +2175,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)trigger_ready (&switch_output_trigger);perf_hooks__invoke_record_start ();for (;;) { -unsigned long long hits = rec->samples; +unsigned long long hits = thread->samples;/* * rec->evlist->bkw_mmap_state is possible to be @@ -2176,8 +2229,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)if (!quiet)fprintf (stderr,"[ perf record: dump data: Woken up %ld times ]\n" , - waking); - waking =0 ; +record__waking (rec)); + thread->waking =0 ; fd =record__switch_output (rec, false);if (fd <0 ) {pr_err ("Failed to switch to new file\n" );@@ -2191,20 +2244,24 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)alarm (rec->switch_output.time); } -if (hits == rec->samples) { +if (hits == thread->samples) {if (done || draining)break ; - err =evlist__poll (rec->evlist,-1 ); + err =fdarray__poll (&thread->pollfd,-1 );/* * Propagate error, only if there's any. Ignore positive * number of returned events and interrupt error. */ if (err >0 || (err <0 && errno ==EINTR )) err =0 ;
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 2264
Quoted 10 lines
tools/perf/builtin-record.c +6
-2- waking++; + thread->waking++; -if (evlist__filter_pollfd (rec->evlist,POLLERR |POLLHUP ) ==0 ) +if (fdarray__filter (&thread->pollfd,POLLERR |POLLHUP , + record__thread_munmap_filtered,NULL ) ==0 ) draining = true; + +evlist__ctlfd_update (rec->evlist, + &thread->pollfd.entries[thread->ctlfd_pos]);
hm, why is this needed? we only switch to record_thread data, right? there should not be any processing change
jirka
Quoted 53 lines
tools/perf/builtin-record.c +5
-14}if (evlist__ctlfd_process (rec->evlist, &cmd) >0 ) {@@ -2258,15 +2315,18 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) }if (!quiet) -fprintf (stderr,"[ perf record: Woken up %ld times to write data ]\n" , waking); +fprintf (stderr,"[ perf record: Woken up %ld times to write data ]\n" , +record__waking (rec));if (target__none (&rec->opts.target))record__synthesize_workload (rec, true); out_child: -evlist__finalize_ctlfd (rec->evlist); +record__stop_threads (rec);record__mmap_read_all (rec, true); +out_free_threads:record__free_thread_data (rec); +evlist__finalize_ctlfd (rec->evlist);record__aio_mmap_read_sync (rec);if (rec->session->bytes_transferred && rec->session->bytes_compressed) {@@ -3158,17 +3218,6 @@ int cmd_record(int argc, const char **argv)symbol__init (NULL ); -if (rec->opts.affinity !=PERF_AFFINITY_SYS ) { - rec->affinity_mask.nbits =cpu__max_cpu (); - rec->affinity_mask.bits =bitmap_zalloc (rec->affinity_mask.nbits); -if (!rec->affinity_mask.bits) { -pr_err ("Failed to allocate thread mask for %zd cpus\n" , rec->affinity_mask.nbits); - err = -ENOMEM ; - goto out_opts; - } -pr_debug2 ("thread mask[%zd]: empty\n" , rec->affinity_mask.nbits); - } - err =record__auxtrace_init (rec);if (err) goto out;@@ -3313,7 +3362,6 @@ int cmd_record(int argc, const char **argv) err =__cmd_record (&record, argc, argv); out: -bitmap_free (rec->affinity_mask.bits);evlist__delete (rec->evlist);symbol__exit ();auxtrace_record__free (rec->itr);Signature · 1 line
2.19.0
Re: [PATCH v12 05/16] perf record: Introduce thread local variable
Quoted 50 lines · Jiri Olsa
On Tue, Nov 23, 2021 at 05:08:01PM +0300, Alexey Bayduraev wrote:
SNIP
Quoted 46 lines
tools/perf/builtin-record.c +9
-6+if (record__start_threads (rec)) + goto out_free_threads; +/* * When perf is starting the traced process, all the events * (apart from group members) have enable_on_exec=1 set, @@ -2122,7 +2175,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)trigger_ready (&switch_output_trigger);perf_hooks__invoke_record_start ();for (;;) { -unsigned long long hits = rec->samples; +unsigned long long hits = thread->samples;/* * rec->evlist->bkw_mmap_state is possible to be @@ -2176,8 +2229,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)if (!quiet)fprintf (stderr,"[ perf record: dump data: Woken up %ld times ]\n" , - waking); - waking =0 ; +record__waking (rec)); + thread->waking =0 ; fd =record__switch_output (rec, false);if (fd <0 ) {pr_err ("Failed to switch to new file\n" );@@ -2191,20 +2244,24 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)alarm (rec->switch_output.time); } -if (hits == rec->samples) { +if (hits == thread->samples) {if (done || draining)break ; - err =evlist__poll (rec->evlist,-1 ); + err =fdarray__poll (&thread->pollfd,-1 );/* * Propagate error, only if there's any. Ignore positive * number of returned events and interrupt error. */ if (err >0 || (err <0 && errno ==EINTR )) err =0 ; - waking++; + thread->waking++;
Quoted 10 lines
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 2264
Quoted 7 lines
tools/perf/builtin-record.c +5
-1-if (evlist__filter_pollfd (rec->evlist,POLLERR |POLLHUP ) ==0 ) +if (fdarray__filter (&thread->pollfd,POLLERR |POLLHUP , + record__thread_munmap_filtered,NULL ) ==0 ) draining = true; + +evlist__ctlfd_update (rec->evlist, + &thread->pollfd.entries[thread->ctlfd_pos]);hm, why is this needed? we only switch to
record_threaddata, right? there should not be any processing change
Hi,
This is necessary to propagate ctlfd events from thread->pollfd to rec->evlist to enable evlist__ctlfd_*() functionality, see [PATCH v12 04/16]. I will add explanations to the description of the patch.
Regards,
Alexey
Quoted 57 lines
jirka
Quoted 53 lines
tools/perf/builtin-record.c +5
-14}if (evlist__ctlfd_process (rec->evlist, &cmd) >0 ) {@@ -2258,15 +2315,18 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) }if (!quiet) -fprintf (stderr,"[ perf record: Woken up %ld times to write data ]\n" , waking); +fprintf (stderr,"[ perf record: Woken up %ld times to write data ]\n" , +record__waking (rec));if (target__none (&rec->opts.target))record__synthesize_workload (rec, true); out_child: -evlist__finalize_ctlfd (rec->evlist); +record__stop_threads (rec);record__mmap_read_all (rec, true); +out_free_threads:record__free_thread_data (rec); +evlist__finalize_ctlfd (rec->evlist);record__aio_mmap_read_sync (rec);if (rec->session->bytes_transferred && rec->session->bytes_compressed) {@@ -3158,17 +3218,6 @@ int cmd_record(int argc, const char **argv)symbol__init (NULL ); -if (rec->opts.affinity !=PERF_AFFINITY_SYS ) { - rec->affinity_mask.nbits =cpu__max_cpu (); - rec->affinity_mask.bits =bitmap_zalloc (rec->affinity_mask.nbits); -if (!rec->affinity_mask.bits) { -pr_err ("Failed to allocate thread mask for %zd cpus\n" , rec->affinity_mask.nbits); - err = -ENOMEM ; - goto out_opts; - } -pr_debug2 ("thread mask[%zd]: empty\n" , rec->affinity_mask.nbits); - } - err =record__auxtrace_init (rec);if (err) goto out;@@ -3313,7 +3362,6 @@ int cmd_record(int argc, const char **argv) err =__cmd_record (&record, argc, argv); out: -bitmap_free (rec->affinity_mask.bits);evlist__delete (rec->evlist);symbol__exit ();auxtrace_record__free (rec->itr);Signature · 1 line
2.19.0
PATCH v12 6/16 perf record: Stop threads in the end of trace streaming
In reply to Alexey BayduraevSignal thread to terminate by closing write fd of msg pipe. Receive THREAD_MSG__READY message as the confirmation of the thread's termination. Stop threads created for parallel trace streaming prior their stats processing.
--- tools/perf/builtin-record.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
tools/perf/builtin-record.c +30 -0
@@ -112,6 +112,16 @@ struct record_thread {static __threadstruct record_thread *thread; +enum thread_msg { +THREAD_MSG__UNDEFINED =0 , +THREAD_MSG__READY , +THREAD_MSG__MAX , +}; + +static const char *thread_msg_tags[THREAD_MSG__MAX ] = { +"UNDEFINED" ,"READY" +}; +struct record {struct perf_tool tool;struct record_opts opts;
@@ -1890,6 +1900,23 @@ static void record__uniquify_name(struct record *rec) } } +static int record__terminate_thread (struct record_thread *thread_data) +{ +int res; +enum thread_msg ack =THREAD_MSG__UNDEFINED ; +pid_t tid = thread_data->tid; + +close (thread_data->pipes.msg[1 ]); + thread_data->pipes.msg[1 ] =-1 ; + res =read (thread_data->pipes.ack[0 ], &ack,sizeof (ack)); +if (res !=-1 ) +pr_debug2 ("threads[%d]: sent %s\n" , tid, thread_msg_tags[ack]); +else +pr_err ("threads[%d]: failed to receive message from tid: %d\n" , thread->tid, tid); + +return 0 ; +} +static int record__start_threads (struct record *rec) {struct record_thread *thread_data = rec->thread_data;
@@ -1906,6 +1933,9 @@ static int record__stop_threads(struct record *rec)int t;struct record_thread *thread_data = rec->thread_data; +for (t =1 ; t < rec->nr_threads; t++) +record__terminate_thread (&thread_data[t]); +for (t =0 ; t < rec->nr_threads; t++) rec->samples += thread_data[t].samples;
Signature · 1 line
2.19.0
PATCH v12 7/16 perf record: Start threads in the beginning of trace streaming
In reply to Alexey BayduraevStart thread in detached state because its management is implemented via messaging to avoid any scaling issues. Block signals prior thread start so only main tool thread would be notified on external async signals during data collection. Thread affinity mask is used to assign eligible cpus for the thread to run. Wait and sync on thread start using thread ack pipe.
--- tools/perf/builtin-record.c | 110 +++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +109 -1
@@ -1477,6 +1477,67 @@ static void record__thread_munmap_filtered(struct fdarray *fda, int fd,perf_mmap__put (map); } +static void *record__thread (void *arg) +{ +enum thread_msg msg =THREAD_MSG__READY ; +bool terminate = false; +struct fdarray *pollfd; +int err, ctlfd_pos; + + thread = arg; + thread->tid =gettid (); + + err =write (thread->pipes.ack[1 ], &msg,sizeof (msg)); +if (err ==-1 ) +pr_err ("threads[%d]: failed to notify on start: %s" , thread->tid,strerror (errno)); + +pr_debug ("threads[%d]: started on cpu=%d\n" , thread->tid,sched_getcpu ()); + + pollfd = &thread->pollfd; + ctlfd_pos = thread->ctlfd_pos; + +for (;;) { +unsigned long long hits = thread->samples; + +if (record__mmap_read_all (thread->rec, false) <0 || terminate) +break ; + +if (hits == thread->samples) { + + err =fdarray__poll (pollfd,-1 ); +/* +* Propagate error, only if there's any. Ignore positive +* number of returned events and interrupt error. +*/ +if (err >0 || (err <0 && errno ==EINTR )) + err =0 ; + thread->waking++; + +if (fdarray__filter (pollfd,POLLERR |POLLHUP , + record__thread_munmap_filtered,NULL ) ==0 ) +break ; + } + +if (pollfd->entries[ctlfd_pos].revents &POLLHUP ) { + terminate = true; +close (thread->pipes.msg[0 ]); + thread->pipes.msg[0 ] =-1 ; + pollfd->entries[ctlfd_pos].fd =-1 ; + pollfd->entries[ctlfd_pos].events =0 ; + } + + pollfd->entries[ctlfd_pos].revents =0 ; + } +record__mmap_read_all (thread->rec, true); + + err =write (thread->pipes.ack[1 ], &msg,sizeof (msg)); +if (err ==-1 ) +pr_err ("threads[%d]: failed to notify on termination: %s" , + thread->tid,strerror (errno)); + +return NULL ; +} +static void record__init_features (struct record *rec) {struct perf_session *session = rec->session;
@@ -1919,13 +1980,60 @@ static int record__terminate_thread(struct record_thread *thread_data)static int record__start_threads (struct record *rec) { +int t, tt, ret =0 , nr_threads = rec->nr_threads;struct record_thread *thread_data = rec->thread_data; +sigset_t full, mask; +pthread_t handle; +pthread_attr_t attrs; thread = &thread_data[0 ]; +if (!record__threads_enabled (rec)) +return 0 ; + +sigfillset (&full); +if (sigprocmask (SIG_SETMASK , &full, &mask)) { +pr_err ("Failed to block signals on threads start: %s\n" ,strerror (errno)); +return -1 ; + } + +pthread_attr_init (&attrs); +pthread_attr_setdetachstate (&attrs,PTHREAD_CREATE_DETACHED ); + +for (t =1 ; t < nr_threads; t++) { +enum thread_msg msg =THREAD_MSG__UNDEFINED ; + +pthread_attr_setaffinity_np (&attrs, +MMAP_CPU_MASK_BYTES (&(thread_data[t].mask->affinity)), + (cpu_set_t *)(thread_data[t].mask->affinity.bits)); + +if (pthread_create (&handle, &attrs, record__thread, &thread_data[t])) { +for (tt =1 ; tt < t; tt++) +record__terminate_thread (&thread_data[t]); +pr_err ("Failed to start threads: %s\n" ,strerror (errno)); + ret =-1 ; + goto out_err; + } + +if (read (thread_data[t].pipes.ack[0 ], &msg,sizeof (msg)) >0 ) +pr_debug2 ("threads[%d]: sent %s\n" , rec->thread_data[t].tid, + thread_msg_tags[msg]); + } + +sched_setaffinity (0 ,MMAP_CPU_MASK_BYTES (&thread->mask->affinity), + (cpu_set_t *)thread->mask->affinity.bits); +pr_debug ("threads[%d]: started on cpu=%d\n" , thread->tid,sched_getcpu ()); -return 0 ; +out_err: +pthread_attr_destroy (&attrs); + +if (sigprocmask (SIG_SETMASK , &mask,NULL )) { +pr_err ("Failed to unblock signals on threads start: %s\n" ,strerror (errno)); + ret =-1 ; + } + +return ret; }static int record__stop_threads (struct record *rec)
Signature · 1 line
2.19.0
PATCH v12 8/16 perf record: Introduce data file at mmap buffer object
In reply to Alexey BayduraevIntroduce data file objects into mmap object so it could be used to process and store data stream from the corresponding kernel data buffer. Initialize data files located at mmap buffer objects so trace data can be written into several data file located at data directory.
--- tools/perf/builtin-record.c | 46 +++++++++++++++++++++++++++++++------ tools/perf/util/mmap.h | 1 + tools/perf/util/record.h | 1 + 3 files changed, 41 insertions(+), 7 deletions(-)
tools/perf/builtin-record.c +39 -7
@@ -167,6 +167,11 @@ static inline pid_t gettid(void) }#endif +static int record__threads_enabled (struct record *rec) +{ +return rec->opts.threads_spec; +} +static bool switch_output_signal (struct record *rec) { return rec->switch_output.signal &&
@@ -197,12 +202,16 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused, {struct perf_data_file *file = &rec->session->data->file; +if (map && map->file) + file = map->file; +if (perf_data_file__write (file, bf, size) <0 ) {pr_err ("failed to write perf data, error: %m\n" );return -1 ; } - rec->bytes_written += size; +if (!(map && map->file)) + rec->bytes_written += size;if (record__output_max_size_exceeded (rec) && !done) { fprintf(stderr, "[ perf record: perf size limit reached (%" PRIu64 " KB),"
@@ -1102,7 +1111,7 @@ static int record__alloc_thread_data(struct record *rec, struct evlist *evlist)static int record__mmap_evlist (struct record *rec,struct evlist *evlist) { -int ret; +int i, ret;struct record_opts *opts = &rec->opts;bool auxtrace_overwrite = opts->auxtrace_snapshot_mode || opts->auxtrace_sample_mode;
@@ -1141,6 +1150,18 @@ static int record__mmap_evlist(struct record *rec,if (ret)return ret; +if (record__threads_enabled (rec)) { + ret =perf_data__create_dir (&rec->data, evlist->core.nr_mmaps); +if (ret) +return ret; +for (i =0 ; i < evlist->core.nr_mmaps; i++) { +if (evlist->mmap) + evlist->mmap[i].file = &rec->data.dir.files[i]; +if (evlist->overwrite_mmap) + evlist->overwrite_mmap[i].file = &rec->data.dir.files[i]; + } + } +return 0 ; }
@@ -1447,8 +1468,12 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,/* * Mark the round finished in case we wrote * at least one event. +* +* No need for round events in directory mode, +* because per-cpu maps and files have data +* sorted by kernel. */ -if (bytes_written != rec->bytes_written) +if (!record__threads_enabled (rec) && bytes_written != rec->bytes_written) rc =record__write (rec,NULL , &finished_round_event,sizeof (finished_round_event));if (overwrite)
@@ -1564,7 +1589,9 @@ static void record__init_features(struct record *rec)if (!rec->opts.use_clockid)perf_header__clear_feat (&session->header,HEADER_CLOCK_DATA ); -perf_header__clear_feat (&session->header,HEADER_DIR_FORMAT ); +if (!record__threads_enabled (rec)) +perf_header__clear_feat (&session->header,HEADER_DIR_FORMAT ); +if (!record__comp_enabled (rec))perf_header__clear_feat (&session->header,HEADER_COMPRESSED );
@@ -1574,6 +1601,7 @@ static void record__init_features(struct record *rec)static void record__finish_output (struct record *rec) { +int i;struct perf_data *data = &rec->data;int fd =perf_data__fd (data);
@@ -1582,8 +1610,14 @@ record__finish_output(struct record *rec) rec->session->header.data_size += rec->bytes_written; data->file.size =lseek (perf_data__fd (data),0 ,SEEK_CUR ); +if (record__threads_enabled (rec)) { +for (i =0 ; i < data->dir.nr; i++) + data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); + }if (!rec->no_buildid) { +/* this will be recalculated during process_buildids() */ + rec->samples =0 ;process_buildids (rec);if (rec->buildid_all)
@@ -2490,8 +2524,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) status = err;record__synthesize (rec, true); -/* this will be recalculated during process_buildids() */ - rec->samples =0 ;if (!err) {if (!rec->timestamp_filename) {
@@ -3312,7 +3344,7 @@ int cmd_record(int argc, const char **argv) goto out_opts; } -if (rec->opts.kcore) +if (rec->opts.kcore ||record__threads_enabled (rec)) rec->data.is_dir = true;if (rec->opts.comp_level !=0 ) {
tools/perf/util/mmap.h +1 -0
@@ -44,6 +44,7 @@ struct mmap {struct mmap_cpu_mask affinity_mask;void *data;int comp_level; +struct perf_data_file *file; };struct mmap_params {
tools/perf/util/record.h +1 -0
@@ -78,6 +78,7 @@ struct record_opts {int ctl_fd_ack;bool ctl_fd_close;int synth; +int threads_spec; };extern const char *const *record_usage;
Signature · 1 line
2.19.0
Re: [PATCH v12 08/16] perf record: Introduce data file at mmap buffer object
On Tue, Nov 23, 2021 at 05:08:04PM +0300, Alexey Bayduraev wrote:
SNIP
Quoted 13 lines
tools/perf/builtin-record.c +6
-0+static int record__threads_enabled (struct record *rec) +{ +return rec->opts.threads_spec; +} +static bool switch_output_signal (struct record *rec) { return rec->switch_output.signal &&@@ -197,12 +202,16 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused, {struct perf_data_file *file = &rec->session->data->file; +if (map && map->file)
tools/perf/builtin-record.c static int record__write(struct record *rec, struct mmap *map __maybe_unused, · line 214
Quoted 10 lines
tools/perf/builtin-record.c +4
-1+ file = map->file; +if (perf_data_file__write (file, bf, size) <0 ) {pr_err ("failed to write perf data, error: %m\n" );return -1 ; } - rec->bytes_written += size; +if (!(map && map->file)) + rec->bytes_written += size;
why is this incremented under that condition?
Quoted 7 lines
tools/perf/builtin-record.c +0
-0if (record__output_max_size_exceeded (rec) && !done) { fprintf(stderr, "[ perf record: perf size limit reached (%" PRIu64 " KB),"@@ -1102,7 +1111,7 @@ static int record__alloc_thread_data(struct record *rec, struct evlist *evlist)static int record__mmap_evlist (struct record *rec,struct evlist *evlist) {
SNIP
Quoted 24 lines
tools/perf/builtin-record.c +7
-0@@ -1574,6 +1601,7 @@ static void record__init_features(struct record *rec)static void record__finish_output (struct record *rec) { +int i;struct perf_data *data = &rec->data;int fd =perf_data__fd (data);@@ -1582,8 +1610,14 @@ record__finish_output(struct record *rec) rec->session->header.data_size += rec->bytes_written; data->file.size =lseek (perf_data__fd (data),0 ,SEEK_CUR ); +if (record__threads_enabled (rec)) { +for (i =0 ; i < data->dir.nr; i++) + data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); + }if (!rec->no_buildid) { +/* this will be recalculated during process_buildids() */ + rec->samples =0 ;process_buildids (rec);if (rec->buildid_all)
tools/perf/builtin-record.c static int __cmd_record(struct record *rec, int argc, const char **argv) · line 2494
Quoted 5 lines
tools/perf/builtin-record.c +0
-2@@ -2490,8 +2524,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) status = err;record__synthesize (rec, true); -/* this will be recalculated during process_buildids() */ - rec->samples =0 ;
hm, why is this removed?
jirka
Quoted 39 lines
tools/perf/builtin-record.c +1
-1if (!err) {if (!rec->timestamp_filename) {@@ -3312,7 +3344,7 @@ int cmd_record(int argc, const char **argv) goto out_opts; } -if (rec->opts.kcore) +if (rec->opts.kcore ||record__threads_enabled (rec)) rec->data.is_dir = true;if (rec->opts.comp_level !=0 ) {tools/perf/util/mmap.h +1
-0@@ -44,6 +44,7 @@ struct mmap {struct mmap_cpu_mask affinity_mask;void *data;int comp_level; +struct perf_data_file *file; };struct mmap_params {tools/perf/util/record.h +1
-0@@ -78,6 +78,7 @@ struct record_opts {int ctl_fd_ack;bool ctl_fd_close;int synth; +int threads_spec; };extern const char *const *record_usage;Signature · 1 line
2.19.0
PATCH v12 9/16 perf record: Introduce bytes written stats
In reply to Alexey BayduraevIntroduce a function to calculate the total amount of data written and use it to support the --max-size option.
--- tools/perf/builtin-record.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
tools/perf/builtin-record.c +18 -3
@@ -108,6 +108,7 @@ struct record_thread {struct record *rec;unsigned long long samples;unsigned long waking; +u64 bytes_written; };static __threadstruct record_thread *thread;
@@ -191,10 +192,22 @@ static bool switch_output_time(struct record *rec)trigger_is_ready (&switch_output_trigger); } +static u64 record__bytes_written (struct record *rec) +{ +int t; +u64 bytes_written = rec->bytes_written; +struct record_thread *thread_data = rec->thread_data; + +for (t =0 ; t < rec->nr_threads; t++) + bytes_written += thread_data[t].bytes_written; + +return bytes_written; +} +static bool record__output_max_size_exceeded (struct record *rec) {return rec->output_max_size && - (rec->bytes_written >= rec->output_max_size); + (record__bytes_written (rec) >= rec->output_max_size); } static int record__write(struct record *rec, struct mmap *map __maybe_unused,
@@ -210,13 +223,15 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused,return -1 ; } -if (!(map && map->file)) +if (map && map->file) + thread->bytes_written += size; +else rec->bytes_written += size;if (record__output_max_size_exceeded (rec) && !done) {fprintf (stderr,"[ perf record: perf size limit reached (%" PRIu64" KB)," " stopping session ]\n" , - rec->bytes_written >>10 ); +record__bytes_written (rec) >>10 ); done =1 ; }
Signature · 1 line
2.19.0
Re: [PATCH v12 09/16] perf record: Introduce bytes written stats
Quoted 48 lines · Alexey Bayduraev
Introduce a function to calculate the total amount of data written and use it to support the --max-size option.
Acked-by Namhyung Kim <[email protected]>Reviewed-by Riccardo Mancini <[email protected]>Tested-by Riccardo Mancini <[email protected]>Signed-off-by Alexey Bayduraev <[email protected]>--- tools/perf/builtin-record.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)tools/perf/builtin-record.c +14
-1@@ -108,6 +108,7 @@ struct record_thread {struct record *rec;unsigned long long samples;unsigned long waking; +u64 bytes_written; };static __threadstruct record_thread *thread;@@ -191,10 +192,22 @@ static bool switch_output_time(struct record *rec)trigger_is_ready (&switch_output_trigger); } +static u64 record__bytes_written (struct record *rec) +{ +int t; +u64 bytes_written = rec->bytes_written; +struct record_thread *thread_data = rec->thread_data; + +for (t =0 ; t < rec->nr_threads; t++) + bytes_written += thread_data[t].bytes_written; + +return bytes_written; +} +static bool record__output_max_size_exceeded (struct record *rec) {return rec->output_max_size && - (rec->bytes_written >= rec->output_max_size); + (record__bytes_written (rec) >= rec->output_max_size); } static int record__write(struct record *rec, struct mmap *map __maybe_unused,
tools/perf/builtin-record.c static int record__write(struct record *rec, struct mmap *map __maybe_unused, · line 229
Quoted 8 lines
tools/perf/builtin-record.c +3
-1@@ -210,13 +223,15 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused,return -1 ; } -if (!(map && map->file)) +if (map && map->file) + thread->bytes_written += size; +else rec->bytes_written += size;
ok, that's why ;-) do we actually stil need rec->bytes_written? can't we count that under synthesizing main thread->bytes_written?
jirka
Quoted 12 lines
tools/perf/builtin-record.c +1
-1if (record__output_max_size_exceeded (rec) && !done) {fprintf (stderr,"[ perf record: perf size limit reached (%" PRIu64" KB)," " stopping session ]\n" , - rec->bytes_written >>10 ); +record__bytes_written (rec) >>10 ); done =1 ; }Signature · 1 line
2.19.0
Re: [PATCH v12 09/16] perf record: Introduce bytes written stats
On 05.12.2021 18:14, Jiri Olsa wrote:
<SNIP>
Quoted 5 lines
Quoted 5 lines
static int record__write(struct record *rec, struct mmap *map
__maybe_unused,tools/perf/builtin-record.c +0
-0@@ -210,13 +223,15 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused,return -1 ; }
Quoted 8 lines
tools/perf/builtin-record.c static int record__write(struct record *rec, struct mmap *map __maybe_unused, · line 229
Quoted 5 lines
tools/perf/builtin-record.c +3
-1-if (!(map && map->file)) +if (map && map->file) + thread->bytes_written += size; +else rec->bytes_written += size;ok, that's why ;-) do we actually stil need
rec->bytes_written? can't we count that under synthesizing mainthread->bytes_written?
Hi Jiri,
No, we still need rec->bytes_written because it is used for the header in "perf.data/data", and it cannot be replaced by threads[0].bytes_written because threads[0] is used for "perf.data/data.0".
Regards,
Alexey
Quoted 16 lines
jirka
Quoted 12 lines
tools/perf/builtin-record.c +1
-1if (record__output_max_size_exceeded (rec) && !done) {fprintf (stderr,"[ perf record: perf size limit reached (%" PRIu64" KB)," " stopping session ]\n" , - rec->bytes_written >>10 ); +record__bytes_written (rec) >>10 ); done =1 ; }Signature · 1 line
2.19.0
PATCH v12 10/16 perf record: Introduce compressor at mmap buffer object
In reply to Alexey BayduraevIntroduce compressor object into mmap object so it could be used to pack the data stream from the corresponding kernel data buffer. Initialize and make use of the introduced per mmap compressor.
--- tools/perf/builtin-record.c | 18 +++++++++++------- tools/perf/util/mmap.c | 10 ++++++++++ tools/perf/util/mmap.h | 2 ++ 3 files changed, 23 insertions(+), 7 deletions(-)
tools/perf/builtin-record.c +11 -7
@@ -243,8 +243,8 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused,static int record__aio_enabled (struct record *rec);static int record__comp_enabled (struct record *rec); -static size_t zstd_compress (struct perf_session *session,void *dst,size_t dst_size, -void *src,size_t src_size); +static size_t zstd_compress (struct perf_session *session,struct mmap *map, +void *dst,size_t dst_size,void *src,size_t src_size);#ifdef HAVE_AIO_SUPPORT static int record__aio_write(struct aiocb *cblock, int trace_fd,
@@ -378,7 +378,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t size*/ if (record__comp_enabled (aio->rec)) { - size =zstd_compress (aio->rec->session, aio->data + aio->size, + size =zstd_compress (aio->rec->session,NULL , aio->data + aio->size,mmap__mmap_len (map) - aio->size, buf, size); }else {
@@ -605,7 +605,7 @@ static int record__pushfn(struct mmap *map, void *to, void *bf, size_t size)struct record *rec = to;if (record__comp_enabled (rec)) { - size =zstd_compress (rec->session, map->data,mmap__mmap_len (map), bf, size); + size =zstd_compress (rec->session, map, map->data,mmap__mmap_len (map), bf, size); bf = map->data; }
@@ -1398,13 +1398,17 @@ static size_t process_comp_header(void *record, size_t increment)return size; } -static size_t zstd_compress (struct perf_session *session,void *dst,size_t dst_size, -void *src,size_t src_size) +static size_t zstd_compress (struct perf_session *session,struct mmap *map, +void *dst,size_t dst_size,void *src,size_t src_size) {size_t compressed;size_t max_record_size =PERF_SAMPLE_MAX_SIZE -sizeof (struct perf_record_compressed ) -1 ; +struct zstd_data *zstd_data = &session->zstd_data; - compressed =zstd_compress_stream_to_records (&session->zstd_data, dst, dst_size, src, src_size, +if (map && map->file) + zstd_data = &map->zstd_data; + + compressed =zstd_compress_stream_to_records (zstd_data, dst, dst_size, src, src_size, max_record_size, process_comp_header); session->bytes_transferred += src_size;
tools/perf/util/mmap.c +10 -0
@@ -230,6 +230,10 @@ void mmap__munmap(struct mmap *map) {bitmap_free (map->affinity_mask.bits); +#ifndef PYTHON_PERF +zstd_fini (&map->zstd_data); +#endif +perf_mmap__aio_munmap (map);if (map->data !=NULL ) {munmap (map->data,mmap__mmap_len (map));
@@ -291,6 +295,12 @@ int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu) map->core.flush = mp->flush; map->comp_level = mp->comp_level; +#ifndef PYTHON_PERF +if (zstd_init (&map->zstd_data, map->comp_level)) { +pr_debug2 ("failed to init mmap commpressor, error %d\n" , errno); +return -1 ; + } +#endif if (map->comp_level && !perf_mmap__aio_enabled (map)) { map->data = mmap(NULL, mmap__mmap_len(map), PROT_READ|PROT_WRITE,
tools/perf/util/mmap.h +2 -0
@@ -14,6 +14,7 @@#endif #include "auxtrace.h" #include "event.h" +#include "util/compress.h" struct aiocb ;
@@ -45,6 +46,7 @@ struct mmap {void *data;int comp_level;struct perf_data_file *file; +struct zstd_data zstd_data; };struct mmap_params {
Signature · 1 line
2.19.0
PATCH v12 11/16 perf record: Introduce data transferred and compressed stats
In reply to Alexey BayduraevIntroduce bytes_transferred and bytes_compressed stats so they would capture statistics for the related data buffer transfers.
--- tools/perf/builtin-record.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
tools/perf/builtin-record.c +22 -3
@@ -109,6 +109,8 @@ struct record_thread {unsigned long long samples;unsigned long waking;u64 bytes_written; +u64 bytes_transferred; +u64 bytes_compressed; };static __threadstruct record_thread *thread;
@@ -1411,8 +1413,13 @@ static size_t zstd_compress(struct perf_session *session, struct mmap *map, compressed =zstd_compress_stream_to_records (zstd_data, dst, dst_size, src, src_size, max_record_size, process_comp_header); - session->bytes_transferred += src_size; - session->bytes_compressed += compressed; +if (map && map->file) { + thread->bytes_transferred += src_size; + thread->bytes_compressed += compressed; + }else { + session->bytes_transferred += src_size; + session->bytes_compressed += compressed; + }return compressed; }
@@ -2097,8 +2104,20 @@ static int record__stop_threads(struct record *rec)for (t =1 ; t < rec->nr_threads; t++)record__terminate_thread (&thread_data[t]); -for (t =0 ; t < rec->nr_threads; t++) +for (t =0 ; t < rec->nr_threads; t++) { rec->samples += thread_data[t].samples; +if (!record__threads_enabled (rec)) +continue ; + rec->session->bytes_transferred += thread_data[t].bytes_transferred; + rec->session->bytes_compressed += thread_data[t].bytes_compressed; +pr_debug ("threads[%d]: samples=%lld, wakes=%ld, " , thread_data[t].tid, + thread_data[t].samples, thread_data[t].waking); +if (thread_data[t].bytes_transferred && thread_data[t].bytes_compressed) +pr_debug ("trasferred=%ld, compressed=%ld\n" , + thread_data[t].bytes_transferred, thread_data[t].bytes_compressed); +else +pr_debug ("written=%ld\n" , thread_data[t].bytes_written); + }return 0 ; }
Signature · 1 line
2.19.0
PATCH v12 12/16 perf record: Introduce --threads command line option
In reply to Alexey BayduraevProvide --threads option in perf record command line interface. The option creates a data streaming thread for each cpu in the system. Document --threads option in Documentation/perf-record.txt.
--- tools/perf/Documentation/perf-record.txt | 4 ++ tools/perf/builtin-record.c | 48 +++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-record.txt +4 -0
@@ -711,6 +711,10 @@ measurements: wait -n ${perf_pid} exit $? +--threads:: +Write collected trace data into several data files using parallel threads. +The option creates a data streaming thread for each cpu in the system. + include::intel-hybrid.txt[] SEE ALSO
tools/perf/builtin-record.c +47 -1
78 lines not on this page · raw message
Signature · 1 line
2.19.0
PATCH v12 13/16 perf record: Extend --threads command line option
In reply to Alexey BayduraevExtend --threads option in perf record command line interface. The option can have a value in the form of masks that specify cpus to be monitored with data streaming threads and its layout in system topology. The masks can be filtered using cpu mask provided via -C option.
The specification value can be user defined list of masks. Masks separated by colon define cpus to be monitored by one thread and affinity mask of that thread is separated by slash. For example:
<cpus mask 1>/<affinity mask 1>:<cpu mask 2>/<affinity mask 2> specifies parallel threads layout that consists of two threads with corresponding assigned cpus to be monitored.
The specification value can be a string e.g. "cpu", "core" or "package" meaning creation of data streaming thread for every cpu or core or package to monitor distinct cpus or cpus grouped by core or package.
The option provided with no or empty value defaults to per-cpu parallel threads layout creating data streaming thread for every cpu being monitored.
Document --threads option syntax and parallel data streaming modes in Documentation/perf-record.txt.
--- tools/perf/Documentation/perf-record.txt | 30 ++- tools/perf/builtin-record.c | 315 ++++++++++++++++++++++- tools/perf/util/record.h | 1 + 3 files changed, 341 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-record.txt +28 -2
@@ -711,9 +711,35 @@ measurements: wait -n ${perf_pid} exit $? ---threads:: +--threads=<spec>:: Write collected trace data into several data files using parallel threads. -The option creates a data streaming thread for each cpu in the system. +<spec> value can be user defined list of masks. Masks separated by colon +define cpus to be monitored by a thread and affinity mask of that thread +is separated by slash: + + <cpus mask 1>/<affinity mask 1>:<cpus mask 2>/<affinity mask 2>:... + +For example user specification like the following: + + 0,2-4/2-4:1,5-7/5-7 + +specifies parallel threads layout that consists of two threads, +the first thread monitors cpus 0 and 2-4 with the affinity mask 2-4, +the second monitors cpus 1 and 5-7 with the affinity mask 5-7. + +<spec> value can also be a string meaning predefined parallel threads +layout: + + cpu - create new data streaming thread for every monitored cpu + core - create new thread to monitor cpus grouped by a core + package - create new thread to monitor cpus grouped by a package + numa - create new threed to monitor cpus grouped by a numa domain + +Predefined layouts can be used on systems with large number of cpus in +order not to spawn multiple per-cpu streaming threads but still avoid LOST +events in data directory files. Option specified with no or empty value +defaults to cpu layout. Masks defined or provided by the option value are +filtered through the mask provided by -C option. include::intel-hybrid.txt[]
tools/perf/builtin-record.c +312 -3
367 lines not on this page · raw message
tools/perf/util/record.h +1 -0
@@ -79,6 +79,7 @@ struct record_opts {bool ctl_fd_close;int synth;int threads_spec; +const char *threads_user_spec; };extern const char *const *record_usage;
Signature · 1 line
2.19.0
Re: [PATCH v12 13/16] perf record: Extend --threads command line option
On Tue, Nov 23, 2021 at 05:08:09PM +0300, Alexey Bayduraev wrote:
SNIP
tools/perf/builtin-record.c static void record__thread_mask_free(struct thread_mask *mask) · line 2829
Quoted 13 lines
tools/perf/builtin-record.c +7
-1+static int record__parse_threads (const struct option *opt,const char *str,int unset) { +int s;struct record_opts *opts = opt->value; -if (unset || !str || !strlen (str)) +if (unset || !str || !strlen (str)) { opts->threads_spec =THREAD_SPEC__CPU ; + }else { +for (s =1 ; s <THREAD_SPEC__MAX ; s++) { +if (s ==THREAD_SPEC__USER ) { + opts->threads_user_spec =strdup (str);
we should bail out if strdup fails
jirka
Quoted 21 lines
tools/perf/builtin-record.c +14
-0+ opts->threads_spec =THREAD_SPEC__USER ; +break ; + } +if (!strncasecmp (str, thread_spec_tags[s],strlen (thread_spec_tags[s]))) { + opts->threads_spec = s; +break ; + } + } + } + +if (opts->threads_spec ==THREAD_SPEC__USER ) +pr_debug ("threads_spec: %s\n" , opts->threads_user_spec); +else +pr_debug ("threads_spec: %s\n" , thread_spec_tags[opts->threads_spec]);return 0 ; }@@ -3263,6 +3327,17 @@ static void record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cset_bit (cpus->map[c], mask->bits); }
SNIP
Re: [PATCH v12 13/16] perf record: Extend --threads command line option
In reply to Alexey BayduraevOn Tue, Nov 23, 2021 at 05:08:09PM +0300, Alexey Bayduraev wrote:
SNIP
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+static int record__init_thread_masks_spec (struct record *rec,struct perf_cpu_map *cpus, +const char **maps_spec,const char **affinity_spec, +u32 nr_spec) +{ +u32 s; +int ret =0 , t =0 ; +struct mmap_cpu_mask cpus_mask; +struct thread_mask thread_mask, full_mask, *prev_masks; + + ret =record__mmap_cpu_mask_alloc (&cpus_mask,cpu__max_cpu ());
tools/perf/builtin-record.c static int record__init_thread_cpu_masks(struct record *rec, struct perf_cpu_map · line 3421
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+if (ret) + goto out; +record__mmap_cpu_mask_init (&cpus_mask, cpus); + ret =record__thread_mask_alloc (&thread_mask,cpu__max_cpu ()); +if (ret) + goto out_free_cpu_mask; + ret =record__thread_mask_alloc (&full_mask,cpu__max_cpu ()); +if (ret) + goto out_free_thread_mask; +record__thread_mask_clear (&full_mask);
nit, is this clear needed?
jirka
Quoted 55 lines
tools/perf/builtin-record.c +55
-0+ +for (s =0 ; s < nr_spec; s++) { +record__thread_mask_clear (&thread_mask); + +record__mmap_cpu_mask_init_spec (&thread_mask.maps, maps_spec[s]); +record__mmap_cpu_mask_init_spec (&thread_mask.affinity, affinity_spec[s]); + +if (!bitmap_and (thread_mask.maps.bits, thread_mask.maps.bits, + cpus_mask.bits, thread_mask.maps.nbits) || + !bitmap_and (thread_mask.affinity.bits, thread_mask.affinity.bits, + cpus_mask.bits, thread_mask.affinity.nbits)) +continue ; + + ret =record__thread_mask_intersects (&thread_mask, &full_mask); +if (ret) + goto out_free_full_mask; +record__thread_mask_or (&full_mask, &full_mask, &thread_mask); + + prev_masks = rec->thread_masks; + rec->thread_masks =realloc (rec->thread_masks, + (t +1 ) *sizeof (struct thread_mask )); +if (!rec->thread_masks) { +pr_err ("Failed to allocate thread masks\n" ); + rec->thread_masks = prev_masks; + ret = -ENOMEM ; + goto out_free_full_mask; + } + rec->thread_masks[t] = thread_mask; +if (verbose) { +pr_debug ("thread_masks[%d]: " , t); +mmap_cpu_mask__scnprintf (&rec->thread_masks[t].maps,"maps" ); +pr_debug ("thread_masks[%d]: " , t); +mmap_cpu_mask__scnprintf (&rec->thread_masks[t].affinity,"affinity" ); + } + t++; + ret =record__thread_mask_alloc (&thread_mask,cpu__max_cpu ()); +if (ret) + goto out_free_full_mask; + } + + rec->nr_threads = t; +pr_debug ("nr_threads: %d\n" , rec->nr_threads); + +if (rec->nr_threads <=0 ) + ret = -EINVAL ; + +out_free_full_mask: +record__thread_mask_free (&full_mask); +out_free_thread_mask: +record__thread_mask_free (&thread_mask); +out_free_cpu_mask: +record__mmap_cpu_mask_free (&cpus_mask); +out: +return ret; +}
SNIP
Re: [PATCH v12 13/16] perf record: Extend --threads command line option
In reply to Alexey BayduraevOn Tue, Nov 23, 2021 at 05:08:09PM +0300, Alexey Bayduraev wrote:
SNIP
Quoted 5 lines
tools/perf/builtin-record.c +0
-0return 0 ; }@@ -3263,6 +3327,17 @@ static void record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cset_bit (cpus->map[c], mask->bits); }
tools/perf/builtin-record.c static void record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_c · line 3338
Quoted 10 lines
tools/perf/builtin-record.c +9
-0+static void record__mmap_cpu_mask_init_spec (struct mmap_cpu_mask *mask,const char *mask_spec) +{ +struct perf_cpu_map *cpus; + + cpus =perf_cpu_map__new (mask_spec); +if (cpus) { +record__mmap_cpu_mask_init (mask, cpus); +perf_cpu_map__put (cpus); + }
we should bail out on perf_cpu_map__new error
jirka
Quoted 84 lines
tools/perf/builtin-record.c +77
-0+} +static void record__free_thread_masks (struct record *rec,int nr_threads) {int t;@@ -3324,6 +3399,214 @@ static int record__init_thread_cpu_masks(struct record *rec, struct perf_cpu_mapreturn 0 ; } +static int record__init_thread_masks_spec (struct record *rec,struct perf_cpu_map *cpus, +const char **maps_spec,const char **affinity_spec, +u32 nr_spec) +{ +u32 s; +int ret =0 , t =0 ; +struct mmap_cpu_mask cpus_mask; +struct thread_mask thread_mask, full_mask, *prev_masks; + + ret =record__mmap_cpu_mask_alloc (&cpus_mask,cpu__max_cpu ()); +if (ret) + goto out; +record__mmap_cpu_mask_init (&cpus_mask, cpus); + ret =record__thread_mask_alloc (&thread_mask,cpu__max_cpu ()); +if (ret) + goto out_free_cpu_mask; + ret =record__thread_mask_alloc (&full_mask,cpu__max_cpu ()); +if (ret) + goto out_free_thread_mask; +record__thread_mask_clear (&full_mask); + +for (s =0 ; s < nr_spec; s++) { +record__thread_mask_clear (&thread_mask); + +record__mmap_cpu_mask_init_spec (&thread_mask.maps, maps_spec[s]); +record__mmap_cpu_mask_init_spec (&thread_mask.affinity, affinity_spec[s]); + +if (!bitmap_and (thread_mask.maps.bits, thread_mask.maps.bits, + cpus_mask.bits, thread_mask.maps.nbits) || + !bitmap_and (thread_mask.affinity.bits, thread_mask.affinity.bits, + cpus_mask.bits, thread_mask.affinity.nbits)) +continue ; + + ret =record__thread_mask_intersects (&thread_mask, &full_mask); +if (ret) + goto out_free_full_mask; +record__thread_mask_or (&full_mask, &full_mask, &thread_mask); + + prev_masks = rec->thread_masks; + rec->thread_masks =realloc (rec->thread_masks, + (t +1 ) *sizeof (struct thread_mask )); +if (!rec->thread_masks) { +pr_err ("Failed to allocate thread masks\n" ); + rec->thread_masks = prev_masks; + ret = -ENOMEM ; + goto out_free_full_mask; + } + rec->thread_masks[t] = thread_mask; +if (verbose) { +pr_debug ("thread_masks[%d]: " , t); +mmap_cpu_mask__scnprintf (&rec->thread_masks[t].maps,"maps" ); +pr_debug ("thread_masks[%d]: " , t); +mmap_cpu_mask__scnprintf (&rec->thread_masks[t].affinity,"affinity" ); + } + t++; + ret =record__thread_mask_alloc (&thread_mask,cpu__max_cpu ()); +if (ret) + goto out_free_full_mask; + } + + rec->nr_threads = t; +pr_debug ("nr_threads: %d\n" , rec->nr_threads); + +if (rec->nr_threads <=0 ) + ret = -EINVAL ; + +out_free_full_mask: +record__thread_mask_free (&full_mask); +out_free_thread_mask: +record__thread_mask_free (&thread_mask); +out_free_cpu_mask: +record__mmap_cpu_mask_free (&cpus_mask); +out: +return ret; +}
SNIP
Re: [PATCH v12 13/16] perf record: Extend --threads command line option
In reply to Alexey BayduraevOn Tue, Nov 23, 2021 at 05:08:09PM +0300, Alexey Bayduraev wrote:
SNIP
Quoted 28 lines
tools/perf/builtin-record.c +27
-0+static int record__init_thread_masks_spec (struct record *rec,struct perf_cpu_map *cpus, +const char **maps_spec,const char **affinity_spec, +u32 nr_spec) +{ +u32 s; +int ret =0 , t =0 ; +struct mmap_cpu_mask cpus_mask; +struct thread_mask thread_mask, full_mask, *prev_masks; + + ret =record__mmap_cpu_mask_alloc (&cpus_mask,cpu__max_cpu ()); +if (ret) + goto out; +record__mmap_cpu_mask_init (&cpus_mask, cpus); + ret =record__thread_mask_alloc (&thread_mask,cpu__max_cpu ()); +if (ret) + goto out_free_cpu_mask; + ret =record__thread_mask_alloc (&full_mask,cpu__max_cpu ()); +if (ret) + goto out_free_thread_mask; +record__thread_mask_clear (&full_mask); + +for (s =0 ; s < nr_spec; s++) { +record__thread_mask_clear (&thread_mask); + +record__mmap_cpu_mask_init_spec (&thread_mask.maps, maps_spec[s]); +record__mmap_cpu_mask_init_spec (&thread_mask.affinity, affinity_spec[s]); +
tools/perf/builtin-record.c static int record__init_thread_cpu_masks(struct record *rec, struct perf_cpu_map · line 3438
Quoted 10 lines
tools/perf/builtin-record.c +10
-0+if (!bitmap_and (thread_mask.maps.bits, thread_mask.maps.bits, + cpus_mask.bits, thread_mask.maps.nbits) || + !bitmap_and (thread_mask.affinity.bits, thread_mask.affinity.bits, + cpus_mask.bits, thread_mask.affinity.nbits)) +continue ; + + ret =record__thread_mask_intersects (&thread_mask, &full_mask); +if (ret) + goto out_free_full_mask; +record__thread_mask_or (&full_mask, &full_mask, &thread_mask);
please put some explanation to comment on the intersection checks, like what's allowed and what's not.. and also some info about that to documentation
thanks,
jirka
Quoted 22 lines
tools/perf/builtin-record.c +22
-0+ + prev_masks = rec->thread_masks; + rec->thread_masks =realloc (rec->thread_masks, + (t +1 ) *sizeof (struct thread_mask )); +if (!rec->thread_masks) { +pr_err ("Failed to allocate thread masks\n" ); + rec->thread_masks = prev_masks; + ret = -ENOMEM ; + goto out_free_full_mask; + } + rec->thread_masks[t] = thread_mask; +if (verbose) { +pr_debug ("thread_masks[%d]: " , t); +mmap_cpu_mask__scnprintf (&rec->thread_masks[t].maps,"maps" ); +pr_debug ("thread_masks[%d]: " , t); +mmap_cpu_mask__scnprintf (&rec->thread_masks[t].affinity,"affinity" ); + } + t++; + ret =record__thread_mask_alloc (&thread_mask,cpu__max_cpu ()); +if (ret) + goto out_free_full_mask; + }
SNIP
PATCH v12 14/16 perf record: Implement compatibility checks
In reply to Alexey BayduraevImplement compatibility checks for other modes and related command line
options: asynchronous (--aio) trace streaming and affinity (--affinity) modes, pipe mode, AUX area tracing --snapshot and --aux-sample options, --switch-output, --switch-output-event, --switch-max-files and --timestamp-filename options. Parallel data streaming is compatible with Zstd compression (--compression-level) and external control commands (--control). Cpu mask provided via -C option filters --threads specification masks.
--- tools/perf/builtin-record.c | 49 ++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-)
tools/perf/builtin-record.c +46 -3
@@ -802,6 +802,12 @@ static int record__auxtrace_init(struct record *rec) {int err; +if ((rec->opts.auxtrace_snapshot_opts || rec->opts.auxtrace_sample_opts) + &&record__threads_enabled (rec)) { +pr_err ("AUX area tracing options are not available in parallel streaming mode.\n" ); +return -EINVAL ; + } +if (!rec->itr) { rec->itr =auxtrace_record__init (rec->evlist, &err);if (err)
@@ -2197,6 +2203,17 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)return PTR_ERR (session); } +if (record__threads_enabled (rec)) { +if (perf_data__is_pipe (&rec->data)) { +pr_err ("Parallel trace streaming is not available in pipe mode.\n" ); +return -1 ; + } +if (rec->opts.full_auxtrace) { +pr_err ("Parallel trace streaming is not available in AUX area tracing mode.\n" ); +return -1 ; + } + } + fd =perf_data__fd (data); rec->session = session;
@@ -2965,12 +2982,22 @@ static int switch_output_setup(struct record *rec)* --switch-output=signal, as we'll send a SIGUSR2 from the side band * thread to its parent. */ -if (rec->switch_output_event_set) +if (rec->switch_output_event_set) { +if (record__threads_enabled (rec)) { +pr_warning ("WARNING: --switch-output-event option is not available in parallel streaming mode.\n" ); +return 0 ; + } goto do_signal; + }if (!s->set)return 0 ; +if (record__threads_enabled (rec)) { +pr_warning ("WARNING: --switch-output option is not available in parallel streaming mode.\n" ); +return 0 ; + } +if (!strcmp (s->str,"signal" )) { do_signal: s->signal = true;
@@ -3289,8 +3316,8 @@ static struct option __record_options[] = { "Set affinity mask of trace reading thread to NUMA node cpu mask or cpu of processed mmap buffer", record__parse_affinity),#ifdef HAVE_ZSTD_SUPPORT -OPT_CALLBACK_OPTARG ('z' ,"compression-level" , &record.opts, &comp_level_default, -"n" ,"Compressed records using specified level (default: 1 - fastest compression, 22 - greatest compression)" , +OPT_CALLBACK_OPTARG ('z' ,"compression-level" , &record.opts, &comp_level_default,"n" , +"Compress records using specified level (default: 1 - fastest compression, 22 - greatest compression)" , record__parse_comp_level), #endif OPT_CALLBACK(0, "max-size", &record.output_max_size,
@@ -3735,6 +3762,17 @@ int cmd_record(int argc, const char **argv)if (rec->opts.kcore ||record__threads_enabled (rec)) rec->data.is_dir = true; +if (record__threads_enabled (rec)) { +if (rec->opts.affinity !=PERF_AFFINITY_SYS ) { +pr_err ("--affinity option is mutually exclusive to parallel streaming mode.\n" ); + goto out_opts; + } +if (record__aio_enabled (rec)) { +pr_err ("Asynchronous streaming mode (--aio) is mutually exclusive to parallel streaming mode.\n" ); + goto out_opts; + } + } +if (rec->opts.comp_level !=0 ) {pr_debug ("Compression enabled, disabling build id collection at the end of the session.\n" ); rec->no_buildid = true;
@@ -3768,6 +3806,11 @@ int cmd_record(int argc, const char **argv) } } +if (rec->timestamp_filename &&record__threads_enabled (rec)) { + rec->timestamp_filename = false; +pr_warning ("WARNING: --timestamp-filename option is not available in parallel streaming mode.\n" ); + } +/* * Allow aliases to facilitate the lookup of symbols for address * filters. Refer to auxtrace_parse_filters().
Signature · 1 line
2.19.0
PATCH v12 15/16 perf session: Load data directory files for analysis
In reply to Alexey BayduraevLoad data directory files and provide basic raw dump and aggregated analysis support of data directories in report mode, still with no memory consumption optimizations.
READER_MAX_SIZE is chosen based on the results of measurements on different machines on perf.data directory sizes >1GB. On machines with big core count (192 cores) the difference between 1MB and 2MB is about 4%. Other sizes (>2MB) are quite equal to 2MB. On machines with small core count (4-24) there is no differences between 1-16 MB sizes. So this constant is 2MB.
--- tools/perf/util/session.c | 133 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+)
tools/perf/util/session.c +133 -0
@@ -2184,6 +2184,8 @@ struct reader {u64 file_pos;u64 file_offset;u64 head; +u64 size; +bool done;struct zstd_data zstd_data;struct decomp_data decomp_data; };
@@ -2301,6 +2303,7 @@ reader__read_event(struct reader *rd, struct perf_session *session,if (skip) size += skip; + rd->size += size; rd->head += size; rd->file_pos += size;
@@ -2409,6 +2412,133 @@ static int __perf_session__process_events(struct perf_session *session)return err; } +/* +* Processing 2 MB of data from each reader in sequence, +* because that's the way the ordered events sorting works +* most efficiently. +*/ +#define READER_MAX_SIZE (2 * 1024 * 1024) + +/* +* This function reads, merge and process directory data. +* It assumens the version 1 of directory data, where each +* data file holds per-cpu data, already sorted by kernel. +*/ +static int __perf_session__process_dir_events (struct perf_session *session) +{ +struct perf_data *data = session->data; +struct perf_tool *tool = session->tool; +int i, ret, readers, nr_readers; +struct ui_progress prog; +u64 total_size =perf_data__size (session->data); +struct reader *rd; + +perf_tool__fill_defaults (tool); + +ui_progress__init_size (&prog, total_size,"Sorting events..." ); + + nr_readers =1 ; +for (i =0 ; i < data->dir.nr; i++) { +if (data->dir.files[i].size) + nr_readers++; + } + + rd =zalloc (nr_readers *sizeof (struct reader )); +if (!rd) +return -ENOMEM ; + + rd[0 ] = (struct reader ) { + .fd =perf_data__fd (session->data), + .data_size = session->header.data_size, + .data_offset = session->header.data_offset, + .process = process_simple, + .in_place_update = session->data->in_place_update, + }; + ret =reader__init (&rd[0 ],NULL ); +if (ret) + goto out_err; + ret =reader__mmap (&rd[0 ], session); +if (ret) + goto out_err; + readers =1 ; + +for (i =0 ; i < data->dir.nr; i++) { +if (!data->dir.files[i].size) +continue ; + rd[readers] = (struct reader ) { + .fd = data->dir.files[i].fd, + .data_size = data->dir.files[i].size, + .data_offset =0 , + .process = process_simple, + .in_place_update = session->data->in_place_update, + }; + ret =reader__init (&rd[readers],NULL ); +if (ret) + goto out_err; + ret =reader__mmap (&rd[readers], session); +if (ret) + goto out_err; + readers++; + } + + i =0 ; +while (readers) { +if (session_done ()) +break ; + +if (rd[i].done) { + i = (i +1 ) % nr_readers; +continue ; + } +if (reader__eof (&rd[i])) { + rd[i].done = true; + readers--; +continue ; + } + + session->active_decomp = &rd[i].decomp_data; + ret =reader__read_event (&rd[i], session, &prog); +if (ret <0 ) { + goto out_err; + }else if (ret ==READER_NODATA ) { + ret =reader__mmap (&rd[i], session); +if (ret) + goto out_err; + } + +if (rd[i].size >=READER_MAX_SIZE ) { + rd[i].size =0 ; + i = (i +1 ) % nr_readers; + } + } + + ret =ordered_events__flush (&session->ordered_events,OE_FLUSH__FINAL ); +if (ret) + goto out_err; + + ret =perf_session__flush_thread_stacks (session); +out_err: +ui_progress__finish (); + +if (!tool->no_warn) +perf_session__warn_about_errors (session); + +/* +* We may switching perf.data output, make ordered_events +* reusable. +*/ +ordered_events__reinit (&session->ordered_events); + + session->one_mmap = false; + + session->active_decomp = &session->decomp_data; +for (i =0 ; i < nr_readers; i++) +reader__release_decomp (&rd[i]); +zfree (&rd); + +return ret; +} +int perf_session__process_events (struct perf_session *session) {if (perf_session__register_idle_thread (session) <0 )
@@ -2417,6 +2547,9 @@ int perf_session__process_events(struct perf_session *session)if (perf_data__is_pipe (session->data))return __perf_session__process_pipe_events (session); +if (perf_data__is_dir (session->data)) +return __perf_session__process_dir_events (session); +return __perf_session__process_events (session); }
Signature · 1 line
2.19.0
PATCH v12 16/16 perf report: Output data file name in raw trace dump
In reply to Alexey BayduraevPrint path and name of a data file into raw dump (-D) <file_offset>@<path/file>:
[email protected] [0x30]: event: 9
or
[email protected]/data.7 [0x30]: event: 9
--- tools/perf/builtin-inject.c | 3 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/ordered-events.c | 3 +- tools/perf/util/ordered-events.h | 3 +- tools/perf/util/session.c | 75 ++++++++++++++++++++------------ tools/perf/util/session.h | 3 +- tools/perf/util/tool.h | 3 +- 9 files changed, 59 insertions(+), 37 deletions(-)
tools/perf/builtin-inject.c +2 -1
@@ -110,7 +110,8 @@ static int perf_event__repipe_op2_synth(struct perf_session *session,static int perf_event__repipe_op4_synth (struct perf_session *session,union perf_event *event, -u64 data__maybe_unused ) +u64 data__maybe_unused , +const char *str__maybe_unused ) {return perf_event__repipe_synth (session->tool, event); }
tools/perf/builtin-kvm.c +1 -1
@@ -771,7 +771,7 @@ static s64 perf_kvm__mmap_read_idx(struct perf_kvm_stat *kvm, int idx,return -1 ; } - err =perf_session__queue_event (kvm->session, event, timestamp,0 ); + err =perf_session__queue_event (kvm->session, event, timestamp,0 ,NULL );/* * FIXME: Here we can't consume the event, as perf_session__queue_event will * point to it, and it'll get possibly overwritten by the kernel.
tools/perf/builtin-top.c +1 -1
@@ -888,7 +888,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)if (ret && ret !=-1 )break ; - ret =ordered_events__queue (top->qe.in, event, last_timestamp,0 ); + ret =ordered_events__queue (top->qe.in, event, last_timestamp,0 ,NULL );if (ret)break ;
tools/perf/builtin-trace.c +1 -1
@@ -3769,7 +3769,7 @@ static int trace__deliver_event(struct trace *trace, union perf_event *event)if (err && err !=-1 )return err; - err =ordered_events__queue (&trace->oe.data, event, trace->oe.last,0 ); + err =ordered_events__queue (&trace->oe.data, event, trace->oe.last,0 ,NULL );if (err)return err;
tools/perf/util/ordered-events.c +2 -1
@@ -192,7 +192,7 @@ void ordered_events__delete(struct ordered_events *oe, struct ordered_event *eve }int ordered_events__queue (struct ordered_events *oe,union perf_event *event, -u64 timestamp,u64 file_offset) +u64 timestamp,u64 file_offset,const char *file_path) {struct ordered_event *oevent;
@@ -217,6 +217,7 @@ int ordered_events__queue(struct ordered_events *oe, union perf_event *event,return -ENOMEM ; oevent->file_offset = file_offset; + oevent->file_path = file_path;return 0 ; }
tools/perf/util/ordered-events.h +2 -1
@@ -9,6 +9,7 @@ struct perf_sample;struct ordered_event {u64 timestamp;u64 file_offset; +const char *file_path;union perf_event *event;struct list_head list; };
@@ -53,7 +54,7 @@ struct ordered_events { };int ordered_events__queue (struct ordered_events *oe,union perf_event *event, -u64 timestamp,u64 file_offset); +u64 timestamp,u64 file_offset,const char *file_path);void ordered_events__delete (struct ordered_events *oe,struct ordered_event *event);int ordered_events__flush (struct ordered_events *oe,enum oe_flush how);int ordered_events__flush_time (struct ordered_events *oe,u64 timestamp);
tools/perf/util/session.c +46 -29
244 lines not on this page · raw message
tools/perf/util/session.h +2 -1
@@ -52,6 +52,7 @@ struct perf_session {struct decomp {struct decomp *next;u64 file_pos; +const char *file_path;size_t mmap_len;u64 head;size_t size;
@@ -87,7 +88,7 @@ int perf_session__peek_events(struct perf_session *session, u64 offset,int perf_session__process_events (struct perf_session *session);int perf_session__queue_event (struct perf_session *s,union perf_event *event, -u64 timestamp,u64 file_offset); +u64 timestamp,u64 file_offset,const char *file_path);void perf_tool__fill_defaults (struct perf_tool *tool);
tools/perf/util/tool.h +2 -1
@@ -28,7 +28,8 @@ typedef int (*event_attr_op)(struct perf_tool *tool,typedef int (*event_op2 )(struct perf_session *session,union perf_event *event);typedef s64 (*event_op3 )(struct perf_session *session,union perf_event *event); -typedef int (*event_op4 )(struct perf_session *session,union perf_event *event,u64 data); +typedef int (*event_op4 )(struct perf_session *session,union perf_event *event,u64 data, +const char *str);typedef int (*event_oe )(struct perf_tool *tool,union perf_event *event,struct ordered_events *oe);
Signature · 1 line
2.19.0
Quoted 10 lines · Alexey Bayduraev
Changes in v12:
- fixed nr_threads=1 cases
- fixed "Woken up %ld times" message
- removed unnecessaryrecord__fini_thread_masksfunction
- moved bytes written/compressed statistics to structrecord_thread
- moved all unnecessary debug messages to verbose=2 level
- renamed "socket" option to "package" for consistency withutil/cputopo.h
- excluded single trace file reading patches
I'm getting perf record hang with:
[root@krava perf]# ./perf record --threads
^C[ perf record: Woken up 1 times to write data ]
^C^C^C^C^C
with following backtrace:
(gdb) bt
#0 0x00007f8115d2885f in __GI___poll (fds=fds@entry=0x7ffd2116b930, nfds=1, timeout=1000) at ../sysdeps/unix/sysv/linux/poll.c:29
#1 0x00007f811574029e in poll (__timeout=<optimized out>, __nfds=<optimized out>, __fds=0x7ffd2116b930) at /usr/include/bits/poll2.h:48
#2 Curl_poll (timeout_ms=<optimized out>, nfds=<optimized out>, ufds=0x7ffd2116b930) at ../../lib/select.c:374
#3 Curl_poll (ufds=0x7ffd2116b930, nfds=<optimized out>, timeout_ms=<optimized out>) at ../../lib/select.c:329
#4 0x00007f8115739cf7 in multi_wait (multi=multi@entry=0x3458c50, extra_fds=extra_fds@entry=0x0, extra_nfds=extra_nfds@entry=0, timeout_ms=<optimized out>,
timeout_ms@entry=1000, ret=ret@entry=0x0, extrawait=extrawait@entry=false, use_wakeup=<optimized out>) at ../../lib/multi.c:1282
#5 0x00007f8115739f26 in multi_wait (use_wakeup=false, extrawait=false, ret=0x0, timeout_ms=1000, extra_nfds=0, extra_fds=0x0, multi=0x3458c50)
at ../../lib/multi.c:1410
#6 curl_multi_wait (multi=multi@entry=0x3458c50, extra_fds=extra_fds@entry=0x0, extra_nfds=extra_nfds@entry=0, timeout_ms=timeout_ms@entry=1000,
ret=ret@entry=0x0) at ../../lib/multi.c:1411
#7 0x00007f811653a7f2 in debuginfod_query_server (c=c@entry=0x2571fb0, build_id=build_id@entry=0x7ffd2116ed70 "c6eee0984964c63e328d13be49d68bd52595ad00",
build_id_len=build_id_len@entry=0, type=type@entry=0x7f811653c3ba "debuginfo", filename=filename@entry=0x0, path=path@entry=0x7ffd2116dcf8)
at /usr/src/debug/elfutils-0.186-1.fc35.x86_64/debuginfod/debuginfod-client.c:1057
#8 0x00007f811653b2a6 in debuginfod_find_debuginfo (client=client@entry=0x2571fb0,
build_id=build_id@entry=0x7ffd2116ed70 "c6eee0984964c63e328d13be49d68bd52595ad00", build_id_len=build_id_len@entry=0, path=path@entry=0x7ffd2116dcf8)
at /usr/src/debug/elfutils-0.186-1.fc35.x86_64/debuginfod/debuginfod-client.c:1511
#9 0x00000000004b18e1 in build_id_cache__find_debug (nsi=0x0, sbuild_id=0x7ffd2116ed70 "c6eee0984964c63e328d13be49d68bd52595ad00") at util/build-id.c:660
#10 build_id_cache__add (sbuild_id=sbuild_id@entry=0x7ffd2116ed70 "c6eee0984964c63e328d13be49d68bd52595ad00",
name=name@entry=0x259be50 "/lib/modules/5.15.6-200.fc35.x86_64/kernel/sound/core/seq/snd-seq-dummy.ko.xz",
realname=realname@entry=0x27255e0 "/usr/lib/modules/5.15.6-200.fc35.x86_64/kernel/sound/core/seq/snd-seq-dummy.ko.xz", nsi=nsi@entry=0x0,
is_kallsyms=is_kallsyms@entry=false, is_vdso=is_vdso@entry=false) at util/build-id.c:724
#11 0x00000000004b1b24 in build_id_cache__add_s (is_vdso=false, is_kallsyms=false, nsi=0x0,
name=0x259be50 "/lib/modules/5.15.6-200.fc35.x86_64/kernel/sound/core/seq/snd-seq-dummy.ko.xz",
sbuild_id=0x7ffd2116ed70 "c6eee0984964c63e328d13be49d68bd52595ad00") at util/build-id.c:805
#12 build_id_cache__add_b (is_vdso=false, is_kallsyms=<optimized out>, nsi=<optimized out>, name=<optimized out>, bid=<optimized out>) at util/build-id.c:821
#13 dso__cache_build_id (dso=<optimized out>, machine=<optimized out>, priv=<optimized out>) at util/build-id.c:889
#14 0x0000000000501674 in machine__for_each_dso (machine=machine@entry=0x2512d58, fn=fn@entry=0x4b1a00 <dso__cache_build_id>, priv=priv@entry=0x0)
at util/machine.c:3179#15 0x00000000004b1f09 in machines__for_each_dso (priv=0x0, fn=0x4b1a00 <dso__cache_build_id>, machines=0x2512d58) at util/build-id.c:896 #16 __perf_session__cache_build_ids (priv=0x0, fn=0x4b1a00 <dso__cache_build_id>, session=0x2512b50) at util/build-id.c:917 #17 __perf_session__cache_build_ids (session=0x2512b50, fn=0x4b1a00 <dso__cache_build_id>, priv=0x0) at util/build-id.c:908 #18 0x00000000004e80fb in write_build_id (ff=ff@entry=0x7ffd2116ef40, evlist=evlist@entry=0x2506050) at util/header.c:329 #19 0x00000000004f15c1 in do_write_feat (evlist=0x2506050, p=<synthetic pointer>, type=2, ff=0x7ffd2116ef40) at util/header.c:3428 #20 perf_header__adds_write (fd=3, evlist=0x2506050, header=0x2512b50) at util/header.c:3473
#21 perf_session__write_header (session=0x2512b50, evlist=0x2506050, fd=3, at_exit=at_exit@entry=true) at util/header.c:3565 #22 0x0000000000423ec4 in record__finish_output (rec=0xbba300 <record>) at builtin-record.c:1673
#23 0x0000000000426374 in __cmd_record (argc=argc@entry=0, argv=argv@entry=0x7ffd21174770, rec=0xbba300 <record>) at builtin-record.c:2600 #24 0x00000000004298e7 in cmd_record (argc=<optimized out>, argv=<optimized out>) at builtin-record.c:3969
#25 0x00000000004a42eb in run_builtin (p=p@entry=0xbd0f78 <commands+216>, argc=argc@entry=2, argv=argv@entry=0x7ffd21174770) at perf.c:313 #26 0x000000000040ec23 in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365
#27 run_argv (argv=<optimized out>, argcp=<optimized out>) at perf.c:409
#28 main (argc=2, argv=0x7ffd21174770) at perf.c:539
jirka
Quoted 210 lines
Changes in v11:
- removed python dependency on zstd (perf test 19)
- captured tags from Riccardo Manciniv10: https://lore.kernel.org/lkml/[email protected]/
Changes in v10:
- renamedfdarray__clonetofdarray__dup_entry_from
- captured Acked-by: tags by Namhyung Kim for 09/24v9: https://lore.kernel.org/lkml/[email protected]/
Changes in v9:
- fixes in [v9 01/24]:
- move 'nr_threads' to before 'thread_masks'
- combined decl+assign into one line inrecord__thread_mask_alloc
- releasing masks inplace inrecord__alloc_thread_masks
- split patch [v8 02/22] to [v9 02/24] and [v9 03/24]
- fixes in [v9 03/24]:
- renamed 'structthread_data' to 'structrecord_thread'
- movednr_mmapsafterctlfd_pos
- releasing resources inplace inrecord__thread_data_init_maps
- initializing pipes by -1 value
- added temporarygettid()wrapper
- split patch [v8 03/22] to [v9 04/24] and [v9 05/24]
- removed upstreamed [v8 09/22]
- split [v8 10/22] to [v9 12/24] and [v9 13/24]
- moved --threads documentation to the related patches
- fixed output of written/compressed stats in [v9 10/24]
- split patch [v8 12/22] to [v9 15/24] and [v9 16/24]
- fixed order of error checking for decompressed events in [v9 16/24]
- merged patch [v8 21/22] with [v9 23/24] and [v9 24/24]
- moved patch [v8 22/22] to [v9 09/24]
- added max reader size constant in [v9 24/24]v8: https://lore.kernel.org/lkml/[email protected]/
Changes in v8:
- captured Acked-by: tags by Namhyung Kim
- merged with origin/perf/core
- added patch 21/22 introducingREADER_NODATAstate
- added patch 22/22 fixing --max-size optionv7: https://lore.kernel.org/lkml/[email protected]/
Changes in v7:
- fixed possible crash afterout_free_threadslabel
- added missingpthread_attr_destroy()call
- added check of correctness of user masks
- fixedzsts_datafinalizationv6: https://lore.kernel.org/lkml/[email protected]/
Changes in v6:
- fixed leaks and possible double free inrecord__thread_mask_alloc()
- fixed leaks inrecord__init_thread_user_masks()
- fixed final mmaps flushing for threads id > 0
- merged with origin/perf/corev5: https://lore.kernel.org/lkml/[email protected]/
Changes in v5:
- fixed leaks inrecord__init_thread_masks_spec()
- fixed leaks after failed realloc
- replaced "%m" tostrerror()
- added masks examples to the documentation
- captured Acked-by: tags by Andi Kleen
- do not allow --thread option forfull_auxtracemode
- split patch 06/12 to 06/20 and 07/20
- split patch 08/12 to 09/20 and 10/20
- split patches 11/12 and 11/12 to 13/20-20/20v4: https://lore.kernel.org/lkml/[email protected]/
Changes in v4:
- renamed 'comm' structure to 'pipes'
- moved thread fd/maps messages to verbose=2
- fixed leaks during allocation ofthread_datastructures
- fixed leaks during allocation of thread masks
- fixed possible fails when releasing thread masksv3: https://lore.kernel.org/lkml/[email protected]/
Changes in v3:
- avoided skipped redundant patch 3/15
- applied "data file" and "data directory" terms allover the patch set
- captured Acked-by: tags by Namhyung Kim
- avoided braces where don't needed
- employed thread local variable for serial trace streaming
- added specs for --thread option - core, socket, numa and user defined
- added parallel loading of data directory files similar to the prototype [1]v2: https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- explicitly added credit tags to patches 6/15 and 15/15, additionally to cites [1], [2]
- updated description of 3/15 to explicitly mention the reason to open data directories in read access mode (e.g. for perf report)
- implemented fix for compilation error of 2/15
- explicitly elaborated on found issues to be resolved for threaded AUX trace capturev1: https://lore.kernel.org/lkml/[email protected]/
Patch set provides parallel threaded trace streaming mode for basic perf record operation. Provided mode mitigates profiling data losses and resolves scalability issues of serial and asynchronous (--aio) trace streaming modes on multicore server systems. The design and implementation are based on the prototype [1], [2].
Parallel threaded mode executes trace streaming threads that read kernel data buffers and write captured data into several data files located at data directory. Layout of trace streaming threads and their mapping to data buffers to read can be configured using a value of --thread command line option. Specification value provides masks separated by colon so the masks define cpus to be monitored by one thread and thread affinity mask is separated by slash. <cpus mask 1>/<affinity mask 1>:<cpu mask 2>/<affinity mask 2> specifies parallel threads layout that consists of two threads with corresponding assigned cpus to be monitored. Specification value can be a string e.g. "cpu", "core" or "socket" meaning creation of data streaming thread for monitoring every cpu, whole core or socket. The option provided with no or empty value defaults to "cpu" layout creating data streaming thread for every cpu being monitored. Specification masks are filtered by the mask provided via -C option.
Parallel streaming mode is compatible with Zstd compression/decompression (--compression-level) and external control commands (--control). The mode is not enabled for pipe mode. The mode is not enabled for AUX area tracing, related and derived modes like --snapshot or --aux-sample. --switch-output-* and --timestamp-filename options are not enabled for parallel streaming. Initial intent to enable AUX area tracing faced the need to define some optimal way to store index data in data directory. --switch-output-* and --timestamp-filename use cases are not clear for data directories. Asynchronous(--aio) trace streaming and affinity (--affinity) modes are mutually exclusive to parallel streaming mode.
Basic analysis of data directories is provided in perf report mode. Raw dump and aggregated reports are available for data directories, still with no memory consumption optimizations.
Tested:
tools/perf/perfrecord -o prof.data --threads -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads= -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads=cpu -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads=core -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads=socket -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads=numa -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads=0-3/3:4-7/4 -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data -C 2,5 --threads=0-3/3:4-7/4 -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data -C 3,4 --threads=0-3/3:4-7/4 -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data -C 0,4,2,6 --threads=core -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data -C 0,4,2,6 --threads=numa -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads -g --call-graph dwarf,4096 -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads -g --call-graph dwarf,4096 --compression-level=3 -- matrix.gcc.g.O3tools/perf/perfrecord -o prof.data --threads -atools/perf/perfrecord -D -1 -e cpu-cycles -a --control fd:10,11 -- sleep 30tools/perf/perfrecord --threads -D -1 -e cpu-cycles -a --control fd:10,11 -- sleep 30
tools/perf/perfreport -i prof.datatools/perf/perfreport -i prof.data --call-graph=calleetools/perf/perfreport -i prof.data --stdio --headertools/perf/perfreport -i prof.data -D --header[1] git clone https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git -b perf/record_threads
[2] https://lore.kernel.org/lkml/[email protected]/Alexey Bayduraev (16):
perf record: Introduce thread affinity and mmap masks tools lib: Introduce fdarray duplicate function
perf record: Introduce thread specific data array perf record: Introduce function to propagate control commands perf record: Introduce thread local variable
perf record: Stop threads in the end of trace streaming perf record: Start threads in the beginning of trace streaming perf record: Introduce data file at mmap buffer object perf record: Introduce bytes written stats
perf record: Introduce compressor at mmap buffer object perf record: Introduce data transferred and compressed stats perf record: Introduce --threads command line option perf record: Extend --threads command line option perf record: Implement compatibility checks
perf session: Load data directory files for analysis perf report: Output data file name in raw trace dumptools/lib/api/fd/array.c | 17 + tools/lib/api/fd/array.h | 1 + tools/perf/Documentation/perf-record.txt | 30 + tools/perf/builtin-inject.c | 3 +- tools/perf/builtin-kvm.c | 2 +- tools/perf/builtin-record.c | 1167 ++++++++++++++++++++-- tools/perf/builtin-top.c | 2 +- tools/perf/builtin-trace.c | 2 +- tools/perf/util/evlist.c | 16 + tools/perf/util/evlist.h | 1 + tools/perf/util/mmap.c | 10 + tools/perf/util/mmap.h | 3 + tools/perf/util/ordered-events.c | 3 +- tools/perf/util/ordered-events.h | 3 +- tools/perf/util/record.h | 2 + tools/perf/util/session.c | 208 +++- tools/perf/util/session.h | 3 +- tools/perf/util/tool.h | 3 +- 18 files changed, 1370 insertions(+), 106 deletions(-)Signature · 1 line
2.19.0
Quoted 27 lines · Jiri Olsa
Quoted 10 lines · Alexey Bayduraev
Changes in v12:
- fixed nr_threads=1 cases
- fixed "Woken up %ld times" message
- removed unnecessaryrecord__fini_thread_masksfunction
- moved bytes written/compressed statistics to structrecord_thread
- moved all unnecessary debug messages to verbose=2 level
- renamed "socket" option to "package" for consistency withutil/cputopo.h
- excluded single trace file reading patchesI'm getting perf record hang with:
[root@krava perf]# ./perf record --threads
^C[ perf record: Woken up 1 times to write data ]^C^C^C^C^C
with following backtrace:
(gdb) bt
Quoted 16 lines
#0 0x00007f8115d2885f in __GI___poll (fds=fds@entry=0x7ffd2116b930, nfds=1, timeout=1000) at ../sysdeps/unix/sysv/linux/poll.c:29
#1 0x00007f811574029e in poll (__timeout=<optimized out>, __nfds=<optimized out>, __fds=0x7ffd2116b930) at /usr/include/bits/poll2.h:48
#2 Curl_poll (timeout_ms=<optimized out>, nfds=<optimized out>, ufds=0x7ffd2116b930) at ../../lib/select.c:374
#3 Curl_poll (ufds=0x7ffd2116b930, nfds=<optimized out>, timeout_ms=<optimized out>) at ../../lib/select.c:329
#4 0x00007f8115739cf7 in multi_wait (multi=multi@entry=0x3458c50, extra_fds=extra_fds@entry=0x0, extra_nfds=extra_nfds@entry=0, timeout_ms=<optimized out>,
timeout_ms@entry=1000, ret=ret@entry=0x0, extrawait=extrawait@entry=false, use_wakeup=<optimized out>) at ../../lib/multi.c:1282
#5 0x00007f8115739f26 in multi_wait (use_wakeup=false, extrawait=false, ret=0x0, timeout_ms=1000, extra_nfds=0, extra_fds=0x0, multi=0x3458c50)
at ../../lib/multi.c:1410
#6 curl_multi_wait (multi=multi@entry=0x3458c50, extra_fds=extra_fds@entry=0x0, extra_nfds=extra_nfds@entry=0, timeout_ms=timeout_ms@entry=1000,
ret=ret@entry=0x0) at ../../lib/multi.c:1411
#7 0x00007f811653a7f2 in debuginfod_query_server (c=c@entry=0x2571fb0, build_id=build_id@entry=0x7ffd2116ed70 "c6eee0984964c63e328d13be49d68bd52595ad00",
build_id_len=build_id_len@entry=0, type=type@entry=0x7f811653c3ba "debuginfo", filename=filename@entry=0x0, path=path@entry=0x7ffd2116dcf8)
at /usr/src/debug/elfutils-0.186-1.fc35.x86_64/debuginfod/debuginfod-client.c:1057
#8 0x00007f811653b2a6 in debuginfod_find_debuginfo (client=client@entry=0x2571fb0,
build_id=build_id@entry=0x7ffd2116ed70 "c6eee0984964c63e328d13be49d68bd52595ad00", build_id_len=build_id_len@entry=0, path=path@entry=0x7ffd2116dcf8)
at /usr/src/debug/elfutils-0.186-1.fc35.x86_64/debuginfod/debuginfod-client.c:1511ok, I should have looked closer on that before sending, it seems to be unrelated issues on fedora 35, because it triggers the debuginfo retrieval on exit.. and that might hang forever apparently, please disregard this one
thanks,
jirka