Merge pull request #4010 from brauner/2021-10-23.fixes

conf: handle kernels without or not using SMT
This commit is contained in:
Stéphane Graber 2021-10-24 01:41:36 -04:00 committed by GitHub
commit 16210a56b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 14 deletions

View File

@ -409,8 +409,8 @@ static int get_attach_context(struct attach_context *ctx,
SYSERROR("Failed to retrieve namespace flags");
ctx->ns_clone_flags = ret;
ctx->core_sched_cookie = core_scheduling_cookie_get(ctx->init_pid);
if (!core_scheduling_cookie_valid(ctx->core_sched_cookie))
ret = core_scheduling_cookie_get(ctx->init_pid, &ctx->core_sched_cookie);
if (ret || !core_scheduling_cookie_valid(ctx->core_sched_cookie))
INFO("Container does not run in a separate core scheduling domain");
else
INFO("Container runs in separate core scheduling domain %llu",
@ -1155,9 +1155,9 @@ __noreturn static void do_attach(struct attach_payload *ap)
goto on_error;
}
core_sched_cookie = core_scheduling_cookie_get(getpid());
if (!core_scheduling_cookie_valid(core_sched_cookie) &&
ctx->core_sched_cookie != core_sched_cookie) {
ret = core_scheduling_cookie_get(getpid(), &core_sched_cookie);
if (ret || !core_scheduling_cookie_valid(core_sched_cookie) ||
(ctx->core_sched_cookie != core_sched_cookie)) {
SYSERROR("Invalid core scheduling domain cookie %llu != %llu",
(llu)core_sched_cookie,
(llu)ctx->core_sched_cookie);

View File

@ -1566,14 +1566,19 @@ static int core_scheduling(struct lxc_handler *handler)
ret = core_scheduling_cookie_create_threadgroup(handler->pid);
if (ret < 0) {
if (ret == -ENODEV) {
INFO("The kernel doesn't support or doesn't use simultaneous multithreading (SMT)");
conf->sched_core = false;
return 0;
}
if (ret == -EINVAL)
return syserror("The kernel does not support core scheduling");
return syserror("Failed to create new core scheduling domain");
}
conf->sched_core_cookie = core_scheduling_cookie_get(handler->pid);
if (!core_scheduling_cookie_valid(conf->sched_core_cookie))
ret = core_scheduling_cookie_get(handler->pid, &conf->sched_core_cookie);
if (ret || !core_scheduling_cookie_valid(conf->sched_core_cookie))
return syserror("Failed to retrieve core scheduling domain cookie");
TRACE("Created new core scheduling domain with cookie %llu",

View File

@ -367,17 +367,21 @@ static inline bool core_scheduling_cookie_valid(__u64 cookie)
return (cookie > 0) && (cookie != INVALID_SCHED_CORE_COOKIE);
}
static inline __u64 core_scheduling_cookie_get(pid_t pid)
static inline int core_scheduling_cookie_get(pid_t pid, __u64 *cookie)
{
__u64 cookie;
int ret;
ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid,
PR_SCHED_CORE_SCOPE_THREAD, (unsigned long)&cookie);
if (ret)
return INVALID_SCHED_CORE_COOKIE;
if (!cookie)
return ret_errno(EINVAL);
return cookie;
ret = prctl(PR_SCHED_CORE, PR_SCHED_CORE_GET, pid,
PR_SCHED_CORE_SCOPE_THREAD, (unsigned long)cookie);
if (ret) {
*cookie = INVALID_SCHED_CORE_COOKIE;
return -errno;
}
return 0;
}
static inline int core_scheduling_cookie_create_threadgroup(pid_t pid)