Blame view

include/linux/cpuset.h 5.74 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
  #ifndef _LINUX_CPUSET_H
  #define _LINUX_CPUSET_H
  /*
   *  cpuset interface
   *
   *  Copyright (C) 2003 BULL SA
825a46af5   Paul Jackson   [PATCH] cpuset me...
7
   *  Copyright (C) 2004-2006 Silicon Graphics, Inc.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
11
12
13
   *
   */
  
  #include <linux/sched.h>
  #include <linux/cpumask.h>
  #include <linux/nodemask.h>
a1bc5a4ee   David Rientjes   cpusets: replace ...
14
  #include <linux/mm.h>
664eeddee   Mel Gorman   mm: page_alloc: u...
15
  #include <linux/jump_label.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
  
  #ifdef CONFIG_CPUSETS
664eeddee   Mel Gorman   mm: page_alloc: u...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  extern struct static_key cpusets_enabled_key;
  static inline bool cpusets_enabled(void)
  {
  	return static_key_false(&cpusets_enabled_key);
  }
  
  static inline int nr_cpusets(void)
  {
  	/* jump label reference count + the top-level cpuset */
  	return static_key_count(&cpusets_enabled_key) + 1;
  }
  
  static inline void cpuset_inc(void)
  {
  	static_key_slow_inc(&cpusets_enabled_key);
  }
  
  static inline void cpuset_dec(void)
  {
  	static_key_slow_dec(&cpusets_enabled_key);
  }
202f72d5d   Paul Jackson   [PATCH] cpuset: n...
39

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
  extern int cpuset_init(void);
  extern void cpuset_init_smp(void);
7ddf96b02   Srivatsa S. Bhat   cpusets, hotplug:...
42
  extern void cpuset_update_active_cpus(bool cpu_online);
6af866af3   Li Zefan   cpuset: remove re...
43
  extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
2baab4e90   Peter Zijlstra   sched: Fix select...
44
  extern void cpuset_cpus_allowed_fallback(struct task_struct *p);
909d75a3b   Paul Jackson   [PATCH] cpuset: i...
45
  extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
9276b1bc9   Paul Jackson   [PATCH] memory pa...
46
  #define cpuset_current_mems_allowed (current->mems_allowed)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
  void cpuset_init_current_mems_allowed(void);
19770b326   Mel Gorman   mm: filter based ...
48
  int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
202f72d5d   Paul Jackson   [PATCH] cpuset: n...
49

344736f29   Vladimir Davydov   cpuset: simplify ...
50
  extern int __cpuset_node_allowed(int node, gfp_t gfp_mask);
02a0e53d8   Paul Jackson   [PATCH] cpuset: r...
51

344736f29   Vladimir Davydov   cpuset: simplify ...
52
  static inline int cpuset_node_allowed(int node, gfp_t gfp_mask)
02a0e53d8   Paul Jackson   [PATCH] cpuset: r...
53
  {
344736f29   Vladimir Davydov   cpuset: simplify ...
54
  	return nr_cpusets() <= 1 || __cpuset_node_allowed(node, gfp_mask);
02a0e53d8   Paul Jackson   [PATCH] cpuset: r...
55
  }
344736f29   Vladimir Davydov   cpuset: simplify ...
56
  static inline int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
202f72d5d   Paul Jackson   [PATCH] cpuset: n...
57
  {
344736f29   Vladimir Davydov   cpuset: simplify ...
58
  	return cpuset_node_allowed(zone_to_nid(z), gfp_mask);
202f72d5d   Paul Jackson   [PATCH] cpuset: n...
59
  }
bbe373f2c   David Rientjes   oom: compare cpus...
60
61
  extern int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  					  const struct task_struct *tsk2);
3e0d98b9f   Paul Jackson   [PATCH] cpuset: m...
62
63
64
65
66
67
68
69
  
  #define cpuset_memory_pressure_bump() 				\
  	do {							\
  		if (cpuset_memory_pressure_enabled)		\
  			__cpuset_memory_pressure_bump();	\
  	} while (0)
  extern int cpuset_memory_pressure_enabled;
  extern void __cpuset_memory_pressure_bump(void);
df5f8314c   Eric W. Biederman   proc: seqfile con...
70
71
  extern void cpuset_task_status_allowed(struct seq_file *m,
  					struct task_struct *task);
52de4779f   Zefan Li   cpuset: simplify ...
72
73
  extern int proc_cpuset_show(struct seq_file *m, struct pid_namespace *ns,
  			    struct pid *pid, struct task_struct *tsk);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74

825a46af5   Paul Jackson   [PATCH] cpuset me...
75
  extern int cpuset_mem_spread_node(void);
6adef3ebe   Jack Steiner   cpusets: new roun...
76
  extern int cpuset_slab_spread_node(void);
