Skip to contentSkip to conversation

kernelshark plugins and ftrace array fields

DISCUSSION Avi Kivity 2 participants 10 messages Sep 2, 2010 – Sep 5, 2010 KVM

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

I'd like to add enhance kvm_emulate_insn display in kernelshark to
show the disassembly of the instruction being emulated. However, pevent_get_field_val() doesn't support arrays (the instruction is provided in a 15-byte array).

Can you add support for arrays in the kernelshark API? With that, it looks like adding disassembly output to the kvm plugin should be quite simple.

Signature · 1 line
error compiling committee.c: too many arguments to function
#1 lore raw
Quoted 9 lines · Avi Kivity

I'd like to add enhance kvm_emulate_insn display in kernelshark to show the disassembly of the instruction being emulated. However, pevent_get_field_val() doesn't support arrays (the instruction is provided in a 15-byte array).

Can you add support for arrays in the kernelshark API? With that, it looks like adding disassembly output to the kvm plugin should be quite simple.

Sure, I could add a pevent_get_field_array() or something. Could you tell me the event and give me an example of what you want to do.

Thanks,

-- Steve

author
#2 lore raw
Quoted 6 lines · Steven Rostedt
Quoted 5 lines · Avi Kivity

I'd like to add enhance kvm_emulate_insn display in kernelshark to show the disassembly of the instruction being emulated. However, pevent_get_field_val() doesn't support arrays (the instruction is provided in a 15-byte array).

Quoted 6 lines
Quoted 4 lines

Can you add support for arrays in the kernelshark API? With that, it looks like adding disassembly output to the kvm plugin should be quite simple.

Sure, I could add a pevent_get_field_array() or something. Could you tell me the event and give me an example of what you want to do.

plugin_kvm.c:

kvm_emulate_insn_handler()
{
fetch insn array and len field
feed into disassembler trace_seq_printf() the disassembled instruction
}

Signature · 1 line
error compiling committee.c: too many arguments to function
#3 lore raw
Quoted 14 lines · Avi Kivity
Quoted 6 lines · Steven Rostedt
Quoted 5 lines · Avi Kivity

I'd like to add enhance kvm_emulate_insn display in kernelshark to show the disassembly of the instruction being emulated. However, pevent_get_field_val() doesn't support arrays (the instruction is provided in a 15-byte array).

Quoted 6 lines
Quoted 4 lines

Can you add support for arrays in the kernelshark API? With that, it looks like adding disassembly output to the kvm plugin should be quite simple.

Sure, I could add a pevent_get_field_array() or something. Could you tell me the event and give me an example of what you want to do.

Quoted 8 lines

plugin_kvm.c:

kvm_emulate_insn_handler()
{
fetch insn array and len field
feed into disassembler trace_seq_printf() the disassembled instruction
}

I don't have that tracepoint in any of my kernels. Is this new? I guess if I see the TRACE_EVENT() I could emulate something and work with it.

-- Steve

author
#4 lore raw
Quoted 12 lines · Steven Rostedt
Quoted 9 lines

plugin_kvm.c:

kvm_emulate_insn_handler()
{
fetch insn array and len field
feed into disassembler trace_seq_printf() the disassembled instruction
}

I don't have that tracepoint in any of my kernels. Is this new? I guess if I see the TRACE_EVENT() I could emulate something and work with it.

e46479f852ada, in 2.6.35-rc1.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Steven Rostedt
Quoted 9 lines

plugin_kvm.c:

kvm_emulate_insn_handler()
{
fetch insn array and len field
feed into disassembler trace_seq_printf() the disassembled instruction
}

Quoted 5 lines
Quoted 3 lines

I don't have that tracepoint in any of my kernels. Is this new? I guess if I see the TRACE_EVENT() I could emulate something and work with it.

e46479f852ada, in 2.6.35-rc1.

Oops! sorry. All my boxes with KVM enabled were running 2.6.34 and I was looking in the code under include/trace/events/kvm.h, forgetting that these are defined in the arch/x86 tree.

Found it, thanks.

-- Steve

#6 lore raw
In reply to Avi Kivity
Quoted 14 lines · Avi Kivity
Quoted 6 lines · Steven Rostedt
Quoted 5 lines · Avi Kivity

