mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-01 00:58:39 +02:00 
			
		
		
		
	block: move the part_stat* helpers from genhd.h to a new header
These macros are just used by a few files. Move them out of genhd.h, which is included everywhere into a new standalone header. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
		
							parent
							
								
									581e26004a
								
							
						
					
					
						commit
						c6a564ffad
					
				
					 13 changed files with 126 additions and 109 deletions
				
			
		|  | @ -4,6 +4,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <linux/idr.h> | #include <linux/idr.h> | ||||||
| #include <linux/blk-mq.h> | #include <linux/blk-mq.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| #include <xen/xen.h> | #include <xen/xen.h> | ||||||
| #include "blk-mq.h" | #include "blk-mq.h" | ||||||
| #include "blk-mq-sched.h" | #include "blk-mq-sched.h" | ||||||
|  |  | ||||||
|  | @ -33,6 +33,7 @@ | ||||||
| #include <linux/random.h> | #include <linux/random.h> | ||||||
| #include <linux/string.h> | #include <linux/string.h> | ||||||
| #include <linux/scatterlist.h> | #include <linux/scatterlist.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| #include "drbd_int.h" | #include "drbd_int.h" | ||||||
| #include "drbd_protocol.h" | #include "drbd_protocol.h" | ||||||
| #include "drbd_req.h" | #include "drbd_req.h" | ||||||
|  |  | ||||||
|  | @ -22,6 +22,7 @@ | ||||||
| #include <linux/random.h> | #include <linux/random.h> | ||||||
| #include <linux/string.h> | #include <linux/string.h> | ||||||
| #include <linux/scatterlist.h> | #include <linux/scatterlist.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| 
 | 
 | ||||||
| #include "drbd_int.h" | #include "drbd_int.h" | ||||||
| #include "drbd_protocol.h" | #include "drbd_protocol.h" | ||||||
|  |  | ||||||
|  | @ -33,6 +33,7 @@ | ||||||
| #include <linux/sysfs.h> | #include <linux/sysfs.h> | ||||||
| #include <linux/debugfs.h> | #include <linux/debugfs.h> | ||||||
| #include <linux/cpuhotplug.h> | #include <linux/cpuhotplug.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| 
 | 
 | ||||||
| #include "zram_drv.h" | #include "zram_drv.h" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -25,6 +25,7 @@ | ||||||
| #include <linux/wait.h> | #include <linux/wait.h> | ||||||
| #include <linux/pr.h> | #include <linux/pr.h> | ||||||
| #include <linux/refcount.h> | #include <linux/refcount.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| 
 | 
 | ||||||
| #define DM_MSG_PREFIX "core" | #define DM_MSG_PREFIX "core" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -61,6 +61,7 @@ | ||||||
| #include <linux/raid/detect.h> | #include <linux/raid/detect.h> | ||||||
| #include <linux/slab.h> | #include <linux/slab.h> | ||||||
| #include <linux/percpu-refcount.h> | #include <linux/percpu-refcount.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| 
 | 
 | ||||||
| #include <trace/events/block.h> | #include <trace/events/block.h> | ||||||
| #include "md.h" | #include "md.h" | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ | ||||||
| #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||||||
| #include <linux/module.h> | #include <linux/module.h> | ||||||
| #include <linux/rculist.h> | #include <linux/rculist.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| 
 | 
 | ||||||
| #include <generated/utsrelease.h> | #include <generated/utsrelease.h> | ||||||
| #include <asm/unaligned.h> | #include <asm/unaligned.h> | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ | ||||||
| #include <linux/uaccess.h> | #include <linux/uaccess.h> | ||||||
| #include <linux/iversion.h> | #include <linux/iversion.h> | ||||||
| #include <linux/unicode.h> | #include <linux/unicode.h> | ||||||
| 
 | #include <linux/part_stat.h> | ||||||
| #include <linux/kthread.h> | #include <linux/kthread.h> | ||||||
| #include <linux/freezer.h> | #include <linux/freezer.h> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -13,6 +13,7 @@ | ||||||
| #include <linux/seq_file.h> | #include <linux/seq_file.h> | ||||||
| #include <linux/slab.h> | #include <linux/slab.h> | ||||||
| #include <linux/proc_fs.h> | #include <linux/proc_fs.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| 
 | 
 | ||||||
| #include "ext4.h" | #include "ext4.h" | ||||||
| #include "ext4_jbd2.h" | #include "ext4_jbd2.h" | ||||||
|  |  | ||||||
|  | @ -22,6 +22,7 @@ | ||||||
| #include <linux/bio.h> | #include <linux/bio.h> | ||||||
| #include <linux/blkdev.h> | #include <linux/blkdev.h> | ||||||
| #include <linux/quotaops.h> | #include <linux/quotaops.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| #include <crypto/hash.h> | #include <crypto/hash.h> | ||||||
| 
 | 
 | ||||||
