fcorbelli / zpaqfranz

Deduplicating archiver with encryption and paranoid-level tests. Swiss army knife for the serious backup and disaster recovery manager. Ransomware neutralizer. Win/Linux/Unix
MIT License
259 stars 22 forks source link

Bus error #85

Closed luckman212 closed 10 months ago

luckman212 commented 11 months ago

Hi,

$ zpaqfranz
zpaqfranz v58.10o-NOJIT-L(2023-10-01)

$ sw_vers
ProductName:        macOS
ProductVersion:     14.1
BuildVersion:       23B5067a

Mac Mini 2020 M1 - 16GB RAM

I am occasionally getting these crash reports from zpaqfranz - "Bus Error". Looks like it's crashing in a simple printf function? Is there any way to debug this further?

Here's the most recent crash report:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               zpaqfranz [19354]
Path:                  /opt/homebrew/*/zpaqfranz
Identifier:            zpaqfranz
Version:               ???
Code Type:             ARM-64 (Native)
Parent Process:        bash [19338]
Responsible:           bash [19221]
User ID:               501

Date/Time:             2023-10-17 23:36:45.4675 -0400
OS Version:            macOS 14.1 (23B5067a)
Report Version:        12
Anonymous UUID:        A6DF521A-3508-6D9A-A2C2-BF0317E32BFC

Time Awake Since Boot: 470000 seconds

System Integrity Protection: enabled

Crashed Thread:        2

Exception Type:        EXC_BAD_ACCESS (SIGBUS)
Exception Codes:       KERN_PROTECTION_FAILURE at 0x000000016daf3f58
Exception Codes:       0x0000000000000002, 0x000000016daf3f58

Termination Reason:    Namespace SIGNAL, Code 10 Bus error: 10
Terminating Process:   exc handler [19354]

VM Region Info: 0x16daf3f58 is in 0x16daf0000-0x16daf4000;  bytes after start: 16216  bytes before end: 167
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      Stack                       16da68000-16daf0000    [  544K] rw-/rwx SM=PRV  thread 1
--->  STACK GUARD                 16daf0000-16daf4000    [   16K] ---/rwx SM=NUL  ... for thread 2
      Stack                       16daf4000-16db7c000    [  544K] rw-/rwx SM=PRV  thread 2

Thread 0::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib                 0x18b4fe66c __ulock_wait + 8
1   libsystem_pthread.dylib                0x18b53f49c _pthread_join + 608
2   zpaqfranz                              0x10242f110 Jidac::verify(bool) + 2960
3   zpaqfranz                              0x102406610 Jidac::add() + 41792
4   zpaqfranz                              0x10244cd2c main + 444
5   dyld                                   0x18b1c10e0 start + 2360

Thread 1:
0   libsystem_kernel.dylib                 0x18b4fe820 __read_nocancel + 8
1   libsystem_c.dylib                      0x18b403744 __sread + 24
2   libsystem_c.dylib                      0x18b3e1964 _sread + 32
3   libsystem_c.dylib                      0x18b3e18f8 __srefill1 + 36
4   libsystem_c.dylib                      0x18b3e1ab8 __fread + 256
5   libsystem_c.dylib                      0x18b3ea178 fread + 64
6   zpaqfranz                              0x102441914 franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long) + 1580
7   zpaqfranz                              0x102449eb4 scansionahash(void*) + 272
8   libsystem_pthread.dylib                0x18b53d034 _pthread_start + 136
9   libsystem_pthread.dylib                0x18b537e3c thread_start + 8

Thread 2 Crashed:
0   libsystem_c.dylib                      0x18b3d7f84 __vfprintf + 60
1   libsystem_c.dylib                      0x18b4027c4 _vsnprintf + 224
2   zpaqfranz                              0x1023b3a24 myprintf(char const*, ...) + 84
3   zpaqfranz                              0x1023e093c myavanzamentoby1sec(long long, long long, long long, bool) + 676
4   zpaqfranz                              0x102441b18 franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long) + 2096
5   zpaqfranz                              0x102449eb4 scansionahash(void*) + 272
6   libsystem_pthread.dylib                0x18b53d034 _pthread_start + 136
7   libsystem_pthread.dylib                0x18b537e3c thread_start + 8

Thread 3:
0   libsystem_kernel.dylib                 0x18b4fe820 __read_nocancel + 8
1   libsystem_c.dylib                      0x18b403744 __sread + 24
2   libsystem_c.dylib                      0x18b3e1964 _sread + 32
3   libsystem_c.dylib                      0x18b3e18f8 __srefill1 + 36
4   libsystem_c.dylib                      0x18b3e1ab8 __fread + 256
5   libsystem_c.dylib                      0x18b3ea178 fread + 64
6   zpaqfranz                              0x102441914 franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long) + 1580
7   zpaqfranz                              0x102449eb4 scansionahash(void*) + 272
8   libsystem_pthread.dylib                0x18b53d034 _pthread_start + 136
9   libsystem_pthread.dylib                0x18b537e3c thread_start + 8

Thread 4:
0   libsystem_kernel.dylib                 0x18b4fe820 __read_nocancel + 8
1   libsystem_c.dylib                      0x18b403744 __sread + 24
2   libsystem_c.dylib                      0x18b3e1964 _sread + 32
3   libsystem_c.dylib                      0x18b3e18f8 __srefill1 + 36
4   libsystem_c.dylib                      0x18b4056ac _fseeko + 732
5   libsystem_c.dylib                      0x18b3e9bec fseeko + 92
6   zpaqfranz                              0x1023be838 prendidimensionefile(char const*) + 40
7   zpaqfranz                              0x1024416a0 franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long) + 952
8   zpaqfranz                              0x102449eb4 scansionahash(void*) + 272
9   libsystem_pthread.dylib                0x18b53d034 _pthread_start + 136
10  libsystem_pthread.dylib                0x18b537e3c thread_start + 8

Thread 5:
0   libsystem_kernel.dylib                 0x18b4fd4a0 __open_nocancel + 8
1   libsystem_kernel.dylib                 0x18b5109f0 open$NOCANCEL + 64
2   libsystem_c.dylib                      0x18b3e5d00 fopen + 92
3   zpaqfranz                              0x1023be770 freadopen(char const*) + 28
4   zpaqfranz                              0x102441680 franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long) + 920
5   zpaqfranz                              0x102449eb4 scansionahash(void*) + 272
6   libsystem_pthread.dylib                0x18b53d034 _pthread_start + 136
7   libsystem_pthread.dylib                0x18b537e3c thread_start + 8

Thread 6:
0   libsystem_kernel.dylib                 0x18b4fe820 __read_nocancel + 8
1   libsystem_c.dylib                      0x18b403744 __sread + 24
2   libsystem_c.dylib                      0x18b3e1964 _sread + 32
3   libsystem_c.dylib                      0x18b3e18f8 __srefill1 + 36
4   libsystem_c.dylib                      0x18b4056ac _fseeko + 732
5   libsystem_c.dylib                      0x18b3e9bec fseeko + 92
6   zpaqfranz                              0x1023be838 prendidimensionefile(char const*) + 40
7   zpaqfranz                              0x1024416a0 franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long) + 952
8   zpaqfranz                              0x102449eb4 scansionahash(void*) + 272
9   libsystem_pthread.dylib                0x18b53d034 _pthread_start + 136
10  libsystem_pthread.dylib                0x18b537e3c thread_start + 8

Thread 7:
0   libsystem_kernel.dylib                 0x18b4fe820 __read_nocancel + 8
1   libsystem_c.dylib                      0x18b403744 __sread + 24
2   libsystem_c.dylib                      0x18b3e1964 _sread + 32
3   libsystem_c.dylib                      0x18b3e18f8 __srefill1 + 36
4   libsystem_c.dylib                      0x18b4056ac _fseeko + 732
5   libsystem_c.dylib                      0x18b3e9bec fseeko + 92
6   zpaqfranz                              0x1023be838 prendidimensionefile(char const*) + 40
7   zpaqfranz                              0x1024416a0 franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long) + 952
8   zpaqfranz                              0x102449eb4 scansionahash(void*) + 272
9   libsystem_pthread.dylib                0x18b53d034 _pthread_start + 136
10  libsystem_pthread.dylib                0x18b537e3c thread_start + 8

Thread 8:
0   libsystem_kernel.dylib                 0x18b4fe820 __read_nocancel + 8
1   libsystem_c.dylib                      0x18b403744 __sread + 24
2   libsystem_c.dylib                      0x18b3e1964 _sread + 32
3   libsystem_c.dylib                      0x18b3e18f8 __srefill1 + 36
4   libsystem_c.dylib                      0x18b3e1ab8 __fread + 256
5   libsystem_c.dylib                      0x18b3ea178 fread + 64
6   zpaqfranz                              0x102441914 franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long) + 1580
7   zpaqfranz                              0x102449eb4 scansionahash(void*) + 272
8   libsystem_pthread.dylib                0x18b53d034 _pthread_start + 136
9   libsystem_pthread.dylib                0x18b537e3c thread_start + 8

Thread 2 crashed with ARM Thread State (64-bit):
    x0: 0x000000016daf4128   x1: 0x00000001e16ec6b8   x2: 0x00000001024a4786   x3: 0x000000016daf5300
    x4: 0x00000001024a4786   x5: 0x000000016daf5300   x6: 0x000000016daf5300   x7: 0x000000010249ea79
    x8: 0x0dba0499489e0023   x9: 0x0dba0499489e0023  x10: 0x000000016daf42d8  x11: 0x00000000ffff0208
   x12: 0x000000000000002e  x13: 0xcccccccccccccccd  x14: 0x000000000000000a  x15: 0x00000000fffffff7
   x16: 0x000000029dc0684c  x17: 0x0000000000000000  x18: 0x0000000000000000  x19: 0x00000001e16ec6b8
   x20: 0x0000000000000001  x21: 0x00000000156319fb  x22: 0x000000002d4cbe9b  x23: 0x0000000000000001
   x24: 0x00000001024fcaf5  x25: 0x000000000000002f  x26: 0x0000000000000000  x27: 0x00000001024a4786
   x28: 0x0000000000000001   fp: 0x000000016daf4110   lr: 0xc57500018b4027c4
    sp: 0x000000016daf3d30   pc: 0x000000018b3d7f84 cpsr: 0x60001000
   far: 0x000000016daf3f58  esr: 0x92000047 (Data Abort) byte write Translation fault

Binary Images:
       0x10239c000 -        0x1024c3fff zpaqfranz (*) <23d7e721-8e5d-310e-b42b-f413028db4a7> /opt/homebrew/*/zpaqfranz
       0x18b4fb000 -        0x18b535fef libsystem_kernel.dylib (*) <8e284c01-80f9-3be7-b660-3cca3893bb20> /usr/lib/system/libsystem_kernel.dylib
       0x18b536000 -        0x18b542ff3 libsystem_pthread.dylib (*) <75288deb-6d30-3e42-8799-88302598394b> /usr/lib/system/libsystem_pthread.dylib
       0x18b1bb000 -        0x18b24f317 dyld (*) <9f091f00-ff69-358f-8d89-adf6bccf8422> /usr/lib/dyld
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???
       0x18b3d6000 -        0x18b454ffb libsystem_c.dylib (*) <253bbb56-ff67-3189-b5c1-d651e35322cf> /usr/lib/system/libsystem_c.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=893.2M resident=0K(0%) swapped_out_or_unallocated=893.2M(100%)
