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_cpucores.h"
17 /// Maximum number of free *coder* threads. This can be set with
18 /// the --threads=NUM command line option.
19 static uint32_t threadlimit;
21 /// Memory usage limit
22 static uint64_t memlimit;
26 hardware_threadlimit_set(uint32_t new_threadlimit)
28 if (new_threadlimit == 0) {
29 // The default is the number of available CPU cores.
30 threadlimit = tuklib_cpucores();
34 threadlimit = new_threadlimit;
42 hardware_threadlimit_get(void)
49 hardware_memlimit_set(uint64_t new_memlimit)
51 if (new_memlimit == 0) {
52 // The default is 40 % of total installed physical RAM.
53 hardware_memlimit_set_percentage(40);
55 memlimit = new_memlimit;
63 hardware_memlimit_set_percentage(uint32_t percentage)
65 assert(percentage > 0);
66 assert(percentage <= 100);
68 uint64_t mem = lzma_physmem();
70 // If we cannot determine the amount of RAM, use the assumption
71 // defined by the configure script.
73 mem = (uint64_t)(ASSUME_RAM) * 1024 * 1024;
75 memlimit = percentage * mem / 100;
81 hardware_memlimit_get(void)
90 hardware_memlimit_set(0);
91 hardware_threadlimit_set(0);