Commit b232fbf8 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

refactor: use C-style commenting everywhere

parent ff302030
......@@ -36,7 +36,7 @@ size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags)
if (!str)
return 0;
len = strlen(str); // not \0 terminated
len = strlen(str); /* not \0 terminated */
if (buffer && len <= size)
memcpy(buffer, str, len);
......
......@@ -99,7 +99,7 @@ void hist_put(struct hist *h, double value)
h->_m[0] = h->_m[1] + (value - h->_m[1]) / h->total;
h->_s[0] = h->_s[1] + (value - h->_m[1]) * (value - h->_m[0]);
// set up for next iteration
/* Set up for next iteration */
h->_m[1] = h->_m[0];
h->_s[1] = h->_s[0];
}
......
......@@ -134,12 +134,12 @@ int kernel_module_load(const char *module)
pid_t pid = fork();
switch (pid) {
case -1: // error
case -1: /* error */
return -1;
case 0: // child
case 0: /* child */
execlp("modprobe", "modprobe", module, (char *) 0);
exit(EXIT_FAILURE); // exec never returns
exit(EXIT_FAILURE); /* exec never returns */
default:
wait(&ret);
......
......@@ -50,8 +50,7 @@ int pci_init(struct pci *p)
}
while ((e = readdir(dp))) {
// ignore special entries
/* Ignore special entries */
if ((strcmp(e->d_name, ".") == 0) ||
(strcmp(e->d_name, "..") == 0) )
continue;
......@@ -244,8 +243,7 @@ int pci_device_compare(const struct pci_device *d, const struct pci_device *f)
if ((f->id.class_code != 0) || (f->id.class_code != d->id.class_code))
return 1;
// found
return 0;
return 0; /* found */
}
struct pci_device * pci_lookup_device(struct pci *p, struct pci_device *f)
......@@ -276,7 +274,8 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions)
size_t len = 0;
int region = 0;
// cap to 8 regions, just because we don't know how many may exist
/* Cap to 8 regions, just because we don't know how many may exist. */
while(region < 8 && (bytesRead = getline(&line, &len, f)) != -1) {
unsigned long long tokens[3];
char* s = line;
......@@ -285,7 +284,7 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions)
tokens[i] = strtoull(s, &end, 16);
if(s == end) {
printf("Error parsing line %d of %s\n", region + 1, sysfs);
tokens[0] = tokens[1] = 0; // mark invalid
tokens[0] = tokens[1] = 0; /* Mark invalid */
break;
}
s = end;
......@@ -293,12 +292,12 @@ size_t pci_get_regions(const struct pci_device *d, struct pci_region** regions)
free(line);
// required for getline() to allocate a new buffer on the next iteration
/* Required for getline() to allocate a new buffer on the next iteration. */
line = NULL;
len = 0;
if(tokens[0] != tokens[1]) {
// this is a valid region
/* This is a valid region */
cur_region->num = region;
cur_region->start = tokens[0];
cur_region->end = tokens[1];
......
......@@ -129,6 +129,6 @@ bool isPreemptible()
#endif /* __linux__ */
} // namespace villas
} // namespace kernel
} // namespace rt
} /* namespace villas */
} /* namespace kernel */
} /* namespace rt */
......@@ -22,23 +22,23 @@
#include <villas/kernel/pci.h>
static const char *vfio_pci_region_names[] = {
"PCI_BAR0", // VFIO_PCI_BAR0_REGION_INDEX,
"PCI_BAR1", // VFIO_PCI_BAR1_REGION_INDEX,
"PCI_BAR2", // VFIO_PCI_BAR2_REGION_INDEX,
"PCI_BAR3", // VFIO_PCI_BAR3_REGION_INDEX,
"PCI_BAR4", // VFIO_PCI_BAR4_REGION_INDEX,
"PCI_BAR5", // VFIO_PCI_BAR5_REGION_INDEX,
"PCI_ROM", // VFIO_PCI_ROM_REGION_INDEX,
"PCI_CONFIG", // VFIO_PCI_CONFIG_REGION_INDEX,
"PCI_VGA" // VFIO_PCI_INTX_IRQ_INDEX,
"PCI_BAR0", /* VFIO_PCI_BAR0_REGION_INDEX */
"PCI_BAR1", /* VFIO_PCI_BAR1_REGION_INDEX */
"PCI_BAR2", /* VFIO_PCI_BAR2_REGION_INDEX */
"PCI_BAR3", /* VFIO_PCI_BAR3_REGION_INDEX */
"PCI_BAR4", /* VFIO_PCI_BAR4_REGION_INDEX */
"PCI_BAR5", /* VFIO_PCI_BAR5_REGION_INDEX */
"PCI_ROM", /* VFIO_PCI_ROM_REGION_INDEX */
"PCI_CONFIG", /* VFIO_PCI_CONFIG_REGION_INDEX */
"PCI_VGA" /* VFIO_PCI_INTX_IRQ_INDEX */
};
static const char *vfio_pci_irq_names[] = {
"PCI_INTX", // VFIO_PCI_INTX_IRQ_INDEX,
"PCI_MSI", // VFIO_PCI_MSI_IRQ_INDEX,
"PCI_MSIX", // VFIO_PCI_MSIX_IRQ_INDEX,
"PCI_ERR", // VFIO_PCI_ERR_IRQ_INDEX,
"PCI_REQ" // VFIO_PCI_REQ_IRQ_INDEX,
"PCI_INTX", /* VFIO_PCI_INTX_IRQ_INDEX */
"PCI_MSI", /* VFIO_PCI_MSI_IRQ_INDEX */
"PCI_MSIX", /* VFIO_PCI_MSIX_IRQ_INDEX */
"PCI_ERR", /* VFIO_PCI_ERR_IRQ_INDEX */
"PCI_REQ" /* VFIO_PCI_REQ_IRQ_INDEX */
};
/* Helpers */
......
......@@ -52,23 +52,23 @@
using namespace villas;
static const char *vfio_pci_region_names[] = {
"PCI_BAR0", // VFIO_PCI_BAR0_REGION_INDEX,
"PCI_BAR1", // VFIO_PCI_BAR1_REGION_INDEX,
"PCI_BAR2", // VFIO_PCI_BAR2_REGION_INDEX,
"PCI_BAR3", // VFIO_PCI_BAR3_REGION_INDEX,
"PCI_BAR4", // VFIO_PCI_BAR4_REGION_INDEX,
"PCI_BAR5", // VFIO_PCI_BAR5_REGION_INDEX,
"PCI_ROM", // VFIO_PCI_ROM_REGION_INDEX,
"PCI_CONFIG", // VFIO_PCI_CONFIG_REGION_INDEX,
"PCI_VGA" // VFIO_PCI_INTX_IRQ_INDEX,
"PCI_BAR0", /* VFIO_PCI_BAR0_REGION_INDEX */
"PCI_BAR1", /* VFIO_PCI_BAR1_REGION_INDEX */
"PCI_BAR2", /* VFIO_PCI_BAR2_REGION_INDEX */
"PCI_BAR3", /* VFIO_PCI_BAR3_REGION_INDEX */
"PCI_BAR4", /* VFIO_PCI_BAR4_REGION_INDEX */
"PCI_BAR5", /* VFIO_PCI_BAR5_REGION_INDEX */
"PCI_ROM", /* VFIO_PCI_ROM_REGION_INDEX */
"PCI_CONFIG", /* VFIO_PCI_CONFIG_REGION_INDEX */
"PCI_VGA" /* VFIO_PCI_INTX_IRQ_INDEX */
};
static const char *vfio_pci_irq_names[] = {
"PCI_INTX", // VFIO_PCI_INTX_IRQ_INDEX,
"PCI_MSI", // VFIO_PCI_MSI_IRQ_INDEX,
"PCI_MSIX", // VFIO_PCI_MSIX_IRQ_INDEX,
"PCI_ERR", // VFIO_PCI_ERR_IRQ_INDEX,
"PCI_REQ" // VFIO_PCI_REQ_IRQ_INDEX,
"PCI_INTX", /* VFIO_PCI_INTX_IRQ_INDEX */
"PCI_MSI", /* VFIO_PCI_MSI_IRQ_INDEX */
"PCI_MSIX", /* VFIO_PCI_MSIX_IRQ_INDEX */
"PCI_ERR", /* VFIO_PCI_ERR_IRQ_INDEX */
"PCI_REQ" /* VFIO_PCI_REQ_IRQ_INDEX */
};
namespace villas {
......@@ -243,7 +243,7 @@ VfioContainer::attachDevice(const char* name, int index)
logger->debug("Device has {} regions", device->info.num_regions);
logger->debug("Device has {} IRQs", device->info.num_irqs);
// reserve slots already so that we can use the []-operator for access
/* Reserve slots already so that we can use the []-operator for access */
device->irqs.resize(device->info.num_irqs);
device->regions.resize(device->info.num_regions);
device->mappings.resize(device->info.num_regions);
......@@ -383,11 +383,12 @@ VfioContainer::memoryMap(uintptr_t virt, uintptr_t phys, size_t length)
logger->debug("DMA map size={:#x}, iova={:#x}, vaddr={:#x}",
dmaMap.size, dmaMap.iova, dmaMap.vaddr);
// mapping successful, advance IOVA allocator
/* Mapping successful, advance IOVA allocator */
this->iova_next += iovaIncrement;
// we intentionally don't return the actual mapped length, the users are
// only guaranteed to have their demanded memory mapped correctly
/* We intentionally don't return the actual mapped length, the users are
* only guaranteed to have their demanded memory mapped correctly
*/
return dmaMap.iova;
}
......@@ -423,14 +424,14 @@ VfioContainer::getOrAttachGroup(int index)
{
Logger logger = logging.get("kernel:vfio");
// search if group with index already exists
/* Search if group with index already exists */
for (auto& group : groups) {
if(group->index == index) {
return *group;
}
}
// group not yet part of this container, so acquire ownership
/* Group not yet part of this container, so acquire ownership */
auto group = VfioGroup::attach(*this, index);
if (not group) {
logger->error("Failed to attach to IOMMU group: {}", index);
......@@ -439,7 +440,7 @@ VfioContainer::getOrAttachGroup(int index)
logger->debug("Attached new group {} to VFIO container", index);
}
// push to our list
/* Push to our list */
groups.push_back(std::move(group));
return *groups.back();
......@@ -837,5 +838,5 @@ VfioGroup::attach(VfioContainer& container, int groupIndex)
return group;
}
} // namespace villas
} /* namespace villas */
......@@ -47,7 +47,7 @@ Log::Log(Level lvl) :
setLevel(level);
setPattern(pattern);
// Default sink
/* Default sink */
sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
sinks->add_sink(sink);
......
......@@ -53,7 +53,7 @@ HostRam::HostRamAllocator::allocateBlock(size_t size)
auto& mm = MemoryManager::get();
// assemble name for this block
/* Assemble name for this block */
std::stringstream name;
name << std::showbase << std::hex << reinterpret_cast<uintptr_t>(addr);
......@@ -78,7 +78,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId
internalOffset(internalOffset),
allocationCount(0)
{
// make sure to start at aligned offset, reduce size in case we need padding
/* Make sure to start at aligned offset, reduce size in case we need padding */
if(const size_t paddingBytes = getAlignmentPadding(internalOffset)) {
assert(paddingBytes < memorySize);
......@@ -86,7 +86,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId
memorySize -= paddingBytes;
}
// deallocation callback
/* Deallocation callback */
free = [&](MemoryBlock* mem) {
logger->debug("Deallocating memory block at local addr {:#x} (addr space {})",
mem->getOffset(), mem->getAddrSpaceId());
......@@ -97,7 +97,7 @@ LinearAllocator::LinearAllocator(MemoryManager::AddressSpaceId memoryAddrSpaceId
if(allocationCount == 0) {
logger->debug("All allocations are deallocated now, freeing memory");
// all allocations have been deallocated, free all memory
/* All allocations have been deallocated, free all memory */
nextFreeAddress = 0;
}
......@@ -126,28 +126,28 @@ LinearAllocator::allocateBlock(size_t size)
throw std::bad_alloc();
}
// assign address
/* Assign address */
const uintptr_t localAddr = nextFreeAddress + internalOffset;
// reserve memory
/* Reserve memory */
nextFreeAddress += size;
// make sure it is aligned
/* Make sure it is aligned */
if(const size_t paddingBytes = getAlignmentPadding(nextFreeAddress)) {
nextFreeAddress += paddingBytes;
// if next free address is outside this block due to padding, cap it
/* If next free address is outside this block due to padding, cap it */
nextFreeAddress = std::min(nextFreeAddress, memorySize);
}
auto& mm = MemoryManager::get();
// assemble name for this block
/* Assemble name for this block */
std::stringstream blockName;
blockName << std::showbase << std::hex << localAddr;
// create address space
/* Create address space */
auto addrSpaceName = mm.getSlaveAddrSpaceName(getName(), blockName.str());
auto addrSpaceId = mm.getOrCreateAddressSpace(addrSpaceName);
......@@ -157,10 +157,10 @@ LinearAllocator::allocateBlock(size_t size)
std::unique_ptr<MemoryBlock, MemoryBlock::deallocator_fn>
mem(new MemoryBlock(localAddr, size, addrSpaceId), this->free);
// mount block into the memory graph
/* Mount block into the memory graph */
insertMemoryBlock(*mem);
// increase the allocation count
/* Increase the allocation count */
allocationCount++;
return mem;
......@@ -233,13 +233,13 @@ HostDmaRam::HostDmaRamAllocator::~HostDmaRamAllocator()
auto translation = mm.getTranslationFromProcess(getAddrSpaceId());
baseVirt = reinterpret_cast<void*>(translation.getLocalAddr(0));
} catch(const std::out_of_range&) {
// not mapped, nothing to do
/* Not mapped, nothing to do */
return;
}
logger->debug("Unmapping {}", getName());
// try to unmap it
/* Try to unmap it */
if(::munmap(baseVirt, getSize()) != 0) {
logger->warn("munmap() failed for {:p} of size {:#x}",
baseVirt, getSize());
......@@ -301,4 +301,4 @@ HostDmaRam::HostDmaRamAllocator&HostDmaRam::getAllocator(int num)
return *allocator;
}
} // namespace villas
} /* namespace villas */
......@@ -48,14 +48,14 @@ MemoryManager::AddressSpaceId
MemoryManager::getOrCreateAddressSpace(std::string name)
{
try {
// try fast lookup
/* Try fast lookup */
return addrSpaceLookup.at(name);
} catch (const std::out_of_range&) {
// does not yet exist, create
/* Does not yet exist, create */
std::shared_ptr<AddressSpace> addrSpace(new AddressSpace);
addrSpace->name = name;
// cache it for the next access
/* Cache it for the next access */
addrSpaceLookup[name] = memoryGraph.addVertex(addrSpace);
return addrSpaceLookup[name];
......@@ -104,7 +104,7 @@ MemoryManager::findPath(MemoryManager::AddressSpaceId fromAddrSpaceId,
auto fromAddrSpace = memoryGraph.getVertex(fromAddrSpaceId);
auto toAddrSpace = memoryGraph.getVertex(toAddrSpaceId);
// find a path through the memory graph
/* Find a path through the memory graph */
MemoryGraph::Path pathGraph;
if(not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, pathGraph, pathCheckFunc)) {
......@@ -126,7 +126,7 @@ MemoryTranslation
MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId,
MemoryManager::AddressSpaceId toAddrSpaceId)
{
// find a path through the memory graph
/* Find a path through the memory graph */
MemoryGraph::Path path;
if(not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, path, pathCheckFunc)) {
......@@ -138,10 +138,10 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId,
throw std::out_of_range("no translation found");
}
// start with an identity mapping
/* Start with an identity mapping */
MemoryTranslation translation(0, 0, SIZE_MAX);
// iterate through path and merge all mappings into a single translation
/* Iterate through path and merge all mappings into a single translation */
for(auto& mappingId : path) {
auto mapping = memoryGraph.getEdge(mappingId);
translation += getTranslationFromMapping(*mapping);
......@@ -153,11 +153,12 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId,
bool
MemoryManager::pathCheck(const MemoryGraph::Path& path)
{
// start with an identity mapping
/* Start with an identity mapping */
MemoryTranslation translation(0, 0, SIZE_MAX);
// Try to add all mappings together to a common translation. If this fails
// there is a non-overlapping window
/* Try to add all mappings together to a common translation. If this fails
* there is a non-overlapping window.
*/
for(auto& mappingId : path) {
auto mapping = memoryGraph.getEdge(mappingId);
try {
......@@ -191,7 +192,7 @@ MemoryTranslation::operator+=(const MemoryTranslation& other)
{
Logger logger = logging.get("MemoryTranslation");
// set level to debug to enable debug output
/* Set level to debug to enable debug output */
logger->set_level(spdlog::level::info);
const uintptr_t this_dst_high = this->dst + this->size;
......@@ -206,7 +207,7 @@ MemoryTranslation::operator+=(const MemoryTranslation& other)
logger->debug("this_dst_high: {:#x}", this_dst_high);
logger->debug("other_src_high: {:#x}", other_src_high);
// make sure there is a common memory area
/* Make sure there is a common memory area */
assertExcept(other.src < this_dst_high, MemoryManager::InvalidTranslation());
assertExcept(this->dst < other_src_high, MemoryManager::InvalidTranslation());
......@@ -227,23 +228,25 @@ MemoryTranslation::operator+=(const MemoryTranslation& other)
logger->debug("diff_hi: {:#x}", diff_hi);
logger->debug("diff_lo: {:#x}", diff_lo);
// new size of aperture, can only stay or shrink
/* New size of aperture, can only stay or shrink */
this->size = (hi - lo) - diff_hi - diff_lo;
// new translation will come out other's destination (by default)
/* New translation will come out other's destination (by default) */
this->dst = other.dst;
// the source stays the same and can only increase with merged translations
/* The source stays the same and can only increase with merged translations */
//this->src = this->src;
if(otherSrcIsSmaller) {
// other mapping starts at lower addresses, so we actually arrive at
// higher addresses
/* Other mapping starts at lower addresses, so we actually arrive at
* higher addresses
*/
this->dst += diff_lo;
} else {
// other mapping starts at higher addresses than this, so we have to
// increase the start
// NOTE: for addresses equality, this just adds 0
/* Other mapping starts at higher addresses than this, so we have to
* increase the start
* NOTE: for addresses equality, this just adds 0
*/
this->src += diff_lo;
}
......@@ -254,4 +257,4 @@ MemoryTranslation::operator+=(const MemoryTranslation& other)
return *this;
}
} // namespace villas
} /* namespace villas */
......@@ -49,11 +49,11 @@ tokenize(std::string s, std::string delimiter)
const size_t tokenLength = curentPos - lastPos;
tokens.push_back(s.substr(lastPos, tokenLength));
// advance in string
/* Advance in string */
lastPos = curentPos + delimiter.length();
}
// check if there's a last token behind the last delimiter
/* Check if there's a last token behind the last delimiter. */
if(lastPos != s.length()) {
const size_t lastTokenLength = s.length() - lastPos;
tokens.push_back(s.substr(lastPos, lastTokenLength));
......@@ -171,5 +171,5 @@ void killme(int sig)
}
} // namespace utils
} // namespace villas
} /* namespace utils */
} /* namespace villas */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment