diff options
Diffstat (limited to 'sideband/internal/include')
-rw-r--r-- | sideband/internal/include/pt_sb_context.h | 99 | ||||
-rw-r--r-- | sideband/internal/include/pt_sb_decoder.h | 69 | ||||
-rw-r--r-- | sideband/internal/include/pt_sb_file.h | 47 | ||||
-rw-r--r-- | sideband/internal/include/pt_sb_pevent.h | 155 | ||||
-rw-r--r-- | sideband/internal/include/pt_sb_session.h | 101 |
5 files changed, 471 insertions, 0 deletions
diff --git a/sideband/internal/include/pt_sb_context.h b/sideband/internal/include/pt_sb_context.h new file mode 100644 index 000000000000..5a205aa3536f --- /dev/null +++ b/sideband/internal/include/pt_sb_context.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2017-2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PT_SB_CONTEXT_H +#define PT_SB_CONTEXT_H + +#include <stdint.h> + +struct pt_image; + + +/* The ABI of the process. */ +enum pt_sb_abi { + pt_sb_abi_unknown, + pt_sb_abi_x64, + pt_sb_abi_x32, + pt_sb_abi_ia32 +}; + +struct pt_sb_context { + /* The next context in a linear list of process contexts. + * + * I do not expect more than a few processes per tracing session. And + * if we had many processes, we'd also have trace spanning many context + * switches and sideband decode won't be the bottleneck. + * + * This field is owned by the sideband tracing session to which this + * context belongs. + */ + struct pt_sb_context *next; + + /* The memory image of that process. + * + * You must hold a reference to this context as long as @image is used. + */ + struct pt_image *image; + + /* The ABI of the process. + * + * This may be relevant for some but not all sideband formats. + * + * This field is collectively owned by all sideband decoders. + */ + enum pt_sb_abi abi; + + /* We identify processes by their process id. + * + * Intel PT provides CR3 and VMCS Base to identify address-spaces and + * notifies us about changes. But at least on Linux, we don't get the + * CR3 and all sideband records refer to pid/tid, so we're using those. + */ + uint32_t pid; + + /* The number of current users. + * + * We remove a context when the process exits but we keep the context + * object and its image alive as long as they are used. + */ + uint16_t ucount; +}; + +/* Allocate a context. + * + * Allocate a context and an image. The optional @name argument is given to the + * context's image. + * + * The context's use-count is initialized to one. Use pt_sb_ctx_put() to free + * the returned context and its image. + * + * Returns a non-NULL context or NULL when out of memory. + */ +extern struct pt_sb_context *pt_sb_ctx_alloc(const char *name); + +#endif /* PT_SB_CONTEXT_H */ diff --git a/sideband/internal/include/pt_sb_decoder.h b/sideband/internal/include/pt_sb_decoder.h new file mode 100644 index 000000000000..70142ee618ad --- /dev/null +++ b/sideband/internal/include/pt_sb_decoder.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017-2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PT_SB_DECODER_H +#define PT_SB_DECODER_H + +#include <stdio.h> + + +/* An Intel PT sideband decoder. */ +struct pt_sb_decoder { + /* The next Intel PT sideband decoder in a linear list of Intel PT + * sideband decoders ordered by @tsc (ascending). + */ + struct pt_sb_decoder *next; + + /* The timestamp of the next sideband record. */ + uint64_t tsc; + + /* Decoder functions provided by the decoder supplier: + * + * - fetch the next sideband record. + */ + int (*fetch)(struct pt_sb_session *session, uint64_t *tsc, void *priv); + + /* - apply the current sideband record. */ + int (*apply)(struct pt_sb_session *session, struct pt_image **image, + const struct pt_event *event, void *priv); + + /* - print the current sideband record. */ + int (*print)(struct pt_sb_session *session, FILE *stream, + uint32_t flags, void *priv); + + /* - destroy the decoder's private data. */ + void (*dtor)(void *priv); + + /* Decoder-specific private data. */ + void *priv; + + /* A flag saying whether this is a primary or secondary decoder. */ + uint32_t primary:1; +}; + +#endif /* PT_SB_DECODER_H */ diff --git a/sideband/internal/include/pt_sb_file.h b/sideband/internal/include/pt_sb_file.h new file mode 100644 index 000000000000..9e1ce1bb6494 --- /dev/null +++ b/sideband/internal/include/pt_sb_file.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017-2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PT_SB_FILE_H +#define PT_SB_FILE_H + +#include <stddef.h> + + +/* Load a file section. + * + * Allocates a large enough buffer and copies the contents of @file from @begin + * to @end into it. If @end is zero, reads from @begin until the end of @file. + * + * On success, provides the buffer in @buffer and its size in @size. + * + * Returns zero on success, a negative error code otherwise. + */ +extern int pt_sb_file_load(void **buffer, size_t *size, const char *filename, + size_t begin, size_t end); + +#endif /* PT_SB_FILE_H */ diff --git a/sideband/internal/include/pt_sb_pevent.h b/sideband/internal/include/pt_sb_pevent.h new file mode 100644 index 000000000000..95a77b951640 --- /dev/null +++ b/sideband/internal/include/pt_sb_pevent.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2017-2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PT_SB_PEVENT_H +#define PT_SB_PEVENT_H + +#include "pevent.h" + + +/* The estimated code location. */ +enum pt_sb_pevent_loc { + /* We do not know where we are. */ + ploc_unknown, + + /* We are in kernel space. */ + ploc_in_kernel, + + /* We are in user space. */ + ploc_in_user, + + /* We are likely in kernel space. */ + ploc_likely_in_kernel, + + /* We are likely in user space. */ + ploc_likely_in_user +}; + +/* A Linux perf event decoder's private data. */ +struct pt_sb_pevent_priv { + /* The sideband filename for printing. + * + * This is a copy of the filename provided by the user when allocating + * the sideband decoder. + */ + char *filename; + + /* The optional system root directory. + * + * If not NULL, this is prepended to every filename referenced in perf + * event sideband records. + * + * This is a copy of the sysroot provided by the user when allocating + * the sideband decoder. + */ + char *sysroot; + + /* The optional 64-bit vdso. + * + * If not NULL, this is used for [vdso] mmaps in 64-bit processes. + * + * This is a copy of the vdso filename provided by the user when + * allocating the sideband decoder. + */ + char *vdso_x64; + + /* The optional x32 vdso. + * + * If not NULL, this is used for [vdso] mmaps in x32 processes. + * + * This is a copy of the vdso filename provided by the user when + * allocating the sideband decoder. + */ + char *vdso_x32; + + /* The optional 32-bit vdso. + * + * If not NULL, this is used for [vdso] mmaps in 32-bit processes. + * + * This is a copy of the vdso filename provided by the user when + * allocating the sideband decoder. + */ + char *vdso_ia32; + + /* The begin and end of the sideband data in memory. */ + uint8_t *begin, *end; + + /* The position of the current and the next record in the sideband + * buffer. + * + * The current position is the position of @event or NULL. + * the next position is the position from which to fetch. + */ + const uint8_t *current, *next; + + /* The libpevent configuration. */ + struct pev_config pev; + + /* The current perf event record. */ + struct pev_event event; + + /* The current process context. + * + * This is NULL if there is no current context. + * Otherwise, holds a reference to @context (put after use). + */ + struct pt_sb_context *context; + + /* The next process context. + * + * This is NULL if we're not waiting to switch contexts. + * Otherwise, holds a reference to @context (put after use). + */ + struct pt_sb_context *next_context; + + /* The start address of the kernel. + * + * This is used to distinguish kernel from user addresses: + * + * kernel >= @kernel_start + * user < @kernel_start + * + * This is only required when tracing ring-0. + */ + uint64_t kernel_start; + + /* An offset to be subtracted from every sideband record timestamp. + * + * This applies sideband records a little bit earlier to compensate for + * too coarse timing. + */ + uint64_t tsc_offset; + + /* The current code location estimated from previous events. */ + enum pt_sb_pevent_loc location; +}; + +extern int pt_sb_pevent_init(struct pt_sb_pevent_priv *priv, + const struct pt_sb_pevent_config *config); + +#endif /* PT_SB_PEVENT_H */ diff --git a/sideband/internal/include/pt_sb_session.h b/sideband/internal/include/pt_sb_session.h new file mode 100644 index 000000000000..365e7daf32dc --- /dev/null +++ b/sideband/internal/include/pt_sb_session.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2017-2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PT_SB_SESSION_H +#define PT_SB_SESSION_H + +#include "libipt-sb.h" + +struct pt_image_section_cache; +struct pt_image; +struct pt_sb_context; +struct pt_sb_decoder; + + +struct pt_sb_session { + /* The image section cache to use for new image sections. + * + * This allows sharing image sections across contexts. + */ + struct pt_image_section_cache *iscache; + + /* A linear list of contexts in no particular order. */ + struct pt_sb_context *contexts; + + /* The kernel memory image. + * + * Just like process images, the kernel image may change over time. It + * is used to populate new process images. + * + * This assumes that the full kernel is mapped into every process. + */ + struct pt_image *kernel; + + /* A list of sideband decoders ordered by their @tsc (ascending). */ + struct pt_sb_decoder *decoders; + + /* A list of newly added sideband decoders in no particular order. + * + * Use pt_sb_init_decoders() to fetch the first record and move them to + * @decoders. + */ + struct pt_sb_decoder *waiting; + + /* A list of retired sideband decoders in no particular order. + * + * They ran out of trace but might still have a postponed effect + * pending. We present events to them until @apply() returns -pte_eos. + */ + struct pt_sb_decoder *retired; + + /* A list of removed sideband decoders in no particular order. + * + * They wait for their destruction when the session is destroyed. + */ + struct pt_sb_decoder *removed; + + /* An optional callback function to be called on sideband decode errors + * and warnings. + */ + pt_sb_error_notifier_t *notify_error; + + /* The private data for the error notifier. */ + void *priv_error; + + /* An optional callback function to be called on context switches. */ + pt_sb_ctx_switch_notifier_t *notify_switch_to; + + /* The private data for the context switch notifier. */ + void *priv_switch_to; +}; + + +extern int pt_sb_error(const struct pt_sb_session *session, int errcode, + const char *filename, uint64_t offset); + +#endif /* PT_SB_SESSION_H */ |