2022-08-15 22:13:05 +02:00
|
|
|
/*
|
|
|
|
* The per-CPU TranslationBlock jump cache.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ACCEL_TCG_TB_JMP_CACHE_H
|
|
|
|
#define ACCEL_TCG_TB_JMP_CACHE_H
|
|
|
|
|
|
|
|
#define TB_JMP_CACHE_BITS 12
|
|
|
|
#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Accessed in parallel; all accesses to 'tb' must be atomic.
|
2022-08-12 18:53:53 +02:00
|
|
|
* For TARGET_TB_PCREL, accesses to 'pc' must be protected by
|
|
|
|
* a load_acquire/store_release to 'tb'.
|
2022-08-15 22:13:05 +02:00
|
|
|
*/
|
|
|
|
struct CPUJumpCache {
|
2023-01-24 19:01:18 +01:00
|
|
|
struct rcu_head rcu;
|
2022-08-15 22:13:05 +02:00
|
|
|
struct {
|
|
|
|
TranslationBlock *tb;
|
2022-08-12 18:53:53 +02:00
|
|
|
#if TARGET_TB_PCREL
|
|
|
|
target_ulong pc;
|
|
|
|
#endif
|
2022-08-15 22:13:05 +02:00
|
|
|
} array[TB_JMP_CACHE_SIZE];
|
|
|
|
};
|
|
|
|
|
2022-08-12 18:53:53 +02:00
|
|
|
static inline TranslationBlock *
|
|
|
|
tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t hash)
|
|
|
|
{
|
|
|
|
#if TARGET_TB_PCREL
|
|
|
|
/* Use acquire to ensure current load of pc from jc. */
|
|
|
|
return qatomic_load_acquire(&jc->array[hash].tb);
|
|
|
|
#else
|
|
|
|
/* Use rcu_read to ensure current load of pc from *tb. */
|
|
|
|
return qatomic_rcu_read(&jc->array[hash].tb);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline target_ulong
|
|
|
|
tb_jmp_cache_get_pc(CPUJumpCache *jc, uint32_t hash, TranslationBlock *tb)
|
|
|
|
{
|
|
|
|
#if TARGET_TB_PCREL
|
|
|
|
return jc->array[hash].pc;
|
|
|
|
#else
|
|
|
|
return tb_pc(tb);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
tb_jmp_cache_set(CPUJumpCache *jc, uint32_t hash,
|
|
|
|
TranslationBlock *tb, target_ulong pc)
|
|
|
|
{
|
|
|
|
#if TARGET_TB_PCREL
|
|
|
|
jc->array[hash].pc = pc;
|
|
|
|
/* Use store_release on tb to ensure pc is written first. */
|
|
|
|
qatomic_store_release(&jc->array[hash].tb, tb);
|
|
|
|
#else
|
|
|
|
/* Use the pc value already stored in tb->pc. */
|
|
|
|
qatomic_set(&jc->array[hash].tb, tb);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-15 22:13:05 +02:00
|
|
|
#endif /* ACCEL_TCG_TB_JMP_CACHE_H */
|