~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to pvm3/src/pvmfrag.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
static char rcsid[] =
 
3
        "$Id: pvmfrag.c,v 1.4 1997/06/25 22:09:37 pvmsrc Exp $";
 
4
 
 
5
/*
 
6
 *         PVM version 3.4:  Parallel Virtual Machine System
 
7
 *               University of Tennessee, Knoxville TN.
 
8
 *           Oak Ridge National Laboratory, Oak Ridge TN.
 
9
 *                   Emory University, Atlanta GA.
 
10
 *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
 
11
 *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
 
12
 *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
 
13
 *                   (C) 1997 All Rights Reserved
 
14
 *
 
15
 *                              NOTICE
 
16
 *
 
17
 * Permission to use, copy, modify, and distribute this software and
 
18
 * its documentation for any purpose and without fee is hereby granted
 
19
 * provided that the above copyright notice appear in all copies and
 
20
 * that both the copyright notice and this permission notice appear in
 
21
 * supporting documentation.
 
22
 *
 
23
 * Neither the Institutions (Emory University, Oak Ridge National
 
24
 * Laboratory, and University of Tennessee) nor the Authors make any
 
25
 * representations about the suitability of this software for any
 
26
 * purpose.  This software is provided ``as is'' without express or
 
27
 * implied warranty.
 
28
 *
 
29
 * PVM version 3 was funded in part by the U.S. Department of Energy,
 
30
 * the National Science Foundation and the State of Tennessee.
 
31
 */
 
32
 
 
33
/*
 
34
 *      pvmfrag.c
 
35
 *
 
36
 *      Frag buffer util.
 
37
 *
 
38
$Log: pvmfrag.c,v $
 
39
 * Revision 1.4  1997/06/25  22:09:37  pvmsrc
 
40
 * Markus adds his frigging name to the author list of
 
41
 *      every file he ever looked at...
 
42
 *
 
43
 * Revision 1.3  1997/04/24  20:58:53  pvmsrc
 
44
 * intialize fr_rip to 0
 
45
 *
 
46
 * Revision 1.2  1997/01/28  19:27:27  pvmsrc
 
47
 * New Copyright Notice & Authors.
 
48
 *
 
49
 * Revision 1.1  1996/09/23  23:44:37  pvmsrc
 
50
 * Initial revision
 
51
 *
 
52
 * Revision 1.3  1995/05/17  16:42:49  manchek
 
53
 * added support for CSPP shared memory.
 
54
 * use CLUMP_ALLOC option to clump frag headers
 
55
 *
 
56
 * Revision 1.2  1994/06/03  20:38:24  manchek
 
57
 * version 3.3.0
 
58
 *
 
59
 * Revision 1.1  1993/08/30  23:26:51  manchek
 
60
 * Initial revision
 
61
 *
 
62
 */
 
63
 
 
64
#include <pvm3.h>
 
65
#include "pvmalloc.h"
 
66
#include "pvmfrag.h"
 
67
#include "listmac.h"
 
68
#include "pvmdabuf.h"
 
69
 
 
70
 
 
71
extern void pvmbailout();
 
72
 
 
73
 
 
74
/***************
 
75
 **  Private  **
 
76
 **           **
 
77
 ***************/
 
78
 
 
79
#ifdef IMA_CSPP
 
80
 
 
81
/* NOTE:  If we were doing flushes on node, we'd have to set dcache_stride
 
82
          to 32 for single node systems and 64 for multinode systems.
 
83
          But since we only do this for cross node systems, we already know
 
84
          it needs to be 64
 
85
*/
 
86
 
 
87
int dcache_stride = 64;
 
88
#endif
 
89
 
 
90
#ifdef  CLUMP_ALLOC
 
91
#ifndef FRAG_CLUMP
 
92
#define FRAG_CLUMP      500
 
93
#endif
 
94
static struct frag freefrags;           /* free frag header cache */
 
95
static int numfrags = 0;
 
96
#endif
 
97
 
 
98
 
 
99
static struct frag *
 
100
frag_get_header()
 
101
{
 
102
        struct frag *fp;
 
103
        int n;
 
104
 
 
105
#ifdef  CLUMP_ALLOC
 
106
        if (numfrags == 0) {
 
107
                freefrags.fr_link = freefrags.fr_rlink = &freefrags;
 
108
                if (!(fp = TALLOC(FRAG_CLUMP, struct frag, "frgs")))
 
109
                        return (struct frag *)0;
 
110
                for (n = FRAG_CLUMP; n-- > 0; ) {
 
111
                        LISTPUTBEFORE(&freefrags, fp, fr_link, fr_rlink);
 
112
                        fp++;
 
113
                }
 
114
                numfrags = FRAG_CLUMP;
 
115
        }
 
116
        numfrags--;
 
117
        fp = freefrags.fr_link;
 
118
        LISTDELETE(fp, fr_link, fr_rlink);
 
119
 
 
120
#else
 
121
        fp = TALLOC(1, struct frag, "frag");
 
122
#endif
 
123
 
 
124
        return fp;
 
125
}
 
126
 
 
127
 
 
128
static
 
129
frag_put_header(fp)
 
130
        struct frag *fp;
 