Writable regions: Total=1.6G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.6G(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Kernel Alloc Once                   32K        1 
MALLOC                             1.6G       53 
MALLOC guard page                   96K        6 
STACK GUARD                       56.1M        9 
Stack                             12.2M        9 
__AUTH                              46K       12 
__AUTH_CONST                        76K       39 
__DATA                             417K       40 
__DATA_CONST                       203K       41 
__DATA_DIRTY                        79K       22 
__LINKEDIT                       886.7M        2 
__OBJC_RO                         70.8M        1 
__OBJC_RW                         2156K        1 
__TEXT                            6640K       43 
dyld private memory                272K        2 
shared memory                       80K        4 
===========                     =======  ======= 
TOTAL                              2.6G      285 

-----------
Full Report
-----------

{"app_name":"zpaqfranz","timestamp":"2023-10-17 23:36:45.00 -0400","app_version":"","slice_uuid":"23d7e721-8e5d-310e-b42b-f413028db4a7","build_version":"","platform":1,"share_with_app_devs":0,"is_first_party":1,"bug_type":"309","os_version":"macOS 14.1 (23B5067a)","roots_installed":0,"incident_id":"B3760B41-1E27-4D32-ACD9-A1F0A20CAF69","name":"zpaqfranz"}
{
  "uptime" : 470000,
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "Macmini9,1",
  "coalitionID" : 3592,
  "osVersion" : {
    "train" : "macOS 14.1",
    "build" : "23B5067a",
    "releaseType" : "User"
  },
  "captureTime" : "2023-10-17 23:36:45.4675 -0400",
  "codeSigningMonitor" : 1,
  "incident" : "B3760B41-1E27-4D32-ACD9-A1F0A20CAF69",
  "pid" : 19354,
  "translated" : false,
  "cpuType" : "ARM-64",
  "roots_installed" : 0,
  "bug_type" : "309",
  "procLaunch" : "2023-10-17 23:36:40.9818 -0400",
  "procStartAbsTime" : 11422984722709,
  "procExitAbsTime" : 11423092309225,
  "procName" : "zpaqfranz",
  "procPath" : "\/opt\/homebrew\/*\/zpaqfranz",
  "parentProc" : "bash",
  "parentPid" : 19338,
  "coalitionName" : "com.ldh.periodic-1h.agent",
  "crashReporterKey" : "A6DF521A-3508-6D9A-A2C2-BF0317E32BFC",
  "responsiblePid" : 19221,
  "responsibleProc" : "bash",
  "codeSigningID" : "zpaqfranz",
  "codeSigningTeamID" : "",
  "codeSigningFlags" : 570556929,
  "codeSigningValidationCategory" : 10,
  "codeSigningTrustLevel" : 4294967295,
  "instructionByteStream" : {"beforePC":"9E8Eqf17Ban9QwGR\/0MO0fsDAqrzAwGqyBgrkAihB5EIAUD5qIMZ+A==","atPC":"4xcB+f+fCDnpgwSR\/wsB+QDkAG8ggQat\/+8Buf\/zAPn\/3wG5\/\/8cqQ=="},
  "sip" : "enabled",
  "vmRegionInfo" : "0x16daf3f58 is in 0x16daf0000-0x16daf4000;  bytes after start: 16216  bytes before end: 167\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      Stack                       16da68000-16daf0000    [  544K] rw-\/rwx SM=PRV  thread 1\n--->  STACK GUARD                 16daf0000-16daf4000    [   16K] ---\/rwx SM=NUL  ... for thread 2\n      Stack                       16daf4000-16db7c000    [  544K] rw-\/rwx SM=PRV  thread 2",
  "exception" : {"codes":"0x0000000000000002, 0x000000016daf3f58","rawCodes":[2,6135168856],"type":"EXC_BAD_ACCESS","signal":"SIGBUS","subtype":"KERN_PROTECTION_FAILURE at 0x000000016daf3f58"},
  "termination" : {"flags":0,"code":10,"namespace":"SIGNAL","indicator":"Bus error: 10","byProc":"exc handler","byPid":19354},
  "vmregioninfo" : "0x16daf3f58 is in 0x16daf0000-0x16daf4000;  bytes after start: 16216  bytes before end: 167\n      REGION TYPE                    START - END         [ VSIZE] PRT\/MAX SHRMOD  REGION DETAIL\n      Stack                       16da68000-16daf0000    [  544K] rw-\/rwx SM=PRV  thread 1\n--->  STACK GUARD                 16daf0000-16daf4000    [   16K] ---\/rwx SM=NUL  ... for thread 2\n      Stack                       16daf4000-16db7c000    [  544K] rw-\/rwx SM=PRV  thread 2",
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 2,
  "threads" : [{"id":6700938,"threadState":{"x":[{"value":18446744073709551612},{"value":0},{"value":4871},{"value":0},{"value":150997247},{"value":3},{"value":0},{"value":0},{"value":4871},{"value":16908290},{"value":17},{"value":0},{"value":8077116824,"symbolLocation":0,"symbol":"vm_page_size"},{"value":13883},{"value":0},{"value":0},{"value":515},{"value":8227993040},{"value":0},{"value":6135132160},{"value":2},{"value":6135132212},{"value":16908290},{"value":8077074336,"symbolLocation":224,"symbol":"_main_thread"},{"value":8077131844,"symbolLocation":0,"symbol":"_pthread_list_lock"},{"value":17},{"value":0},{"value":1664},{"value":6134518576}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6632502428},"cpsr":{"value":1073745920},"fp":{"value":6134314656},"sp":{"value":6134314560},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6632236652},"far":{"value":0}},"queue":"com.apple.main-thread","frames":[{"imageOffset":13932,"symbol":"__ulock_wait","symbolLocation":8,"imageIndex":1},{"imageOffset":38044,"symbol":"_pthread_join","symbolLocation":608,"imageIndex":2},{"imageOffset":602384,"symbol":"Jidac::verify(bool)","symbolLocation":2960,"imageIndex":0},{"imageOffset":435728,"symbol":"Jidac::add()","symbolLocation":41792,"imageIndex":0},{"imageOffset":724268,"symbol":"main","symbolLocation":444,"imageIndex":0},{"imageOffset":24800,"symbol":"start","symbolLocation":2360,"imageIndex":3}]},{"id":6701078,"frames":[{"imageOffset":14368,"symbol":"__read_nocancel","symbolLocation":8,"imageIndex":1},{"imageOffset":186180,"symbol":"__sread","symbolLocation":24,"imageIndex":5},{"imageOffset":47460,"symbol":"_sread","symbolLocation":32,"imageIndex":5},{"imageOffset":47352,"symbol":"__srefill1","symbolLocation":36,"imageIndex":5},{"imageOffset":47800,"symbol":"__fread","symbolLocation":256,"imageIndex":5},{"imageOffset":82296,"symbol":"fread","symbolLocation":64,"imageIndex":5},{"imageOffset":678164,"symbol":"franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long)","symbolLocation":1580,"imageIndex":0},{"imageOffset":712372,"symbol":"scansionahash(void*)","symbolLocation":272,"imageIndex":0},{"imageOffset":28724,"symbol":"_pthread_start","symbolLocation":136,"imageIndex":2},{"imageOffset":7740,"symbol":"thread_start","symbolLocation":8,"imageIndex":2}],"threadState":{"x":[{"value":73916},{"value":0},{"value":524288},{"value":9},{"value":6134601664},{"value":616562688},{"value":105553516606112},{"value":4333365881,"symbolLocation":11,"symbol":"myulltoa(unsigned long long, int)::xlat"},{"value":6631208748,"symbolLocation":0,"symbol":"__sread"},{"value":130},{"value":144384},{"value":6266496},{"value":64949},{"value":4294934537},{"value":225},{"value":4294934015},{"value":396},{"value":8227994568},{"value":0},{"value":8077109392,"symbolLocation":304,"symbol":"usual"},{"value":2147482624},{"value":8077109392,"symbolLocation":304,"symbol":"usual"},{"value":6134607032},{"value":6134607032},{"value":524287},{"value":0},{"value":524288},{"value":8077109416,"symbolLocation":328,"symbol":"usual"},{"value":524288}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6631208772},"cpsr":{"value":4096},"fp":{"value":6134600368},"sp":{"value":6134600368},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6632237088},"far":{"value":0}}},{"triggered":true,"id":6701079,"threadState":{"x":[{"value":6135169320},{"value":8077100728,"symbolLocation":0,"symbol":"__global_locale"},{"value":4333389702,"symbolLocation":9503,"symbol":"MD5::getHash()::dec2hex"},{"value":6135173888},{"value":4333389702,"symbolLocation":9503,"symbol":"MD5::getHash()::dec2hex"},{"value":6135173888},{"value":6135173888},{"value":4333365881,"symbolLocation":11,"symbol":"myulltoa(unsigned long long, int)::xlat"},{"value":989108124556066851},{"value":989108124556066851},{"value":6135169752},{"value":4294902280},{"value":46},{"value":14757395258967641293},{"value":10},{"value":4294967287},{"value":11236567116},{"value":0},{"value":0},{"value":8077100728,"symbolLocation":0,"symbol":"__global_locale"},{"value":1},{"value":358816251},{"value":760004251},{"value":1},{"value":4333751029,"symbolLocation":0,"symbol":"tohuman2(long long)::io_buf"},{"value":47},{"value":0},{"value":4333389702,"symbolLocation":9503,"symbol":"MD5::getHash()::dec2hex"},{"value":1}],"flavor":"ARM_THREAD_STATE64","lr":{"value":14228278604378154948},"cpsr":{"value":1610616832},"fp":{"value":6135169296},"sp":{"value":6135168304},"esr":{"value":2449473607,"description":"(Data Abort) byte write Translation fault"},"pc":{"value":6631030660,"matchesCrashFrame":1},"far":{"value":6135168856}},"frames":[{"imageOffset":8068,"symbol":"__vfprintf","symbolLocation":60,"imageIndex":5},{"imageOffset":182212,"symbol":"_vsnprintf","symbolLocation":224,"imageIndex":5},{"imageOffset":96804,"symbol":"myprintf(char const*, ...)","symbolLocation":84,"imageIndex":0},{"imageOffset":280892,"symbol":"myavanzamentoby1sec(long long, long long, long long, bool)","symbolLocation":676,"imageIndex":0},{"imageOffset":678680,"symbol":"franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long)","symbolLocation":2096,"imageIndex":0},{"imageOffset":712372,"symbol":"scansionahash(void*)","symbolLocation":272,"imageIndex":0},{"imageOffset":28724,"symbol":"_pthread_start","symbolLocation":136,"imageIndex":2},{"imageOffset":7740,"symbol":"thread_start","symbolLocation":8,"imageIndex":2}]},{"id":6701080,"frames":[{"imageOffset":14368,"symbol":"__read_nocancel","symbolLocation":8,"imageIndex":1},{"imageOffset":186180,"symbol":"__sread","symbolLocation":24,"imageIndex":5},{"imageOffset":47460,"symbol":"_sread","symbolLocation":32,"imageIndex":5},{"imageOffset":47352,"symbol":"__srefill1","symbolLocation":36,"imageIndex":5},{"imageOffset":47800,"symbol":"__fread","symbolLocation":256,"imageIndex":5},{"imageOffset":82296,"symbol":"fread","symbolLocation":64,"imageIndex":5},{"imageOffset":678164,"symbol":"franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long)","symbolLocation":1580,"imageIndex":0},{"imageOffset":712372,"symbol":"scansionahash(void*)","symbolLocation":272,"imageIndex":0},{"imageOffset":28724,"symbol":"_pthread_start","symbolLocation":136,"imageIndex":2},{"imageOffset":7740,"symbol":"thread_start","symbolLocation":8,"imageIndex":2}],"threadState":{"x":[{"value":97889},{"value":0},{"value":524288},{"value":24},{"value":6135748544},{"value":15744},{"value":105553516789120},{"value":4333365881,"symbolLocation":11,"symbol":"myulltoa(unsigned long long, int)::xlat"},{"value":6631208748,"symbolLocation":0,"symbol":"__sread"},{"value":130},{"value":39424},{"value":6266496},{"value":64949},{"value":4294934552},{"value":20},{"value":4294934015},{"value":396},{"value":8227994568},{"value":0},{"value":8077109544,"symbolLocation":456,"symbol":"usual"},{"value":2147482624},{"value":8077109544,"symbolLocation":456,"symbol":"usual"},{"value":6135753912},{"value":6135753912},{"value":524287},{"value":0},{"value":524288},{"value":8077109568,"symbolLocation":480,"symbol":"usual"},{"value":524288}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6631208772},"cpsr":{"value":4096},"fp":{"value":6135747248},"sp":{"value":6135747248},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6632237088},"far":{"value":0}}},{"id":6701081,"frames":[{"imageOffset":14368,"symbol":"__read_nocancel","symbolLocation":8,"imageIndex":1},{"imageOffset":186180,"symbol":"__sread","symbolLocation":24,"imageIndex":5},{"imageOffset":47460,"symbol":"_sread","symbolLocation":32,"imageIndex":5},{"imageOffset":47352,"symbol":"__srefill1","symbolLocation":36,"imageIndex":5},{"imageOffset":194220,"symbol":"_fseeko","symbolLocation":732,"imageIndex":5},{"imageOffset":80876,"symbol":"fseeko","symbolLocation":92,"imageIndex":5},{"imageOffset":141368,"symbol":"prendidimensionefile(char const*)","symbolLocation":40,"imageIndex":0},{"imageOffset":677536,"symbol":"franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long)","symbolLocation":952,"imageIndex":0},{"imageOffset":712372,"symbol":"scansionahash(void*)","symbolLocation":272,"imageIndex":0},{"imageOffset":28724,"symbol":"_pthread_start","symbolLocation":136,"imageIndex":2},{"imageOffset":7740,"symbol":"thread_start","symbolLocation":8,"imageIndex":2}],"threadState":{"x":[{"value":2938},{"value":0},{"value":4096},{"value":105553168310192},{"value":105553168310272},{"value":32},{"value":105553168310144},{"value":4333365881,"symbolLocation":11,"symbol":"myulltoa(unsigned long long, int)::xlat"},{"value":6631208748,"symbolLocation":0,"symbol":"__sread"},{"value":15},{"value":0},{"value":0},{"value":0},{"value":117626},{"value":2},{"value":73},{"value":396},{"value":8227994568},{"value":0},{"value":8077110152,"symbolLocation":1064,"symbol":"usual"},{"value":0},{"value":2},{"value":2938},{"value":1},{"value":0},{"value":6136321152},{"value":760004251},{"value":6136851984},{"value":6136852240}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6631208772},"cpsr":{"value":1073745920},"fp":{"value":6136320576},"sp":{"value":6136320576},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6632237088},"far":{"value":0}}},{"id":6701082,"frames":[{"imageOffset":9376,"symbol":"__open_nocancel","symbolLocation":8,"imageIndex":1},{"imageOffset":88560,"symbol":"open$NOCANCEL","symbolLocation":64,"imageIndex":1},{"imageOffset":64768,"symbol":"fopen","symbolLocation":92,"imageIndex":5},{"imageOffset":141168,"symbol":"freadopen(char const*)","symbolLocation":28,"imageIndex":0},{"imageOffset":677504,"symbol":"franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long)","symbolLocation":920,"imageIndex":0},{"imageOffset":712372,"symbol":"scansionahash(void*)","symbolLocation":272,"imageIndex":0},{"imageOffset":28724,"symbol":"_pthread_start","symbolLocation":136,"imageIndex":2},{"imageOffset":7740,"symbol":"thread_start","symbolLocation":8,"imageIndex":2}],"threadState":{"x":[{"value":11},{"value":0},{"value":0},{"value":105553161393008},{"value":105553161393024},{"value":32},{"value":105553161392928},{"value":4333365881,"symbolLocation":11,"symbol":"myulltoa(unsigned long long, int)::xlat"},{"value":438},{"value":8},{"value":92358976754688},{"value":92358976754690},{"value":21504},{"value":92358976754688},{"value":2768404515},{"value":35},{"value":398},{"value":8227994296},{"value":0},{"value":0},{"value":105553161392352},{"value":105553161392352},{"value":0},{"value":6137425376},{"value":0},{"value":6137425624},{"value":760004251},{"value":6137425424},{"value":6137425680}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6632311280},"cpsr":{"value":1073745920},"fp":{"value":6136894288},"sp":{"value":6136894240},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6632232096},"far":{"value":0}}},{"id":6701083,"frames":[{"imageOffset":14368,"symbol":"__read_nocancel","symbolLocation":8,"imageIndex":1},{"imageOffset":186180,"symbol":"__sread","symbolLocation":24,"imageIndex":5},{"imageOffset":47460,"symbol":"_sread","symbolLocation":32,"imageIndex":5},{"imageOffset":47352,"symbol":"__srefill1","symbolLocation":36,"imageIndex":5},{"imageOffset":194220,"symbol":"_fseeko","symbolLocation":732,"imageIndex":5},{"imageOffset":80876,"symbol":"fseeko","symbolLocation":92,"imageIndex":5},{"imageOffset":141368,"symbol":"prendidimensionefile(char const*)","symbolLocation":40,"imageIndex":0},{"imageOffset":677536,"symbol":"franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long)","symbolLocation":952,"imageIndex":0},{"imageOffset":712372,"symbol":"scansionahash(void*)","symbolLocation":272,"imageIndex":0},{"imageOffset":28724,"symbol":"_pthread_start","symbolLocation":136,"imageIndex":2},{"imageOffset":7740,"symbol":"thread_start","symbolLocation":8,"imageIndex":2}],"threadState":{"x":[{"value":3440},{"value":0},{"value":4096},{"value":105553516616768},{"value":105553516616832},{"value":32},{"value":105553516616736},{"value":4333365881,"symbolLocation":11,"symbol":"myulltoa(unsigned long long, int)::xlat"},{"value":6631208748,"symbolLocation":0,"symbol":"__sread"},{"value":15},{"value":0},{"value":0},{"value":0},{"value":3440},{"value":2},{"value":76},{"value":396},{"value":8227994568},{"value":0},{"value":8077110608,"symbolLocation":1520,"symbol":"usual"},{"value":0},{"value":2},{"value":3440},{"value":1},{"value":0},{"value":6137468032},{"value":760004251},{"value":6137998864},{"value":6137999120}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6631208772},"cpsr":{"value":1073745920},"fp":{"value":6137467456},"sp":{"value":6137467456},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6632237088},"far":{"value":0}}},{"id":6701084,"frames":[{"imageOffset":14368,"symbol":"__read_nocancel","symbolLocation":8,"imageIndex":1},{"imageOffset":186180,"symbol":"__sread","symbolLocation":24,"imageIndex":5},{"imageOffset":47460,"symbol":"_sread","symbolLocation":32,"imageIndex":5},{"imageOffset":47352,"symbol":"__srefill1","symbolLocation":36,"imageIndex":5},{"imageOffset":194220,"symbol":"_fseeko","symbolLocation":732,"imageIndex":5},{"imageOffset":80876,"symbol":"fseeko","symbolLocation":92,"imageIndex":5},{"imageOffset":141368,"symbol":"prendidimensionefile(char const*)","symbolLocation":40,"imageIndex":0},{"imageOffset":677536,"symbol":"franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long)","symbolLocation":952,"imageIndex":0},{"imageOffset":712372,"symbol":"scansionahash(void*)","symbolLocation":272,"imageIndex":0},{"imageOffset":28724,"symbol":"_pthread_start","symbolLocation":136,"imageIndex":2},{"imageOffset":7740,"symbol":"thread_start","symbolLocation":8,"imageIndex":2}],"threadState":{"x":[{"value":2874},{"value":0},{"value":4096},{"value":16},{"value":105553516789696},{"value":32},{"value":105553516789600},{"value":4333365881,"symbolLocation":11,"symbol":"myulltoa(unsigned long long, int)::xlat"},{"value":6631208748,"symbolLocation":0,"symbol":"__sread"},{"value":15},{"value":0},{"value":0},{"value":0},{"value":318266},{"value":28},{"value":4294934015},{"value":396},{"value":8227994568},{"value":0},{"value":8077110456,"symbolLocation":1368,"symbol":"usual"},{"value":0},{"value":2},{"value":2874},{"value":1},{"value":0},{"value":6138041472},{"value":760004251},{"value":6138572304},{"value":6138572560}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6631208772},"cpsr":{"value":1073745920},"fp":{"value":6138040896},"sp":{"value":6138040896},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6632237088},"far":{"value":0}}},{"id":6701085,"frames":[{"imageOffset":14368,"symbol":"__read_nocancel","symbolLocation":8,"imageIndex":1},{"imageOffset":186180,"symbol":"__sread","symbolLocation":24,"imageIndex":5},{"imageOffset":47460,"symbol":"_sread","symbolLocation":32,"imageIndex":5},{"imageOffset":47352,"symbol":"__srefill1","symbolLocation":36,"imageIndex":5},{"imageOffset":47800,"symbol":"__fread","symbolLocation":256,"imageIndex":5},{"imageOffset":82296,"symbol":"fread","symbolLocation":64,"imageIndex":5},{"imageOffset":678164,"symbol":"franz_do_hash::filehash(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long long, long long)","symbolLocation":1580,"imageIndex":0},{"imageOffset":712372,"symbol":"scansionahash(void*)","symbolLocation":272,"imageIndex":0},{"imageOffset":28724,"symbol":"_pthread_start","symbolLocation":136,"imageIndex":2},{"imageOffset":7740,"symbol":"thread_start","symbolLocation":8,"imageIndex":2}],"threadState":{"x":[{"value":235846},{"value":0},{"value":524288},{"value":17},{"value":6138615744},{"value":12192},{"value":105553516605344},{"value":4333365881,"symbolLocation":11,"symbol":"myulltoa(unsigned long long, int)::xlat"},{"value":6631208748,"symbolLocation":0,"symbol":"__sread"},{"value":130},{"value":140288},{"value":6266496},{"value":64949},{"value":4294934545},{"value":217},{"value":4294934015},{"value":396},{"value":8227994568},{"value":0},{"value":8077109088,"symbolLocation":0,"symbol":"usual"},{"value":2147482624},{"value":8077109088,"symbolLocation":0,"symbol":"usual"},{"value":6138621112},{"value":6138621112},{"value":524287},{"value":0},{"value":524288},{"value":8077109112,"symbolLocation":24,"symbol":"usual"},{"value":524288}],"flavor":"ARM_THREAD_STATE64","lr":{"value":6631208772},"cpsr":{"value":4096},"fp":{"value":6138614448},"sp":{"value":6138614448},"esr":{"value":1442840704,"description":" Address size fault"},"pc":{"value":6632237088},"far":{"value":0}}}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4332306432,
    "size" : 1212416,
    "uuid" : "23d7e721-8e5d-310e-b42b-f413028db4a7",
    "path" : "\/opt\/homebrew\/*\/zpaqfranz",
    "name" : "zpaqfranz"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6632222720,
    "size" : 241648,
    "uuid" : "8e284c01-80f9-3be7-b660-3cca3893bb20",
    "path" : "\/usr\/lib\/system\/libsystem_kernel.dylib",
    "name" : "libsystem_kernel.dylib"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6632464384,
    "size" : 53236,
    "uuid" : "75288deb-6d30-3e42-8799-88302598394b",
    "path" : "\/usr\/lib\/system\/libsystem_pthread.dylib",
    "name" : "libsystem_pthread.dylib"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6628814848,
    "size" : 607000,
    "uuid" : "9f091f00-ff69-358f-8d89-adf6bccf8422",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  },
  {
    "size" : 0,
    "source" : "A",
    "base" : 0,
    "uuid" : "00000000-0000-0000-0000-000000000000"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6631022592,
    "size" : 520188,
    "uuid" : "253bbb56-ff67-3189-b5c1-d651e35322cf",
    "path" : "\/usr\/lib\/system\/libsystem_c.dylib",
    "name" : "libsystem_c.dylib"
  }
],
  "sharedCache" : {
  "base" : 6628065280,
  "size" : 4018503680,
  "uuid" : "b015a7de-cec9-38ee-93e9-43fb3debde90"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=893.2M resident=0K(0%) swapped_out_or_unallocated=893.2M(100%)\nWritable regions: Total=1.6G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.6G(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nKernel Alloc Once                   32K        1 \nMALLOC                             1.6G       53 \nMALLOC guard page                   96K        6 \nSTACK GUARD                       56.1M        9 \nStack                             12.2M        9 \n__AUTH                              46K       12 \n__AUTH_CONST                        76K       39 \n__DATA                             417K       40 \n__DATA_CONST                       203K       41 \n__DATA_DIRTY                        79K       22 \n__LINKEDIT                       886.7M        2 \n__OBJC_RO                         70.8M        1 \n__OBJC_RW                         2156K        1 \n__TEXT                            6640K       43 \ndyld private memory                272K        2 \nshared memory                       80K        4 \n===========                     =======  ======= \nTOTAL                              2.6G      285 \n",
  "legacyInfo" : {
  "threadTriggered" : {

  }
},
  "logWritingSignature" : "954f84f7df65c5ac34640376fce35e235143af41",
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "64b21a7351cbb02ce3442e4e",
      "factorPackIds" : {
        "REMINDERS_GROCERY" : "64d6bf89aa6c2933834d3f9d"
      },
      "deploymentId" : 250000016
    },
    {
      "rolloutId" : "5ffde50ce2aacd000d47a95f",
      "factorPackIds" : {

      },
      "deploymentId" : 250000328
    }
  ],
  "experiments" : [
    {
      "treatmentId" : "6dd670af-0633-45e4-ae5f-122ae4df02be",
      "experimentId" : "64406ba83deb637ac8a04419",
      "deploymentId" : 900000017
    }
  ]
}
}
fcorbelli commented 11 months ago

Sadly I do not have an M1 Mac. Please try this workaroud: use the -noeta switch

This will "turn off" the advancement (i.e. the myavanzamentoby1sec function) which may be the culprit. If the problem does not recur, then the error is in there, and we will investigate further

Please let me know, thanks

luckman212 commented 11 months ago

Thanks @fcorbelli

I added the -noeta switch to my script. It runs automated anyway in the background, so there is nobody there to see the ETA anyway. I will let you know if I see further crashes.

luckman212 commented 10 months ago

Might be too soon to tell, but so far, no crashes since adding -noeta

fcorbelli commented 10 months ago

Good, this could help very much for the debugging

ghost commented 10 months ago

I've had your .cpp locally, so I took a look for a moment (I haven't run anything): could it be that in

char* mymigliaia(int64_t i_bytes,char* i_buffer,int i_buffersize)

This one

    char *p=&i_buffer[sizeof(i_buffer)-1]

should rather use i_buffersize?

ghost commented 10 months ago

could it be that in

char* mymigliaia(int64_t i_bytes,char* i_buffer,int i_buffersize)

This one

    char *p=&i_buffer[sizeof(i_buffer)-1]

should rather use i_buffersize?

Specifically, I believe that the cited line is equivalent to

 char *p=&i_buffer[7]

and that's improbable to be intentional.

luckman212 commented 10 months ago

@janko-js Nice catch. I checked that function with chatGPT and it seems to agree...

image
fcorbelli commented 10 months ago

It's definitely a bug, due to a change from a vector of fixed size, for which sizeof works, to a pointer, for which it returns the size of the pointer and not of the vector

ghost commented 10 months ago

It's definitely a bug, due to a change from a vector of fixed size, for which sizeof works, to a pointer, for which it returns the size of the pointer and not of the vector

And the potential memory corruption that later can probably sometimes cause a crash (depending what's in memory before) could happen at the moment when the function processes a big enough number. That corruption doesn't have to cause an immediate crash, but a delayed one.

fcorbelli commented 10 months ago

If you look at those lines you find my correction, against sizeof(), but in another function 😄

/// snprintf(i_buffer,sizeof(i_buffer),"%.02lf %s",mybytes,myappend[i]);
    snprintf(i_buffer,i_buffersize,"%.02f %s",mybytes,myappend[i]);
fcorbelli commented 10 months ago

Please check the attached pre-release 58_11s.zip

ghost commented 10 months ago

I wrote something here about invalid pointer, but it's actually static (I missed that detail!) so I deleted the previous post. But then the potential problem is running in multiple threads, more threads "attacking" the same static buffers, also a problem.

fcorbelli commented 10 months ago

There is a mutex on the output, so this doesn't happen It's a choice for performance

fcorbelli commented 10 months ago

Something like that

lock(job.mutex);
(print something)
release(job.mutex);
ghost commented 10 months ago

If you mutex, that can still potentially cost more performance then having local

char buff1[...], buff2[ ]
... migl( buff1, x ),   migl( buff2, y) ...
fcorbelli commented 10 months ago

Mutex is mandatory for console output Therefore only a single thread can call the output function migliaia

Better, the functionS migliaia No C++ strings allowed, too slow

Yep weird, but fast

ghost commented 10 months ago

Yes I'm not talking about C++ but on passing up to N buffer pointers to local buffers to a single myg function instead of having "static" buffers and N myg functions

fcorbelli commented 10 months ago

Different functions is the fastest overall implementation, kind of "function unrolling"

Because you have to call multiple times for a single output row with printf %s Up to 5 in fact You really do not want to allocate and deallocate on stack char buffers, for (worst case) millions of times And you do not want any kind of conversions of char to strings etc

As I said it is a performance issue

ghost commented 10 months ago

Because you have to call multiple times for a single output row with printf %s Up to 5 in fact You really do not want to allocate and deallocate on stack char buffers, for (worst case) millions of times And you do not want any kind of conversions of char to strings etc

I know it differently, and I'm quite sure also in the use case there, where you use these statics, one "allocation" on the stack of a few local char[30 ] buffers in a function which is calling myprintf and a few miglias is practically zero cost operation (most of the time introducing zero new T states spent, and neither dependent on N in buff1 or buff1, buff2, buffN there, and, of course, nor on M which would be the sum of the bytes needed) and at the same time can even be less stressful for the CPU caches (a few bytes on the stack practically always in all CPU mem caches) than access of the statics (in data segment somewhere not touched since who knows when). And I agree, I would also avoid using C++ "string" classes there.

It's all measurable, and in almost any real-life code (doing complex enough work) local "plain" variables (and char [ ] are such too) are faster than statics. It also helps avoiding functions with many parameters, but simply passing pointers to "plain" structures around instead, where such structures are totally ok to be on the stack too, also practically needing "zero" time for what you refer to as "allocation".

fcorbelli commented 10 months ago

The situation is more complex than you think The problem concerns the use, in a single printf, of multiple integer to string conversions (with dots) Something like

printf("ciao %s  %s  %s  %s %s\n",migliaia(10),migliaia(100),migliaia(1000),migliaia(10000),migliaia(100000));

You REALLY do not want to "split" in multiple printf(), like

printf("ciao ");
migliaia(10);
printf(" ");
migliaia(100);
printf(" ");
migliaia(1000);
printf(" ");
migliaia(10000);
printf(" ");
migliaia(100000);
printf("\n");

To make a single printf you need (in this example) 5 ready strings. They can be C++ strings, in which case you will use c_str(), or null-terminated char* (C strings). Obviously the second case is preferable (much faster)

The problem now is to have "something" capable of converting integers to text. For C strings (char*) this is not possible, because you will have to allocate memory "somewhere" (e.g. on the heap), and then you will have to deallocate it (malloc/free => internal fragmentation), or on the stack, every time Like (suppose a migliaia function that get, as 2nd parameter, the output char buffer)

char string1[30];
char string2[30];
char string3[30];
char string4[30];
char string5[30];
migliaia(10,string1);
migliaia(100,string2);
migliaia(1000,string3);
migliaia(10000,string4);
migliaia(100000,string5);

printf("ciao %s %s %s %s %s\n",string1,string2,string3,string4,string5);

You cannot even return an array of characters allocated on the stack, i.e. a local variable of a function, just in your deleted post

You can, of course, create functions and helper structures, creating "your" strings, similar to C++, but at that point you might as well use std::string (too slow indeed)

This is why the various solutions have already been examined, with profiling (i.e. concrete measurement of performance), arriving at today's solution.

More precisely, in reality, there were actually different functions (function unrolling) for maximum performance but it was so bad, stylistically, that I decided to refactor along the lines (introducing the bug in question, having corrected one but not the two functions of conversion)

And no, passing structures to functions slows down. Sometimes it's not a problem, sometimes it is The "amateur" approaches, let's say from a programmer with little experience who has read about patterns and antipatterns in books, are very far from the professional approaches of those who have been programming for thirty years, and perhaps have also programmed compilers and perhaps programmed in assembly for decades You read "do not pass a lot of parameters to a function, this is bad and can make issues" True If you are programming a software with a GUI or that does almost "nothing" all the time (aka: not CPU bound)

Sometimes I'm lazy, and I don't care, to use decidedly sub-optimal systems.

Sometimes, however, I enjoy writing as it was done when programs occupied a maximum of 1000 bytes (the video memory of a Commodore 64)

You will see many apparently strange things, for less experienced programmers, such as the use of dozens and dozens of Boolean variables for switches, instead of much more elegant and compact structures (like maps, vectors or whatever you want) The reason, again, is performance

Testing a boolean variable is orders of magnitude faster than querying a complex structure. Sometimes also try to reduce the number of variables tested, to hope for an optimization in one CPU register (this is rarely achieved) by the compiler

And, within cycles repeated millions or billions of times [like in a compressor] the difference becomes noticeable

Then there are many more hard core approaches, i.e. specific optimizations for the single CPU, which are natural for an old assembler developer like me (e.g. the CPUID instruction is normally faster than an if(booleanvariable) and also reduces cache flush)

But I'm avoiding them, because CPUs are now among the strangest, and you can't assume that what is "smart" for processor X is also smart for processor Y, perhaps completely different

Short version: if you don't understand the "why" of a solution, maybe it has already been thought of, rethought, measured and optimized over time. Or, even, it is simply wrong 😄

ghost commented 10 months ago

The principle used in the example you've given, let's call that principle (1):

char s1[30], s2[30], s3[30], char s4[30], s5[30];
myf(10,s1); myf(100,s2); myf(1000,s3); myf(10000,s4); myf(100000,s5);
printf("ciao %s %s %s %s %s\n",s1,s2,s3,s4,s5);

is indeed that what I've suggested, in most real-life uses, to be faster, and in the rest of the cases, at least not slower than your "static char []" way (let's call that (2)). As I've mentioned: what you call an "allocation" in a function which already has its own stack frame doesn't cost any new cycles, as long as you still use char [ ] (and not C++ string classes) and it can be more cache friendly than your preferred "static" solution.

The function containing that printf typically already has to have its own stack frame and the instructions executed for that are identical, with or without the existence of the space on the stack reserved for these s1..s5. Additionally, in the specific example of yours, the execution times of myf and printf are already orders of magnitude higher than that stack frame maintenance, making the difference, which you say exists, probably immeasurable.

If you have actually observed the difference between (1) against (2) in the actual use, I'm curious to learn about some specific location in zpaqfranz where that can be seen in measurements. I can imagine a special example of a function which in the (2) case wouldn't need its stack frame, if the function code created due to (1) results in the need for the stack frame to be introduced by a compiler. It would be interesting to me to see an example where that actually happens and really changes the execution time (as in: "I measure ... with 1 and ... with 2). That would be a new insight for me.

fcorbelli commented 10 months ago

The principle used in the example you've given, let's call that principle (1):

char s1[30], s2[30], s3[30], char s4[30], s5[30];
myf(10,s1); myf(100,s2); myf(1000,s3); myf(10000,s4); myf(100000,s5);
printf("ciao %s %s %s %s %s\n",s1,s2,s3,s4,s5);

is indeed that what I've suggested, in most real-life uses, to be faster, and in the rest of the cases, at least not slower than your "static char []" way (let's call that (2)).

The syntactic complexity becomes enormous. That is, you have to write code upon code upon code, to get the same result in terms of performance So it is a worse choice

