[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] MiNTlib timing related functions behavior/performance
Hi,
On keskiviikko 17 huhtikuu 2013, Alan Hourihane wrote:
> On 04/17/13 16:59, Eero Tamminen wrote:
> > I'm mainly interested in TOS performance, would a patch to
> > shortcircuit nanosleep() to _clock() when running without
> > MiNT be acceptable?
Attached is an untested patch.
- Eero
PS. It's untested because MiNTlib from CVS doesn't build
in my Sparemint/Aranym setup ("cat" complains about
there being no file named "-", Make complaining about
"multibyte" directory missing).
As a wild guess, that might be related to "includepath" file
that doesn't exist, but is references in relation to "cat":
-------------
$ grep includepath $(find -type f)
./buildrules:-I$(top_srcdir)/mintlib -I$(top_srcdir)/stdlib -I$(shell cat
$(top_srcdir)/includepath)
./buildrules:all-here: $(top_srcdir)/CFILES $(top_srcdir)/includepath
$(LIBS)
./buildrules:$(top_srcdir)/includepath: $(top_srcdir)/configvars
./Makefile: rm -rf .deps includepath CFILES
./checkrules:INCLUDES = -nostdinc -I$(shell cat $(top_srcdir)/includepath) \
./TODO:o includepath: Guido
./ChangeLog: * buildrules, checkrules: Fix the includepath generation
based on
./.cvsignore:includepath
-------------
? diff
Index: posix/nanosleep.c
===================================================================
RCS file: /mint/mintlib/posix/nanosleep.c,v
retrieving revision 1.1
diff -u -r1.1 nanosleep.c
--- posix/nanosleep.c 13 Dec 2010 09:35:35 -0000 1.1
+++ posix/nanosleep.c 18 Apr 2013 12:09:15 -0000
@@ -5,6 +5,13 @@
#include <time.h>
#include <sys/time.h>
#include <errno.h>
+#include <mint/mintbind.h>
+
+#define TIMESPEC_TO_USEC(ts) ((ts)->tv_sec * 1000000L + (ts)->tv_nsec / 1000)
+#define USEC_PER_TICK (1000000L / ((unsigned long)CLOCKS_PER_SEC))
+#define USEC_TO_CLOCK_TICKS(us) ((us) / USEC_PER_TICK )
+
+clock_t _clock (void);
enum { BILLION = 1000 * 1000 * 1000 };
@@ -20,6 +27,19 @@
return -1;
}
+ if (!__mint) {
+ /* on TOS this cannot be interrupted and
+ * there's no Tgettimeofday/Fselect,
+ * so just busyloop
+ */
+ long stop;
+ __useconds_t useconds = TIMESPEC_TO_USEC(req);
+ stop = _clock() + USEC_TO_CLOCK_TICKS(useconds);
+ while (_clock() < stop)
+ ;
+ return 0;
+ }
+
wait.tv_sec = req->tv_sec;
wait.tv_usec = (req->tv_nsec + 999) / 1000;
if (wait.tv_usec == 1000000) {