Linux Perf
builtin-lock.c File Reference
#include <errno.h>
#include <inttypes.h>
#include "builtin.h"
#include "perf.h"
#include "util/evlist.h"
#include "util/evsel.h"
#include "util/util.h"
#include "util/cache.h"
#include "util/symbol.h"
#include "util/thread.h"
#include "util/header.h"
#include <subcmd/parse-options.h>
#include "util/trace-event.h"
#include "util/debug.h"
#include "util/session.h"
#include "util/tool.h"
#include "util/data.h"
#include <sys/types.h>
#include <sys/prctl.h>
#include <semaphore.h>
#include <pthread.h>
#include <math.h>
#include <limits.h>
#include <linux/list.h>
#include <linux/hash.h>
#include <linux/kernel.h>
Include dependency graph for builtin-lock.c:

Go to the source code of this file.

Classes

struct  lock_stat
 
struct  lock_seq_stat
 
struct  thread_stat
 
struct  lock_key
 
struct  trace_lock_handler
 

Macros

#define LOCKHASH_BITS   12
 
#define LOCKHASH_SIZE   (1UL << LOCKHASH_BITS)
 
#define __lockhashfn(key)   hash_long((unsigned long)key, LOCKHASH_BITS)
 
#define lockhashentry(key)   (lockhash_table + __lockhashfn((key)))
 
#define SEQ_STATE_UNINITIALIZED   0 /* initial state */
 
#define SEQ_STATE_RELEASED   1
 
#define SEQ_STATE_ACQUIRING   2
 
#define SEQ_STATE_ACQUIRED   3
 
#define SEQ_STATE_READ_ACQUIRED   4
 
#define SEQ_STATE_CONTENDED   5
 
#define MAX_LOCK_DEPTH   48
 
#define SINGLE_KEY(member)
 
#define DEF_KEY_LOCK(name, fn_suffix)   { #name, lock_stat_key_ ## fn_suffix }
 

Typedefs

typedef int(* tracepoint_handler) (struct perf_evsel *evsel, struct perf_sample *sample)
 

Enumerations

enum  broken_state {
  BROKEN_ACQUIRE, BROKEN_ACQUIRED, BROKEN_CONTENDED, BROKEN_RELEASE,
  BROKEN_MAX
}
 
enum  acquire_flags { TRY_LOCK = 1, READ_LOCK = 2 }
 

Functions

static struct thread_statthread_stat_find (u32 tid)
 
static void thread_stat_insert (struct thread_stat *new)
 
static struct thread_statthread_stat_findnew_after_first (u32 tid)
 
static struct thread_statthread_stat_findnew_first (u32 tid)
 
static int lock_stat_key_wait_time_min (struct lock_stat *one, struct lock_stat *two)
 
static int select_key (void)
 
static void insert_to_result (struct lock_stat *st, int(*bigger)(struct lock_stat *, struct lock_stat *))
 
static struct lock_statpop_from_result (void)
 
static struct lock_statlock_stat_findnew (void *addr, const char *name)
 
static struct lock_seq_statget_seq (struct thread_stat *ts, void *addr)
 
static int report_lock_acquire_event (struct perf_evsel *evsel, struct perf_sample *sample)
 
static int report_lock_acquired_event (struct perf_evsel *evsel, struct perf_sample *sample)
 
static int report_lock_contended_event (struct perf_evsel *evsel, struct perf_sample *sample)
 
static int report_lock_release_event (struct perf_evsel *evsel, struct perf_sample *sample)
 
static int perf_evsel__process_lock_acquire (struct perf_evsel *evsel, struct perf_sample *sample)
 
static int perf_evsel__process_lock_acquired (struct perf_evsel *evsel, struct perf_sample *sample)
 
static int perf_evsel__process_lock_contended (struct perf_evsel *evsel, struct perf_sample *sample)
 
static int perf_evsel__process_lock_release (struct perf_evsel *evsel, struct perf_sample *sample)
 
static void print_bad_events (int bad, int total)
 
static void print_result (void)
 
static void dump_threads (void)
 
static void dump_map (void)
 
static int dump_info (void)
 
static int process_sample_event (struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample, struct perf_evsel *evsel, struct machine *machine)
 
