Annotation of OSKit-Mach/include/mach/profil.h, revision 1.1.1.1

1.1       root        1: /* 
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
                      4:  * All Rights Reserved.
                      5:  * 
                      6:  * Permission to use, copy, modify and distribute this software and its
                      7:  * documentation is hereby granted, provided that both the copyright
                      8:  * notice and this permission notice appear in all copies of the
                      9:  * software, derivative works or modified versions, and any portions
                     10:  * thereof, and that both notices appear in supporting documentation.
                     11:  * 
                     12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     15:  * 
                     16:  * Carnegie Mellon requests users of this software to return to
                     17:  * 
                     18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
                     22:  * 
                     23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: 
                     27: /*
                     28:  * Copyright 1991 by Open Software Foundation,
                     29:  * Grenoble, FRANCE
                     30:  *
                     31:  *             All Rights Reserved
                     32:  * 
                     33:  *   Permission to use, copy, modify, and distribute this software and
                     34:  * its documentation for any purpose and without fee is hereby granted,
                     35:  * provided that the above copyright notice appears in all copies and
                     36:  * that both the copyright notice and this permission notice appear in
                     37:  * supporting documentation, and that the name of OSF or Open Software
                     38:  * Foundation not be used in advertising or publicity pertaining to
                     39:  * distribution of the software without specific, written prior
                     40:  * permission.
                     41:  * 
                     42:  *   OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
                     43:  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
                     44:  * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
                     45:  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
                     46:  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
                     47:  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
                     48:  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     49:  */
                     50: 
                     51: 
                     52: #ifndef _MACH_PROFIL_H_
                     53: #define _MACH_PROFIL_H_
                     54: 
                     55: #include <mach/boolean.h>
                     56: #include <ipc/ipc_object.h>
                     57: #include <vm/vm_kern.h> 
                     58: 
                     59: 
                     60: #define        NB_PROF_BUFFER          2       /* number of buffers servicing a 
                     61:                                         * profiled thread */
                     62: #define        SIZE_PROF_BUFFER        100     /* size of a profil buffer (in int) 
                     63:                                         * This values is also defined in
                     64:                                         * the server (ugly), be careful ! */
                     65: 
                     66: 
                     67: struct prof_data {
                     68:        ipc_object_t    prof_port;      /* where to send a full buffer */
                     69: 
                     70:        struct buffer {
                     71:            int *p_zone;                /* points to the actual storage area */
                     72:            int                 p_index;/* next slot to be filled */
                     73:            boolean_t           p_full; /* is the current buffer full ? */ 
                     74:        } prof_area[NB_PROF_BUFFER];
                     75: 
                     76:        int             prof_index;     /* index of the buffer structure
                     77:                                         *   currently in use */
                     78: 
                     79: };
                     80: typedef struct prof_data       *prof_data_t;
                     81: #define NULLPBUF ((prof_data_t) 0)
                     82: typedef struct buffer          *buffer_t;
                     83: 
                     84: /* Macros */
                     85: 
                     86: #define        set_pbuf_nb(pbuf, nb) \
                     87:          (((nb) >= 0 && (nb) < NB_PROF_BUFFER) \
                     88:         ? (pbuf)->prof_index = (nb), 1 \
                     89:         : 0)
                     90: 
                     91: 
                     92: #define        get_pbuf_nb(pbuf) \
                     93:        (pbuf)->prof_index
                     94: 
                     95: 
                     96: extern vm_map_t kernel_map; 
                     97: 
                     98: #define dealloc_pbuf_area(pbuf) \
                     99:           { \
                    100:          register int i; \
                    101:                                   \
                    102:            for(i=0; i < NB_PROF_BUFFER ; i++)  \
                    103:              kmem_free(kernel_map, \
                    104:                         (vm_offset_t) (pbuf)->prof_area[i].p_zone, \
                    105:                         SIZE_PROF_BUFFER*sizeof(int)); \
                    106:             kmem_free(kernel_map, \
                    107:                           (vm_offset_t)(pbuf), \
                    108:                           sizeof(struct prof_data)); \
                    109:           }
                    110:        
                    111: 
                    112: #define alloc_pbuf_area(pbuf, vmpbuf) \
                    113:       (vmpbuf) = (vm_offset_t) 0; \
                    114:       if (kmem_alloc(kernel_map, &(vmpbuf) , sizeof(struct prof_data)) == \
                    115:                                            KERN_SUCCESS) { \
                    116:           register int i; \
                    117:           register boolean_t end; \
                    118:                                   \
                    119:           (pbuf) = (prof_data_t) (vmpbuf); \
                    120:           for(i=0, end=FALSE; i < NB_PROF_BUFFER && end == FALSE; i++) { \
                    121:               (vmpbuf) = (vm_offset_t) 0; \
                    122:              if (kmem_alloc(kernel_map,&(vmpbuf),SIZE_PROF_BUFFER*sizeof(int)) == KERN_SUCCESS) { \
                    123:                 (pbuf)->prof_area[i].p_zone = (int *) (vmpbuf); \
                    124:                 (pbuf)->prof_area[i].p_full = FALSE; \
                    125:              } \
                    126:              else { \
                    127:                 (pbuf) = NULLPBUF; \
                    128:                 end = TRUE; \
                    129:              } \
                    130:                    } \
                    131:        } \
                    132:        else \
                    133:          (pbuf) = NULLPBUF; 
                    134:        
                    135: 
                    136: 
                    137: /* MACRO set_pbuf_value 
                    138: ** 
                    139: ** enters the value 'val' in the buffer 'pbuf' and returns the following
                    140: ** indications:     0: means that a fatal error occured: the buffer was full
                    141: **                       (it hasn't been sent yet)
                    142: **                  1: means that a value has been inserted successfully
                    143: **                 2: means that we'v just entered the last value causing 
                    144: **                     the current buffer to be full.(must switch to 
                    145: **                     another buffer and signal the sender to send it)
                    146: */ 
                    147:          
                    148: #define set_pbuf_value(pbuf, val) \
                    149:         { \
                    150:          register buffer_t a = &((pbuf)->prof_area[(pbuf)->prof_index]); \
                    151:          register int i = a->p_index++; \
                    152:          register boolean_t f = a->p_full; \
                    153:                          \
                    154:          if (f == TRUE ) \
                    155:              *(val) = 0; \
                    156:          else { \
                    157:            a->p_zone[i] = *(val); \
                    158:            if (i == SIZE_PROF_BUFFER-1) { \
                    159:                a->p_full = TRUE; \
                    160:                *(val) = 2; \
                    161:             } \
                    162:             else \
                    163:                *(val) = 1; \
                    164:           } \
                    165:        }
                    166: 
                    167:          
                    168: #define        reset_pbuf_area(pbuf) \
                    169:        { \
                    170:         register int *i = &((pbuf)->prof_index); \
                    171:                                              \
                    172:         *i = (*i == NB_PROF_BUFFER-1) ? 0 : ++(*i); \
                    173:         (pbuf)->prof_area[*i].p_index = 0; \
                    174:        }
                    175: 
                    176: 
                    177: /**************************************************************/
                    178: /* Structure, elements used for queuing operations on buffers */
                    179: /**************************************************************/
                    180: 
                    181: #define        thread_t int *
                    182: /*
                    183: ** This must be done in order to avoid a circular inclusion 
                    184: ** with file kern/thread.h . 
                    185: ** When using this data structure, one must cast the actual 
                    186: ** type, this is (int *) or (thread_t)
                    187: */
                    188: 
                    189: struct buf_to_send {
                    190:        queue_chain_t list;
                    191:        thread_t thread;
                    192:         int number;         /* the number of the buffer to be sent */
                    193:        char wakeme;        /* do wakeup when buffer has been sent */
                    194:         }      ;
                    195: 
                    196: #undef thread_t
                    197: 
                    198: 
                    199: 
                    200: typedef struct buf_to_send *buf_to_send_t;
                    201: 
                    202: #define        NULLBTS         ((buf_to_send_t) 0)
                    203: 
                    204: /*
                    205: ** Global variable: the head of the queue of buffers to send 
                    206: ** It is a queue with locks (uses macros from queue.h) and it
                    207: ** is shared by hardclock() and the sender_thread() 
                    208: */
                    209: 
                    210: mpqueue_head_t prof_queue; 
                    211: 
                    212: #endif /* _MACH_PROF_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.