[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

B. Function Summary

The following miscellaneous library functions are provided. Several are simply cover functions for standard Unix library functions, but are provided to simplify the creation of portable GM programs, or to provide the ANSI functionality on non-ANSI systems, such as Windows NT.

- void gm_abort ()
Cover function for abort(). Aborts the current process.

- void * gm_alloc_pages (unsigned long len)
Allocate len bytes, aligned on a page boundary. Any fractional page following the buffer is wasted.

- int gm_alloc_send_token (struct gm_port *port, unsigned int priority)
This trivial utility function allocates a send token of priority priority previously freed with gm_free_send_token() or returns 0 if no token is available. Clients may choose to maintain their own send token counts without using this utility function.

- void gm_allow_remote_memory_access (struct gm_port *port)
Allow any remote GM port to modify the contents of any GM DMAable memory using the gm_directed_send() function. This is a significant security hole, but is very useful on tightly coupled clusters on trusted networks.

- void gm_bcopy (void *from, void *to, unsigned long len)
Copy len bytes starting at from to location to. Does not handle overlapping regions.

- union gm_receive_event * gm_blocking_receive (struct gm_port *port)
Block until there is a receive event and then return a pointer to the event. If no send is immediately available, this call suspends the current process until a receive event is available. As an optimization for applications with one CPU per CPU-intensive thread, this function polls for receives for one millisecond before sleeping the process, so it is not suited for machines running more than one performance critical process or thread on the machine.

- union gm_receive_event * gm_blocking_receive_no_spin (struct gm_port *port)
This function behaves just like gm_blocking_receive(), only it sleeps the current thread immediately if no receive is pending. It is well suited to applications with more than one CPU-intensive thread per processor.

- void gm_bzero (void *ptr, int len)
Clear the len bytes of memory starting at ptr.

- void * gm_calloc (unsigned long len, unsigned long cnt)
Allocate and clear an array of cnt elements of length len.

- void gm_close (struct gm_port *port)
Close a previously opened port, and free all resources associated with the port.

- void gm_datagram_send (struct gm_port *port, void *message, unsigned int size, unsigned int len, unsigned int priority, unsigned int target_node_id, unsigned int target_port_id, gm_send_completion_callback_t callback, void *context)
Queue message of length length to be sent unreliably to a buffer of size size at target_port_id on target_node_id. length must be no larger than gm_mtu(port) If any network error is encountered while sending the packet, the packet is silently and immediately dropped. After the packet has been DMA'd from host memory, callback(port,context,status) is called inside a user invokation of gm_unknown(), reporting the status of the attempted send.

- gm_status_t gm_deregister_memory (struct gm_port *port, void *ptr, unsigned len)
Deregister len bytes of user virtual memory starting at ptr that were previously registered for DMA transfers with a matching call to gm_register_memory().

- void gm_directed_send (struct gm_port *p, void *source_buffer, gm_remote_ptr_t target_buffer, unsigned long len, enum gm_priority priority, unsigned int target_node_id, unsigned int target_port_id)
This function is deprecated. Use gm_directed_send_with_callback() instead.

Transfer the len bytes at source_buffer to target_port_id on target_node_id with priority priority and store the data at the remote virtual memory address target_buffer. The order of the transfer is preserved relative to messages of the same priority sent using gm_send() or gm_send_to_peer().

- void gm_directed_send_with_callback (struct gm_port *p, void *source_buffer, gm_remote_ptr_t target_buffer, unsigned long len, enum gm_priority priority, unsigned int target_node_id, unsigned int target_port_id, gm_send_completion_callback_t callback, void *context)
Transfer the len bytes at source_buffer to target_port_id on target_node_id with priority priority and store the data at the remote virtual memory address target_buffer. Call callback(port,context,status) when the send completes or fails, with status indicating the status of the send. The order of the transfer is preserved relative to messages of the same priority sent using gm_send() or gm_send_to_peer().

- void * gm_dma_calloc (struct gm_port *port, unsigned count, unsigned length)
Allocates and clears count*length bytes of DMAable memory aligned on a 4-byte boundary.

- void gm_dma_free (struct gm_port *port, void *ptr)
Frees ptr, which was allocated by a call to gm_dma_calloc() or gm_dma_malloc(). Note that the memory is not necessarily unlocked and returned to the operating system, but may be reused in future calls to gm_dma_calloc() and gm_dma_malloc().

- void * gm_dma_malloc (struct gm_port *port, unsigned count)
Allocates length bytes of DMAable memory aligned on a 4-byte boundary.

- void gm_drop_sends (struct gm_port *port, unsigned int priority, unsigned int target_node_id, unsigned int target_port_id, gm_send_completion_callback_t callback, void *context);
Drop all enqueued sends for port of priority priority destined for target_port_id of target_node_id to be dropped, and reenable packet transmission on that connection. This function should only be called after an error is reported to a send completion callback routine, and only with parameters matching those of the failed send. It should be called only once per reported error. The dropped sends will be returned to the client with a status of GM_SEND_DROPPED. This function requires a send token, which is implicitly returned to the caller when the callback is called.

- void gm_exit (gm_status_t status)
Cause the current process to exit with a status appropriate to the GM status code status.

- void gm_finalize ()
Decrement the GM initialization counter, and if it becomes zero, free all resources associated with GM in the current process. Each call to gm_finalize() should be matched by a call to gm_init().

- void gm_free (void *ptr)
Free the memory buffer at ptr, which was previously allocated by gm_malloc(), or gm_calloc().

- void gm_free_pages (void *ptr)
Free the pages at ptr, which were previously allocated with gm_alloc_pages().

- void gm_free_send_token (struct gm_port *port, unsigned int priority)
This trivial utility function increments a count of free send tokens of priority for port so that it can later be allocated using gm_alloc_send_token(). Clients may choose to maintain their own count of send tokens in the client's possession instead of using this utility function.

- void gm_free_send_tokens (struct gm_port *port, unsigned int priority, unsigned int count)
Like gm_free_send_token(), but can be used to free zero or more tokens.

- gm_status_t gm_get_host_name (struct gm_port *port, char name[GM_MAX_HOST_NAME_LEN])
Copy the host name of the local node to name.

- gm_status_t gm_get_node_id (struct gm_port *port, unsigned int *n)
Copy the GM ID of the network interface card associated with port to *n.

- gm_status_t gm_get_unique_board_id (struct gm_port *port, char unique[6])
Copy the 6-byte MAC address of the network interface card associated with port to the buffer at unique.

- void gm_handle_directed_send_notification (struct gm_port *{port}, gm_recv_event_t *event)
Deprecated. When a GM_DIRECTED_SEND_NOTIFICATION event is received, programs may optionally call this function instead of gm_unknown() as an optimization for handling send completions more efficiently. This function does not improve performance on newer hardware, which does not generate GM_DIRECTED_SEND_NOTIFICATION events.

- void gm_handle_sent_tokens (struct gm_port *port, gm_recv_event_t *event);
Deprecated. When a GM_DIRECTED_SEND_NOTIFICATION event is received, programs may optionally call this function instead of gm_unknown() as an optimization for handling send completions more efficiently. This function does not improve performance on newer hardware, which does not generate GM_DIRECTED_SEND_NOTIFICATION events.

- unsigned int gm_host_name_to_node_id (struct gm_port *port, char *host_name)
Return the GM ID associated with host_name or GM_NO_SUCH_NODE_ID in case of an error.

- gm_status_t gm_init ()
Increment the GM initialization counter and ianitialize GM if it was uninitialized. This call must be performed before any other GM call and before any reference to a GM global variable (e.g.: GM_PAGE_LEN). Each call to gm_init() should be matched by a call to gm_finalize(). (5)

- unsigned long gm_log2_roundup (unsigned long n)
Returns the logarithm, base 2, of n, rounded up to the next integer.

- void * gm_malloc (unsigned long len)
Allocates and returns a pointer to len bytes of uninitialized memory. The memory should be freed with gm_free().

- unsigned long gm_max_length_for_size (unsigned int size)
Return the maximum length of a message that will fit in a GM buffer of size size.

- gm_status_t gm_max_node_id (struct gm_port *port, unsigned int *n)
Store the maximum GM node ID supported by the the network interface card corresponding to port at *n.

- gm_status_t gm_max_node_id_in_use (struct gm_port *port, unsigned int *n)
Store the maximum in-use node ID for the network attached to port at *n.

- int gm_memcmp (void *a, void *b, unsigned long len)
Emulate the ANSI memcmp() function.

- void * gm_memorize_message (void *message, void *buffer, unsigned int len)
Function for optionally optimizing the handling "FAST" receive messages as described in See section 9. Receiving Messages. If message and buffer differ, gm_memorize_message(port, message,buffer) copies the message pointed to by message into the buffer pointed to by buffer. gm_memorize_message() returns buffer. This function is optimized for performing such aligned copies.

- unsigned int gm_min_message_size (struct gm_port *port)
Returns the minimum message size supported by this GM implementation.

- unsigned int gm_min_size_for_length (unsigned long length)
Returns the minimum GM message buffer size required to store a message of length length.

- char * gm_node_id_to_host_name (struct gm_port *port, unsigned int node_id)
Return a pointer to the host name of the host containing the network interface card with GM node id node_id. The data referenced by the returned pointer is only valid until the next GM API call.

- gm_status_t gm_node_id_to_unique_id (struct gm_port *port, unsigned int n, char unique[6])
Store the MAC address for the interface with GM ID n at unique.

- unsigned int gm_num_ports (struct gm_port *p)
Return the number of ports supported by the the network interface card associated with port p.

- unsigned int gm_num_receive_tokens (struct gm_port *p)
Return the number of receive tokens implicitly owned by the port's client after the port is opened.

- unsigned int gm_num_send_tokens (struct gm_port *p)
Return the number of send tokens implicitly owned by the port's client after the port is opened.

- gm_status_t gm_on_exit (gm_on_exit_callback_t callback, void *{arg})
Much like Linux on_exit(), this functions registers a callback so that callback(status,arg) is called when the program exits. Callbacks are called in the reverse of the order of registration. This function is also somewhat similar to BSD atexit().

- gm_status_t gm_open (struct gm_port **p, int device, int port, char *port_name)
Opens GM port port for LANai interface device, a pointer to the port's state at *p. This pointer must be passed to all subsequent functions that operate on the opened port. port_name is a null-terminated ASCII string that is used to identify the port client for debugging (and potentially other) purposes; pass in the name of your program.

Note that unit and port numbers start at 0, and that ports 0 and 1 reserved, so clients will usually open ports 2 and higher.

- void * gm_page_alloc ()
Returns a pointer to a newly allocated aligned uninitialized page of memory.

void: gm_page_free (void *addr)
Frees the page of memory at addr, an address returned by gm_page_alloc().

- void gm_perror (char *message, gm_status_t errno)
Similar to ANSI standard perror, but takes the error code as a parameter to allow thread safety in future implementations, and only supports GM error numbers. Prints message followed by a description of errno.

- int gm_printf (char *format, ...)
Emulate or invoke the ANSI standard printf() function.

- void gm_provide_receive_buffer (struct gm_port *port, void *message, unsigned size, unsigned priority)
Equivalent to calling gm_provide_receive_buffer_with_tag(...,0), and no faster than doing so. It is included for backwards compatibility. Many new clients will want to use gm_provide_receive_buffer_with_tag() instead.

- void gm_provide_receive_buffer_with_tag (struct gm_port *port, void *message, unsigned size, unsigned priority, unsigned int tag)
This function provides GM with a buffer into which it can receive messages with matching size and priority fields. It is the client software's responsibility to provide buffers of each size and priority that might be received; not doing so can cause program deadlock, which will eventually result in the port being closed after a timeout(6).

The client software may provide up to gm_num_receive_tokens() different receive buffers into which messages may be received.

Each buffer provided by the client software to GM via this function will be used only once to receive a message. In other words, calling gm_provide_receive_buffer(port, buffer, size, priority) provides GM a token to receive a single message of size size and priority priority into the receive buffer buffer. When a message is eventually received into this buffer, gm_receive(port) stores the buffer pointer buffer and tag in the returned event, returning control of the buffer (token) to the client software. If the client software wishes for the buffer to be reused for a similar receive, it must call gm_provide_receive_buffer() again with the same or similar parameters.

Once a buffer has been provided to GM, its content should not be changed until control of the buffer has been returned to the client software via gm_receive().

The tag parameter must be in the range [0,255], and is returned in the receive event describing a receive into the buffer. It may be used in any way the client desires, and need not be unique.

- int gm_rand ()
Returns a pseudo-random integer, using a poor but fast random number generator.

- int gm_rand_mod (int modulus).
Returns a pseudo-random number modulo modulus, using a poor but fast random number generator.

- union gm_recv_event * gm_receive (struct gm_port *p)
Returns a receive event. If no significant receive event is pending, then an event of type GM_NO_RECV_EVENT is immediately returned.

- int gm_receive_pending (struct gm_port *port)
Returns nonzero if a receive event is pending. If a receive event is pending A call to any gm_receive*)() function will return the event immediately, although gm_receive() is preferred in this case for efficiency.

