Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Avoid strict-aliasing related issues when compiling with optimization
[palacios.git] / linux_usr / v3_dvfs.c
1 #include <stdint.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include "v3_user_dvfs.h"
6
7 void usage() 
8 {
9     fprintf(stderr,"usage: v3_dvfs core|core..core command\n");
10     fprintf(stderr,"    where command is one of the following\n");
11     fprintf(stderr,"           acquire direct|external\n");
12     fprintf(stderr,"           pstate  number\n");
13     fprintf(stderr,"           freq    number (kHz)\n");
14     fprintf(stderr,"           release\n\n"); 
15     fprintf(stderr,"Look at /proc/v3vee/v3-dvfs to see state\n\n");
16 }
17
18   
19
20 int main(int argc, char *argv[])
21 {
22   if (argc!=4 && argc!=3) { 
23     usage();
24     return -1;
25   }
26
27
28   uint32_t corestart, coreend, core ;
29   int rc;
30   char *cmd=argv[2];
31
32   if (strstr(argv[1],"..")) { 
33       if (sscanf(argv[1],"%u..%u",&corestart,&coreend)!=2) {
34           usage();
35           return -1;
36       }
37   } else {
38       corestart=coreend=atoi(argv[1]);
39   }
40
41
42   if (argc==3 && strcasecmp(cmd,"release")) { 
43       usage();
44       return -1;
45   }
46
47   char *arg=argv[3];
48
49   rc=0;
50
51   for (core=corestart;core<=coreend;core++) {
52       if (!strcasecmp(cmd,"acquire")) { 
53           if (!strcasecmp(arg,"direct")) { 
54               if (v3_user_dvfs_acquire_direct(core)) { 
55                   fprintf(stderr,"Failed to set core %u to direct\n",core);
56                   rc=-1;
57               } else {
58                   fprintf(stderr,"Core %u set to direct\n",core);
59               }
60           } else if (!strcasecmp(arg,"external")) {
61               if (v3_user_dvfs_acquire_external(core)) { 
62                   fprintf(stderr,"Failed to set core %u to external\n",core);
63                   rc=-1;
64               } else {
65                   fprintf(stderr,"Core %u set to external\n",core);
66               }
67           } else {
68               usage();
69               return -1;
70           }
71       } else if (!strcasecmp(cmd,"pstate")) { 
72           if (v3_user_dvfs_set_pstate(core,atoll(arg))) { 
73               fprintf(stderr,"Failed to set core %u to pstate %d\n",core,atoi(arg));
74               rc=-1;
75           } else {
76               fprintf(stderr,"Core %u set to pstate %d\n",core,atoi(arg));
77           }
78       } else if (!strcasecmp(cmd,"freq")) { 
79           if (v3_user_dvfs_set_freq(core,atoll(arg))) { 
80               fprintf(stderr,"Failed to set core %u to frequency %lld kHz\n",core,atoll(arg));
81               rc=-1;
82           } else {
83               fprintf(stderr,"Core %u set to frequency %lld kHz\n",core,atoll(arg));
84           }
85       } else if (!strcasecmp(cmd,"release")) { 
86           if (v3_user_dvfs_release(core)) { 
87               fprintf(stderr,"Failed to release core %u to host control\n",core);
88               rc=-1;
89           } else {
90               fprintf(stderr,"Released core %u to host control\n",core);
91           }
92       } else {
93           usage();
94           return -1;
95       }
96   }
97
98   return rc;
99
100 }
101