If you are curious to look for the "archaic" versions of zpaqfranz you will see different solutions for this problem. Frankly, I have not kept track of it, it is inside the sources

The question to be answered is: is the currently implemented solution concise (syntactically) and fast (in execution)? If the answer is yes, then it is the best tradeoff (under the circumstances)

ghost commented 10 months ago

To summarize, I'm saying for this, what I call (1):

// (1)
// works always, uses stack
char s1[30], s2[30], s3[30], s4[30], s5[30];
myf(10,s1); myf(100,s2); myf(1000,s3); myf(10000,s4); myf(100000,s5);
printf("ciao %s %s %s %s %s\n",s1,s2,s3,s4,s5);

I don't expect to be possible to measure in practical use cases to be slower (and I explained the technical reasons for that) than this:

// (2)
// needs functions with different names
inline char* myf1(int64 x) 
{
    static char s[ 30 ]; // uses data segment
    return myf( x, s );
}    
inline char* myf2(int64 x) 
{
    static char s[ 30 ];
    return myf( x, s );
}    
inline char* myf3(int64 x) 
{
    static char s[ 30 ];
    return myf( x, s );
}    
inline char* myf4(int64 x) 
{
    static char s[ 30 ];
    return myf( x, s );
}    
inline char* myf5(int64 x) 
{
    static char s[ 30 ];
    return myf( x, s );
}    
lock( ); // needs locks <-- critical before use of myfN because they depend on "static" vars
printf("ciao %s %s %s %s %s\n",
    myf1(10),myf2(100),myf3(1000),myf4(10000),myf5(100000));
