1 /*
2 * Copyright 2007, Intel Corporation
3 *
4 * This file is part of PowerTOP
5 *
6 * This program file is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program in a file named COPYING; if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
20 *
21 * Authors:
22 * Arjan van de Ven <arjan@linux.intel.com>
23 */
24
25 #include <unistd.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdint.h>
30 #include <sys/types.h>
31 #include <dirent.h>
32
33 #include "powertop.h"
34
35 int alpm_activated;
36
activate_alpm(void)37 static void activate_alpm(void)
38 {
39 DIR *dir;
40 struct dirent *dirent;
41 FILE *file;
42 char filename[PATH_MAX];
43
44 dir = opendir("/sys/class/scsi_host");
45 if (!dir)
46 return;
47
48 while ((dirent = readdir(dir))) {
49 if (dirent->d_name[0]=='.')
50 continue;
51 sprintf(filename, "/sys/class/scsi_host/%s/link_power_management_policy", dirent->d_name);
52 file = fopen(filename, "w");
53 if (!file)
54 continue;
55 fprintf(file, "min_power\n");
56 fclose(file);
57 }
58
59 closedir(dir);
60 alpm_activated = 1;
61 }
62
suggest_sata_alpm(void)63 void suggest_sata_alpm(void)
64 {
65 DIR *dir;
66 struct dirent *dirent;
67 FILE *file;
68 char filename[PATH_MAX];
69 char line[1024];
70 int need_hint = 0;
71
72 if (alpm_activated)
73 return;
74
75
76 dir = opendir("/sys/class/scsi_host/");
77 if (!dir)
78 return;
79
80 while ((dirent = readdir(dir))) {
81 if (dirent->d_name[0]=='.')
82 continue;
83 sprintf(filename, "/sys/class/scsi_host/%s/link_power_management_policy", dirent->d_name);
84 file = fopen(filename, "r");
85 if (!file)
86 continue;
87 memset(line, 0, 1024);
88 if (fgets(line, 1023,file)==NULL) {
89 fclose(file);
90 continue;
91 }
92 if (!strstr(line, "min_power"))
93 need_hint = 1;
94
95 fclose(file);
96 }
97
98 closedir(dir);
99
100 if (need_hint) {
101 add_suggestion(_("Suggestion: Enable SATA ALPM link power management via: \n"
102 " echo min_power > /sys/class/scsi_host/host0/link_power_management_policy\n"
103 "or press the S key."),
104 15, 'S', _(" S - SATA Link Power Management "), activate_alpm);
105 }
106 }
107