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

kernel: refactor naming style

parent 8949fb44
......@@ -34,10 +34,10 @@ namespace kernel {
utils::Version getVersion();
/** Get number of reserved hugepages. */
int get_nr_hugepages();
int getNrHugepages();
/** Set number of reserved hugepages. */
int set_nr_hugepages(int nr);
int setNrHugepages(int nr);
/** Get kernel cmdline parameter
*
......@@ -49,7 +49,7 @@ int set_nr_hugepages(int nr);
* @retval 0 Parameter \p key was found and value was copied to \p value
* @reval <>0 Kernel was not booted with parameter \p key
*/
int get_cmdline_param(const char *param, char *buf, size_t len);
int getCmdlineParam(const char *param, char *buf, size_t len);
/** Checks if a kernel module is loaded
*
......@@ -57,28 +57,28 @@ int get_cmdline_param(const char *param, char *buf, size_t len);
* @retval 0 Module is loaded.
* @reval <>0 Module is not loaded.
*/
int module_loaded(const char *module);
int isModuleLoaded(const char *module);
/** Load kernel module via modprobe */
int module_load(const char *module);
int loadModule(const char *module);
/** Set parameter of loaded kernel module */
int module_set_param(const char *module, const char *param, const char *value);
int setModuleParam(const char *module, const char *param, const char *value);
/** Get cacheline size in bytes */
int get_cacheline_size();
int getCachelineSize();
/** Get the size of a standard page in bytes. */
int get_page_size();
int getPageSize();
/** Get the size of a huge page in bytes. */
int get_hugepage_size();
int getHugePageSize();
/** Get CPU base frequency */
int get_cpu_frequency(uint64_t *freq);
/** Set SMP affinity of IRQ */
int irq_setaffinity(unsigned irq, uintmax_t aff , uintmax_t *old);
int setIRQAffinity(unsigned irq, uintmax_t aff , uintmax_t *old);
} /* namespace villas */
} /* namespace kernel */
......@@ -59,7 +59,7 @@ Version villas::kernel::getVersion()
return Version(ver);
}
int villas::kernel::get_cacheline_size()
int villas::kernel::getCachelineSize()
{
#if defined(__linux__) && defined(__x86_64__) && defined(__GLIBC__)
return sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
......@@ -82,7 +82,7 @@ int villas::kernel::get_cacheline_size()
}
#if defined(__linux__) || defined(__APPLE__)
int villas::kernel::get_page_size()
int villas::kernel::getPageSize()
{
return sysconf(_SC_PAGESIZE);
}
......@@ -91,7 +91,7 @@ int villas::kernel::get_page_size()
#endif
/* There is no sysconf interface to get the hugepage size */
int villas::kernel::get_hugepage_size()
int villas::kernel::getHugePageSize()
{
#ifdef __linux__
char *key, *value, *unit, *line = nullptr, *lasts;
......@@ -129,7 +129,7 @@ int villas::kernel::get_hugepage_size()
#ifdef __linux__
int villas::kernel::module_set_param(const char *module, const char *param, const char *value)
int villas::kernel::setModuleParam(const char *module, const char *param, const char *value)
{
FILE *f;
char fn[256];
......@@ -148,11 +148,11 @@ int villas::kernel::module_set_param(const char *module, const char *param, cons
return 0;
}
int villas::kernel::module_load(const char *module)
int villas::kernel::loadModule(const char *module)
{
int ret;
ret = module_loaded(module);
ret = isModuleLoaded(module);
if (!ret) {
auto logger = logging.get("kernel");
logger->debug("Kernel module {} already loaded...", module);
......@@ -171,11 +171,11 @@ int villas::kernel::module_load(const char *module)
default:
wait(&ret);
return module_loaded(module);
return isModuleLoaded(module);
}
}
int villas::kernel::module_loaded(const char *module)
int villas::kernel::isModuleLoaded(const char *module)
{
FILE *f;
int ret = -1;
......@@ -199,7 +199,7 @@ int villas::kernel::module_loaded(const char *module)
return ret;
}
int villas::kernel::get_cmdline_param(const char *param, char *buf, size_t len)
int villas::kernel::getCmdlineParam(const char *param, char *buf, size_t len)
{
int ret;
char cmdline[512], key[128], value[128], *lasts, *tok;
......@@ -236,7 +236,7 @@ out:
return -1; /* not found or error */
}
int villas::kernel::get_nr_hugepages()
int villas::kernel::getNrHugepages()
{
FILE *f;
int nr, ret;
......@@ -257,7 +257,7 @@ int villas::kernel::get_nr_hugepages()
return nr;
}
int villas::kernel::set_nr_hugepages(int nr)
int villas::kernel::setNrHugepages(int nr)
{
FILE *f;
......@@ -266,7 +266,7 @@ int villas::kernel::set_nr_hugepages(int nr)
auto logger = logging.get("kernel");
if (is_container()) {
logger->warn("This functionality is unavailable in this mode. Please run the Docker container in the privileged mode:");
logger->warn("This functionality is unavailable in this mode. Please run the container in the privileged mode:");
logger->warn(" $ docker run --privilged ...");
}
else
......@@ -281,7 +281,7 @@ int villas::kernel::set_nr_hugepages(int nr)
return 0;
}
int villas::kernel::irq_setaffinity(unsigned irq, uintmax_t aff, uintmax_t *old)
int villas::kernel::setIRQAffinity(unsigned irq, uintmax_t aff, uintmax_t *old)
{
char fn[64];
FILE *f;
......
......@@ -62,7 +62,7 @@ void init(int priority, int affinity)
logger->warn("You might want to use the 'priority' setting to increase " PROJECT_NAME "'s process priority");
if (affinity) {
is_isol = get_cmdline_param("isolcpus", isolcpus, sizeof(isolcpus));
is_isol = getCmdlineParam("isolcpus", isolcpus, sizeof(isolcpus));
if (is_isol)
logger->warn("You should reserve some cores for " PROJECT_NAME " (see 'isolcpus')");
else {
......
......@@ -85,7 +85,7 @@ Container::Container()
};
for (const char* module : requiredKernelModules) {
if (kernel::module_load(module) != 0)
if (kernel::loadModule(module) != 0)
throw RuntimeError("Kernel module '{}' required but could not be loaded. "
"Please load manually!", module);
}
......@@ -280,7 +280,7 @@ Container::attachDevice(const pci::Device &pdev)
Logger logger = logging.get("kernel:vfio");
/* Load PCI bus driver for VFIO */
if (kernel::module_load("vfio_pci"))
if (kernel::loadModule("vfio_pci"))
throw RuntimeError("Failed to load kernel driver: vfio_pci");
/* Bind PCI card to vfio-pci driver if not already bound */
......@@ -292,7 +292,7 @@ Container::attachDevice(const pci::Device &pdev)
/* Get IOMMU group of device */
int index = isIommuEnabled() ? pdev.getIOMMUGroup() : 0;
if (index < 0) {
ret = kernel::get_cmdline_param("intel_iommu", iommu_state, sizeof(iommu_state));
ret = kernel::getCmdlineParam("intel_iommu", iommu_state, sizeof(iommu_state));
if (ret != 0 || strcmp("on", iommu_state) != 0)
logger->warn("Kernel booted without command line parameter "
"'intel_iommu' set to 'on'. Please check documentation "
......
......@@ -47,13 +47,13 @@ Test(kernel, sizes)
{
int sz;
sz = get_page_size();
sz = getPageSize();
cr_assert_eq(sz, PAGESIZE);
sz = get_hugepage_size();
sz = getHugePageSize();
cr_assert(sz == HUGEPAGESIZE);
sz = get_cacheline_size();
sz = getCachelineSize();
cr_assert_eq(sz, CACHELINESIZE);
}
......@@ -62,16 +62,16 @@ Test(kernel, hugepages)
{
int ret;
ret = set_nr_hugepages(25);
ret = setNrHugepages(25);
cr_assert_eq(ret, 0);
ret = get_nr_hugepages();
ret = getNrHugepages();
cr_assert_eq(ret, 25);
ret = set_nr_hugepages(10);
ret = setNrHugepages(10);
cr_assert_eq(ret, 0);
ret = get_nr_hugepages();
ret = getNrHugepages();
cr_assert_eq(ret, 10);
}
......@@ -91,10 +91,10 @@ Test(kernel, module, .disabled = true)
{
int ret;
ret = module_loaded("nf_nat");
ret = isModuleLoaded("nf_nat");
cr_assert_eq(ret, 0);
ret = module_loaded("does_not_exist");
ret = isModuleLoaded("does_not_exist");
cr_assert_neq(ret, 0);
}
......
Markdown is supported
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