From: Rodrigo Campos <rodrigo@sdfg.com.ar>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@kernel.org>, Paul Mackerras <paulus@samba.org>,
Namhyung Kim <namhyung.kim@lge.com>,
LKML <linux-kernel@vger.kernel.org>, Arun Sharma <asharma@fb.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Andi Kleen <andi@firstfloor.org>, David Ahern <dsahern@gmail.com>
Subject: Re: [PATCH 18/21] perf top: Convert to hist_entry_iter
Date: Fri, 7 Feb 2014 13:26:01 +0000 [thread overview]
Message-ID: <20140207132601.GA25259@sdfg.com.ar> (raw)
In-Reply-To: <1391736923-30765-19-git-send-email-namhyung@kernel.org>
On Fri, Feb 07, 2014 at 10:35:20AM +0900, Namhyung Kim wrote:
> Reuse hist_entry_iter__add() function to share the similar code with
> perf report. Note that it needs to be called with hists.lock so tweak
> some internal functions not to deadlock or hold the lock too long.
>
> Tested-by: Arun Sharma <asharma@fb.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/builtin-top.c | 78 ++++++++++++++++++++++++++----------------------
> 1 file changed, 43 insertions(+), 35 deletions(-)
>
> diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
> index 40e430530168..e7d67421eb0f 100644
> --- a/tools/perf/builtin-top.c
> +++ b/tools/perf/builtin-top.c
> @@ -194,6 +194,12 @@ static void perf_top__record_precise_ip(struct perf_top *top,
>
> pthread_mutex_unlock(¬es->lock);
>
> + /*
> + * This function is now called with he->hists->lock held.
> + * Release it before going to sleep.
> + */
> + pthread_mutex_unlock(&he->hists->lock);
> +
> if (err == -ERANGE && !he->ms.map->erange_warned)
> ui__warn_map_erange(he->ms.map, sym, ip);
> else if (err == -ENOMEM) {
> @@ -201,6 +207,8 @@ static void perf_top__record_precise_ip(struct perf_top *top,
> sym->name);
> sleep(1);
> }
> +
> + pthread_mutex_lock(&he->hists->lock);
> }
I've seen Jiri's comment on this on a previous version of the patch, and the
comment now really helps. Thanks :)
But it still feels weird for me unlocking and then re-aquiring the lock at the
end. Maybe is error prone too, as it's easy to add a "return" in between where
we don't have yet aquired the lock and everything breaks, for example. I would
document that this function must always return with that lock acquired. But
maybe this is too personal :)
And just curious, isn't it possible that the caller releases the lock before
calling the function and aquires it after ? This function could then aquire +
release the lock and be done with it. Or do you need that atomicity and know
that nobody else have taken the lock between the caller took it and this
function was called ? Although I'm not sure if this is better... Maybe is the
same at the end, as the caller should (maybe) always unlock before calling.
Also, I realize this is shared code so it might not make any sense or even
complicate things a lot more in some other places where this ends-up being
called. Sorry in advance if this is the case, I really don't know about perf :S
Thanks a lot, and sorry again,
Rodrigo
next prev parent reply other threads:[~2014-02-07 13:26 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-07 1:35 [PATCHSET 00/21] perf tools: Add support to accumulate hist periods (v8) Namhyung Kim
2014-02-07 1:35 ` [PATCH 01/21] perf tools: Introduce struct hist_entry_iter Namhyung Kim
2014-02-07 1:35 ` [PATCH 02/21] perf hists: Add support for accumulated stat of hist entry Namhyung Kim
2014-02-07 1:35 ` [PATCH 03/21] perf hists: Check if accumulated when adding a " Namhyung Kim
2014-02-07 1:35 ` [PATCH 04/21] perf hists: Accumulate hist entry stat based on the callchain Namhyung Kim
2014-02-07 1:35 ` [PATCH 05/21] perf tools: Update cpumode for each cumulative entry Namhyung Kim
2014-02-07 1:35 ` [PATCH 06/21] perf report: Cache cumulative callchains Namhyung Kim
2014-02-07 1:35 ` [PATCH 07/21] perf callchain: Add callchain_cursor_snapshot() Namhyung Kim
2014-02-07 1:35 ` [PATCH 08/21] perf tools: Save callchain info for each cumulative entry Namhyung Kim
2014-02-07 1:35 ` [PATCH 09/21] perf hists: Sort hist entries by accumulated period Namhyung Kim
2014-02-07 1:35 ` [PATCH 10/21] perf ui/hist: Add support to accumulated hist stat Namhyung Kim
2014-02-07 1:35 ` [PATCH 11/21] perf ui/browser: " Namhyung Kim
2014-02-07 1:35 ` [PATCH 12/21] perf ui/gtk: " Namhyung Kim
2014-02-07 1:35 ` [PATCH 13/21] perf tools: Apply percent-limit to cumulative percentage Namhyung Kim
2014-02-07 1:35 ` [PATCH 14/21] perf tools: Add more hpp helper functions Namhyung Kim
2014-02-07 1:35 ` [PATCH 15/21] perf report: Add --children option Namhyung Kim
2014-02-07 1:35 ` [PATCH 16/21] perf report: Add report.children config option Namhyung Kim
2014-02-07 1:35 ` [PATCH 17/21] perf tools: Add callback function to hist_entry_iter Namhyung Kim
2014-02-07 1:35 ` [PATCH 18/21] perf top: Convert " Namhyung Kim
2014-02-07 13:26 ` Rodrigo Campos [this message]
2014-02-10 2:58 ` Namhyung Kim
2014-02-07 1:35 ` [PATCH 19/21] perf top: Add --children option Namhyung Kim
2014-02-07 1:35 ` [PATCH 20/21] perf top: Add top.children config option Namhyung Kim
2014-02-07 1:35 ` [PATCH 21/21] perf tools: Enable --children option by default Namhyung Kim
2014-02-07 3:31 ` [PATCHSET 00/21] perf tools: Add support to accumulate hist periods (v8) Rodrigo Campos
2014-02-10 2:43 ` Namhyung Kim
2014-02-10 8:07 ` Jiri Olsa
2014-02-10 11:00 ` Namhyung Kim
-- strict thread matches above, loose matches on Subject: below --
2014-03-20 5:36 [PATCHSET 00/21] perf tools: Add support to accumulate hist periods (v9) Namhyung Kim
2014-03-20 5:36 ` [PATCH 18/21] perf top: Convert to hist_entry_iter Namhyung Kim
2014-01-23 0:13 [PATCHSET 00/24] perf tools: Add support to accumulate hist periods (v7) Namhyung Kim
2014-01-23 0:14 ` [PATCH 18/21] perf top: Convert to hist_entry_iter Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140207132601.GA25259@sdfg.com.ar \
--to=rodrigo@sdfg.com.ar \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=andi@firstfloor.org \
--cc=asharma@fb.com \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox