Skip to content

Use SSE-less memcpy for valgrind profiling #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ env:
CXX: ccache g++
jobs:
LINUX_X64:
if: false
services:
mysql:
image: mysql:8
Expand Down Expand Up @@ -135,6 +136,7 @@ jobs:
if: ${{ !matrix.asan }}
uses: ./.github/actions/verify-generated-files
MACOS_DEBUG_NTS:
if: false
runs-on: macos-12
steps:
- name: git checkout
Expand Down Expand Up @@ -168,6 +170,7 @@ jobs:
- name: Verify generated files are up to date
uses: ./.github/actions/verify-generated-files
WINDOWS:
if: false
name: WINDOWS_X64_ZTS
runs-on: windows-2019
env:
Expand Down Expand Up @@ -264,6 +267,44 @@ jobs:
path: benchmark/repos/data
- name: Benchmark
run: php benchmark/benchmark.php true
- name: Benchmark 2
run: php benchmark/benchmark.php true
- name: Benchmark 3
run: php benchmark/benchmark.php true
- name: Benchmark 4
run: php benchmark/benchmark.php true
- name: Benchmark 5
run: php benchmark/benchmark.php true
- name: Benchmark 6
run: php benchmark/benchmark.php true
- name: Benchmark 7
run: php benchmark/benchmark.php true
- name: Benchmark 8
run: php benchmark/benchmark.php true
- name: Benchmark 9
run: php benchmark/benchmark.php true
- name: Benchmark 10
run: php benchmark/benchmark.php true
- name: Benchmark 11
run: php benchmark/benchmark.php true
- name: Benchmark 12
run: php benchmark/benchmark.php true
- name: Benchmark 13
run: php benchmark/benchmark.php true
- name: Benchmark 14
run: php benchmark/benchmark.php true
- name: Benchmark 15
run: php benchmark/benchmark.php true
- name: Benchmark 16
run: php benchmark/benchmark.php true
- name: Benchmark 17
run: php benchmark/benchmark.php true
- name: Benchmark 18
run: php benchmark/benchmark.php true
- name: Benchmark 19
run: php benchmark/benchmark.php true
- name: Benchmark 20
run: php benchmark/benchmark.php true
- name: Store result
if: github.event_name == 'push'
run: |
Expand Down
67 changes: 67 additions & 0 deletions Zend/zend_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3168,3 +3168,70 @@ size_t zend_mm_globals_size(void)
return sizeof(zend_alloc_globals);
}
#endif

#ifdef HAVE_VALGRIND
# if defined(__GNUC__) && !defined(__clang__)
# pragma GCC push_options
# pragma GCC optimize ("-fno-tree-loop-distribute-patterns")
# pragma GCC diagnostic ignored "-Wattributes"
# endif

/* Use custom memory copying implementations to avoid SSE when profiling. Depending on the memory
* alignment SSE can or cannot be effectively used, which leads to random noise in the profiling
* output. */

void *memcpy(void *restrict dest, const void *restrict src, size_t n)
{
const char *csrc = src;
char *cdest = dest;
for (int i = 0; i < n; i++) {
cdest[i] = csrc[i];
}
return dest;
}
void *memmove(void *dest, const void *src, size_t n)
{
char *csrc = (char *)src;
char *cdest = (char *)dest;

if (cdest < csrc) {
while (n-- != 0) {
*cdest++ = *csrc++;
}
} else {
while (n-- != 0) {
cdest[n] = csrc[n];
}
}
return dest;
}
void *memset(void *s, int c, size_t n)
{
unsigned char *cs = (unsigned char *)s;

for (int i = 0; i < n; i++) {
cs[i] = (unsigned char)c;
}
return s;
}
int memcmp(const void *s1, const void *s2, size_t n)
{
if (s1 == s2) {
return 0;
}

unsigned char *p = (unsigned char *)s1;
unsigned char *q = (unsigned char *)s2;
while (n-- != 0) {
if (*p != *q) {
return (*p > *q) ? 1 : -1;
}
p++;
q++;
}
return 0;
}
# if defined(__GNUC__) && !defined(__clang__)
# pragma GCC pop_options
# endif
#endif
18 changes: 14 additions & 4 deletions benchmark/benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ function main() {
if (false !== $branch = getenv('GITHUB_REF_NAME')) {
$data['branch'] = $branch;
}
$data['Zend/bench.php'] = runBench(false);
$data['Zend/bench.php JIT'] = runBench(true);
// $data['Zend/bench.php'] = runBench(false);
// $data['Zend/bench.php JIT'] = runBench(true);
$data['Symfony Demo 2.2.3'] = runSymfonyDemo(false);
$data['Symfony Demo 2.2.3 JIT'] = runSymfonyDemo(true);
// $data['Symfony Demo 2.2.3 JIT'] = runSymfonyDemo(true);
$data['Wordpress 6.2'] = runWordpress(false);
$data['Wordpress 6.2 JIT'] = runWordpress(true);
// $data['Wordpress 6.2 JIT'] = runWordpress(true);
$result = json_encode($data, JSON_PRETTY_PRINT) . "\n";

fwrite(STDOUT, $result);
Expand Down Expand Up @@ -107,6 +107,16 @@ function runValgrindPhpCgiCommand(
if ($jit) {
$profileOut .= '.jit';
}
$i = 1;
while (true) {
$tmp = $profileOut . '.' . $i;
if (file_exists($tmp)) {
$i++;
} else {
$profileOut = $tmp;
break;
}
}

$process = runCommand([
'valgrind',
Expand Down