Skip to content

Commit

Permalink
Add instruction address metadata to vivisect broker
Browse files Browse the repository at this point in the history
  • Loading branch information
andrej committed Nov 16, 2024
1 parent aa8b54e commit 6f97ace
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 236 deletions.
17 changes: 13 additions & 4 deletions MetadataCategories.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@
#define LLVM_MCA_METADATACATEGORIES_H
namespace llvm {
namespace mcad {

enum MetadataCategories {

// Metadata for LSUnit
static constexpr unsigned MD_LSUnit_MemAccess = 0;
MD_LSUnit_MemAccess = 0,

// Metadata for Branch Prediction
static constexpr unsigned MD_FrontEnd_BranchFlow = 1;
MD_FrontEnd_BranchFlow = 1,

// Virtual address at which an instruction is located in memory
MD_InstrAddr = 2,

// Used for marking the start of custom MD Category
static constexpr unsigned MD_LAST = MD_FrontEnd_BranchFlow;
MD_LAST,

// Metadata categories (custom)
static constexpr unsigned MD_BinaryRegionMarkers = MD_LAST + 1;
MD_BinaryRegionMarkers

};

} // end namespace mcad
} // end namespace llvm
#endif
52 changes: 33 additions & 19 deletions plugins/vivisect-broker/Broker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,40 @@ class VivisectBroker : public Broker {

MCIS[i] = &MCI; // return a pointer into our MCI_Pool

if (MDE && insn.has_memory_access()) {
auto MemAccess = insn.memory_access();
auto &Registry = MDE->MDRegistry;
auto &IndexMap = MDE->IndexMap;
auto &MemAccessCat = Registry[MD_LSUnit_MemAccess];
IndexMap[i] = TotalNumTraces;
MemAccessCat[TotalNumTraces] = std::move(MDMemoryAccess{
MemAccess.is_store(),
MemAccess.vaddr(),
MemAccess.size(),
});
}
// Add metadata to the fetched instruction if metadata exchanger
// is available
if (MDE) {

// The registry stores the metadata
auto &Registry = MDE->MDRegistry;

// The IndexMap maps instruction index (within this region) to
// the identifier we chose for our metadata. We chose a
// monotonically increasing counter as the identifier for each
// metadata entry.
auto &IndexMap = MDE->IndexMap;
IndexMap[i] = TotalNumTraces;

auto &InstrAddrCat = Registry[MD_InstrAddr];
InstrAddrCat[TotalNumTraces] = insn.addr();

if (insn.has_memory_access()) {
auto MemAccess = insn.memory_access();
auto &MemAccessCat = Registry[MD_LSUnit_MemAccess];
MemAccessCat[TotalNumTraces] = std::move(MDMemoryAccess{
MemAccess.is_store(),
MemAccess.vaddr(),
MemAccess.size(),
});
}

if (insn.has_branch_flow()) {
auto BranchFlow = insn.branch_flow();
auto &Registry = MDE->MDRegistry;
auto &BranchFlowCat = Registry[MD_FrontEnd_BranchFlow];
BranchFlowCat[TotalNumTraces] = BranchFlow.is_mispredict();
}

if (MDE && insn.has_branch_flow()) {
auto BranchFlow = insn.branch_flow();
auto &Registry = MDE->MDRegistry;
auto &IndexMap = MDE->IndexMap;
auto &BranchFlowCat = Registry[MD_FrontEnd_BranchFlow];
IndexMap[i] = TotalNumTraces;
BranchFlowCat[TotalNumTraces] = BranchFlow.is_mispredict();
}

++TotalNumTraces;
Expand Down
2 changes: 1 addition & 1 deletion plugins/vivisect-broker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ C++-based server and a python client. To update them, edit the interface
`emulator.proto` and rerun the following.

```
python3 -m grpc_tools.protoc -I. --python_out=. --pyi_out=. --grpc_python_out=. emulator.proto
python3 -m grpc_tools.protoc -I. --python_out=grpc_client --pyi_out=grpc_client --grpc_python_out=grpc_client emulator.proto
protoc --grpc_out=. --cpp_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` emulator.proto
```

Expand Down
101 changes: 64 additions & 37 deletions plugins/vivisect-broker/emulator.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6f97ace

Please sign in to comment.