unlock( );

and also that (1) has the advantages of not depending on the locks used in the correct places to be able to trust the results of the output as soon as the code is called from more threads. You call the approach (1) "code upon code upon code", and I don't see it that way.

I understood you that you like the trade-off you use, and I agree that you can do what you like in your own code.

I personally consider (2) a kind of code which is has bigger potential to result in the output which can contain something that doesn't reflect the information that was supposed to be printed (due to the mentioned locking issues) but I definitely know that after informing you about that I really can't expect from you to do anything about it. Thanks.

ghost commented 10 months ago

I've also forgotten to make it fully clear: if you ever happen to have the calls to the functions containing uses of statics like this, and it happens that they are executed in parallel from different threads (i.e. the correct locks() didn't protect from that) that remains a source of potential crashes, even after the sizeof() bug is corrected. That is the main reason I've pointed to that, I really have no interest to discuss the esthetic preferences of the sources here, just what is actually executed as a consequence of something written.

fcorbelli commented 10 months ago

Context is key During important phases (i.e., multithread compression), you cannot run the risk of having any race condition between threads, full stop. The output must be serialized, and here is the mutex This solves any possible issues at the root

On support functions (e.g., multithreaded folder scanning), on the other hand, the issue is much more relaxed You can get inexact results (partially overwritten), not crashes But there is not the slightest importance in the correctness of the data shown, they are advances info, nobody really cares You can even find on the developer forum my thread on this very situation

