Skip to content

Commit

Permalink
ANDROID: KVM: arm64: Move hyp event enable into ro data section
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vdonnefort committed Feb 1, 2023
1 parent 936f394 commit 818d44d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions arch/arm64/kvm/hyp/nvhe/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 818d44d

Please sign in to comment.