blob: c352628353911eef3198dde599d46bfdaab59966 [file] [log] [blame]
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -08001/*
2 **************************************************************************
Guojun Jinf7f90f82018-08-16 18:09:23 -07003 * Copyright (c) 2014, 2018 The Linux Foundation. All rights reserved.
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -08004 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17/*
18 * profilesample.h
19 * Sample format for profiling
20 */
21
Guojun Jinf7f90f82018-08-16 18:09:23 -070022#ifndef _NSS_PROFILE_SAMPLE_H_
23#define _NSS_PROFILE_SAMPLE_H_
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080024
Guojun Jinf7f90f82018-08-16 18:09:23 -070025#define NSS_PROFILE_STACK_WORDS 4
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080026
27/*
28 * Each sample is for an enabled thread, not including the profiling thread.
29 * HRT thread sampling is optional.
30 * Sampled threads may be active or inactive. Samples are included in thread number
31 * order, so each sample interval has a set of samples starting with one from thread 0
32 *
33 * Samples include bits indicating if this thread is blocked
34 */
Guojun Jinf7f90f82018-08-16 18:09:23 -070035#define NSS_PROFILE_I_BLOCKED_BIT 5
36#define NSS_PROFILE_I_BLOCKED (1 << NSS_PROFILE_I_BLOCKED_BIT)
37#define NSS_PROFILE_D_BLOCKED_BIT 4
38#define NSS_PROFILE_D_BLOCKED (1 << NSS_PROFILE_D_BLOCKED_BIT)
39#define NSS_PROFILE_BTB_SHIFT 6
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080040
Guojun Jinf7f90f82018-08-16 18:09:23 -070041struct nss_profile_sample {
42 uint32_t pc; /* PC value */
43 uint32_t pid; /* pid for the current process, or 0 if NOMMU or unmapped space */
44 uint16_t active; /* threads are active - for accurate counting */
45 uint16_t d_blocked; /* threads are blocked due to D cache misses : may be removed */
46 uint16_t i_blocked; /* threads are blocked due to I cache misses */
47 uint8_t cond_codes; /* for branch prediction */
48 uint8_t thread; /* 4-bit thread number */
49 uint32_t a_reg; /* source An if PC points to a calli. Otherwise a5 contents for parent of leaf function */
50 uint32_t parent[NSS_PROFILE_STACK_WORDS];
51 /* return addresses from stack, to find the caller */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080052};
53
54
55/*
Guojun Jinf7f90f82018-08-16 18:09:23 -070056 * packet size for profile communication = MSS - tcp/ip headers
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080057 */
Guojun Jinf7f90f82018-08-16 18:09:23 -070058#define NSS_PROFILE_MAX_PACKET_SIZE 1440
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080059
Guojun Jinf7f90f82018-08-16 18:09:23 -070060#define NSS_PROFILE_MAX_COUNTERS ((NSS_PROFILE_MAX_PACKET_SIZE - sizeof(struct profile_header_counters)) / (PROFILE_COUNTER_NAME_LENGTH + 4))
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080061
62struct profile_counter {
63 char name[PROFILE_COUNTER_NAME_LENGTH];
64 uint32_t value;
65};
66
67/*
Guojun Jinf7f90f82018-08-16 18:09:23 -070068 * NSS HW counters and CPU threads
69 */
70#define NSS_HW_COUNTERS 8
71#define NSS_CPU_THREADS 12
72
73/*
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080074 * sampling period info cross all modules -- use extended struct to avoid copy
75 */
76struct profile_ext_header {
Guojun Jinf7f90f82018-08-16 18:09:23 -070077 uint16_t d_blocked; /* threads are blocked due to D cache misses */
78 uint16_t i_blocked; /* threads are blocked due to I cache misses */
79 uint16_t high; /* threads were enabled high priority -- unused */
80 uint16_t enabled_threads; /* threads were enabled at the last sample time */
81 uint16_t hrt; /* HRT threads */
82 uint8_t profiler_tid; /* thread running the profile sampler */
83 uint8_t sample_sets; /* typical 5-8 sets, and may be 9 - see design doc for details */
84 uint32_t sets_map; /* a set map uses a nibble, 8 maps and 9th is derived */
85 uint32_t clocks; /* system clock timer at last sample */
86 uint32_t inst_count[NSS_CPU_THREADS]; /* sampled instruction counts at most recent sample */
87 uint32_t stats[NSS_HW_COUNTERS]; /* contents of the cache statistics counters */
Sundarajan Srinivasan1b03fe22014-12-02 13:20:56 -080088};
89
Guojun Jinf7f90f82018-08-16 18:09:23 -070090#endif /* _NSS_PROFILE_SAMPLE_H_ */