Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14304
Modified Files: Tag: devel_0_38 s_inter.c m_sched.c Log Message: - scheduler cleanup: there are professional profilers out there - split microsleep & socket polling
Index: s_inter.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_inter.c,v retrieving revision 1.5.4.7 retrieving revision 1.5.4.8 diff -C2 -d -r1.5.4.7 -r1.5.4.8 *** s_inter.c 9 Jan 2005 13:03:01 -0000 1.5.4.7 --- s_inter.c 8 May 2005 23:14:35 -0000 1.5.4.8 *************** *** 151,198 **** }
! static int sys_domicrosleep(int microsec, int pollem) { struct timeval timout; ! int i, didsomething = 0; t_fdpoll *fp; timout.tv_sec = 0; ! timout.tv_usec = microsec; ! if (pollem) ! { ! fd_set readset, writeset, exceptset; ! FD_ZERO(&writeset); ! FD_ZERO(&readset); ! FD_ZERO(&exceptset); ! for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++) ! FD_SET(fp->fdp_fd, &readset); ! #ifdef MSW ! if (sys_maxfd == 0) ! Sleep(microsec/1000); ! else ! #endif ! select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout); ! for (i = 0; i < sys_nfdpoll; i++) ! if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset)) { (*sys_fdpoll[i].fdp_fn)(sys_fdpoll[i].fdp_ptr, sys_fdpoll[i].fdp_fd); didsomething = 1; } ! return (didsomething); ! } ! else ! { ! #ifdef MSW ! if (sys_maxfd == 0) ! Sleep(microsec/1000); ! else ! #endif ! select(0, 0, 0, 0, &timout); ! return (0); ! } }
void sys_microsleep(int microsec) { ! sys_domicrosleep(microsec, 1); }
--- 151,192 ---- }
! ! int sys_pollsockets (void) { struct timeval timout; ! int didsomething = 0; ! int i; t_fdpoll *fp; timout.tv_sec = 0; ! timout.tv_usec = 0; ! ! fd_set readset, writeset, exceptset; ! FD_ZERO(&writeset); ! FD_ZERO(&readset); ! FD_ZERO(&exceptset); ! for (fp = sys_fdpoll, i = sys_nfdpoll; i--; fp++) ! FD_SET(fp->fdp_fd, &readset); ! ! select(sys_maxfd+1, &readset, &writeset, &exceptset, &timout); ! for (i = 0; i < sys_nfdpoll; i++) ! if (FD_ISSET(sys_fdpoll[i].fdp_fd, &readset)) { (*sys_fdpoll[i].fdp_fn)(sys_fdpoll[i].fdp_ptr, sys_fdpoll[i].fdp_fd); didsomething = 1; } ! return (didsomething); }
void sys_microsleep(int microsec) { ! #ifndef MSW ! struct timespec rec, rem; ! rec.tv_sec = 0; ! rec.tv_nsec = 100 * microsec; ! nanosleep(&rec, &rem); ! #else ! /* tb: sleep granularity on windows only 1ms??? */ ! Sleep(microsec/1000); ! #endif }
*************** *** 818,822 **** int sys_pollgui(void) { ! return (sys_domicrosleep(0, 1) || sys_poll_togui()); }
--- 812,817 ---- int sys_pollgui(void) { ! /* return (sys_domicrosleep(0, 1) || sys_poll_togui()); */ ! return (sys_pollsockets() || sys_poll_togui()); }
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.26 retrieving revision 1.5.4.27 diff -C2 -d -r1.5.4.26 -r1.5.4.27 *** m_sched.c 4 May 2005 17:13:57 -0000 1.5.4.26 --- m_sched.c 8 May 2005 23:14:35 -0000 1.5.4.27 *************** *** 356,363 **** }
! /* take the scheduler forward one DSP tick, also handling clock timeouts */ ! void sched_tick(double next_sys_time) { - int countdown = 5000; while (clock_setlist && clock_setlist->c_settime < next_sys_time) { --- 356,362 ---- }
! ! static void run_clock_callbacks(double next_sys_time) { while (clock_setlist && clock_setlist->c_settime < next_sys_time) { *************** *** 367,383 **** outlet_setstacklim(); (*c->c_fn)(c->c_owner); - if (!countdown--) - { - countdown = 5000; - sys_pollgui(); - } if (sys_quit) return; } ! sys_time = next_sys_time; dsp_tick(); - sched_diddsp++; }
/* Here is Pd's "main loop." This routine dispatches clock timeouts and DSP --- 366,384 ---- outlet_setstacklim(); (*c->c_fn)(c->c_owner); if (sys_quit) return; } ! } ! ! ! /* take the scheduler forward one DSP tick, also handling clock timeouts */ ! void sched_tick(double next_sys_time) ! { ! run_clock_callbacks(next_sys_time); /* tb: is the dsp tick the right place for this? */ ! sys_time = next_sys_time; dsp_tick(); }
+ /* Here is Pd's "main loop." This routine dispatches clock timeouts and DSP *************** *** 431,435 **** int timeforward;
- /* sys_addhist(0); */ waitfortick: if (sched_usedacs) --- 432,435 ---- *************** *** 467,471 **** } sys_setmiditimediff(0, 1e-6 * sys_schedadvance); ! /* sys_addhist(1); */ if (timeforward != SENDDACS_NO) sched_tick(sys_time + sys_time_per_dsp_tick); --- 467,471 ---- } sys_setmiditimediff(0, 1e-6 * sys_schedadvance); ! if (timeforward != SENDDACS_NO) sched_tick(sys_time + sys_time_per_dsp_tick); *************** *** 473,485 **** didsomething = 1;
- /* sys_addhist(2); */ sys_pollmidiqueue(); if (sys_pollgui()) { - /* if (!didsomething) */ - /* sched_didpoll++; */ didsomething = 1; } - /* sys_addhist(3); */
/* test for idle; if so, do graphics updates. */ --- 473,481 ---- *************** *** 488,492 ****
sched_pollformeters(); - /* sys_reportidle(); */
/* tb: call idle callbacks */ --- 484,487 ---- *************** *** 503,510 **** #endif } - - /* sys_addhist(5); */ - /* sched_didnothing++; */ - } } --- 498,501 ----