20 Apr, 2017

2 commits

  • Removing it from util.h, part of an effort to disentangle the includes
    hell, that makes changes to util.h or something included by it to cause
    a complete rebuild of the tools.

    Cc: Adrian Hunter
    Cc: David Ahern
    Cc: Jiri Olsa
    Cc: Namhyung Kim
    Cc: Wang Nan
    Link: http://lkml.kernel.org/n/tip-ztrjy52q1rqcchuy3rubfgt2@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     
  • Moving them from util.h, where they don't belong. Since libc already
    have string.h, name it slightly differently, as string2.h.

    Cc: Adrian Hunter
    Cc: David Ahern
    Cc: Jiri Olsa
    Cc: Namhyung Kim
    Cc: Wang Nan
    Link: http://lkml.kernel.org/n/tip-eh3vz5sqxsrdd8lodoro4jrw@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

04 Mar, 2017

1 commit

  • The refcount_t type and corresponding API should be used instead of
    atomic_t when the variable is used as a reference counter.

    This allows to avoid accidental refcounter overflows that might lead to
    use-after-free situations.

    Signed-off-by: Elena Reshetova
    Signed-off-by: David Windsor
    Signed-off-by: Hans Liljestrand
    Signed-off-by: Kees Kook
    Tested-by: Arnaldo Carvalho de Melo
    Cc: Alexander Shishkin
    Cc: Andrew Morton
    Cc: David Windsor
    Cc: Greg Kroah-Hartman
    Cc: Hans Liljestrand
    Cc: Jiri Olsa
    Cc: Kees Kook
    Cc: Mark Rutland
    Cc: Matija Glavinic Pecotic
    Cc: Peter Zijlstra
    Cc: alsa-devel@alsa-project.org
    Link: http://lkml.kernel.org/r/1487691303-31858-10-git-send-email-elena.reshetova@intel.com
    [ Did missing tests/thread-map.c conversion ]
    Signed-off-by: Arnaldo Carvalho de Melo

    Elena Reshetova
     

09 Feb, 2017

1 commit

  • The size of dirent->dt_name is NAME_MAX + 1, but the size for the 'path'
    buffer is hard coded at 256, which may truncate it because we also
    prepend "/proc/", so that all that into account and thank gcc 7 for this
    warning:

    /git/linux/tools/perf/util/thread_map.c: In function 'thread_map__new_by_uid':
    /git/linux/tools/perf/util/thread_map.c:119:39: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 250 [-Werror=format-truncation=]
    snprintf(path, sizeof(path), "/proc/%s", dirent->d_name);
    ^~
    In file included from /usr/include/stdio.h:939:0,
    from /git/linux/tools/perf/util/thread_map.c:5:
    /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 7 and 262 bytes into a destination of size 256
    return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    __bos (__s), __fmt, __va_arg_pack ());
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Cc: Adrian Hunter
    Cc: David Ahern
    Cc: Jiri Olsa
    Cc: Namhyung Kim
    Cc: Wang Nan
    Link: http://lkml.kernel.org/n/tip-csy0r8zrvz5efccgd4k12c82@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

16 Dec, 2016

1 commit

  • Add thread_map__remove function to remove thread from thread map.

    Add automated test also.

    Committer notes:

    Testing it:

    # perf test "Remove thread map"
    39: Remove thread map : Ok
    # perf test -v "Remove thread map"
    39: Remove thread map :
    --- start ---
    test child forked, pid 4483
    2 threads: 4482, 4483
    1 thread: 4483
    0 thread:
    test child finished with 0
    ---- end ----
    Remove thread map: Ok
    #

    Signed-off-by: Jiri Olsa
    Tested-by: Arnaldo Carvalho de Melo
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Link: http://lkml.kernel.org/r/1481538943-21874-4-git-send-email-jolsa@kernel.org
    [ Added stdlib.h, to get the free() declaration ]
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     

23 Jun, 2016

1 commit


13 Apr, 2016

