summaryrefslogtreecommitdiffstats
path: root/src/usr/trace/daemon/daemon.H
blob: ad0028be42756b2f4a53178b9116311cfa60ceae (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
130
131
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/trace/daemon/daemon.H $                               */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012                   */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* 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 transfered to mailbox.
             */
            void sendContBuffer(void* i_buffer, size_t i_size);
            /** Send extract trace buffer to SP.
             *
             *  Ownership of i_buffer is transfered 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);

            /** Write mailbox scratch register to a value. */
            void writeScratchReg(uint64_t i_value);
            /** Read mailbox scratch register. */
            uint64_t readScratchReg();

                /** 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;

    };


}

#endif
OpenPOWER on IntegriCloud