public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix traceaio with IO_CMD_{PREAD,PWRITE}
@ 2021-09-23 17:49 Nir Soffer
  2021-09-23 22:21 ` Nir Soffer
  0 siblings, 1 reply; 4+ messages in thread
From: Nir Soffer @ 2021-09-23 17:49 UTC (permalink / raw)
  To: systemtap; +Cc: teigland, fche, Nir Soffer

When using IO_CMD_{PREAD,PWRITE} aio_nbytes is the size of a single
buffer aio_buf.

Previously the script logged unrelated memory contents from userspace:

[     0 sanlock(8214):] io_submit(140589225578496, 1, 0x7fdd5fefc718)
    iocb[   0]=0x7fdd58000b70, fd=16, opcode=0, offset=0, nbytes=1048576, buf=0x7fdd5c5f6000
        iovec[   0]=0x7fdd5c5f6000, base=0x3000412212010, len=16
        iovec[   1]=0x7fdd5c5f6010, base=0x0, len=1
        iovec[   2]=0x7fdd5c5f6020, base=0x1, len=16
        ...

Now we trace iovecs only when using IO_CMD_{PREADV,PWITEV}:

[     0 sanlock(8397):] io_submit(140589225566208, 1, 0x7fdd5e6f9718)
    iocb[   0]=0x7fdd48000b70, fd=19, opcode=0, offset=0, nbytes=1048576, buf=0x7fdd5c3f2000
[     0 sanlock(8397):] io_submit(140589225566208, 1, 0x7fdd5e6f9718)
    iocb[   0]=0x7fdd48000b70, fd=19, opcode=1, offset=512, nbytes=512, buf=0x7fdd4810a000

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
---
 testsuite/systemtap.examples/io/traceaio.stp | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/testsuite/systemtap.examples/io/traceaio.stp b/testsuite/systemtap.examples/io/traceaio.stp
index 126ea9c3c..903d65526 100755
--- a/testsuite/systemtap.examples/io/traceaio.stp
+++ b/testsuite/systemtap.examples/io/traceaio.stp
@@ -8,6 +8,9 @@
 # published by the Free Software Foundation.
 #
 
+@define IO_CMD_PREADV   %( 7 %)
+@define IO_CMD_PWRITEV  %( 8 %)
+
 probe begin {
     println("Tracing started");
 }
@@ -27,12 +30,14 @@ probe syscall.io_submit
             printf("    iocb[%4d]=%p, fd=%d, opcode=%d, offset=%d, nbytes=%d, buf=%p\n",
                    i, iocbp, fd, opcode, offset, nbytes, buf)
 
-            for (j = 0; j < nbytes; j++) {
-                iovecp = &@cast(buf, "iovec", "kernel")[j]
-                base = user_uint64(&@cast(iovecp, "iovec", "kernel")->iov_base)
-                len = user_uint32(&@cast(iovecp, "iovec", "kernel")->iov_len)
-                printf("        iovec[%4d]=%p, base=%p, len=%d\n",
-                       j, iovecp, base, len)
+            if (opcode == @IO_CMD_PREADV || opcode == @IO_CMD_PREADV) {
+                for (j = 0; j < nbytes; j++) {
+                    iovecp = &@cast(buf, "iovec", "kernel")[j]
+                    base = user_uint64(&@cast(iovecp, "iovec", "kernel")->iov_base)
+                    len = user_uint32(&@cast(iovecp, "iovec", "kernel")->iov_len)
+                    printf("        iovec[%4d]=%p, base=%p, len=%d\n",
+                           j, iovecp, base, len)
+                }
             }
         }
     }
-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix traceaio with IO_CMD_{PREAD,PWRITE}
  2021-09-23 17:49 [PATCH] Fix traceaio with IO_CMD_{PREAD,PWRITE} Nir Soffer
@ 2021-09-23 22:21 ` Nir Soffer
  2021-09-23 23:00   ` Frank Ch. Eigler
  0 siblings, 1 reply; 4+ messages in thread
From: Nir Soffer @ 2021-09-23 22:21 UTC (permalink / raw)
  To: systemtap; +Cc: David Teigland, fche

On Thu, Sep 23, 2021 at 8:49 PM Nir Soffer <nsoffer@redhat.com> wrote:
>
> When using IO_CMD_{PREAD,PWRITE} aio_nbytes is the size of a single
> buffer aio_buf.
>
> Previously the script logged unrelated memory contents from userspace:
>
> [     0 sanlock(8214):] io_submit(140589225578496, 1, 0x7fdd5fefc718)
>     iocb[   0]=0x7fdd58000b70, fd=16, opcode=0, offset=0, nbytes=1048576, buf=0x7fdd5c5f6000
>         iovec[   0]=0x7fdd5c5f6000, base=0x3000412212010, len=16
>         iovec[   1]=0x7fdd5c5f6010, base=0x0, len=1
>         iovec[   2]=0x7fdd5c5f6020, base=0x1, len=16
>         ...
>
> Now we trace iovecs only when using IO_CMD_{PREADV,PWITEV}:
>
> [     0 sanlock(8397):] io_submit(140589225566208, 1, 0x7fdd5e6f9718)
>     iocb[   0]=0x7fdd48000b70, fd=19, opcode=0, offset=0, nbytes=1048576, buf=0x7fdd5c3f2000
> [     0 sanlock(8397):] io_submit(140589225566208, 1, 0x7fdd5e6f9718)
>     iocb[   0]=0x7fdd48000b70, fd=19, opcode=1, offset=512, nbytes=512, buf=0x7fdd4810a000
>
> Signed-off-by: Nir Soffer <nsoffer@redhat.com>
> ---
>  testsuite/systemtap.examples/io/traceaio.stp | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/testsuite/systemtap.examples/io/traceaio.stp b/testsuite/systemtap.examples/io/traceaio.stp
> index 126ea9c3c..903d65526 100755
> --- a/testsuite/systemtap.examples/io/traceaio.stp
> +++ b/testsuite/systemtap.examples/io/traceaio.stp
> @@ -8,6 +8,9 @@
>  # published by the Free Software Foundation.
>  #
>
> +@define IO_CMD_PREADV   %( 7 %)
> +@define IO_CMD_PWRITEV  %( 8 %)

Unfortunately this does not work. I tested this before adding these "constants".

This works:

global IO_CMD_PREADV = 7
global IO_CMD_PWRITEV = 8

Do we have a better way to handle this?

> +
>  probe begin {
>      println("Tracing started");
>  }
> @@ -27,12 +30,14 @@ probe syscall.io_submit
>              printf("    iocb[%4d]=%p, fd=%d, opcode=%d, offset=%d, nbytes=%d, buf=%p\n",
>                     i, iocbp, fd, opcode, offset, nbytes, buf)
>
> -            for (j = 0; j < nbytes; j++) {
> -                iovecp = &@cast(buf, "iovec", "kernel")[j]
> -                base = user_uint64(&@cast(iovecp, "iovec", "kernel")->iov_base)
> -                len = user_uint32(&@cast(iovecp, "iovec", "kernel")->iov_len)
> -                printf("        iovec[%4d]=%p, base=%p, len=%d\n",
> -                       j, iovecp, base, len)
> +            if (opcode == @IO_CMD_PREADV || opcode == @IO_CMD_PREADV) {
> +                for (j = 0; j < nbytes; j++) {
> +                    iovecp = &@cast(buf, "iovec", "kernel")[j]
> +                    base = user_uint64(&@cast(iovecp, "iovec", "kernel")->iov_base)
> +                    len = user_uint32(&@cast(iovecp, "iovec", "kernel")->iov_len)
> +                    printf("        iovec[%4d]=%p, base=%p, len=%d\n",
> +                           j, iovecp, base, len)
> +                }
>              }
>          }
>      }
> --
> 2.31.1
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix traceaio with IO_CMD_{PREAD,PWRITE}
  2021-09-23 22:21 ` Nir Soffer
