Commit 2edfb279 authored by Mark Janes's avatar Mark Janes
Browse files

intel: combine common gather routines in INTEL_MEASURE



Anv and iris had separate, similar routines to gather intel_measure
timestamps.  Timestamps are now managed within intel_measure, allowing
those routines to be consolidated.
Acked-by: Kenneth Graunke's avatarKenneth Graunke <kenneth@whitecape.org>
Part-of: <mesa/mesa!7354>
parent d6fc72e2
......@@ -42,9 +42,6 @@ iris_init_screen_measure(struct iris_screen *screen)
if (config == NULL)
return;
list_inithead(&measure_device->queued_snapshots);
pthread_mutex_init(&measure_device->mutex, NULL);
/* the final member of intel_measure_ringbuffer is a zero-length array of
* intel_measure_buffered_result objects. Allocate additional space for
* the buffered objects based on the run-time configurable buffer_size
......@@ -325,60 +322,24 @@ _iris_measure_snapshot(struct iris_context *ice,
}
}
static void
iris_measure_gather(struct iris_context *ice)
{
struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
struct intel_measure_device *measure_device = &screen->measure;
/* gather snapshots */
pthread_mutex_lock(&measure_device->mutex);
/* iterate snapshots and collect if ready */
while (!list_is_empty(&measure_device->queued_snapshots)) {
struct iris_measure_batch *measure =
list_first_entry(&measure_device->queued_snapshots,
struct iris_measure_batch, link);
if (!intel_measure_ready(&measure->base)) {
/* batch has not completed execution */
break;
}
list_del(&measure->link);
assert(measure->bo);
assert(measure->base.index % 2 == 0);
intel_measure_push_result(measure_device, &measure->base);
/* iris_bo_unmap(measure->bo); */
measure->base.index = 0;
measure->base.frame = 0;
iris_destroy_batch_measure(measure);
}
intel_measure_print(measure_device, &screen->devinfo);
pthread_mutex_unlock(&measure_device->mutex);
}
void
iris_destroy_ctx_measure(struct iris_context *ice)
{
/* All outstanding snapshots must be collected before the context is
* destroyed.
*/
iris_measure_gather(ice);
struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
intel_measure_gather(&screen->measure, &screen->devinfo);
}
void
iris_measure_batch_end(struct iris_context *ice, struct iris_batch *batch)
{
const struct intel_measure_config *config = config_from_context(ice);
struct iris_screen *screen = (struct iris_screen *) ice->ctx.screen;
struct iris_measure_batch *iris_measure_batch = batch->measure;
struct intel_measure_batch *measure_batch = &iris_measure_batch->base;
struct intel_measure_device *measure_device =
&((struct iris_screen *) ice->ctx.screen)->measure;
struct intel_measure_device *measure_device = &screen->measure;
if (!config)
return;
......@@ -403,7 +364,7 @@ iris_measure_batch_end(struct iris_context *ice, struct iris_batch *batch)
/* enqueue snapshot for gathering */
pthread_mutex_lock(&measure_device->mutex);
list_addtail(&iris_measure_batch->link, &measure_device->queued_snapshots);
list_addtail(&iris_measure_batch->base.link, &measure_device->queued_snapshots);
batch->measure = NULL;
pthread_mutex_unlock(&measure_device->mutex);
/* init new measure_batch */
......@@ -411,7 +372,7 @@ iris_measure_batch_end(struct iris_context *ice, struct iris_batch *batch)
static int interval = 0;
if (++interval > 10) {
iris_measure_gather(ice);
intel_measure_gather(measure_device, &screen->devinfo);
interval = 0;
}
}
......@@ -429,5 +390,5 @@ iris_measure_frame_end(struct iris_context *ice)
/* increment frame counter */
intel_measure_frame_transition(p_atomic_inc_return(&measure_device->frame));
iris_measure_gather(ice);
intel_measure_gather(measure_device, &screen->devinfo);
}
......@@ -30,7 +30,6 @@ struct iris_screen;
struct iris_measure_batch {
struct iris_bo *bo;
struct list_head link;
struct intel_measure_batch base;
};
......
......@@ -56,10 +56,10 @@ void
intel_measure_init(struct intel_measure_device *device)
{
static bool once = false;
const char *env = getenv("INTEL_MEASURE");
if (unlikely(!once)) {
once = true;
memset(&config, 0, sizeof(struct intel_measure_config));
const char *env = getenv("INTEL_MEASURE");
if (!env)
return;
......@@ -209,7 +209,11 @@ intel_measure_init(struct intel_measure_device *device)
}
device->config = NULL;
if (getenv("INTEL_MEASURE"))
device->frame = 0;
pthread_mutex_init(&device->mutex, NULL);
list_inithead(&device->queued_snapshots);
if (env)
device->config = &config;
}
......@@ -389,7 +393,7 @@ intel_measure_ready(struct intel_measure_batch *batch)
* Depending on configuration, snapshot data may need to be collated before
* writing to the output file.
*/
void
static void
intel_measure_push_result(struct intel_measure_device *device,
struct intel_measure_batch *batch)
{
......@@ -447,7 +451,6 @@ intel_measure_push_result(struct intel_measure_device *device,
}
}
static unsigned
ringbuffer_size(const struct intel_measure_ringbuffer *rb)
{
......@@ -604,7 +607,7 @@ print_combined_results(struct intel_measure_device *measure_device,
/**
* Empty the ringbuffer of events that can be printed.
*/
void
static void
intel_measure_print(struct intel_measure_device *device,
struct gen_device_info *info)
{
......@@ -616,3 +619,42 @@ intel_measure_print(struct intel_measure_device *device,
}
}
/**
* Collect snapshots from completed command buffers and submit them to
* intel_measure for printing.
*/
void
intel_measure_gather(struct intel_measure_device *measure_device,
struct gen_device_info *info)
{
pthread_mutex_lock(&measure_device->mutex);
/* Iterate snapshots and collect if ready. Each snapshot queue will be
* in-order, but we must determine which queue has the oldest batch.
*/
/* iterate snapshots and collect if ready */
while (!list_is_empty(&measure_device->queued_snapshots)) {
struct intel_measure_batch *batch =
list_first_entry(&measure_device->queued_snapshots,
struct intel_measure_batch, link);
if (!intel_measure_ready(batch)) {
/* command buffer has begun execution on the gpu, but has not
* completed.
*/
break;
}
list_del(&batch->link);
assert(batch->index % 2 == 0);
intel_measure_push_result(measure_device, batch);
batch->index = 0;
batch->frame = 0;
}
intel_measure_print(measure_device, info);
pthread_mutex_unlock(&measure_device->mutex);
}
......@@ -141,6 +141,7 @@ struct intel_measure_device {
};
struct intel_measure_batch {
struct list_head link;
unsigned index;
unsigned frame, batch_count, event_count;
uintptr_t framebuffer;
......@@ -157,11 +158,8 @@ void intel_measure_frame_transition(unsigned frame);
bool intel_measure_ready(struct intel_measure_batch *batch);
void intel_measure_push_result(struct intel_measure_device *device,
struct intel_measure_batch *batch);
struct gen_device_info;
void intel_measure_print(struct intel_measure_device *device,
struct gen_device_info *info);
void intel_measure_gather(struct intel_measure_device *device,
struct gen_device_info *info);
#endif /* INTEL_MEASURE_H */
......@@ -32,7 +32,6 @@
struct anv_measure_batch {
struct anv_bo *bo;
struct list_head link;
struct intel_measure_batch base;
};
......@@ -67,11 +66,6 @@ anv_measure_device_init(struct anv_physical_device *device)
/* initialise list of measure structures that await rendering */
struct intel_measure_device *measure_device = &device->measure_device;
pthread_mutex_init(&measure_device->mutex, NULL);
list_inithead(&measure_device->queued_snapshots);
measure_device->frame = 0;
intel_measure_init(measure_device);
struct intel_measure_config *config = measure_device->config;
if (config == NULL)
......@@ -128,48 +122,9 @@ anv_measure_init(struct anv_cmd_buffer *cmd_buffer)
measure->base.timestamps = measure->bo->map;
assert(result == VK_SUCCESS);
list_inithead(&measure->link);
cmd_buffer->measure = measure;
}
/**
* Collect snapshots from completed command buffers and submit them to
* intel_measure for printing.
*/
static void
anv_measure_gather(struct anv_device *device)
{
struct intel_measure_device *measure_device = &device->physical->measure_device;
pthread_mutex_lock(&measure_device->mutex);
/* iterate snapshots and collect if ready */
while (!list_is_empty(&measure_device->queued_snapshots)) {
struct anv_measure_batch *measure =
list_first_entry(&measure_device->queued_snapshots,
struct anv_measure_batch, link);
if (!intel_measure_ready(&measure->base)) {
/* command buffer has begun execution on the gpu, but has not
* completed.
*/
break;
}
list_del(&measure->link);
assert(measure->base.index % 2 == 0);
intel_measure_push_result(measure_device, &measure->base);
measure->base.index = 0;
measure->base.frame = 0;
}
intel_measure_print(measure_device, &device->info);
pthread_mutex_unlock(&measure_device->mutex);
}
static void
anv_measure_start_snapshot(struct anv_cmd_buffer *cmd_buffer,
enum intel_measure_snapshot_type type,
......@@ -359,7 +314,8 @@ anv_measure_reset(struct anv_cmd_buffer *cmd_buffer)
/* it is possible that the command buffer contains snapshots that have not
* yet been processed
*/
anv_measure_gather(device);
intel_measure_gather(&device->physical->measure_device,
&device->info);
assert(cmd_buffer->device != NULL);
......@@ -367,7 +323,7 @@ anv_measure_reset(struct anv_cmd_buffer *cmd_buffer)
measure->base.framebuffer = 0;
measure->base.frame = 0;
measure->base.event_count = 0;
list_inithead(&measure->link);
list_inithead(&measure->base.link);
anv_device_release_bo(device, measure->bo);
VkResult result =
......@@ -386,6 +342,7 @@ anv_measure_destroy(struct anv_cmd_buffer *cmd_buffer)
struct intel_measure_config *config = config_from_command_buffer(cmd_buffer);
struct anv_measure_batch *measure = cmd_buffer->measure;
struct anv_device *device = cmd_buffer->device;
struct anv_physical_device *physical = device->physical;
if (!config)
return;
......@@ -395,7 +352,7 @@ anv_measure_destroy(struct anv_cmd_buffer *cmd_buffer)
/* it is possible that the command buffer contains snapshots that have not
* yet been processed
*/
anv_measure_gather(device);
intel_measure_gather(&physical->measure_device, &physical->info);
anv_device_release_bo(device, measure->bo);
vk_free(&cmd_buffer->pool->alloc, measure);
......@@ -453,7 +410,7 @@ _anv_measure_submit(struct anv_cmd_buffer *cmd_buffer)
/* add to the list of submitted snapshots */
pthread_mutex_lock(&measure_device->mutex);
list_addtail(&measure->link, &measure_device->queued_snapshots);
list_addtail(&measure->base.link, &measure_device->queued_snapshots);
pthread_mutex_unlock(&measure_device->mutex);
}
......@@ -474,7 +431,7 @@ anv_measure_acquire(struct anv_device *device)
intel_measure_frame_transition(p_atomic_inc_return(&measure_device->frame));
/* iterate the queued snapshots and publish those that finished */
anv_measure_gather(device);
intel_measure_gather(measure_device, &device->physical->info);
}
void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment