1 //===-- SubprocessMemory.h --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// 9 /// \file 10 /// Defines a class that automatically handles auxiliary memory and the 11 /// underlying shared memory backings for memory definitions 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_SUBPROCESSMEMORY_H 16 #define LLVM_TOOLS_LLVM_EXEGESIS_SUBPROCESSMEMORY_H 17 18 #include "BenchmarkResult.h" 19 #include <string> 20 #include <unordered_map> 21 #include <vector> 22 23 #ifdef _MSC_VER 24 typedef int pid_t; 25 #else 26 #include <sys/types.h> 27 #endif // _MSC_VER 28 29 30 namespace llvm { 31 namespace exegesis { 32 33 class SubprocessMemory { 34 public: 35 static constexpr const size_t AuxiliaryMemoryOffset = 1; 36 static constexpr const size_t AuxiliaryMemorySize = 4096; 37 38 Error initializeSubprocessMemory(pid_t ProcessID); 39 40 // The following function sets up memory definitions. It creates shared 41 // memory objects for the definitions and fills them with the specified 42 // values. Arguments: MemoryDefinitions - A map from memory value names to 43 // MemoryValues, ProcessID - The ID of the current process. 44 Error addMemoryDefinition( 45 std::unordered_map<std::string, MemoryValue> MemoryDefinitions, 46 pid_t ProcessID); 47 48 // The following function sets up the auxiliary memory by opening shared 49 // memory objects backing memory definitions and putting file descriptors 50 // into appropriate places. Arguments: MemoryDefinitions - A map from memory 51 // values names to Memoryvalues, ParentPID - The ID of the process that 52 // setup the memory definitions, CounterFileDescriptor - The file descriptor 53 // for the performance counter that will be placed in the auxiliary memory 54 // section. 55 static Expected<int> setupAuxiliaryMemoryInSubprocess( 56 std::unordered_map<std::string, MemoryValue> MemoryDefinitions, 57 pid_t ParentPID, uint64_t ParentTID, int CounterFileDescriptor); 58 59 ~SubprocessMemory(); 60 61 private: 62 std::vector<std::string> SharedMemoryNames; 63 }; 64 65 } // namespace exegesis 66 } // namespace llvm 67 68 #endif 69