Skip to content

Commit c822e05

Browse files
drm/i915: expose rcs topology through query uAPI
With the introduction of asymmetric slices in CNL, we cannot rely on the previous SUBSLICE_MASK getparam to tell userspace what subslices are available. Here we introduce a more detailed way of querying the Gen's GPU topology that doesn't aggregate numbers. This is essential for monitoring parts of the GPU with the OA unit, because counters need to be normalized to the number of EUs/subslices/slices. The current aggregated numbers like EU_TOTAL do not gives us sufficient information. The Mesa series making use of this API is : https://patchwork.freedesktop.org/series/38795/ As a bonus we can draw representations of the GPU : https://imgur.com/a/vuqpa v2: Rename uapi struct s/_mask/_info/ (Tvrtko) Report max_slice/subslice/eus_per_subslice rather than strides (Tvrtko) Add uapi macros to read data from *_info structs (Tvrtko) v3: Use !!(v & DRM_I915_BIT()) for uapi macros instead of custom shifts (Tvrtko) v4: factorize query item writting (Tvrtko) tweak uapi struct/define names (Tvrtko) v5: Replace ALIGN() macro (Chris) v6: Updated uapi comments (Tvrtko) Moved flags != 0 checks into vfuncs (Tvrtko) v7: Use access_ok() before copying anything, to avoid overflows (Chris) Switch BUG_ON() to GEM_WARN_ON() (Tvrtko) v8: Tweak uapi comments style to match the coding style (Lionel) v9: Fix error in comment about computation of enabled subslice (Tvrtko) v10: Fix/update comments in uAPI (Sagar) v11: Drop drm_i915_query_(slice|subslice|eu)_info in favor of a single drm_i915_query_topology_info (Joonas) v12: Add subslice_stride/eu_stride in drm_i915_query_topology_info (Joonas) v13: Fix comment in uAPI (Joonas) Signed-off-by: Lionel Landwerlin <[email protected]> Acked-by: Chris Wilson <[email protected]> Reviewed-by: Joonas Lahtinen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent a446ae2 commit c822e05

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

drivers/gpu/drm/i915/i915_query.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,83 @@
88
#include "i915_query.h"
99
#include <uapi/drm/i915_drm.h>
1010

11+
static int query_topology_info(struct drm_i915_private *dev_priv,
12+
struct drm_i915_query_item *query_item)
13+
{
14+
const struct sseu_dev_info *sseu = &INTEL_INFO(dev_priv)->sseu;
15+
struct drm_i915_query_topology_info topo;
16+
u32 slice_length, subslice_length, eu_length, total_length;
17+
18+
if (query_item->flags != 0)
19+
return -EINVAL;
20+
21+
if (sseu->max_slices == 0)
22+
return -ENODEV;
23+
24+
BUILD_BUG_ON(sizeof(u8) != sizeof(sseu->slice_mask));
25+
26+
slice_length = sizeof(sseu->slice_mask);
27+
subslice_length = sseu->max_slices *
28+
DIV_ROUND_UP(sseu->max_subslices,
29+
sizeof(sseu->subslice_mask[0]) * BITS_PER_BYTE);
30+
eu_length = sseu->max_slices * sseu->max_subslices *
31+
DIV_ROUND_UP(sseu->max_eus_per_subslice, BITS_PER_BYTE);
32+
33+
total_length = sizeof(topo) + slice_length + subslice_length + eu_length;
34+
35+
if (query_item->length == 0)
36+
return total_length;
37+
38+
if (query_item->length < total_length)
39+
return -EINVAL;
40+
41+
if (copy_from_user(&topo, u64_to_user_ptr(query_item->data_ptr),
42+
sizeof(topo)))
43+
return -EFAULT;
44+
45+
if (topo.flags != 0)
46+
return -EINVAL;
47+
48+
if (!access_ok(VERIFY_WRITE, u64_to_user_ptr(query_item->data_ptr),
49+
total_length))
50+
return -EFAULT;
51+
52+
memset(&topo, 0, sizeof(topo));
53+
topo.max_slices = sseu->max_slices;
54+
topo.max_subslices = sseu->max_subslices;
55+
topo.max_eus_per_subslice = sseu->max_eus_per_subslice;
56+
57+
topo.subslice_offset = slice_length;
58+
topo.subslice_stride = DIV_ROUND_UP(sseu->max_subslices, BITS_PER_BYTE);
59+
topo.eu_offset = slice_length + subslice_length;
60+
topo.eu_stride =
61+
DIV_ROUND_UP(sseu->max_eus_per_subslice, BITS_PER_BYTE);
62+
63+
if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr),
64+
&topo, sizeof(topo)))
65+
return -EFAULT;
66+
67+
if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr + sizeof(topo)),
68+
&sseu->slice_mask, slice_length))
69+
return -EFAULT;
70+
71+
if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr +
72+
sizeof(topo) + slice_length),
73+
sseu->subslice_mask, subslice_length))
74+
return -EFAULT;
75+
76+
if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr +
77+
sizeof(topo) +
78+
slice_length + subslice_length),
79+
sseu->eu_mask, eu_length))
80+
return -EFAULT;
81+
82+
return total_length;
83+
}
84+
1185
static int (* const i915_query_funcs[])(struct drm_i915_private *dev_priv,
1286
struct drm_i915_query_item *query_item) = {
87+
query_topology_info,
1388
};
1489

