Skip to content

Commit 4db5128

Browse files
committed
Use defined constant values of trace
1 parent 09c5728 commit 4db5128

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

contrib/plugins/bap-tracing/frame_buffer.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,13 @@ static bool std_frame_add_operand(StdFrame *std_frame, OperandInfo *oi) {
8787
return true;
8888
}
8989

90-
FrameBuffer *frame_buffer_new(size_t size) {
90+
FrameBuffer *frame_buffer_new(void) {
9191
FrameBuffer *fb = g_malloc0(sizeof(FrameBuffer));
92-
fb->fbuf = g_malloc0(sizeof(Frame *) * size);
93-
fb->max_size = size;
9492
return fb;
9593
}
9694

9795
bool frame_buffer_is_full(const FrameBuffer *buf) {
98-
return buf->idx + 1 >= buf->max_size;
96+
return buf->idx + 1 >= frames_per_toc_entry;
9997
}
10098

10199
void frame_buffer_close_frame(FrameBuffer *buf) {
@@ -162,7 +160,7 @@ bool frame_buffer_is_empty(const FrameBuffer *buf) {
162160
}
163161

164162
void frame_buffer_flush_to_file(FrameBuffer *buf, WLOCKED FILE *file) {
165-
for (size_t i = 0; i <= buf->idx && i < buf->max_size; ++i) {
163+
for (size_t i = 0; i <= buf->idx && i < frames_per_toc_entry; ++i) {
166164
Frame *frame = buf->fbuf[i];
167165
size_t msg_size = frame__get_packed_size(frame);
168166
uint8_t *packed_buffer = g_alloca(msg_size);
@@ -172,7 +170,7 @@ void frame_buffer_flush_to_file(FrameBuffer *buf, WLOCKED FILE *file) {
172170
buf->frames_written++;
173171
frame_free(frame);
174172
}
175-
memset(buf->fbuf, 0, sizeof(Frame *) * buf->max_size);
173+
memset(buf->fbuf, 0, sizeof(buf->fbuf));
176174
buf->idx = 0;
177175
// toc_update(); ??
178176
}

contrib/plugins/bap-tracing/frame_buffer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdio.h>
1010

1111
#include "frame.piqi.pb-c-patched.h"
12+
#include "trace_consts.h"
1213
#include "trace_meta.h"
1314

1415
typedef enum {
@@ -17,17 +18,16 @@ typedef enum {
1718
} OperandAccess;
1819

1920
typedef struct {
20-
Frame **fbuf; ///< The frames buffered.
21-
size_t idx; ///< Points to currently open frame.
22-
size_t max_size; ///< Maximum number of elements fbuf can hold.
21+
Frame *fbuf[FRAMES_PER_TOC_ENTRY_]; ///< The frames buffered.
22+
size_t idx; ///< Points to currently open frame.
2323
size_t frames_written; ///< Number of frames written from buffer to file.
2424
} FrameBuffer;
2525

2626
/**
2727
* \brief Initializes a frame buffer with space for \p size frames.
2828
* Returns the buffer or NULL in case of failure.
2929
*/
30-
FrameBuffer *frame_buffer_new(size_t size);
30+
FrameBuffer *frame_buffer_new(void);
3131

3232
void frame_buffer_flush_to_file(FrameBuffer *buf, WLOCKED FILE *file);
3333
bool frame_buffer_is_full(const FrameBuffer *buf);

contrib/plugins/bap-tracing/trace_consts.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
// Trace header constants
77

88
static const uint64_t magic_number = 7456879624156307493LL;
9-
static const uint64_t magic_number_offset = 0LL;
10-
static const uint64_t trace_version_offset = 8LL;
11-
static const uint64_t bfd_arch_offset = 16LL;
12-
static const uint64_t bfd_machine_offset = 24LL;
13-
static const uint64_t num_trace_frames_offset = 32LL;
14-
static const uint64_t toc_offset_offset = 40LL;
15-
static const uint64_t first_frame_offset = 48LL;
16-
static const uint64_t out_trace_version = 2LL;
9+
10+
static const uint64_t offset_magic_number = 0LL;
11+
static const uint64_t offset_trace_version = 8LL;
12+
static const uint64_t offset_target_arch = 16LL;
13+
static const uint64_t offset_target_machine = 24LL;
14+
static const uint64_t offset_frames_per_toc_entry = 32LL;
15+
static const uint64_t offset_toc_index_offset = 40LL;
16+
static const uint64_t offset_toc_start = 48LL;
17+
static const uint64_t offset_first_frame = 48LL;
18+
19+
static const uint64_t trace_version = 3LL;
20+
21+
#define FRAMES_PER_TOC_ENTRY_ 64LL
22+
static const uint64_t frames_per_toc_entry = FRAMES_PER_TOC_ENTRY_;
1723

1824
// Arch specific
1925

contrib/plugins/bap-tracing/tracing.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) {
152152
}
153153
g_ptr_array_insert(state.vcpus, vcpu_index, vcpu);
154154

155-
FrameBuffer *vcpu_frame_buffer = frame_buffer_new(FRAME_BUFFER_SIZE_DEFAULT);
155+
FrameBuffer *vcpu_frame_buffer = frame_buffer_new();
156156
g_ptr_array_insert(state.frame_buffer, vcpu_index, vcpu_frame_buffer);
157157

158158
g_rw_lock_writer_unlock(&state.frame_buffer_lock);
@@ -208,14 +208,14 @@ static bool write_header(FILE *file, const char *target_name) {
208208
qemu_plugin_outs("Failed to get arch/mach.\n");
209209
return false;
210210
}
211-
uint64_t num_frames = 0ULL;
212-
uint64_t toc_off = 0ULL;
211+
uint64_t num_toc_entries = 0ULL;
212+
uint64_t toc_index_offset = 0ULL;
213213
WRITE(magic_number);
214-
WRITE(out_trace_version);
214+
WRITE(trace_version);
215215
WRITE(frame_arch);
216216
WRITE(frame_mach);
217-
WRITE(num_frames);
218-
WRITE(toc_off);
217+
WRITE(num_toc_entries); // Gets updated later
218+
WRITE(toc_index_offset); // Gets updated later
219219
return true;
220220
}
221221

contrib/plugins/bap-tracing/tracing.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ static struct arch_enum_entry arch_map[] = {
106106

107107
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
108108

109-
#define FRAME_BUFFER_SIZE_DEFAULT 1024
110-
111109
/**
112110
* \brief VLIW architecture have instructions longer than 4 or 8bytes.
113111
*/

0 commit comments

Comments
 (0)