[Cpufreqd-devel] sources2/src main.c,1.6,1.7
Brought to you by:
mattia-san
From: Mattia D. <mat...@us...> - 2005-07-03 16:38:49
|
Update of /cvsroot/cpufreqd/sources2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18004 Modified Files: main.c Log Message: - readability cleanups - found some bugs in all those casts Index: main.c =================================================================== RCS file: /cvsroot/cpufreqd/sources2/src/main.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** main.c 3 Jul 2005 15:46:01 -0000 1.6 --- main.c 3 Jul 2005 16:38:39 -0000 1.7 *************** *** 60,63 **** --- 60,65 ---- struct NODE *n, *np_iter, *nr_iter; struct plugin_obj *o_plugin; + struct profile *tmp_profile; + struct rule *tmp_rule; char buf[256]; *************** *** 120,124 **** } /* create governor string */ ! if ((((struct profile *)n->content)->policy.governor = malloc(MAX_STRING_LEN*sizeof(char))) ==NULL) { cpufreqd_log(LOG_ERR, "init_configuration(): cannot make enough room for a new Profile governor (%s)\n", strerror(errno)); --- 122,127 ---- } /* create governor string */ ! tmp_profile = (struct profile *)n->content; ! if ((tmp_profile->policy.governor = malloc(MAX_STRING_LEN*sizeof(char))) ==NULL) { cpufreqd_log(LOG_ERR, "init_configuration(): cannot make enough room for a new Profile governor (%s)\n", strerror(errno)); *************** *** 126,136 **** } ! if ( parse_config_profile(fp_config, n->content) != -1) { /* checks duplicate names */ for (np_iter=configuration.profiles.first; np_iter!=NULL; np_iter=np_iter->next) { ! if (strcmp(((struct profile *)np_iter->content)->name, ((struct profile *)n->content)->name) == 0) { cpufreqd_log(LOG_CRIT, "init_configuration(): [Profile] name \"%s\" already exists.\n", ! ((struct profile *)n->content)->name); node_free(n); fclose(fp_config); --- 129,139 ---- } ! if ( parse_config_profile(fp_config, tmp_profile) != -1) { /* checks duplicate names */ for (np_iter=configuration.profiles.first; np_iter!=NULL; np_iter=np_iter->next) { ! if (strcmp(((struct profile *)np_iter->content)->name, tmp_profile->name) == 0) { cpufreqd_log(LOG_CRIT, "init_configuration(): [Profile] name \"%s\" already exists.\n", ! tmp_profile->name); node_free(n); fclose(fp_config); *************** *** 161,171 **** } ! if ( parse_config_rule(fp_config, n->content) != -1) { for (nr_iter=configuration.rules.first; nr_iter!=NULL; nr_iter=nr_iter->next) { /* check duplicate names */ ! if (strcmp(((struct profile *)nr_iter->content)->name, ((struct profile *)n->content)->name) == 0) { cpufreqd_log(LOG_CRIT, "init_configuration(): [Rule] name \"%s\" already exists.\n", ! ((struct profile *)n->content)->name); node_free(n); return -1; --- 164,175 ---- } ! tmp_rule = (struct rule *)n->content; ! if ( parse_config_rule(fp_config, tmp_rule) != -1) { for (nr_iter=configuration.rules.first; nr_iter!=NULL; nr_iter=nr_iter->next) { /* check duplicate names */ ! if (strcmp(((struct rule *)nr_iter->content)->name, tmp_rule->name) == 0) { cpufreqd_log(LOG_CRIT, "init_configuration(): [Rule] name \"%s\" already exists.\n", ! tmp_rule->name); node_free(n); return -1; *************** *** 198,208 **** */ for (nr_iter=configuration.rules.first; nr_iter!=NULL; nr_iter=nr_iter->next) { int profile_found = 0; for (np_iter=configuration.profiles.first; np_iter!=NULL; np_iter=np_iter->next) { ! /* go through profiles */ ! if (strcmp( ! ((struct rule *)nr_iter->content)->profile_name, ! ((struct profile *)np_iter->content)->name)==0) { /* a profile is allowed to be addressed by more than 1 rule */ ((struct rule *)nr_iter->content)->prof = np_iter->content; --- 202,212 ---- */ for (nr_iter=configuration.rules.first; nr_iter!=NULL; nr_iter=nr_iter->next) { + tmp_rule = (struct rule *)nr_iter->content; int profile_found = 0; for (np_iter=configuration.profiles.first; np_iter!=NULL; np_iter=np_iter->next) { ! tmp_profile = (struct profile *)np_iter->content; ! /* go through profiles */ ! if (strcmp(tmp_rule->profile_name, tmp_profile->name)==0) { /* a profile is allowed to be addressed by more than 1 rule */ ((struct rule *)nr_iter->content)->prof = np_iter->content; *************** *** 214,220 **** if (!profile_found) { cpufreqd_log(LOG_CRIT, "init_configuration(): Syntax error: no Profile section found for Rule \"%s\" \ ! (requested Profile \"%s\")\n", ! ((struct rule *)nr_iter->content)->name, ! ((struct rule *)nr_iter->content)->profile_name); return -1; } --- 218,222 ---- if (!profile_found) { cpufreqd_log(LOG_CRIT, "init_configuration(): Syntax error: no Profile section found for Rule \"%s\" \ ! (requested Profile \"%s\")\n", tmp_rule->name, tmp_rule->profile_name); return -1; } *************** *** 222,228 **** for (nr_iter=configuration.rules.first; nr_iter!=NULL; nr_iter=nr_iter->next) { ! cpufreqd_log(LOG_INFO, "init_configuration(): Rule \"%s\" has Profile \"%s\"\n", ! ((struct rule *)nr_iter->content)->name, ((struct rule *)nr_iter->content)->prof->name); } return 0; --- 224,231 ---- for (nr_iter=configuration.rules.first; nr_iter!=NULL; nr_iter=nr_iter->next) { ! tmp_rule = (struct rule *)nr_iter->content; ! cpufreqd_log(LOG_INFO, "init_configuration(): Rule \"%s\" has Profile \"%s\"\n", ! tmp_rule->name, tmp_rule->prof->name); } return 0; *************** *** 440,444 **** /* if one of the probes fails remove all the others also */ if (cpufreq_get_hardware_limits(i, &((configuration.limits+i)->min), &((configuration.limits+i)->max))!=0) { ! /* TODO: if libcpufreq fails try to read /proc/cpuinfo and warn about this not baing reliable */ cpufreqd_log(LOG_WARNING, "Unable to get hardware frequency limits for CPU%d.\n", i); free(configuration.limits); --- 443,447 ---- /* if one of the probes fails remove all the others also */ if (cpufreq_get_hardware_limits(i, &((configuration.limits+i)->min), &((configuration.limits+i)->max))!=0) { ! /* TODO: if libcpufreq fails try to read /proc/cpuinfo and warn about this not being reliable */ cpufreqd_log(LOG_WARNING, "Unable to get hardware frequency limits for CPU%d.\n", i); free(configuration.limits); *************** *** 515,518 **** --- 518,522 ---- } + tmp_score = 0; /* got objects and config now test it, call plugin->eval for each rule */ /* O(rules*entries) */ *************** *** 520,524 **** tmp_rule = (struct rule*)nd->content; /* reset the score before counting */ ! tmp_rule->score = tmp_score = i = 0; cpufreqd_log(LOG_DEBUG, "Considering Rule \"%s\"\n", tmp_rule->name); --- 524,528 ---- tmp_rule = (struct rule*)nd->content; /* reset the score before counting */ ! tmp_rule->score = i = 0; cpufreqd_log(LOG_DEBUG, "Considering Rule \"%s\"\n", tmp_rule->name); *************** *** 536,540 **** * so that a single entry rule might be the best match */ - if ((100*tmp_rule->score)/i > tmp_score) { tmp_profile = tmp_rule->prof; --- 540,543 ---- *************** *** 542,546 **** } ! cpufreqd_log(LOG_INFO, "Rule \"%s\" score: %d%%\n", tmp_rule->name, tmp_rule->score++); } /* end foreach rule */ --- 545,550 ---- } ! cpufreqd_log(LOG_INFO, "Rule \"%s\" score: %d%%\n", tmp_rule->name, ! (100*tmp_rule->score)/i); } /* end foreach rule */ |