Short version: in critical section you must serialize the output => you must use a mutex or whatever => no possible crashes, no possible overwrite => already done

Everywhere else... who care? 😄

PS as you have seen, or maybe not, there is NOT printf() in zpaqfranz, but myprintf() Because I can easilly put a mutex right here, in myprintf(), if I really want to be sure

myprint(whatever)
{
lock( ); // needs locks <-- critical before use of myfN because they depend on "static"  
printf(whatever)
unlock( );
}

myprintf("ciao");
myprintf("cucu");
fcorbelli commented 10 months ago

But, in fact, there is already something like that (with explicit pthread mutex), just to be sure no concurrent calls

pthread_mutex_lock(&g_mylock);
if ((!flagsilent) && (!flagnoconsole))
{
    setupConsole();
    printf("\033[%d;0H",(int)i_tnumber+1);
    restoreConsole();
}
myprintf("Thread %02d %03d s %12s: speed (%11s/s)",i_tnumber,trascorso,i_runningalgo.c_str(),tohuman3((int64_t)o_speed));
pthread_mutex_unlock(&g_mylock);

The "tohuman" functions are just like migliaia

ghost commented 10 months ago

You can get inexact results (partially overwritten), not crashes

If they aren't inside of the lock and if they use statics, there can be crashes. It's actually improbable that the result will be "just inexactness" on every CPU architecture, almost none has an identical semantics as x86 . ARM's will definitely re-order memory writes relative to other writes when x86 won't.

Read that slowly: they re-order writes. What you've learned to expect about how the code executes in multiple threads on x86 just won't help you.

It's a long topic and a lot is written about it.

Everywhere else... who care?

I don't know? I thought, you, as we are discussing this in the thread about the crash in native ARM code? And you would not write these functions to be executed without the locks in multiple threads, without having some expectations. Reading your answers:

I hope I have summarized your messages correctly. If it's so, I don't think it's realistic to create such functions (EDIT: which use static" -- to be clear, that's what I talked about all the time) and expect from them to not crash on different CPU architectures. You should familiarize yourself with the problems caused by reordering on non-x86 architectures.

Once you do, I believe you can find that my suggestion is significantly cheaper than locks, even if you manage to place them on all correct places (which is typically not trivial). Until then, I expect there will be crashes.

If you say you simply don't care about the non x86-like architectures, I can understand that too. It's your work.

fcorbelli commented 10 months ago

Read that slowly

Read that even more slowly. There-is-mutex I repeat There-is-mutex

Yes, really, there is a g_mylock (a global lock) to be used to be sure no races during console output for non-Jidac threads

It's a very basic topic, I have writted a lot about it, more than 20 years ago Well, maybe even 30, let's say 28 😃

You should familiarize yourself with the problems caused by reordering on non-x86 architectures.

Thanks for your help. I will give it the consideration it deserves

Consider that not only did I write an entire operating system Unix-like on a non-Intel architecture (AXP) but I even designed my very own microprocessor (well, actually quite simple) and my first university paper was on Motorola 68K Let's say that I think I have a fairly precise idea of ​​"how it works" It's my job, afterall

Short version: no risks for crashes by multithread, in zpaqfranz, (obviously excluding the bugs it is full of) Trivial problem already taken into consideration

ghost commented 10 months ago

I wrote my previous message after seeing:

You can get inexact results (partially overwritten), not crashes

Reading that lead me to believe that you aren't familiar with write reordering issues, as I can't imagine that it's possible to claim that without the locks. And with the locks I haven't expected partial overwrites.

I'm also not familiar with Motorola 68K architecture which was ever able to exhibit the Arm-like conditions for reordering, so I don't know how that's relevant.

If you already lock in all needed places, then I admit that there will be no mysterious crashes that are the consequence of your preferential use of static variables in multithreaded code.

luckman212 commented 10 months ago

This conversation was surely an interesting read and went way over my head. But thank you @janko-js for your insights and especially thank you @fcorbelli for fixing the crash. 🙏