From: Adam D. <ada...@us...> - 2008-01-23 15:18:09
|
Update of /cvsroot/contiki/contiki-2.x/core/sys In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv23602 Modified Files: process.c process.h Log Message: Rewrote the process code so that initialization events are posted synchronously instead of asynchronously, so that we don't have to explicitly wait for processes to be initialized. This also reduces the size of the event queue by half on the Tmote Sky platform since the queue was maximized during system bootup. This change also prompted an update of the process invokation code to ensure that a process is not invoked again when processing an event. General cleanup of the code also. Index: process.h =================================================================== RCS file: /cvsroot/contiki/contiki-2.x/core/sys/process.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** process.h 17 Nov 2007 22:11:19 -0000 1.12 --- process.h 23 Jan 2008 15:18:06 -0000 1.13 *************** *** 276,280 **** process_event_t ev, \ process_data_t data)) - #if PROCESS_LOADABLE #define PROCESS_LOAD(name) const struct process *process_load = &name --- 276,279 ---- *************** *** 321,325 **** PT_THREAD((* thread)(struct pt *, process_event_t, process_data_t)); struct pt pt; ! unsigned char state; }; --- 320,324 ---- PT_THREAD((* thread)(struct pt *, process_event_t, process_data_t)); struct pt pt; ! unsigned char state, needspoll; }; *************** *** 338,342 **** * */ ! void process_start(struct process *p, char *arg); /** --- 337,341 ---- * */ ! void process_start(struct process *p, const char *arg); /** *************** *** 498,501 **** --- 497,512 ---- int process_run(void); + + /** + * Check if a process is running. + * + * This function checks if a specific process is running. + * + * \param p The process. + * \retval Non-zero if the process is running. + * \retval Zero if the process is not running. + */ + int process_is_running(struct process *p); + /** * Number of events waiting to be processed. Index: process.c =================================================================== RCS file: /cvsroot/contiki/contiki-2.x/core/sys/process.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** process.c 4 Apr 2007 09:19:18 -0000 1.5 --- process.c 23 Jan 2008 15:18:06 -0000 1.6 *************** *** 50,53 **** --- 50,55 ---- #include "sys/arg.h" + PROCESS_NAME(simple_cc2420_process); + /* * Pointer to the currently running process structure. *************** *** 67,84 **** }; - #ifdef PROCESS_CONF_FASTPOLL - #define NPOLLS PROCESS_CONF_FASTPOLL - static volatile unsigned npolls; - static struct process *needpoll[NPOLLS]; - #endif static process_num_events_t nevents, fevent; static struct event_data events[PROCESS_CONF_NUMEVENTS]; static volatile unsigned char poll_requested; #define PROCESS_STATE_NONE 0 ! #define PROCESS_STATE_INIT 1 ! #define PROCESS_STATE_RUNNING 2 ! #define PROCESS_STATE_NEEDS_POLL 3 static void call_process(struct process *p, process_event_t ev, process_data_t data); --- 69,84 ---- }; static process_num_events_t nevents, fevent; static struct event_data events[PROCESS_CONF_NUMEVENTS]; + #if PROCESS_CONF_STATS + process_num_events_t process_maxevents; + #endif + static volatile unsigned char poll_requested; #define PROCESS_STATE_NONE 0 ! #define PROCESS_STATE_RUNNING 1 ! #define PROCESS_STATE_CALLED 2 static void call_process(struct process *p, process_event_t ev, process_data_t data); *************** *** 100,104 **** /*---------------------------------------------------------------------------*/ void ! process_start(struct process *p, char *arg) { struct process *q; --- 100,104 ---- /*---------------------------------------------------------------------------*/ void ! process_start(struct process *p, const char *arg) { struct process *q; *************** *** 115,125 **** p->next = process_list; process_list = p; ! ! p->state = PROCESS_STATE_INIT; ! PT_INIT(&p->pt); ! ! /* Post an asynchronous event to the process. */ ! process_post(p, PROCESS_EVENT_INIT, (process_data_t)arg); } /*---------------------------------------------------------------------------*/ --- 115,125 ---- p->next = process_list; process_list = p; ! p->state = PROCESS_STATE_RUNNING; PT_INIT(&p->pt); ! ! PRINTF("process: starting '%s'\n", p->name); ! ! /* Post a synchronous initialization event to the process. */ ! process_post_synch(p, PROCESS_EVENT_INIT, (process_data_t)arg); } /*---------------------------------------------------------------------------*/ *************** *** 130,134 **** struct process *old_current = process_current; ! if(p->state != PROCESS_STATE_NONE) { /* Process was running */ p->state = PROCESS_STATE_NONE; --- 130,136 ---- struct process *old_current = process_current; ! PRINTF("process: exit_process '%s'\n", p->name); ! ! if(process_is_running(p)) { /* Process was running */ p->state = PROCESS_STATE_NONE; *************** *** 169,173 **** if(events[i].p == p) { events[i].p = PROCESS_ZOMBIE; ! #if 0 printf("soft panic: exiting process has remaining event 0x%x\n", events[i].ev); --- 171,175 ---- if(events[i].p == p) { events[i].p = PROCESS_ZOMBIE; ! #if DEBUG printf("soft panic: exiting process has remaining event 0x%x\n", events[i].ev); *************** *** 176,186 **** i = (i + 1) % PROCESS_CONF_NUMEVENTS; } - #ifdef NPOLLS - for(i = 0; i < NPOLLS && i < npolls; i++) { - if(needpoll[i] == p) { - needpoll[i] = PROCESS_ZOMBIE; - } - } - #endif } process_current = old_current; --- 178,181 ---- *************** *** 191,200 **** { int ret; ! if((p->state == PROCESS_STATE_RUNNING || ! p->state == PROCESS_STATE_NEEDS_POLL) && p->thread != NULL) { process_current = p; ! ret = p->thread(&p->pt, ev, data); if(ret == PT_EXITED || --- 186,201 ---- { int ret; + + #if DEBUG + if(p->state == PROCESS_STATE_CALLED) { + printf("process: process '%s' called again with event %d\n", p->name, ev); + } + #endif /* DEBUG */ ! if((p->state & PROCESS_STATE_RUNNING) && p->thread != NULL) { + PRINTF("process: calling process '%s' with event %d\n", p->name, ev); process_current = p; ! p->state = PROCESS_STATE_CALLED; ret = p->thread(&p->pt, ev, data); if(ret == PT_EXITED || *************** *** 202,205 **** --- 203,208 ---- ev == PROCESS_EVENT_EXIT) { exit_process(p, p); + } else { + p->state = PROCESS_STATE_RUNNING; } } *************** *** 218,221 **** --- 221,227 ---- nevents = fevent = 0; + #if PROCESS_CONF_STATS + process_maxevents = 0; + #endif /* PROCESS_CONF_STATS */ process_current = process_list = NULL; *************** *** 230,283 **** { struct process *p; - - poll_requested = 0; - - #ifdef NPOLLS - unsigned i; - int s; - /* Fastpoll */ - //printf("F %d\n", npolls); - for(i = 0; i < npolls; i++) { - do_more: - if(i == NPOLLS) { - goto slowpoll; - } - if(needpoll[i] != PROCESS_ZOMBIE - && needpoll[i]->state == PROCESS_STATE_NEEDS_POLL) { - needpoll[i]->state = PROCESS_STATE_RUNNING; - call_process(needpoll[i], PROCESS_EVENT_POLL, NULL); - } - } - s = splhigh(); - if(i == npolls) { - npolls = 0; - splx(s); - return; - } - splx(s); - goto do_more; - - /* Call poll handlers. */ - slowpoll: - //printf("S %d\n", npolls); - npolls = 0; - #endif - /* Call poll handlers. */ - for(p = process_list; p != NULL; p = p->next) { - - if(p->state == PROCESS_STATE_NEEDS_POLL) { - p->state = PROCESS_STATE_RUNNING; - call_process(p, PROCESS_EVENT_POLL, NULL); - } ! #if 0 ! /* If a poll has been requested for one of the processes, we start ! from the beginning again. */ ! if(poll_requested) { ! poll_requested = 0; ! p = process_list; } ! #endif ! } } /*---------------------------------------------------------------------------*/ --- 236,251 ---- { struct process *p; ! do { ! poll_requested = 0; ! /* Call the processes that needs to be polled. */ ! for(p = process_list; p != NULL; p = p->next) { ! if(p->needspoll) { ! p->state = PROCESS_STATE_RUNNING; ! p->needspoll = 0; ! call_process(p, PROCESS_EVENT_POLL, NULL); ! } } ! } while(poll_requested); } /*---------------------------------------------------------------------------*/ *************** *** 348,357 **** process_run(void) { ! /* Process "poll" events. */ if(poll_requested) { do_poll(); } ! ! /* Process one event */ do_event(); --- 316,325 ---- process_run(void) { ! /* Process poll events. */ if(poll_requested) { do_poll(); } ! ! /* Process one event from the queue */ do_event(); *************** *** 362,370 **** process_nevents(void) { - #ifdef NPOLLS - return nevents + npolls; - #else return nevents + poll_requested; - #endif } /*---------------------------------------------------------------------------*/ --- 330,334 ---- *************** *** 391,394 **** --- 355,364 ---- ++nevents; + #if PROCESS_CONF_STATS + if(nevents > process_maxevents) { + process_maxevents = nevents; + } + #endif /* PROCESS_CONF_STATS */ + return PROCESS_ERR_OK; } *************** *** 407,424 **** { if(p != NULL) { ! if(p->state == PROCESS_STATE_RUNNING) { ! p->state = PROCESS_STATE_NEEDS_POLL; poll_requested = 1; - #ifdef NPOLLS - int s = splhigh(); - if(npolls < NPOLLS) { - needpoll[npolls] = p; - } - if(npolls != ~0u) npolls++; /* Beware of overflow! */ - splx(s); - #endif } } } /*---------------------------------------------------------------------------*/ /** @} */ --- 377,393 ---- { if(p != NULL) { ! if(p->state == PROCESS_STATE_RUNNING || ! p->state == PROCESS_STATE_CALLED) { ! p->needspoll = 1; poll_requested = 1; } } } /*---------------------------------------------------------------------------*/ + int + process_is_running(struct process *p) + { + return p->state != PROCESS_STATE_NONE; + } + /*---------------------------------------------------------------------------*/ /** @} */ |