2 commits

  • It will be used in following patch.

    Signed-off-by: Jiri Olsa
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Link: http://lkml.kernel.org/r/1460467771-26532-6-git-send-email-jolsa@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     
  • Adding thread_map__has() to return bool of pid presence in threads map.

    Signed-off-by: Jiri Olsa
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Link: http://lkml.kernel.org/r/1460467771-26532-2-git-send-email-jolsa@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     

08 Apr, 2016

1 commit

  • The readdir() function is thread safe as long as just one thread uses a
    DIR, which is the case in thread_map, so, to avoid breaking the build
    with glibc-2.23.90 (upcoming 2.24), use it instead of readdir_r().

    See: http://man7.org/linux/man-pages/man3/readdir.3.html

    "However, in modern implementations (including the glibc implementation),
    concurrent calls to readdir() that specify different directory streams
    are thread-safe. In cases where multiple threads must read from the
    same directory stream, using readdir() with external synchronization is
    still preferable to the use of the deprecated readdir_r(3) function."

    Noticed while building on a Fedora Rawhide docker container.

    Cc: Adrian Hunter
    Cc: David Ahern
    Cc: Jiri Olsa
    Cc: Namhyung Kim
    Cc: Wang Nan
    Link: http://lkml.kernel.org/n/tip-del8h2a0f40z75j4r42l96l0@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

18 Dec, 2015

1 commit

  • Introducing the thread_map__new_event function to create a struct
    thread_map object from a thread_map event.

    Signed-off-by: Jiri Olsa
    Tested-by: Kan Liang
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Link: http://lkml.kernel.org/r/1445784728-21732-6-git-send-email-jolsa@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     

11 Dec, 2015

1 commit


21 Jul, 2015

1 commit

  • …/acme/linux into perf/core

    Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

    New features:

    - Allow filtering out of perf's PID via 'perf record --exclude-perf'. (Wang Nan)

    - 'perf trace' now supports syscall groups, like strace, i.e:

    $ trace -e file touch file

    Will expand 'file' into multiple, file related, syscalls. More work needed to
    add extra groups for other syscall groups, and also to complement what was
    added for the 'file' group, included as a proof of concept. (Arnaldo Carvalho de Melo)

    - Add lock_pi stresser to 'perf bench futex', to test the kernel code
    related to FUTEX_(UN)LOCK_PI. (Davidlohr Bueso)

    User visible fixes:

    - Apply --filter to all events in a glob matching, not just the last one. (Wang Nan)

    Documentation changes:

    - Document setting '-e pmu/period=N/' in the 'perf record' man page. (Kan Liang)

    Infrastructure changes:

    - 'perf probe' code simplifications and movements to separate files. (Masami Hiramatsu)

    - Fix makefile generation under 'dash'. (Sergei Trofimovich)

    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>

    Ingo Molnar
     

20 Jul, 2015

1 commit

  • So that we can pass more info to strlist__new() without having to change
    its function signature, just adding entries to the strlist_config struct
    with sensible defaults for when those fields are not specified.

    Cc: Adrian Hunter
    Cc: Borislav Petkov
    Cc: David Ahern
    Cc: Frederic Weisbecker
    Cc: Jiri Olsa
    Cc: Namhyung Kim
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/n/tip-5uaaler4931i0s9sedxjquhq@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

09 Jul, 2015

1 commit

  • When we started adding extra stuff per array entry, growing the size of
    those entries to more than sizeof(pid_t), we had to convert those sizeof
    operations to the more robust sizeof(map->map[0]) idiom, that is future
    proof, i.e. if/when we add more stuff to those entries, that expression
    will produce the new per-entry size.

    And besides that, we need to zero out those extra fields, that sometimes
    may not get filled, like when we couldn't care less about the comms,
    since we don't need those, but since we will try freeing it at
    thread_map__delete(), we better fix it.

    That is why a thread_map__realloc() was provided.

    But that method wasn't used in thread_map__new_by_uid(), fix it.

    Reported-by: Ingo Molnar
    Fixes: 792402fd5c0a ("perf thrad_map: Add comm string into array")
    Fixes: 9d7e8c3a96e5 ("perf tools: Add thread_map__(alloc|realloc) helpers")
    Cc: Adrian Hunter
    Cc: Borislav Petkov
    Cc: David Ahern
    Cc: Frederic Weisbecker
    Cc: Jiri Olsa
    Cc: Namhyung Kim
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/n/tip-6a0swlm6m8lnu3wpjv284hkb@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