I'd like to add enhance kvm_emulate_insn display in kernelshark to show the disassembly of the instruction being emulated. However, pevent_get_field_val() doesn't support arrays (the instruction is provided in a 15-byte array).

Quoted 6 lines
Quoted 4 lines

Can you add support for arrays in the kernelshark API? With that, it looks like adding disassembly output to the kvm plugin should be quite simple.

Sure, I could add a pevent_get_field_array() or something. Could you tell me the event and give me an example of what you want to do.

Quoted 9 lines

plugin_kvm.c:

kvm_emulate_insn_handler()
{
fetch insn array and len field
feed into disassembler trace_seq_printf() the disassembled instruction
}

OK, with no modification of what I have already, I just created this handler:

static int
kvm_emulate_insn_handler(struct trace_seq *s, struct record *record,
struct event_format *event, void *context)

{
        struct format_field *field;
        unsigned char *data = record->data;
        int i;

        field = pevent_find_field(event, "insn");
        if (!field) {
                trace_seq_puts(s, "Can't find inst field");
                return 0;
        }

        trace_seq_puts(s, "insn: ");
        for (i = 0; i < field->size; i++) {
                trace_seq_printf(s, "%s%02x",
                                 i ? "," : "",
                                 data[field->offset + i]);
        }

        return 0;
}

I think this is what you would want, right?

-- Steve

#7 lore raw
Quoted 31 lines · Steven Rostedt

On Thu, 2010-09-02 at 17:34 +0300, Avi Kivity wrote:

OK, with no modification of what I have already, I just created this handler:

static int
kvm_emulate_insn_handler(struct trace_seq *s, struct record *record,
struct event_format *event, void *context)

{
        struct format_field *field;
        unsigned char *data = record->data;
        int i;

        field = pevent_find_field(event, "insn");
        if (!field) {
                trace_seq_puts(s, "Can't find inst field");
                return 0;
        }

        trace_seq_puts(s, "insn: ");
        for (i = 0; i < field->size; i++) {
                trace_seq_printf(s, "%s%02x",
                                 i ? "," : "",
                                 data[field->offset + i]);
        }

        return 0;
}
Quoted 1 line

I think this is what you would want, right?

I think I will add a:

void *pevent_get_field_raw(stuct trace_seq *s,
struct event_format *event, char *field_name, struct record *record, int **field_len);

which will return a pointer into record->data and set the field_len to the actual size.

This will be useful for dynamic arrays too, since it is more complex than just using a field->offset.

-- Steve

#8 lore raw
Quoted 8 lines · Steven Rostedt

I think I will add a:

void *pevent_get_field_raw(stuct trace_seq *s,
struct event_format *event, char *field_name, struct record *record, int **field_len);

Quoted 5 lines

which will return a pointer into record->data and set the field_len to the actual size.

This will be useful for dynamic arrays too, since it is more complex than just using a field->offset.

I just pushed out the changes and my new example looks like this:

static int
kvm_emulate_insn_handler(struct trace_seq *s, struct record *record,
struct event_format *event, void *context)

{
        unsigned char *data;
        int len;
        int i;

        data = pevent_get_field_raw(s, event, "insn", record,
                                    &len, 1);
        if (!data)
                return -1;

        trace_seq_puts(s, "insn: ");
        for (i = 0; i < len; i++) {
                trace_seq_printf(s, "%s%02x",
                                 i ? "," : "",
                                 data[i]);
        }

        return 0;
}
author
#9 lore raw
Quoted 17 lines · Steven Rostedt

I just pushed out the changes and my new example looks like this:

static int
kvm_emulate_insn_handler(struct trace_seq *s, struct record *record,
struct event_format *event, void *context)

{
         unsigned char *data;
         int len;
         int i;

         data = pevent_get_field_raw(s, event, "insn", record,
                                     &len, 1);
         if (!data)
                 return -1;

         trace_seq_puts(s, "insn: ");
Quoted 9 lines
         for (i = 0; i<  len; i++) {
                 trace_seq_printf(s, "%s%02x",
                                  i ? "," : "",
                                  data[i]);
         }

         return 0;
}

That looks perfect. But on which branch can I find it?

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.