@ 2021-09-23 23:00   ` Frank Ch. Eigler
  2021-09-29  9:14     ` Nir Soffer
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Ch. Eigler @ 2021-09-23 23:00 UTC (permalink / raw)
  To: Nir Soffer; +Cc: systemtap, David Teigland

Hi -

> This works:
> 
> global IO_CMD_PREADV = 7
> global IO_CMD_PWRITEV = 8
> 
> Do we have a better way to handle this?

Within a tapset snippet, code can use
   @const("IO_CMD_PREADV")
referring to an identifier in embedded-C scope.

If the IO_CMD_PREADV identifier were an enum value that shows up in
DWARF, then $IO_CMD_PREADV can resolve in recent versions of stap.

If none of the above, yeah, use the global gadget.

- FChE


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix traceaio with IO_CMD_{PREAD,PWRITE}
  2021-09-23 23:00   ` Frank Ch. Eigler
@ 2021-09-29  9:14     ` Nir Soffer
  0 siblings, 0 replies; 4+ messages in thread
From: Nir Soffer @ 2021-09-29  9:14 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: systemtap, David Teigland

On Fri, Sep 24, 2021 at 2:00 AM Frank Ch. Eigler <fche@redhat.com> wrote:
>
> Hi -
>
> > This works:
> >
> > global IO_CMD_PREADV = 7
> > global IO_CMD_PWRITEV = 8
> >
> > Do we have a better way to handle this?
>
> Within a tapset snippet, code can use
>    @const("IO_CMD_PREADV")
> referring to an identifier in embedded-C scope.

This works, bug require -g in stap script. I don't think it makes sense
to require Guru mode just to access an enum. It would be nice it this
could work without -g, since accessing constants seems to be a safe
operation.

> If the IO_CMD_PREADV identifier were an enum value that shows up in
> DWARF, then $IO_CMD_PREADV can resolve in recent versions of stap.

I could not find the enum in debuginfo files or in stap -L output, but maybe
I was not using the right tool for this.

In a test program using libaio, I cannot find the enum values in the symbols
so I guess this info is not available.

> If none of the above, yeah, use the global gadget.

I sent v2 using globals.

Nir


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-29  9:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 17:49 [PATCH] Fix traceaio with IO_CMD_{PREAD,PWRITE} Nir Soffer
2021-09-23 22:21 ` Nir Soffer
2021-09-23 23:00   ` Frank Ch. Eigler
2021-09-29  9:14     ` Nir Soffer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).