static void sort_result (void)
 
static int __cmd_report (bool display_info)
 
static int __cmd_record (int argc, const char **argv)
 
int cmd_lock (int argc, const char **argv)
 

Variables

static struct perf_sessionsession
 
static struct list_head lockhash_table [LOCKHASH_SIZE]
 
static struct rb_root thread_stats
 
static struct thread_stat *(* thread_stat_findnew )(u32 tid)
 
static const char * sort_key = "acquired"
 
static int(* compare )(struct lock_stat *, struct lock_stat *)
 
static struct rb_root result
 
struct lock_key keys []
 
static int bad_hist [BROKEN_MAX]
 
static struct trace_lock_handler report_lock_ops
 
static struct trace_lock_handlertrace_handler
 
static bool info_threads
 
static bool info_map
 
static const struct perf_evsel_str_handler lock_tracepoints []
 
static bool force
 

Macro Definition Documentation

◆ __lockhashfn

#define __lockhashfn (   key)    hash_long((unsigned long)key, LOCKHASH_BITS)

Definition at line 42 of file builtin-lock.c.

◆ DEF_KEY_LOCK

#define DEF_KEY_LOCK (   name,
  fn_suffix 
)    { #name, lock_stat_key_ ## fn_suffix }

Definition at line 250 of file builtin-lock.c.

◆ LOCKHASH_BITS

#define LOCKHASH_BITS   12

Definition at line 37 of file builtin-lock.c.

◆ LOCKHASH_SIZE

#define LOCKHASH_SIZE   (1UL << LOCKHASH_BITS)

Definition at line 38 of file builtin-lock.c.

◆ lockhashentry

#define lockhashentry (   key)    (lockhash_table + __lockhashfn((key)))

Definition at line 43 of file builtin-lock.c.

◆ MAX_LOCK_DEPTH

#define MAX_LOCK_DEPTH   48

Definition at line 94 of file builtin-lock.c.

◆ SEQ_STATE_ACQUIRED

#define SEQ_STATE_ACQUIRED   3

Definition at line 85 of file builtin-lock.c.

◆ SEQ_STATE_ACQUIRING

#define SEQ_STATE_ACQUIRING   2

Definition at line 84 of file builtin-lock.c.

◆ SEQ_STATE_CONTENDED

#define SEQ_STATE_CONTENDED   5

Definition at line 87 of file builtin-lock.c.

◆ SEQ_STATE_READ_ACQUIRED

#define SEQ_STATE_READ_ACQUIRED   4

Definition at line 86 of file builtin-lock.c.

◆ SEQ_STATE_RELEASED

#define SEQ_STATE_RELEASED   1

Definition at line 83 of file builtin-lock.c.

◆ SEQ_STATE_UNINITIALIZED

#define SEQ_STATE_UNINITIALIZED   0 /* initial state */

Definition at line 82 of file builtin-lock.c.

◆ SINGLE_KEY

#define SINGLE_KEY (   member)
Value:
static int lock_stat_key_ ## member(struct lock_stat *one, \
struct lock_stat *two) \
{ \
return one->member > two->member; \
}

Definition at line 209 of file builtin-lock.c.

Typedef Documentation

◆ tracepoint_handler

typedef int(* tracepoint_handler) (struct perf_evsel *evsel, struct perf_sample *sample)

Definition at line 809 of file builtin-lock.c.

Enumeration Type Documentation

◆ acquire_flags

Enumerator
TRY_LOCK 
READ_LOCK 

Definition at line 394 of file builtin-lock.c.

◆ broken_state

Enumerator
BROKEN_ACQUIRE 
BROKEN_ACQUIRED 
BROKEN_CONTENDED 
BROKEN_RELEASE 
BROKEN_MAX 

Definition at line 384 of file builtin-lock.c.

Function Documentation

◆ __cmd_record()

static int __cmd_record ( int  argc,
const char **  argv 
)
static

Definition at line 912 of file builtin-lock.c.

Here is the call graph for this function:

◆ __cmd_report()

static int __cmd_report ( bool  display_info)
static

Definition at line 859 of file builtin-lock.c.

