Is there any news?
I ran the program in 64-bit mode on Raspberry Pi 3 (1GiB RAM) with:
kernel-4.9.28-1 (Fedora 25)
gcc-6.3.1
glibc-2.24-4.fc25.aarch64
valgrind-3.12.0 (compiled from .tar.bz2 in one-half hour)
A swap file of 2GiB was not enough:
=====
==22295== Valgrind's memory management: out of memory:
==22295== newSuperblock's request for 1835012096 bytes failed.
==22295== 1,247,584,256 bytes have already been mmap-ed ANONYMOUS.
==22295== Valgrind cannot continue. Sorry.
=====
A swap file of 4GiB allowed execution to finish:
# dd if=/dev/zero of=/swap-file bs=1M count=4096
# chmod 600 /swap-file
# swapon /swap-file
[Side comment: Requiring more than 3GiB (1GiB RAM plus 2GiB swapspace)
for this small, short program is wildly extravagant by callgrind.]
The execution (several minutes) was:
gcc -g -O0 ./main.cpp
valgrind --tool=callgrind ./a.out
callgrind_annotate --auto=yes callgrind.out.PID main.cpp
The complete output from callgrind_annotate is attached (callgrind_annotate.out,
4.5 kB). I see lines such as
=====
10,485,720 char getCommon2(char * argv) {
5,242,860 char result = 0;
15,728,580 result = argv[0];
94,371,480 for(int i = 0; i < 2; i++ ) {
34 => ./main.cpp:getCommon2(char*)'2 (1x)
52,428,600 if( argv[1] > 20 ) {
=====
This suggests to me that callgrind's code which discovers tracebacks
has a problem, because there is no subroutine call anywhere in getCommon2,
yet callgrind thinks that getCommon2 called itself [recursively].
I have not looked carefully at what is happening.
--
--------------------------------------------------------------------------------
Profile data file 'callgrind.out.12136' (creator: callgrind-3.12.0)
--------------------------------------------------------------------------------
I1 cache:
D1 cache:
LL cache:
Timerange: Basic block 0 - 152273546
Trigger: Program termination
Profiled target: ./a.out (PID 12136, part 1)
Events recorded: Ir
Events shown: Ir
Event sort order: Ir
Thresholds: 99
Include dirs:
User annotated: main.cpp
Auto-annotation: on
--------------------------------------------------------------------------------
Ir
--------------------------------------------------------------------------------
814,181,009 PROGRAM TOTALS
--------------------------------------------------------------------------------
Ir file:function
--------------------------------------------------------------------------------
319,814,460 /home/jreiser/callgrind-bug/./main.cpp:getCommon2(char*)
[/bigdata/home/jreiser/callgrind-bug/a.out]
288,357,850 /home/jreiser/callgrind-bug/./main.cpp:getCommon(char*)
[/bigdata/home/jreiser/callgrind-bug/a.out]
204,471,913 /home/jreiser/callgrind-bug/./main.cpp:main
[/bigdata/home/jreiser/callgrind-bug/a.out]
--------------------------------------------------------------------------------
-- Auto-annotated source: /home/jreiser/callgrind-bug/./main.cpp
--------------------------------------------------------------------------------
Ir
. #include <stdio.h>
. #include <stdlib.h>
. #include <string.h>
.
15,728,610 char getCommon(char * argv) {
5,242,870 char result = 0;
15,728,610 result = argv[0];
57,671,570 for(int i = 0; i < 2; i++ ) {
52,428,700 if( argv[1] > 100 ) {
. result += argv[1] + 10;
. }
.
52,428,700 if( argv[2] < 30 ) {
73,400,180 result += argv[2] * 2;
. }
. }
.
5,242,870 return result;
10,485,740 }
.
15,728,580 char getCommon2(char * argv) {
5,242,860 char result = 0;
15,728,580 result = argv[0];
57,671,460 for(int i = 0; i < 2; i++ ) {
52,428,600 if( argv[1] > 20 ) {
. result += argv[1] + 10;
. }
.
52,428,600 if( argv[2] < 110 ) {
104,857,200 result += argv[2] * 3;
. }
. }
.
5,242,860 return result;
10,485,720 }
.
.
6 int main(int argc, char ** argv) {
1 unsigned long i = 0;
8 char * p = (char *)malloc(1024 * 1024);
174,155 => ???:_dl_runtime_resolve_avx_slow (1x)
10 memset(p, 1, 1024 * 1024);
115,612 => ???:_dl_runtime_resolve_avx_slow (1x)
. #if 0
. for(int i = 0; i < 10; i++ ) {
. for(int j = 0; j < 1024 * 1024 - 3; j++) {
. if(j % 10 == 0) {
. p[j] = getCommon(p + j);
. } else {
. p[j] = (getCommon2(p + j) + 20 ) >> 2 ;
. }
. }
. memset(p, 1, 1024 * 1024);
. }
. #endif
.
43 for(int i = 0; i < 10; i++ ) {
41,942,950 for(int j = 0; j < 1024 * 1024 - 3; j++) {
41,942,920 if(j % 2 == 0) {
62,914,440 p[j] = getCommon(p + j);
288,357,850 => /home/jreiser/callgrind-bug/./main.cpp:getCommon(char*)
(5242870x)
. } else {
57,671,460 p[j] = getCommon2(p + j);
319,814,460 => /home/jreiser/callgrind-bug/./main.cpp:getCommon2(char*)
(5242860x)
. }
. }
60 memset(p, 1, 1024 * 1024);
1,147,070 => ???:__GI_memset (10x)
. }
10 printf("p=%p\n", p);
2,729 => ???:_dl_runtime_resolve_avx_slow (1x)
1 return 0;
4 }
--------------------------------------------------------------------------------
-- User-annotated source: main.cpp
--------------------------------------------------------------------------------
No information has been collected for main.cpp
--------------------------------------------------------------------------------
Ir
--------------------------------------------------------------------------------
100 percentage of events annotated
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users