annotate libitm/local.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1 /* Copyright (C) 2008-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
2 Contributed by Richard Henderson <rth@redhat.com>.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of the GNU Transactional Memory Library (libitm).
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 Libitm is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
7 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3 of the License, or
kono
parents:
diff changeset
9 (at your option) any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
kono
parents:
diff changeset
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
kono
parents:
diff changeset
14 more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include "libitm_i.h"
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 namespace GTM HIDDEN {
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 // This function needs to be noinline because we need to prevent that it gets
kono
parents:
diff changeset
30 // inlined into another function that calls further functions. This could
kono
parents:
diff changeset
31 // break our assumption that we only call memcpy and thus only need to
kono
parents:
diff changeset
32 // additionally protect the memcpy stack (see the hack in mask_stack_bottom()).
kono
parents:
diff changeset
33 // Even if that isn't an issue because those other calls don't happen during
kono
parents:
diff changeset
34 // copying, we still need mask_stack_bottom() to be called "close" to the
kono
parents:
diff changeset
35 // memcpy in terms of stack frames, so just ensure that for now using the
kono
parents:
diff changeset
36 // noinline.
kono
parents:
diff changeset
37 void __attribute__((noinline))
kono
parents:
diff changeset
38 gtm_undolog::rollback (gtm_thread* tx, size_t until_size)
kono
parents:
diff changeset
39 {
kono
parents:
diff changeset
40 size_t i, n = undolog.size();
kono
parents:
diff changeset
41 void *top = mask_stack_top(tx);
kono
parents:
diff changeset
42 void *bot = mask_stack_bottom(tx);
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 if (n > 0)
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 for (i = n; i-- > until_size; )
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 void *ptr = (void *) undolog[i--];
kono
parents:
diff changeset
49 size_t len = undolog[i];
kono
parents:
diff changeset
50 size_t words = (len + sizeof(gtm_word) - 1) / sizeof(gtm_word);
kono
parents:
diff changeset
51 i -= words;
kono
parents:
diff changeset
52 // Filter out any updates that overlap the libitm stack. We don't
kono
parents:
diff changeset
53 // bother filtering out just the overlapping bytes because we don't
kono
parents:
diff changeset
54 // merge writes and thus any overlapping write is either bogus or
kono
parents:
diff changeset
55 // would restore data on stack frames that are not in use anymore.
kono
parents:
diff changeset
56 // FIXME The memcpy can/will end up as another call but we
kono
parents:
diff changeset
57 // calculated BOT based on the current function. Can we inline or
kono
parents:
diff changeset
58 // reimplement this without too much trouble due to unaligned calls
kono
parents:
diff changeset
59 // and still have good performance, so that we can remove the hack
kono
parents:
diff changeset
60 // in mask_stack_bottom()?
kono
parents:
diff changeset
61 if (likely(ptr > top || (uint8_t*)ptr + len <= bot))
kono
parents:
diff changeset
62 __builtin_memcpy (ptr, &undolog[i], len);
kono
parents:
diff changeset
63 }
kono
parents:
diff changeset
64 undolog.set_size(until_size);
kono
parents:
diff changeset
65 }
kono
parents:
diff changeset
66 }
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 void ITM_REGPARM
kono
parents:
diff changeset
69 GTM_LB (const void *ptr, size_t len)
kono
parents:
diff changeset
70 {
kono
parents:
diff changeset
71 gtm_thread *tx = gtm_thr();
kono
parents:
diff changeset
72 tx->undolog.log(ptr, len);
kono
parents:
diff changeset
73 }
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 } // namespace GTM
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 using namespace GTM;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* ??? Use configure to determine if aliases are supported. Or convince
kono
parents:
diff changeset
80 the compiler to not just tail call this, but actually generate the
kono
parents:
diff changeset
81 same_body_alias itself. */
kono
parents:
diff changeset
82 void ITM_REGPARM
kono
parents:
diff changeset
83 _ITM_LB (const void *ptr, size_t len)
kono
parents:
diff changeset
84 {
kono
parents:
diff changeset
85 GTM_LB (ptr, len);
kono
parents:
diff changeset
86 }
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 #define ITM_LOG_DEF(T) \
kono
parents:
diff changeset
89 void ITM_REGPARM _ITM_L##T (const _ITM_TYPE_##T *ptr) \
kono
parents:
diff changeset
90 { GTM_LB (ptr, sizeof (*ptr)); }
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 ITM_LOG_DEF(U1)
kono
parents:
diff changeset
93 ITM_LOG_DEF(U2)
kono
parents:
diff changeset
94 ITM_LOG_DEF(U4)
kono
parents:
diff changeset
95 ITM_LOG_DEF(U8)
kono
parents:
diff changeset
96 ITM_LOG_DEF(F)
kono
parents:
diff changeset
97 ITM_LOG_DEF(D)
kono
parents:
diff changeset
98 ITM_LOG_DEF(E)
kono
parents:
diff changeset
99 ITM_LOG_DEF(CF)
kono
parents:
diff changeset
100 ITM_LOG_DEF(CD)
kono
parents:
diff changeset
101 ITM_LOG_DEF(CE)