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 #ifndef __linux__ 24 typedef int pid_t; 25 #endif // __linux__ 26 27 namespace llvm { 28 namespace exegesis { 29 30 class SubprocessMemory { 31 public: 32 static constexpr const size_t AuxiliaryMemoryOffset = 1; 33 static constexpr const size_t AuxiliaryMemorySize = 4096; 34 35 Error initializeSubprocessMemory(pid_t ProcessID); 36 37 // The following function sets up memory definitions. It creates shared 38 // memory objects for the definitions and fills them with the specified 39 // values. Arguments: MemoryDefinitions - A map from memory value names to 40 // MemoryValues, ProcessID - The ID of the current process. 41 Error addMemoryDefinition( 42 std::unordered_map<std::string, MemoryValue> MemoryDefinitions, 43 pid_t ProcessID); 44 45 // The following function sets up the auxiliary memory by opening shared 46 // memory objects backing memory definitions and putting file descriptors 47 // into appropriate places. Arguments: MemoryDefinitions - A map from memory 48 // values names to Memoryvalues, ParentPID - The ID of the process that 49 // setup the memory definitions, CounterFileDescriptor - The file descriptor 50 // for the performance counter that will be placed in the auxiliary memory 51 // section. 52 static Expected<int> setupAuxiliaryMemoryInSubprocess( 53 std::unordered_map<std::string, MemoryValue> MemoryDefinitions, 54 pid_t ParentPID, int CounterFileDescriptor); 55 56 ~SubprocessMemory(); 57 58 private: 59 std::vector<std::string> SharedMemoryNames; 60 }; 61 62 } // namespace exegesis 63 } // namespace llvm 64 65 #endif 66