Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/cpuinfo: Increase the file descriptors limit to handle more CPUs #262

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/common.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <unistd.h>

FILE *
Expand Down Expand Up @@ -392,3 +393,24 @@ pqos_read(int fd, void *buf, size_t count)

return count;
}

int
pqos_set_no_files_limit(unsigned long max_core_count)
{
struct rlimit files_limit;

if (getrlimit(RLIMIT_NOFILE, &files_limit))
return PQOS_RETVAL_ERROR;

/* Check if rlim_max can handle the number of CPUs */
if (files_limit.rlim_max < max_core_count * 4)
return PQOS_RETVAL_ERROR;

if (files_limit.rlim_cur < max_core_count * 4) {
files_limit.rlim_cur = max_core_count * 4;
if (setrlimit(RLIMIT_NOFILE, &files_limit))
return PQOS_RETVAL_ERROR;
}

return PQOS_RETVAL_OK;
}
11 changes: 11 additions & 0 deletions lib/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ PQOS_LOCAL void pqos_munmap(void *mem, const uint64_t size);
*/
PQOS_LOCAL ssize_t pqos_read(int fd, void *buf, size_t count);

/**
* @brief Increase the number of open files limit to handle more
* than 256 CPUs.
*
* @param [in] Max CPUs on the system
*
* @return PQOS_RETVAL_OK for success
* @retval PQOS_RETVAL_ERROR for failure
*/
PQOS_LOCAL int pqos_set_no_files_limit(unsigned long max_core_count);

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions lib/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "allocation.h"
#include "cap.h"
#include "common.h"
#include "cpu_registers.h"
#include "log.h"
#include "machine.h"
Expand All @@ -57,6 +58,7 @@
#endif
#ifdef __linux__
#include <sched.h> /* sched affinity */
#include <sys/resource.h>
#include <sys/syscall.h>
#endif

Expand Down Expand Up @@ -452,6 +454,11 @@ cpuinfo_build_topo(struct apic_info *apic)
return NULL;
}

if (pqos_set_no_files_limit(max_core_count)) {
LOG_ERROR("Open files limit not sufficient!\n");
return NULL;
}

const size_t mem_sz =
sizeof(*l_cpu) + (max_core_count * sizeof(struct pqos_coreinfo));

Expand Down
6 changes: 6 additions & 0 deletions lib/os_cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>

#define SYSTEM_CPU "/sys/devices/system/cpu"
#define SYSTEM_NODE "/sys/devices/system/node"
Expand Down Expand Up @@ -267,6 +268,11 @@ os_cpuinfo_topology(void)
return NULL;
}

if (pqos_set_no_files_limit(max_core_count)) {
LOG_ERROR("Open files limit not sufficient!\n");
return NULL;
}

const size_t mem_sz =
sizeof(*cpu) + (max_core_count * sizeof(struct pqos_coreinfo));

Expand Down
2 changes: 1 addition & 1 deletion pqos/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ set_allocation_assoc(const struct pqos_devinfo *dev)
static void
fill_core_tab(char *str)
{
unsigned max_cores_count = 128;
unsigned max_cores_count = sysconf(_SC_NPROCESSORS_CONF);
uint64_t *cores = calloc(max_cores_count, sizeof(uint64_t));
unsigned i = 0, n = 0, cos = 0;
char *p = NULL;
Expand Down
Loading