1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Detection of available hardware resources
6 // Author: Lasse Collin
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
11 ///////////////////////////////////////////////////////////////////////////////
14 #include "tuklib_physmem.h"
15 #include "tuklib_cpucores.h"
18 /// Maximum number of free *coder* threads. This can be set with
19 /// the --threads=NUM command line option.
20 static uint32_t threadlimit;
22 /// Memory usage limit
23 static uint64_t memlimit;
27 hardware_threadlimit_set(uint32_t new_threadlimit)
29 if (new_threadlimit == 0) {
30 // The default is the number of available CPU cores.
31 threadlimit = tuklib_cpucores();
35 threadlimit = new_threadlimit;
43 hardware_threadlimit_get(void)
50 hardware_memlimit_set(uint64_t new_memlimit)
52 if (new_memlimit == 0) {
53 // The default is 40 % of total installed physical RAM.
54 hardware_memlimit_set_percentage(40);
56 memlimit = new_memlimit;
64 hardware_memlimit_set_percentage(uint32_t percentage)
66 assert(percentage > 0);
67 assert(percentage <= 100);
69 uint64_t mem = tuklib_physmem();
71 // If we cannot determine the amount of RAM, use the assumption
72 // defined by the configure script.
74 mem = (uint64_t)(ASSUME_RAM) * 1024 * 1024;
76 memlimit = percentage * mem / 100;
82 hardware_memlimit_get(void)
91 hardware_memlimit_set(0);
92 hardware_threadlimit_set(0);