AROS ABIv0 clock() WTF?! (SOLVED)

aGGreSSor · 814

aGGreSSor

  • Member
  • ***
    • Posts: 122
    • Karma: +3/-0
    • russian transit
on: October 28, 2020, 12:46:43 PM
Simple code:
Code: [Select]
#include <stdio.h>
#include <time.h>

int main(void)
{
  unsigned long tick1;
  for(int i=0;i<100000000;i++);
  tick1 = clock ();
  printf("tick1 = %d\n", tick1);
  long tick2;
  for(int i=0;i<100000000;i++);
  tick2 = clock ();
  printf("tick2 = %d\n", tick2);
}
Compile it:
Quote
i386-aros-gcc clock.c -o clock_aros-i386.exe -std=c99
Run it:
Quote
tick1 = 0
tick2 = 0
WTF?! Why clock() call always return zero?
Am I doing something wrong?
« Last Edit: November 05, 2020, 11:22:11 PM by aGGreSSor »



mmartinka

  • Newbie
  • *
    • Posts: 39
    • Karma: +3/-0
Reply #1 on: October 28, 2020, 05:42:36 PM
Simple code:
Code: [Select]
#include <stdio.h>
#include <time.h>

int main(void)
{
  unsigned long tick1;
  for(int i=0;i<100000000;i++);
  tick1 = clock ();
  printf("tick1 = %d\n", tick1);
  long tick2;
  for(int i=0;i<100000000;i++);
  tick2 = clock ();
  printf("tick2 = %d\n", tick2);
}
Am I doing something wrong?

This not work me too ... try this code...
Code: [Select]
#include <proto/timer.h>

struct timeval  tv1, tv2;
gettimeofday(&tv1, NULL);
/* stuff to do! */
gettimeofday(&tv2, NULL);