- int gm_next_event_peek (struct gm_port *p, gm_u16_t *sender);
Returns the nonzero event type if an event is pending. If the event is a message receive event, then the sender parameter will be filled with the gmID of the message sender. If an event is pending a call to any gm_receive*)() function will return the event immediately, although gm_receive() is preferred in this case for efficiency.

- void * gm_register_memory (struct gm_port *port, void *ptr, unsigned len)
Register len bytes of user virtual memory starting at ptr for DMA transfers. The memory is locked down (made nonpageable) and DMAs on the region of memory are enabled. Memory may be registered multiple times. Memory may be deregistered using matching calls to gm_deregister_memory(). Note that memory registration is an expensive operation relative to sending and receiving packets, so you should use persistent memory registrations wherever possible. Also note that memory registration is not supported on Solaris due to operating system limitations.

- void gm_resume_sending (struct gm_port *port, unsigned int priority, unsigned int target_node_id, unsigned int target_port_id, gm_send_completion_callback_t callback, void *context);
Reenable packet transmission of messages from port of priority priority destined for target_port_id of target_node_id. This function should only be called after an error is reported to a send completion callback routine, and only with parameters matching those of the failed send. It should be called only once per reported error. This function requires a send token, which is implicitly returned to the caller when the callback is called.

- void gm_send (struct gm_port *port, void *message, unsigned int size, unsigned int len, unsigned int priority, unsigned int target_node_id, unsigned int target_port_id)
This function is deprecated and included only for backwards compatibility with GM-1.0.

