blob: 912b8ea01d33f5485b940ce6db569f197aac58ea [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Peter Oberparleiter2521f2c2009-06-17 16:28:08 -07002/*
3 * Profiling infrastructure declarations.
4 *
5 * This file is based on gcc-internal definitions. Data structures are
6 * defined to be compatible with gcc counterparts. For a better
7 * understanding, refer to gcc source: gcc/gcov-io.h.
8 *
9 * Copyright IBM Corp. 2009
10 * Author(s): Peter Oberparleiter <oberpar@linux.vnet.ibm.com>
11 *
12 * Uses gcc-internal data definitions.
13 */
14
15#ifndef GCOV_H
16#define GCOV_H GCOV_H
17
Greg Hackmanne178a5b2019-05-14 15:45:31 -070018#include <linux/module.h>
Peter Oberparleiter2521f2c2009-06-17 16:28:08 -070019#include <linux/types.h>
20
21/*
22 * Profiling data types used for gcc 3.4 and above - these are defined by
23 * gcc and need to be kept as close to the original definition as possible to
24 * remain compatible.
25 */
Peter Oberparleiter2521f2c2009-06-17 16:28:08 -070026#define GCOV_DATA_MAGIC ((unsigned int) 0x67636461)
27#define GCOV_TAG_FUNCTION ((unsigned int) 0x01000000)
28#define GCOV_TAG_COUNTER_BASE ((unsigned int) 0x01a10000)
29#define GCOV_TAG_FOR_COUNTER(count) \
30 (GCOV_TAG_COUNTER_BASE + ((unsigned int) (count) << 17))
31
32#if BITS_PER_LONG >= 64
33typedef long gcov_type;
34#else
35typedef long long gcov_type;
36#endif
37
Frantisek Hrbata8cbce372013-11-12 15:11:24 -080038/* Opaque gcov_info. The gcov structures can change as for example in gcc 4.7 so
39 * we cannot use full definition here and they need to be placed in gcc specific
40 * implementation of gcov. This also means no direct access to the members in
41 * generic code and usage of the interface below.*/
42struct gcov_info;
Peter Oberparleiter2521f2c2009-06-17 16:28:08 -070043
Frantisek Hrbata8cbce372013-11-12 15:11:24 -080044/* Interface to access gcov_info data */
45const char *gcov_info_filename(struct gcov_info *info);
46unsigned int gcov_info_version(struct gcov_info *info);
47struct gcov_info *gcov_info_next(struct gcov_info *info);
48void gcov_info_link(struct gcov_info *info);
49void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info);
Greg Hackmanne178a5b2019-05-14 15:45:31 -070050bool gcov_info_within_module(struct gcov_info *info, struct module *mod);
Johannes Berg7a1d55b2021-05-06 18:04:45 -070051size_t convert_to_gcda(char *buffer, struct gcov_info *info);
Peter Oberparleiter2521f2c2009-06-17 16:28:08 -070052
53/* Base interface. */
54enum gcov_action {
55 GCOV_ADD,
56 GCOV_REMOVE,
57};
58
59void gcov_event(enum gcov_action action, struct gcov_info *info);
60void gcov_enable_events(void);
61
Johannes Berg7a1d55b2021-05-06 18:04:45 -070062/* writing helpers */
63size_t store_gcov_u32(void *buffer, size_t off, u32 v);
64size_t store_gcov_u64(void *buffer, size_t off, u64 v);
Peter Oberparleiter2521f2c2009-06-17 16:28:08 -070065
66/* gcov_info control. */
67void gcov_info_reset(struct gcov_info *info);
68int gcov_info_is_compatible(struct gcov_info *info1, struct gcov_info *info2);
69void gcov_info_add(struct gcov_info *dest, struct gcov_info *source);
70struct gcov_info *gcov_info_dup(struct gcov_info *info);
71void gcov_info_free(struct gcov_info *info);
72
73struct gcov_link {
74 enum {
75 OBJ_TREE,
76 SRC_TREE,
77 } dir;
78 const char *ext;
79};
80extern const struct gcov_link gcov_link[];
81
Greg Hackmann826eba02019-05-14 15:45:25 -070082extern int gcov_events_enabled;
83extern struct mutex gcov_lock;
84
Peter Oberparleiter2521f2c2009-06-17 16:28:08 -070085#endif /* GCOV_H */