The Pedigree Project 0.1
LocksCommand.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef LOCKSCOMMAND_H
21#define LOCKSCOMMAND_H
22#include "pedigree/kernel/Atomic.h"
23#include "pedigree/kernel/debugger/DebuggerCommand.h"
24#include "pedigree/kernel/debugger/DebuggerIO.h"
25#include "pedigree/kernel/debugger/Scrollable.h"
26#include "pedigree/kernel/processor/state_forward.h"
27#include "pedigree/kernel/processor/types.h"
28#include "pedigree/kernel/utilities/StaticString.h"
29
30#include <config.h>
31
32class Spinlock;
33
37#define NUM_BT_FRAMES 6
38#define MAX_DESCRIPTORS 50
39
40#ifdef TESTSUITE
41#define LOCKS_COMMAND_NUM_CPU 4
42#else
43#if MULTIPROCESSOR
44#define LOCKS_COMMAND_NUM_CPU 255
45#else
46#define LOCKS_COMMAND_NUM_CPU 1
47#endif
48#endif
49
53class LocksCommand : public DebuggerCommand, public Scrollable {
54 friend class Spinlock;
55
56 public:
61
65 virtual ~LocksCommand();
66
70 void autocomplete(const HugeStaticString& input, HugeStaticString& output);
71
75 bool execute(const HugeStaticString& input, HugeStaticString& output, InterruptState& state,
76 DebuggerIO* screen);
77
82 return NormalStaticString("locks");
83 }
84
85 void setReady();
86
91 void setFatal();
92
93 bool lockAttempted(const Spinlock* pLock, size_t nCpu = ~0U, bool intState = false);
94 bool lockAcquired(const Spinlock* pLock, size_t nCpu = ~0U, bool intState = false);
95 bool lockReleased(const Spinlock* pLock, size_t nCpu = ~0U);
96
102 bool checkSchedule(size_t nCpu = ~0U);
103
110 bool checkState(const Spinlock* pLock, size_t nCpu = ~0U);
111
112 // Scrollable interface.
113 virtual const char* getLine1(size_t index, DebuggerIO::Colour& colour,
114 DebuggerIO::Colour& bgColour);
115 virtual const char* getLine2(size_t index, size_t& colOffset, DebuggerIO::Colour& colour,
116 DebuggerIO::Colour& bgColour);
117 virtual size_t getLineCount();
118
119 protected:
120 void clearFatal();
121
122 private:
133
134 const char* stateName(State s) {
135 switch (s) {
136 case Attempted:
137 return "attempted";
138 case Acquired:
139 return "acquired";
140 case Checked:
141 return "checked";
142 case Inactive:
143 return "inactive";
144 default:
145 return "unknown";
146 }
147 }
148
150 LockDescriptor() : pLock(0), state(Inactive) {}
151
152 const Spinlock* pLock;
153 State state;
154 };
155
156 LockDescriptor m_pDescriptors[LOCKS_COMMAND_NUM_CPU][MAX_DESCRIPTORS];
157
158 Atomic<bool> m_bAcquiring;
160 Atomic<uint8_t> m_NextPosition[LOCKS_COMMAND_NUM_CPU];
161 Atomic<size_t> m_LockIndex;
162
163 bool m_bFatal;
164
165 size_t m_SelectedLine;
166
169};
170
171extern LocksCommand g_LocksCommand;
172
174#endif
LockDescriptor * m_pSelectedLock
Lock we've selected for backtracing.
bool checkState(const Spinlock *pLock, size_t nCpu=~0U)
bool checkSchedule(size_t nCpu=~0U)
virtual ~LocksCommand()
Atomic< uint8_t > m_NextPosition[LOCKS_COMMAND_NUM_CPU]
void autocomplete(const HugeStaticString &input, HugeStaticString &output)
@ Inactive
This entry is no longer active.
@ Attempted
The lock is about to be attempted.
@ Acquired
The lock is acquired.
@ Checked
The lock failed to be acquired, and has been checked once.
bool lockReleased(const Spinlock *pLock, size_t nCpu=~0U)
const NormalStaticString getString()
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)