@@ -250,10 +250,20 @@ struct layer *lookup_layer(int idx)
250
250
return & layers [idx ];
251
251
}
252
252
253
+ /*
254
+ * Because the layer membership is by the default hierarchy cgroups rather than
255
+ * the CPU controller membership, we can't use ops.cgroup_move(). Let's iterate
256
+ * the tasks manually and set refresh_layer.
257
+ *
258
+ * The iteration isn't synchronized and may fail spuriously. It's not a big
259
+ * practical problem as process migrations are very rare in most modern systems.
260
+ * That said, we eventually want this to be based on CPU controller membership.
261
+ */
253
262
SEC ("tp_btf/cgroup_attach_task" )
254
263
int BPF_PROG (tp_cgroup_attach_task , struct cgroup * cgrp , const char * cgrp_path ,
255
264
struct task_struct * leader , bool threadgroup )
256
265
{
266
+ struct list_head * thread_head ;
257
267
struct task_struct * next ;
258
268
struct task_ctx * tctx ;
259
269
int leader_pid = leader -> pid ;
@@ -265,6 +275,8 @@ int BPF_PROG(tp_cgroup_attach_task, struct cgroup *cgrp, const char *cgrp_path,
265
275
if (!threadgroup )
266
276
return 0 ;
267
277
278
+ thread_head = & leader -> signal -> thread_head ;
279
+
268
280
if (!(next = bpf_task_acquire (leader ))) {
269
281
scx_bpf_error ("failed to acquire leader" );
270
282
return 0 ;
@@ -274,18 +286,18 @@ int BPF_PROG(tp_cgroup_attach_task, struct cgroup *cgrp, const char *cgrp_path,
274
286
struct task_struct * p ;
275
287
int pid ;
276
288
277
- p = container_of (next -> thread_group .next , struct task_struct , thread_group );
289
+ p = container_of (next -> thread_node .next , struct task_struct , thread_node );
278
290
bpf_task_release (next );
279
291
280
- pid = BPF_CORE_READ (p , pid );
281
- if (pid == leader_pid ) {
292
+ if (& p -> thread_node == thread_head ) {
282
293
next = NULL ;
283
294
break ;
284
295
}
285
296
297
+ pid = BPF_CORE_READ (p , pid );
286
298
next = bpf_task_from_pid (pid );
287
299
if (!next ) {
288
- scx_bpf_error ( " thread iteration failed" );
300
+ bpf_printk ( "scx_layered: tp_cgroup_attach_task: thread iteration failed" );
289
301
break ;
290
302
}
291
303
0 commit comments