Queues the message of length len to be sent with priority priority to node target_node_id. Before calling gm_send(), client software must first possess a send token of the same priority, and by calling gm_send () the client implicitly relinquishes this send token. After a call to gm_send(..., message, len, ...), the memory specified by message and len must not be modified until the send completes. The buffer pointed to by message is not modified by GM between the time gm_send(port, message,...) is called and the time that the sent message pointer appears in a GM_SENT_EVENT.

- void gm_send_with_callback (struct gm_port *port, void *message, unsigned int size, unsigned int len, unsigned int priority, unsigned int target_node_id, unsigned int target_port_id, gm_send_completion_callback_t callback, void *context)
Queues the message of length len to be sent with priority priority to node target_node_id. Before calling gm_send(), client software must first possess a send token of the same priority, and by calling gm_send () the client implicitly relinquishes this send token. After a call to gm_send(..., message, len, ...), the memory specified by message and len must not be modified until the send completes. After the send completes, callback(port,context,status) will be called inside gm_unknown(), with status indicating the status of the completed send. The buffer pointed to by message should not be modified by GM between the time gm_send(port, message,...) is called and the time that the sent completes.

- void gm_send_to_peer (struct gm_port *port, void *message, unsigned int len, unsigned int priority, unsigned int target_node_id)
This function is deprecated and is included only for backwards compatibility with GM-1.0.

