From: chris hyser <chris.hyser@oracle.com>
To: "Joel Fernandes (Google)" <joel@joelfernandes.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 -tip 17/26] sched: Split the cookie and setup per-task cookie on fork
Date: Mon, 9 Nov 2020 18:23:13 -0500 [thread overview]
Message-ID: <6e864ca1-d02b-dc56-7ec2-6224eeb0b32d@oracle.com> (raw)
In-Reply-To: <4ff7f030-b797-6711-fb6a-fe39bb02075a@oracle.com>
> On 10/19/20 9:43 PM, Joel Fernandes (Google) wrote:
>> In order to prevent interference and clearly support both per-task and CGroup
>> APIs, split the cookie into 2 and allow it to be set from either per-task, or
>> CGroup API. The final cookie is the combined value of both and is computed when
>> the stop-machine executes during a change of cookie.
>>
>> Also, for the per-task cookie, it will get weird if we use pointers of any
>> emphemeral objects. For this reason, introduce a refcounted object who's sole
>> purpose is to assign unique cookie value by way of the object's pointer.
>>
>> While at it, refactor the CGroup code a bit. Future patches will introduce more
>> APIs and support.
>>
>> Tested-by: Julien Desfossez <jdesfossez@digitalocean.com>
>> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
>> ---
>> include/linux/sched.h | 2 +
>> kernel/sched/core.c | 241 ++++++++++++++++++++++++++++++++++++++++--
>> kernel/sched/debug.c | 4 +
>> 3 files changed, 236 insertions(+), 11 deletions(-)
>>
>> diff --git a/include/linux/sched.h b/include/linux/sched.h
>> index fe6f225bfbf9..c6034c00846a 100644
>> --- a/include/linux/sched.h
>> +++ b/include/linux/sched.h
>> @@ -688,6 +688,8 @@ struct task_struct {
>> #ifdef CONFIG_SCHED_CORE
>> struct rb_node core_node;
>> unsigned long core_cookie;
>> + unsigned long core_task_cookie;
>> + unsigned long core_group_cookie;
>> unsigned int core_occupation;
>> #endif
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index bab4ea2f5cd8..30a9e4cb5ce1 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -346,11 +346,14 @@ void sched_core_put(void)
>> mutex_unlock(&sched_core_mutex);
>> }
>> +static int sched_core_share_tasks(struct task_struct *t1, struct task_struct *t2);
>> +
>> #else /* !CONFIG_SCHED_CORE */
>> static inline void sched_core_enqueue(struct rq *rq, struct task_struct *p) { }
>> static inline void sched_core_dequeue(struct rq *rq, struct task_struct *p) { }
>> static bool sched_core_enqueued(struct task_struct *task) { return false; }
>> +static int sched_core_share_tasks(struct task_struct *t1, struct task_struct *t2) { }
>> #endif /* CONFIG_SCHED_CORE */
>> @@ -3583,6 +3586,20 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
>> #endif
>> #ifdef CONFIG_SCHED_CORE
>> RB_CLEAR_NODE(&p->core_node);
>> +
>> + /*
>> + * Tag child via per-task cookie only if parent is tagged via per-task
>> + * cookie. This is independent of, but can be additive to the CGroup tagging.
>> + */
>> + if (current->core_task_cookie) {
>> +
>> + /* If it is not CLONE_THREAD fork, assign a unique per-task tag. */
>> + if (!(clone_flags & CLONE_THREAD)) {
>> + return sched_core_share_tasks(p, p);
>> + }
>> + /* Otherwise share the parent's per-task tag. */
>> + return sched_core_share_tasks(p, current);
>> + }
>> #endif
>> return 0;
>> }
sched_core_share_tasks() looks at the value of the new tasks core_task_cookie which is non-zero on a
process or thread clone and causes underflow for both the enable flag itself and for cookie ref counts.
So just zero it in __sched_fork().
-chris
PATCH] sched: zero out the core scheduling cookie on clone
From: chris hyser <chris.hyser@oracle.com>
As the cookie is reference counted, even if inherited, zero this and allow
explicit sharing.
Signed-off-by: Chris Hyser <chris.hyser@oracle.com>
---
kernel/sched/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fd3cc03..2af0ea6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3378,6 +3378,9 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
p->capture_control = NULL;
#endif
init_numa_balancing(clone_flags, p);
+#ifdef CONFIG_SCHED_CORE
+ p->core_task_cookie = 0;
+#endif
#ifdef CONFIG_SMP
p->wake_entry.u_flags = CSD_TYPE_TTWU;
#endif
--
1.8.3.1
next parent reply other threads:[~2020-11-09 23:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4ff7f030-b797-6711-fb6a-fe39bb02075a@oracle.com>
2020-11-09 23:23 ` chris hyser [this message]
2020-11-10 14:15 ` Joel Fernandes
2020-11-17 0:45 ` Joel Fernandes
2020-10-20 1:43 [PATCH v8 -tip 00/26] Core scheduling Joel Fernandes (Google)
2020-10-20 1:43 ` [PATCH v8 -tip 17/26] sched: Split the cookie and setup per-task cookie on fork Joel Fernandes (Google)
2020-11-04 22:30 ` chris hyser
2020-11-05 14:49 ` Joel Fernandes
2020-11-09 23:30 ` chris hyser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6e864ca1-d02b-dc56-7ec2-6224eeb0b32d@oracle.com \
--to=chris.hyser@oracle.com \
--cc=joel@joelfernandes.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®