From: stan@rti.com (Stan Schneider)
Newsgroups: comp.os.vxworks
Subject: re:  spawning overhead
Date: 21 Aug 92 04:28:08 GMT
Organization: Lawrence Berkeley Laboratory, Berkeley CA
NNTP-Posting-Host: 128.3.112.16
Originator: daemon@vxw.ee.lbl.gov

>> Submitted-by fjr@ssd.ray.com  Thu Aug 20 05:37:24 1992
>> Submitted-by: Roeber <fjr@ssd.ray.com>
>>  
>> >  Submitted-by fortin%helios.nosc.mil@nosc.mil  Tue Aug 18 16:08:43 1992
>> >  Submitted-by: fortin%helios.nosc.mil@nosc.mil (Richard Fortin)
>> >   
>> >  
>> >  Has anyone out there done any overhead studies concerning the hit taken
>> > for creating a new process?  We'd be really interested if it had been
>> > done with Ada tasks but plain vanilla C spawning would be useful too.
>> 
>> We have run the standard Ada PIWG benchmark tests on a version of VADSWorks
>> (2.0.3 beta) on a 25MHz 68030 processor.  The "c0000x" series of tests
>> measures task creation and termination times (combined).  What we found is
>> it takes about 3ms to create/terminate a task.  A non trivial part of this
>> is the time to zero out the run time stack since changing the task stack size
>> from 1000 to 100 bytes drops the execution time down to 2.5ms. 

Well, this looked interesting, so I wrote a little test program (attached
below).

The results (25 MHz 68040):			time 	
  task spawn/delete with 2048 byte stack	0.59 ms	
  with VX_FP_TASK and VX_STD_IO set		0.82 ms
  with 20480 byte stack				1.36 ms	


In general, it seems like pretty tight code.  In case you're curious, here's
where the profiler says the CPU was being used (only routines that accounted
for at least 1% shown):

-> ProfileShowTree 0,0,1.0
Profiling all tasks and routines.
   Cumulative        Current
sum %  direct %   sum %  direct %
86.92    .55      88.13    .53      _vxTaskEntry
59.14    .35      59.91    .36      .   _SpawnTestMasterTask
51.36    .46      51.63    .38      .   .   _taskSpawn
47.23    .78      47.27    .61      .   .   .   _taskCreat
39.47   3.73      40.03   3.96      .   .   .   .   _taskInit
14.84  14.84      14.18  14.18      .   .   .   .   .   _bfill
11.40    .63      11.47    .43      .   .   .   .   .   _sigInit
 4.85    .12       5.08    .10      .   .   .   .   .   .   _bzero
 4.71   4.71       4.98   4.98      .   .   .   .   .   .   .   _bfill
 3.03    .27       3.05    .13      .   .   .   .   .   .   _semBInit
 1.84    .33       1.73    .27      .   .   .   .   .   .   .   _semQInit
 1.42   1.06       1.38   1.03      .   .   .   .   .   .   .   .   _qInit
 2.01    .36       2.06    .49      .   .   .   .   .   .   _semMInit
 1.32    .19       1.23    .19      .   .   .   .   .   .   .   _semQInit
 1.07    .80        .99    .74      .   .   .   .   .   .   .   .   _qInit
 2.40    .45       3.08    .58      .   .   .   .   .   _inherit_fds
 1.62   1.16       2.02   1.52      .   .   .   .   .   .   _ioTaskStdGet
 1.26    .88       1.35    .97      .   .   .   .   .   _qInit
 5.62    .57       5.28    .60      .   .   .   .   _objAllocExtra
 3.45   2.34       3.18   2.06      .   .   .   .   .   _memPartAlloc
 3.41   0.06       3.62   0.03      .   .   .   _taskActivate
 2.47   1.00       2.79   1.06      .   .   .   .   _taskResume
 1.35    .39       1.65    .49      .   .   .   .   .   _windResume
 7.25    .11       7.75    .12      .   .   _sprintf
 6.88   2.53       7.44   2.82      .   .   .   _fioFormatV
 2.97   2.53       3.18   2.64      .   .   .   .   _itob
 1.23    .25       1.16    .17      .   .   .   .   _fioFormatV
26.56    .66      27.06    .56      .   _excTask
14.48   2.47      14.79   2.35      .   .   _taskDestroy
 8.21    .55       8.77    .51      .   .   .   _objFree
 5.62   1.75       6.09   1.78      .   .   .   .   _memPartFree
 1.96   1.39       2.09   1.38      .   .   .   .   .   _memPartShow
 1.94    .39       1.80    .54      .   .   .   _windDelete
 1.07    .43        .91    .31      .   .   .   .   _qPriBMapRemove
 9.30    .76       9.83    .93      .   .   _msgQReceive
 4.50    .68       4.49    .84      .   .   .   _qJobGet
 3.66    .67       3.54    .67      .   .   .   .   _windPendQPut
 2.03    .64       2.06    .68      .   .   .   .   .   _qPriBMapRemove
 1.01    .66        .97    .58      .   .   .   .   .   .   _qPriBMapEach
 1.16   1.16       1.24   1.24      .   .   .   _intUnlock
 9.49    .00       8.56    .00      _windIntStackSet
 9.47    .22       8.52    .25      .   _exit
 7.86    .45       7.11    .59      .   .   _taskDestroy
 7.36    .45       6.49    .39      .   .   .   _excJobAdd
 6.62   1.00       5.83    .84      .   .   .   .   _msgQSend
 2.31    .16       2.22    .15      .   .   .   .   .   _qJobPut
 1.98    .62       1.90    .63      .   .   .   .   .   .   _windPendQGet
 1.30    .69       1.11    .69      .   .   _taskOptionsSet


Note: inherit_fds is a local task create hook.

---------------------------------------------------------
The code:

#include "stdioLib.h"
#include "taskLib.h"

static
int DummyTask(void)
{
    return(0);
}

static
int SpawnTestMasterTask(int numTasks, int prio, int options, int stacksize)
{
    int i;
    char name[64];

    printf("Spawning %d tasks.\n", numTasks);
    for (i=0; i<numTasks; i++) {
	sprintf(name, "task%d", i);  /* This is slow!  20-20 hind-sight. */
	taskSpawn(name, prio, options, stacksize, DummyTask);
    }
    printf("SpawnTest done.\n");
    return(0);
}

void SpawnTest(int numTasks, int prio, int options, int stacksize)
{
    if (numTasks == 0) {numTasks = 1000;}
    if ((prio == 0) || (prio >= 255)) {prio = 254;}
    if (stacksize == 0) {stacksize = 2048;}

    /* Spawn the master task.  It's priority must be less than the spawned
       tasks, or the new tasks will pile up. */
    taskSpawn("SpawnMaster", prio+1, options, 2048, SpawnTestMasterTask,
	      numTasks, prio, options, stacksize);
}


Sorry for the length of this message...

        -- Stan


===============================================================================
=                                           =                                 =
=   Stan Schneider                          =   email: stan@rti.com           =
=   Real-Time Innovations, Inc.             =   Phone: (408) 720-8312         =
=   954 Aster, Sunnyvale, CA 94086          =   Fax:   (408) 720-8419         =
=                                           =                                 =
===============================================================================