NVMLib  very early alpha
A library to optimally use a Hybrid RAM setup.
mem_log.c
Go to the documentation of this file.
1 #include "mem_log.h"
2 #include "malloc.h"
3 #include <time.h>
4 #include <libiberty/splay-tree.h>
5 // #include <splay-tree.h>
6 
8  TAILQ_INIT(&write_queue_head);
9  TAILQ_INIT(&read_queue_head);
10 }
11 
23 void log_write(void* addr, size_t size) {
24  address_log* ad_log = (address_log*)malloc(sizeof(address_log));
25  ad_log->size = size >> 3;
26 
27  addr2memoid_key skey;
28  skey.comp = cmp_addr;
29  skey.addr = addr;
30  time(&ad_log->access_time);
31  uv_mutex_lock(&write_splay_tree_mutex);
32  splay_tree_node ret_node = splay_tree_lookup(addr2MemOID_write, (splay_tree_key)&skey);
33 
34  MEMoidKey mkey = ((addr2memoid_key*)ret_node->key)->key;
35  ad_log->key = mkey;
36  ad_log->offset = addr - KEY_FIRST(mkey);
37  uv_mutex_unlock(&write_splay_tree_mutex);
38  TAILQ_INSERT_TAIL(&write_queue_head, ad_log, list);
39 }
40 
52 void log_read(void* addr, size_t size) {
53  address_log* ad_log = (address_log*)malloc(sizeof(address_log));
54  ad_log->size = size >> 3;
55 
56  addr2memoid_key skey;
57  skey.comp = cmp_addr;
58  skey.addr = addr;
59  time(&ad_log->access_time);
60  uv_mutex_lock(&read_splay_tree_mutex);
61  splay_tree_node ret_node = splay_tree_lookup(addr2MemOID_read, (splay_tree_key)&skey);
62 
63  MEMoidKey mkey = ((addr2memoid_key*)ret_node->key)->key;
64  ad_log->key = mkey;
65  ad_log->offset = addr - KEY_FIRST(mkey);
66  uv_mutex_unlock(&read_splay_tree_mutex);
67  TAILQ_INSERT_TAIL(&read_queue_head, ad_log, list);
68 }
address_log::access_time
time_t access_time
Definition: mem_log.h:12
cmp_addr
@ cmp_addr
Definition: malloc.h:112
address_log
Definition: mem_log.h:8
address_log::key
MEMoidKey key
Definition: mem_log.h:9
addr2MemOID_write
splay_tree addr2MemOID_write
Definition: malloc.c:30
MEMoidKey
uint64_t MEMoidKey
The key of the HashTable that contains <MEMoidKey, MEMoid>.
Definition: malloc.h:49
log_read
void log_read(void *addr, size_t size)
Function to record the memory addresses read from in a given object.
Definition: mem_log.c:52
log_write
void log_write(void *addr, size_t size)
Function to record the memory addresses written into in a given object.
Definition: mem_log.c:23
addr2MemOID_read
splay_tree addr2MemOID_read
Definition: malloc.c:29
initialize_log_queues
void initialize_log_queues()
Definition: mem_log.c:7
addr2memoid_key::comp
enum splay_comp comp
Definition: malloc.h:117
mem_log.h
KEY_FIRST
#define KEY_FIRST(key)
Definition: malloc.h:88
malloc.h
read_splay_tree_mutex
uv_mutex_t read_splay_tree_mutex
The mutex used during manupulation of read splay tree
Definition: object_maintainance.c:18
addr2memoid_key::addr
void * addr
Definition: malloc.h:119
write_splay_tree_mutex
uv_mutex_t write_splay_tree_mutex
The mutex used during manupulation of read splay tree
Definition: object_maintainance.c:19
address_log::size
size_t size
Definition: mem_log.h:11
addr2memoid_key
The structure used in spaly_tree which used for getting MEMoid from the memory address.
Definition: malloc.h:116
address_log::offset
size_t offset
Definition: mem_log.h:10