drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
Extension
.c
Size
18309 bytes
Lines
680
Domain
Driver Families
Bucket
drivers/gpu
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct amdgpu_pmu_event_attribute {
	struct device_attribute attr;
	const char *event_str;
	unsigned int type;
};

/* record to keep track of pmu entry per pmu type per device */
struct amdgpu_pmu_entry {
	struct list_head entry;
	struct amdgpu_device *adev;
	struct pmu pmu;
	unsigned int pmu_perf_type;
	char *pmu_type_name;
	char *pmu_file_prefix;
	struct attribute_group fmt_attr_group;
	struct amdgpu_pmu_event_attribute *fmt_attr;
	struct attribute_group evt_attr_group;
	struct amdgpu_pmu_event_attribute *evt_attr;
};

static ssize_t amdgpu_pmu_event_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct amdgpu_pmu_event_attribute *amdgpu_pmu_attr;

	amdgpu_pmu_attr = container_of(attr, struct amdgpu_pmu_event_attribute,
									attr);

	if (!amdgpu_pmu_attr->type)
		return sprintf(buf, "%s\n", amdgpu_pmu_attr->event_str);

	return sprintf(buf, "%s,type=0x%x\n",
			amdgpu_pmu_attr->event_str, amdgpu_pmu_attr->type);
}

static LIST_HEAD(amdgpu_pmu_list);


struct amdgpu_pmu_attr {
	const char *name;
	const char *config;
};

struct amdgpu_pmu_type {
	const unsigned int type;
	const unsigned int num_of_type;
};

struct amdgpu_pmu_config {
	struct amdgpu_pmu_attr *formats;
	unsigned int num_formats;
	struct amdgpu_pmu_attr *events;
	unsigned int num_events;
	struct amdgpu_pmu_type *types;
	unsigned int num_types;
};

/*
 * Events fall under two categories:
 *  - PMU typed
 *    Events in /sys/bus/event_source/devices/amdgpu_<pmu_type>_<dev_num> have
 *    performance counter operations handled by one IP <pmu_type>.  Formats and
 *    events should be defined by <pmu_type>_<asic_type>_formats and
 *    <pmu_type>_<asic_type>_events respectively.
 *
 *  - Event config typed
 *    Events in /sys/bus/event_source/devices/amdgpu_<dev_num> have performance
 *    counter operations that can be handled by multiple IPs dictated by their
 *    "type" format field.  Formats and events should be defined by
 *    amdgpu_pmu_formats and <asic_type>_events respectively.  Format field
 *    "type" is generated in amdgpu_pmu_event_show and defined in
 *    <asic_type>_event_config_types.
 */

static struct amdgpu_pmu_attr amdgpu_pmu_formats[NUM_FORMATS_AMDGPU_PMU] = {
	{ .name = "event", .config = "config:0-7" },
	{ .name = "instance", .config = "config:8-15" },
	{ .name = "umask", .config = "config:16-23"},
	{ .name = "type", .config = "config:56-63"}
};

/* Vega20 events */
static struct amdgpu_pmu_attr vega20_events[NUM_EVENTS_VEGA20_MAX] = {
	{ .name = "xgmi_link0_data_outbound",
			.config = "event=0x7,instance=0x46,umask=0x2" },
	{ .name = "xgmi_link1_data_outbound",
			.config = "event=0x7,instance=0x47,umask=0x2" }
};

static struct amdgpu_pmu_type vega20_types[NUM_EVENT_TYPES_VEGA20] = {

Annotation

Implementation Notes