1 /* SPDX-License-Identifier: GPL-2.0 1 /* SPDX-License-Identifier: GPL-2.0 2 * 2 * 3 * Legacy blkg rwstat helpers enabled by CONFI 3 * Legacy blkg rwstat helpers enabled by CONFIG_BLK_CGROUP_RWSTAT. 4 * Do not use in new code. 4 * Do not use in new code. 5 */ 5 */ 6 #include "blk-cgroup-rwstat.h" 6 #include "blk-cgroup-rwstat.h" 7 7 8 int blkg_rwstat_init(struct blkg_rwstat *rwsta 8 int blkg_rwstat_init(struct blkg_rwstat *rwstat, gfp_t gfp) 9 { 9 { 10 int i, ret; 10 int i, ret; 11 11 12 ret = percpu_counter_init_many(rwstat- !! 12 for (i = 0; i < BLKG_RWSTAT_NR; i++) { 13 if (ret) !! 13 ret = percpu_counter_init(&rwstat->cpu_cnt[i], 0, gfp); 14 return ret; !! 14 if (ret) { 15 !! 15 while (--i >= 0) 16 for (i = 0; i < BLKG_RWSTAT_NR; i++) !! 16 percpu_counter_destroy(&rwstat->cpu_cnt[i]); >> 17 return ret; >> 18 } 17 atomic64_set(&rwstat->aux_cnt[ 19 atomic64_set(&rwstat->aux_cnt[i], 0); >> 20 } 18 return 0; 21 return 0; 19 } 22 } 20 EXPORT_SYMBOL_GPL(blkg_rwstat_init); 23 EXPORT_SYMBOL_GPL(blkg_rwstat_init); 21 24 22 void blkg_rwstat_exit(struct blkg_rwstat *rwst 25 void blkg_rwstat_exit(struct blkg_rwstat *rwstat) 23 { 26 { 24 percpu_counter_destroy_many(rwstat->cp !! 27 int i; >> 28 >> 29 for (i = 0; i < BLKG_RWSTAT_NR; i++) >> 30 percpu_counter_destroy(&rwstat->cpu_cnt[i]); 25 } 31 } 26 EXPORT_SYMBOL_GPL(blkg_rwstat_exit); 32 EXPORT_SYMBOL_GPL(blkg_rwstat_exit); 27 33 28 /** 34 /** 29 * __blkg_prfill_rwstat - prfill helper for a 35 * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat 30 * @sf: seq_file to print to 36 * @sf: seq_file to print to 31 * @pd: policy private data of interest 37 * @pd: policy private data of interest 32 * @rwstat: rwstat to print 38 * @rwstat: rwstat to print 33 * 39 * 34 * Print @rwstat to @sf for the device assocai 40 * Print @rwstat to @sf for the device assocaited with @pd. 35 */ 41 */ 36 u64 __blkg_prfill_rwstat(struct seq_file *sf, 42 u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd, 37 const struct blkg_rws 43 const struct blkg_rwstat_sample *rwstat) 38 { 44 { 39 static const char *rwstr[] = { 45 static const char *rwstr[] = { 40 [BLKG_RWSTAT_READ] = "Rea 46 [BLKG_RWSTAT_READ] = "Read", 41 [BLKG_RWSTAT_WRITE] = "Wri 47 [BLKG_RWSTAT_WRITE] = "Write", 42 [BLKG_RWSTAT_SYNC] = "Syn 48 [BLKG_RWSTAT_SYNC] = "Sync", 43 [BLKG_RWSTAT_ASYNC] = "Asy 49 [BLKG_RWSTAT_ASYNC] = "Async", 44 [BLKG_RWSTAT_DISCARD] = "Dis 50 [BLKG_RWSTAT_DISCARD] = "Discard", 45 }; 51 }; 46 const char *dname = blkg_dev_name(pd-> 52 const char *dname = blkg_dev_name(pd->blkg); 47 u64 v; 53 u64 v; 48 int i; 54 int i; 49 55 50 if (!dname) 56 if (!dname) 51 return 0; 57 return 0; 52 58 53 for (i = 0; i < BLKG_RWSTAT_NR; i++) 59 for (i = 0; i < BLKG_RWSTAT_NR; i++) 54 seq_printf(sf, "%s %s %llu\n", 60 seq_printf(sf, "%s %s %llu\n", dname, rwstr[i], 55 rwstat->cnt[i]); 61 rwstat->cnt[i]); 56 62 57 v = rwstat->cnt[BLKG_RWSTAT_READ] + 63 v = rwstat->cnt[BLKG_RWSTAT_READ] + 58 rwstat->cnt[BLKG_RWSTAT_WRITE] 64 rwstat->cnt[BLKG_RWSTAT_WRITE] + 59 rwstat->cnt[BLKG_RWSTAT_DISCAR 65 rwstat->cnt[BLKG_RWSTAT_DISCARD]; 60 seq_printf(sf, "%s Total %llu\n", dnam 66 seq_printf(sf, "%s Total %llu\n", dname, v); 61 return v; 67 return v; 62 } 68 } 63 EXPORT_SYMBOL_GPL(__blkg_prfill_rwstat); 69 EXPORT_SYMBOL_GPL(__blkg_prfill_rwstat); 64 70 65 /** 71 /** 66 * blkg_prfill_rwstat - prfill callback for bl 72 * blkg_prfill_rwstat - prfill callback for blkg_rwstat 67 * @sf: seq_file to print to 73 * @sf: seq_file to print to 68 * @pd: policy private data of interest 74 * @pd: policy private data of interest 69 * @off: offset to the blkg_rwstat in @pd 75 * @off: offset to the blkg_rwstat in @pd 70 * 76 * 71 * prfill callback for printing a blkg_rwstat. 77 * prfill callback for printing a blkg_rwstat. 72 */ 78 */ 73 u64 blkg_prfill_rwstat(struct seq_file *sf, st 79 u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd, 74 int off) 80 int off) 75 { 81 { 76 struct blkg_rwstat_sample rwstat = { } 82 struct blkg_rwstat_sample rwstat = { }; 77 83 78 blkg_rwstat_read((void *)pd + off, &rw 84 blkg_rwstat_read((void *)pd + off, &rwstat); 79 return __blkg_prfill_rwstat(sf, pd, &r 85 return __blkg_prfill_rwstat(sf, pd, &rwstat); 80 } 86 } 81 EXPORT_SYMBOL_GPL(blkg_prfill_rwstat); 87 EXPORT_SYMBOL_GPL(blkg_prfill_rwstat); 82 88 83 /** 89 /** 84 * blkg_rwstat_recursive_sum - collect hierarc 90 * blkg_rwstat_recursive_sum - collect hierarchical blkg_rwstat 85 * @blkg: blkg of interest 91 * @blkg: blkg of interest 86 * @pol: blkcg_policy which contains the blkg_ 92 * @pol: blkcg_policy which contains the blkg_rwstat 87 * @off: offset to the blkg_rwstat in blkg_pol 93 * @off: offset to the blkg_rwstat in blkg_policy_data or @blkg 88 * @sum: blkg_rwstat_sample structure containi 94 * @sum: blkg_rwstat_sample structure containing the results 89 * 95 * 90 * Collect the blkg_rwstat specified by @blkg, 96 * Collect the blkg_rwstat specified by @blkg, @pol and @off and all its 91 * online descendants and their aux counts. T 97 * online descendants and their aux counts. The caller must be holding the 92 * queue lock for online tests. 98 * queue lock for online tests. 93 * 99 * 94 * If @pol is NULL, blkg_rwstat is at @off byt 100 * If @pol is NULL, blkg_rwstat is at @off bytes into @blkg; otherwise, it 95 * is at @off bytes into @blkg's blkg_policy_d 101 * is at @off bytes into @blkg's blkg_policy_data of the policy. 96 */ 102 */ 97 void blkg_rwstat_recursive_sum(struct blkcg_gq 103 void blkg_rwstat_recursive_sum(struct blkcg_gq *blkg, struct blkcg_policy *pol, 98 int off, struct blkg_rwstat_sa 104 int off, struct blkg_rwstat_sample *sum) 99 { 105 { 100 struct blkcg_gq *pos_blkg; 106 struct blkcg_gq *pos_blkg; 101 struct cgroup_subsys_state *pos_css; 107 struct cgroup_subsys_state *pos_css; 102 unsigned int i; 108 unsigned int i; 103 109 104 lockdep_assert_held(&blkg->q->queue_lo 110 lockdep_assert_held(&blkg->q->queue_lock); 105 111 106 memset(sum, 0, sizeof(*sum)); << 107 rcu_read_lock(); 112 rcu_read_lock(); 108 blkg_for_each_descendant_pre(pos_blkg, 113 blkg_for_each_descendant_pre(pos_blkg, pos_css, blkg) { 109 struct blkg_rwstat *rwstat; 114 struct blkg_rwstat *rwstat; 110 115 111 if (!pos_blkg->online) 116 if (!pos_blkg->online) 112 continue; 117 continue; 113 118 114 if (pol) 119 if (pol) 115 rwstat = (void *)blkg_ 120 rwstat = (void *)blkg_to_pd(pos_blkg, pol) + off; 116 else 121 else 117 rwstat = (void *)pos_b 122 rwstat = (void *)pos_blkg + off; 118 123 119 for (i = 0; i < BLKG_RWSTAT_NR 124 for (i = 0; i < BLKG_RWSTAT_NR; i++) 120 sum->cnt[i] += blkg_rw !! 125 sum->cnt[i] = blkg_rwstat_read_counter(rwstat, i); 121 } 126 } 122 rcu_read_unlock(); 127 rcu_read_unlock(); 123 } 128 } 124 EXPORT_SYMBOL_GPL(blkg_rwstat_recursive_sum); 129 EXPORT_SYMBOL_GPL(blkg_rwstat_recursive_sum); 125 130
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.