/* * The Versatile Governor * *vsgov-locator: deals with detecting and setting throttle info. Copyright (C) 2004 Joseph Pingenot This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "libproc/acpi.h" #include "vsgov-locator.h" /***************************************************************** *Internal throttling functions *****************************************************************/ unsigned int locate_throttling(struct libproc_acpi_cputhrottling* throttle, float tload) { struct libproc_acpi_tstate* tstate; struct libproc_acpi_tstate* best = NULL; /*Freedom is the opposite of load. It's a measure of how little we need the * processor.*/ unsigned int freedom = 100 - (int)(tload*100.0); //float fload = tload*100.0; //float fload2 = fload; //int load = (int)fload; //freedom = 100 - load; //printf(" freedom: %d, tload=%f (fload=%f, fload2=%f, load=%d)\n", freedom, tload, fload, fload2, load); /*Walk through the list. Who is closest?*/ for(tstate = throttle->tstates; tstate != NULL; tstate = tstate->next) { //printf(" tstate: T%d, tstate->throttling: %d%%; best: T%d, best->throttling: %d%%\n", tstate->state, tstate->throttling, (best == NULL)? -1:best->state, (best == NULL)? -1:best->throttling); /*We seek the tstate that is the closest to the freedom we have.*/ if((best == NULL) || (abs(tstate->throttling - freedom) < abs(best->throttling - freedom))){ //printf("***this is the best state now.\n"); /*Match. This is now the best.*/ best = tstate; } } /*Now we have a winner.*/ if(best == NULL) { /*Default is no throttling*/ return 0; }else{ return best->state; } }