Skip to content

Commit a918709

Browse files
committed
Reset the inherited cpu affinity
Signed-off-by: ningmingxiao <[email protected]>
1 parent 15f855f commit a918709

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/libcrun/scheduler.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,17 @@ int
8282
libcrun_reset_cpu_affinity_mask (pid_t pid, libcrun_error_t *err)
8383
{
8484
int ret;
85+
cpu_set_t mask;
8586

8687
/* Reset the inherited cpu affinity. Old kernels do that automatically, but
8788
new kernels remember the affinity that was set before the cgroup move.
8889
This is undesirable, because it inherits the systemd affinity when the container
8990
should really move to the container space cpus.
90-
91-
The sched_setaffinity call will always return an error (EINVAL or ENODEV);
92-
when used like this. This is expected and part of the backward compatibility.
93-
94-
Ignore ENOSYS as well, as it might be blocked by seccomp.
95-
9691
See: https://issues.redhat.com/browse/OCPBUGS-15102 */
97-
ret = sched_setaffinity (pid, 0, NULL);
98-
if (LIKELY (ret < 0))
99-
{
100-
if (LIKELY (errno == EINVAL || errno == ENODEV || errno == ENOSYS))
101-
return 0;
102-
103-
return crun_make_error (err, errno, "failed to reset affinity");
104-
}
105-
92+
memset (&mask, 0xFF, sizeof (cpu_set_t));
93+
ret = sched_setaffinity (pid, sizeof (mask), &mask);
94+
if (UNLIKELY (ret < 0))
95+
return crun_make_error (err, errno, "sched_setaffinity");
10696
return 0;
10797
}
10898

0 commit comments

Comments
 (0)