tools/tracing/latency/latency-collector.c

Source file repositories/reference/linux-study-clean/tools/tracing/latency/latency-collector.c

File Facts

System
Linux kernel
Corpus path
tools/tracing/latency/latency-collector.c
Extension
.c
Size
50718 bytes
Lines
2109
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct policy {
	const char *name;
	int policy;
	int default_pri;
};

static const struct policy policies[] = {
	{ "other", SCHED_OTHER, DEFAULT_PRI    },
	{ "batch", SCHED_BATCH, DEFAULT_PRI    },
	{ "idle",  SCHED_IDLE,  DEFAULT_PRI    },
	{ "rr",    SCHED_RR,    RT_DEFAULT_PRI },
	{ "fifo",  SCHED_FIFO,  RT_DEFAULT_PRI },
	{ NULL,    0,           DEFAULT_PRI    }
};

/*
 * The default tracer will be the first on this list that is supported by the
 * currently running Linux kernel.
 */
static const char * const relevant_tracers[] = {
	"preemptirqsoff",
	"preemptoff",
	"irqsoff",
	"wakeup",
	"wakeup_rt",
	"wakeup_dl",
	NULL
};

/* This is the list of tracers for which random sleep makes sense */
static const char * const random_tracers[] = {
	"preemptirqsoff",
	"preemptoff",
	"irqsoff",
	NULL
};

static const char *current_tracer;
static bool force_tracer;

struct ftrace_state {
	char *tracer;
	char *thresh;
	bool opt[OPTIDX_NR];
	bool opt_valid[OPTIDX_NR];
	pthread_mutex_t mutex;
};

struct entry {
	int ticket;
	int ticket_completed_ref;
};

struct print_state {
	int ticket_counter;
	int ticket_completed;
	pthread_mutex_t mutex;
	pthread_cond_t cond;
	int cnt;
	pthread_mutex_t cnt_mutex;
};

struct short_msg {
	char buf[160];
	int len;
};

static struct print_state printstate;
static struct ftrace_state save_state;
volatile sig_atomic_t signal_flag;

#define PROB_TABLE_MAX_SIZE (1000)

int probabilities[PROB_TABLE_MAX_SIZE];

struct sleep_table {
	int *table;
	int size;
	pthread_mutex_t mutex;
};

static struct sleep_table sleeptable;

#define QUEUE_SIZE (10)

struct queue {
	struct entry entries[QUEUE_SIZE];
	int next_prod_idx;
	int next_cons_idx;
	pthread_mutex_t mutex;

Annotation

Implementation Notes