1590
int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)

include/uapi/drm/i915_drm.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,7 @@ struct drm_i915_perf_oa_config {
16191619

16201620
struct drm_i915_query_item {
16211621
__u64 query_id;
1622+
#define DRM_I915_QUERY_TOPOLOGY_INFO 1
16221623

16231624
/*
16241625
* When set to zero by userspace, this is filled with the size of the
@@ -1655,6 +1656,67 @@ struct drm_i915_query {
16551656
__u64 items_ptr;
16561657
};
16571658

1659+
/*
1660+
* Data written by the kernel with query DRM_I915_QUERY_TOPOLOGY_INFO :
1661+
*
1662+
* data: contains the 3 pieces of information :
1663+
*
1664+
* - the slice mask with one bit per slice telling whether a slice is
1665+
* available. The availability of slice X can be queried with the following
1666+
* formula :
1667+
*
1668+
* (data[X / 8] >> (X % 8)) & 1
1669+
*
1670+
* - the subslice mask for each slice with one bit per subslice telling
1671+
* whether a subslice is available. The availability of subslice Y in slice
1672+
* X can be queried with the following formula :
1673+
*
1674+
* (data[subslice_offset +
1675+
* X * subslice_stride +
1676+
* Y / 8] >> (Y % 8)) & 1
1677+
*
1678+
* - the EU mask for each subslice in each slice with one bit per EU telling
1679+
* whether an EU is available. The availability of EU Z in subslice Y in
1680+
* slice X can be queried with the following formula :
1681+
*
1682+
* (data[eu_offset +
1683+
* (X * max_subslices + Y) * eu_stride +
1684+
* Z / 8] >> (Z % 8)) & 1
1685+
*/
1686+
struct drm_i915_query_topology_info {
1687+
/*
1688+
* Unused for now. Must be cleared to zero.
1689+
*/
1690+
__u16 flags;
1691+
1692+
__u16 max_slices;
1693+
__u16 max_subslices;
1694+
__u16 max_eus_per_subslice;
1695+
1696+
/*
1697+
* Offset in data[] at which the subslice masks are stored.
1698+
*/
1699+
__u16 subslice_offset;
1700+
1701+
/*
1702+
* Stride at which each of the subslice masks for each slice are
1703+
* stored.
1704+
*/
1705+
__u16 subslice_stride;
1706+
1707+
/*
1708+
* Offset in data[] at which the EU masks are stored.
1709+
*/
1710+
__u16 eu_offset;
1711+
1712+
/*
1713+
* Stride at which each of the EU masks for each subslice are stored.
1714+
*/
1715+
__u16 eu_stride;
1716+
1717+
__u8 data[];
1718+
};
1719+
16581720
#if defined(__cplusplus)
16591721
}
16601722
#endif

0 commit comments

Comments
 (0)