825a46af5   Paul Jackson   [PATCH] cpuset me...
77
78
79
  
  static inline int cpuset_do_page_mem_spread(void)
  {
2ad654bc5   Zefan Li   cpuset: PF_SPREAD...
80
  	return task_spread_page(current);
825a46af5   Paul Jackson   [PATCH] cpuset me...
81
82
83
84
  }
  
  static inline int cpuset_do_slab_mem_spread(void)
  {
2ad654bc5   Zefan Li   cpuset: PF_SPREAD...
85
  	return task_spread_slab(current);
825a46af5   Paul Jackson   [PATCH] cpuset me...
86
  }
8793d854e   Paul Menage   Task Control Grou...
87
  extern int current_cpuset_is_being_rebound(void);
e761b7725   Max Krasnyansky   cpu hotplug, sche...
88
  extern void rebuild_sched_domains(void);
da39da3a5   David Rientjes   mm, oom: remove t...
89
  extern void cpuset_print_current_mems_allowed(void);
75aa19941   David Rientjes   oom: print trigge...
90

c0ff7453b   Miao Xie   cpuset,mm: fix no...
91
  /*
d26914d11   Mel Gorman   mm: optimize put_...
92
93
94
95
96
   * read_mems_allowed_begin is required when making decisions involving
   * mems_allowed such as during page allocation. mems_allowed can be updated in
   * parallel and depending on the new value an operation can fail potentially
   * causing process failure. A retry loop with read_mems_allowed_begin and
   * read_mems_allowed_retry prevents these artificial failures.
c0ff7453b   Miao Xie   cpuset,mm: fix no...
97
   */
d26914d11   Mel Gorman   mm: optimize put_...
98
  static inline unsigned int read_mems_allowed_begin(void)
c0ff7453b   Miao Xie   cpuset,mm: fix no...
99
  {
46e700abc   Mel Gorman   mm, page_alloc: r...
100
101
  	if (!cpusets_enabled())
  		return 0;
cc9a6c877   Mel Gorman   cpuset: mm: reduc...
102
  	return read_seqcount_begin(&current->mems_allowed_seq);
c0ff7453b   Miao Xie   cpuset,mm: fix no...
103
  }
cc9a6c877   Mel Gorman   cpuset: mm: reduc...
104
  /*
d26914d11   Mel Gorman   mm: optimize put_...
105
106
107
   * If this returns true, the operation that took place after
   * read_mems_allowed_begin may have failed artificially due to a concurrent
   * update of mems_allowed. It is up to the caller to retry the operation if
cc9a6c877   Mel Gorman   cpuset: mm: reduc...
108
109
   * appropriate.
   */
d26914d11   Mel Gorman   mm: optimize put_...
110
  static inline bool read_mems_allowed_retry(unsigned int seq)
c0ff7453b   Miao Xie   cpuset,mm: fix no...
111
  {
46e700abc   Mel Gorman   mm, page_alloc: r...
112
113
  	if (!cpusets_enabled())
  		return false;
d26914d11   Mel Gorman   mm: optimize put_...
114
  	return read_seqcount_retry(&current->mems_allowed_seq, seq);
c0ff7453b   Miao Xie   cpuset,mm: fix no...
115
  }