26 Jun, 2015

4 commits

  • Adding support to hold comm name together with pids in 'struct
    thread_map'. It will be useful for --per-thread option to display task
    pid together with task name.

    Adding thread_map__read_comms function that reads/set
    comm string for the 'struct thread_map'.

    Getting the task name from /proc/$pid/comm.

    Signed-off-by: Jiri Olsa
    Cc: Adrian Hunter
    Cc: Andi Kleen
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/r/1435310967-14570-3-git-send-email-jolsa@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     
  • We need to reset newly allocated 'struct thread_map_data' entries,
    because we will introduce new comm memeber, which will get set later or
    not at all.

    Signed-off-by: Jiri Olsa
    Cc: Adrian Hunter
    Cc: Andi Kleen
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/r/1435310967-14570-2-git-send-email-jolsa@kernel.org
    [ Use sizeof(map->map[0]) to be independent of the array entry type ]
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     
  • Adding reference counting for thread_map object, so it could be easily
    shared among other objects.

    Using thread_map__put instead thread_map__delete and making
    thread_map__delete static.

    Signed-off-by: Jiri Olsa
    Cc: Adrian Hunter
    Cc: Andi Kleen
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/r/1435012588-9007-5-git-send-email-jolsa@kernel.org
    [ Adjustments to move it ahead of the "comm" patches ]
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     
  • Signed-off-by: Jiri Olsa
    Cc: Adrian Hunter
    Cc: Andi Kleen
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/r/20150625174840.GH3253@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

24 Jun, 2015

1 commit

  • Instead provide a method to set the array entries, and another to access
    the contents.

    Signed-off-by: Jiri Olsa
    Cc: Adrian Hunter
    Cc: Andi Kleen
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/r/1435012588-9007-2-git-send-email-jolsa@kernel.org
    [ Split providing the set/get accessors from transforming the entries structs ]
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     

16 Jun, 2015

1 commit

  • In order to have 'struct thread_map' allocation on single place and can
    change it easily in following patch.

    Using alloc|realloc for static helpers, because thread_map__new is
    already used in public interface.

    Signed-off-by: Jiri Olsa
    Cc: Adrian Hunter
    Cc: Andi Kleen
    Cc: David Ahern
    Cc: Namhyung Kim
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/r/1434269985-521-3-git-send-email-jolsa@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Jiri Olsa
     

15 Oct, 2014

1 commit

  • Create a dummy thread_map, one that has just one entry and it is -1,
    meaning 'all threads', as this ends up going down to perf_event_open().

    Cc: Adrian Hunter
    Cc: Borislav Petkov
    Cc: David Ahern
    Cc: Don Zickus
    Cc: Frederic Weisbecker
    Cc: Jean Pihet
    Cc: Jiri Olsa
    Cc: Mike Galbraith
    Cc: Namhyung Kim
    Cc: Paul Mackerras
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/n/tip-8av26cz8uxmbnihl5mmrygp9@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

28 Dec, 2013

