perf cgroup: Avoid needless closing of unopened fd
Subsystems (3)
PATCH 1/4 perf cgroup: Avoid needless closing of unopened fd
Do not bother with close() if fd is not valid, just to silence valgrind:
$ valgrind ./perf script
==59169== Memcheck, a memory error detector
==59169== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==59169== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==59169== Command: ./perf script
==59169==
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()--- tools/perf/util/cgroup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/cgroup.c +2 -1
@@ -107,7 +107,8 @@ static int add_cgroup(struct evlist *evlist, const char *str)static void cgroup__delete (struct cgroup *cgroup) { -close (cgroup->fd); +if (cgroup->fd >=0 ) +close (cgroup->fd);zfree (&cgroup->name);free (cgroup); }
Signature · 1 line
2.25.2
PATCH 2/4 perf tools: Move zstd_fini() to session deletion
Move zstd_fini() call to perf_session__delete(), so that we always cleanup the zstd state when deleting the session.
--- tools/perf/builtin-inject.c | 1 - tools/perf/builtin-record.c | 1 - tools/perf/builtin-report.c | 1 - tools/perf/util/session.c | 1 + 4 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/builtin-inject.c +0 -1
@@ -836,7 +836,6 @@ int cmd_inject(int argc, const char **argv) ret =__cmd_inject (&inject); out_delete: -zstd_fini (&(inject.session->zstd_data));perf_session__delete (inject.session);return ret; }
tools/perf/builtin-record.c +0 -1
@@ -1827,7 +1827,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) } out_delete_session: -zstd_fini (&session->zstd_data);perf_session__delete (session);if (!opts->no_bpf_event)
tools/perf/builtin-report.c +0 -1
@@ -1579,7 +1579,6 @@ int cmd_report(int argc, const char **argv) report.block_reports =NULL ; } -zstd_fini (&(session->zstd_data));perf_session__delete (session);return ret; }
tools/perf/util/session.c +1 -0
@@ -302,6 +302,7 @@ void perf_session__delete(struct perf_session *session)machines__exit (&session->machines);if (session->data)perf_data__close (session->data); +zstd_fini (&session->zstd_data);free (session); }
Signature · 1 line
2.25.2
Re: [PATCH 2/4] perf tools: Move zstd_fini() to session deletion
Quoted 2 lines · Tommi Rantala
Move
zstd_fini()call toperf_session__delete(), so that we always cleanup the zstd state when deleting the session.
it shold be orthogonal with zstd_init calls, which are not currently called within perf_session
I guess zstd_initcould moved to perf_session__new, just need some nice way to pass rec->opts.comp_level
jirka
Quoted 60 lines
Signed-off-by Tommi Rantala <[email protected]>--- tools/perf/builtin-inject.c | 1 - tools/perf/builtin-record.c | 1 - tools/perf/builtin-report.c | 1 - tools/perf/util/session.c | 1 + 4 files changed, 1 insertion(+), 3 deletions(-)tools/perf/builtin-inject.c +0
-1@@ -836,7 +836,6 @@ int cmd_inject(int argc, const char **argv) ret =__cmd_inject (&inject); out_delete: -zstd_fini (&(inject.session->zstd_data));perf_session__delete (inject.session);return ret; }tools/perf/builtin-record.c +0
-1@@ -1827,7 +1827,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) } out_delete_session: -zstd_fini (&session->zstd_data);perf_session__delete (session);if (!opts->no_bpf_event)tools/perf/builtin-report.c +0
-1@@ -1579,7 +1579,6 @@ int cmd_report(int argc, const char **argv) report.block_reports =NULL ; } -zstd_fini (&(session->zstd_data));perf_session__delete (session);return ret; }tools/perf/util/session.c +1
-0@@ -302,6 +302,7 @@ void perf_session__delete(struct perf_session *session)machines__exit (&session->machines);if (session->data)perf_data__close (session->data); +zstd_fini (&session->zstd_data);free (session); }Signature · 1 line
2.25.2
Re: [PATCH 2/4] perf tools: Move zstd_fini() to session deletion
Quoted 9 lines · Jiri Olsa
Quoted 2 lines · Tommi Rantala
Move
zstd_fini()call toperf_session__delete(), so that we always cleanup the zstd state when deleting the session.it shold be orthogonal with
zstd_initcalls, which are not currently called withinperf_sessionI guess
zstd_initcouldmoved toperf_session__new, just need some nice way to passrec->opts.comp_level
Makes sense, I'll post v2 later.
-Tommi
PATCH 3/4 perf tools: Fix segfaults due to missing zstd decompressor initialization
In reply to Tommi RantalaInitialization of zstd decompressor state is done for "perf report" and "perf inject", but missing for other tools, causing segfaults e.g. with "perf script" and "perf annotate" when zstd compressed data is used:
# ./perf record -z -a -- sleep 1 # gdb -q --args ./perf script (gdb) run Program received signal SIGSEGV, Segmentation fault. 0x00007ffff771d4cb in ZSTD_decompressStream () from /lib64/libzstd.so.1 (gdb) bt #0 0x00007ffff771d4cb in ZSTD_decompressStream () from /lib64/libzstd.so.1 #1 0x00000000005c92a8 in zstd_decompress_stream (data=0xc3f8e0, src=0x7ffff6dd3038, src_size=255, dst=0x7ffff61ec028, dst_size=528384) at util/zstd.c:100 #2 0x00000000005262ba in perf_session__process_compressed_event (session=0xc38cc0, event=0x7ffff6dd3030, file_offset=11948080) at util/session.c:73 #3 0x000000000052a596 in perf_session__process_user_event (session=0xc38cc0, event=0x7ffff6dd3030, file_offset=11948080) at util/session.c:1581 #4 0x000000000052ab4b in perf_session__process_event (session=0xc38cc0, event=0x7ffff6dd3030, file_offset=11948080) at util/session.c:1713 #5 0x000000000052bed6 in process_simple (session=0xc38cc0, event=0x7ffff6dd3030, file_offset=11948080) at util/session.c:2209 #6 0x000000000052bcfe in reader__process_events (rd=0x7fffffffb400, session=0xc38cc0, prog=0x7fffffffb420) at util/session.c:2175 #7 0x000000000052bfc2 in __perf_session__process_events (session=0xc38cc0) at util/session.c:2232 #8 0x000000000052c0f3 in perf_session__process_events (session=0xc38cc0) at util/session.c:2265 #9 0x0000000000447266 in __cmd_script (script=0x7fffffffb5c0) at builtin-script.c:2608 #10 0x000000000044ba79 in cmd_script (argc=0, argv=0x7fffffffd330) at builtin-script.c:3988 #11 0x00000000004bf2b8 in run_builtin (p=0xa398f8 <commands+408>, argc=1, argv=0x7fffffffd330) at perf.c:312 #12 0x00000000004bf525 in handle_internal_command (argc=1, argv=0x7fffffffd330) at perf.c:364 #13 0x00000000004bf66c in run_argv (argcp=0x7fffffffd18c, argv=0x7fffffffd180) at perf.c:408 #14 0x00000000004bfa38 in main (argc=1, argv=0x7fffffffd330) at perf.c:538
Split zstd_init() into zstd_decomp_init() and zstd_comp_init(), so that we can do lazy initialization for the decompressor, and handle it all in perf_session to make it easily available to all the tools.
--- tools/perf/builtin-inject.c | 3 --- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 3 --- tools/perf/util/compress.h | 10 ++++++++-- tools/perf/util/session.c | 3 +++ tools/perf/util/zstd.c | 14 +++++++++++++- 6 files changed, 25 insertions(+), 10 deletions(-)
tools/perf/builtin-inject.c +0 -3
@@ -803,9 +803,6 @@ int cmd_inject(int argc, const char **argv)if (IS_ERR (inject.session))return PTR_ERR (inject.session); -if (zstd_init (&(inject.session->zstd_data),0 ) <0 ) -pr_warning ("Decompression initialization failed.\n" ); -if (inject.build_ids) {/* * to make sure the mmap records are ordered correctly
tools/perf/builtin-record.c +1 -1
@@ -1461,7 +1461,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) fd =perf_data__fd (data); rec->session = session; -if (zstd_init (&session->zstd_data, rec->opts.comp_level) <0 ) { +if (zstd_comp_init (&session->zstd_data, rec->opts.comp_level) <0 ) {pr_err ("Compression initialization failed.\n" );return -1 ; }
tools/perf/builtin-report.c +0 -3
@@ -1355,9 +1355,6 @@ int cmd_report(int argc, const char **argv)if (ret)return ret; -if (zstd_init (&(session->zstd_data),0 ) <0 ) -pr_warning ("Decompression initialization failed. Reported data may be incomplete.\n" ); -if (report.queue_size) {ordered_events__set_alloc_size (&session->ordered_events, report.queue_size);
tools/perf/util/compress.h +8 -2
@@ -26,7 +26,8 @@ struct zstd_data {#ifdef HAVE_ZSTD_SUPPORT -int zstd_init (struct zstd_data *data,int level); +int zstd_comp_init (struct zstd_data *data,int level); +int zstd_decomp_init (struct zstd_data *data);int zstd_fini (struct zstd_data *data); size_t zstd_compress_stream_to_records(struct zstd_data *data, void *dst, size_t dst_size,
@@ -37,7 +38,12 @@ size_t zstd_decompress_stream(struct zstd_data *data, void *src, size_t src_size void *dst, size_t dst_size);#else /* !HAVE_ZSTD_SUPPORT */ -static inline int zstd_init (struct zstd_data *data__maybe_unused ,int level__maybe_unused ) +static inline int zstd_comp_init (struct zstd_data *data__maybe_unused ,int level__maybe_unused ) +{ +return 0 ; +} + +static inline int zstd_decomp_init (struct zstd_data *data__maybe_unused ) {return 0 ; }
tools/perf/util/session.c +3 -0
@@ -45,6 +45,9 @@ static int perf_session__process_compressed_event(struct perf_session *session,size_t mmap_len, decomp_len = session->header.env.comp_mmap_len;struct decomp *decomp, *decomp_last = session->decomp_last; +if (zstd_decomp_init (&session->zstd_data) <0 ) +return -1 ; +if (decomp_last) { decomp_last_rem = decomp_last->size - decomp_last->head; decomp_len += decomp_last_rem;
tools/perf/util/zstd.c +13 -1
@@ -5,10 +5,13 @@#include "util/compress.h" #include "util/debug.h" -int zstd_init (struct zstd_data *data,int level) +int zstd_decomp_init (struct zstd_data *data) {size_t ret; +if (data->dstream) +return 0 ; + data->dstream =ZSTD_createDStream ();if (data->dstream ==NULL ) {pr_err ("Couldn't create decompression stream.\n" );
@@ -18,9 +21,18 @@ int zstd_init(struct zstd_data *data, int level) ret =ZSTD_initDStream (data->dstream);if (ZSTD_isError (ret)) {pr_err ("Failed to initialize decompression stream: %s\n" ,ZSTD_getErrorName (ret)); +ZSTD_freeDStream (data->dstream); + data->dstream =NULL ;return -1 ; } +return 0 ; +} + +int zstd_comp_init (struct zstd_data *data,int level) +{ +size_t ret; +if (!level)return 0 ;
Signature · 1 line
2.25.2
Re: [PATCH 3/4] perf tools: Fix segfaults due to missing zstd decompressor initialization
Quoted 26 lines · Tommi Rantala
Initialization of zstd decompressor state is done for "perf report" and "perf inject", but missing for other tools, causing segfaults e.g. with "perf script" and "perf annotate" when zstd compressed data is used:
# ./perf record -z -a -- sleep 1 # gdb -q --args ./perf script (gdb) run Program received signal SIGSEGV, Segmentation fault. 0x00007ffff771d4cb in ZSTD_decompressStream () from /lib64/libzstd.so.1 (gdb) bt #0 0x00007ffff771d4cb in ZSTD_decompressStream () from /lib64/libzstd.so.1 #1 0x00000000005c92a8 in zstd_decompress_stream (data=0xc3f8e0, src=0x7ffff6dd3038, src_size=255, dst=0x7ffff61ec028, dst_size=528384) at util/zstd.c:100 #2 0x00000000005262ba in perf_session__process_compressed_event (session=0xc38cc0, event=0x7ffff6dd3030, file_offset=11948080) at util/session.c:73 #3 0x000000000052a596 in perf_session__process_user_event (session=0xc38cc0, event=0x7ffff6dd3030, file_offset=11948080) at util/session.c:1581 #4 0x000000000052ab4b in perf_session__process_event (session=0xc38cc0, event=0x7ffff6dd3030, file_offset=11948080) at util/session.c:1713 #5 0x000000000052bed6 in process_simple (session=0xc38cc0, event=0x7ffff6dd3030, file_offset=11948080) at util/session.c:2209 #6 0x000000000052bcfe in reader__process_events (rd=0x7fffffffb400, session=0xc38cc0, prog=0x7fffffffb420) at util/session.c:2175 #7 0x000000000052bfc2 in __perf_session__process_events (session=0xc38cc0) at util/session.c:2232 #8 0x000000000052c0f3 in perf_session__process_events (session=0xc38cc0) at util/session.c:2265 #9 0x0000000000447266 in __cmd_script (script=0x7fffffffb5c0) at builtin-script.c:2608 #10 0x000000000044ba79 in cmd_script (argc=0, argv=0x7fffffffd330) at builtin-script.c:3988 #11 0x00000000004bf2b8 in run_builtin (p=0xa398f8 <commands+408>, argc=1, argv=0x7fffffffd330) at perf.c:312 #12 0x00000000004bf525 in handle_internal_command (argc=1, argv=0x7fffffffd330) at perf.c:364 #13 0x00000000004bf66c in run_argv (argcp=0x7fffffffd18c, argv=0x7fffffffd180) at perf.c:408 #14 0x00000000004bfa38 in main (argc=1, argv=0x7fffffffd330) at perf.c:538
Quoted 3 lines
Split
zstd_init()intozstd_decomp_init()andzstd_comp_init(), so that we can do lazy initialization for the decompressor, and handle it all inperf_sessionto make it easily available to all the tools.
Alexey, could you please check on this one?
thanks,
jirka
Quoted 135 lines
Signed-off-by Tommi Rantala <[email protected]>--- tools/perf/builtin-inject.c | 3 --- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 3 --- tools/perf/util/compress.h | 10 ++++++++-- tools/perf/util/session.c | 3 +++ tools/perf/util/zstd.c | 14 +++++++++++++- 6 files changed, 25 insertions(+), 10 deletions(-)tools/perf/builtin-inject.c +0
-3@@ -803,9 +803,6 @@ int cmd_inject(int argc, const char **argv)if (IS_ERR (inject.session))return PTR_ERR (inject.session); -if (zstd_init (&(inject.session->zstd_data),0 ) <0 ) -pr_warning ("Decompression initialization failed.\n" ); -if (inject.build_ids) {/* * to make sure the mmap records are ordered correctly tools/perf/builtin-record.c +1
-1@@ -1461,7 +1461,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) fd =perf_data__fd (data); rec->session = session; -if (zstd_init (&session->zstd_data, rec->opts.comp_level) <0 ) { +if (zstd_comp_init (&session->zstd_data, rec->opts.comp_level) <0 ) {pr_err ("Compression initialization failed.\n" );return -1 ; }tools/perf/builtin-report.c +0
-3@@ -1355,9 +1355,6 @@ int cmd_report(int argc, const char **argv)if (ret)return ret; -if (zstd_init (&(session->zstd_data),0 ) <0 ) -pr_warning ("Decompression initialization failed. Reported data may be incomplete.\n" ); -if (report.queue_size) {ordered_events__set_alloc_size (&session->ordered_events, report.queue_size);tools/perf/util/compress.h +8
-2@@ -26,7 +26,8 @@ struct zstd_data {#ifdef HAVE_ZSTD_SUPPORT -int zstd_init (struct zstd_data *data,int level); +int zstd_comp_init (struct zstd_data *data,int level); +int zstd_decomp_init (struct zstd_data *data);int zstd_fini (struct zstd_data *data); size_t zstd_compress_stream_to_records(struct zstd_data *data, void *dst, size_t dst_size,@@ -37,7 +38,12 @@ size_t zstd_decompress_stream(struct zstd_data *data, void *src, size_t src_size void *dst, size_t dst_size);#else /* !HAVE_ZSTD_SUPPORT */ -static inline int zstd_init (struct zstd_data *data__maybe_unused ,int level__maybe_unused ) +static inline int zstd_comp_init (struct zstd_data *data__maybe_unused ,int level__maybe_unused ) +{ +return 0 ; +} + +static inline int zstd_decomp_init (struct zstd_data *data__maybe_unused ) {return 0 ; }tools/perf/util/session.c +3
-0@@ -45,6 +45,9 @@ static int perf_session__process_compressed_event(struct perf_session *session,size_t mmap_len, decomp_len = session->header.env.comp_mmap_len;struct decomp *decomp, *decomp_last = session->decomp_last; +if (zstd_decomp_init (&session->zstd_data) <0 ) +return -1 ; +if (decomp_last) { decomp_last_rem = decomp_last->size - decomp_last->head; decomp_len += decomp_last_rem;tools/perf/util/zstd.c +13
-1@@ -5,10 +5,13 @@#include "util/compress.h" #include "util/debug.h" -int zstd_init (struct zstd_data *data,int level) +int zstd_decomp_init (struct zstd_data *data) {size_t ret; +if (data->dstream) +return 0 ; + data->dstream =ZSTD_createDStream ();if (data->dstream ==NULL ) {pr_err ("Couldn't create decompression stream.\n" );@@ -18,9 +21,18 @@ int zstd_init(struct zstd_data *data, int level) ret =ZSTD_initDStream (data->dstream);if (ZSTD_isError (ret)) {pr_err ("Failed to initialize decompression stream: %s\n" ,ZSTD_getErrorName (ret)); +ZSTD_freeDStream (data->dstream); + data->dstream =NULL ;return -1 ; } +return 0 ; +} + +int zstd_comp_init (struct zstd_data *data,int level) +{ +size_t ret; +if (!level)return 0 ;Signature · 1 line
2.25.2
PATCH 4/4 perf bench: Fix div-by-zero if runtime is zero
In reply to Tommi RantalaFix div-by-zero if runtime is zero:
$ perf bench futex hash --runtime=0 # Running 'futex/hash' benchmark: Run summary [PID 12090]: 4 threads, each operating on 1024 [private] futexes for 0 secs. Floating point exception (core dumped)
--- tools/perf/bench/epoll-wait.c | 3 ++- tools/perf/bench/futex-hash.c | 3 ++- tools/perf/bench/futex-lock-pi.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)
tools/perf/bench/epoll-wait.c +2 -1
@@ -519,7 +519,8 @@ int bench_epoll_wait(int argc, const char **argv)qsort (worker, nthreads,sizeof (struct worker ), cmpworker);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);
tools/perf/bench/futex-hash.c +2 -1
@@ -205,7 +205,8 @@ int bench_futex_hash(int argc, const char **argv)pthread_mutex_destroy (&thread_lock);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);if (!silent) {if (nfutexes ==1 )
tools/perf/bench/futex-lock-pi.c +2 -1
@@ -211,7 +211,8 @@ int bench_futex_lock_pi(int argc, const char **argv)pthread_mutex_destroy (&thread_lock);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);if (!silent)
Signature · 1 line
2.25.2
Re: [PATCH 4/4] perf bench: Fix div-by-zero if runtime is zero
Quoted 8 lines · Tommi Rantala
Fix div-by-zero if runtime is zero:
$ perf bench futex hash --runtime=0 # Running 'futex/hash' benchmark: Run summary [PID 12090]: 4 threads, each operating on 1024 [private] futexes for 0 secs. Floating point exception (core dumped)Signed-off-by Tommi Rantala <[email protected]>
thanks,
jirka
Quoted 51 lines
--- tools/perf/bench/epoll-wait.c | 3 ++- tools/perf/bench/futex-hash.c | 3 ++- tools/perf/bench/futex-lock-pi.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)tools/perf/bench/epoll-wait.c +2
-1@@ -519,7 +519,8 @@ int bench_epoll_wait(int argc, const char **argv)qsort (worker, nthreads,sizeof (struct worker ), cmpworker);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);tools/perf/bench/futex-hash.c +2
-1@@ -205,7 +205,8 @@ int bench_futex_hash(int argc, const char **argv)pthread_mutex_destroy (&thread_lock);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);if (!silent) {if (nfutexes ==1 )tools/perf/bench/futex-lock-pi.c +2
-1@@ -211,7 +211,8 @@ int bench_futex_lock_pi(int argc, const char **argv)pthread_mutex_destroy (&thread_lock);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);if (!silent)Signature · 1 line
2.25.2
Arnaldo Carvalho de Melo
AppliedRe: [PATCH 4/4] perf bench: Fix div-by-zero if runtime is zero
Em Mon, Apr 20, 2020 at 11:05:26AM +0200, Jiri Olsa escreveu:
Quoted 11 lines · Tommi Rantala
Quoted 8 lines
Fix div-by-zero if runtime is zero:
$ perf bench futex hash --runtime=0 # Running 'futex/hash' benchmark: Run summary [PID 12090]: 4 threads, each operating on 1024 [private] futexes for 0 secs. Floating point exception (core dumped)Signed-off-by Tommi Rantala <[email protected]>Acked-by Jiri Olsa <[email protected]>
Thanks, applied,
- Arnaldo
[tip: perf/core] perf bench: Fix div-by-zero if runtime is zero
In reply to Tommi RantalaThe following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 41e7c32b978974adaadd4808ba42f9026634dca3 Gitweb: https://git.kernel.org/tip/41e7c32b978974adaadd4808ba42f9026634dca3 Author: Tommi Rantala <[email protected]> AuthorDate: Fri, 17 Apr 2020 16:23:29 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Wed, 22 Apr 2020 10:01:33 -03:00
perf bench: Fix div-by-zero if runtime is zero
Fix div-by-zero if runtime is zero:
$ perf bench futex hash --runtime=0 # Running 'futex/hash' benchmark: Run summary [PID 12090]: 4 threads, each operating on 1024 [private] futexes for 0 secs. Floating point exception (core dumped)
--- tools/perf/bench/epoll-wait.c | 3 ++- tools/perf/bench/futex-hash.c | 3 ++- tools/perf/bench/futex-lock-pi.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-)
tools/perf/bench/epoll-wait.c +2 -1
@@ -519,7 +519,8 @@ int bench_epoll_wait(int argc, const char **argv)qsort (worker, nthreads,sizeof (struct worker ), cmpworker);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);
tools/perf/bench/futex-hash.c +2 -1
@@ -205,7 +205,8 @@ int bench_futex_hash(int argc, const char **argv)pthread_mutex_destroy (&thread_lock);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);if (!silent) {if (nfutexes ==1 )
tools/perf/bench/futex-lock-pi.c +2 -1
@@ -211,7 +211,8 @@ int bench_futex_lock_pi(int argc, const char **argv)pthread_mutex_destroy (&thread_lock);for (i =0 ; i < nthreads; i++) { -unsigned long t = worker[i].ops / bench__runtime.tv_sec; +unsigned long t = bench__runtime.tv_sec >0 ? + worker[i].ops / bench__runtime.tv_sec :0 ;update_stats (&throughput_stats, t);if (!silent)
Quoted 17 lines · Tommi Rantala
Do not bother with
close()if fd is not valid, just to silence valgrind:$ valgrind ./perf script ==59169== Memcheck, a memory error detector ==59169== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==59169== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info ==59169== Command: ./perf script ==59169== ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close()
Quoted 1 line
Signed-off-by Tommi Rantala <[email protected]>
thanks,
jirka
Quoted 21 lines
--- tools/perf/util/cgroup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tools/perf/util/cgroup.c +2
-1@@ -107,7 +107,8 @@ static int add_cgroup(struct evlist *evlist, const char *str)static void cgroup__delete (struct cgroup *cgroup) { -close (cgroup->fd); +if (cgroup->fd >=0 ) +close (cgroup->fd);zfree (&cgroup->name);free (cgroup); }Signature · 1 line
2.25.2
Arnaldo Carvalho de Melo
AppliedEm Mon, Apr 20, 2020 at 10:48:47AM +0200, Jiri Olsa escreveu:
Quoted 18 lines · Tommi Rantala
Quoted 17 lines
Do not bother with
close()if fd is not valid, just to silence valgrind:$ valgrind ./perf script ==59169== Memcheck, a memory error detector ==59169== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==59169== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info ==59169== Command: ./perf script ==59169== ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close() ==59169== Warning: invalid file descriptor -1 in syscall close()
Quoted 3 lines
Quoted 1 line
Signed-off-by Tommi Rantala <[email protected]>Acked-by Jiri Olsa <[email protected]>
Thanks, applied,
- Arnaldo
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: d2e7d8636fb7d3e30aa8f894003f9e293ea62eea Gitweb: https://git.kernel.org/tip/d2e7d8636fb7d3e30aa8f894003f9e293ea62eea Author: Tommi Rantala <[email protected]> AuthorDate: Fri, 17 Apr 2020 16:23:26 +03:00 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitterDate: Wed, 22 Apr 2020 10:01:33 -03:00
perf cgroup: Avoid needless closing of unopened fd
Do not bother with close() if fd is not valid, just to silence valgrind:
$ valgrind ./perf script
==59169== Memcheck, a memory error detector
==59169== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==59169== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==59169== Command: ./perf script
==59169==
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()
==59169== Warning: invalid file descriptor -1 in syscall close()--- tools/perf/util/cgroup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/cgroup.c +2 -1
@@ -107,7 +107,8 @@ found:static void cgroup__delete (struct cgroup *cgroup) { -close (cgroup->fd); +if (cgroup->fd >=0 ) +close (cgroup->fd);zfree (&cgroup->name);free (cgroup); }