• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión403f290c0603f35f2d09c982bf5549b6d0803ec1 (tree)
Tiempo2018-10-19 11:46:53
AutorEmilio G. Cota <cota@braa...>
CommiterRichard Henderson

Log Message

cputlb: read CPUTLBEntry.addr_write atomically

Updates can come from other threads, so readers that do not
take tlb_lock must use atomic_read to avoid undefined
behaviour (UB).

This completes the conversion to tlb_lock. This conversion results
on average in no performance loss, as the following experiments
(run on an Intel i7-6700K CPU @ 4.00GHz) show.

1. aarch64 bootup+shutdown test:

- Before:

Performance counter stats for 'taskset -c 0 ../img/aarch64/die.sh' (10 runs):
7487.087786 task-clock (msec) # 0.998 CPUs utilized ( +- 0.12% )
31,574,905,303 cycles # 4.217 GHz ( +- 0.12% )
57,097,908,812 instructions # 1.81 insns per cycle ( +- 0.08% )
10,255,415,367 branches # 1369.747 M/sec ( +- 0.08% )
173,278,962 branch-misses # 1.69% of all branches ( +- 0.18% )
7.504481349 seconds time elapsed ( +- 0.14% )

- After:

Performance counter stats for 'taskset -c 0 ../img/aarch64/die.sh' (10 runs):
7462.441328 task-clock (msec) # 0.998 CPUs utilized ( +- 0.07% )
31,478,476,520 cycles # 4.218 GHz ( +- 0.07% )
57,017,330,084 instructions # 1.81 insns per cycle ( +- 0.05% )
10,251,929,667 branches # 1373.804 M/sec ( +- 0.05% )
173,023,787 branch-misses # 1.69% of all branches ( +- 0.11% )
7.474970463 seconds time elapsed ( +- 0.07% )

2. SPEC06int:

SPEC06int (test set)
[Y axis: Speedup over master]
1.15 +-+----+------+------+------+------+------+-------+------+------+------+------+------+------+----+-+
| |
1.1 +-+.................................+++.............................+ tlb-lock-v2 (m+++x) +-+
| +++ | +++ tlb-lock-v3 (spinl|ck) |
| +++ | | +++ +++ | | |
1.05 +-+....+++...........####.........|####.+++.|......|.....###....+++...........+++....###.........+-+
| ### ++#| # |# |# ***### +++### +++#+# | +++ | #|# ### |
1 +-+++***+#++++####+++#++#++++++++++#++#+*+*++#++++#+#+****+#++++###++++###++++###++++#+#++++#+#+++-+
| *+* # #++# *** # #### *** # * *++# ****+# *| * # ****|# |# # #|# #+# # # |
0.95 +-+..*.*.#....#..#.*|*..#...#..#.*|*..#.*.*..#.*|.*.#.*++*.#.*++*+#.****.#....#+#....#.#..++#.#..+-+
| * * # # # *|* # # # *|* # * * # *++* # * * # * * # * |* # ++# # # # *** # |
| * * # ++# # *+* # # # *|* # * * # * * # * * # * * # *++* # **** # ++# # * * # |
0.9 +-+..*.*.#...|#..#.*.*..#.++#..#.*|*..#.*.*..#.*..*.#.*..*.#.*..*.#.*..*.#.*.|*.#...|#.#..*.*.#..+-+
| * * # *** # * * # |# # *+* # * * # * * # * * # * * # * * # *++* # |# # * * # |
0.85 +-+..*.*.#..*|*..#.*.*..#.***..#.*.*..#.*.*..#.*..*.#.*..*.#.*..*.#.*..*.#.*..*.#.****.#..*.*.#..+-+
| * * # *+* # * * # *|* # * * # * * # * * # * * # * * # * * # * * # * |* # * * # |
| * * # * * # * * # *+* # * * # * * # * * # * * # * * # * * # * * # * |* # * * # |
0.8 +-+..*.*.#..*.*..#.*.*..#.*.*..#.*.*..#.*.*..#.*..*.#.*..*.#.*..*.#.*..*.#.*..*.#.*++*.#..*.*.#..+-+
| * * # * * # * * # * * # * * # * * # * * # * * # * * # * * # * * # * * # * * # |
0.75 +-+--***##--***###-***###-***###-***###-***###-****##-****##-****##-****##-****##-****##--***##--+-+
400.perlben401.bzip2403.gcc429.m445.gob456.hmme45462.libqua464.h26471.omnet473483.xalancbmkgeomean