| #include <linux/fscrypt.h> | #include <linux/fscrypt.h> | ||||||
|  |  | ||||||
|  | @ -24,6 +24,7 @@ | ||||||
| #include <linux/sysfs.h> | #include <linux/sysfs.h> | ||||||
| #include <linux/quota.h> | #include <linux/quota.h> | ||||||
| #include <linux/unicode.h> | #include <linux/unicode.h> | ||||||
|  | #include <linux/part_stat.h> | ||||||
| 
 | 
 | ||||||
| #include "f2fs.h" | #include "f2fs.h" | ||||||
| #include "node.h" | #include "node.h" | ||||||
|  |  | ||||||
|  | @ -298,114 +298,6 @@ extern void disk_part_iter_init(struct disk_part_iter *piter, | ||||||
| extern struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter); | extern struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter); | ||||||
| extern void disk_part_iter_exit(struct disk_part_iter *piter); | extern void disk_part_iter_exit(struct disk_part_iter *piter); | ||||||
| 
 | 
 | ||||||
| /*
 |  | ||||||
|  * Macros to operate on percpu disk statistics: |  | ||||||
|  * |  | ||||||
|  * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters |  | ||||||
|  * and should be called between disk_stat_lock() and |  | ||||||
|  * disk_stat_unlock(). |  | ||||||
|  * |  | ||||||
|  * part_stat_read() can be called at any time. |  | ||||||
|  * |  | ||||||
|  * part_stat_{add|set_all}() and {init|free}_part_stats are for |  | ||||||
|  * internal use only. |  | ||||||
|  */ |  | ||||||
| #ifdef	CONFIG_SMP |  | ||||||
| #define part_stat_lock()	({ rcu_read_lock(); get_cpu(); }) |  | ||||||
| #define part_stat_unlock()	do { put_cpu(); rcu_read_unlock(); } while (0) |  | ||||||
| 
 |  | ||||||
| #define part_stat_get_cpu(part, field, cpu)					\ |  | ||||||
| 	(per_cpu_ptr((part)->dkstats, (cpu))->field) |  | ||||||
| 
 |  | ||||||
| #define part_stat_get(part, field)					\ |  | ||||||
| 	part_stat_get_cpu(part, field, smp_processor_id()) |  | ||||||
| 
 |  | ||||||
| #define part_stat_read(part, field)					\ |  | ||||||
| ({									\ |  | ||||||
| 	typeof((part)->dkstats->field) res = 0;				\ |  | ||||||
| 	unsigned int _cpu;						\ |  | ||||||
| 	for_each_possible_cpu(_cpu)					\ |  | ||||||
| 		res += per_cpu_ptr((part)->dkstats, _cpu)->field;	\ |  | ||||||
| 	res;								\ |  | ||||||
| }) |  | ||||||
| 
 |  | ||||||
