1. 30 7月, 2019 24 次提交
    • J
      perf evsel: Rename perf_evsel__delete() to evsel__delete() · 5eb2dd2a
      Jiri Olsa 提交于
      Remame perf_evsel__delete() to evsel__delete(), so we don't have a name
      clash when we add perf_evsel__delete() in libperf.
      
      Also renaming perf_evsel__delete_priv() to evsel__delete_priv().
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20190721112506.12306-11-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5eb2dd2a
    • J
      perf evlist: Rename perf_evlist__delete() to evlist__delete() · c12995a5
      Jiri Olsa 提交于
      Rename perf_evlist__delete() to evlist__delete(), so we don't have a
      name clash when we add perf_evlist__delete() in libperf.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20190721112506.12306-10-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c12995a5
    • J
      perf evlist: Rename perf_evlist__new() to evlist__new() · 0f98b11c
      Jiri Olsa 提交于
      Rename perf_evlist__new() to evlist__new(), so we don't have a name
      clash when we add perf_evlist__new() in libperf.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20190721112506.12306-9-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      0f98b11c
    • J
      perf evlist: Rename struct perf_evlist to struct evlist · 63503dba
      Jiri Olsa 提交于
      Rename struct perf_evlist to struct evlist, so we don't have a name
      clash when we add struct perf_evlist in libperf.
      
      Committer notes:
      
      Added fixes to build on arm64, from Jiri and from me
      (tools/perf/util/cs-etm.c)
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20190721112506.12306-6-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      63503dba
    • J
      perf evsel: Rename struct perf_evsel to struct evsel · 32dcd021
      Jiri Olsa 提交于
      Rename struct perf_evsel to struct evsel, so we don't have a name clash
      when we add struct perf_evsel in libperf.
      
      Committer notes:
      
      Added fixes for arm64, provided by Jiri.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20190721112506.12306-5-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      32dcd021
    • A
      perf trace: Add "sendfile64" alias to the "sendfile" syscall · e4b00e93
      Arnaldo Carvalho de Melo 提交于
      We were looking in tracefs for:
      
        /sys/kernel/debug/tracing/events/syscalls/sys_enter_sendfile/format when
      
      what is there is just
      
        /sys/kernel/debug/tracing/events/syscalls/sys_enter_sendfile/format
      
      Its the same id, 40 in x86_64, so just add an alias and let the existing
      logic take care of that.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-km2hmg7hru6u4pawi5fi903q@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e4b00e93
    • A
      perf trace: Reuse BPF augmenters from syscalls with similar args signature · ad4153f9
      Arnaldo Carvalho de Melo 提交于
      We have an augmenter for the "open" syscall, which has just one pointer,
      in the first argument, a "const char *", so any other syscall that has
      just one pointer and that is the first can reuse the "open" BPF
      augmenter program.
      
      Even more, syscalls that get two pointers with the first being a string
      can reuse "open"'s BPF augmenter till we have an augmenter that better
      matches that syscall with two pointers.
      
      With this the few augmenters we have, for open (first arg is a string),
      openat (2nd arg is a string), renameat (2nd and 4th are strings) can be
      reused by a lot of syscalls, ditto for "bind" reusing "connect" because
      both have the 2nd argument as a sockaddr and the 3rd as its len.
      
      Lets see how this makes the "bind" syscall reuse the "connect" BPF prog
      augmenter found in tools/perf/examples/bpf/augmented_raw_syscalls.c:
      
        # perf trace -e bind,connect systemctl restart sshd
        connect(3, { .family: PF_LOCAL, path: /run/systemd/private }, 23) = 0
        #
      
      Oh, it just connects to some daemon, so we better do it system wide and then
      stop/start sshd:
      
        # perf trace -e bind,connect
        systemctl/10124 connect(3, { .family: PF_LOCAL, path: /run/systemd/private }, 23) = 0
        sshd/10102 connect(7, { .family: PF_LOCAL, path: /dev/log }, 110) = 0
        systemctl/10126 connect(3, { .family: PF_LOCAL, path: /run/systemd/private }, 23) = 0
        systemd/10128  ... [continued]: connect())            = 0
        (sshd)/10128 connect(3, { .family: PF_LOCAL, path: /run/systemd/journal/stdout }, 30) ...
        sshd/10128 bind(3, { .family: PF_NETLINK }, 12)    = 0
        sshd/10128 connect(4, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        sshd/10128 connect(3, { .family: PF_INET6, port: 22, addr: :: }, 28) = 0
        sshd/10128 connect(3, { .family: PF_UNSPEC }, 16)  = 0
        sshd/10128 connect(3, { .family: PF_INET, port: 22, addr: 0.0.0.0 }, 16) = 0
        sshd/10128 connect(3, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        sshd/10128 connect(3, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        sshd/10128 connect(5, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        sshd/10128 connect(5, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        sshd/10128 bind(4, { .family: PF_INET, port: 22, addr: 0.0.0.0 }, 16) = 0
        sshd/10128 connect(6, { .family: PF_LOCAL, path: /dev/log }, 110) = 0
        sshd/10128 bind(6, { .family: PF_INET6, port: 22, addr: :: }, 28) = 0
        sshd/10128 connect(7, { .family: PF_LOCAL, path: /dev/log }, 110) = 0
        ^C#
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-zfley2ghs4nim1uq4nu6ed3l@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ad4153f9
    • A
      perf trace: Preallocate the syscall table · 30a910d7
      Arnaldo Carvalho de Melo 提交于
      We'll continue reading its details from tracefs as we need it, but
      preallocate the whole thing otherwise we may realloc and end up with
      pointers to the previous buffer.
      
      I.e. in an upcoming algorithm we'll look for syscalls that have function
      signatures that are similar to a given syscall to see if we can reuse
      its BPF augmenter, so we may be at syscall 42, having a 'struct syscall'
      pointing to that slot in trace->syscalls.table[] and try to read the
      slot for an yet unread syscall, which would realloc that table to read
      the info for syscall 43, say, which would trigger a realoc of
      trace->syscalls.table[], and then the pointer we had for syscall 42
      would be pointing to the previous block of memory. b00m.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-m3cjzzifibs13imafhkk77a0@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      30a910d7
    • A
      perf trace: Mark syscall ids that are not allocated to avoid unnecessary error messages · b8b1033f
      Arnaldo Carvalho de Melo 提交于
      There are holes in syscall tables with IDs not associated with any
      syscall, mark those when trying to read information for syscalls, which
      could happen when iterating thru all syscalls from 0 to the highest
      numbered syscall id.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-cku9mpcrcsqaiq0jepu86r68@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b8b1033f
    • A
      perf trace: Forward error codes when trying to read syscall info · 5d2bd889
      Arnaldo Carvalho de Melo 提交于
      We iterate thru the syscall table produced from the kernel syscall
      tables reading info, propagate the error and add to the debug message.
      
      This helps in fixing further bugs, such as failing to read the
      "sendfile" syscall info when it really should try the aliasm
      "sendfile64".
      
        Problems reading syscall 40: 2 (No such file or directory)(sendfile) information
      
        # grep sendfile /tmp/build/perf/arch/x86/include/generated/asm/syscalls_64.c
      	[40] = "sendfile",
        #
      
      I.e. in the tracefs format file for the syscall tracepoints we have it
      as sendfile64:
      
        # find /sys -type f -name format | grep sendfile
        /sys/kernel/debug/tracing/events/syscalls/sys_enter_sendfile64/format
        /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendfile64/format
        #
      
      But as "sendfile" in the file used to build the syscall table used in
      perf:
      
        $ grep sendfile arch/x86/entry/syscalls/syscall_64.tbl
        40	common	sendfile		__x64_sys_sendfile64
        $
      
      So we need to add, in followup patches, aliases in 'perf trace' syscall
      data structures to cope with thie.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-w3eluap63x9je0bb8o3t79tz@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5d2bd889
    • A
      perf trace beauty: Beautify bind's sockaddr arg · 247dd65b
      Arnaldo Carvalho de Melo 提交于
      By reusing the "connect" BPF collector.
      
      Testing it system wide and stopping/starting sshd:
      
        # perf trace -e bind
        LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        DNS Res~er #18/15132 bind(243, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #19/4833 bind(247, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #19/4833 bind(238, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #18/15132 bind(243, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #18/10327 bind(258, { .family: PF_NETLINK }, 12)  = 0
        :6507/6507 bind(24, { .family: PF_NETLINK }, 12)   = 0
        DNS Res~er #19/4833 bind(238, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #18/15132 bind(242, { .family: PF_NETLINK }, 12)  = 0
        sshd/6514 bind(3, { .family: PF_NETLINK }, 12)    = 0
        sshd/6514 bind(5, { .family: PF_INET, port: 22, addr: 0.0.0.0 }, 16) = 0
        sshd/6514 bind(7, { .family: PF_INET6, port: 22, addr: :: }, 28) = 0
        DNS Res~er #18/10327 bind(229, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #18/15132 bind(231, { .family: PF_NETLINK }, 12)  = 0
        DNS Res~er #19/4833 bind(229, { .family: PF_NETLINK }, 12)  = 0
        ^C#
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-m2hmxqrckxxw2ciki0tu889u@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      247dd65b
    • A
      perf trace beauty: Do not try to use the fd->pathname beautifier for bind/connect fd arg · ef969ca6
      Arnaldo Carvalho de Melo 提交于
      Doesn't make sense and also we now beautify the sockaddr, which provides
      enough info:
      
        # trace -e close,socket,connec* ssh www.bla.com
        <SNIP>
        close(5)                                = 0
        socket(PF_INET, SOCK_DGRAM|CLOEXEC|NONBLOCK, IPPROTO_IP) = 5
        connect(5, { .family: PF_INET, port: 53, addr: 192.168.44.1 }, 16) = 0
        close(5)                                = 0
        socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 5
        ^C#
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-h9drpb7ail808d2mh4n7tla4@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ef969ca6
    • A
      perf trace beauty: Disable fd->pathname when close() not enabled · 79d725cd
      Arnaldo Carvalho de Melo 提交于
      As we invalidate the fd->pathname table in the SCA_CLOSE_FD beautifier,
      if we don't have it we may end up keeping an fd->pathname association
      that then gets misprinted.
      
      The previous behaviour continues when the close() syscall is enabled,
      which may still be a a problem if we lose records (i.e. we may lose a
      'close' record and then get that fd reused by socket()) but then the
      tool will notify that records are being lost and the user will be warned
      that some of the heuristics will fall apart.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-b7t6h8sq9lebemvfy2zh3qq1@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      79d725cd
    • A
      perf trace beauty: Make connect's addrlen be printed as an int, not hex · 1d862752
      Arnaldo Carvalho de Melo 提交于
        # perf trace -e connec* ssh www.bla.com
        connect(3</var/lib/sss/mc/passwd>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(3</var/lib/sss/mc/passwd>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(4<socket:[16610959]>, { .family: PF_LOCAL, path: /var/lib/sss/pipes/nss }, 110) = 0
        connect(7, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(7, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(5, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        connect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_INET, port: 53, addr: 192.168.44.1 }, 16) = 0
        connect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_INET, port: 22, addr: 146.112.61.108 }, 16) = 0
        connect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_INET6, port: 22, addr: ::ffff:146.112.61.108 }, 28) = 0
        ^Cconnect(5</usr/lib64/libnss_mdns4_minimal.so.2>, { .family: PF_INET, port: 22, addr: 146.112.61.108 }, 16) = -1 (unknown) (INTERNAL ERROR: strerror_r(512, [buf], 128)=22)
        #
      
      Argh, the SCA_FD needs to invalidate its cache when close is done...
      
      It works if the 'close' syscall is not filtered out ;-\
      
        # perf trace -e close,connec* ssh www.bla.com
        close(3)                                = 0
        close(3</usr/lib64/libpcre2-8.so.0.8.0>) = 0
        close(3)                                = 0
        close(3</usr/lib64/libkrb5.so.3.3>)     = 0
        close(3</usr/lib64/libkrb5.so.3.3>)     = 0
        close(3)                                = 0
        close(3</usr/lib64/libk5crypto.so.3.1>) = 0
        close(3</usr/lib64/libk5crypto.so.3.1>) = 0
        close(3</usr/lib64/libcom_err.so.2.1>)  = 0
        close(3</usr/lib64/libcom_err.so.2.1>)  = 0
        close(3)                                = 0
        close(3</usr/lib64/libkrb5support.so.0.1>) = 0
        close(3</usr/lib64/libkrb5support.so.0.1>) = 0
        close(3</usr/lib64/libkeyutils.so.1.8>) = 0
        close(3</usr/lib64/libkeyutils.so.1.8>) = 0
        close(3)                                = 0
        close(3)                                = 0
        close(3)                                = 0
        close(3)                                = 0
        close(4)                                = 0
        close(3)                                = 0
        close(3)                                = 0
        connect(3</etc/nsswitch.conf>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        close(3</etc/nsswitch.conf>)            = 0
        connect(3</usr/lib64/libnss_sss.so.2>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 110) = -1 ENOENT (No such file or directory)
        close(3</usr/lib64/libnss_sss.so.2>)    = 0
        close(3</usr/lib64/libnss_sss.so.2>)    = 0
        close(3)                                = 0
        close(3)                                = 0
        connect(4<socket:[16616519]>, { .family: PF_LOCAL, path: /var/lib/sss/pipes/nss }, 110) = 0
        ^C
        #
      
      Will disable this beautifier when 'close' is filtered out...
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-ekuiciyx4znchvy95c8p1yyi@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1d862752
    • A
      perf trace: Look for default name for entries in the syscalls prog array · 8b8044e5
      Arnaldo Carvalho de Melo 提交于
      I.e. just look for "!syscalls:sys_enter_" or "exit_" plus the syscall
      name, that way we need just to add entries to the
      augmented_raw_syscalls.c BPF source to add handlers.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-6xavwddruokp6ohs7tf4qilb@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8b8044e5
    • A
      perf augmented_raw_syscalls: Support copying two string syscall args · 8d5da264
      Arnaldo Carvalho de Melo 提交于
      Starting with the renameat and renameat2 syscall, that both receive as
      second and fourth parameters a pathname:
      
        # perf trace -e rename* mv one ANOTHER
        LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        mv: cannot stat 'one': No such file or directory
        renameat2(AT_FDCWD, "one", AT_FDCWD, "ANOTHER", RENAME_NOREPLACE) = -1 ENOENT (No such file or directory)
        #
      
      Since the per CPU scratch buffer map has space for two maximum sized
      pathnames, the verifier is satisfied that there will be no overrun.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-x2uboyg5kx2wqeru288209b6@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8d5da264
    • A
      perf augmented_raw_syscalls: Add handler for "openat" · 236dd583
      Arnaldo Carvalho de Melo 提交于
      I.e. for a syscall that has its second argument being a string, its
      difficult these days to find 'open' being used in the wild :-)
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-yf3kbzirqrukd3fb2sp5qx4p@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      236dd583
    • A
      perf trace: Handle raw_syscalls:sys_enter just like the BPF_OUTPUT augmented event · b119970a
      Arnaldo Carvalho de Melo 提交于
      So, we use a PERF_COUNT_SW_BPF_OUTPUT to output the augmented sys_enter
      payload, i.e. to output more than just the raw syscall args, and if
      something goes wrong when handling an unfiltered syscall, we bail out
      and just return 1 in the bpf program associated with
      raw_syscalls:sys_enter, meaning, don't filter that tracepoint, in which
      case what will appear in the perf ring buffer isn't the BPF_OUTPUT
      event, but the original raw_syscalls:sys_enter event with its normal
      payload.
      
      Now that we're switching to using a bpf_tail_call +
      BPF_MAP_TYPE_PROG_ARRAY we're going to use this in the common case, so a
      bug where raw_syscalls:sys_enter wasn't being handled by
      trace__sys_enter() surfaced and for  that case, instead of using the
      strace-like augmenter (trace__sys_enter()), we continued to use the
      normal generic tracepoint handler:
      
        (gdb) p evsel
        $2 = (struct perf_evsel *) 0xc03e40
        (gdb) p evsel->name
        $3 = 0xbc56c0 "raw_syscalls:sys_enter"
        (gdb) p ((struct perf_evsel *) 0xc03e40)->name
        $4 = 0xbc56c0 "raw_syscalls:sys_enter"
        (gdb) p ((struct perf_evsel *) 0xc03e40)->handler
        $5 = (void *) 0x495eb3 <trace__event_handler>
      
      This resulted in this:
      
           0.027 raw_syscalls:sys_enter:NR 12 (0, 7fcfcac64c9b, 4d, 7fcfcac64c9b, 7fcfcac6ce00, 19)
           ... [continued]: brk())                = 0x563b88677000
      
      I.e. only the sys_exit tracepoint was being properly handled, but since
      the sys_enter went to the generic trace__event_handler() we printed it
      using libtraceevent's formatter instead of 'perf trace's strace-like
      one.
      
      Fix it by setting trace__sys_enter() as the handler for
      raw_syscalls:sys_enter and setup the tp_field tracepoint field
      accessors.
      
      Now, to test it we just make raw_syscalls:sys_enter return 1 right after
      checking if the pid is filtered, making it not use
      bpf_perf_output_event() but rather ask for the tracepoint not to be
      filtered and the result is the expected one:
      
        brk(NULL)                               = 0x556f42d6e000
      
      I.e. raw_syscalls:sys_enter returns 1, gets handled by
      trace__sys_enter() and gets it combined with the raw_syscalls:sys_exit
      in a strace-like way.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-0mkocgk31nmy0odknegcby4z@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b119970a
    • A
      perf trace: Put the per-syscall entry/exit prog_array BPF map infrastructure in place · 3803a229
      Arnaldo Carvalho de Melo 提交于
      I.e. look for "syscalls_sys_enter" and "syscalls_sys_exit" BPF maps of
      type PROG_ARRAY and populate it with the handlers as specified per
      syscall, for now only 'open' is wiring it to something, in time all
      syscalls that need to copy arguments entering a syscall or returning
      from one will set these to the right handlers, reusing when possible
      pre-existing ones.
      
      Next step is to use bpf_tail_call() into that.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-t0p4u43i9vbpzs1xtowna3gb@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      3803a229
    • A
      perf trace: Allow specifying the bpf prog to augment specific syscalls · 6ff8fff4
      Arnaldo Carvalho de Melo 提交于
      This is a step in the direction of being able to use a
      BPF_MAP_TYPE_PROG_ARRAY to handle syscalls that need to copy pointer
      payloads in addition to the raw tracepoint syscall args.
      
      There is a first example in
      tools/perf/examples/bpf/augmented_raw_syscalls.c for the 'open' syscall.
      
      Next step is to introduce the prog array map and use this 'open'
      augmenter, then use that augmenter in other syscalls that also only copy
      the first arg as a string, and then show how to use with a syscall that
      reads more than one filename, like 'rename', etc.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-pys4v57x5qqrybb4cery2mc8@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6ff8fff4
    • A
      perf trace: Add BPF handler for unaugmented syscalls · 5834da7f
      Arnaldo Carvalho de Melo 提交于
      Will be used to assign to syscalls that don't need augmentation, i.e.
      those with just integer args.
      
      All syscalls will be in a BPF_MAP_TYPE_PROG_ARRAY, and the
      bpf_tail_call() keyed by the syscall id will either find nothing in
      place, which means the syscall is being filtered, or a function that
      will either add things like filenames to the ring buffer, right after
      the raw syscall args, or be this unaugmented handler that will just
      return 1, meaning don't filter the original
      raw_syscalls:sys_{enter,exit} tracepoint.
      
      For now it is not really being used, this is just leg work to break the
      patch into smaller pieces.
      
      It introduces a trace__find_bpf_program_by_title() helper that in turn
      uses libbpf's bpf_object__find_program_by_title() on the BPF object with
      the __augmented_syscalls__ map. "title" is how libbpf calls the SEC()
      argument for functions, i.e. the ELF section that follows a convention
      to specify what BPF program (a function with this SEC() marking) should
      be connected to which tracepoint, kprobes, etc.
      
      In perf anything that is of the form SEC("sys:event_name") will be
      connected to that tracepoint by perf's BPF loader.
      
      In this case its something that will be bpf_tail_call()ed from either
      the "raw_syscalls:sys_enter" or "raw_syscall:sys_exit" tracepoints, so
      its named "!raw_syscalls:unaugmented" to convey that idea, i.e. its not
      going to be directly attached to a tracepoint, thus it starts with a
      "!".
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-meucpjx2u0slpkayx56lxqq6@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5834da7f
    • A
      perf trace: Order -e syscalls table · 83e69b92
      Arnaldo Carvalho de Melo 提交于
      The ev_qualifier is an array with the syscall ids passed via -e on the
      command line, sort it as we'll search it when setting up the
      BPF_MAP_TYPE_PROG_ARRAY.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-c8hprylp3ai6e0z9burn2r3s@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      83e69b92
    • A
      perf trace: Look up maps just on the __augmented_syscalls__ BPF object · 5ca0b7f5
      Arnaldo Carvalho de Melo 提交于
      We can conceivably have multiple BPF object files for other purposes, so
      better look just on the BPF object containing the __augmented_syscalls__
      map for all things augmented_syscalls related.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-3jt8knkuae9lt705r1lns202@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5ca0b7f5
    • A
      perf trace: Add pointer to BPF object containing __augmented_syscalls__ · c8c80570
      Arnaldo Carvalho de Melo 提交于
      So that we can use it when looking for other components of that object
      file, such as other programs to add to the BPF_MAP_TYPE_PROG_ARRAY and
      use with bpf_tail_call().
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-1ibmz7ouv6llqxajy7m8igtd@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c8c80570
  2. 10 7月, 2019 1 次提交
    • A
      perf trace: Auto bump rlimit(MEMLOCK) for eBPF maps sake · c3e78a34
      Arnaldo Carvalho de Melo 提交于
      Circa v5.2 this started to fail:
      
        # perf trace -e /wb/augmented_raw_syscalls.o
        event syntax error: '/wb/augmented_raw_syscalls.o'
                             \___ Operation not permitted
      
        (add -v to see detail)
        Run 'perf list' for a list of valid events
      
         Usage: perf trace [<options>] [<command>]
            or: perf trace [<options>] -- <command> [<options>]
            or: perf trace record [<options>] [<command>]
            or: perf trace record [<options>] -- <command> [<options>]
      
            -e, --event <event>   event/syscall selector. use 'perf list' to list available events
        #
      
      In verbose mode we some -EPERM when creating a BPF map:
      
        # perf trace -v -e /wb/augmented_raw_syscalls.o
        <SNIP>
        libbpf: failed to create map (name: '__augmented_syscalls__'): Operation not permitted
        libbpf: failed to load object '/wb/augmented_raw_syscalls.o'
        bpf: load objects failed: err=-1: (Operation not permitted)
        event syntax error: '/wb/augmented_raw_syscalls.o'
                             \___ Operation not permitted
      
        (add -v to see detail)
        Run 'perf list' for a list of valid events
      
         Usage: perf trace [<options>] [<command>]
            or: perf trace [<options>] -- <command> [<options>]
            or: perf trace record [<options>] [<command>]
            or: perf trace record [<options>] -- <command> [<options>]
      
            -e, --event <event>   event/syscall selector. use 'perf list' to list available events
        #
      
      If we bumped 'ulimit -l 128' to get it from the 64k default to double that, it
      worked, so use the recently added rlimit__bump_memlock() helper:
      
        # perf trace -e /wb/augmented_raw_syscalls.o -e open*,*sleep sleep 1
             0.000 ( 0.007 ms): sleep/28042 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC) = 3
             0.022 ( 0.004 ms): sleep/28042 openat(dfd: CWD, filename: "/lib64/libc.so.6", flags: RDONLY|CLOEXEC) = 3
             0.201 ( 0.007 ms): sleep/28042 openat(dfd: CWD, filename: "", flags: RDONLY|CLOEXEC)                 = 3
             0.241 (1000.421 ms): sleep/28042 nanosleep(rqtp: 0x7ffd6c3e6ed0)                                       = 0
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-j6f2ioa6hj9dinzpjvlhcjoc@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      c3e78a34
  3. 09 7月, 2019 2 次提交
    • A
      tools lib: Adopt zalloc()/zfree() from tools/perf · 7f7c536f
      Arnaldo Carvalho de Melo 提交于
      Eroding a bit more the tools/perf/util/util.h hodpodge header.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-natazosyn9rwjka25tvcnyi0@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7f7c536f
    • L
      perf trace: Fix potential NULL pointer dereference found by the smatch tool · 7a6d49dc
      Leo Yan 提交于
      Based on the following report from Smatch, fix the potential NULL
      pointer dereference check.
      
        tools/perf/builtin-trace.c:1044
        thread_trace__new() error: we previously assumed 'ttrace' could be
        null (see line 1041).
      
        tools/perf/builtin-trace.c
        1037 static struct thread_trace *thread_trace__new(void)
        1038 {
        1039         struct thread_trace *ttrace =  zalloc(sizeof(struct thread_trace));
        1040
        1041         if (ttrace)
        1042                 ttrace->files.max = -1;
        1043
        1044         ttrace->syscall_stats = intlist__new(NULL);
                     ^^^^^^^^
        1045
        1046         return ttrace;
        1047 }
      Signed-off-by: NLeo Yan <leo.yan@linaro.org>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
      Cc: Alexios Zavras <alexios.zavras@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Changbin Du <changbin.du@intel.com>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Eric Saint-Etienne <eric.saint.etienne@oracle.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Link: http://lkml.kernel.org/r/20190702103420.27540-6-leo.yan@linaro.org
      [ Just made it look like other tools/perf constructors, same end result ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7a6d49dc
  4. 26 6月, 2019 1 次提交
    • A
      tools perf: Move from sane_ctype.h obtained from git to the Linux's original · 3052ba56
      Arnaldo Carvalho de Melo 提交于
      We got the sane_ctype.h headers from git and kept using it so far, but
      since that code originally came from the kernel sources to the git
      sources, perhaps its better to just use the one in the kernel, so that
      we can leverage tools/perf/check_headers.sh to be notified when our copy
      gets out of sync, i.e. when fixes or goodies are added to the code we've
      copied.
      
      This will help with things like tools/lib/string.c where we want to have
      more things in common with the kernel, such as strim(), skip_spaces(),
      etc so as to go on removing the things that we have in tools/perf/util/
      and instead using the code in the kernel, indirectly and removing things
      like EXPORT_SYMBOL(), etc, getting notified when fixes and improvements
      are made to the original code.
      
      Hopefully this also should help with reducing the difference of code
      hosted in tools/ to the one in the kernel proper.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-7k9868l713wqtgo01xxygn12@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      3052ba56
  5. 18 6月, 2019 3 次提交
    • A
      perf trace: Fixup pointer arithmetic when consuming augmented syscall args · 016f327c
      Arnaldo Carvalho de Melo 提交于
      We can't just add the consumed bytes to the arg->augmented.args member,
      as it is not void *, so it will access (consumed * sizeof(struct augmented_arg))
      in the next augmented arg, totally wrong, cast the member to void pointe
      before adding the number of bytes consumed, duh.
      
      With this and hardcoding handling the 'renameat' and 'renameat2'
      syscalls in the tools/perf/examples/bpf/augmented_raw_syscalls.c eBPF
      proggie, we get:
      
      	mv/24388 renameat2(AT_FDCWD, "/tmp/build/perf/util/.bpf-event.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.bpf-event.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24394 renameat2(AT_FDCWD, "/tmp/build/perf/util/.perf-hooks.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.perf-hooks.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24398 renameat2(AT_FDCWD, "/tmp/build/perf/util/.pmu-bison.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.pmu-bison.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24401 renameat2(AT_FDCWD, "/tmp/build/perf/util/.expr-bison.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.expr-bison.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24406 renameat2(AT_FDCWD, "/tmp/build/perf/util/.pmu.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.pmu.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24407 renameat2(AT_FDCWD, "/tmp/build/perf/util/.pmu-flex.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.pmu-flex.o.cmd", RENAME_NOREPLACE) = 0
      	mv/24416 renameat2(AT_FDCWD, "/tmp/build/perf/util/.parse-events-flex.o.tmp", AT_FDCWD, "/tmp/build/perf/util/.parse-events-flex.o.cmd", RENAME_NOREPLACE) = 0
      
      I.e. it works with two string args in the same syscall.
      
      Now back to taming the verifier...
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Fixes: 8195168e ("perf trace: Consume the augmented_raw_syscalls payload")
      Link: https://lkml.kernel.org/n/tip-n1w59lpxks6m1le7fpo6rmyw@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      016f327c
    • A
      perf trace: Streamline validation of select syscall names list · 99f26f85
      Arnaldo Carvalho de Melo 提交于
      Rename the 'i' variable to 'nr_used' and use set 'nr_allocated' since
      the start of this function, leaving the final assignment of the longer
      named trace->ev_qualifier_ids.nr state to 'nr_used' at the end of the
      function.
      
      No change in behaviour intended.
      
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
      Link: https://lkml.kernel.org/n/tip-kpgyn8xjdjgt0timrrnniquv@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      99f26f85
    • A
      perf trace: Fix exclusion of not available syscall names from selector list · a4066d64
      Arnaldo Carvalho de Melo 提交于
      We were just skipping the syscalls not available in a particular
      architecture without reflecting this in the number of entries in the
      ev_qualifier_ids.nr variable, fix it.
      
      This was done with the most minimalistic way, reusing the index variable
      'i', a followup patch will further clean this by making 'i' renamed to
      'nr_used' and using 'nr_allocated' in a few more places.
      Reported-by: NLeo Yan <leo.yan@linaro.org>
      Tested-by: NLeo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
      Fixes: 04c41bcb ("perf trace: Skip unknown syscalls when expanding strace like syscall groups")
      Link: https://lkml.kernel.org/r/20190613181514.GC1402@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a4066d64
  6. 11 6月, 2019 2 次提交
    • A
      perf trace: Skip unknown syscalls when expanding strace like syscall groups · 04c41bcb
      Arnaldo Carvalho de Melo 提交于
      We have $INSTALL_DIR/share/perf-core/strace/groups/string files with
      syscalls that should be selected when 'string' is used, meaning, in this
      case, syscalls that receive as one of its arguments a string, like a
      pathname.
      
      But those were first selected and tested on x86_64, and end up failing
      in architectures where some of those syscalls are not available, like
      the 'access' syscall on arm64, which makes using 'perf trace -e string'
      in such archs to fail.
      
      Since this the routine doing the validation is used only when reading
      such files, do not fail when some syscall is not found in the
      syscalltbl, instead just use pr_debug() to register that in case people
      are suspicious of problems.
      
      Now using 'perf trace -e string' should work on arm64, selecting only
      the syscalls that have a string and are available on that architecture.
      Reported-by: NLeo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
      Cc: Yonghong Song <yhs@fb.com>
      Link: https://lkml.kernel.org/r/20190610184754.GU21245@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      04c41bcb
    • L
      perf trace: Exit when failing to build eBPF program · 012749ca
      Leo Yan 提交于
      On my Juno board with ARM64 CPUs, perf trace command reports the eBPF
      program building failure but the command will not exit and continue to
      run.  If we define an eBPF event in config file, the event will be
      parsed with below flow:
      
        perf_config()
          `> trace__config()
               `> parse_events_option()
                    `> parse_events__scanner()
                         `-> parse_events_parse()
                               `> parse_events_load_bpf()
                                    `> llvm__compile_bpf()
      
      Though the low level functions return back error values when detect eBPF
      building failure, but parse_events_option() returns 1 for this case and
      trace__config() passes 1 to perf_config(); perf_config() doesn't treat
      the returned value 1 as failure and it continues to parse other
      configurations.  Thus the perf command continues to run even without
      enabling eBPF event successfully.
      
      This patch changes error handling in trace__config(), when it detects
      failure it will return -1 rather than directly pass error value (1);
      finally, perf_config() will directly bail out and perf will exit for
      this case.
      
      Committer notes:
      
      Simplified the patch to just check directly the return of
      parse_events_option() and it it is non-zero, change err from its initial
      zero value to -1.
      Signed-off-by: NLeo Yan <leo.yan@linaro.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
      Cc: Yonghong Song <yhs@fb.com>
      Fixes: ac96287c ("perf trace: Allow specifying a set of events to add in perfconfig")
      Link: https://lkml.kernel.org/n/tip-x4i63f5kscykfok0hqim3zma@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      012749ca
  7. 05 6月, 2019 4 次提交
  8. 29 5月, 2019 3 次提交
    • A
      perf trace: Beautify 'sync_file_range' arguments · a9a187a7
      Arnaldo Carvalho de Melo 提交于
      Use existing beautifiers for the first arg, fd, assigned using the
      heuristic that looks for syscall arg names and associates SCA_FD with
      'fd' named argumes, and wire up the recently introduced sync_file_range
      flags table generator.
      
      Now it should be possible to just use:
      
         perf trace -e sync_file_range
      
      As root and see all sync_file_range syscalls with its args beautified.
      
        Doing a syscall strace like session looking for this syscall, then run
        postgresql's initdb command:
      
        # perf trace -e sync_file_range
        <SNIP>
        initdb/1332 sync_file_range(6</var/lib/pgsql/data/global/1260_fsm>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(6</var/lib/pgsql/data/global/1260_fsm>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(7</var/lib/pgsql/data/base/1/2682>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(6</var/lib/pgsql/data/global/1260_fsm>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(7</var/lib/pgsql/data/base/1/2682>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(6</var/lib/pgsql/data/global/1260_fsm>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(5</var/lib/pgsql/data/global>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(4</var/lib/pgsql/data>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        initdb/1332 sync_file_range(4</var/lib/pgsql/data>, 0, 0, SYNC_FILE_RANGE_WRITE) = 0
        ^C
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Amir Goldstein <amir73il@gmail.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-8tqy34xhpg8gwnaiv74xy93w@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a9a187a7
    • A
      perf trace: Beautify 'fsmount' arguments · f6af0956
      Arnaldo Carvalho de Melo 提交于
      Use existing beautifiers for the first arg, fd, assigned using the
      heuristic that looks for syscall arg names and associates SCA_FD with
      'fd' named argumes, and wire up the recently introduced fsmount
      attr_flags table generator.
      
      Now it should be possible to just use:
      
         perf trace -e fsmount
      
      As root and see all fsmount syscalls with its args beautified.
      
        # cat sys_fsmount.c
        #define _GNU_SOURCE        /* See feature_test_macros(7) */
        #include <unistd.h>
        #include <sys/syscall.h>   /* For SYS_xxx definitions */
      
        #define __NR_fsmount 432
      
        #define MOUNT_ATTR_RDONLY	 0x00000001 /* Mount read-only */
        #define MOUNT_ATTR_NOSUID	 0x00000002 /* Ignore suid and sgid bits */
        #define MOUNT_ATTR_NODEV	 0x00000004 /* Disallow access to device special files */
        #define MOUNT_ATTR_NOEXEC	 0x00000008 /* Disallow program execution */
        #define MOUNT_ATTR__ATIME	 0x00000070 /* Setting on how atime should be updated */
        #define MOUNT_ATTR_RELATIME	 0x00000000 /* - Update atime relative to mtime/ctime. */
        #define MOUNT_ATTR_NOATIME	 0x00000010 /* - Do not update access times. */
        #define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
        #define MOUNT_ATTR_NODIRATIME	 0x00000080 /* Do not update directory access times */
      
        static inline int sys_fsmount(int fs_fd, int flags, int attr_flags)
        {
        	syscall(__NR_fsmount, fs_fd, flags, attr_flags);
        }
      
        int main(int argc, char *argv[])
        {
        	int attr_flags = 0, fs_fd = 0;
      
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	attr_flags |= MOUNT_ATTR_RDONLY;
        	sys_fsmount(fs_fd++, 1, attr_flags);
        	attr_flags |= MOUNT_ATTR_NOSUID;
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	attr_flags |= MOUNT_ATTR_NODEV;
        	sys_fsmount(fs_fd++, 1, attr_flags);
        	attr_flags |= MOUNT_ATTR_NOEXEC;
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	attr_flags |= MOUNT_ATTR_NOATIME;
        	sys_fsmount(fs_fd++, 1, attr_flags);
        	attr_flags |= MOUNT_ATTR_STRICTATIME;
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	attr_flags |= MOUNT_ATTR_NODIRATIME;
        	sys_fsmount(fs_fd++, 0, attr_flags);
        	return 0;
        }
        #
        # perf trace -e fsmount ./sys_fsmount
        fsmount(0, 0, MOUNT_ATTR_RELATIME)      = -1 EINVAL (Invalid argument)
        fsmount(1, FSMOUNT_CLOEXEC, MOUNT_ATTR_RDONLY|MOUNT_ATTR_RELATIME) = -1 EINVAL (Invalid argument)
        fsmount(2, 0, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_RELATIME) = -1 EINVAL (Invalid argument)
        fsmount(3, FSMOUNT_CLOEXEC, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_RELATIME) = -1 EBADF (Bad file descriptor)
        fsmount(4, 0, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_RELATIME) = -1 EBADF (Bad file descriptor)
        fsmount(5, FSMOUNT_CLOEXEC, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME) = -1 EBADF (Bad file descriptor)
        fsmount(6, 0, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME|MOUNT_ATTR_STRICTATIME) = -1 EINVAL (Invalid argument)
        fsmount(7, 0, MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME|MOUNT_ATTR_STRICTATIME|MOUNT_ATTR_NODIRATIME) = -1 EINVAL (Invalid argument)
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-w71uge0sfo6ns9uclhwtthca@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f6af0956
    • A
      perf trace: Introduce syscall_arg__scnprintf_strarray_flags · f5b91dbb
      Arnaldo Carvalho de Melo 提交于
      So that one can just define a strarray and process it as a set of flags,
      similar to syscall_arg__scnprintf_strarray() with plain arrays.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-nnt25wkpkow2w0yefhi6sb7q@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f5b91dbb