ANDROID: KVM: arm64: Move hyp event enable into ro data section

It is expected for hyp events to be used in hot paths. We then need to
reduce the overhead of having the events placed even when they are
disabled. Moving the variable enabling event tracing into a read-only
section increase the chance of sharing a cache line with immutable
objects and as a consequence making it less likely to get a cache miss.

A RW mapping alias must then be made with the fixmap to turn on and off
events.

Bug: 229972309
Change-Id: Ib15bb3fd16b3adb9a889a730b701fd26171c9d37
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2023-01-27 18:09:24 +00:00
parent 936f394ef7
commit 818d44dd84

View File

@@ -4,13 +4,14 @@
*/
#include <nvhe/trace.h>
#include <nvhe/mm.h>
extern struct hyp_event_id __hyp_event_ids_start[];
extern struct hyp_event_id __hyp_event_ids_end[];
#undef HYP_EVENT
#define HYP_EVENT(__name, __proto, __struct, __assign, __printk) \
atomic_t __name##_enabled = ATOMIC_INIT(0); \
atomic_t __ro_after_init __name##_enabled = ATOMIC_INIT(0); \
struct hyp_event_id hyp_event_id_##__name __section("_hyp_event_ids") = { \
.data = (void *)&__name##_enabled, \
}
@@ -28,11 +29,11 @@ int __pkvm_enable_event(unsigned short id, bool enable)
continue;
enable_key = (atomic_t *)event_id->data;
enable_key = hyp_fixmap_map(__hyp_pa(enable_key));
if (enable)
atomic_set(enable_key, 1);
else
atomic_set(enable_key, 0);
atomic_set(enable_key, enable);
hyp_fixmap_unmap();
return 0;
}