1 #if defined(RS6K) && defined(__64BIT__) 14 typedef long long int ll_t;
16 #define WORDLEN ((ll_t)sizeof(ll_t)) 17 #define RNDUP(i,n) (( ( (i) + (n) - 1 ) / (n) ) * (n)) 18 #define TRUE_BYTES(x) ((x) + 4*WORDLEN) 20 #if defined(CRAY) && !defined(SV2) 21 #define getcurheap GETCURHEAP 22 #define getmaxcurheap GETMAXCURHEAP 23 #define getcurheap_thread GETCURHEAP_THREAD 24 #define getmaxcurheap_thread GETMAXCURHEAP_THREAD 25 #define getmaxloc GETMAXLOC 26 #define resetmaxloc RESETMAXLOC 27 #define profile_heap_get PROFILE_HEAP_GET 29 #define getcurheap getcurheap_ 30 #define getmaxcurheap getmaxcurheap_ 31 #define getcurheap_thread getcurheap_thread_ 32 #define getmaxcurheap_thread getmaxcurheap_thread_ 33 #define getmaxloc getmaxloc_ 34 #define resetmaxloc resetmaxloc_ 35 #define profile_heap_get profile_heap_get_ 42 #if !defined(CACHELINESIZE) 43 #define CACHELINESIZE 128 60 extern void necsx_trbk_(
const char *msg,
int msglen);
61 extern void necsx_trbk_fl_(
const char *msg,
const char *filename,
int *lineno,
62 int msglen,
int filenamelen);
63 #define xl__trbk_() { int lineno = __LINE__; necsx_trbk_fl_("Error", __FILE__, &lineno, 5, sizeof(__FILE__)-1); } 72 #if defined(INTERCEPT_ALLOC) 76 #if defined(RS6K) && defined(__64BIT__) 82 #define EC_free __free 83 #define EC_malloc __malloc 84 #define EC_calloc __calloc 85 #define EC_realloc __realloc 86 #define EC_strdup __strdup 100 #undef INTERCEPT_ALLOC 109 #if defined(CLSZ_OPT) 125 char pad[CACHELINESIZE - 2*WORDLEN];
128 #define NANS_FILL ((ll_t)0x7FF7FFFF7FF7FFFF) 137 #if !defined(NODISCLAIM) 144 #if defined(NODISCLAIM) 153 #if !defined(NODISCLAIM) 175 const ll_t big = (
ll_t) 1000000000000L;
176 if (curalloc < 0 || curalloc > big) {
178 "Check_curalloc(): curalloc has probably gone crazy : Attempt to allocate ==> %lld bytes\n",
curalloc);
189 char *env = getenv(
"EC_PROFILE_HEAP");
195 #if !defined(NODISCLAIM) 197 env = getenv(
"EC_DISCLAIM_THRESHOLD");
199 double tmp = atof(env);
219 for (j=0; j<NPROFILE; j++) {
242 for (j=0; j<NPROFILE; j++) {
266 #if defined(INTERCEPT_ALLOC) 270 if (nval < 0) nval = 0;
271 if (nval > NPROFILE+1) nval = NPROFILE+1;
273 for (j=0; j<nval; j++) {
278 for (it=0; it<nt; it++) {
279 for (j=0; j<nval; j++) {
286 for (j=0; j<nval; j++) val[j] =
free_hits[j];
288 else if (icase == 1) {
291 else if (icase == 2) {
294 else if (icase == 3) {
297 else if (icase == 4) {
298 for (j=0; j<nval; j++) {
300 val[j] = (tmp > 0) ? RNDUP(
alloc_amount[j],tmp)/tmp : 0;
313 #if defined(CLSZ_OPT) 326 ll_t nans = NANS_FILL;
327 ll_t j = adjsize/WORDLEN;
329 fprintf(stderr,
"WARNING: NaNS at end of array overwritten with %e\n",q[j]);
333 fprintf(stderr,
"ERROR: Too many NaNS overwrites at end of arrays\n");
341 true_bytes = -TRUE_BYTES(adjsize);
342 #if !defined(NODISCLAIM) 349 unsigned int len = (
unsigned int)tb;
351 int rc = disclaim(p, len, ZERO_MEM);
359 clsz_opt[it].curalloca += true_bytes;
376 char *env = getenv(
"EC_FILL_NANS");
379 if (strcmp(env,
"true") == 0 ||
380 strcmp(env,
"TRUE") == 0 ||
385 if (adjsize < 0) adjsize = 0;
386 adjsize = RNDUP(adjsize,WORDLEN);
390 true_bytes = TRUE_BYTES(adjsize);
397 DRHOOK_START(malloc);
398 d = (
double *)malloc(true_bytes);
402 d = (
double *)malloc(true_bytes);
425 DRHOOK_START(thread);
428 clsz_opt[it].curalloca += true_bytes;
446 clsz_opt[it].curalloca += true_bytes;
454 ll_t nans = NANS_FILL;
455 for (j=0; j<(WORDLEN+adjsize)/WORDLEN; j++) {
462 if (it == 1 && ip == 1 ) {
464 q=(
ll_t)p+true_bytes;
480 "EC_malloc(size=%lld => thesize=%lld => adjsize=%lld, true_bytes=%lld bytes) failed in file=%s, line=%d\n",
481 size, thesize, adjsize, true_bytes, __FILE__, __LINE__);
492 ll_t totbytes = nelem * elsize;
494 if (p) memset(p, 0, totbytes);
503 ll_t oldsize = p[-1];
504 if (oldsize < size) {
507 memcpy(pnew, p, oldsize);
523 ll_t totbytes =
sizeof(*s) * strlen(s);
532 #if defined(CLSZ_OPT) 538 for (i=1; i<nt; i++) {
544 #elif defined(_CRAYC) 557 #if defined(CLSZ_OPT) 558 int it = (thread_id && (*thread_id > 0)) ? *thread_id :
get_thread_id_();
570 #if defined(CLSZ_OPT) 571 ll_t maxcurheap_local=0;
574 for (it=0; it<nt; it++) {
575 maxcurheap_local +=
clsz_opt[it].maxcurheapa;
579 return maxcurheap_local;
590 #if defined(CLSZ_OPT) 591 int it = (thread_id && (*thread_id > 0)) ? *thread_id :
get_thread_id_();
static struct @0 clsz_opt[NTHRDS]
static ll_t disclaim_threshold_test
ll_t getcurheap_thread(const int *thread_id)
char pad[CACHELINESIZE - 2 *WORDLEN]
static void Profile_heap_put_thrd(ll_t size, int is_malloc, int it)
ll_t getmaxcurheap_thread(const int *thread_id)
static void Profile_heap_init()
void necsx_trbk_(const char *msg, int msglen)
static ll_t malloc_hits_thrd[NTHRDS][NPROFILE+1]
static void Profile_heap_put(ll_t size, int is_malloc)
static ll_t alloc_amount[NPROFILE+1]
static ll_t disclaim_threshold_limit
static ll_t alloc_amount_thrd[NTHRDS][NPROFILE+1]
void profile_heap_get(ll_t val[], const int *Nval, const int *Icase, int *nret)
static ll_t free_hits_thrd[NTHRDS][NPROFILE+1]
static ll_t malloc_hits[NPROFILE+1]
void * EC_realloc(void *vptr, ll_t size)
static double disclaim_threshold
pthread_mutex_t getcurheap_lock
void c_drhook_memcounter_(const int *thread_id, const long long int *size, long long int *keyptr_addr)
char * EC_strdup(const char *s)
void * EC_calloc(ll_t nelem, ll_t elsize)
static void Check_curalloc()
void necsx_trbk_fl_(const char *msg, const char *filename, int *lineno, int msglen, int filenamelen)
static ll_t free_hits[NPROFILE+1]
size_t get_tcmalloc_current_allocated_bytes_()
void * EC_malloc(ll_t size)
int get_max_threads_(void)
static int max_free_error