tools/perf/util/intel-pt.c

Source file repositories/reference/linux-study-clean/tools/perf/util/intel-pt.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/intel-pt.c
Extension
.c
Size
121093 bytes
Lines
4726
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

pid = event->context_switch.next_prev_pid;
		tid = event->context_switch.next_prev_tid;
	} else {
		if (out)
			return 0;
		pid = sample->pid;
		tid = sample->tid;
	}

	if (tid == -1)
		intel_pt_log("context_switch event has no tid\n");

	ret = intel_pt_sync_switch(pt, cpu, tid, sample->time);
	if (ret <= 0)
		return ret;

	return machine__set_current_tid(pt->machine, cpu, pid, tid);
}

static int intel_pt_process_itrace_start(struct intel_pt *pt,
					 union perf_event *event,
					 struct perf_sample *sample)
{
	if (!pt->per_cpu_mmaps)
		return 0;

	intel_pt_log("itrace_start: cpu %d pid %d tid %d time %"PRIu64" tsc %#"PRIx64"\n",
		     sample->cpu, event->itrace_start.pid,
		     event->itrace_start.tid, sample->time,
		     perf_time_to_tsc(sample->time, &pt->tc));

	return machine__set_current_tid(pt->machine, sample->cpu,
					event->itrace_start.pid,
					event->itrace_start.tid);
}

/*
 * Events with data_src are identified by L1_Hit_Indication
 * refer https://github.com/intel/perfmon
 */
static int intel_pt_data_src_fmt(struct intel_pt *pt, struct evsel *evsel)
{
	struct perf_env *env = pt->machine->env;
	int fmt = DATA_SRC_FORMAT_NA;

	if (!env->cpuid)
		return DATA_SRC_FORMAT_ERR;

	/*
	 * PEBS-via-PT is only supported on E-core non-hybrid. Of those only
	 * Gracemont and Crestmont have data_src. Check for:
	 *	Alderlake N   (Gracemont)
	 *	Sierra Forest (Crestmont)
	 *	Grand Ridge   (Crestmont)
	 */

	if (!strncmp(env->cpuid, "GenuineIntel,6,190,", 19))
		fmt = DATA_SRC_FORMAT_GRT;

	if (!strncmp(env->cpuid, "GenuineIntel,6,175,", 19) ||
	    !strncmp(env->cpuid, "GenuineIntel,6,182,", 19))
		fmt = DATA_SRC_FORMAT_CMT;

	if (fmt == DATA_SRC_FORMAT_NA)
		return fmt;

	/*
	 * Only data_src events are:
	 *	mem-loads	event=0xd0,umask=0x5
	 *	mem-stores	event=0xd0,umask=0x6
	 */
	if (evsel->core.attr.type == PERF_TYPE_RAW &&
	    ((evsel->core.attr.config & 0xffff) == 0x5d0 ||
	     (evsel->core.attr.config & 0xffff) == 0x6d0))
		return fmt;

	return DATA_SRC_FORMAT_NA;
}

static int intel_pt_process_aux_output_hw_id(struct intel_pt *pt,
					     union perf_event *event,
					     struct perf_sample *sample)
{
	u64 hw_id = event->aux_output_hw_id.hw_id;
	struct auxtrace_queue *queue;
	struct intel_pt_queue *ptq;
	struct evsel *evsel;

	queue = auxtrace_queues__sample_queue(&pt->queues, sample, pt->session);
	evsel = evlist__id2evsel_strict(pt->session->evlist, sample->id);

Annotation

Implementation Notes