quic/qbox
Loading...
Searching...
No Matches
qkmultithread.h
1/*
2 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 * Author: GreenSocs 2022
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef QKMULTITHREAD_H
9#define QKMULTITHREAD_H
10
11#include <mutex>
12#include <condition_variable>
13#include <atomic>
14#include <systemc>
15#include <tlm>
16#include <scp/report.h>
17#include <tlm_utils/tlm_quantumkeeper.h>
18#include <async_event.h>
19#include <qk_extendedif.h>
20
21namespace gs {
22// somewhat tuned multiple threaded QK
24{
25 SCP_LOGGER();
26 std::thread::id m_systemc_thread_id;
27 std::mutex mutex;
28 std::condition_variable cond;
29 std::thread m_worker_thread;
30
31protected:
32 bool m_systemc_waiting;
33 bool m_extern_waiting;
34 async_event m_tick;
35
36 virtual bool is_sysc_thread() const;
37
38private:
39 void timehandler();
40
41public:
44
45 virtual SyncPolicy::Type get_thread_type() const override { return SyncPolicy::OS_THREAD; }
46
47 /* cleanly start and stop, with optional 'job' to start */
48 virtual void start(std::function<void()> job = nullptr) override;
49 virtual void stop() override;
50
51 /* convenience for initiators to evaluate budget */
52 virtual sc_core::sc_time time_to_sync() override;
53
54 /* standard TLM2 API */
55 void inc(const sc_core::sc_time& t) override;
56 void set(const sc_core::sc_time& t) override;
57 virtual void sync() override;
58 void reset() override;
59 sc_core::sc_time get_current_time() const override;
60 sc_core::sc_time get_local_time() const override;
61
62 /* non-const need_sync */
63 virtual bool need_sync() override;
64
65 // only NONE, RUNNING and STOPPED will be used by the model, the rest are for debug
66 enum jobstates { NONE = 0, RUNNING = 1, STOPPED = 2, SYSC_WAITING = 4, EXT_WAITING = 8, ILLEGAL = 12 };
67 std::atomic<jobstates> status;
68 // MAKE THIS INTO A CCI_PARAM, and provide to_json in the 'normal' way !!!!!
69
70 // this function provided only for debug.
71 jobstates get_status() { return (jobstates)(status | (m_systemc_waiting << 2) | (m_extern_waiting << 3)); }
72 std::string get_status_json()
73 {
74 std::string s = "\"name\":\"" + std::string(name()) + "\"";
75 s = s + ",\"quantum_time\":\"" + std::string(get_local_time().to_string()) + "\"";
76 s = s + ",\"local_time\":\"" + std::string(get_current_time().to_string()) + "\"";
77 if ((status & (RUNNING | STOPPED)) == NONE) s = s + ",\"state\":\"NONE\"";
78 if (status & RUNNING) s = s + ",\"state\":\"RUNNING\"";
79 if (status & STOPPED) s = s + ",\"state\":\"IDLE\"";
80 if (m_systemc_waiting) s = s + ",\"sc_waiting\":true";
81 if (m_extern_waiting) s = s + ",\"extern_waiting\":true";
82 return "{" + s + "}";
83 }
84};
85
86static std::vector<gs::tlm_quantumkeeper_multithread*> find_all_tlm_quantumkeeper_multithread()
87{
89}
90
91} // namespace gs
92#endif // QKMULTITHREAD_H
Definition target.h:160
Definition async_event.h:22
Definition qk_extendedif.h:34
Definition qkmultithread.h:24
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10