printf ("Total time = %f seconds\n",
         (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
         (double) (tv2.tv_sec - tv1.tv_sec));
« Last Edit: October 28, 2020, 07:00:38 PM by mmartinka »



dizzy

  • Newbie
  • *
    • Posts: 43
    • Karma: +0/-0
Reply #2 on: October 30, 2020, 12:47:37 PM
Simple code:
Code: [Select]
#include <stdio.h>
#include <time.h>

int main(void)
{
  unsigned long tick1;
  for(int i=0;i<100000000;i++);
  tick1 = clock ();
  printf("tick1 = %d\n", tick1);
  long tick2;
  for(int i=0;i<100000000;i++);
  tick2 = clock ();
  printf("tick2 = %d\n", tick2);
}
Compile it:
Quote
i386-aros-gcc clock.c -o clock_aros-i386.exe -std=c99
Run it:
Quote
tick1 = 0
tick2 = 0
WTF?! Why clock() call always return zero?
Am I doing something wrong?

Try a different compiler optimization option perhaps?



deadwood

  • AROS Developer
  • Member
  • *****
    • Posts: 213
    • Karma: +18/-0
Reply #3 on: October 30, 2020, 04:35:31 PM
What does time(NULL) give you?



aGGreSSor

  • Member
  • ***
    • Posts: 122
    • Karma: +3/-0
    • russian transit
Reply #4 on: October 31, 2020, 01:38:45 AM
What does time(NULL) give you?
It's just work..

Code: [Select]
// deadwood.c
#include <stdio.h>
#include <time.h>

int main(void)
{
    time_t t = time(NULL);
    struct tm tm = *localtime(&t);
    printf("NOW: %d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}
Code: [Select]
$ gcc deadwood.c -o deadwood_win.exe
$ ./deadwood_win.exe
NOW: 2020-10-31 03:34:55
Code: [Select]
$ i386-aros-gcc deadwood.c -o deadwood_aros-i386.exe -std=c99
$ ./deadwood_aros-i386.exe
NOW: 2020-10-31 03:37:59

Try a different compiler optimization option perhaps?
I found this problem while trying to compile bogomips.
The original of any version compiles and works fine on all platforms (except AROS) with the option -O3.
So I also thought about optimization and didn't use the optmization option in this examples. It didn't help me.

try this code...
This code works, but it isn't very convenient to use in iterations. Although this might be a solution for AROS.
« Last Edit: October 31, 2020, 01:51:41 AM by aGGreSSor »



aGGreSSor

  • Member
  • ***
    • Posts: 122
    • Karma: +3/-0
    • russian transit
Reply #5 on: October 31, 2020, 02:13:33 AM
O.K.
Code: [Select]
$ gcc bogomips.c -o bogomips_win.exe -O0
$ ./bogomips_win.exe
..
DEBUG: ticks 796
DEBUG: delay 536870912
DEBUG: iteration
DEBUG: ticks 1562
DEBUG: delay 1073741824
DEBUG: ticks 1547 >= clock 1000
ok - 1388.16 BogoMips

Code: [Select]
$ i386-aros-gcc bogomips.c -o bogomips_aros-i386.exe -O0 -std=c99
$ ./bogomips_aros-i386.exe
...
DEBUG: ticks 0
DEBUG: delay 134217728
DEBUG: iteration
DEBUG: ticks 0
DEBUG: delay 268435456
DEBUG: iteration
DEBUG: ticks 0
DEBUG: delay 536870912
DEBUG: iteration
DEBUG: ticks 1
DEBUG: delay 1073741824
DEBUG: iteration
DEBUG: ticks 3
DEBUG: delay 2147483648
failed
bogomips_aros-i386.exe: filesystem action type unknown



deadwood

  • AROS Developer
  • Member
  • *****
    • Posts: 213
    • Karma: +18/-0
Reply #6 on: October 31, 2020, 11:17:48 AM
clock() is indeed broken in AROS since 2012...

It was changed to use time(), but time() has resolution of seconds, so that's why you get '0' as result most of the time.

I'll see if I can fix that, but this means people will have to update their C libraries for your software to work.



deadwood

  • AROS Developer
  • Member
  • *****
    • Posts: 213
    • Karma: +18/-0
Reply #7 on: October 31, 2020, 11:57:19 AM
Here is a new version of stdc.library. Let me know if it works for you.

https://axrt.org/development/stdc.library.zip



aGGreSSor

  • Member
  • ***
    • Posts: 122
    • Karma: +3/-0
    • russian transit
Reply #8 on: October 31, 2020, 12:57:18 PM
Unfortunately it didn't work for me. I replaced LIBS:stdc.library to your version, rebooted the virtual machine with AROS installed and tried to run the previously compiled bogomips_aros-i386.exe The error remained the same.

My cygwin doesn't have a clock () in /gcc/i386-aros-gcc/
Quote
$ grep -rwn "clock()" /usr/local/amiga/
/usr/local/amiga/lib/gcc/ppc-morphos/2.95.3/lib/sys-include/machine/ansi.h:50:#define   _BSD_CLOCK_T_           unsigned long   /* clock() */
/usr/local/amiga/lib/gcc/ppc-morphos/2.95.3/sys-include/machine/ansi.h:50:#define       _BSD_CLOCK_T_           unsigned long   /* clock() */
/usr/local/amiga/lib/gcc/ppc-morphos/2.95.3/sys-includestd/machine/ansi.h:53:#define    _BSD_CLOCK_T_   unsigned long           /* clock() */
/usr/local/amiga/lib/gcc-lib/ppc-morphos/2.95.3/lib/sys-include/machine/ansi.h:50:#define       _BSD_CLOCK_T_           unsigned long   /* clock() */
/usr/local/amiga/lib/gcc-lib/ppc-morphos/2.95.3/sys-include/machine/ansi.h:50:#define   _BSD_CLOCK_T_           unsigned long   /* clock() */
/usr/local/amiga/lib/gcc-lib/ppc-morphos/2.95.3/sys-includestd/machine/ansi.h:53:#define        _BSD_CLOCK_T_   unsigned long           /* clock() */
/usr/local/amiga/m68k-amigaos/clib2/include/time.h:59: * Divide the number returned by clock() by CLOCKS_PER_SEC to obtain
/usr/local/amiga/m68k-amigaos/sys-include/sys/_types.h:185:#define      _CLOCK_T_       unsigned long   /* clock() */
/usr/local/amiga/ppc-amigaos/SDK/clib2/include/time.h:59: * Divide the number returned by clock() by CLOCKS_PER_SEC to obtain
/usr/local/amiga/ppc-amigaos/SDK/local/clib2/include/time.h:59: * Divide the number returned by clock() by CLOCKS_PER_SEC to obtain
/usr/local/amiga/ppc-amigaos/SDK/local/newlib/include/machine/types.h:13:#define        _CLOCK_T_       unsigned long long      /* clock() */
/usr/local/amiga/ppc-amigaos/SDK/newlib/_include/machine/types.h:13:#define     _CLOCK_T_       unsigned long long      /* clock() */
/usr/local/amiga/ppc-morphos/lib/sys-include/machine/ansi.h:50:#define  _BSD_CLOCK_T_           unsigned long   /* clock() */
/usr/local/amiga/ppc-morphos/lib/sys-includestd/machine/ansi.h:53:#define       _BSD_CLOCK_T_   unsigned long           /* clock() */
/usr/local/amiga/ppc-morphos/sys-include/machine/ansi.h:50:#define      _BSD_CLOCK_T_           unsigned long   /* clock() */
/usr/local/amiga/ppc-morphos/sys-includestd/machine/ansi.h:53:#define   _BSD_CLOCK_T_   unsigned long           /* clock() */

Indeed, in AROS itself, few application use call() and everything comes from stdc..
Quote
$ grep -rwn "clock()" AROS-main/
AROS-main/compiler/stdc/clock.c:23:       clock() returns an approximation of the time passed since
AROS-main/developer/debug/test/freetype/src/ftbench.c:190:    /* clock() accuracy has improved since glibc 2.18 */
AROS-main/developer/debug/test/freetype/src/ftbench.c:191:    return 1E6 * (double)clock() / (double)CLOCKS_PER_SEC;
AROS-main/developer/debug/test/freetype/src/fttimer.c:29:#include <time.h>    /* for clock() */
AROS-main/developer/debug/test/freetype/src/fttimer.c:83:    return clock() * 10000 / CLOCKS_PER_SEC;
AROS-main/developer/debug/test/freetype/src/gbench.c:484:  /* clock() has an awful precision (~10ms) under Linux 2.4 + glibc 2.2 */
AROS-main/developer/debug/test/freetype/src/gbench.c:485:  return (double)clock() / (double)CLOCKS_PER_SEC;
AROS-main/workbench/classes/zune/nlist/demo/NListtree-Demo.c:752:       start = clock();
AROS-main/workbench/classes/zune/nlist/demo/NListtree-Demo.c:754:       end = clock();
AROS-main/workbench/libs/expat/tests/benchmark/benchmark.c:83:    tstart = clock();
AROS-main/workbench/libs/expat/tests/benchmark/benchmark.c:102:    tend = clock();
AROS-main/workbench/libs/png/pngtest.c:1460:   t_stop = (float)clock();
AROS-main/workbench/libs/png/pngtest.c:1501:         t_stop = (float)clock();
AROS-main/workbench/libs/png/pngtest.c:1507:         t_stop = (float)clock();
AROS-main/workbench/libs/png/pngtest.c:2105:   t_stop = (float)clock();
AROS-main/workbench/system/Wanderer/filesystems.c:466:                    unsigned int difftime = clock();
AROS-main/workbench/system/Wanderer/filesystems.c:475:                                display->difftime = clock() - difftime;


I think my problem here is static linking..
« Last Edit: October 31, 2020, 01:17:36 PM by aGGreSSor »



deadwood

  • AROS Developer
  • Member
  • *****
    • Posts: 213
    • Karma: +18/-0
Reply #9 on: October 31, 2020, 01:17:19 PM
You seems to be using the arosc.library C implementation. Which compiler are you using? A cross-compiler or a native gcc under AROS? What is the version of the compiler?



aGGreSSor

  • Member
  • ***
    • Posts: 122
    • Karma: +3/-0
    • russian transit
Reply #10 on: October 31, 2020, 01:20:56 PM
You seems to be using the arosc.library C implementation. Which compiler are you using? A cross-compiler or a native gcc under AROS? What is the version of the compiler?
I think my problem here is static linking, but not immediately find where it comes from. i'm using cross compiler under cygwin.

Quote
$ i386-aros-gcc --version
i386-aros-gcc.exe (GCC) 4.2.2
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Quote
$ i386-aros-gcc bogomips.c -o bogomips_aros-i386.exe -std=c99 -O0 -v
Using built-in specs.
Target: i386-aros
Configured with: ./configure --target=i386-aros --prefix=/mingw --enable-languages=c,c++
Thread model: single
gcc version 4.2.2
 c:/dev/cygwin64/usr/local/amiga/bin/../libexec/gcc/i386-aros/4.2.2/cc1.exe -quiet -v -iprefix c:\dev\cygwin64\usr\local\amiga\bin\../lib/gcc/i386-aros/4.2.2/

 bogomips.c -quiet -dumpbase bogomips.c -mtune=i386 -auxbase bogomips -O0 -std=c99 -version -o C:\dev\cygwin64\tmp/cc7QWTdH.s
ignoring nonexistent directory "/usr/local/amiga/lib/gcc/i386-aros/4.2.2/include"
ignoring nonexistent directory "/usr/local/amiga/lib/gcc/../../i386-aros/sys-include"
ignoring nonexistent directory "/usr/local/amiga/lib/gcc/../../i386-aros/include"
#include "..." search starts here:
#include <...> search starts here:
 c:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc/i386-aros/4.2.2/include
 c:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc/i386-aros/4.2.2/../../../../i386-aros/sys-include
 c:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc/i386-aros/4.2.2/../../../../i386-aros/include
End of search list.
GNU C version 4.2.2 (i386-aros)
        compiled by GNU C version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: e9cb931580dbcd5c6743cf4bb8533fdb
 c:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc/i386-aros/4.2.2/../../../../i386-aros/bin/as.exe -V -Qy -o C:\dev\cygwin64\tmp/ccoaApgq.o C:\dev\cygwin64\tmp/

cc7QWTdH.s
GNU assembler version 2.19 (i386-aros) using BFD version (GNU Binutils) 2.19
 c:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc/i386-aros/4.2.2/../../../../i386-aros/bin/collect-aros.exe --eh-frame-hdr -m elf_i386 -o bogomips_aros-i386.ex

e c:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc/i386-aros/4.2.2/../../../../i386-aros/lib/startup.o -Lc:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc/i386-aro

s/4.2.2 -Lc:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc -Lc:/dev/cygwin64/usr/local/amiga/bin/../lib/gcc/i386-aros/4.2.2/../../../../i386-aros/lib C:\dev\cyg

win64\tmp/ccoaApgq.o -lgcc -lamiga -larossupport -larosc -lm -lgcc -lautoinit


deadwood

  • AROS Developer
  • Member
  • *****
    • Posts: 213
    • Karma: +18/-0
Reply #11 on: October 31, 2020, 01:31:14 PM
Ok, that's explains it. You are using an older compiler which was linking to arosc.library. Here is patched vesion:

https://axrt.org/development/arosc.library.43.1.zip



aGGreSSor

  • Member
  • ***
    • Posts: 122
    • Karma: +3/-0
    • russian transit
Reply #12 on: October 31, 2020, 02:26:14 PM
Ok, that's explains it. You are using an older compiler which was linking to arosc.library. Here is patched vesion:
https://axrt.org/development/arosc.library.43.1.zip

It worked!



I will upload these two libraries to an aros-archive.org with your permission?
i had the same problems in the AROS One and IcarOS distributive.


deadwood

  • AROS Developer
  • Member
  • *****
    • Posts: 213
    • Karma: +18/-0
Reply #13 on: October 31, 2020, 02:33:32 PM
Glad it worked.

I'll build you a release version (this one has debug info so it is big). You only need arosc.library.
Please don't upload the library separatelly, but include it in your program package.



deadwood

  • AROS Developer
  • Member
  • *****
    • Posts: 213
    • Karma: +18/-0
Reply #14 on: October 31, 2020, 03:47:09 PM