summaryrefslogtreecommitdiffstats
path: root/src/usr/trace/daemon/daemon.H
blob: 57e908696ea5db0adc9a355bd10cc08be2e1e57e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/trace/daemon/daemon.H $                               */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,2016                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef __TRACE_DAEMON_DAEMON_H
#define __TRACE_DAEMON_DAEMON_H

/** @file daemon.H
 *  Declarations for the daemon class.
 */

#include <stdint.h>
#include "../service.H"

    // Forward declarations.
namespace TRACE
{
    class BufferPage;
    class Entry;
}

namespace TRACEDAEMON
{
    /** @class Daemon
     *
     *  @brief Class to handle trace background ops and mailbox messages.
     */
    class Daemon
    {
        public:
            /** Default constructor.
             *
             *  Initializes class.
             *
             */
            Daemon();
            /** Destructor.
             *
             *  Not currently supported, asserts.
             */
            ~Daemon();

            /** @fn start
             *
             *  Thread entry-point for daemon.  Calls 'execute'.
             */
            static void* start(void*);

        private:

            /** @fn execute
             *
             *  Performs daemon work.
             */
            void execute();

            /** Gather trace pages from client-side buffers. */
            void collectTracePages();
            /** Send continuous trace buffer to SP.
             *
             *  Ownership of i_buffer is transferred to mailbox.
             */
            void sendContBuffer(void* i_buffer, size_t i_size);
            /** Send extract trace buffer to SP.
             *
             *  Ownership of i_buffer is transferred to mailbox.
             */
            void sendExtractBuffer(void* i_buffer, size_t i_size);
            /** Reduce component trace buffers if exceeded max size. */
            void pruneTraceEntries(bool i_all = false);
            /** Combine trace buffer pages to remove pruned entries. */
            void coalescePages();
            /** Extract all trace buffers down to the SP. */
            void extractTraceBuffer();

            /** Locklessly move a trace entry from one location to another. */
            void replaceEntry(TRACE::Entry* from, TRACE::Entry* to);

                /** Client-service object. */
            TRACE::Service* iv_service;

                /** First (oldest) combined-buffer page. */
            TRACE::BufferPage* iv_first;
                /** Last (newested) combined-buffer page. */
            TRACE::BufferPage* iv_last;

            // These are kept as class variables rather than function variables
            // so that they can be extraced by the debug tools, since we might
            // be in the middle of the 'collectTracePages' function when the
            // debug tools try to extract the trace.
                /** Intermediate pages
                 *      After collection from client-side, before combining. */
            TRACE::BufferPage* iv_curPages[TRACE::BUFFER_COUNT];
                /** Current offset into intermediate page. */
            size_t iv_curOffset[TRACE::BUFFER_COUNT];

                /** Current size of trace entries pruned. */
            size_t iv_totalPruned;

                /** Address of scratch register. */
            static const uint32_t MB_SCRATCH_REGISTER_1 = 0x00050038;
            static const uint32_t MB_SCRATCH_REGISTER_2 = 0x00050039;

    };


}

#endif
OpenPOWER on IntegriCloud