2 commits

  • Several areas already used this technique, so do some audit to
    consistently use it elsewhere.

    Cc: Adrian Hunter
    Cc: David Ahern
    Cc: Frederic Weisbecker
    Cc: Jiri Olsa
    Cc: Mike Galbraith
    Cc: Namhyung Kim
    Cc: Paul Mackerras
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/n/tip-9sbere0kkplwe45ak6rk4a1f@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     
  • For the frequent idiom of:

    free(ptr);
    ptr = NULL;

    Make it expect a pointer to the pointer being freed, so that it becomes
    clear at first sight that the variable being freed is being modified.

    Cc: Adrian Hunter
    Cc: David Ahern
    Cc: Frederic Weisbecker
    Cc: Jiri Olsa
    Cc: Mike Galbraith
    Cc: Namhyung Kim
    Cc: Paul Mackerras
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/n/tip-pfw02ezuab37kha18wlut7ir@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

25 May, 2012

1 commit


22 Feb, 2012

1 commit

  • The following commit:
    b52956c perf tools: Allow multiple threads or processes in record, stat, top

    introduced a bug in the thread_map code which caused perf record -a to
    not setup system-wide monitoring properly.

    $ taskset -c 1 noploop 1000 &
    $ perf record -a -C 1 sleep 10
    $ perf report -D | tail -20
    cycles stats:
    TOTAL events: 4413
    MMAP events: 4025
    COMM events: 340
    SAMPLE events: 48

    Here I was expecting about 10,000 samples and not 48.

    In system-wide mode, the PID passed to perf_event_open() must be -1 and
    it was 0. That caused the kernel to setup a per-process event on PID:0.
    Consequently, the number of samples captured does not correspond to the
    requested measurement.

    The following one-liner fixes the problem for me with or without -C.

    I would also suggest to change the malloc() to something that matches
    the struct definition. thread_map->map[] is declared as int map[] and
    not pid_t map[]. If map[] can only contain pids, then change the struct
    definition.

    Acked-by: David Ahern
    Cc: David Ahern
    Cc: Eric Dumazet
    Cc: Ingo Molnar
    Cc: Peter Zijlstra
    Link: http://lkml.kernel.org/r/20120221145424.GA6757@quad
    Signed-off-by: Stephane Eranian
    Signed-off-by: Arnaldo Carvalho de Melo

    Stephane Eranian
     

14 Feb, 2012

1 commit

  • Allow a user to collect events for multiple threads or processes
    using a comma separated list.

    e.g., collect data on a VM and its vhost thread:
    perf top -p 21483,21485
    perf stat -p 21483,21485 -ddd
    perf record -p 21483,21485

    or monitoring vcpu threads
    perf top -t 21488,21489
    perf stat -t 21488,21489 -ddd
    perf record -t 21488,21489

    Cc: Frederic Weisbecker
    Cc: Ingo Molnar
    Cc: Paul Mackerras
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/1328718772-16688-1-git-send-email-dsahern@gmail.com
    Signed-off-by: David Ahern
    Signed-off-by: Arnaldo Carvalho de Melo

    David Ahern
     

25 Jan, 2012

2 commits

  • The new --uid command line option will show only the tasks for a given
    user, using the proc interface to figure out the existing tasks.

    Kernel work is needed to close races at startup, but this should already
    be useful in many use cases.

    Cc: David Ahern
    Cc: Frederic Weisbecker
    Cc: Mike Galbraith
    Cc: Paul Mackerras
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/n/tip-bdnspm000gw2l984a2t53o8z@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     
  • For helping with debugging.

    Cc: David Ahern
    Cc: Frederic Weisbecker
    Cc: Mike Galbraith
    Cc: Paul Mackerras
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Link: http://lkml.kernel.org/n/tip-m06n4rp7pwr6dlzwoq89cl69@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo
     

24 Jan, 2011

1 commit

  • To untangle it from struct thread handling, that is tied to symbols, etc.

    Right now in the python bindings I'm working on I need just a subset of
    the util/ files, untangling it allows me to do that.

    Cc: Frederic Weisbecker
    Cc: Ingo Molnar
    Cc: Mike Galbraith
    Cc: Paul Mackerras
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Cc: Tom Zanussi
    LKML-Reference:
    Signed-off-by: Arnaldo Carvalho de Melo

    Arnaldo Carvalho de Melo