ROSS
tw-state.c
Go to the documentation of this file.
1 #include <ross.h>
2 #include <assert.h>
3 #include "lz4.h"
4 
5 /**
6  * Make a snapshot of the LP state and store it into the delta buffer
7  */
8 void
9 tw_snapshot(tw_lp *lp, size_t state_sz)
10 {
11  assert(lp->pe->delta_buffer[0] && "increase --buddy-size argument!");
12  memcpy(lp->pe->delta_buffer[0], lp->cur_state, state_sz);
13 }
14 
15 /**
16  * Create the delta from the current state and the snapshot.
17  * Compress it.
18  * @return The size of the compressed data placed in delta_buffer[1].
19  */
20 long
21 tw_snapshot_delta(tw_lp *lp, size_t state_sz)
22 {
23  unsigned long i;
24  tw_clock start;
25  int ret_size = 0;
26  unsigned char *current_state = (unsigned char *)lp->cur_state;
27  unsigned char *snapshot = lp->pe->delta_buffer[0];
28  void *scratch = lp->pe->delta_buffer[2];
29 
30  for (i = 0; i < state_sz; i++) {
31  snapshot[i] = current_state[i] - snapshot[i];
32  }
33 
34  start = tw_clock_read();
35  ret_size = LZ4_compress_fast_extState(scratch, (char*)snapshot, (char*)lp->pe->delta_buffer[1], state_sz, g_tw_delta_sz, g_tw_lz4_knob);
36  g_tw_pe->stats.s_lz4 += (tw_clock_read() - start);
37  if (ret_size < 0) {
38  tw_error(TW_LOC, "LZ4_compress error");
39  }
40 
41  start = tw_clock_read();
42  lp->pe->cur_event->delta_buddy = buddy_alloc(ret_size);
43  g_tw_pe->stats.s_buddy += (tw_clock_read() - start);
44  assert(lp->pe->cur_event->delta_buddy);
45  lp->pe->cur_event->delta_size = ret_size;
46  memcpy(lp->pe->cur_event->delta_buddy, lp->pe->delta_buffer[1], ret_size);
47 
48  return ret_size;
49 }
50 
51 /**
52  * Restore the state of lp to the (decompressed) data held in buffer
53  */
54 void
55 tw_snapshot_restore(tw_lp *lp, size_t state_sz)
56 {
57  unsigned int i;
58  tw_clock start = tw_clock_read();
59  unsigned char *snapshot = (unsigned char *)lp->pe->cur_event->delta_buddy;
60  unsigned char *current_state = (unsigned char *)lp->cur_state;
61 
62  int ret = LZ4_decompress_fast((char *)snapshot, (char*)lp->pe->delta_buffer[0], state_sz);
63  g_tw_pe->stats.s_lz4 += (tw_clock_read() - start);
64  if (ret < 0) {
65  tw_error(TW_LOC, "LZ4_decompress_fast error");
66  }
67 
68  snapshot = lp->pe->delta_buffer[0];
69  for (i = 0; i < state_sz; i++) {
70  current_state[i] = current_state[i] - snapshot[i];
71  }
72 }
#define TW_LOC
Definition: ross-extern.h:164
void * delta_buddy
Delta memory from buddy allocator.
Definition: ross-types.h:275
int LZ4_decompress_fast(const char *source, char *dest, int originalSize)
Definition: lz4.c:1298
size_t delta_size
Size of delta.
Definition: ross-types.h:276
void tw_snapshot_restore(tw_lp *lp, size_t state_sz)
Definition: tw-state.c:55
void tw_error(const char *file, int line, const char *fmt,...) NORETURN
Definition: tw-util.c:74
tw_statistics stats
per PE counters
Definition: ross-types.h:415
unsigned char * delta_buffer[3]
buffers used for delta encoding
Definition: ross-types.h:388
static tw_clock tw_clock_read(void)
Definition: aarch64.h:6
tw_clock s_lz4
Definition: ross-types.h:150
void * buddy_alloc(unsigned size)
Definition: buddy.c:234
long tw_snapshot_delta(tw_lp *lp, size_t state_sz)
Definition: tw-state.c:21
int LZ4_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.c:657
size_t g_tw_delta_sz
Definition: ross-global.c:34
void tw_snapshot(tw_lp *lp, size_t state_sz)
Definition: tw-state.c:9
tw_clock s_buddy
Definition: ross-types.h:149
tw_event * cur_event
Current event being processed.
Definition: ross-types.h:385
tw_pe * g_tw_pe
Definition: ross-global.c:75
tw_pe * pe
Definition: ross-types.h:308
uint64_t tw_clock
Definition: aarch64.h:4
void * cur_state
Current application LP data.
Definition: ross-types.h:315
unsigned int g_tw_lz4_knob
Definition: ross-global.c:41
LP State Structure.
Definition: ross-types.h:304