All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 0/3] drm/panthor: Performance counter implementation with single manual client support
@ 2026-11-26 20:57 Lukas Zapolskas
  2026-11-26 20:57 ` [PATCH v8 1/3] drm/panthor: Add perf setup and session management Lukas Zapolskas
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Lukas Zapolskas @ 2026-11-26 20:57 UTC (permalink / raw)
  To: Daniel Almeida, Alice Ryhl, Boris Brezillon, Steven Price,
	Liviu Dudau, David Airlie, Simona Vetter, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, Akash Goel, Karunika Choo,
	Lukas Zapolskas, Chris Diamand
  Cc: dri-devel, linux-kernel, nd, rust-for-linux, Mihail Atanassov,
	Adrián Larumbe

Hello,

This patch set implements initial support for performance counter
sampling in Panthor, as a follow-up for Adrián Larumbe's patch
set [1]. In response to follow-up comments on v6, uAPI features that
were not being populated in the original series are now dropped, leaving
only the features necessary for the initial implementation.

The Mali performance counters are controlled via a global firmware
interface to point to a buffer that contains samples of either 64 or 128
32-bit counters per block instance. Each of the block types has its own
32-bit enable mask, allowing for finer-grained control of which counters
are emitted. The size of the sample is dictated by the sum of the
FIRMWARE_SIZE and the HARDWARE_SIZE fields, but neither the FW nor the
HW provide sufficient information about what block types are present at
what offsets. This information is architectural, and may change between
different major versions, as well as different firmware revisions.

To work around the instability of the counter block layout, the kernel
maintains its own offset table per GPU, and provides that via
additional block headers inserted into the data. This enables old
userspace clients to interpret a buffer copied over directly from hardware,
and lets users like libGPUCounters[2] embedded in an executable retain some
level of support for counter sampling without being updated.

The following performance counter implementation supports a single
userspace explicitly requesting samples via ioctl, and managing the
consumed samples via a ring buffer and a set of control indices. The
user client passes in the resources to create a session, at which point
they can explicitly enable or disable sampling via the
PERF_SESSION_START/PERF_SESSION_STOP ioctls.

Samples are requested via an explicit PERF_SESSION_SAMPLE ioctl. When
the request round trips back to the KMD, an eventfd is signaled for the
user indicating that the sample is complete and can be found in the
shared user/kernel ring buffer.

Existing performance counter workflows, such as those in game
engines, and user-space power models/governor implementations
require the ability to simultaneously obtain counter data on the same
driver. Though this is not enabled out of the box, handling for multiple
sessions sampling at different cadences is added via the sample
accumulation handling.

Mesa MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35024

Changes in v8:
- Consolidated the series into three patches.
- Converted bitmaps to use DECLARE_BITMAP directly.
- Documented session_try_start and session_try_stop return values.
- Added overflow checks for the user_sample_size.
- Reworked session destruction order.
- Reset session state on start.
- Added graceful failure for perf registration.
- Documented interface use and memory barriers
- Fixed ring buffer size wording in the uAPI docs, and relax user buffer
  size requirements
- Link to v7: https://patch.msgid.link/20261011-panthor-performance-counters-v7-0-12c32495062f@arm.com

Changes in v7:
- Move the perf commands into their own ioctls
- Moved session tracking to the pfile
- Fixed padding on uAPI structs
- Removed the sampler abstraction
- Moved new registers to a separate commit
- Drop the offset argument for session creation
- Drop the count of enabled clients, using the session_list directly
- Removed the r-b's due to significant changes in the patches
- Added check for CAP_PERFMON on session setup
- Fixed architectural handling of prfcnt_en
- Link to v6: https://lore.kernel.org/dri-devel/20251215171453.2506348-1-lukas.zapolskas@arm.com/

Changes in v6:
- xa_erase -> xa_delete to fix up dangling session issues
- Move setting user data into request callback to avoid setting it on error
- Embed the enable mask into the sampler
- Added helper for sample_enable and sampler_disable to eliminate duplicate checks
- Drop PM reference on session enable failure
- Drop the panthor_perf_em_zero function
- Added R-b's for the first several patches
- Added reading of the PRFCNT_FEATURES register on supporting architectures
- link to v5: https://lore.kernel.org/dri-devel/cover.1753449448.git.lukas.zapolskas@arm.com/

Changes in v5:
- Started re-using perf info size fields instead of
  recomputing the size where needed
- Removed panthor_file pointer to the drm_file
- Fixed ordering of subsystem unplug on init failure
- Using the kernel struct size to allocate memory for user-passed
  uAPI struct.
- Inlined panthor_perf_sampler_{suspend,resume} into
  panthor_perf_{suspend,resume}
- Inlined
- Updated all callers of CIRC_SPACE_TO_END to use CIRC_SPACE
  for correct ring buffer wraparound.
- Free the session and sampler enable maps on termination
- Drop the return values from panthor_perf_{suspend,resume}
- Update userdata and end timestamp on accumulation
- Removed the ptdev checks on suspend and resume paths
- Link to v4: https://lore.kernel.org/dri-devel/cover.1747148172.git.lukas.zapolskas@arm.com/

Changes in v4:
- Added sample size to the uAPI.
- Clarified the bit-to-counter mapping for enable masks.
- Fixed IRQ handling: the PERFCNT_THRESHOLD and PERFCNT_OVERFLOW
  interrupts can be handled by checking the difference between the
  REQ and ACK bits, whereas PERFCNT_SAMPLE needs external data to
  validate.
- FW ring buffer indices are now only wrapped when reading the buffer
  and are otherwise left in their pre-wrapped form.
- Accumulation index is now bumped after the first copy.
- All insert and extract index reads now use the proper, full-width
  type.
- L2 slices are now computed via a macro to extract the relevant
  bits from the MEM_FEATURES register. This macro was moved from
  the uAPI due to changes in the register making it unstable.
- Consistently take the sampler lock to check if a sample has been
  requested.
- Link to v3: https://lore.kernel.org/dri-devel/cover.1743517880.git.lukas.zapolskas@arm.com/

Changes in v3:
- Fixed offset issues into FW ring buffer
- Fixed sparse shader core handling
- Added pre- and post- reset handlers
- Added module param to control size of FW ring buffer
- Clarified naming on sampler functions
- Added error logging for PERF_SETUP
- Link to v2: https://lore.kernel.org/dri-devel/20241211165024.490748-1-lukas.zapolskas@arm.com/

RFC v2:
- Link to v1: https://lore.kernel.org/lkml/20240305165820.585245-1-adrian.larumbe@collabora.com/T/#m67d1f89614fe35dc0560e8304d6731eb1a6942b6

[1]: https://lore.kernel.org/lkml/20240305165820.585245-1-adrian.larumbe@collabora.com/T/#m67d1f89614fe35dc0560e8304d6731eb1a6942b6
[2]: https://github.com/ARM-software/libGPUCounters

---
Lukas Zapolskas (3):
      drm/panthor: Add perf setup and session management
      drm/panthor: Implement performance counter firmware sampling
      drm/panthor: Expose performance counter queries and ioctls

 drivers/gpu/drm/panthor/Makefile           |    1 +
 drivers/gpu/drm/panthor/panthor_device.c   |   15 +-
 drivers/gpu/drm/panthor/panthor_device.h   |   12 +-
 drivers/gpu/drm/panthor/panthor_drv.c      |  137 +-
 drivers/gpu/drm/panthor/panthor_fw.c       |    7 +
 drivers/gpu/drm/panthor/panthor_fw.h       |    7 +
 drivers/gpu/drm/panthor/panthor_gpu.c      |    5 +
 drivers/gpu/drm/panthor/panthor_gpu.h      |    2 +
 drivers/gpu/drm/panthor/panthor_gpu_regs.h |    4 +
 drivers/gpu/drm/panthor/panthor_perf.c     | 2030 ++++++++++++++++++++++++++++
 drivers/gpu/drm/panthor/panthor_perf.h     |   39 +
 include/uapi/drm/panthor_drm.h             |  479 +++++++
 12 files changed, 2734 insertions(+), 4 deletions(-)
---
base-commit: 97429bac371273886238bfcf63d78e7405cacb46
change-id: 20260529-panthor-performance-counters-594dea247c2b

Best regards,
--  
Lukas Zapolskas <lukas.zapolskas@arm.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH v8 1/3] drm/panthor: Add perf setup and session management
@ 2026-11-29  2:54 kernel test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2026-11-29  2:54 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "same reports for this branch"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261126-panthor-performance-counters-v8-1-6e7db0ec33f5@arm.com>
References: <20261126-panthor-performance-counters-v8-1-6e7db0ec33f5@arm.com>
TO: Lukas Zapolskas <lukas.zapolskas@arm.com>
TO: Daniel Almeida <daniel.almeida@collabora.com>
TO: Alice Ryhl <aliceryhl@google.com>
TO: Boris Brezillon <bbrezillon@kernel.org>
TO: Steven Price <steven.price@arm.com>
TO: Liviu Dudau <liviu.dudau@arm.com>
TO: David Airlie <airlied@gmail.com>
TO: Simona Vetter <simona@ffwll.ch>
TO: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
TO: Maxime Ripard <mripard@kernel.org>
TO: Thomas Zimmermann <tzimmermann@suse.de>
TO: Akash Goel <akash.goel@arm.com>
TO: Karunika Choo <karunika.choo@arm.com>
TO: Lukas Zapolskas <lukas.zapolskas@arm.com>
TO: Chris Diamand <chris.diamand@arm.com>
CC: dri-devel@lists.freedesktop.org
CC: linux-kernel@vger.kernel.org
CC: rust-for-linux@vger.kernel.org
CC: Mihail Atanassov <mihail.atanassov@arm.com>

Hi Lukas,

kernel test robot noticed the following build errors:

[auto build test ERROR on 97429bac371273886238bfcf63d78e7405cacb46]

url:    https://github.com/intel-lab-lkp/linux/commits/Lukas-Zapolskas/drm-panthor-Add-perf-setup-and-session-management/20261126-205737
base:   97429bac371273886238bfcf63d78e7405cacb46
patch link:    https://lore.kernel.org/r/20261126-panthor-performance-counters-v8-1-6e7db0ec33f5%40arm.com
patch subject: [PATCH v8 1/3] drm/panthor: Add perf setup and session management
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20261129/20261129103739.CXJRb6oD-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261129/20261129103739.CXJRb6oD-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/20261129103739.CXJRb6oD-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/device.h:15,
                    from include/linux/dma-mapping.h:5,
                    from include/linux/dma-buf.h:21,
                    from include/drm/drm_gem.h:38,
                    from drivers/gpu/drm/panthor/panthor_perf.c:6:
   drivers/gpu/drm/panthor/panthor_perf.c: In function 'panthor_perf_bo_get':
   include/drm/drm_print.h:615:46: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
     615 |         dev_##level##type(__drm_to_dev(drm), "[drm] " fmt, ##__VA_ARGS__)
         |                                              ^~~~~~~~
   include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
         |                              ^~~
   include/linux/dev_printk.h:154:56: note: in expansion of macro 'dev_fmt'
     154 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                        ^~~~~~~
   include/drm/drm_print.h:615:9: note: in expansion of macro 'dev_err'
     615 |         dev_##level##type(__drm_to_dev(drm), "[drm] " fmt, ##__VA_ARGS__)
         |         ^~~~
   include/drm/drm_print.h:628:9: note: in expansion of macro '__drm_printk'
     628 |         __drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__)
         |         ^~~~~~~~~~~~
   drivers/gpu/drm/panthor/panthor_perf.c:254:17: note: in expansion of macro 'drm_err'
     254 |                 drm_err(ddev,
         |                 ^~~~~~~
   include/drm/drm_print.h:615:46: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
     615 |         dev_##level##type(__drm_to_dev(drm), "[drm] " fmt, ##__VA_ARGS__)
         |                                              ^~~~~~~~
   include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
         |                              ^~~
   include/linux/dev_printk.h:154:56: note: in expansion of macro 'dev_fmt'
     154 |         dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                        ^~~~~~~
   include/drm/drm_print.h:615:9: note: in expansion of macro 'dev_err'
     615 |         dev_##level##type(__drm_to_dev(drm), "[drm] " fmt, ##__VA_ARGS__)
         |         ^~~~
   include/drm/drm_print.h:628:9: note: in expansion of macro '__drm_printk'
     628 |         __drm_printk((drm), err,, "*ERROR* " fmt, ##__VA_ARGS__)
         |         ^~~~~~~~~~~~
   drivers/gpu/drm/panthor/panthor_perf.c:254:17: note: in expansion of macro 'drm_err'
     254 |                 drm_err(ddev,
         |                 ^~~~~~~
   In file included from <command-line>:
   drivers/gpu/drm/panthor/panthor_perf.c: In function 'session_read_extract_idx.isra':
>> include/linux/compiler_types.h:702:45: error: call to '__compiletime_assert_559' declared with attribute error: Need native word sized stores/loads for atomicity.
     702 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |                                             ^
   include/linux/compiler_types.h:683:25: note: in definition of macro '__compiletime_assert'
     683 |                         prefix ## suffix();                             \
         |                         ^~~~~~
   include/linux/compiler_types.h:702:9: note: in expansion of macro '_compiletime_assert'
     702 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/compiler_types.h:705:9: note: in expansion of macro 'compiletime_assert'
     705 |         compiletime_assert(__native_word(t),                            \
         |         ^~~~~~~~~~~~~~~~~~
   arch/x86/include/asm/barrier.h:69:9: note: in expansion of macro 'compiletime_assert_atomic_type'
      69 |         compiletime_assert_atomic_type(*p);                             \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/barrier.h:176:29: note: in expansion of macro '__smp_load_acquire'
     176 | #define smp_load_acquire(p) __smp_load_acquire(p)
         |                             ^~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/panthor/panthor_perf.c:378:16: note: in expansion of macro 'smp_load_acquire'
     378 |         return smp_load_acquire(&session->control->extract_idx);
         |                ^~~~~~~~~~~~~~~~


vim +/__compiletime_assert_559 +702 include/linux/compiler_types.h

eb5c2d4b45e3d2 Will Deacon 2020-07-21  688  
eb5c2d4b45e3d2 Will Deacon 2020-07-21  689  #define _compiletime_assert(condition, msg, prefix, suffix) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21  690  	__compiletime_assert(condition, msg, prefix, suffix)
eb5c2d4b45e3d2 Will Deacon 2020-07-21  691  
eb5c2d4b45e3d2 Will Deacon 2020-07-21  692  /**
eb5c2d4b45e3d2 Will Deacon 2020-07-21  693   * compiletime_assert - break build and emit msg if condition is false
eb5c2d4b45e3d2 Will Deacon 2020-07-21  694   * @condition: a compile-time constant condition to check
eb5c2d4b45e3d2 Will Deacon 2020-07-21  695   * @msg:       a message to emit if condition is false
eb5c2d4b45e3d2 Will Deacon 2020-07-21  696   *
eb5c2d4b45e3d2 Will Deacon 2020-07-21  697   * In tradition of POSIX assert, this macro will break the build if the
eb5c2d4b45e3d2 Will Deacon 2020-07-21  698   * supplied condition is *false*, emitting the supplied error message if the
eb5c2d4b45e3d2 Will Deacon 2020-07-21  699   * compiler has support to do so.
eb5c2d4b45e3d2 Will Deacon 2020-07-21  700   */
eb5c2d4b45e3d2 Will Deacon 2020-07-21  701  #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @702  	_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
eb5c2d4b45e3d2 Will Deacon 2020-07-21  703  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-29  2:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 20:57 [PATCH v8 0/3] drm/panthor: Performance counter implementation with single manual client support Lukas Zapolskas
2026-11-26 20:57 ` [PATCH v8 1/3] drm/panthor: Add perf setup and session management Lukas Zapolskas
2026-11-26 21:14   ` sashiko-bot
2026-11-27  6:56   ` kernel test robot
2026-11-28 15:33   ` kernel test robot
2026-11-26 20:57 ` [PATCH v8 2/3] drm/panthor: Implement performance counter firmware sampling Lukas Zapolskas
2026-11-26 21:31   ` sashiko-bot
2026-11-28 18:17   ` kernel test robot
2026-11-26 20:57 ` [PATCH v8 3/3] drm/panthor: Expose performance counter queries and ioctls Lukas Zapolskas
2026-11-26 21:16   ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-11-29  2:54 [PATCH v8 1/3] drm/panthor: Add perf setup and session management kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.