Skip to content

Commit

Permalink
Merge branch 'mcount-update'
Browse files Browse the repository at this point in the history
A couple of fixes and update during investigation of #1949.

Signed-off-by: Namhyung Kim <[email protected]>
  • Loading branch information
namhyung committed Sep 2, 2024
2 parents 7e07a43 + c454d1e commit 9d88589
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
37 changes: 30 additions & 7 deletions arch/x86_64/mcount.S
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ GLOBAL(mcount)
/* save rax (implicit argument for variadic functions) */
push %rax

/* save scratch registers due to -fipa-ra */
push %r10
push %r11

call mcount_entry

pop %r11
pop %r10

pop %rax

/* restore original stack pointer */
Expand Down Expand Up @@ -88,10 +95,19 @@ END(mcount)
*/
ENTRY(mcount_return)
.cfi_startproc
sub $48, %rsp
.cfi_def_cfa_offset 48

movq %rdi, 32(%rsp)
sub $96, %rsp
.cfi_def_cfa_offset 96

/* save all caller-saved registers due to -fipa-ra */
movq %r11, 80(%rsp)
movq %r10, 72(%rsp)
movq %r9, 64(%rsp)
movq %r8, 56(%rsp)
movq %rdi, 48(%rsp)
movq %rsi, 40(%rsp)
movq %rcx, 32(%rsp)

/* below are used to carry return value */
movdqu %xmm0, 16(%rsp)
movq %rdx, 8(%rsp)
movq %rax, 0(%rsp)
Expand All @@ -113,14 +129,21 @@ ENTRY(mcount_return)
movq 0(%rsp), %rsp

/* restore original return address in parent */
movq %rax, 40(%rsp)
movq %rax, 88(%rsp)

movq 0(%rsp), %rax
movq 8(%rsp), %rdx
movdqu 16(%rsp), %xmm0
movq 32(%rsp), %rdi

add $40, %rsp
movq 32(%rsp), %rcx
movq 40(%rsp), %rsi
movq 48(%rsp), %rdi
movq 56(%rsp), %r8
movq 64(%rsp), %r9
movq 72(%rsp), %r10
movq 80(%rsp), %r11

add $88, %rsp
.cfi_def_cfa_offset 8
retq
.cfi_endproc
Expand Down
2 changes: 1 addition & 1 deletion libmcount/mcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ void mcount_entry_filter_record(struct mcount_thread_data *mtdp, struct mcount_r
#define FLAGS_TO_CHECK (TRIGGER_FL_RECOVER | TRIGGER_FL_TRACE_ON | TRIGGER_FL_TRACE_OFF)

if (tr->flags & FLAGS_TO_CHECK) {
if (tr->flags & TRIGGER_FL_RECOVER) {
if ((tr->flags & TRIGGER_FL_RECOVER) && !mcount_estimate_return) {
mcount_rstack_restore(mtdp);
*rstack->parent_loc = mcount_return_fn;
rstack->flags |= MCOUNT_FL_RECOVER;
Expand Down
3 changes: 1 addition & 2 deletions libmcount/mcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ struct mcount_ret_stack {
unsigned long parent_ip;
unsigned long child_ip;
enum mcount_rstack_flag flags;
unsigned dyn_idx;
/* time in nsec (CLOCK_MONOTONIC) */
uint64_t start_time;
uint64_t end_time;
int tid;
unsigned dyn_idx;
uint64_t filter_time;
unsigned filter_size;
unsigned short depth;
Expand Down
2 changes: 1 addition & 1 deletion libmcount/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ static int record_event(struct mcount_thread_data *mtdp, struct mcount_event *ev
rec->data += 4; /* set 'more' bit in uftrace_record */

*(uint16_t *)ptr = data_size;
memcpy(ptr + 2, event->data, data_size);
mcount_memcpy1(ptr + 2, event->data, data_size);
}

curr_buf->size += size;
Expand Down

0 comments on commit 9d88589

Please sign in to comment.