#include <stdio.h>
#include<string.h>
int prio_map_to_weight(int prio_min, int prio_max, int weight_beg, int weight_end, int prio)
{
int weight;
weight = weight_beg - (prio - prio_min)*(weight_beg - weight_end +1)/(prio_max - prio_min + 1);
return weight;
}
void mi_prio_weight_update(int prio)
{
int prio_list[2][9] = {{139, 129, 119, 109, 99, 89, 79, 49, -1}, {1, 6, 11, 16, 21, 26, 31, 36, 41}};
int i;
int prio_min = 0;
int prio_max = 0;
int weight_beg= 40;
int weight_end = 40;
int PRIO_LEVEL_MAX = sizeof(prio_list[0])/sizeof(prio_list[0][0]);
int prio_weight;
for (i = 0; i < PRIO_LEVEL_MAX; i++) {
if (prio == prio_list[0][i]) {
prio_weight = prio_list[1][i];
printf("%d:%d\n", prio, prio_weight);
return;
} else if (prio > prio_list[0][i]) {
prio_min = prio_list[0][i] + 1;
prio_max = prio_list[0][i-1];
weight_beg = prio_list[1][i] - 1;
weight_end = prio_list[1][i-1];
break;
}
}
prio_weight = prio_map_to_weight(prio_min, prio_max, weight_beg, weight_end, prio);
printf("%d:%d\n", prio, prio_weight);
}
void mi_cgroup_weight_update(const char * cgroup_name)
{
char cgroup_list[6][20] = {"top-app", "foreground", "audio", "system-backgroud", "backgroud", "other"};
int cgroup_weight_list[6] = {30, 25, 20, 15, 5, 10};
int cgroup_weight;
int CGROUP_NUM = sizeof(cgroup_list)/sizeof(cgroup_list[0]);
int i;
for(i = 0; i < CGROUP_NUM - 1; i++)
{
if (!strcmp(cgroup_name, cgroup_list[i])) {
cgroup_weight = cgroup_weight_list[i];
printf("%s:%d\n", cgroup_name, cgroup_weight);
return;
}
}
cgroup_weight = cgroup_weight_list[i];
printf("%s:%d\n", cgroup_name, cgroup_weight);
}
int mi_tag_weight_update(int index)
{
int tag_list[6] = {30, 25, 20, 15, 10, 5};
int tag_weight;
if (index != -1)
tag_weight = tag_list[index];
printf("%d:%d\n", index, tag_weight);
return 0;
}
int main () {
for (int i =130; i< 140;i++)
mi_prio_weight_update(i);
const char a[]="system-backgroud";
const char *p = &a;
mi_cgroup_weight_update(p);
for (int i = -1;i < 6;i++)
mi_tag_weight_update(i);
return 0;
}