131
{
 
132
#ifdef  CLUMP_ALLOC
 
133
        if (numfrags == 0)
 
134
                freefrags.fr_link = freefrags.fr_rlink = &freefrags;
 
135
        LISTPUTBEFORE(&freefrags, fp, fr_link, fr_rlink);
 
136
        numfrags++;
 
137
 
 
138
#else
 
139
        PVM_FREE(fp);
 
140
#endif
 
141
        return 0;
 
142
}
 
143
 
 
144
 
 
145
/**********************
 
146
 **  Frag Functions  **
 
147
 **                  **
 
148
 **********************/
 
149
 
 
150
/*      fr_new()
 
151
*
 
152
*       Create a new frag with 1 reference, not in a list.
 
153
*       If len is nonzero, len bytes are allocated as data space.
 
154
*       Else, the frag has no data (is a master or will get data later).
 
155
*/
 
156
 
 
157
struct frag *
 
158
fr_new(len)
 
159
        int len;        /* (max) buffer size or 0 */
 
160
{
 
161
        struct frag *fp;
 
162
 
 
163
        if (!(fp = frag_get_header()))
 
164
                goto oops;
 
165
 
 
166
        if (len) {      /* slave frag */
 
167
                fp->fr_link = fp->fr_rlink = 0;
 
168
                if (!(fp->fr_dat = fp->fr_buf = da_new(len))) {
 
169
                        frag_put_header(fp);
 
170
                        goto oops;
 
171
                }
 
172
                fp->fr_max = len;
 
173
 
 
174
        } else {        /* master */
 
175
                fp->fr_link = fp->fr_rlink = fp;
 
176
                fp->fr_dat = fp->fr_buf = 0;
 
177
                fp->fr_max = 0;
 
178
        }
 
179
        fp->fr_len = 0;
 
180
        fp->fr_u.ref = 1;
 
181
        fp->fr_u.dab = 1;
 
182
        fp->fr_u.spr = 0;
 
183
        fp->fr_rip = 0;
 
184
#ifdef IMA_CSPP
 
185
        fp->fr_num_unpacked = 0;
 
186
#endif
 
187
/*
 
188
        pvmlogprintf("fr_new() %d = %lx\n", len, fp);
 
189
*/
 
190
        return fp;
 
191
 
 
192
oops:
 
193
        pvmlogerror("fr_new() can't get memory\n");
 
194
        pvmbailout(0);
 
195
        return (struct frag*)0;
 
196
}
 
197
 
 
198
 
 
199
/*      fr_snew()
 
200
*
 
201
*       Create a new frag with 1 reference, not in a list.
 
202
*       Its buffer is assumed to be a writable, dense, non-databuf.
 
203
*/
 
204
 
 
205
struct frag *
 
206
fr_snew(cp, len)
 
207
        char *cp;       /* buffer */
 
208
        int len;        /* buffer size */
 
209
{
 
210
        struct frag *fp;
 
211
 
 
212
        if (!(fp = frag_get_header()))
 
213
                goto oops;
 
214
 
 
215
        fp->fr_link = fp->fr_rlink = 0;
 
216
        fp->fr_dat = fp->fr_buf = cp;
 
217
        fp->fr_max = fp->fr_len = len;
 
218
        fp->fr_u.ref = 1;
 
219
        fp->fr_u.dab = 0;
 
220
        fp->fr_u.spr = 0;
 
221
        fp->fr_rip = 0;
 
222
        return fp;
 
223
 
 
224
oops:
 
225
        pvmlogerror("fr_snew() can't get memory\n");
 
226
        pvmbailout(0);
 
227
        return (struct frag*)0;
 
228
}
 
229
 
 
230
 
 
231
/*      fr_unref()
 
232
*
 
233
*       Reduce frag refcount by 1.  If result is < 1:
 
234
*               If the frag is a master, unref all its slave frags
 
235
*               Else, unref its data.
 
236
*               Then, free the frag.
 
237
*/
 
238
 
 
239
void
 
240
fr_unref(fp)
 
241
        struct frag *fp;                /* master frag */
 
242
{
 
243
/*
 
244
        pvmlogprintf("fr_unref() %lx ref %d\n", fp, fp->fr_u.ref);
 
245
*/
 
246
        if (fp->fr_u.ref-- == 1) {
 
247
                struct frag *fp2, *fp3;
 
248
 
 
249
                if (fp->fr_buf) {               /* slave frag */
 
250
                        if (fp->fr_u.dab)
 
251
#ifdef IMA_CSPP
 
252
                        if (fp->fr_num_unpacked) {
 
253
                                unsigned int addr = (unsigned int)(fp->fr_dat);
 
254
                                int nbytes = fp->fr_num_unpacked;
 
255
 
 
256
                                nbytes += (addr & 0x3f);
 
257
                                addr &= ~0x3f;
 
258
                                dcache_flush_region(addr, nbytes);
 
259
                        }
 
260
#endif
 
261
                                da_unref(fp->fr_buf);
 
262
 
 
263
                } else {                                /* master frag */
 
264
 
 
265
        /* unref all frags in chain */
 
266
                        for (fp2 = fp->fr_link; fp2 != fp; fp2 = fp3) {
 
267
                                fp3 = fp2->fr_link;
 
268
                                LISTDELETE(fp2, fr_link, fr_rlink);
 
269
                                fr_unref(fp2);
 
270
                        }
 
271
                }
 
272
                frag_put_header(fp);
 
273
        }
 
274
}
 
275
 
 
276