1020ac568SIngo Weinhold/*
2020ac568SIngo Weinhold * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3020ac568SIngo Weinhold * Distributed under the terms of the MIT License.
4020ac568SIngo Weinhold */
5020ac568SIngo Weinhold#ifndef _KERNEL_SCHEDULING_ANALYSIS_H
6020ac568SIngo Weinhold#define _KERNEL_SCHEDULING_ANALYSIS_H
7020ac568SIngo Weinhold
8020ac568SIngo Weinhold#include <tracing.h>
9020ac568SIngo Weinhold#include <thread_defs.h>
10020ac568SIngo Weinhold
11020ac568SIngo Weinhold
125ea5f51dSIngo Weinholdstruct ConditionVariable;
13020ac568SIngo Weinholdstruct mutex;
14020ac568SIngo Weinholdstruct rw_lock;
15020ac568SIngo Weinhold
16020ac568SIngo Weinhold
17020ac568SIngo Weinhold#if SCHEDULING_ANALYSIS_TRACING
18020ac568SIngo Weinholdnamespace SchedulingAnalysisTracing {
19020ac568SIngo Weinhold
20020ac568SIngo Weinholdclass WaitObjectTraceEntry : public AbstractTraceEntry {
21020ac568SIngo Weinholdpublic:
22020ac568SIngo Weinhold	virtual uint32 Type() const = 0;
23020ac568SIngo Weinhold	virtual void* Object() const = 0;
24020ac568SIngo Weinhold	virtual const char* Name() const = 0;
25020ac568SIngo Weinhold
26020ac568SIngo Weinhold	virtual void* ReferencedObject() const
27020ac568SIngo Weinhold	{
28020ac568SIngo Weinhold		return NULL;
29020ac568SIngo Weinhold	}
30020ac568SIngo Weinhold};
31020ac568SIngo Weinhold
32020ac568SIngo Weinhold
33020ac568SIngo Weinholdclass CreateSemaphore : public WaitObjectTraceEntry {
34020ac568SIngo Weinholdpublic:
35020ac568SIngo Weinhold	CreateSemaphore(sem_id id, const char* name)
36020ac568SIngo Weinhold		:
37020ac568SIngo Weinhold		fID(id),
38020ac568SIngo Weinhold		fName(alloc_tracing_buffer_strcpy(name, 128, false))
39020ac568SIngo Weinhold	{
40020ac568SIngo Weinhold		Initialized();
41020ac568SIngo Weinhold	}
42020ac568SIngo Weinhold
43020ac568SIngo Weinhold	virtual void AddDump(TraceOutput& out)
44020ac568SIngo Weinhold	{
45251eb00dSFredrik Holmqvist		out.Print("sem create \"%s\" -> %" B_PRId32 "", fName, fID);
46020ac568SIngo Weinhold	}
47020ac568SIngo Weinhold
48020ac568SIngo Weinhold	virtual uint32 Type() const
49020ac568SIngo Weinhold	{
50020ac568SIngo Weinhold		return THREAD_BLOCK_TYPE_SEMAPHORE;
51020ac568SIngo Weinhold	}
52020ac568SIngo Weinhold
53020ac568SIngo Weinhold	virtual void* Object() const
54020ac568SIngo Weinhold	{
55020ac568SIngo Weinhold		return (void*)(addr_t)fID;
56020ac568SIngo Weinhold	}
57020ac568SIngo Weinhold
58020ac568SIngo Weinhold	virtual const char* Name() const
59020ac568SIngo Weinhold	{
60020ac568SIngo Weinhold		return fName;
61020ac568SIngo Weinhold	}
62020ac568SIngo Weinhold
63020ac568SIngo Weinholdprivate:
64020ac568SIngo Weinhold	sem_id		fID;
65020ac568SIngo Weinhold	const char*	fName;
66020ac568SIngo Weinhold};
67020ac568SIngo Weinhold
68020ac568SIngo Weinhold
69020ac568SIngo Weinholdclass InitConditionVariable : public WaitObjectTraceEntry {
70020ac568SIngo Weinholdpublic:
71020ac568SIngo Weinhold	InitConditionVariable(ConditionVariable* variable, const void* object,
72020ac568SIngo Weinhold		const char* objectType)
73020ac568SIngo Weinhold		:
74020ac568SIngo Weinhold		fVariable(variable),
75020ac568SIngo Weinhold		fObject(object),
76020ac568SIngo Weinhold		fObjectType(alloc_tracing_buffer_strcpy(objectType, 128, false))
77020ac568SIngo Weinhold	{
78020ac568SIngo Weinhold		Initialized();
79020ac568SIngo Weinhold	}
80020ac568SIngo Weinhold
81020ac568SIngo Weinhold	virtual void AddDump(TraceOutput& out)
82020ac568SIngo Weinhold	{
83020ac568SIngo Weinhold		out.Print("cvar init variable %p: object: %p \"%s\"", fVariable,
84020ac568SIngo Weinhold			fObject, fObjectType);
85020ac568SIngo Weinhold	}
86020ac568SIngo Weinhold
87020ac568SIngo Weinhold	virtual uint32 Type() const
88020ac568SIngo Weinhold	{
89020ac568SIngo Weinhold		return THREAD_BLOCK_TYPE_CONDITION_VARIABLE;
90020ac568SIngo Weinhold	}
91020ac568SIngo Weinhold
92020ac568SIngo Weinhold	virtual void* Object() const
93020ac568SIngo Weinhold	{
94020ac568SIngo Weinhold		return fVariable;
95020ac568SIngo Weinhold	}
96020ac568SIngo Weinhold
97020ac568SIngo Weinhold	virtual const char* Name() const
98020ac568SIngo Weinhold	{
99020ac568SIngo Weinhold		return fObjectType;
100020ac568SIngo Weinhold	}
101020ac568SIngo Weinhold
102020ac568SIngo Weinhold	virtual void* ReferencedObject() const
103020ac568SIngo Weinhold	{
104020ac568SIngo Weinhold		return (void*)fObject;
105020ac568SIngo Weinhold	}
106020ac568SIngo Weinhold
107020ac568SIngo Weinholdprivate:
108020ac568SIngo Weinhold	ConditionVariable*	fVariable;
109020ac568SIngo Weinhold	const void*			fObject;
110020ac568SIngo Weinhold	const char*			fObjectType;
111020ac568SIngo Weinhold};
112020ac568SIngo Weinhold
113020ac568SIngo Weinhold
114020ac568SIngo Weinholdclass InitMutex : public WaitObjectTraceEntry {
115020ac568SIngo Weinholdpublic:
116020ac568SIngo Weinhold	InitMutex(mutex* lock, const char* name)
117020ac568SIngo Weinhold		:
118020ac568SIngo Weinhold		fMutex(lock),
119020ac568SIngo Weinhold		fName(alloc_tracing_buffer_strcpy(name, 128, false))
120020ac568SIngo Weinhold	{
121020ac568SIngo Weinhold		Initialized();
122020ac568SIngo Weinhold	}
123020ac568SIngo Weinhold
124020ac568SIngo Weinhold	virtual void AddDump(TraceOutput& out)
125020ac568SIngo Weinhold	{
126020ac568SIngo Weinhold		out.Print("mutex init %p: name: \"%s\"", fMutex, fName);
127020ac568SIngo Weinhold	}
128020ac568SIngo Weinhold
129020ac568SIngo Weinhold	virtual uint32 Type() const
130020ac568SIngo Weinhold	{
131020ac568SIngo Weinhold		return THREAD_BLOCK_TYPE_MUTEX;
132020ac568SIngo Weinhold	}
133020ac568SIngo Weinhold
134020ac568SIngo Weinhold	virtual void* Object() const
135020ac568SIngo Weinhold	{
136020ac568SIngo Weinhold		return fMutex;
137020ac568SIngo Weinhold	}
138020ac568SIngo Weinhold
139020ac568SIngo Weinhold	virtual const char* Name() const
140020ac568SIngo Weinhold	{
141020ac568SIngo Weinhold		return fName;
142020ac568SIngo Weinhold	}
143020ac568SIngo Weinhold
144020ac568SIngo Weinholdprivate:
145020ac568SIngo Weinhold	mutex*		fMutex;
146020ac568SIngo Weinhold	const char*	fName;
147020ac568SIngo Weinhold};
148020ac568SIngo Weinhold
149020ac568SIngo Weinhold
150020ac568SIngo Weinholdclass InitRWLock : public WaitObjectTraceEntry {
151020ac568SIngo Weinholdpublic:
152020ac568SIngo Weinhold	InitRWLock(rw_lock* lock, const char* name)
153020ac568SIngo Weinhold		:
154020ac568SIngo Weinhold		fLock(lock),
155020ac568SIngo Weinhold		fName(alloc_tracing_buffer_strcpy(name, 128, false))
156020ac568SIngo Weinhold	{
157020ac568SIngo Weinhold		Initialized();
158020ac568SIngo Weinhold	}
159020ac568SIngo Weinhold
160020ac568SIngo Weinhold	virtual void AddDump(TraceOutput& out)
161020ac568SIngo Weinhold	{
162020ac568SIngo Weinhold		out.Print("rwlock init %p: name: \"%s\"", fLock, fName);
163020ac568SIngo Weinhold	}
164020ac568SIngo Weinhold
165020ac568SIngo Weinhold	virtual uint32 Type() const
166020ac568SIngo Weinhold	{
167020ac568SIngo Weinhold		return THREAD_BLOCK_TYPE_RW_LOCK;
168020ac568SIngo Weinhold	}
169020ac568SIngo Weinhold
170020ac568SIngo Weinhold	virtual void* Object() const
171020ac568SIngo Weinhold	{
172020ac568SIngo Weinhold		return fLock;
173020ac568SIngo Weinhold	}
174020ac568SIngo Weinhold
175020ac568SIngo Weinhold	virtual const char* Name() const
176020ac568SIngo Weinhold	{
177020ac568SIngo Weinhold		return fName;
178020ac568SIngo Weinhold	}
179020ac568SIngo Weinhold
180020ac568SIngo Weinholdprivate:
181020ac568SIngo Weinhold	rw_lock*	fLock;
182020ac568SIngo Weinhold	const char*	fName;
183020ac568SIngo Weinhold};
184020ac568SIngo Weinhold
185020ac568SIngo Weinhold}	// namespace SchedulingAnalysisTracing
186020ac568SIngo Weinhold
187020ac568SIngo Weinhold#	define T_SCHEDULING_ANALYSIS(x) \
188020ac568SIngo Weinhold		new(std::nothrow) SchedulingAnalysisTracing::x;
189020ac568SIngo Weinhold#else
190020ac568SIngo Weinhold#	define T_SCHEDULING_ANALYSIS(x) ;
191020ac568SIngo Weinhold#endif	// SCHEDULING_ANALYSIS_TRACING
192020ac568SIngo Weinhold
193020ac568SIngo Weinhold#endif	// _KERNEL_SCHEDULING_ANALYSIS_H
194