• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef FFRT_QUEUE_MONITOR_H
16 #define FFRT_QUEUE_MONITOR_H
17 
18 #include <vector>
19 #include <sstream>
20 #include <shared_mutex>
21 #include "util/slab.h"
22 #include "sched/execute_ctx.h"
23 #include "tm/queue_task.h"
24 
25 namespace ffrt {
26 class QueueHandler;
27 class QueueMonitor {
28 public:
29     static QueueMonitor &GetInstance();
30     void RegisterQueue(QueueHandler* queue);
31     void DeregisterQueue(QueueHandler* queue);
32     void UpdateQueueInfo();
33     std::string DumpQueueTimeoutInfo();
34 
35 private:
36     QueueMonitor();
37     ~QueueMonitor();
38     QueueMonitor(const QueueMonitor &) = delete;
39     QueueMonitor(QueueMonitor &&) = delete;
40     QueueMonitor &operator=(const QueueMonitor &) = delete;
41     QueueMonitor &operator=(QueueMonitor &&) = delete;
42 
43     void SetAlarm(uint64_t steadyUs);
44     void ScheduleAlarm();
45     void CheckTimeout(uint64_t& nextTaskStart);
46     void ReportEventTimeout(uint64_t curGid, const std::stringstream& ss);
47     void UpdateTimeoutUs();
48 
49     WaitUntilEntry* we_ = nullptr;
50     std::atomic<uint64_t> timeoutUs_ = 0;
51     std::stringstream timeoutMSG_;
52     std::shared_mutex infoMutex_;
53     std::atomic_bool suspendAlarm_ = {true};
54     std::vector<QueueHandler*> queuesInfo_;
55     std::vector<std::pair<uint64_t, std::string>> taskTimeoutInfo_;
56 };
57 } // namespace ffrt
58 
59 #endif // FFRT_QUEUE_MONITOR_H
60