panvk: add u_trace_context to panvk_device

It allocs priv bos for timestamps and uses timestamp_frequency to
convert timestamps to nanoseconds.

There is no trace event to process yet so it is not really used.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32360>
This commit is contained in:
Chia-I Wu 2024-11-22 20:25:35 -08:00 committed by Marge Bot
parent b4d472cd67
commit d340ed6726
6 changed files with 138 additions and 0 deletions

View file

@ -0,0 +1,22 @@
/*
* Copyright 2024 Google LLC
* SPDX-License-Identifier: MIT
*/
#include "panvk_utrace.h"
#include "panvk_device.h"
void
panvk_per_arch(utrace_context_init)(struct panvk_device *dev)
{
u_trace_context_init(&dev->utrace.utctx, NULL, sizeof(uint64_t), 0,
panvk_utrace_create_buffer, panvk_utrace_delete_buffer,
NULL, panvk_utrace_read_ts, NULL, NULL, NULL);
}
void
panvk_per_arch(utrace_context_fini)(struct panvk_device *dev)
{
u_trace_context_fini(&dev->utrace.utctx);
}

View file

@ -27,6 +27,7 @@ libpanvk_files = files(
'panvk_mempool.c',
'panvk_physical_device.c',
'panvk_priv_bo.c',
'panvk_utrace.c',
'panvk_wsi.c',
)
libpanvk_files += [sha1_h]
@ -69,6 +70,7 @@ csf_files = [
'csf/panvk_vX_event.c',
'csf/panvk_vX_exception_handler.c',
'csf/panvk_vX_queue.c',
'csf/panvk_vX_utrace.c',
]
common_per_arch_files = [

View file

@ -20,6 +20,7 @@
#include "kmod/pan_kmod.h"
#include "util/pan_ir.h"
#include "util/perf/u_trace.h"
#include "util/vma.h"
@ -61,6 +62,10 @@ struct panvk_device {
struct panvk_queue *queues[PANVK_MAX_QUEUE_FAMILIES];
int queue_count[PANVK_MAX_QUEUE_FAMILIES];
struct {
struct u_trace_context utctx;
} utrace;
struct {
struct pandecode_context *decode_ctx;
} debug;

View file

@ -0,0 +1,58 @@
/*
* Copyright 2024 Google LLC
* SPDX-License-Identifier: MIT
*/
#include "panvk_utrace.h"
#include "kmod/pan_kmod.h"
#include "util/timespec.h"
#include "panvk_device.h"
#include "panvk_physical_device.h"
#include "panvk_priv_bo.h"
static struct panvk_device *
to_dev(struct u_trace_context *utctx)
{
return container_of(utctx, struct panvk_device, utrace.utctx);
}
void *
panvk_utrace_create_buffer(struct u_trace_context *utctx, uint64_t size_B)
{
struct panvk_device *dev = to_dev(utctx);
struct panvk_priv_bo *bo;
if (panvk_priv_bo_create(dev, size_B, 0, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE,
&bo) != VK_SUCCESS)
return NULL;
return bo;
}
void
panvk_utrace_delete_buffer(struct u_trace_context *utctx, void *buffer)
{
struct panvk_priv_bo *bo = buffer;
panvk_priv_bo_unref(bo);
}
uint64_t
panvk_utrace_read_ts(struct u_trace_context *utctx, void *timestamps,
uint64_t offset_B, void *flush_data)
{
struct panvk_device *dev = to_dev(utctx);
const struct panvk_physical_device *pdev =
to_panvk_physical_device(dev->vk.physical);
const struct pan_kmod_dev_props *props = &pdev->kmod.props;
const struct panvk_priv_bo *bo = timestamps;
assert(props->timestamp_frequency);
const uint64_t *ts_ptr = bo->addr.host + offset_B;
uint64_t ts = *ts_ptr;
if (ts != U_TRACE_NO_TIMESTAMP)
ts = (ts * NSEC_PER_SEC) / props->timestamp_frequency;
return ts;
}

View file

@ -0,0 +1,46 @@
/*
* Copyright 2024 Google LLC
* SPDX-License-Identifier: MIT
*/
#ifndef PANVK_UTRACE_H
#define PANVK_UTRACE_H
#include "util/perf/u_trace.h"
#include "panvk_macros.h"
struct panvk_device;
void *panvk_utrace_create_buffer(struct u_trace_context *utctx,
uint64_t size_B);
void panvk_utrace_delete_buffer(struct u_trace_context *utctx, void *buffer);
uint64_t panvk_utrace_read_ts(struct u_trace_context *utctx, void *timestamps,
uint64_t offset_B, void *flush_data);
#ifdef PAN_ARCH
#if PAN_ARCH >= 10
void panvk_per_arch(utrace_context_init)(struct panvk_device *dev);
void panvk_per_arch(utrace_context_fini)(struct panvk_device *dev);
#else /* PAN_ARCH >= 10 */
static inline void
panvk_per_arch(utrace_context_init)(struct panvk_device *dev)
{
}
static inline void
panvk_per_arch(utrace_context_fini)(struct panvk_device *dev)
{
}
#endif /* PAN_ARCH >= 10 */
#endif /* PAN_ARCH */
#endif /* PANVK_UTRACE_H */

View file

@ -23,6 +23,7 @@
#include "panvk_physical_device.h"
#include "panvk_priv_bo.h"
#include "panvk_queue.h"
#include "panvk_utrace.h"
#include "genxml/decode.h"
#include "genxml/gen_macros.h"
@ -355,6 +356,8 @@ panvk_per_arch(create_device)(struct panvk_physical_device *physical_device,
}
}
panvk_per_arch(utrace_context_init)(device);
*pDevice = panvk_device_to_handle(device);
return VK_SUCCESS;
@ -395,6 +398,8 @@ panvk_per_arch(destroy_device)(struct panvk_device *device,
if (!device)
return;
panvk_per_arch(utrace_context_fini)(device);
for (unsigned i = 0; i < PANVK_MAX_QUEUE_FAMILIES; i++) {
for (unsigned q = 0; q < device->queue_count[i]; q++)
panvk_per_arch(queue_finish)(&device->queues[i][q]);