Skip to content

Commit d436f90

Browse files
captain5050namhyung
authored andcommitted
perf machine: Move machine's threads into its own abstraction
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 <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Oliver Upton <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 45ac496 commit d436f90

File tree

5 files changed

+243
-203
lines changed

5 files changed

+243
-203
lines changed

tools/perf/util/bpf_lock_contention.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static const char *lock_contention_get_name(struct lock_contention *con,
328328

329329
/* do not update idle comm which contains CPU number */
330330
if (pid) {
331-
struct thread *t = __machine__findnew_thread(machine, /*pid=*/-1, pid);
331+
struct thread *t = machine__findnew_thread(machine, /*pid=*/-1, pid);
332332

333333
if (t == NULL)
334334
return name;
@@ -422,7 +422,7 @@ int lock_contention_read(struct lock_contention *con)
422422
account_end_timestamp(con);
423423

424424
if (con->aggr_mode == LOCK_AGGR_TASK) {
425-
struct thread *idle = __machine__findnew_thread(machine,
425+
struct thread *idle = machine__findnew_thread(machine,
426426
/*pid=*/0,
427427
/*tid=*/0);
428428
thread__set_comm(idle, "swapper", /*timestamp=*/0);

0 commit comments

Comments
 (0)