1 /* 2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _KERNEL_SCHEDULING_ANALYSIS_H 6 #define _KERNEL_SCHEDULING_ANALYSIS_H 7 8 #include <tracing.h> 9 #include <thread_defs.h> 10 11 12 struct ConditionVariable; 13 struct mutex; 14 struct rw_lock; 15 16 17 #if SCHEDULING_ANALYSIS_TRACING 18 namespace SchedulingAnalysisTracing { 19 20 class WaitObjectTraceEntry : public AbstractTraceEntry { 21 public: 22 virtual uint32 Type() const = 0; 23 virtual void* Object() const = 0; 24 virtual const char* Name() const = 0; 25 26 virtual void* ReferencedObject() const 27 { 28 return NULL; 29 } 30 }; 31 32 33 class CreateSemaphore : public WaitObjectTraceEntry { 34 public: 35 CreateSemaphore(sem_id id, const char* name) 36 : 37 fID(id), 38 fName(alloc_tracing_buffer_strcpy(name, 128, false)) 39 { 40 Initialized(); 41 } 42 43 virtual void AddDump(TraceOutput& out) 44 { 45 out.Print("sem create \"%s\" -> %" B_PRId32 "", fName, fID); 46 } 47 48 virtual uint32 Type() const 49 { 50 return THREAD_BLOCK_TYPE_SEMAPHORE; 51 } 52 53 virtual void* Object() const 54 { 55 return (void*)(addr_t)fID; 56 } 57 58 virtual const char* Name() const 59 { 60 return fName; 61 } 62 63 private: 64 sem_id fID; 65 const char* fName; 66 }; 67 68 69 class InitConditionVariable : public WaitObjectTraceEntry { 70 public: 71 InitConditionVariable(ConditionVariable* variable, const void* object, 72 const char* objectType) 73 : 74 fVariable(variable), 75 fObject(object), 76 fObjectType(alloc_tracing_buffer_strcpy(objectType, 128, false)) 77 { 78 Initialized(); 79 } 80 81 virtual void AddDump(TraceOutput& out) 82 { 83 out.Print("cvar init variable %p: object: %p \"%s\"", fVariable, 84 fObject, fObjectType); 85 } 86 87 virtual uint32 Type() const 88 { 89 return THREAD_BLOCK_TYPE_CONDITION_VARIABLE; 90 } 91 92 virtual void* Object() const 93 { 94 return fVariable; 95 } 96 97 virtual const char* Name() const 98 { 99 return fObjectType; 100 } 101 102 virtual void* ReferencedObject() const 103 { 104 return (void*)fObject; 105 } 106 107 private: 108 ConditionVariable* fVariable; 109 const void* fObject; 110 const char* fObjectType; 111 }; 112 113 114 class InitMutex : public WaitObjectTraceEntry { 115 public: 116 InitMutex(mutex* lock, const char* name) 117 : 118 fMutex(lock), 119 fName(alloc_tracing_buffer_strcpy(name, 128, false)) 120 { 121 Initialized(); 122 } 123 124 virtual void AddDump(TraceOutput& out) 125 { 126 out.Print("mutex init %p: name: \"%s\"", fMutex, fName); 127 } 128 129 virtual uint32 Type() const 130 { 131 return THREAD_BLOCK_TYPE_MUTEX; 132 } 133 134 virtual void* Object() const 135 { 136 return fMutex; 137 } 138 139 virtual const char* Name() const 140 { 141 return fName; 142 } 143 144 private: 145 mutex* fMutex; 146 const char* fName; 147 }; 148 149 150 class InitRWLock : public WaitObjectTraceEntry { 151 public: 152 InitRWLock(rw_lock* lock, const char* name) 153 : 154 fLock(lock), 155 fName(alloc_tracing_buffer_strcpy(name, 128, false)) 156 { 157 Initialized(); 158 } 159 160 virtual void AddDump(TraceOutput& out) 161 { 162 out.Print("rwlock init %p: name: \"%s\"", fLock, fName); 163 } 164 165 virtual uint32 Type() const 166 { 167 return THREAD_BLOCK_TYPE_RW_LOCK; 168 } 169 170 virtual void* Object() const 171 { 172 return fLock; 173 } 174 175 virtual const char* Name() const 176 { 177 return fName; 178 } 179 180 private: 181 rw_lock* fLock; 182 const char* fName; 183 }; 184 185 } // namespace SchedulingAnalysisTracing 186 187 # define T_SCHEDULING_ANALYSIS(x) \ 188 new(std::nothrow) SchedulingAnalysisTracing::x; 189 #else 190 # define T_SCHEDULING_ANALYSIS(x) ; 191 #endif // SCHEDULING_ANALYSIS_TRACING 192 193 #endif // _KERNEL_SCHEDULING_ANALYSIS_H 194