AROS World Exec
Development => Development (General) => Topic started by: aGGreSSor on October 28, 2020, 06:46:43 AM
-
Simple code:
#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:
i386-aros-gcc clock.c -o clock_aros-i386.exe -std=c99
Run it:
tick1 = 0
tick2 = 0
WTF?! Why clock() call always return zero?
Am I doing something wrong?
-
Simple code:
#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...
#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));
-
Simple code:
#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:
i386-aros-gcc clock.c -o clock_aros-i386.exe -std=c99
Run it:
tick1 = 0
tick2 = 0
WTF?! Why clock() call always return zero?
Am I doing something wrong?
Try a different compiler optimization option perhaps?
-
What does time(NULL) give you?
-
What does time(NULL) give you?
It's just work..
// 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);
}
$ gcc deadwood.c -o deadwood_win.exe
$ ./deadwood_win.exe
NOW: 2020-10-31 03:34:55
$ 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.
-
O.K.
$ 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
$ 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
-
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.
-
Here is a new version of stdc.library. Let me know if it works for you.
https://axrt.org/development/stdc.library.zip (https://axrt.org/development/stdc.library.zip)
-
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/
$ 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..
$ 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;
(https://i.postimg.cc/c4zV7XSp/AROS-stdc.png)
I think my problem here is static linking..
-
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?
-
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.
$ 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.
$ 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
-
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
-
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!
(https://i.postimg.cc/Z5cMRScx/AROS-bogomips.png)
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.
-
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.
-
Here is non-debug version:
https://axrt.org/development/arosc.library.43.1
-
Here is non-debug version:
https://axrt.org/development/arosc.library.43.1
My deepest thanks!
BogoMIPS on aminet (http://aminet.net/package/util/moni/BogoMIPS), os4depot (http://os4depot.net/?function=showfile&file=utility/benchmark/bogomips.lha) and aros-exec (http://archives.aros-exec.org/download.php?file=queue/bogomips.i386-aros.lha).