1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_DRM_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_DRM_TRACKER_H_ 19 20 #include <cstdint> 21 #include <deque> 22 #include <memory> 23 24 #include "perfetto/ext/base/flat_hash_map.h" 25 #include "perfetto/ext/base/string_view.h" 26 #include "perfetto/protozero/field.h" 27 #include "src/trace_processor/storage/trace_storage.h" 28 29 namespace perfetto::trace_processor { 30 31 class TraceProcessorContext; 32 33 class DrmTracker { 34 public: 35 explicit DrmTracker(TraceProcessorContext*); 36 37 void ParseDrm(int64_t timestamp, 38 uint32_t field_id, 39 uint32_t pid, 40 protozero::ConstBytes blob); 41 42 private: 43 void DrmVblankEvent(int64_t timestamp, int32_t crtc, uint32_t seqno); 44 void DrmVblankEventDelivered(int64_t timestamp, int32_t crtc, uint32_t seqno); 45 46 struct SchedRing { 47 TrackId track_id; 48 std::deque<uint64_t> running_jobs; 49 50 base::FlatHashMap<uint64_t, SliceId> out_slice_ids; 51 }; 52 SchedRing& GetSchedRingByName(base::StringView name); 53 void BeginSchedRingSlice(int64_t timestamp, SchedRing& ring); 54 55 void DrmSchedJob(int64_t timestamp, 56 uint32_t pid, 57 base::StringView name, 58 uint64_t job_id); 59 void DrmRunJob(int64_t timestamp, 60 base::StringView name, 61 uint64_t job_id, 62 uint64_t fence_id); 63 void DrmSchedProcessJob(int64_t timestamp, uint64_t fence_id); 64 65 struct FenceTimeline { 66 TrackId track_id; 67 bool has_dma_fence_emit; 68 std::deque<uint32_t> pending_fences; 69 }; 70 FenceTimeline& GetFenceTimelineByContext(uint32_t context, 71 base::StringView name); 72 void BeginFenceTimelineSlice(int64_t timestamp, 73 const FenceTimeline& timeline); 74 75 void DmaFenceInit(int64_t timestamp, 76 base::StringView name, 77 uint32_t context, 78 uint32_t seqno); 79 void DmaFenceEmit(int64_t timestamp, 80 base::StringView name, 81 uint32_t context, 82 uint32_t seqno); 83 void DmaFenceSignaled(int64_t timestamp, 84 base::StringView name, 85 uint32_t context, 86 uint32_t seqno); 87 void DmaFenceWaitStart(int64_t timestamp, 88 uint32_t pid, 89 uint32_t context, 90 uint32_t seqno); 91 void DmaFenceWaitEnd(int64_t timestamp, uint32_t pid); 92 93 TraceProcessorContext* const context_; 94 95 const StringId vblank_slice_signal_id_; 96 const StringId vblank_slice_deliver_id_; 97 const StringId vblank_arg_seqno_id_; 98 const StringId sched_slice_schedule_id_; 99 const StringId sched_slice_job_id_; 100 const StringId sched_arg_ring_id_; 101 const StringId sched_arg_job_id_; 102 const StringId fence_slice_fence_id_; 103 const StringId fence_slice_wait_id_; 104 const StringId fence_arg_context_id_; 105 const StringId fence_arg_seqno_id_; 106 107 base::FlatHashMap<base::StringView, std::unique_ptr<SchedRing>> sched_rings_; 108 base::FlatHashMap<uint64_t, SchedRing*> sched_pending_fences_; 109 110 base::FlatHashMap<uint32_t, std::unique_ptr<FenceTimeline>> fence_timelines_; 111 }; 112 113 } // namespace perfetto::trace_processor 114 115 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_DRM_TRACKER_H_ 116