| static inline void part_stat_set_all(struct hd_struct *part, int value) |  | ||||||
| { |  | ||||||
| 	int i; |  | ||||||
| 
 |  | ||||||
| 	for_each_possible_cpu(i) |  | ||||||
| 		memset(per_cpu_ptr(part->dkstats, i), value, |  | ||||||
| 				sizeof(struct disk_stats)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static inline int init_part_stats(struct hd_struct *part) |  | ||||||
| { |  | ||||||
| 	part->dkstats = alloc_percpu(struct disk_stats); |  | ||||||
| 	if (!part->dkstats) |  | ||||||
| 		return 0; |  | ||||||
| 	return 1; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static inline void free_part_stats(struct hd_struct *part) |  | ||||||
| { |  | ||||||
| 	free_percpu(part->dkstats); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #else /* !CONFIG_SMP */ |  | ||||||
| #define part_stat_lock()	({ rcu_read_lock(); 0; }) |  | ||||||
| #define part_stat_unlock()	rcu_read_unlock() |  | ||||||
| 
 |  | ||||||
| #define part_stat_get(part, field)		((part)->dkstats.field) |  | ||||||
| #define part_stat_get_cpu(part, field, cpu)	part_stat_get(part, field) |  | ||||||
| #define part_stat_read(part, field)		part_stat_get(part, field) |  | ||||||
| 
 |  | ||||||
| static inline void part_stat_set_all(struct hd_struct *part, int value) |  | ||||||
| { |  | ||||||
| 	memset(&part->dkstats, value, sizeof(struct disk_stats)); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static inline int init_part_stats(struct hd_struct *part) |  | ||||||
| { |  | ||||||
| 	return 1; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static inline void free_part_stats(struct hd_struct *part) |  | ||||||
| { |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #endif /* CONFIG_SMP */ |  | ||||||
| 
 |  | ||||||
| #define part_stat_read_accum(part, field)				\ |  | ||||||
| 	(part_stat_read(part, field[STAT_READ]) +			\ |  | ||||||
| 	 part_stat_read(part, field[STAT_WRITE]) +			\ |  | ||||||
| 	 part_stat_read(part, field[STAT_DISCARD])) |  | ||||||
| 
 |  | ||||||
| #define __part_stat_add(part, field, addnd)				\ |  | ||||||
| 	(part_stat_get(part, field) += (addnd)) |  | ||||||
| 
 |  | ||||||
| #define part_stat_add(part, field, addnd)	do {			\ |  | ||||||
| 	__part_stat_add((part), field, addnd);				\ |  | ||||||
| 	if ((part)->partno)						\ |  | ||||||
| 		__part_stat_add(&part_to_disk((part))->part0,		\ |  | ||||||
| 				field, addnd);				\ |  | ||||||
| } while (0) |  | ||||||
| 
 |  | ||||||
| #define part_stat_dec(gendiskp, field)					\ |  | ||||||
| 	part_stat_add(gendiskp, field, -1) |  | ||||||
| #define part_stat_inc(gendiskp, field)					\ |  | ||||||
| 	part_stat_add(gendiskp, field, 1) |  | ||||||
| #define part_stat_sub(gendiskp, field, subnd)				\ |  | ||||||
| 	part_stat_add(gendiskp, field, -subnd) |  | ||||||
| 
 |  | ||||||
| #define part_stat_local_dec(gendiskp, field)				\ |  | ||||||
| 	local_dec(&(part_stat_get(gendiskp, field))) |  | ||||||
| #define part_stat_local_inc(gendiskp, field)				\ |  | ||||||
| 	local_inc(&(part_stat_get(gendiskp, field))) |  | ||||||
| #define part_stat_local_read(gendiskp, field)				\ |  | ||||||
| 	local_read(&(part_stat_get(gendiskp, field))) |  | ||||||
| #define part_stat_local_read_cpu(gendiskp, field, cpu)			\ |  | ||||||
| 	local_read(&(part_stat_get_cpu(gendiskp, field, cpu))) |  | ||||||
| 
 |  | ||||||
| /* block/genhd.c */ | /* block/genhd.c */ | ||||||
| extern void device_add_disk(struct device *parent, struct gendisk *disk, | extern void device_add_disk(struct device *parent, struct gendisk *disk, | ||||||
| 			    const struct attribute_group **groups); | 			    const struct attribute_group **groups); | ||||||
|  |  | ||||||
							
								
								
									
										115
									
								
								include/linux/part_stat.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								include/linux/part_stat.h
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,115 @@ | ||||||
|  | /* SPDX-License-Identifier: GPL-2.0 */ | ||||||
|  | #ifndef _LINUX_PART_STAT_H | ||||||
|  | #define _LINUX_PART_STAT_H | ||||||
|  | 
 | ||||||
|  | #include <linux/genhd.h> | ||||||
|  | 
 | ||||||
|  | /*
 | ||||||
|  |  * Macros to operate on percpu disk statistics: | ||||||
|  |  * | ||||||
|  |  * {disk|part|all}_stat_{add|sub|inc|dec}() modify the stat counters | ||||||
|  |  * and should be called between disk_stat_lock() and | ||||||
|  |  * disk_stat_unlock(). | ||||||
|  |  * | ||||||
|  |  * part_stat_read() can be called at any time. | ||||||
|  |  * | ||||||
|  |  * part_stat_{add|set_all}() and {init|free}_part_stats are for | ||||||
|  |  * internal use only. | ||||||
|  |  */ | ||||||
|  | #ifdef	CONFIG_SMP | ||||||
|  | #define part_stat_lock()	({ rcu_read_lock(); get_cpu(); }) | ||||||
|  | #define part_stat_unlock()	do { put_cpu(); rcu_read_unlock(); } while (0) | ||||||
|  | 
 | ||||||
|  | #define part_stat_get_cpu(part, field, cpu)				\ | ||||||
|  | 	(per_cpu_ptr((part)->dkstats, (cpu))->field) | ||||||
|  | 
 | ||||||
|  | #define part_stat_get(part, field)					\ | ||||||
|  | 	part_stat_get_cpu(part, field, smp_processor_id()) | ||||||
|  | 
 | ||||||
|  | #define part_stat_read(part, field)					\ | ||||||
|  | ({									\ | ||||||
|  | 	typeof((part)->dkstats->field) res = 0;				\ | ||||||
|  | 	unsigned int _cpu;						\ | ||||||
|  | 	for_each_possible_cpu(_cpu)					\ | ||||||
|  | 		res += per_cpu_ptr((part)->dkstats, _cpu)->field;	\ | ||||||
|  | 	res;								\ | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | static inline void part_stat_set_all(struct hd_struct *part, int value) | ||||||
|  | { | ||||||
|  | 	int i; | ||||||
|  | 
 | ||||||
|  | 	for_each_possible_cpu(i) | ||||||
|  | 		memset(per_cpu_ptr(part->dkstats, i), value, | ||||||
|  | 				sizeof(struct disk_stats)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static inline int init_part_stats(struct hd_struct *part) | ||||||
|  | { | ||||||
|  | 	part->dkstats = alloc_percpu(struct disk_stats); | ||||||
|  | 	if (!part->dkstats) | ||||||
|  | 		return 0; | ||||||
|  | 	return 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static inline void free_part_stats(struct hd_struct *part) | ||||||
|  | { | ||||||
|  | 	free_percpu(part->dkstats); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #else /* !CONFIG_SMP */ | ||||||
|  | #define part_stat_lock()	({ rcu_read_lock(); 0; }) | ||||||
|  | #define part_stat_unlock()	rcu_read_unlock() | ||||||
|  | 
 | ||||||
|  | #define part_stat_get(part, field)		((part)->dkstats.field) | ||||||
|  | #define part_stat_get_cpu(part, field, cpu)	part_stat_get(part, field) | ||||||
|  | #define part_stat_read(part, field)		part_stat_get(part, field) | ||||||
|  | 
 | ||||||
|  | static inline void part_stat_set_all(struct hd_struct *part, int value) | ||||||
|  | { | ||||||
|  | 	memset(&part->dkstats, value, sizeof(struct disk_stats)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static inline int init_part_stats(struct hd_struct *part) | ||||||
|  | { | ||||||
|  | 	return 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static inline void free_part_stats(struct hd_struct *part) | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif /* CONFIG_SMP */ | ||||||
|  | 
 | ||||||
|  | #define part_stat_read_accum(part, field)				\ | ||||||
|  | 	(part_stat_read(part, field[STAT_READ]) +			\ | ||||||
|  | 	 part_stat_read(part, field[STAT_WRITE]) +			\ | ||||||
|  | 	 part_stat_read(part, field[STAT_DISCARD])) | ||||||
|  | 
 | ||||||
|  | #define __part_stat_add(part, field, addnd)				\ | ||||||
|  | 	(part_stat_get(part, field) += (addnd)) | ||||||
|  | 
 | ||||||
|  | #define part_stat_add(part, field, addnd)	do {			\ | ||||||
|  | 	__part_stat_add((part), field, addnd);				\ | ||||||
|  | 	if ((part)->partno)						\ | ||||||
|  | 		__part_stat_add(&part_to_disk((part))->part0,		\ | ||||||
|  | 				field, addnd);				\ | ||||||
|  | } while (0) | ||||||
|  | 
 | ||||||
|  | #define part_stat_dec(gendiskp, field)					\ | ||||||
|  | 	part_stat_add(gendiskp, field, -1) | ||||||
|  | #define part_stat_inc(gendiskp, field)					\ | ||||||
|  | 	part_stat_add(gendiskp, field, 1) | ||||||
|  | #define part_stat_sub(gendiskp, field, subnd)				\ | ||||||
|  | 	part_stat_add(gendiskp, field, -subnd) | ||||||
|  | 
 | ||||||
|  | #define part_stat_local_dec(gendiskp, field)				\ | ||||||
|  | 	local_dec(&(part_stat_get(gendiskp, field))) | ||||||
|  | #define part_stat_local_inc(gendiskp, field)				\ | ||||||
|  | 	local_inc(&(part_stat_get(gendiskp, field))) | ||||||
|  | #define part_stat_local_read(gendiskp, field)				\ | ||||||
|  | 	local_read(&(part_stat_get(gendiskp, field))) | ||||||
|  | #define part_stat_local_read_cpu(gendiskp, field, cpu)			\ | ||||||
|  | 	local_read(&(part_stat_get_cpu(gendiskp, field, cpu))) | ||||||
|  | 
 | ||||||
|  | #endif /* _LINUX_PART_STAT_H */ | ||||||
		Loading…
	
		Reference in a new issue
	
	 Christoph Hellwig
						Christoph Hellwig