void suggest_wireless_powersave(void) { char sug[1024]; int ret; if (strlen(wireless_nic)==0) find_wireless_nic(); find_4965(); ret = check_unused_wiresless_up(); if (ret >= 0 && need_wireless_suggest(wireless_nic)) { sprintf(sug, _("Suggestion: Enable wireless power saving mode by executing the following command:\n " " iwpriv %s set_power 5 \n" "This will sacrifice network performance slightly to save power."), wireless_nic); add_suggestion(sug, 20, 'W', _(" W - Enable wireless power saving "), activate_wireless_suggestion); } if (ret >= 0 && need_wireless_suggest_new()) { sprintf(sug, _("Suggestion: Enable wireless power saving mode by executing the following command:\n " " echo 5 > %s \n" "This will sacrifice network performance slightly to save power."), powersave_path); add_suggestion(sug, 20, 'W', _(" W - Enable wireless power saving "), activate_wireless_suggestion_new); } if (ret>0) { sprintf(sug, _("Suggestion: Disable the unused WIFI radio by executing the following command:\n " " echo 1 > %s \n"), rfkill_path); add_suggestion(sug, 60, 'I', _(" I - disable WIFI Radio "), activate_rfkill_suggestion); } }
void suggest_hpet(void) { FILE *file; char buffer[1024]; file = fopen("/sys/devices/system/clocksource/clocksource0/available_clocksource", "r"); if (!file) return; memset(buffer, 0, 1024); if (!fgets(buffer, 1023, file)) { fclose(file); return; } if (strstr(buffer, "hpet")) { fclose(file); return; } fclose(file); add_suggestion( _("Suggestion: enable the HPET (Multimedia Timer) in your BIOS or add \n" "the kernel patch to force-enable HPET. HPET support allows Linux to \n" "have much longer sleep intervals."), 7, 0, NULL, NULL); }
void slapt_generate_suggestions(slapt_transaction_t *tran) { unsigned int i; for (i = 0;i < tran->install_pkgs->pkg_count; ++i) { add_suggestion(tran,tran->install_pkgs->pkgs[i]); } }
void alsa_activity_hint(void) { int total_active = 0; int pick; struct device_data *dev; dev = devices; while (dev) { if (dev->power_on-1 > dev->previous_power_on) total_active++; dev = dev->next; } if (!total_active) return; pick = rand() % total_active; total_active = 0; dev = devices; while (dev) { if (dev->power_on-1 > dev->previous_power_on) { if (total_active == pick) { char alsa_hint[8000]; sprintf(alsa_hint, _("An audio device is active %4.1f%% of the time:\n%s"), 100.0*(dev->power_on - dev->previous_power_on) / (0.00001 + dev->power_on + dev->power_off - dev->previous_power_on - dev->previous_power_off), dev->human_name); add_suggestion(alsa_hint, 1, 'A', _(" A - Turn HD audio powersave on "), hda_power_on); } total_active++; } dev = dev->next; } }
static int check_adds(trie_dict *t, string word, int edits, rb_tree *suggs){ int i, j; char c, ch; string tmp; tmp.len = word.len+1; tmp.str = alloca(tmp.len); for(i=0;i<=word.len;i++){ /* I might be off on the indexing here */ trie_dict_node *node = trie_dict_lookup_node(t, word.mem, i); if(!node){ continue; } memcpy(tmp.str, word.str, i); memcpy(tmp.str + i + 1, word.str + i, word.len - i); for(j=0;j<52;j++){ tmp.str[i] = eng_alphabet[j]; if(trie_dict_lookup(node->children[j], word.mem + i, word.len - i)){ add_suggestion(suggs, tmp); } check_edits(t, tmp, edits-1, suggs); } } return 0; }
void suggest_on_dmesg(char *string, char *comment, int weight) { read_dmesg(); if (strstr(dmesg_content, string)) add_suggestion(comment, weight, 0, NULL, NULL); }
void usb_activity_hint(void) { int total_active = 0; int pick; struct device_data *dev; dev = devices; while (dev) { if (dev->active-1 > dev->previous_active && !dev->controller) total_active++; dev = dev->next; } if (!total_active) return; pick = rand() % total_active; total_active = 0; dev = devices; while (dev) { if (dev->active-1 > dev->previous_active && !dev->controller) { if (total_active == pick) { char usb_hint[8000]; sprintf(usb_hint, _("A USB device is active %4.1f%% of the time:\n%s"), 100.0*(dev->active - dev->previous_active) / (0.00001 + dev->connected - dev->previous_connected), dev->human_name); add_suggestion(usb_hint, 1, 'U', _(" U - Enable USB suspend "), activate_usb_autosuspend); } total_active++; } dev = dev->next; } }
void ahci_activity_hint(void) { int total_active = 0; int pick; struct device_data *dev; dev = devices; while (dev) { if (dev->active-1 > dev->previous_active && dev->active) total_active++; dev = dev->next; } if (!total_active) return; pick = rand() % total_active; total_active = 0; dev = devices; while (dev) { if (dev->active-1 > dev->previous_active && dev->active) { if (total_active == pick) { char ahci_hint[8000]; sprintf(ahci_hint, _("A SATA device is active %1.1f%% of the time:\n%s"), 100.0*(dev->active - dev->previous_active) / (0.00001 + dev->total - dev->previous_total), dev->human_name); add_suggestion(ahci_hint, 15, 'S', _(" S - SATA Link Power Management "), activate_alpm); } total_active++; } dev = dev->next; } }
static int check_subs(trie_dict *t, string word, int edits, rb_tree *suggs){ int i, j; char c, ch; string tmp; tmp.len = word.len; tmp.str = alloca(tmp.len); memcpy(tmp.mem, word.mem, word.len); for(i=0;i<word.len;i++){ trie_dict_node *node = trie_dict_lookup_node(t, word.mem, i); if(!node){ continue; } ch = word.str[i]; for(j=0;j<52;j++){ if(ch == eng_alphabet[j]){continue;} tmp.str[i] = eng_alphabet[j]; if(trie_dict_lookup(node->children[j], word.mem + (i+1), word.len - (i+1))){ add_suggestion(suggs, tmp); } check_edits(t, tmp, edits-1, suggs); } tmp.str[i] = ch; } return 0; }
void suggest_ondemand_governor(void) { DIR *dir; struct dirent *dirent; FILE *file; char filename[PATH_MAX]; char line[1024]; char gov[1024]; int ret = 0; gov[0] = 0; dir = opendir("/sys/devices/system/cpu"); if (!dir) return; while ((dirent = readdir(dir))) { if (dirent->d_name[0]=='.') continue; sprintf(filename, "/sys/devices/system/cpu/%s/cpufreq/scaling_governor", dirent->d_name); file = fopen(filename, "r"); if (!file) continue; memset(line, 0, 1024); if (fgets(line, 1023,file)==NULL) { fclose(file); continue; } if (strlen(gov)==0) strcpy(gov, line); else /* if the governors are inconsistent, warn */ if (strcmp(gov, line)) ret = 1; fclose(file); } closedir(dir); /* if the governor is set to userspace, also warn */ if (strstr(gov, "userspace")) ret = 1; /* if the governor is set to performance, also warn */ /* FIXME: check if this is fair on all cpus */ if (strstr(gov, "performance")) ret = 1; if (ret) { add_suggestion(_("Suggestion: Enable the ondemand cpu speed governor for all processors via: \n" " echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor \n"), 15, 'O', _(" O - enable Ondemand governor "), activate_ondemand); } }
static void parse_event(void *ptr, int verbose) { char line[8192]; char pid[14]; int suggested = 0; struct sample_event *event = ptr; if (event->trace.type != this_trace) return; if (event->trace.size < sizeof(struct dirty_inode)) return; if (event->inode.pid == 0) return; if (strcmp(event->inode.comm, "powertop") == 0) return; /* * btrfs kernel threads are internal and only * do IO on behalf of others that also got recorded */ if (strcmp(event->inode.comm, "btrfs-") == 0) return; /* * don't record "IO" to tmpfs or /proc */ if (strcmp(event->inode.dev, "tmpfs") == 0) return; if (strcmp(event->inode.dev, "proc") == 0) return; if (strcmp(event->inode.dev, "pipefs") == 0) return; if (strcmp(event->inode.dev, "anon_inodefs") == 0) return; sprintf(pid, "%i", event->inode.pid); sprintf(line, "%s", event->inode.comm); push_line_pid(line, 0, 1, pid); if (!suggested && strcmp(event->inode.file, "?")) { suggested = 1; sprintf(line,_("The program '%s' is writing to file '%s' on /dev/%s.\nThis prevents the disk from going to powersave mode."), event->inode.comm, event->inode.file, event->inode.dev); add_suggestion(line, 30, 0, NULL, NULL); } if (verbose) printf(_("The application '%s' is writing to file '%s' on /dev/%s\n"), event->inode.comm, event->inode.file, event->inode.dev); }
void suggest_powersched(void) { FILE *file; char buffer[1024]; int suggest = 0; int cpu; file = fopen("/sys/devices/system/cpu/sched_mc_power_savings","r"); if (!file) return; memset(buffer, 0, 1024); if (!fgets(buffer, 1023, file)) { fclose(file); return; } fclose(file); if (buffer[0]!='0') return; /* ok so power saving scheduler is off; now to see if we actually have a multi-package system */ cpu = sysconf(_SC_NPROCESSORS_ONLN); if (cpu<2) return; /* UP system */ file = fopen("/proc/cpuinfo", "r"); suggest = 1; if (!file) return; while (!feof(file)) { memset(buffer, 0, 1024); char *c; if (!fgets(buffer, 1023, file)) break; if (strstr(buffer, "cpu cores")) { c = strchr(buffer, ':'); if (!c) continue; c++; if (strtoll(c, NULL, 10) >= cpu) suggest = 0; } } fclose(file); if (suggest) { add_suggestion( _("Suggestion: enable the power aware CPU scheduler with the following command:\n" " echo 1 > /sys/devices/system/cpu/sched_mc_power_savings\n" "or by pressing the C key."), 5, 'C', _(" C - Power aware CPU scheduler "), powersched_on); } }
void suggest_process_death(char *process_match, char *tokill, struct line *slines, int linecount, double minwakeups, char *comment, int weight) { int i; for (i = 0; i < linecount; i++) { if (slines[i].string && strstr(slines[i].string, process_match)) { char hotkey_string[300]; sprintf(hotkey_string, _(" K - kill %s "), tokill); strcpy(process_to_kill, tokill); if (minwakeups < slines[i].count) add_suggestion(comment, weight, 'K' , hotkey_string, do_kill); break; } } fflush(stdout); }
void suggest_sata_alpm(void) { DIR *dir; struct dirent *dirent; FILE *file; char filename[PATH_MAX]; char line[1024]; int need_hint = 0; if (alpm_activated) return; dir = opendir("/sys/class/scsi_host/"); if (!dir) return; while ((dirent = readdir(dir))) { if (dirent->d_name[0]=='.') continue; sprintf(filename, "/sys/class/scsi_host/%s/link_power_management_policy", dirent->d_name); file = fopen(filename, "r"); if (!file) continue; memset(line, 0, 1024); if (fgets(line, 1023,file)==NULL) { fclose(file); continue; } if (!strstr(line, "min_power\n")) need_hint = 1; fclose(file); } closedir(dir); if (need_hint) { add_suggestion(_("Suggestion: Enable SATA ALPM link power management via: \n" " echo min_power > /sys/class/scsi_host/host0/link_power_management_policy\n" "or press the S key."), 15, 'S', _(" S - SATA Link Power Management "), activate_alpm); } }
static int check_dels(trie_dict *t, string word, int edits, rb_tree *suggs){ int i, j; char c, ch; string tmp; tmp.len = word.len-1; tmp.str = alloca(tmp.len); //it may be possible to optimize this using the trie, But it doesn't seem //like it'd be worth it for(i=0;i<word.len;i++){ memcpy(tmp.str, word.str, i); memcpy(tmp.str + i, word.str + i + 1, word.len - (i+1)); if(trie_dict_lookup(t, tmp.mem, tmp.len)){ // DEBUG_PRINTF("adding suggestion (del) %.*s\n", (int)tmp.len, tmp.str); add_suggestion(suggs, tmp); } check_edits(t, tmp, edits-1, suggs); } return 0; }
void suggest_ac97_powersave(void) { FILE *file; char buffer[1024]; file = fopen("/sys/module/snd_ac97_codec/parameters/power_save", "r"); if (!file) return; memset(buffer, 0, 1024); if (!fgets(buffer, 1023, file)) { fclose(file); return; } if (buffer[0]=='N') { add_suggestion( _("Suggestion: enable AC97 powersave mode by executing the following command:\n" " echo 1 > /sys/module/snd_ac97_codec/parameters/power_save \n" "or by passing power_save=1 as module parameter."), 25, 'A', _(" A - Turn AC97 powersave on "), ac97_power_on); } fclose(file); }
void suggest_nmi_watchdog(void) { FILE *file; int i; char buffer[1024]; file = fopen("/proc/sys/kernel/nmi_watchdog", "r"); if (!file) return; memset(buffer, 0, 1024); if (!fgets(buffer, 1023, file)) { fclose(file); return; } i = strtoul(buffer, NULL, 10); if (i!=0) { add_suggestion( _("Suggestion: disable the NMI watchdog by executing the following command:\n" " echo 0 > /proc/sys/kernel/nmi_watchdog \n" "The NMI watchdog is a kernel debug mechanism to detect deadlocks"), 25, 'N', _(" N - Turn NMI watchdog off "), nmi_watchdog_off); } fclose(file); }
void suggest_xrandr_TV_off(void) { FILE *file; int has_tv = 0; int has_tv_active = 0; char line[1024]; if (has_no_xrandr) return; memset(line, 0, 1024); file = popen("xrandr 2> /dev/null", "r"); if (!file || feof(file)) { has_no_xrandr = 1; return; } while (!feof(file)) { if (fgets(line, 1024, file)==NULL) break; if (line[0]!=' ') { if (line[0]=='T' && line[1]=='V' && line[2]==' ') has_tv = 1; else has_tv = 0; } else { if (strchr(line,'*') && has_tv) has_tv_active = 1; } } pclose(file); if (has_tv_active) add_suggestion(_("Suggestion: disable TV out via: \n" " xrandr --output TV --off \n" "or press the V key."), 35, 'V', _(" V - Disable TV out "), activate_noTV); /* check this only once if no suggestion needed */ else has_no_xrandr = 1; }
void suggest_laptop_mode(void) { FILE *file; int i; char buffer[1024]; /* * Check to see if we are on AC - lots of distros have * annoying scripts to turn laptop mode off when on AC, which * results in annoying distracting return of set laptop mode * hint. */ file = fopen("/proc/acpi/ac_adapter/AC/state", "r"); if (!file) return; memset(buffer, 0, 1024); if (!fgets(buffer, 1023, file)) { fclose(file); return; } fclose(file); if (strstr(buffer, "on-line") != NULL) return; /* Now check for laptop mode */ file = fopen("/proc/sys/vm/laptop_mode", "r"); if (!file) return; memset(buffer, 0, 1024); if (!fgets(buffer, 1023, file)) { fclose(file); return; } i = strtoul(buffer, NULL, 10); if (i<1) { add_suggestion( _("Suggestion: Enable laptop-mode by executing the following command:\n" " echo 5 > /proc/sys/vm/laptop_mode \n"), 15, 'L', _(" L - enable Laptop mode "), set_laptop_mode); } fclose(file); }
void suggest_noatime(void) { FILE *file; char buffer[1024]; int suggest = 0; file = fopen("/proc/mounts","r"); if (!file) return; while (!feof(file)) { memset(buffer, 0, 1024); if (!fgets(buffer, 1023, file)) break; if (strstr(buffer, " / ext3") && !strstr(buffer, "noatime") && !strstr(buffer, "relatime")) suggest = 1; } if (suggest) { add_suggestion( _("Suggestion: enable the noatime filesystem option by executing the following command:\n" " mount -o remount,noatime / or by pressing the T key \n" "noatime disables persistent access time of file accesses, which causes lots of disk IO."), 5, 'T', _(" T - enable noatime "), noatime_on); } fclose(file); }
void suggest_writeback_time(void) { FILE *file; char buffer[1024]; int i; file = fopen("/proc/sys/vm/dirty_writeback_centisecs", "r"); if (!file) return; memset(buffer, 0, 1024); if (!fgets(buffer, 1023, file)) { fclose(file); return; } i = strtoull(buffer, NULL, 10); if (i<1400) { char line[1024]; sprintf(line,_("Suggestion: increase the VM dirty writeback time from %1.2f to 15 seconds with:\n" " echo 1500 > /proc/sys/vm/dirty_writeback_centisecs \n" "This wakes the disk up less frequently for background VM activity"), i/100.0); add_suggestion(line, 15, 'W', _(" W - Increase Writeback time "), writeback_long); } fclose(file); }
/* * Suggest the user to turn on/off a kernel config option. * "comment" gets displayed if it's not already set to the right value */ void suggest_kernel_config(char *string, int onoff, char *comment, int weight) { int i; char searchon[100]; char searchoff[100]; int found = 0; read_kernel_config(); sprintf(searchon, "%s=", string); sprintf(searchoff, "# %s is not set", string); for (i = 0; i < configcount; i++) { if (onoff && strstr(configlines[i], searchon)) return; if (onoff==0 && strstr(configlines[i], searchoff)) return; if (onoff==0 && strstr(configlines[i], searchon)) found = 1; } if (onoff || found) add_suggestion(comment, weight, 0, NULL, NULL); fflush(stdout); }