| .. | .. |
|---|
| 6 | 6 | |
|---|
| 7 | 7 | #include "cgroup-internal.h" |
|---|
| 8 | 8 | |
|---|
| 9 | +#include <trace/events/cgroup.h> |
|---|
| 10 | + |
|---|
| 9 | 11 | /* |
|---|
| 10 | 12 | * Propagate the cgroup frozen state upwards by the cgroup tree. |
|---|
| 11 | 13 | */ |
|---|
| .. | .. |
|---|
| 28 | 30 | cgrp->nr_descendants) { |
|---|
| 29 | 31 | set_bit(CGRP_FROZEN, &cgrp->flags); |
|---|
| 30 | 32 | cgroup_file_notify(&cgrp->events_file); |
|---|
| 33 | + TRACE_CGROUP_PATH(notify_frozen, cgrp, 1); |
|---|
| 31 | 34 | desc++; |
|---|
| 32 | 35 | } |
|---|
| 33 | 36 | } else { |
|---|
| .. | .. |
|---|
| 35 | 38 | if (test_bit(CGRP_FROZEN, &cgrp->flags)) { |
|---|
| 36 | 39 | clear_bit(CGRP_FROZEN, &cgrp->flags); |
|---|
| 37 | 40 | cgroup_file_notify(&cgrp->events_file); |
|---|
| 41 | + TRACE_CGROUP_PATH(notify_frozen, cgrp, 0); |
|---|
| 38 | 42 | desc++; |
|---|
| 39 | 43 | } |
|---|
| 40 | 44 | } |
|---|
| .. | .. |
|---|
| 73 | 77 | clear_bit(CGRP_FROZEN, &cgrp->flags); |
|---|
| 74 | 78 | } |
|---|
| 75 | 79 | cgroup_file_notify(&cgrp->events_file); |
|---|
| 80 | + TRACE_CGROUP_PATH(notify_frozen, cgrp, frozen); |
|---|
| 76 | 81 | |
|---|
| 77 | 82 | /* Update the state of ancestor cgroups. */ |
|---|
| 78 | 83 | cgroup_propagate_frozen(cgrp, frozen); |
|---|
| .. | .. |
|---|
| 134 | 139 | cgroup_update_frozen(cgrp); |
|---|
| 135 | 140 | WARN_ON_ONCE(!current->frozen); |
|---|
| 136 | 141 | current->frozen = false; |
|---|
| 142 | + } else if (!(current->jobctl & JOBCTL_TRAP_FREEZE)) { |
|---|
| 143 | + spin_lock(¤t->sighand->siglock); |
|---|
| 144 | + current->jobctl |= JOBCTL_TRAP_FREEZE; |
|---|
| 145 | + set_thread_flag(TIF_SIGPENDING); |
|---|
| 146 | + spin_unlock(¤t->sighand->siglock); |
|---|
| 137 | 147 | } |
|---|
| 138 | 148 | spin_unlock_irq(&css_set_lock); |
|---|
| 139 | | - |
|---|
| 140 | | - if (unlikely(current->frozen)) { |
|---|
| 141 | | - /* |
|---|
| 142 | | - * If the task remained in the frozen state, |
|---|
| 143 | | - * make sure it won't reach userspace without |
|---|
| 144 | | - * entering the signal handling loop. |
|---|
| 145 | | - */ |
|---|
| 146 | | - spin_lock_irq(¤t->sighand->siglock); |
|---|
| 147 | | - recalc_sigpending(); |
|---|
| 148 | | - spin_unlock_irq(¤t->sighand->siglock); |
|---|
| 149 | | - } |
|---|
| 150 | 149 | } |
|---|
| 151 | 150 | |
|---|
| 152 | 151 | /* |
|---|
| .. | .. |
|---|
| 189 | 188 | clear_bit(CGRP_FREEZE, &cgrp->flags); |
|---|
| 190 | 189 | spin_unlock_irq(&css_set_lock); |
|---|
| 191 | 190 | |
|---|
| 191 | + if (freeze) |
|---|
| 192 | + TRACE_CGROUP_PATH(freeze, cgrp); |
|---|
| 193 | + else |
|---|
| 194 | + TRACE_CGROUP_PATH(unfreeze, cgrp); |
|---|
| 195 | + |
|---|
| 192 | 196 | css_task_iter_start(&cgrp->self, 0, &it); |
|---|
| 193 | 197 | while ((task = css_task_iter_next(&it))) { |
|---|
| 194 | 198 | /* |
|---|
| .. | .. |
|---|
| 227 | 231 | return; |
|---|
| 228 | 232 | |
|---|
| 229 | 233 | /* |
|---|
| 234 | + * It's not necessary to do changes if both of the src and dst cgroups |
|---|
| 235 | + * are not freezing and task is not frozen. |
|---|
| 236 | + */ |
|---|
| 237 | + if (!test_bit(CGRP_FREEZE, &src->flags) && |
|---|
| 238 | + !test_bit(CGRP_FREEZE, &dst->flags) && |
|---|
| 239 | + !task->frozen) |
|---|
| 240 | + return; |
|---|
| 241 | + |
|---|
| 242 | + /* |
|---|
| 230 | 243 | * Adjust counters of freezing and frozen tasks. |
|---|
| 231 | 244 | * Note, that if the task is frozen, but the destination cgroup is not |
|---|
| 232 | 245 | * frozen, we bump both counters to keep them balanced. |
|---|
| .. | .. |
|---|
| 242 | 255 | * Force the task to the desired state. |
|---|
| 243 | 256 | */ |
|---|
| 244 | 257 | cgroup_freeze_task(task, test_bit(CGRP_FREEZE, &dst->flags)); |
|---|
| 245 | | -} |
|---|
| 246 | | - |
|---|
| 247 | | -void cgroup_freezer_frozen_exit(struct task_struct *task) |
|---|
| 248 | | -{ |
|---|
| 249 | | - struct cgroup *cgrp = task_dfl_cgroup(task); |
|---|
| 250 | | - |
|---|
| 251 | | - lockdep_assert_held(&css_set_lock); |
|---|
| 252 | | - |
|---|
| 253 | | - cgroup_dec_frozen_cnt(cgrp); |
|---|
| 254 | | - cgroup_update_frozen(cgrp); |
|---|
| 255 | 258 | } |
|---|
| 256 | 259 | |
|---|
| 257 | 260 | void cgroup_freeze(struct cgroup *cgrp, bool freeze) |
|---|
| .. | .. |
|---|
| 312 | 315 | * In both cases it's better to notify a user, that there is |
|---|
| 313 | 316 | * nothing to wait for. |
|---|
| 314 | 317 | */ |
|---|
| 315 | | - if (!applied) |
|---|
| 318 | + if (!applied) { |
|---|
| 319 | + TRACE_CGROUP_PATH(notify_frozen, cgrp, |
|---|
| 320 | + test_bit(CGRP_FROZEN, &cgrp->flags)); |
|---|
| 316 | 321 | cgroup_file_notify(&cgrp->events_file); |
|---|
| 322 | + } |
|---|
| 317 | 323 | } |
|---|