blob: 8ccc20464daeca7a92cd3c2c2865c45f30e713e2 [file] [log] [blame]
Vivek Goyal31e4c282009-12-03 12:59:42 -05001#ifndef _BLK_CGROUP_H
2#define _BLK_CGROUP_H
3/*
4 * Common Block IO controller cgroup interface
5 *
6 * Based on ideas and code from CFQ, CFS and BFQ:
7 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
8 *
9 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
10 * Paolo Valente <paolo.valente@unimore.it>
11 *
12 * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com>
13 * Nauman Rafique <nauman@google.com>
14 */
15
16#include <linux/cgroup.h>
17
Ben Blum67523c42010-03-10 15:22:11 -080018#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
19
20#ifndef CONFIG_BLK_CGROUP
21/* When blk-cgroup is a module, its subsys_id isn't a compile-time constant */
22extern struct cgroup_subsys blkio_subsys;
23#define blkio_subsys_id blkio_subsys.subsys_id
24#endif
Jens Axboe2f5ea472009-12-03 21:06:43 +010025
Vivek Goyal31e4c282009-12-03 12:59:42 -050026struct blkio_cgroup {
27 struct cgroup_subsys_state css;
28 unsigned int weight;
29 spinlock_t lock;
30 struct hlist_head blkg_list;
31};
32
33struct blkio_group {
34 /* An rcu protected unique identifier for the group */
35 void *key;
36 struct hlist_node blkcg_node;
Vivek Goyalb1c35762009-12-03 12:59:47 -050037 unsigned short blkcg_id;
Vivek Goyal2868ef72009-12-03 12:59:48 -050038#ifdef CONFIG_DEBUG_BLK_CGROUP
39 /* Store cgroup path */
40 char path[128];
Vivek Goyal22084192009-12-03 12:59:49 -050041 /* How many times this group has been removed from service tree */
42 unsigned long dequeue;
Vivek Goyal2868ef72009-12-03 12:59:48 -050043#endif
Vivek Goyal22084192009-12-03 12:59:49 -050044 /* The device MKDEV(major, minor), this group has been created for */
45 dev_t dev;
46
47 /* total disk time and nr sectors dispatched by this group */
48 unsigned long time;
49 unsigned long sectors;
Vivek Goyal31e4c282009-12-03 12:59:42 -050050};
51
Vivek Goyal3e252062009-12-04 10:36:42 -050052typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
53typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
54 unsigned int weight);
55
56struct blkio_policy_ops {
57 blkio_unlink_group_fn *blkio_unlink_group_fn;
58 blkio_update_group_weight_fn *blkio_update_group_weight_fn;
59};
60
61struct blkio_policy_type {
62 struct list_head list;
63 struct blkio_policy_ops ops;
64};
65
66/* Blkio controller policy registration */
67extern void blkio_policy_register(struct blkio_policy_type *);
68extern void blkio_policy_unregister(struct blkio_policy_type *);
69
Jens Axboe2f5ea472009-12-03 21:06:43 +010070#else
71
72struct blkio_group {
73};
74
Vivek Goyal3e252062009-12-04 10:36:42 -050075struct blkio_policy_type {
76};
77
78static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
79static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
80
Jens Axboe2f5ea472009-12-03 21:06:43 +010081#endif
82
Vivek Goyal31e4c282009-12-03 12:59:42 -050083#define BLKIO_WEIGHT_MIN 100
84#define BLKIO_WEIGHT_MAX 1000
85#define BLKIO_WEIGHT_DEFAULT 500
86
Vivek Goyal2868ef72009-12-03 12:59:48 -050087#ifdef CONFIG_DEBUG_BLK_CGROUP
88static inline char *blkg_path(struct blkio_group *blkg)
89{
90 return blkg->path;
91}
Vivek Goyal22084192009-12-03 12:59:49 -050092void blkiocg_update_blkio_group_dequeue_stats(struct blkio_group *blkg,
93 unsigned long dequeue);
Vivek Goyal2868ef72009-12-03 12:59:48 -050094#else
95static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
Vivek Goyal22084192009-12-03 12:59:49 -050096static inline void blkiocg_update_blkio_group_dequeue_stats(
97 struct blkio_group *blkg, unsigned long dequeue) {}
Vivek Goyal2868ef72009-12-03 12:59:48 -050098#endif
99
Ben Blum67523c42010-03-10 15:22:11 -0800100#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
Vivek Goyal31e4c282009-12-03 12:59:42 -0500101extern struct blkio_cgroup blkio_root_cgroup;
102extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
103extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
Vivek Goyal22084192009-12-03 12:59:49 -0500104 struct blkio_group *blkg, void *key, dev_t dev);
Vivek Goyal31e4c282009-12-03 12:59:42 -0500105extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
106extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
107 void *key);
Vivek Goyal22084192009-12-03 12:59:49 -0500108void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
109 unsigned long time, unsigned long sectors);
Vivek Goyal31e4c282009-12-03 12:59:42 -0500110#else
Jens Axboe2f5ea472009-12-03 21:06:43 +0100111struct cgroup;
Vivek Goyal31e4c282009-12-03 12:59:42 -0500112static inline struct blkio_cgroup *
113cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
114
115static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
Vivek Goyal22084192009-12-03 12:59:49 -0500116 struct blkio_group *blkg, void *key, dev_t dev)
Vivek Goyal31e4c282009-12-03 12:59:42 -0500117{
118}
119
120static inline int
121blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
122
123static inline struct blkio_group *
124blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
Vivek Goyal22084192009-12-03 12:59:49 -0500125static inline void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
126 unsigned long time, unsigned long sectors)
127{
128}
Vivek Goyal31e4c282009-12-03 12:59:42 -0500129#endif
130#endif /* _BLK_CGROUP_H */