1/* 2 * Copyright (c) 2011, ETH Zurich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#include <stdio.h> 11#include <rcce/RCCE.h> 12#include <barrelfish/barrelfish.h> 13 14#define ALLOC_BYTES 0x100000 15#define MAX_ROUNDS 10000 16 17enum state { 18 State_Idle, 19 State_Inflate, 20 State_Deflate 21}; 22 23int RCCE_APP(int argc, char **argv) 24{ 25 int ME; 26 size_t total = 0; 27 enum state state = State_Idle; 28 static void *mem[MAX_ROUNDS]; 29 int j; 30 void *ret; 31 32 RCCE_init(&argc, &argv); 33 // RCCE_debug_set(RCCE_DEBUG_ALL); 34 35 ME = RCCE_ue(); 36 printf("Core %d passed RCCE_init\n", ME); 37 38 for(int i = 0; i < MAX_ROUNDS; i++) { 39 mem[i] = NULL; 40 } 41 42 for(int i = 0; i < RCCE_num_ues() * 9; i++) { 43 printf("%d: ", ME); 44 45 switch(state) { 46 case State_Idle: 47 printf("Idling\n"); 48 if(i % RCCE_num_ues() == ME) { 49 state = State_Inflate; 50 } 51 break; 52 53 case State_Inflate: 54 printf("Inflating\n"); 55 total = 0; 56 j = 0; 57 do { 58 ret = malloc(ALLOC_BYTES); 59 if(ret == NULL) { 60 /* printf("%d: Out of memory! total %lu bytes after %d allocations\n", */ 61 /* ME, total, j); */ 62 /* printf("highest memory at %p\n", mem[j - 1]); */ 63 } else { 64 assert(j < MAX_ROUNDS); 65 mem[j] = ret; 66 total += ALLOC_BYTES; 67 j++; 68 69 /* printf("%d: got memory at %p, run %d\n", ME, ret, j); */ 70 71 bool dirty = false; 72 for(int x = 0; x < ALLOC_BYTES; x++) { 73 char *c = ret; 74 75 if(c[x] != 0) { 76 dirty = true; 77 } 78 } 79 80 if(dirty) { 81 printf("Memory dirty\n"); 82 /* abort(); */ 83 /* } else { */ 84 /* printf("Memory clean\n"); */ 85 } 86 } 87 } while(ret != NULL); 88 89 printf("%d: Total %zu bytes after %d allocations\n", ME, total, j); 90 91 state = State_Deflate; 92 break; 93 94 case State_Deflate: 95 printf("Deflating\n"); 96 for(j = 0; mem[j] != NULL; j++) { 97 /* printf("%d: freeing %d\n", disp_get_core_id(), j); */ 98 free(mem[j]); 99 mem[j] = NULL; 100 } 101 state = State_Idle; 102 break; 103 } 104 105 RCCE_barrier(&RCCE_COMM_WORLD); 106 } 107 108 printf("%d: done\n", ME); 109 return 0; 110} 111