| OpenSS7 SS7 for the Common Man | © Copyright 1997-2007 OpenSS7 Corporation All Rights Reserved. Last modified: Mon, 28 Apr 2008 12:53:49 GMT | ||||||||||||||||
| |||||||||||||||||
| Manpage of ESBALLOCDescription: Manual PageKeywords: ss7 ss7/ip ss7 over ip ss7 mtp ss7 sccp ss7 tcap sigtran mtp sccp tcap openss7 acb56 linux telephony pstn linux telephony linux nebs linux compactpciESBALLOCSection: The OpenSS7 Project DDI/DKI (9)Updated: Sun, 26 May 2013 09:14:07 GMT Index Return to Main Contents NAMEesballoc - allocate a STREAMS message and data block with a caller supplied data bufferSYNOPSIS#include <sys/stream.h>
ARGUMENTS
INTERFACEDESCRIPTIONesballoc() is used where the STREAMS driver needs control over the location, allocation and deallocation of data buffers. This may be because the data buffers are subject to some physical contraints (e.g. must be allocated in DMA-able memory, or must exist in dual-ported RAM or in a descriptor ring). This may also be because some other mechanism outside of STREAMS has already allocated and passed the data buffer to a STREAMS driver. Where it is not necessary that the caller provide the data buffer, allocb(9) is more appropriate. esballoc() allocates a message block and a data block using the caller supplied data buffer at base of the specified size and priority. The priority can be one of the following values:
If esballoc() is called with a priority other than BPRI_LO, BPRI_MED, BPRI_HI or BPRI_WAITOK, the request will be treated as BPRI_LO. The priority argument is ignored by SVR 4[1] and later implementations. The data buffer of length size and with the necessary physical memory type has already been allocated by the caller and is pointed to by the argument base. In addition, esballoc() accepts a pointer to a free_rtn structure that contains the following elements:
The allocated message block will have a data block type of M_DATA(9). USAGEPriority BPRI_WAITOK is added for OSF/1®[2] compatibility and should not be used by portable STREAMS drivers or modules. Portable STREAMS drivers and modules should not rely on any setting of priority and should assume that the implementation ignores the priority argument. RETURNUpon success, esballoc() returns a pointer to the allocated message block. Upon failure, esballoc() returns a NULL message pointer. ERRORSWhen esballoc() fails to allocate a message or data block, it returns NULL. Failure to allocate a message block will typically be followed by a call to esbbcall(9). esballoc() will always fail to allocate a message block when the number of outstanding combined message data blocks allocated by the system exceeds the system control sysctl_str_nstrmsgs. esballoc() will also fail if size is greater than system control sysctl_str_strmsgsz, the maximum STREAMS message size. CONTEXTesballoc() can be called from any context, including user context, module procedures, callouts, callbacks, soft interrupts (tasklets and bottom halves), and interrupt service routines. The priority BPRI_WAITOK must only be used from a blocking context. MP-STREAMSesballoc() is MP-safe. The caller has exclusive access to the returned message. NOTICESMany post-SVR 4.2[3] compliant STREAMS implementations ignore the priority argument to esballoc(). The message block priority was an SVR 3[4] concept which was found not to be useful, primarily due to priority inversion. For a history of the priority mechanism and a discussion as to why the mechanism was abandoned in SVR 4.2[3], see ``The Magic Garden'' section 7.2.2[5]. Linux Fast-STREAMS keeps two stores for combined message data blocks (mdbblocks): a per-CPU free block list that is maintained during the runqueues(9) pass to hold freed message blocks (but freed to the memory cache at the end of the pass), and an mdbblock memory cache. In consideration of priority, esballoc() uses the following allocation differences based on the value of priority:
In this way, the priority argument determines the delay in satisfying the request rather than the ultimate probability of success, permitting low latency tasks to specify BPRI_HI and high-latency tasks to specify BPRI_LO. esballoc() presents challenges when used from within Linux kernel modules. Particularly when the free_func function pointer references a function which is resident only within the kernel module. Care must be taken that the kernel module containing the free_func does not get unloaded from the system before all message blocks referencing free_func are freed. Under Linux 2.4 kernels, and kernels that do not provide the module_text_address() symbol, module reference counting is the caller's responsibility and Linux Fast-STREAMS provides no automatic facility for this purpose. If a kernel module contains the free_func that is passed to esballoc(), the caller should increment the kernel module use count with MOD_INC_USE_COUNT prior to the allocation, and decrement the module use count with MOD_DEC_USE_COUNT within the function referenced by free_func. See ``EXAMPLES'' below. Under Linux 2.6 kernels, and kernels that provide the module_text_address() symbol, Linux Fast-STREAMS will perform the module reference counting automatically. EXAMPLESThe following examples shows how a data buffer suitable for use by Direct Memory Access is allocated:
1 #ifndef MOD_INC_USE_COUNT
2 #define MOD_INC_USE_COUNT do { } while (0)
3 #define MOD_DEC_USE_COUNT do { } while (0)
4 #endif
5
6 void
7 xxx_free_func(char *buf)
8 {
9 kfree(buf);
10 MOD_DEC_USE_COUNT;
11 }
12
13 mblk_t *
14 xxx_alloc_dma_buf(size_t bufsize)
15 {
16 unsigned char *buf;
17
18 MOD_INC_USE_COUNT;
19 if ((buf = kmalloc(bufsize,
20 GFP_ATOMIC | GFP_DMA))) {
21 mblk_t *mp;
22 frtn_t freertn = {
23 free_func:&xxx_free_func,
24 free_arg:(char *) buf,
25 };
26
27 if (!(mp = esballoc(buf, bufsize,
28 BPRI_MED, &freertn)))
29 xxx_free_func(buf);
30 return (mp);
31 }
32 MOD_DEC_USE_COUNT;
33 return (NULL);
34 }
The example, above, also shows the technique for keeping the current kernel module from unloading before the free function is called for all outstanding message blocks that reference the free function. See ``NOTICES'', above. MOD_INC_USE_COUNT and MOD_DEC_USE_COUNT in the example code is only necessary for Linux 2.4 kernels and can be defined as shown for Linux 2.6 kernels (where reference counting is performed automatically). SEE ALSOfreeb(9), freemsg(9), bufcall(9), and esbbcall(9). BUGSCOMPATIBILITYesballoc() is compatible with SVR 4.2 MP DDI/DKI[6], and implementations based on SVR 4, with the following portability considerations:
See STREAMS(9) for additional compatibility information. CONFORMANCEHISTORYesballoc() appears as part of SVR 4.0 STREAMS [1]. esballoc() first appeared in SVR 3[10]. REFERENCES
TRADEMARKS
Other trademarks are the property of their respective owners. IDENTIFICATION
Copyright©1997-2008OpenSS7 Corp.
Index
This document was created by man2html, using the manual pages. Time: 09:14:07 GMT, May 26, 2013 | ||||||||||||||||
| OpenSS7 SS7 for the Common Man |
| ||||||||||||||||
| Last modified: Mon, 28 Apr 2008 12:53:49 GMT © Copyright 1997-2007 OpenSS7 Corporation All Rights Reserved. |