/* * Clean all caches promptly. This just calls cache_clean * repeatedly until we are sure that every cache has had a chance to * be fully cleaned */ void cache_flush(void) { while (cache_clean() != -1) cond_resched(); while (cache_clean() != -1) cond_resched(); }
static int read_map(const char *root, time_t now, struct lookup_context *ctxt) { char key[KEY_MAX_LEN + 1]; char mapent[MAPENT_MAX_LEN + 1]; char *mapname; FILE *f; int entry; time_t age = now ? now : time(NULL); mapname = alloca(strlen(ctxt->mapname) + 6); sprintf(mapname, "file:%s", ctxt->mapname); f = fopen(ctxt->mapname, "r"); if (!f) { error(MODPREFIX "could not open map file %s", ctxt->mapname); return 0; } while(1) { entry = read_one(f, key, mapent); if (entry) cache_add(root, key, mapent, age); if (feof(f)) break; } fclose(f); /* Clean stale entries from the cache */ cache_clean(root, age); return 1; }
/* Insert one entry into the cache */ int cache_insert(char *key, SPDMessageType msgtype, FT_Wave * fwave) { GHashTable *cache; TCacheEntry *entry; TCounterEntry *centry; char *key_table; if (FestivalCacheOn == 0) return 0; if (key == NULL) return -1; if (fwave == NULL) return -1; /* Check if the entry isn't present already */ if (cache_lookup(key, msgtype, 0) != NULL) return 0; key_table = cache_gen_key(msgtype); log_msg(OTTS_LOG_DEBUG, "Cache: Inserting wave with key:'%s' into table '%s'", key, key_table); /* Clean less used cache entries if the size would exceed max. size */ if ((FestivalCache.size + fwave->num_samples * sizeof(short)) > (FestivalCacheMaxKBytes * 1024)) if (cache_clean(fwave->num_samples * sizeof(short)) != 0) return -1; /* Select the right table according to language, voice, etc. or create a new one */ cache = g_hash_table_lookup(FestivalCache.caches, key_table); if (cache == NULL) { cache = g_hash_table_new(g_str_hash, g_str_equal); g_hash_table_insert(FestivalCache.caches, key_table, cache); } else { g_free(key_table); } /* Fill the CounterEntry structure that will later allow us to remove the less used entries from cache */ centry = (TCounterEntry *) g_malloc(sizeof(TCounterEntry)); centry->start = time(NULL); centry->count = 1; centry->size = fwave->num_samples * sizeof(short); centry->p_caches = cache; centry->key = g_strdup(key); FestivalCache.cache_counter = g_list_append(FestivalCache.cache_counter, centry); entry = (TCacheEntry *) g_malloc(sizeof(TCacheEntry)); entry->p_counter_entry = centry; entry->fwave = fwave; FestivalCache.size += centry->size; g_hash_table_insert(cache, g_strdup(key), entry); return 0; }
static void clear_cache (GConfSource* source) { XMLSource* xs = (XMLSource*)source; /* clean all entries older than 0 seconds */ cache_clean(xs->cache, 0); }
/* This timeout periodically cleans up the old cruft in the cache */ static gboolean cleanup_timeout(gpointer data) { XMLSource* xs = (XMLSource*)data; cache_clean(xs->cache, 60*5 /* 5 minutes */); return TRUE; }
/** * Generate a set of random timing samples using the SAME KEY! */ void generate_samples(timing_pair * buffer, key_data * key) { int i; for (i = 0; i < BUF_SIZE; i++) { //printf("generate_samples i = %d\n", i); cache_clean(0); timing_sample(key, buffer + i); } }
/* * We want to regularly clean the cache, so we need to schedule some work ... */ static void do_cache_clean(void *data) { int delay = 5; if (cache_clean() == -1) delay = 30*HZ; if (list_empty(&cache_list)) delay = 0; if (delay) schedule_delayed_work(&cache_cleaner, delay); }
static struct file * cache_get(const char *path) { struct file *f = NULL; pthread_mutex_lock(&cache.lock); cache_clean(); f = g_hash_table_lookup(cache.files, path); if(f == NULL) f = cache_insert(path); pthread_mutex_unlock(&cache.lock); return f; }
int main(int argc, char *argv[]) { int c; int value = 0; int check = 0; unsigned int size = 1024; while ((c = getopt(argc, argv, "s:v:ch")) != -1) { switch(c) { case 's': size = atoi(optarg); break; case 'v': value = atoi(optarg); break; case 'c': check = 1; break; case 'h': usage(); return 0; default: printf("invalid option: %c\n", c); usage(); return -1; } } int fd_mem = open(UIO_MEM, O_RDWR); if(fd_mem < 1){ perror(argv[0]); printf("Invalid UIO device file: '%s'\n", UIO_MEM); return -1; } volatile unsigned int *usermemory = (volatile unsigned int*) mmap(NULL, UMEM_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd_mem, 0); int fd_pycoram = open(UIO_PYCORAM, O_RDWR); if(fd_pycoram < 1){ perror(argv[0]); printf("Invalid UIO device file: '%s'\n", UIO_PYCORAM); return -1; } volatile unsigned int *pycoram = (volatile unsigned int*) mmap(NULL, MAP_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd_pycoram, 0); volatile int *a = (volatile int*) &usermemory[0]; volatile int *b = (volatile int*) &usermemory[size]; // initialization of data int i; if(check) goto verify; for(i=0; i<size * 2; i++){ //printf("write %10d\n", i); a[i] = i + value; } cache_clean((char*)usermemory, size * sizeof(int) * 2); msync((void*)usermemory, UMEM_SIZE, MS_SYNC); int src = UMEM_ADDR; int dst = UMEM_ADDR + size * sizeof(int); printf("memcpy from 'a' to 'b'\n"); printf("src = %08x\n", src); printf("dst = %08x\n", dst); printf("size = %8d\n", size); *pycoram = (volatile unsigned int) src; printf("."); *pycoram = (volatile unsigned int) dst; printf("."); *pycoram = (volatile unsigned int) size * sizeof(int); printf(".\n"); volatile int recv = *pycoram; verify: if(check){ printf("check only\n"); } cache_clean((char*)usermemory, size * sizeof(int) * 2); msync((void*)usermemory, UMEM_SIZE, MS_INVALIDATE); int mismatch = 0; for(i=0; i<size; i++){ //printf("read %10d\n", b[i]); if(a[i] != b[i]){ mismatch = 1; printf("%10d %10d\n", a[i], b[i]); } if(i==size-1){ //printf("read %10d\n", b[i]); } } if(mismatch){ printf("NG\n"); }else{ printf("OK\n"); } munmap((void*) usermemory, UMEM_SIZE); munmap((void*) pycoram, MAP_SIZE); return 0; }