]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - frsh_aquosa/mngr/disk.c
Splitted frsh_servicethe.c
[frescor/fwp.git] / frsh_aquosa / mngr / disk.c
1
2 /***************************************************************************/
3 /* H A R D   D I S K   H A N D L I N G   U T I L I T Y   F U N C T I O N S */
4 /***************************************************************************/
5
6 static bool disk_init()
7 {
8         int i;
9
10         for (i = 0; i < N_DISKS; i++) {
11                 disk[i].aggregate_bw = DISK_DEFAULT_AGGREGATE_BW;
12                 disk[i].sched_budget = DISK_DEFAULT_SCHED_BUDGET;
13                 disk[i].weight_sum = 0;
14                 disk[i].thread_num = 0;
15         }
16
17         return true;
18 }
19
20 static inline unsigned int disk_sched_ioprio(unsigned int weight) {
21
22         if (weight == 100)
23                 return 0;
24         if (weight > 14)
25                 return 1;
26         return 8 - 1 - (weight / 2);
27 }
28
29 static inline unsigned int disk_sched_ioweight(frsh_resource_id_t disk_id, struct timespec budget, struct timespec period) {
30         float th, weight;
31         int b, w_i;
32         unsigned long int q_i, p_i;
33
34         th = disk[disk_id_2_index(disk_id)].aggregate_bw / 10E9;
35         b = disk[disk_id_2_index(disk_id)].sched_budget;
36
37         /* nsec */
38         q_i = timespec_to_usec(budget);
39         p_i = timespec_to_usec(period);
40         q_i *= 1000;
41         p_i *= 1000;
42
43         if (p_i < b / th)
44                 return -1;
45
46         weight = (DISK_WEIGHT_MAX * q_i ) / (p_i - (b / th));
47         w_i = floor(weight);
48         
49         if (weight != w_i)
50                 w_i++;
51
52         return w_i;
53 }
54
55 static inline float disk_sched_iobandwidth(frsh_resource_id_t disk_id, unsigned int weight) {
56         return (float) weight * (disk[disk_id_2_index(disk_id)].aggregate_bw / disk[disk_id_2_index(disk_id)].weight_sum);
57 }
58