Count time and transitions between devfreq frequencies in separate struct devfreq_stats for improved code readability and maintenance.
Unified · Split
| @@ -224,8 +224,8 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) · 223 unmodified lines | ||
| 224 | 224 | goto out; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | − devfreq->time_in_state[prev_lev] += | |
| 228 | − cur_time - devfreq->last_stat_updated; | |
| 227 | + devfreq->stats.time_in_state[prev_lev] += | |
| 228 | + cur_time - devfreq->stats.last_update; | |
| 229 | 229 | |
| 230 | 230 | lev = devfreq_get_freq_level(devfreq, freq); |
| 231 | 231 | if (lev < 0) { |
| @@ -234,13 +234,13 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) · 2 unmodified lines | ||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | if (lev != prev_lev) { |
| 237 | − devfreq->trans_table[(prev_lev * | |
| 238 | − devfreq->profile->max_state) + lev]++; | |
| 239 | − devfreq->total_trans++; | |
| 237 | + devfreq->stats.trans_table[ | |
| 238 | + (prev_lev * devfreq->profile->max_state) + lev]++; | |
| 239 | + devfreq->stats.total_trans++; | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | out: |
| 243 | − devfreq->last_stat_updated = cur_time; | |
| 243 | + devfreq->stats.last_update = cur_time; | |
| 244 | 244 | return ret; |
| 245 | 245 | } |
| 246 | 246 | EXPORT_SYMBOL(devfreq_update_status); |
| @@ -535,7 +535,7 @@ void devfreq_monitor_resume(struct devfreq *devfreq) · 288 unmodified lines | ||
| 535 | 535 | msecs_to_jiffies(devfreq->profile->polling_ms)); |
| 536 | 536 | |
| 537 | 537 | out_update: |
| 538 | − devfreq->last_stat_updated = get_jiffies_64(); | |
| 538 | + devfreq->stats.last_update = get_jiffies_64(); | |
| 539 | 539 | devfreq->stop_polling = false; |
| 540 | 540 | |
| 541 | 541 | if (devfreq->profile->get_cur_freq && |
| @@ -807,28 +807,29 @@ struct devfreq *devfreq_add_device(struct device *dev, · 265 unmodified lines | ||
| 807 | 807 | goto err_out; |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | − devfreq->trans_table = devm_kzalloc(&devfreq->dev, | |
| 810 | + devfreq->stats.trans_table = devm_kzalloc(&devfreq->dev, | |
| 811 | 811 | array3_size(sizeof(unsigned int), |
| 812 | 812 | devfreq->profile->max_state, |
| 813 | 813 | devfreq->profile->max_state), |
| 814 | 814 | GFP_KERNEL); |
| 815 | − if (!devfreq->trans_table) { | |
| 815 | + if (!devfreq->stats.trans_table) { | |
| 816 | 816 | mutex_unlock(&devfreq->lock); |
| 817 | 817 | err = -ENOMEM; |
| 818 | 818 | goto err_devfreq; |
| 819 | 819 | } |
| 820 | 820 | |
| 821 | − devfreq->time_in_state = devm_kcalloc(&devfreq->dev, | |
| 821 | + devfreq->stats.time_in_state = devm_kcalloc(&devfreq->dev, | |
| 822 | 822 | devfreq->profile->max_state, |
| 823 | − sizeof(*devfreq->time_in_state), | |
| 823 | + sizeof(*devfreq->stats.time_in_state), | |
| 824 | 824 | GFP_KERNEL); |
| 825 | − if (!devfreq->time_in_state) { | |
| 825 | + if (!devfreq->stats.time_in_state) { | |
| 826 | 826 | mutex_unlock(&devfreq->lock); |
| 827 | 827 | err = -ENOMEM; |
| 828 | 828 | goto err_devfreq; |
| 829 | 829 | } |
| 830 | 830 | |
| 831 | − devfreq->last_stat_updated = get_jiffies_64(); | |
| 831 | + devfreq->stats.total_trans = 0; | |
| 832 | + devfreq->stats.last_update = get_jiffies_64(); | |
| 832 | 833 | |
| 833 | 834 | srcu_init_notifier_head(&devfreq->transition_notifier_list); |
| 834 | 835 | |
| @@ -1588,13 +1589,14 @@ static ssize_t trans_stat_show(struct device *dev, · 753 unmodified lines | ||
| 1588 | 1589 | devfreq->profile->freq_table[i]); |
| 1589 | 1590 | for (j = 0; j < max_state; j++) |
| 1590 | 1591 | len += sprintf(buf + len, "%10u", |
| 1591 | − devfreq->trans_table[(i * max_state) + j]); | |
| 1592 | + devfreq->stats.trans_table[(i * max_state) + j]); | |
| 1593 | + | |
| 1592 | 1594 | len += sprintf(buf + len, "%10llu\n", (u64) |
| 1593 | − jiffies64_to_msecs(devfreq->time_in_state[i])); | |
| 1595 | + jiffies64_to_msecs(devfreq->stats.time_in_state[i])); | |
| 1594 | 1596 | } |
| 1595 | 1597 | |
| 1596 | 1598 | len += sprintf(buf + len, "Total transition : %u\n", |
| 1597 | − devfreq->total_trans); | |
| 1599 | + devfreq->stats.total_trans); | |
| 1598 | 1600 | return len; |
| 1599 | 1601 | } |
| 1600 | 1602 | |
| @@ -1613,13 +1615,13 @@ static ssize_t trans_stat_store(struct device *dev, · 12 unmodified lines | ||
| 1613 | 1615 | return -EINVAL; |
| 1614 | 1616 | |
| 1615 | 1617 | mutex_lock(&df->lock); |
| 1616 | − memset(df->time_in_state, 0, (df->profile->max_state * | |
| 1617 | − sizeof(*df->time_in_state))); | |
| 1618 | − memset(df->trans_table, 0, array3_size(sizeof(unsigned int), | |
| 1618 | + memset(df->stats.time_in_state, 0, (df->profile->max_state * | |
| 1619 | + sizeof(*df->stats.time_in_state))); | |
| 1620 | + memset(df->stats.trans_table, 0, array3_size(sizeof(unsigned int), | |
| 1619 | 1621 | df->profile->max_state, |
| 1620 | 1622 | df->profile->max_state)); |
| 1621 | − df->total_trans = 0; | |
| 1622 | − df->last_stat_updated = get_jiffies_64(); | |
| 1623 | + df->stats.total_trans = 0; | |
| 1624 | + df->stats.last_update = get_jiffies_64(); | |
| 1623 | 1625 | mutex_unlock(&df->lock); |
| 1624 | 1626 | |
| 1625 | 1627 | return count; |
| @@ -107,6 +107,20 @@ struct devfreq_dev_profile { · 106 unmodified lines | ||
| 107 | 107 | unsigned int max_state; |
| 108 | 108 | }; |
| 109 | 109 | |
| 110 | +/** | |
| 111 | + * struct devfreq_stats - Statistics of devfreq device behavior | |
| 112 | + * @total_trans: Number of devfreq transitions. | |
| 113 | + * @trans_table: Statistics of devfreq transitions. | |
| 114 | + * @time_in_state: Statistics of devfreq states. | |
| 115 | + * @last_update: The last time stats were updated. | |
| 116 | + */ | |
| 117 | +struct devfreq_stats { | |
| 118 | + unsigned int total_trans; | |
| 119 | + unsigned int *trans_table; | |
| 120 | + u64 *time_in_state; | |
| 121 | + u64 last_update; | |
| 122 | +}; | |
| 123 | + | |
| 110 | 124 | /** |
| 111 | 125 | * struct devfreq - Device devfreq structure |
| 112 | 126 | * @node: list node - contains the devices with devfreq that have been |
| @@ -132,10 +146,7 @@ struct devfreq_dev_profile { · 19 unmodified lines | ||
| 132 | 146 | * @suspend_freq: frequency of a device set during suspend phase. |
| 133 | 147 | * @resume_freq: frequency of a device set in resume phase. |
| 134 | 148 | * @suspend_count: suspend requests counter for a device. |
| 135 | − * @total_trans: Number of devfreq transitions | |
| 136 | − * @trans_table: Statistics of devfreq transitions | |
| 137 | − * @time_in_state: Statistics of devfreq states | |
| 138 | − * @last_stat_updated: The last time stat updated | |
| 149 | + * @stats: Statistics of devfreq device behavior | |
| 139 | 150 | * @transition_notifier_list: list head of DEVFREQ_TRANSITION_NOTIFIER notifier |
| 140 | 151 | * @nb_min: Notifier block for DEV_PM_QOS_MIN_FREQUENCY |
| 141 | 152 | * @nb_max: Notifier block for DEV_PM_QOS_MAX_FREQUENCY |
| @@ -174,11 +185,8 @@ struct devfreq { · 32 unmodified lines | ||
| 174 | 185 | unsigned long resume_freq; |
| 175 | 186 | atomic_t suspend_count; |
| 176 | 187 | |
| 177 | − /* information for device frequency transition */ | |
| 178 | − unsigned int total_trans; | |
| 179 | − unsigned int *trans_table; | |
| 180 | − u64 *time_in_state; | |
| 181 | − u64 last_stat_updated; | |
| 188 | + /* information for device frequency transitions */ | |
| 189 | + struct devfreq_stats stats; | |
| 182 | 190 | |
| 183 | 191 | struct srcu_notifier_head transition_notifier_list; |
| 184 | 192 | |