Notes:
- tlb-lock-v2 corresponds to an implementation with a mutex.
- tlb-lock-v3 corresponds to the current implementation, i.e.

a spinlock and a single lock acquisition in tlb_set_page_with_attrs.

Signed-off-by: Emilio G. Cota <cota@braap.org>
Message-Id: <20181016153840.25877-1-cota@braap.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Cambiar Resumen

Diferencia incremental

--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -258,7 +258,7 @@ static inline bool tlb_hit_page_anyprot(CPUTLBEntry *tlb_entry,
258258 target_ulong page)
259259 {
260260 return tlb_hit_page(tlb_entry->addr_read, page) ||
261- tlb_hit_page(tlb_entry->addr_write, page) ||
261+ tlb_hit_page(tlb_addr_write(tlb_entry), page) ||
262262 tlb_hit_page(tlb_entry->addr_code, page);
263263 }
264264
@@ -855,7 +855,7 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry,
855855 tlb_fill(cpu, addr, size, MMU_DATA_STORE, mmu_idx, retaddr);
856856
857857 entry = tlb_entry(env, mmu_idx, addr);
858- tlb_addr = entry->addr_write;
858+ tlb_addr = tlb_addr_write(entry);
859859 if (!(tlb_addr & ~(TARGET_PAGE_MASK | TLB_RECHECK))) {
860860 /* RAM access */
861861 uintptr_t haddr = addr + entry->addend;
@@ -904,7 +904,14 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index,
904904 assert_cpu_is_self(ENV_GET_CPU(env));
905905 for (vidx = 0; vidx < CPU_VTLB_SIZE; ++vidx) {
906906 CPUTLBEntry *vtlb = &env->tlb_v_table[mmu_idx][vidx];
907- target_ulong cmp = *(target_ulong *)((uintptr_t)vtlb + elt_ofs);
907+ target_ulong cmp;
908+
909+ /* elt_ofs might correspond to .addr_write, so use atomic_read */
910+#if TCG_OVERSIZED_GUEST
911+ cmp = *(target_ulong *)((uintptr_t)vtlb + elt_ofs);
912+#else
913+ cmp = atomic_read((target_ulong *)((uintptr_t)vtlb + elt_ofs));
914+#endif
908915
909916 if (cmp == page) {
910917 /* Found entry in victim tlb, swap tlb and iotlb. */
@@ -977,7 +984,7 @@ void probe_write(CPUArchState *env, target_ulong addr, int size, int mmu_idx,
977984 uintptr_t index = tlb_index(env, mmu_idx, addr);
978985 CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
979986
980- if (!tlb_hit(entry->addr_write, addr)) {
987+ if (!tlb_hit(tlb_addr_write(entry), addr)) {
981988 /* TLB entry is for a different page */
982989 if (!VICTIM_TLB_HIT(addr_write, addr)) {
983990 tlb_fill(ENV_GET_CPU(env), addr, size, MMU_DATA_STORE,
@@ -995,7 +1002,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
9951002 size_t mmu_idx = get_mmuidx(oi);
9961003 uintptr_t index = tlb_index(env, mmu_idx, addr);
9971004 CPUTLBEntry *tlbe = tlb_entry(env, mmu_idx, addr);
998- target_ulong tlb_addr = tlbe->addr_write;
1005+ target_ulong tlb_addr = tlb_addr_write(tlbe);
9991006 TCGMemOp mop = get_memop(oi);
10001007 int a_bits = get_alignment_bits(mop);
10011008 int s_bits = mop & MO_SIZE;
@@ -1026,7 +1033,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
10261033 tlb_fill(ENV_GET_CPU(env), addr, 1 << s_bits, MMU_DATA_STORE,
10271034 mmu_idx, retaddr);
10281035 }
1029- tlb_addr = tlbe->addr_write & ~TLB_INVALID_MASK;
1036+ tlb_addr = tlb_addr_write(tlbe) & ~TLB_INVALID_MASK;
10301037 }
10311038
10321039 /* Notice an IO access or a needs-MMU-lookup access */
--- a/accel/tcg/softmmu_template.h
+++ b/accel/tcg/softmmu_template.h
@@ -280,7 +280,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
280280 uintptr_t mmu_idx = get_mmuidx(oi);
281281 uintptr_t index = tlb_index(env, mmu_idx, addr);
282282 CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
283- target_ulong tlb_addr = entry->addr_write;
283+ target_ulong tlb_addr = tlb_addr_write(entry);
284284 unsigned a_bits = get_alignment_bits(get_memop(oi));
285285 uintptr_t haddr;
286286
@@ -295,7 +295,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
295295 tlb_fill(ENV_GET_CPU(env), addr, DATA_SIZE, MMU_DATA_STORE,
296296 mmu_idx, retaddr);
297297 }
298- tlb_addr = entry->addr_write & ~TLB_INVALID_MASK;
298+ tlb_addr = tlb_addr_write(entry) & ~TLB_INVALID_MASK;
299299 }
300300
301301 /* Handle an IO access. */
@@ -325,7 +325,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
325325 cannot evict the first. */
326326 page2 = (addr + DATA_SIZE) & TARGET_PAGE_MASK;
327327 entry2 = tlb_entry(env, mmu_idx, page2);
328- if (!tlb_hit_page(entry2->addr_write, page2)
328+ if (!tlb_hit_page(tlb_addr_write(entry2), page2)
329329 && !VICTIM_TLB_HIT(addr_write, page2)) {
330330 tlb_fill(ENV_GET_CPU(env), page2, DATA_SIZE, MMU_DATA_STORE,
331331 mmu_idx, retaddr);
@@ -358,7 +358,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
358358 uintptr_t mmu_idx = get_mmuidx(oi);
359359 uintptr_t index = tlb_index(env, mmu_idx, addr);
360360 CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
361- target_ulong tlb_addr = entry->addr_write;
361+ target_ulong tlb_addr = tlb_addr_write(entry);
362362 unsigned a_bits = get_alignment_bits(get_memop(oi));
363363 uintptr_t haddr;
364364
@@ -373,7 +373,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
373373 tlb_fill(ENV_GET_CPU(env), addr, DATA_SIZE, MMU_DATA_STORE,
374374 mmu_idx, retaddr);
375375 }
376- tlb_addr = entry->addr_write & ~TLB_INVALID_MASK;
376+ tlb_addr = tlb_addr_write(entry) & ~TLB_INVALID_MASK;
377377 }
378378
379379 /* Handle an IO access. */
@@ -403,7 +403,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
403403 cannot evict the first. */
404404 page2 = (addr + DATA_SIZE) & TARGET_PAGE_MASK;
405405 entry2 = tlb_entry(env, mmu_idx, page2);
406- if (!tlb_hit_page(entry2->addr_write, page2)
406+ if (!tlb_hit_page(tlb_addr_write(entry2), page2)
407407 && !VICTIM_TLB_HIT(addr_write, page2)) {
408408 tlb_fill(ENV_GET_CPU(env), page2, DATA_SIZE, MMU_DATA_STORE,
409409 mmu_idx, retaddr);
--- a/include/exec/cpu_ldst.h
+++ b/include/exec/cpu_ldst.h
@@ -126,6 +126,15 @@ extern __thread uintptr_t helper_retaddr;
126126 /* The memory helpers for tcg-generated code need tcg_target_long etc. */
127127 #include "tcg.h"
128128
129+static inline target_ulong tlb_addr_write(const CPUTLBEntry *entry)
130+{
131+#if TCG_OVERSIZED_GUEST
132+ return entry->addr_write;
133+#else
134+ return atomic_read(&entry->addr_write);
135+#endif
136+}
137+
129138 /* Find the TLB index corresponding to the mmu_idx + address pair. */
130139 static inline uintptr_t tlb_index(CPUArchState *env, uintptr_t mmu_idx,
131140 target_ulong addr)
@@ -439,7 +448,7 @@ static inline void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr,
439448 tlb_addr = tlbentry->addr_read;
440449 break;
441450 case 1:
442- tlb_addr = tlbentry->addr_write;
451+ tlb_addr = tlb_addr_write(tlbentry);
443452 break;
444453 case 2:
445454 tlb_addr = tlbentry->addr_code;
--- a/include/exec/cpu_ldst_template.h
+++ b/include/exec/cpu_ldst_template.h
@@ -177,7 +177,7 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,
177177 addr = ptr;
178178 mmu_idx = CPU_MMU_INDEX;
179179 entry = tlb_entry(env, mmu_idx, addr);
180- if (unlikely(entry->addr_write !=
180+ if (unlikely(tlb_addr_write(entry) !=
181181 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
182182 oi = make_memop_idx(SHIFT, mmu_idx);
183183 glue(glue(helper_ret_st, SUFFIX), MMUSUFFIX)(env, addr, v, oi,