Here is the call graph for this function:

◆ cmd_lock()

int cmd_lock ( int  argc,
const char **  argv 
)

Definition at line 955 of file builtin-lock.c.

Here is the call graph for this function:

◆ dump_info()

static int dump_info ( void  )
static

Definition at line 793 of file builtin-lock.c.

Here is the call graph for this function:

◆ dump_map()

static void dump_map ( void  )
static

Definition at line 780 of file builtin-lock.c.

◆ dump_threads()

static void dump_threads ( void  )
static

Definition at line 762 of file builtin-lock.c.

Here is the call graph for this function:

◆ get_seq()

static struct lock_seq_stat* get_seq ( struct thread_stat ts,
void *  addr 
)
static

Definition at line 363 of file builtin-lock.c.

Here is the call graph for this function:

◆ insert_to_result()

static void insert_to_result ( struct lock_stat st,
int(*)(struct lock_stat *, struct lock_stat *)  bigger 
)
static

Definition at line 281 of file builtin-lock.c.

◆ lock_stat_findnew()

static struct lock_stat* lock_stat_findnew ( void *  addr,
const char *  name 
)
static

Definition at line 317 of file builtin-lock.c.

Here is the call graph for this function:

◆ lock_stat_key_wait_time_min()

static int lock_stat_key_wait_time_min ( struct lock_stat one,
struct lock_stat two 
)
static

Definition at line 222 of file builtin-lock.c.

◆ perf_evsel__process_lock_acquire()

