drivers/gpu/drm/i915/i915_perf.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/i915_perf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/i915_perf.c- Extension
.c- Size
- 157067 bytes
- Lines
- 5263
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/anon_inodes.hlinux/nospec.hlinux/sizes.hlinux/uuid.hgem/i915_gem_context.hgem/i915_gem_internal.hgt/intel_engine_pm.hgt/intel_engine_regs.hgt/intel_engine_user.hgt/intel_execlists_submission.hgt/intel_gpu_commands.hgt/intel_gt.hgt/intel_gt_clock_utils.hgt/intel_gt_mcr.hgt/intel_gt_print.hgt/intel_gt_regs.hgt/intel_lrc.hgt/intel_lrc_reg.hgt/intel_rc6.hgt/intel_ring.hgt/uc/intel_guc_slpc.hi915_drv.hi915_file_private.hi915_perf.hi915_perf_oa_regs.hi915_reg.hi915_mmio_range.hselftests/i915_perf.c
Detected Declarations
struct perf_open_propertiesstruct i915_oa_config_bostruct flexfunction i915_oa_config_releasefunction i915_perf_get_oa_configfunction free_oa_config_bofunction gen12_oa_hw_tail_readfunction gen8_oa_hw_tail_readfunction gen7_oa_hw_tail_readfunction oa_report_idfunction oa_report_reasonfunction oa_report_id_clearfunction oa_report_ctx_invalidfunction oa_timestampfunction oa_timestamp_clearfunction oa_context_idfunction oa_context_id_squashfunction fopsfunction recordfunction readfunction readfunction userspacefunction userspacefunction readfunction userspacefunction fullfunction readfunction i915_oa_poll_waitfunction i915_oa_readfunction for_each_gem_enginefunction __store_reg_to_memfunction __read_regfunction gen12_guc_sw_ctx_idfunction gen12_get_render_context_idfunction oa_find_reg_in_lrifunction oa_context_image_offsetfunction set_oa_ctx_ctrl_offsetfunction engine_supports_mi_queryfunction oa_get_render_ctx_idfunction oa_put_render_ctx_idfunction free_oa_bufferfunction free_oa_configsfunction free_noa_waitfunction engine_supports_oafunction engine_supports_oa_formatfunction i915_oa_stream_destroyfunction gen7_init_oa_bufferfunction gen8_init_oa_buffer
Annotated Snippet
static const struct file_operations fops = {
.owner = THIS_MODULE,
.release = i915_perf_release,
.poll = i915_perf_poll,
.read = i915_perf_read,
.unlocked_ioctl = i915_perf_ioctl,
/* Our ioctl have no arguments, so it's safe to use the same function
* to handle 32bits compatibility.
*/
.compat_ioctl = i915_perf_ioctl,
};
/**
* i915_perf_open_ioctl_locked - DRM ioctl() for userspace to open a stream FD
* @perf: i915 perf instance
* @param: The open parameters passed to 'DRM_I915_PERF_OPEN`
* @props: individually validated u64 property value pairs
* @file: drm file
*
* See i915_perf_ioctl_open() for interface details.
*
* Implements further stream config validation and stream initialization on
* behalf of i915_perf_open_ioctl() with the >->perf.lock mutex
* taken to serialize with any non-file-operation driver hooks.
*
* Note: at this point the @props have only been validated in isolation and
* it's still necessary to validate that the combination of properties makes
* sense.
*
* In the case where userspace is interested in OA unit metrics then further
* config validation and stream initialization details will be handled by
* i915_oa_stream_init(). The code here should only validate config state that
* will be relevant to all stream types / backends.
*
* Returns: zero on success or a negative error code.
*/
static int
i915_perf_open_ioctl_locked(struct i915_perf *perf,
struct drm_i915_perf_open_param *param,
struct perf_open_properties *props,
struct drm_file *file)
{
struct i915_gem_context *specific_ctx = NULL;
struct i915_perf_stream *stream = NULL;
unsigned long f_flags = 0;
bool privileged_op = true;
int stream_fd;
int ret;
if (props->single_context) {
u32 ctx_handle = props->ctx_handle;
struct drm_i915_file_private *file_priv = file->driver_priv;
specific_ctx = i915_gem_context_lookup(file_priv, ctx_handle);
if (IS_ERR(specific_ctx)) {
drm_dbg(&perf->i915->drm,
"Failed to look up context with ID %u for opening perf stream\n",
ctx_handle);
ret = PTR_ERR(specific_ctx);
goto err;
}
}
/*
* On Haswell the OA unit supports clock gating off for a specific
* context and in this mode there's no visibility of metrics for the
* rest of the system, which we consider acceptable for a
* non-privileged client.
*
* For Gen8->11 the OA unit no longer supports clock gating off for a
* specific context and the kernel can't securely stop the counters
* from updating as system-wide / global values. Even though we can
* filter reports based on the included context ID we can't block
* clients from seeing the raw / global counter values via
* MI_REPORT_PERF_COUNT commands and so consider it a privileged op to
* enable the OA unit by default.
*
* For Gen12+ we gain a new OAR unit that only monitors the RCS on a
* per context basis. So we can relax requirements there if the user
* doesn't request global stream access (i.e. query based sampling
* using MI_RECORD_PERF_COUNT.
*/
if (IS_HASWELL(perf->i915) && specific_ctx)
privileged_op = false;
else if (GRAPHICS_VER(perf->i915) == 12 && specific_ctx &&
(props->sample_flags & SAMPLE_OA_REPORT) == 0)
privileged_op = false;
if (props->hold_preemption) {
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/nospec.h`, `linux/sizes.h`, `linux/uuid.h`, `gem/i915_gem_context.h`, `gem/i915_gem_internal.h`, `gt/intel_engine_pm.h`, `gt/intel_engine_regs.h`.
- Detected declarations: `struct perf_open_properties`, `struct i915_oa_config_bo`, `struct flex`, `function i915_oa_config_release`, `function i915_perf_get_oa_config`, `function free_oa_config_bo`, `function gen12_oa_hw_tail_read`, `function gen8_oa_hw_tail_read`, `function gen7_oa_hw_tail_read`, `function oa_report_id`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.