58568d2a8   Miao Xie   cpuset,mm: update...
116
117
  static inline void set_mems_allowed(nodemask_t nodemask)
  {
db751fe3e   John Stultz   cpuset: Fix poten...
118
  	unsigned long flags;
c0ff7453b   Miao Xie   cpuset,mm: fix no...
119
  	task_lock(current);
db751fe3e   John Stultz   cpuset: Fix poten...
120
  	local_irq_save(flags);
cc9a6c877   Mel Gorman   cpuset: mm: reduc...
121
  	write_seqcount_begin(&current->mems_allowed_seq);
58568d2a8   Miao Xie   cpuset,mm: update...
122
  	current->mems_allowed = nodemask;
cc9a6c877   Mel Gorman   cpuset: mm: reduc...
123
  	write_seqcount_end(&current->mems_allowed_seq);
db751fe3e   John Stultz   cpuset: Fix poten...
124
  	local_irq_restore(flags);
c0ff7453b   Miao Xie   cpuset,mm: fix no...
125
  	task_unlock(current);
58568d2a8   Miao Xie   cpuset,mm: update...
126
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
  #else /* !CONFIG_CPUSETS */
664eeddee   Mel Gorman   mm: page_alloc: u...
128
  static inline bool cpusets_enabled(void) { return false; }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
  static inline int cpuset_init(void) { return 0; }
  static inline void cpuset_init_smp(void) {}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131

7ddf96b02   Srivatsa S. Bhat   cpusets, hotplug:...
132
  static inline void cpuset_update_active_cpus(bool cpu_online)
3a101d054   Tejun Heo   sched: adjust whe...
133
134
135
  {
  	partition_sched_domains(1, NULL, NULL);
  }
6af866af3   Li Zefan   cpuset: remove re...
136
137
  static inline void cpuset_cpus_allowed(struct task_struct *p,
  				       struct cpumask *mask)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
  {
aa85ea5b8   Rusty Russell   cpumask: use new ...
139
  	cpumask_copy(mask, cpu_possible_mask);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
140
  }
2baab4e90   Peter Zijlstra   sched: Fix select...
141
  static inline void cpuset_cpus_allowed_fallback(struct task_struct *p)
9084bb824   Oleg Nesterov   sched: Make selec...
142
  {
9084bb824   Oleg Nesterov   sched: Make selec...
143
  }
909d75a3b   Paul Jackson   [PATCH] cpuset: i...
144
145
146
147
  static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
  {
  	return node_possible_map;
  }
38d7bee9d   Lai Jiangshan   cpuset: use N_MEM...
148
  #define cpuset_current_mems_allowed (node_states[N_MEMORY])
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
149
  static inline void cpuset_init_current_mems_allowed(void) {}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150

19770b326   Mel Gorman   mm: filter based ...
151
  static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
153
154
  {
  	return 1;
  }
344736f29   Vladimir Davydov   cpuset: simplify ...
155
  static inline int cpuset_node_allowed(int node, gfp_t gfp_mask)
02a0e53d8   Paul Jackson   [PATCH] cpuset: r...
156
157
158
  {
  	return 1;
  }
344736f29   Vladimir Davydov   cpuset: simplify ...
159
  static inline int cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
161
162
  {
  	return 1;
  }
bbe373f2c   David Rientjes   oom: compare cpus...
163
164
  static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
  						 const struct task_struct *tsk2)
ef08e3b49   Paul Jackson   [PATCH] cpusets: ...
165
166
167
  {
  	return 1;
  }
3e0d98b9f   Paul Jackson   [PATCH] cpuset: m...
168
  static inline void cpuset_memory_pressure_bump(void) {}
df5f8314c   Eric W. Biederman   proc: seqfile con...
169
170
  static inline void cpuset_task_status_allowed(struct seq_file *m,
  						struct task_struct *task)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172
  }
825a46af5   Paul Jackson   [PATCH] cpuset me...
173
174
175
176
  static inline int cpuset_mem_spread_node(void)
  {
  	return 0;
  }
6adef3ebe   Jack Steiner   cpusets: new roun...
177
178
179
180
  static inline int cpuset_slab_spread_node(void)
  {
  	return 0;
  }
825a46af5   Paul Jackson   [PATCH] cpuset me...
181
182
183
184
185
186
187
188
189
  static inline int cpuset_do_page_mem_spread(void)
  {
  	return 0;
  }
  
  static inline int cpuset_do_slab_mem_spread(void)
  {
  	return 0;
  }
8793d854e   Paul Menage   Task Control Grou...
190
191
192
193
  static inline int current_cpuset_is_being_rebound(void)
  {
  	return 0;
  }
e761b7725   Max Krasnyansky   cpu hotplug, sche...
194
195
  static inline void rebuild_sched_domains(void)
  {
dfb512ec4   Max Krasnyansky   sched: arch_reini...
196
  	partition_sched_domains(1, NULL, NULL);
e761b7725   Max Krasnyansky   cpu hotplug, sche...
197
  }
da39da3a5   David Rientjes   mm, oom: remove t...
198
  static inline void cpuset_print_current_mems_allowed(void)
75aa19941   David Rientjes   oom: print trigge...
199
200
  {
  }
58568d2a8   Miao Xie   cpuset,mm: update...
201
202
203
  static inline void set_mems_allowed(nodemask_t nodemask)
  {
  }
d26914d11   Mel Gorman   mm: optimize put_...
204
  static inline unsigned int read_mems_allowed_begin(void)
c0ff7453b   Miao Xie   cpuset,mm: fix no...
205
  {
cc9a6c877   Mel Gorman   cpuset: mm: reduc...
206
  	return 0;
c0ff7453b   Miao Xie   cpuset,mm: fix no...
207
  }
d26914d11   Mel Gorman   mm: optimize put_...
208
  static inline bool read_mems_allowed_retry(unsigned int seq)
c0ff7453b   Miao Xie   cpuset,mm: fix no...
209
  {
d26914d11   Mel Gorman   mm: optimize put_...
210
  	return false;
c0ff7453b   Miao Xie   cpuset,mm: fix no...
211
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
212
213
214
  #endif /* !CONFIG_CPUSETS */
  
  #endif /* _LINUX_CPUSET_H */