static int perf_evsel__process_lock_acquire ( struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 659 of file builtin-lock.c.

◆ perf_evsel__process_lock_acquired()

static int perf_evsel__process_lock_acquired ( struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 667 of file builtin-lock.c.

◆ perf_evsel__process_lock_contended()

static int perf_evsel__process_lock_contended ( struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 675 of file builtin-lock.c.

◆ perf_evsel__process_lock_release()

static int perf_evsel__process_lock_release ( struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 683 of file builtin-lock.c.

◆ pop_from_result()

static struct lock_stat* pop_from_result ( void  )
static

Definition at line 303 of file builtin-lock.c.

◆ print_bad_events()

static void print_bad_events ( int  bad,
int  total 
)
static

Definition at line 691 of file builtin-lock.c.

◆ print_result()

static void print_result ( void  )
static

Definition at line 707 of file builtin-lock.c.

Here is the call graph for this function:

◆ process_sample_event()

static int process_sample_event ( struct perf_tool *tool  __maybe_unused,
union perf_event event,
struct perf_sample sample,
struct perf_evsel evsel,
struct machine machine 
)
static

Definition at line 812 of file builtin-lock.c.

Here is the call graph for this function:

◆ report_lock_acquire_event()

static int report_lock_acquire_event ( struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 399 of file builtin-lock.c.

Here is the call graph for this function:

◆ report_lock_acquired_event()

static int report_lock_acquired_event ( struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 471 of file builtin-lock.c.

Here is the call graph for this function:

◆ report_lock_contended_event()

static int report_lock_contended_event ( struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 534 of file builtin-lock.c.

Here is the call graph for this function:

◆ report_lock_release_event()

static int report_lock_release_event ( struct perf_evsel evsel,
struct perf_sample sample 
)
static

Definition at line 589 of file builtin-lock.c.

Here is the call graph for this function:

◆ select_key()

static int select_key ( void  )
static

Definition at line 265 of file builtin-lock.c.

◆ sort_result()

static void sort_result ( void  )
static

Definition at line 838 of file builtin-lock.c.

Here is the call graph for this function:

◆ thread_stat_find()

static struct thread_stat* thread_stat_find ( u32  tid)
static

Definition at line 122 of file builtin-lock.c.

◆ thread_stat_findnew_after_first()

static struct thread_stat* thread_stat_findnew_after_first ( u32  tid)
static

Definition at line 163 of file builtin-lock.c.

Here is the call graph for this function:

◆ thread_stat_findnew_first()

static struct thread_stat * thread_stat_findnew_first ( u32  tid)
static

Definition at line 189 of file builtin-lock.c.

Here is the call graph for this function:

◆ thread_stat_insert()

static void thread_stat_insert ( struct thread_stat new)
static

Definition at line 141 of file builtin-lock.c.

Variable Documentation

◆ bad_hist

int bad_hist[BROKEN_MAX]
static

Definition at line 392 of file builtin-lock.c.

◆ compare

int(* compare) (struct lock_stat *, struct lock_stat *)
static

Definition at line 246 of file builtin-lock.c.

◆ force

bool force
static

Definition at line 857 of file builtin-lock.c.

◆ info_map

bool info_map
static

Definition at line 760 of file builtin-lock.c.

◆ info_threads

bool info_threads
static

Definition at line 760 of file builtin-lock.c.

◆ keys

struct lock_key keys[]
Initial value:
= {
DEF_KEY_LOCK(acquired, nr_acquired),
DEF_KEY_LOCK(contended, nr_contended),
DEF_KEY_LOCK(avg_wait, avg_wait_time),
DEF_KEY_LOCK(wait_total, wait_time_total),
DEF_KEY_LOCK(wait_min, wait_time_min),
DEF_KEY_LOCK(wait_max, wait_time_max),
{ NULL, NULL }
}
#define DEF_KEY_LOCK(name, fn_suffix)
Definition: builtin-lock.c:250

Definition at line 252 of file builtin-lock.c.

◆ lock_tracepoints

const struct perf_evsel_str_handler lock_tracepoints[]
static
Initial value:
= {
{ "lock:lock_acquire", perf_evsel__process_lock_acquire, },
{ "lock:lock_acquired", perf_evsel__process_lock_acquired, },
{ "lock:lock_contended", perf_evsel__process_lock_contended, },
{ "lock:lock_release", perf_evsel__process_lock_release, },
}
static int perf_evsel__process_lock_release(struct perf_evsel *evsel, struct perf_sample *sample)
Definition: builtin-lock.c:683
static int perf_evsel__process_lock_acquire(struct perf_evsel *evsel, struct perf_sample *sample)
Definition: builtin-lock.c:659
static int perf_evsel__process_lock_acquired(struct perf_evsel *evsel, struct perf_sample *sample)
Definition: builtin-lock.c:667
static int perf_evsel__process_lock_contended(struct perf_evsel *evsel, struct perf_sample *sample)
Definition: builtin-lock.c:675

Definition at line 850 of file builtin-lock.c.

◆ lockhash_table

struct list_head lockhash_table[LOCKHASH_SIZE]
static

Definition at line 40 of file builtin-lock.c.

◆ report_lock_ops

struct trace_lock_handler report_lock_ops
static
Initial value:
= {
.acquire_event = report_lock_acquire_event,
.acquired_event = report_lock_acquired_event,
.contended_event = report_lock_contended_event,
.release_event = report_lock_release_event,
}
static int report_lock_acquired_event(struct perf_evsel *evsel, struct perf_sample *sample)
Definition: builtin-lock.c:471
static int report_lock_acquire_event(struct perf_evsel *evsel, struct perf_sample *sample)
Definition: builtin-lock.c:399
static int report_lock_contended_event(struct perf_evsel *evsel, struct perf_sample *sample)
Definition: builtin-lock.c:534
static int report_lock_release_event(struct perf_evsel *evsel, struct perf_sample *sample)
Definition: builtin-lock.c:589

Definition at line 650 of file builtin-lock.c.

◆ result

struct rb_root result
static

Definition at line 248 of file builtin-lock.c.

◆ session

struct perf_session* session
static

Definition at line 34 of file builtin-lock.c.

◆ sort_key

const char* sort_key = "acquired"
static

Definition at line 244 of file builtin-lock.c.

◆ thread_stat_findnew

struct thread_stat*(* thread_stat_findnew) (u32 tid)
static
Initial value:
=
static struct thread_stat * thread_stat_findnew_first(u32 tid)
Definition: builtin-lock.c:189

Definition at line 186 of file builtin-lock.c.

◆ thread_stats

struct rb_root thread_stats
static

Definition at line 120 of file builtin-lock.c.

◆ trace_handler

struct trace_lock_handler* trace_handler
static

Definition at line 657 of file builtin-lock.c.