Skip to content
Snippets Groups Projects
  1. Sep 28, 2022
  2. Mar 18, 2022
  3. Mar 11, 2022
    • Steven Rostedt (Google)'s avatar
      tracing: Add sample code for custom trace events · 953c2f05
      Steven Rostedt (Google) authored
      Add sample code to show how to create custom trace events in the tracefs
      directory that can be enabled and modified like any event in tracefs
      (including triggers, histograms, synthetic events and event probes).
      
      The example is creating a custom sched_switch and a sched_waking to limit
      what is recorded:
      
      If the custom sched switch only records the prev_prio, next_prio and
      next_pid, it can bring the size from 64 bytes per event, down to just 16
      bytes!
      
      If sched_waking only records the prio and pid of the woken event, it will
      bring the size down from 36 bytes to 12 bytes per event.
      
      This will allow for a much smaller footprint into the ring buffer and keep
      more events from dropping.
      
      Link: https://lkml.kernel.org/r/20220303220625.369226746@goodmis.org
      
      
      
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Tom Zanussi <zanussi@kernel.org>
      Suggested-by: default avatarJoel Fernandes <joel@joelfernandes.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      953c2f05
  4. Nov 26, 2021
  5. Nov 18, 2021
  6. Nov 01, 2021
  7. Oct 27, 2021
  8. Oct 19, 2021
  9. Jun 21, 2021
  10. Apr 22, 2021
  11. Jan 21, 2021
  12. Jun 21, 2020
  13. Jun 11, 2020
    • Masahiro Yamada's avatar
      samples: binderfs: really compile this sample and fix build issues · fca5e949
      Masahiro Yamada authored
      
      Even after commit c624adc9 ("samples: fix binderfs sample"), this
      sample is never compiled.
      
      'hostprogs' teaches Kbuild that this is a host program, but not enough
      to order to compile it. You must add it to 'always-y' to really compile
      it.
      
      Since this sample has never been compiled in upstream, various issues
      are left unnoticed.
      
      [1] compilers without <linux/android/binderfs.h> are still widely used
      
      <linux/android/binderfs.h> is only available since commit c13295ad
      ("binderfs: rename header to binderfs.h"), i.e., Linux 5.0
      
      If your compiler is based on UAPI headers older than Linux 5.0, you
      will see the following error:
      
        samples/binderfs/binderfs_example.c:16:10: fatal error: linux/android/binderfs.h: No such file or directory
         #include <linux/android/binderfs.h>
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
        compilation terminated.
      
      You cannot rely on compilers having such a new header.
      
      The common approach is to install UAPI headers of this kernel into
      usr/include, and then add it to the header search path.
      
      I added 'depends on HEADERS_INSTALL' in Kconfig, and '-I usr/include'
      compiler flag in Makefile.
      
      [2] compile the sample for target architecture
      
      Because headers_install works for the target architecture, only the
      native compiler was able to build sample code that requires
      '-I usr/include'.
      
      Commit 7f3a59db ("kbuild: add infrastructure to build userspace
      programs") added the new syntax 'userprogs' to compile user-space
      programs for the target architecture.
      
      Use it, and then 'ifndef CROSS_COMPILE' will go away.
      
      I added 'depends on CC_CAN_LINK' because $(CC) is not necessarily
      capable of linking user-space programs.
      
      [3] use subdir-y to descend into samples/binderfs
      
      Since this directory does not contain any kernel-space code, it has no
      point in generating built-in.a or modules.order.
      
      Replace obj-$(CONFIG_...) with subdir-$(CONFIG_...).
      
      [4] -Wunused-variable warning
      
      If I compile this, I see the following warning.
      
        samples/binderfs/binderfs_example.c: In function 'main':
        samples/binderfs/binderfs_example.c:21:9: warning: unused variable 'len' [-Wunused-variable]
           21 |  size_t len;
              |         ^~~
      
      I removed the unused 'len'.
      
      [5] CONFIG_ANDROID_BINDERFS is not required
      
      Since this is a user-space standalone program, it is independent of
      the kernel configuration.
      
      Remove 'depends on ANDROID_BINDERFS'.
      
      Fixes: 9762dc14 ("samples: add binderfs sample program")
      Fixes: c624adc9 ("samples: fix binderfs sample")
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      fca5e949
  14. May 19, 2020
    • David Howells's avatar
      Add sample notification program · f5b5a164
      David Howells authored
      
      The sample program is run like:
      
      	./samples/watch_queue/watch_test
      
      and watches "/" for mount changes and the current session keyring for key
      changes:
      
      	# keyctl add user a a @s
      	1035096409
      	# keyctl unlink 1035096409 @s
      
      producing:
      
      	# ./watch_test
      	read() = 16
      	NOTIFY[000]: ty=000001 sy=02 i=00000110
      	KEY 2ffc2e5d change=2[linked] aux=1035096409
      	read() = 16
      	NOTIFY[000]: ty=000001 sy=02 i=00000110
      	KEY 2ffc2e5d change=3[unlinked] aux=1035096409
      
      Other events may be produced, such as with a failing disk:
      
      	read() = 22
      	NOTIFY[000]: ty=000003 sy=02 i=00000416
      	USB 3-7.7 dev-reset e=0 r=0
      	read() = 24
      	NOTIFY[000]: ty=000002 sy=06 i=00000418
      	BLOCK 00800050 e=6[critical medium] s=64000ef8
      
      This corresponds to:
      
      	blk_update_request: critical medium error, dev sdf, sector 1677725432 op 0x0:(READ) flags 0x0 phys_seg 1 prio class 0
      
      in dmesg.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      f5b5a164
  15. May 17, 2020
  16. May 05, 2020
  17. Nov 23, 2019
    • Divya Indi's avatar
      tracing: Sample module to demonstrate kernel access to Ftrace instances. · 89ed4249
      Divya Indi authored
      This is a sample module to demonstrate the use of the newly introduced and
      exported APIs to access Ftrace instances from within the kernel.
      
      Newly introduced APIs used here -
      
      1. Create/Lookup a trace array with the given name.
      struct trace_array *trace_array_get_by_name(const char *name)
      
      2. Destroy/Remove a trace array.
      int trace_array_destroy(struct trace_array *tr)
      
      4. Enable/Disable trace events:
      int trace_array_set_clr_event(struct trace_array *tr, const char *system,
              const char *event, bool enable);
      
      Exported APIs -
      1. trace_printk equivalent for instances.
      int trace_array_printk(struct trace_array *tr,
                     unsigned long ip, const char *fmt, ...);
      
      2. Helper function.
      void trace_printk_init_buffers(void);
      
      3. To decrement the reference counter.
      void trace_array_put(struct trace_array *tr)
      
      Sample output(contents of /sys/kernel/tracing/instances/sample-instance)
      NOTE: Tracing disabled after ~5 sec)
      
                                    _-----=> irqs-off
                                   / _----=> need-resched
                                  | / _---=> hardirq/softirq
                                  || / _--=> preempt-depth
                                  ||| /     delay
                 TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
                    | |       |   ||||       |         |
      sample-instance-1452  [002] ....    49.430948: simple_thread: trace_array_printk: count=0
      sample-instance-1452  [002] ....    49.430951: sample_event: count value=0 at jiffies=4294716608
      sample-instance-1452  [002] ....    50.454847: simple_thread: trace_array_printk: count=1
      sample-instance-1452  [002] ....    50.454849: sample_event: count value=1 at jiffies=4294717632
      sample-instance-1452  [002] ....    51.478748: simple_thread: trace_array_printk: count=2
      sample-instance-1452  [002] ....    51.478750: sample_event: count value=2 at jiffies=4294718656
      sample-instance-1452  [002] ....    52.502652: simple_thread: trace_array_printk: count=3
      sample-instance-1452  [002] ....    52.502655: sample_event: count value=3 at jiffies=4294719680
      sample-instance-1452  [002] ....    53.526533: simple_thread: trace_array_printk: count=4
      sample-instance-1452  [002] ....    53.526535: sample_event: count value=4 at jiffies=4294720704
      sample-instance-1452  [002] ....    54.550438: simple_thread: trace_array_printk: count=5
      sample-instance-1452  [002] ....    55.574336: simple_thread: trace_array_printk: count=6
      
      Link: http://lkml.kernel.org/r/1574276919-11119-3-git-send-email-divya.indi@oracle.com
      
      
      
      Reviewed-by: default avatarAruna Ramakrishna <aruna.ramakrishna@oracle.com>
      Signed-off-by: default avatarDivya Indi <divya.indi@oracle.com>
      [ Moved to samples/ftrace ]
      Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
      89ed4249
  18. Nov 13, 2019
  19. Oct 21, 2019
  20. Jul 15, 2019
  21. Jun 15, 2019
    • Masahiro Yamada's avatar
      kbuild: add CONFIG_HEADERS_INSTALL and loosen the dependency of samples · e949f4c2
      Masahiro Yamada authored
      
      Commit 5318321d ("samples: disable CONFIG_SAMPLES for UML") used
      a big hammer to fix the build errors under the samples/ directory.
      Only some samples actually include uapi headers from usr/include.
      
      Introduce CONFIG_HEADERS_INSTALL since 'depends on HEADERS_INSTALL' is
      clearer than 'depends on !UML'. If this option is enabled, uapi headers
      are installed before starting directory descending.
      
      I added 'depends on HEADERS_INSTALL' to per-sample CONFIG options.
      This allows UML to compile some samples.
      
      $ make ARCH=um allmodconfig samples/
        [ snip ]
        CC [M]  samples/configfs/configfs_sample.o
        CC [M]  samples/kfifo/bytestream-example.o
        CC [M]  samples/kfifo/dma-example.o
        CC [M]  samples/kfifo/inttype-example.o
        CC [M]  samples/kfifo/record-example.o
        CC [M]  samples/kobject/kobject-example.o
        CC [M]  samples/kobject/kset-example.o
        CC [M]  samples/trace_events/trace-events-sample.o
        CC [M]  samples/trace_printk/trace-printk.o
        AR      samples/vfio-mdev/built-in.a
        AR      samples/built-in.a
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      e949f4c2
  22. May 21, 2019
  23. May 03, 2019
  24. Mar 20, 2019
  25. Jan 15, 2019
  26. Oct 10, 2018
  27. Jun 09, 2018
  28. Jun 08, 2018
Loading