forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

clock() doesn't work anymore

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sun Nov 27, 2005 4:11 am    Post subject: clock() doesn't work anymore Reply with quote

In the program below, with the PSPSDK from SVN repository from yesterday, the displayed clock values look random instead of counting up. The same problem is in Lua Player, where the problem was found. I think in earlier versions of the PSPSDK it worked, but the problem shows only sometimes (looks like it depends on the system time and how long the PSP runs), so I'm not sure. Or is it my fault how I use the clock function?

main.c:

Code:

#include <time.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>

/* Define the module info section */
PSP_MODULE_INFO("TEST", 0, 1, 1);

/* Define the main thread's attribute value (optional) */
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

int main(void)
{
   pspDebugScreenInit();
   while (1) {
      SceCtrlData pad;
      sceCtrlReadBufferPositive(&pad, 1);
      if (pad.Buttons) break;
      pspDebugScreenClear();
      pspDebugScreenPrintf("clock: %lu\n", clock());
      sceDisplayWaitVblankStart();
      sceDisplayWaitVblankStart();
   }
   sceKernelExitGame();

   return 0;
}


Makefile:

Code:

TARGET = test
OBJS = main.o

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LDFLAGS =
LIBS = -lpsputility

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Test

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Sun Nov 27, 2005 4:54 am    Post subject: Reply with quote

__psp_set_errno should probably be removed from clock() and maybe time() in newlib-psp/newlib/libc/sys/psp/libcglue.c.
Back to top
View user's profile Send private message
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Sun Nov 27, 2005 5:05 am    Post subject: Reply with quote

Fixed in revision 1489.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sun Nov 27, 2005 5:11 am    Post subject: Reply with quote

mrbrown wrote:
Fixed in revision 1489.


Thanks! This was fast, as always :-)
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Sun Nov 27, 2005 5:19 am    Post subject: Reply with quote

The fix in 1489 is definitely right for clock, but I think time and gettimeofday should keep __psp_set_errno. You could check the return value of time(123) and gettimeofday(123, 456) to see. I can't test it at the moment.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sun Nov 27, 2005 5:26 am    Post subject: Reply with quote

jimparis wrote:
The fix in 1489 is definitely right for clock, but I think time and gettimeofday should keep __psp_set_errno. You could check the return value of time(123) and gettimeofday(123, 456) to see. I can't test it at the moment.


According to some Unix man pages, gettimeofday should return 0. Looks like errno is not set: http://www.opengroup.org/onlinepubs/009695399/functions/gettimeofday.html

Looks like time() has no errors defined, too, so it should be ok: http://www.opengroup.org/onlinepubs/009695399/functions/time.html
Back to top
View user's profile Send private message
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Sun Nov 27, 2005 5:32 am    Post subject: Reply with quote

Fixed again :). Thanks for spotting this. I just looked at the manual pages and those funcs should be setting errno on error.
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sun Nov 27, 2005 7:00 am    Post subject: Reply with quote

mrbrown wrote:
Fixed again :). Thanks for spotting this. I just looked at the manual pages and those funcs should be setting errno on error.


According to the ANSI C standard (at least the ISO/IEC 9899:1999, which I have here) the time() function needs not to set errno, but chapter 7.5 says, that it is implementation dependent: A function can set errno, if it is not documented in the standard otherwise. And looks like for gettimeofday some architectures in newlib sets the variable and some not. And the "Single Unix specification" doesn't define that errno is set, but most Unix manual pages does. But this is hairsplitting, I've never seen a program, which checks errno for gettimeofday, so your patch is ok :-)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group