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 <deque> 21 #include <memory> 22 23 #include "perfetto/ext/base/flat_hash_map.h" 24 #include "perfetto/ext/base/string_view.h" 25 #include "perfetto/protozero/field.h" 26 #include "src/trace_processor/storage/trace_storage.h" 27 28 namespace perfetto { 29 namespace 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 TrackId InternVblankTrack(int32_t crtc); 44 void DrmVblankEvent(int64_t timestamp, int32_t crtc, uint32_t seqno); 45 void DrmVblankEventDelivered(int64_t timestamp, int32_t crtc, uint32_t seqno); 46 47 struct SchedRing { 48 TrackId track_id; 49 std::deque<uint64_t> running_jobs; 50 51 base::FlatHashMap<uint64_t, SliceId> out_slice_ids; 52 }; 53 SchedRing& GetSchedRingByName(base::StringView name); 54 void BeginSchedRingSlice(int64_t timestamp, SchedRing& ring); 55 56 void DrmSchedJob(int64_t timestamp, 57 uint32_t pid, 58 base::StringView name, 59 uint64_t job_id); 60 void DrmRunJob(int64_t timestamp, 61 base::StringView name, 62 uint64_t job_id, 63 uint64_t fence_id); 64 void DrmSchedProcessJob(int64_t timestamp, uint64_t fence_id); 65 66 struct FenceTimeline { 67 TrackId track_id; 68 bool has_dma_fence_emit; 69 std::deque<uint32_t> pending_fences; 70 }; 71 FenceTimeline& GetFenceTimelineByContext(uint32_t context, 72 base::StringView name); 73 void BeginFenceTimelineSlice(int64_t timestamp, 74 const FenceTimeline& timeline); 75 76 void DmaFenceInit(int64_t timestamp, 77 base::StringView name, 78 uint32_t context, 79 uint32_t seqno); 80 void DmaFenceEmit(int64_t timestamp, 81 base::StringView name, 82 uint32_t context, 83 uint32_t seqno); 84 void DmaFenceSignaled(int64_t timestamp, 85 base::StringView name, 86 uint32_t context, 87 uint32_t seqno); 88 void DmaFenceWaitStart(int64_t timestamp, 89 uint32_t pid, 90 uint32_t context, 91 uint32_t seqno); 92 void DmaFenceWaitEnd(int64_t timestamp, uint32_t pid); 93 94 TraceProcessorContext* const context_; 95 96 const StringId vblank_slice_signal_id_; 97 const StringId vblank_slice_deliver_id_; 98 const StringId vblank_arg_seqno_id_; 99 const StringId sched_slice_schedule_id_; 100 const StringId sched_slice_job_id_; 101 const StringId sched_arg_ring_id_; 102 const StringId sched_arg_job_id_; 103 const StringId fence_slice_fence_id_; 104 const StringId fence_slice_wait_id_; 105 const StringId fence_arg_context_id_; 106 const StringId fence_arg_seqno_id_; 107 108 base::FlatHashMap<base::StringView, std::unique_ptr<SchedRing>> sched_rings_; 109 base::FlatHashMap<uint64_t, SchedRing*> sched_pending_fences_; 110 111 base::FlatHashMap<uint32_t, std::unique_ptr<FenceTimeline>> fence_timelines_; 112 }; 113 114 } // namespace trace_processor 115 } // namespace perfetto 116 117 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_DRM_TRACKER_H_ 118