2 * Copyright (c) 2017 Etnaviv Project
3 * Copyright (C) 2017 Zodiac Inflight Innovations
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Christian Gmeiner <christian.gmeiner@gmail.com>
28 #include "util/u_memory.h"
30 #include "etnaviv_context.h"
31 #include "etnaviv_query_pm.h"
32 #include "etnaviv_screen.h"
35 etna_pm_add_signal(struct etna_pm_query
*pq
, struct etna_perfmon
*perfmon
,
36 const struct etna_perfmon_config
*cfg
)
38 struct etna_perfmon_signal
*signal
= etna_pm_query_signal(perfmon
, cfg
->source
);
44 realloc_query_bo(struct etna_context
*ctx
, struct etna_pm_query
*pq
)
49 pq
->bo
= etna_bo_new(ctx
->screen
->dev
, 64, DRM_ETNA_GEM_CACHE_WC
);
50 if (unlikely(!pq
->bo
))
53 pq
->data
= etna_bo_map(pq
->bo
);
59 etna_pm_query_get(struct etna_cmd_stream
*stream
, struct etna_query
*q
,
62 struct etna_pm_query
*pq
= etna_pm_query(q
);
66 if (flags
== ETNA_PM_PROCESS_PRE
)
71 struct etna_perf p
= {
73 .sequence
= pq
->sequence
,
79 etna_cmd_stream_perf(stream
, &p
);
83 etna_pm_query_update(struct etna_query
*q
)
85 struct etna_pm_query
*pq
= etna_pm_query(q
);
87 if (pq
->data
[0] == pq
->sequence
)
92 etna_pm_destroy_query(struct etna_context
*ctx
, struct etna_query
*q
)
94 struct etna_pm_query
*pq
= etna_pm_query(q
);
101 etna_pm_begin_query(struct etna_context
*ctx
, struct etna_query
*q
)
103 struct etna_pm_query
*pq
= etna_pm_query(q
);
108 etna_pm_query_get(ctx
->stream
, q
, ETNA_PM_PROCESS_PRE
);
114 etna_pm_end_query(struct etna_context
*ctx
, struct etna_query
*q
)
116 etna_pm_query_get(ctx
->stream
, q
, ETNA_PM_PROCESS_POST
);
120 etna_pm_get_query_result(struct etna_context
*ctx
, struct etna_query
*q
,
121 bool wait
, union pipe_query_result
*result
)
123 struct etna_pm_query
*pq
= etna_pm_query(q
);
125 etna_pm_query_update(q
);
131 if (!etna_bo_cpu_prep(pq
->bo
, DRM_ETNA_PREP_READ
))
135 etna_bo_cpu_fini(pq
->bo
);
138 result
->u32
= pq
->data
[2] - pq
->data
[1];
143 static const struct etna_query_funcs hw_query_funcs
= {
144 .destroy_query
= etna_pm_destroy_query
,
145 .begin_query
= etna_pm_begin_query
,
146 .end_query
= etna_pm_end_query
,
147 .get_query_result
= etna_pm_get_query_result
,
151 etna_pm_create_query(struct etna_context
*ctx
, unsigned query_type
)
153 struct etna_perfmon
*perfmon
= ctx
->screen
->perfmon
;
154 const struct etna_perfmon_config
*cfg
;
155 struct etna_pm_query
*pq
;
156 struct etna_query
*q
;
158 cfg
= etna_pm_query_config(query_type
);
162 if (!etna_pm_cfg_supported(perfmon
, cfg
))
165 pq
= CALLOC_STRUCT(etna_pm_query
);
169 if (!realloc_query_bo(ctx
, pq
)) {
175 q
->funcs
= &hw_query_funcs
;
176 q
->type
= query_type
;
178 etna_pm_add_signal(pq
, perfmon
, cfg
);