linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	Oliver Upton <oliver.upton@linux.dev>,
	 Yang Jihong <yangjihong1@huawei.com>,
	linux-kernel@vger.kernel.org,  linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 4/7] perf machine: Move machine's threads into its own abstraction
Date: Thu, 29 Feb 2024 17:36:05 -0800	[thread overview]
Message-ID: <CAM9d7cj9CgxmvSMLvDa=RM8zPRJpRbKqMkU7_B68HwEX7qo=hg@mail.gmail.com> (raw)
In-Reply-To: <20240229063253.561838-5-irogers@google.com>

On Wed, Feb 28, 2024 at 10:33 PM Ian Rogers <irogers@google.com> wrote:
>
> Move thread_rb_node into the machine.c file. This hides the
> implementation of threads from the rest of the code allowing for it to
> be refactored.
>
> Locking discipline is tightened up in this change. As the lock is now
> encapsulated in threads, the findnew function requires holding it (as
> it already did in machine). Rather than do conditionals with locks
> based on whether the thread should be created (which could potentially
> be error prone with a read lock match with a write unlock), have a
> separate threads__find that won't create the thread and only holds the
> read lock. This effectively duplicates the findnew logic, with the
> existing findnew logic only operating under a write lock assuming
> creation is necessary as a previous find failed. The creation may
> still fail with the write lock due to another thread. The duplication
> is removed in a later next patch that delegates the implementation to
> hashtable.
>
> Signed-off-by: Ian Rogers <irogers@google.com>

Thanks for doing this!  A nit below..

> ---
[SNIP]
> @@ -3228,27 +3258,31 @@ int thread__resolve_callchain(struct thread *thread,
>         return ret;
>  }
>
> -int machine__for_each_thread(struct machine *machine,
> -                            int (*fn)(struct thread *thread, void *p),
> -                            void *priv)
> +int threads__for_each_thread(struct threads *threads,
> +                            int (*fn)(struct thread *thread, void *data),
> +                            void *data)
>  {
> -       struct threads *threads;
> -       struct rb_node *nd;
> -       int rc = 0;
> -       int i;
> +       for (int i = 0; i < THREADS__TABLE_SIZE; i++) {
> +               struct threads_table_entry *table = &threads->table[i];
> +               struct rb_node *nd;
>
> -       for (i = 0; i < THREADS__TABLE_SIZE; i++) {
> -               threads = &machine->threads[i];
> -               for (nd = rb_first_cached(&threads->entries); nd;
> -                    nd = rb_next(nd)) {
> +               for (nd = rb_first_cached(&table->entries); nd; nd = rb_next(nd)) {
>                         struct thread_rb_node *trb = rb_entry(nd, struct thread_rb_node, rb_node);
> +                       int rc = fn(trb->thread, data);
>
> -                       rc = fn(trb->thread, priv);
>                         if (rc != 0)
>                                 return rc;
>                 }
>         }
> -       return rc;
> +       return 0;

Don't we need locking in this function?

Thanks,
Namhyung


> +
> +}
> +
> +int machine__for_each_thread(struct machine *machine,
> +                            int (*fn)(struct thread *thread, void *p),
> +                            void *priv)
> +{
> +       return threads__for_each_thread(&machine->threads, fn, priv);
>  }
>

  reply	other threads:[~2024-03-01  1:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29  6:32 [PATCH v3 0/7] Thread memory improvements and fixes Ian Rogers
2024-02-29  6:32 ` [PATCH v3 1/7] perf report: Sort child tasks by tid Ian Rogers
2024-02-29  6:32 ` [PATCH v3 2/7] perf trace: Ignore thread hashing in summary Ian Rogers
2024-02-29  6:32 ` [PATCH v3 3/7] perf machine: Move fprintf to for_each loop and a callback Ian Rogers
2024-02-29  6:32 ` [PATCH v3 4/7] perf machine: Move machine's threads into its own abstraction Ian Rogers
2024-03-01  1:36   ` Namhyung Kim [this message]
2024-03-01  5:02     ` Ian Rogers
2024-02-29  6:32 ` [PATCH v3 5/7] perf threads: Move threads to its own files Ian Rogers
2024-02-29  6:32 ` [PATCH v3 6/7] perf threads: Switch from rbtree to hashmap Ian Rogers
2024-02-29  6:32 ` [PATCH v3 7/7] perf threads: Reduce table size from 256 to 8 Ian Rogers

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='CAM9d7cj9CgxmvSMLvDa=RM8zPRJpRbKqMkU7_B68HwEX7qo=hg@mail.gmail.com' \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=oliver.upton@linux.dev \
    --cc=peterz@infradead.org \
    --cc=yangjihong1@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).