The Pedigree Project 0.1
TimeTracker.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 _PROCESS_TIME_TRACKER_H
21#define _PROCESS_TIME_TRACKER_H
22#include "pedigree/kernel/compiler.h"
23
24#include <config.h>
25#include <stddef.h>
26
27class Process;
28class Thread;
29
37 public:
38 // Expose member initialization so stack auto-initialization does not fill
39 // the whole object before the constructor writes the same fields.
40 ALWAYS_INLINE TimeTracker(Process* pProcess, bool fromUserspace,
41 bool entryInterruptsAlreadyDisabled = false,
42 Thread* currentThread = nullptr)
43 : m_pProcess(pProcess),
44 m_pThread(currentThread),
45 m_bFromUserspace(fromUserspace)
46#if PEDIGREE_BENCHMARK_SYSCALL_TIMING
47 ,
48 m_bSyscallAttributed(false),
49 m_PreviousSyscallTimingSlot(~static_cast<size_t>(0))
50#endif
51 {
52 initialise(entryInterruptsAlreadyDisabled);
53 }
55 if (m_pProcess && m_pThread)
56 finish();
57 }
58
60 void finish();
61
63 void finishInKernel();
64
67#if PEDIGREE_BENCHMARK_SYSCALL_TIMING
68 if (m_bSyscallAttributed) {
69 // Publish the final attributed interval before clearing its syscall slot.
71 return;
72 }
73#endif
74 Thread* thread = m_pThread;
75 if (!m_pProcess || !thread)
76 return;
77
78 // The architecture tail owns the final accounting sample. Keep retirement
79 // visible here so destruction can omit a second completion attempt.
80 m_pProcess = nullptr;
81 m_pThread = nullptr;
82#if PEDIGREE_BENCHMARK_SYSCALL_TIMING
83 restoreSyscallTiming(thread);
84#endif
85 }
86
88 void attributeSyscall(size_t rawNumber);
89
90 private:
91 void initialise(bool entryInterruptsAlreadyDisabled);
92#if PEDIGREE_BENCHMARK_SYSCALL_TIMING
93 void restoreSyscallTiming(Thread* thread);
94#endif
95
96 Process* m_pProcess;
97 Thread* m_pThread;
98 bool m_bFromUserspace;
99#if PEDIGREE_BENCHMARK_SYSCALL_TIMING
100 bool m_bSyscallAttributed;
101 size_t m_PreviousSyscallTimingSlot;
102#endif
103};
104
105#endif
void attributeSyscall(size_t rawNumber)
void finishInKernel()
void finish()
ALWAYS_INLINE void finishForUserReturn()
Definition TimeTracker.h:66