Skip to content

Commit ee2f2f4

Browse files
committed
Use SSE-less memcpy for valgrind profiling
1 parent 186a07f commit ee2f2f4

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

.github/workflows/push.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ env:
4343
CXX: ccache g++
4444
jobs:
4545
LINUX_X64:
46+
if: false
4647
services:
4748
mysql:
4849
image: mysql:8
@@ -135,6 +136,7 @@ jobs:
135136
if: ${{ !matrix.asan }}
136137
uses: ./.github/actions/verify-generated-files
137138
MACOS_DEBUG_NTS:
139+
if: false
138140
runs-on: macos-12
139141
steps:
140142
- name: git checkout
@@ -168,6 +170,7 @@ jobs:
168170
- name: Verify generated files are up to date
169171
uses: ./.github/actions/verify-generated-files
170172
WINDOWS:
173+
if: false
171174
name: WINDOWS_X64_ZTS
172175
runs-on: windows-2019
173176
env:
@@ -223,6 +226,7 @@ jobs:
223226
set -x
224227
./buildconf --force
225228
./configure \
229+
CFLAGS="-fno-memcpy -fno-memmove -fno-memset"
226230
--disable-debug \
227231
--enable-mbstring \
228232
--enable-opcache \
@@ -264,6 +268,44 @@ jobs:
264268
path: benchmark/repos/data
265269
- name: Benchmark
266270
run: php benchmark/benchmark.php true
271+
- name: Benchmark 2
272+
run: php benchmark/benchmark.php true
273+
- name: Benchmark 3
274+
run: php benchmark/benchmark.php true
275+
- name: Benchmark 4
276+
run: php benchmark/benchmark.php true
277+
- name: Benchmark 5
278+
run: php benchmark/benchmark.php true
279+
- name: Benchmark 6
280+
run: php benchmark/benchmark.php true
281+
- name: Benchmark 7
282+
run: php benchmark/benchmark.php true
283+
- name: Benchmark 8
284+
run: php benchmark/benchmark.php true
285+
- name: Benchmark 9
286+
run: php benchmark/benchmark.php true
287+
- name: Benchmark 10
288+
run: php benchmark/benchmark.php true
289+
- name: Benchmark 11
290+
run: php benchmark/benchmark.php true
291+
- name: Benchmark 12
292+
run: php benchmark/benchmark.php true
293+
- name: Benchmark 13
294+
run: php benchmark/benchmark.php true
295+
- name: Benchmark 14
296+
run: php benchmark/benchmark.php true
297+
- name: Benchmark 15
298+
run: php benchmark/benchmark.php true
299+
- name: Benchmark 16
300+
run: php benchmark/benchmark.php true
301+
- name: Benchmark 17
302+
run: php benchmark/benchmark.php true
303+
- name: Benchmark 18
304+
run: php benchmark/benchmark.php true
305+
- name: Benchmark 19
306+
run: php benchmark/benchmark.php true
307+
- name: Benchmark 20
308+
run: php benchmark/benchmark.php true
267309
- name: Store result
268310
if: github.event_name == 'push'
269311
run: |

Zend/zend_alloc.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,3 +3168,55 @@ size_t zend_mm_globals_size(void)
31683168
return sizeof(zend_alloc_globals);
31693169
}
31703170
#endif
3171+
3172+
#ifdef HAVE_VALGRIND
3173+
# if defined(__GNUC__) && !defined(__clang__)
3174+
# pragma GCC push_options
3175+
# pragma GCC optimize ("-fno-tree-loop-distribute-patterns")
3176+
# pragma GCC diagnostic ignored "-Wattributes"
3177+
# endif
3178+
3179+
/* Use custom memory copying implementations to avoid SSE when profiling. Depending on the memory
3180+
* alignment SSE can or cannot be effectively used, which leads to random noise in the profiling
3181+
* output. */
3182+
3183+
void *memcpy(void *restrict dest, const void *restrict src, size_t n)
3184+
{
3185+
const char *csrc = src;
3186+
char *cdest = dest;
3187+
for (int i = 0; i < n; i++) {
3188+
cdest[i] = csrc[i];
3189+
}
3190+
return dest;
3191+
}
3192+
void *memmove(void *dest, const void *src, size_t n)
3193+
{
3194+
char *csrc = (char *)src;
3195+
char *cdest = (char *)dest;
3196+
3197+
if (cdest < csrc) {
3198+
while (n-- != 0) {
3199+
*cdest++ = *csrc++;
3200+
}
3201+
} else {
3202+
while (n-- != 0) {
3203+
cdest[n] = csrc[n];
3204+
}
3205+
}
3206+
3207+
return dest;
3208+
}
3209+
void *memset(void *s, int c, size_t n)
3210+
{
3211+
unsigned char *cs = (unsigned char *)s;
3212+
3213+
for (int i = 0; i < n; i++) {
3214+
cs[i] = (unsigned char)c;
3215+
}
3216+
3217+
return s;
3218+
}
3219+
# if defined(__GNUC__) && !defined(__clang__)
3220+
# pragma GCC pop_options
3221+
# endif
3222+
#endif

benchmark/benchmark.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ function main() {
2121
if (false !== $branch = getenv('GITHUB_REF_NAME')) {
2222
$data['branch'] = $branch;
2323
}
24-
$data['Zend/bench.php'] = runBench(false);
25-
$data['Zend/bench.php JIT'] = runBench(true);
24+
// $data['Zend/bench.php'] = runBench(false);
25+
// $data['Zend/bench.php JIT'] = runBench(true);
2626
$data['Symfony Demo 2.2.3'] = runSymfonyDemo(false);
27-
$data['Symfony Demo 2.2.3 JIT'] = runSymfonyDemo(true);
27+
// $data['Symfony Demo 2.2.3 JIT'] = runSymfonyDemo(true);
2828
$data['Wordpress 6.2'] = runWordpress(false);
29-
$data['Wordpress 6.2 JIT'] = runWordpress(true);
29+
// $data['Wordpress 6.2 JIT'] = runWordpress(true);
3030
$result = json_encode($data, JSON_PRETTY_PRINT) . "\n";
3131

3232
fwrite(STDOUT, $result);
@@ -107,6 +107,16 @@ function runValgrindPhpCgiCommand(
107107
if ($jit) {
108108
$profileOut .= '.jit';
109109
}
110+
$i = 1;
111+
while (true) {
112+
$tmp = $profileOut . '.' . $i;
113+
if (file_exists($tmp)) {
114+
$i++;
115+
} else {
116+
$profileOut = $tmp;
117+
break;
118+
}
119+
}
110120

111121
$process = runCommand([
112122
'valgrind',

0 commit comments

Comments
 (0)