static void test_physical_memory_scale(void) { uint64_t p; log_info("/* %s */", __func__); p = physical_memory(); assert_se(physical_memory_scale(0, 100) == 0); assert_se(physical_memory_scale(100, 100) == p); log_info("Memory original: %" PRIu64, physical_memory()); log_info("Memory scaled by 50%%: %" PRIu64, physical_memory_scale(50, 100)); log_info("Memory divided by 2: %" PRIu64, physical_memory() / 2); log_info("Page size: %zu", page_size()); /* There might be an uneven number of pages, hence permit these calculations to be half a page off... */ assert_se(page_size()/2 + physical_memory_scale(50, 100) - p/2 <= page_size()); assert_se(physical_memory_scale(200, 100) == p*2); assert_se(physical_memory_scale(0, 1) == 0); assert_se(physical_memory_scale(1, 1) == p); assert_se(physical_memory_scale(2, 1) == p*2); assert_se(physical_memory_scale(0, 2) == 0); assert_se(page_size()/2 + physical_memory_scale(1, 2) - p/2 <= page_size()); assert_se(physical_memory_scale(2, 2) == p); assert_se(physical_memory_scale(4, 2) == p*2); assert_se(physical_memory_scale(0, UINT32_MAX) == 0); assert_se(physical_memory_scale(UINT32_MAX, UINT32_MAX) == p); /* overflow */ assert_se(physical_memory_scale(UINT64_MAX/4, UINT64_MAX) == UINT64_MAX); }
void CCpuDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCpuDlg) DDX_Text(pDX, IDC_HOURS, m_hours); DDV_MinMaxUInt(pDX, m_hours, 1, 24); DDX_Text(pDX, IDC_START_TIME, m_start_time); DDX_Text(pDX, IDC_END_TIME, m_end_time); DDX_Text(pDX, IDC_DAY_MEMORY, m_day_memory); DDV_MinMaxUInt(pDX, m_day_memory, 8, (UINT) (0.9 * physical_memory ())); DDX_Text(pDX, IDC_NIGHT_MEMORY, m_night_memory); DDV_MinMaxUInt(pDX, m_night_memory, 8, (UINT) (0.9 * physical_memory ())); DDX_Text(pDX, IDC_CPU_INFO, m_cpu_info); DDX_Control(pDX, IDC_DAY_MEMORY_TEXT, c_day_memory_text); DDX_Control(pDX, IDC_DAY_MEMORY, c_day_memory); DDX_Control(pDX, IDC_NIGHT_MEMORY_TEXT, c_night_memory_text); DDX_Control(pDX, IDC_NIGHT_MEMORY, c_night_memory); DDX_Control(pDX, IDC_START_TIME_TEXT, c_start_time_text); DDX_Control(pDX, IDC_START_TIME, c_start_time); DDX_Control(pDX, IDC_END_TIME_TEXT, c_end_time_text); DDX_Control(pDX, IDC_END_TIME, c_end_time); //}}AFX_DATA_MAP c_day_memory_text.EnableWindow (m_memory_editable); c_day_memory.EnableWindow (m_memory_editable); c_night_memory_text.EnableWindow (m_memory_editable); c_night_memory.EnableWindow (m_memory_editable); c_start_time_text.EnableWindow (m_memory_editable); c_start_time.EnableWindow (m_memory_editable); c_end_time_text.EnableWindow (m_memory_editable); c_end_time.EnableWindow (m_memory_editable); }
static void manager_reset_config(Manager *m) { m->n_autovts = 6; m->reserve_vt = 6; m->remove_ipc = true; m->inhibit_delay_max = 5 * USEC_PER_SEC; m->handle_power_key = HANDLE_POWEROFF; m->handle_suspend_key = HANDLE_SUSPEND; m->handle_hibernate_key = HANDLE_HIBERNATE; m->handle_lid_switch = HANDLE_SUSPEND; m->handle_lid_switch_docked = HANDLE_IGNORE; m->power_key_ignore_inhibited = false; m->suspend_key_ignore_inhibited = false; m->hibernate_key_ignore_inhibited = false; m->lid_switch_ignore_inhibited = true; m->holdoff_timeout_usec = 30 * USEC_PER_SEC; m->idle_action_usec = 30 * USEC_PER_MINUTE; m->idle_action = HANDLE_IGNORE; m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */ m->user_tasks_max = 12288; m->sessions_max = 8192; m->inhibitors_max = 8192; m->kill_user_processes = KILL_USER_PROCESSES; m->kill_only_users = strv_free(m->kill_only_users); m->kill_exclude_users = strv_free(m->kill_exclude_users); }
static void test_physical_memory(void) { uint64_t p; char buf[FORMAT_BYTES_MAX]; p = physical_memory(); assert_se(p > 0); assert_se(p < UINT64_MAX); assert_se(p % page_size() == 0); log_info("Memory: %s (%" PRIu64 ")", format_bytes(buf, sizeof(buf), p), p); }
jboolean ServerClassMachineImpl(void) { jboolean result = JNI_FALSE; /* How big is a server class machine? */ const unsigned long server_processors = 2UL; const uint64_t server_memory = 2UL * GB; const uint64_t actual_memory = physical_memory(); /* Is this a server class machine? */ if (actual_memory >= server_memory) { const unsigned long actual_processors = physical_processors(); if (actual_processors >= server_processors) { result = JNI_TRUE; } } JLI_TraceLauncher("unix_" LIBARCHNAME "_ServerClassMachine: %s\n", (result == JNI_TRUE ? "JNI_TRUE" : "JNI_FALSE")); return result; }
static Manager *manager_new(void) { Manager *m; int r; m = new0(Manager, 1); if (!m) return NULL; m->console_active_fd = -1; m->reserve_vt_fd = -1; m->n_autovts = 6; m->reserve_vt = 6; m->remove_ipc = true; m->inhibit_delay_max = 5 * USEC_PER_SEC; m->handle_power_key = HANDLE_POWEROFF; m->handle_suspend_key = HANDLE_SUSPEND; m->handle_hibernate_key = HANDLE_HIBERNATE; m->handle_lid_switch = HANDLE_SUSPEND; m->handle_lid_switch_docked = HANDLE_IGNORE; m->lid_switch_ignore_inhibited = true; m->holdoff_timeout_usec = 30 * USEC_PER_SEC; m->idle_action_usec = 30 * USEC_PER_MINUTE; m->idle_action = HANDLE_IGNORE; m->idle_action_not_before_usec = now(CLOCK_MONOTONIC); m->runtime_dir_size = PAGE_ALIGN((size_t) (physical_memory() / 10)); /* 10% */ m->devices = hashmap_new(&string_hash_ops); m->seats = hashmap_new(&string_hash_ops); m->sessions = hashmap_new(&string_hash_ops); m->users = hashmap_new(NULL); m->inhibitors = hashmap_new(&string_hash_ops); m->buttons = hashmap_new(&string_hash_ops); m->user_units = hashmap_new(&string_hash_ops); m->session_units = hashmap_new(&string_hash_ops); if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units) goto fail; m->kill_exclude_users = strv_new("root", NULL); if (!m->kill_exclude_users) goto fail; m->udev = udev_new(); if (!m->udev) goto fail; r = sd_event_default(&m->event); if (r < 0) goto fail; sd_event_set_watchdog(m->event, true); return m; fail: manager_free(m); return NULL; }
void torture (void) { unsigned long m_thread, m_type, m_minfft, m_maxfft; unsigned long m_memory, m_timefft; unsigned long mem, blendmemory; m_thread = NUM_CPUS * CPU_HYPERTHREADS; mem = physical_memory (); if (mem >= 2000) { blendmemory = GetSuggestedMemory (1600); } else if (mem >= 500) { blendmemory = GetSuggestedMemory (mem - 256); } else if (mem >= 200) { blendmemory = GetSuggestedMemory (mem / 2); } else { blendmemory = 8; } m_timefft = 3; if (NUM_CPUS * CPU_HYPERTHREADS > 1) askNum ("Number of torture test threads to run", &m_thread, 1, NUM_CPUS * CPU_HYPERTHREADS); outputLongLine ("Choose a type of torture test to run.\n 1 = Small FFTs (maximum heat and FPU stress, data fits in L2 cache, RAM not tested much).\n 2 = In-place large FFTs (maximum power consumption, some RAM tested).\n 3 = Blend (tests some of everything, lots of RAM tested).\n 11,12,13 = Allows you to fine tune the above three selections.\nBlend is the default. NOTE: if you fail the blend test, but can pass the small FFT test then your problem is likely bad memory or a bad memory controller.\n"); m_type = 3; askNum ("Type of torture test to run", &m_type, 1, 13); if (m_type == 1 || m_type == 11) { m_minfft = 8; m_maxfft = 64; m_memory = 0; } else if (m_type == 2 || m_type == 12) { m_minfft = 128; m_maxfft = 1024; m_memory = 0; } else { m_minfft = 8; m_maxfft = 4096; m_memory = blendmemory; } if (m_type >= 11) { askNum ("Min FFT size (in K)", &m_minfft, (CPU_FLAGS & CPU_AVX) ? 0 : 7, (CPU_FLAGS & CPU_SSE2 ? MAX_FFTLEN_SSE2 : MAX_FFTLEN) / 1024); askNum ("Max FFT size (in K)", &m_maxfft, (CPU_FLAGS & CPU_AVX) ? 1 : 7, (CPU_FLAGS & CPU_SSE2 ? MAX_FFTLEN_SSE2 : MAX_FFTLEN) / 1024); if (blendmemory > 8) askNum ("Memory to use (in MB, 0 = in-place FFTs)", &m_memory, 0, mem); askNum ("Time to run each FFT size (in minutes)", &m_timefft, 1, 60); } if (askOkCancel ()) { IniWriteInt (INI_FILE, "MinTortureFFT", m_minfft); IniWriteInt (INI_FILE, "MaxTortureFFT", m_maxfft); mem = m_memory / m_thread; IniWriteInt (INI_FILE, "TortureMem", mem); IniWriteInt (INI_FILE, "TortureTime", m_timefft); LaunchTortureTest (m_thread, TRUE); } }
void options_cpu (void) { unsigned int day_memory, night_memory, day_start_time, day_end_time; unsigned long m_hours, m_day_memory, m_night_memory, max_mem; int m_memory_editable; char m_start_time[13]; char m_end_time[13]; char buf[512]; m_memory_editable = read_memory_settings (&day_memory, &night_memory, &day_start_time, &day_end_time); //again: m_hours = CPU_HOURS; m_day_memory = day_memory; m_night_memory = night_memory; minutesToStr (day_start_time, m_start_time); minutesToStr (day_end_time, m_end_time); askNum ("Hours per day this program will run", &m_hours, 1, 24); printf ("\nPlease see the readme.txt file for important\n"); printf ("information on the P-1/ECM stage 2 memory settings.\n\n"); if (m_memory_editable) { max_mem = physical_memory () - 8; if (max_mem < 8) max_mem = 8; askNum ("Daytime P-1/ECM stage 2 memory in MB", &m_day_memory, 8, max_mem); askNum ("Nighttime P-1/ECM stage 2 memory in MB", &m_night_memory, 8, max_mem); if (m_day_memory != m_night_memory) { askStr ("Daytime begins at", (char *) &m_start_time, 12); askStr ("Daytime ends at", (char *) &m_end_time, 12); } } getCpuDescription (buf, 0); printf ("\nCPU Information:\n%s\n", buf); if (askOkCancel ()) { unsigned int new_day_start_time, new_day_end_time; if (CPU_HOURS != m_hours) { CPU_HOURS = m_hours; IniWriteInt (LOCALINI_FILE, "CPUHours", CPU_HOURS); ROLLING_AVERAGE = 1000; IniWriteInt (LOCALINI_FILE, "RollingAverage", 1000); IniWriteInt (LOCALINI_FILE, "RollingStartTime", 0); spoolMessage (PRIMENET_UPDATE_COMPUTER_INFO, NULL); delete_timed_event (TE_COMM_SERVER); UpdateEndDates (); } new_day_start_time = strToMinutes ((char *) &m_start_time); new_day_end_time = strToMinutes ((char *) &m_end_time); if (m_memory_editable && (day_memory != m_day_memory || night_memory != m_night_memory || day_start_time != new_day_start_time || day_end_time != new_day_end_time)) { write_memory_settings (m_day_memory, m_night_memory, new_day_start_time, new_day_end_time); mem_settings_have_changed (); } spoolMessage (PRIMENET_PROGRAM_OPTIONS, NULL); // Now that Primenet almost always hands out LL assignments that are P-1'ed, // there is little reason to prompt user into allowing us to use more memory. // if (!IniGetInt (INI_FILE, "AskedAboutMemory", 0)) { // IniWriteInt (INI_FILE, "AskedAboutMemory", 1); // if (m_day_memory == 8 && m_night_memory == 8) { // outputLongLine (MSG_MEMORY); // if (askYesNo ('Y')) goto again; // } // } } else STARTUP_IN_PROGRESS = 0; }