Like gm_send(), only with the target_node_id implicitly set to the same ID as port. This function is marginally faster than gm_send().

- void gm_send_to_peer_with_callback (struct gm_port *port, void *message, unsigned int len, unsigned int priority, unsigned int target_node_id, gm_send_completion_callback_t callback, void *context)
Like gm_send_with_callback(), only with the target_node_id implicitly set to the same ID as port. This function is marginally faster than gm_send_with_callback().

- int gm_send_token_available (struct gm_port *port, unsigned priority)
Returns the value gm_alloc_send_token(port, priority) would return, without actually allocating a send token. This function allows client software to test for the availability of a send token without actually allocating the send token.

- gm_status_t gm_set_acceptable_sizes (struct gm_port *p, enum gm_priority priority, unsigned long mask)
Inform GM of the acceptable sizes of GM messages received on port p with priority priority. Each set bit of mask represents indicates an acceptable size. While calling this function is not required, clients should call it during program initialization to errors involving the reception of badly sized messages to be reported nearly instantaneously, rather than after a substantial delay of 30 seconds or more.

- int gm_sleep (unsigned seconds)
Emulate ANSI standard sleep(), sleeping the entire process for seconds seconds.

- char * gm_strerror (gm_status_t errno)
Return a pointer to a constant string describing GM error code errno. This is somewhat similar to Unix strerror(), except errno must be a GM error code; it must not be a system error code.

- gm_status_t gm_node_id_to_unique_id (struct gm_port *port, unsigned int n, char unique[6])
Store the MAC address for the interface with GM ID n at unique.

- void gm_unknown (struct gm_port *p, union gm_recv_event *e)
This functions handles all GM events not recognized or processed by the client software, allowing the GM library and network interface card firmware to interact. This functions also catches and reports several common client program errors, and converts some unrecognizable events into recognizable form for the client.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Glenn Brown on October, 18 2001 using texi2html