From: Kyle Hale, Shiva Rao, and Peter Dinda Date: Wed, 13 Aug 2014 00:05:25 +0000 (-0500) Subject: P-State control on Linux - User Utility and Library X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=624392c7b8a4c9a00939315e62add5f30d3d807c P-State control on Linux - User Utility and Library --- diff --git a/linux_usr/Makefile b/linux_usr/Makefile index f1aaaca..e57a444 100644 --- a/linux_usr/Makefile +++ b/linux_usr/Makefile @@ -33,7 +33,8 @@ BASE_EXECS = v3_mem \ v3_receive \ v3_pci \ v3_guest_mem_access \ - v3_guest_mem_track + v3_guest_mem_track \ + v3_dvfs # @@ -67,7 +68,7 @@ COPIED_EXECS = v3_x0vncserver v3_x0gui # # Libraries that we need to build # -LIBS = libv3_user_host_dev.a libv3_user_keyed_stream.a libv3_ctrl.a libv3_guest_mem.a libv3_fb.a +LIBS = libv3_user_host_dev.a libv3_user_keyed_stream.a libv3_ctrl.a libv3_guest_mem.a libv3_fb.a libv3_user_dvfs.a BUILD_EXECS = $(BASE_EXECS) $(EXAMPLE_EXECS) $(EXPERIMENTAL_EXECS) BUILD_LIBS = $(LIBS) @@ -180,6 +181,17 @@ v3_guest_mem_access : v3_guest_mem_access.c libv3_guest_mem.a libv3_ctrl.a v3_guest_mem_track : v3_guest_mem_track.c libv3_guest_mem.a libv3_ctrl.a $(CC) $(CFLAGS) $< -L. -lv3_guest_mem -lv3_ctrl -o $@ +# +# User DVFS control includse a library and a caller +# +libv3_user_dvfs.a : v3_user_dvfs.c v3_user_dvfs.h v3_ctrl.h + $(CC) $(CFLAGS) -I../linux_module -c v3_user_dvfs.c + $(AR) ruv libv3_user_dvfs.a v3_user_dvfs.o + rm -f v3_user_dvfs.o + +v3_dvfs : v3_dvfs.c libv3_user_dvfs.a libv3_ctrl.a + $(CC) $(CFLAGS) $< -I../linux_module -L. -lv3_user_dvfs -lv3_ctrl -o $@ + # # FB (Graphics Console) user interface library (needed for VNC access diff --git a/linux_usr/v3_ctrl.h b/linux_usr/v3_ctrl.h index 20eadc4..8b448bc 100644 --- a/linux_usr/v3_ctrl.h +++ b/linux_usr/v3_ctrl.h @@ -21,6 +21,8 @@ #define V3_ADD_PCI_HW_DEV 55 #define V3_ADD_PCI_USER_DEV 56 +#define V3_DVFS_CTRL 60 + /* VM Specific IOCTLs */ /* VM Specific ioctls */ diff --git a/linux_usr/v3_dvfs.c b/linux_usr/v3_dvfs.c new file mode 100644 index 0000000..edd655f --- /dev/null +++ b/linux_usr/v3_dvfs.c @@ -0,0 +1,101 @@ +#include +#include +#include + +#include "v3_user_dvfs.h" + +void usage() +{ + fprintf(stderr,"usage: v3_dvfs core|core..core command\n"); + fprintf(stderr," where command is one of the following\n"); + fprintf(stderr," acquire direct|external\n"); + fprintf(stderr," pstate number\n"); + fprintf(stderr," freq number (kHz)\n"); + fprintf(stderr," release\n\n"); + fprintf(stderr,"Look at /proc/v3vee/v3-dvfs to see state\n\n"); +} + + + +int main(int argc, char *argv[]) +{ + if (argc!=4 && argc!=3) { + usage(); + return -1; + } + + + uint32_t corestart, coreend, core ; + int rc; + char *cmd=argv[2]; + + if (strstr(argv[1],"..")) { + if (sscanf(argv[1],"%u..%u",&corestart,&coreend)!=2) { + usage(); + return -1; + } + } else { + corestart=coreend=atoi(argv[1]); + } + + + if (argc==3 && strcasecmp(cmd,"release")) { + usage(); + return -1; + } + + char *arg=argv[3]; + + rc=0; + + for (core=corestart;core<=coreend;core++) { + if (!strcasecmp(cmd,"acquire")) { + if (!strcasecmp(arg,"direct")) { + if (v3_user_dvfs_acquire_direct(core)) { + fprintf(stderr,"Failed to set core %u to direct\n",core); + rc=-1; + } else { + fprintf(stderr,"Core %u set to direct\n",core); + } + } else if (!strcasecmp(arg,"external")) { + if (v3_user_dvfs_acquire_external(core)) { + fprintf(stderr,"Failed to set core %u to external\n",core); + rc=-1; + } else { + fprintf(stderr,"Core %u set to external\n",core); + } + } else { + usage(); + return -1; + } + } else if (!strcasecmp(cmd,"pstate")) { + if (v3_user_dvfs_set_pstate(core,atoi(arg))) { + fprintf(stderr,"Failed to set core %u to pstate %d\n",core,atoi(arg)); + rc=-1; + } else { + fprintf(stderr,"Core %u set to pstate %d\n",core,atoi(arg)); + } + } else if (!strcasecmp(cmd,"freq")) { + if (v3_user_dvfs_set_freq(core,atoll(arg))) { + fprintf(stderr,"Failed to set core %u to frequency %lld kHz\n",core,atoll(arg)); + rc=-1; + } else { + fprintf(stderr,"Core %u set to frequency %lld kHz\n",core,atoll(arg)); + } + } else if (!strcasecmp(cmd,"release")) { + if (v3_user_dvfs_release(core)) { + fprintf(stderr,"Failed to release core %u to host control\n",core); + rc=-1; + } else { + fprintf(stderr,"Released core %u to host control\n",core); + } + } else { + usage(); + return -1; + } + } + + return rc; + +} +