next up previous contents
Next: Synchronization support for multiprocessor Up: Porting Applications to RSIM Previous: Process creation and shared

RSIM applications library

 

As discussed in section 3.2.4, RSIM's trap convention differs from that of Solaris, so libraries that include Solaris system traps cannot be directly used with an application. Thus, RSIM is distributed with the RSIM Applications Library, which provides some of the library functions needed for linking the applications to be simulated. The RSIM Applications Library includes code derived from the GNU C Library and is distributed under the terms of the GNU Library General Public License, described at http://www.gnu.org/copyleft/lgpl.html.

The RSIM applications library includes the UNIX I/O functions (close, dup, dup2, lseek, open, read, and write), the stdio library (e.g. printf, fscanf, fopen), the sbrk memory allocation system trap, system traps associated with timing (time and times), the exit function, the atexit function, and the getopt function. The semantics of these functions are almost always identical to those on an ordinary UNIX system; however, in the case of an error, these functions will not set the errno variable (set by many of the standard UNIX functions).

Additionally, the RSIM applications library provides important multiprocessor primitives for process management, memory allocation, memory mapping, and synchronization. (The synchronization primitives are described in Section 5.3.) Other functions, such as the math library, the string library, the standard memory-allocation functions (malloc, free, calloc, etc.), and random-number generators can be linked from the ordinary system libraries.

Besides the above system traps used for supporting UNIX functions, a few additional system traps are provided with RSIM to enable ease of programming. The call getpid() returns the processor number of the calling process. The trap sys_bzero(void *addr, int sz) performs a fast, non-simulated clearing of a region of memory. This trap can be useful for speeding up initialization in some applications.

As described in Section 5.1, new processes are generated in RSIM using the fork() call, which spawns off a new process on a separate processor. RSIM also provides a new library function called atfork() which provides a set of optional cleanup functions to be called by the parent process before executing a fork(), just as the standard UNIX function atexit() does for the exit() call.

Shared memory can only be allocated through the use of the function void *shmalloc(int size). This function returns a pointer to a region of shared memory with a size of size, just as malloc does for the private heap. Currently, this function returns regions starting at a cache-line boundary.

AssociateAddrNode(void *start, void *end, int proc, char *name) assigns proc as the home node for the memory range from start (inclusive) to end (exclusive). This assignment can be done at the granularity of a cache line. This function is an optional performance-tuning technique for applications; if a cache line being accessed is not associated, it will be associated using a first-touch policy on a cache-line granularity. The name argument is required and can be used internally for debugging, but currently has no externally visible role.

abort(int code) forces all processors to stop immediately; this differs from exit(int code) in that exit only terminates the calling process. Further, exit calls the cleanup functions provided through the atexit library functions, whereas abort does not.

GET_L2CACHELINE_SIZE() returns the cache-line size of the secondary cache, which is the system's coherence granularity. This can be useful for padding out array accesses to avoid false-sharing.

Some system traps support timing functions. time and times report the simulated time of the application execution and have nearly the same semantics as in Unix, although time starts the clock at the beginning of simulation rather than the beginning of 1970. sysclocks() gives a more detailed measurement, actually returning the number of simulated processor clock cycles since the start of the simulation.

Currently, some UNIX system traps are not supported with RSIM at all; consequently, functions based on these traps (such as strftime and signal) are not supported. Additionally, self-modifying code is not supported.


next up previous contents
Next: Synchronization support for multiprocessor Up: Porting Applications to RSIM Previous: Process creation and shared

Vijay Sadananda Pai
Thu Aug 7 14:18:56 CDT 1997