1/**
2 * @file daemon/opd_sfile.h
3 * Management of sample files
4 *
5 * @remark Copyright 2002 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author John Levon
9 * @author Philippe Elie
10 */
11
12#ifndef OPD_SFILE_H
13#define OPD_SFILE_H
14
15#include "opd_cookie.h"
16
17#include "odb.h"
18#include "op_hw_config.h"
19#include "op_types.h"
20#include "op_list.h"
21
22#include <sys/types.h>
23
24struct kernel_image;
25struct transient;
26
27#define CG_HASH_SIZE 16
28#define UNUSED_EMBEDDED_OFFSET ~0LLU
29
30/**
31 * Each set of sample files (where a set is over the physical counter
32 * types) will have one of these for it. We match against the
33 * descriptions here to find which sample DB file we need to modify.
34 *
35 * cg files are stored in the hash.
36 */
37struct sfile {
38	/** hash value for this sfile */
39	unsigned long hashval;
40	/** cookie value for the binary profiled */
41	cookie_t cookie;
42	/** cookie value for the application owner, INVALID_COOKIE if not set */
43	cookie_t app_cookie;
44	/** thread ID, -1 if not set */
45	pid_t tid;
46	/** thread group ID, -1 if not set */
47	pid_t tgid;
48	/** CPU number */
49	unsigned int cpu;
50	/** kernel image if applicable */
51	struct kernel_image * kernel;
52	/** anonymous mapping */
53	struct anon_mapping * anon;
54	/** embedded offset for Cell BE SPU */
55	uint64_t embedded_offset;
56
57	/** hash table link */
58	struct list_head hash;
59	/** lru list */
60	struct list_head lru;
61	/** true if this file should be ignored in profiles */
62	int ignored;
63	/** opened sample files */
64	odb_t files[OP_MAX_COUNTERS];
65	/** extended sample files */
66	odb_t * ext_files;
67	/** hash table of opened cg sample files */
68	struct list_head cg_hash[CG_HASH_SIZE];
69};
70
71/** a call-graph entry */
72struct cg_entry {
73	/** where arc is to */
74	struct sfile to;
75	/** next in the hash slot */
76	struct list_head hash;
77};
78
79/** clear any sfiles that are for the kernel */
80void sfile_clear_kernel(void);
81
82struct anon_mapping;
83
84/** clear any sfiles for the given anon mapping */
85void sfile_clear_anon(struct anon_mapping *);
86
87/** sync sample files */
88void sfile_sync_files(void);
89
90/** close sample files */
91void sfile_close_files(void);
92
93/** clear out a certain amount of LRU entries
94 * return non-zero if the lru is already empty */
95int sfile_lru_clear(void);
96
97/** remove a sfile from the lru list, protecting it from sfile_lru_clear() */
98void sfile_get(struct sfile * sf);
99
100/** add this sfile to lru list */
101void sfile_put(struct sfile * sf);
102
103/**
104 * Find the sfile for the current parameters. Note that is required
105 * that the PC value be set appropriately (needed for kernel images)
106 */
107struct sfile * sfile_find(struct transient const * trans);
108
109/** Log the sample in a previously located sfile. */
110void sfile_log_sample(struct transient const * trans);
111
112/** Log the event/cycle count in a previously located sfile */
113void sfile_log_sample_count(struct transient const * trans,
114                            unsigned long int count);
115
116/** initialise hashes */
117void sfile_init(void);
118
119#endif /* OPD_SFILE_H */
120