linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Peter Oskolkov <posk@google.com>
Cc: mingo@redhat.com, tglx@linutronix.de, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, linux-api@vger.kernel.org, x86@kernel.org,
	pjt@google.com, avagin@google.com, jannh@google.com,
	tdelisle@uwaterloo.ca, posk@posk.io
Subject: Re: [RFC PATCH v2 5/5] sched: UMCG: allow to sys_umcg_kick UMCG servers
Date: Thu, 27 Jan 2022 17:35:12 +0100	[thread overview]
Message-ID: <20220127163512.GR20638@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <20220113233940.3608440-6-posk@google.com>

On Thu, Jan 13, 2022 at 03:39:40PM -0800, Peter Oskolkov wrote:
> ---
>  include/uapi/linux/umcg.h | 10 ++++++++++
>  kernel/sched/umcg.c       |  7 +++++--
>  2 files changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/include/uapi/linux/umcg.h b/include/uapi/linux/umcg.h
> index 93fccb44283b..a29e5e91a251 100644
> --- a/include/uapi/linux/umcg.h
> +++ b/include/uapi/linux/umcg.h
> @@ -148,4 +148,14 @@ enum umcg_ctl_flag {
>  	UMCG_CTL_WORKER		= 0x10000,
>  };
>  
> +/**
> + * enum umcg_kick_flag - flags to pass to sys_umcg_kick
> + * @UMCG_KICK_RESCHED: reschedule the task; used for worker preemption
> + * @UMCG_KICK_TTWU: wake the task; used to wake servers
> + */
> +enum umcg_kick_flag {
> +	UMCG_KICK_RESCHED	= 0x001,
> +	UMCG_KICK_TTWU		= 0x002,
> +};
> +
>  #endif /* _UAPI_LINUX_UMCG_H */
> diff --git a/kernel/sched/umcg.c b/kernel/sched/umcg.c
> index b85dec6b82e4..e33ec9eddc3e 100644
> --- a/kernel/sched/umcg.c
> +++ b/kernel/sched/umcg.c
> @@ -669,12 +669,15 @@ SYSCALL_DEFINE2(umcg_kick, u32, flags, pid_t, tid)
>  	if (!task)
>  		return -ESRCH;
>  
> -	if (flags)
> +	if (flags != UMCG_KICK_RESCHED && flags != UMCG_KICK_TTWU)
>  		return -EINVAL;
>  
>  #ifdef CONFIG_SMP
> -	smp_send_reschedule(task_cpu(task));
> +	if (flags == UMCG_KICK_RESCHED)
> +		smp_send_reschedule(task_cpu(task));
>  #endif
> +	if (flags == UMCG_KICK_TTWU)
> +		try_to_wake_up(task, TASK_NORMAL, 0);
>  
>  	return 0;
>  }

I'm thinking the simpler thing is this..
(also note the task ref leak fixed)

--- a/kernel/sched/umcg.c
+++ b/kernel/sched/umcg.c
@@ -719,16 +719,22 @@ void umcg_notify_resume(struct pt_regs *
  */
 SYSCALL_DEFINE2(umcg_kick, u32, flags, pid_t, tid)
 {
-	struct task_struct *task = umcg_get_task(tid);
-	if (!task)
-		return -ESRCH;
+	struct task_struct *task;
 
 	if (flags)
 		return -EINVAL;
+       
+	task = umcg_get_task(tid);
+	if (!task)
+		return -ESRCH;
 
+	if (!try_to_wake_up(task, TASK_NORMAL, WF_CURRENT_CPU)) {
 #ifdef CONFIG_SMP
-	smp_send_reschedule(task_cpu(task));
+		smp_send_reschedule(task_cpu(task));
 #endif
+	}
+
+	put_task_struct(task);
 
 	return 0;
 }

      reply	other threads:[~2022-01-27 16:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 23:39 [RFC PATCH v2 0/5] User Managed Concurrency Groups Peter Oskolkov
2022-01-13 23:39 ` [RFC PATCH v2 1/5] sched/umcg: add WF_CURRENT_CPU and externise ttwu Peter Oskolkov
2022-01-13 23:39 ` [RFC PATCH v2 2/5] x86/uaccess: Implement unsafe_try_cmpxchg_user() Peter Oskolkov
2022-01-13 23:39 ` [RFC PATCH v2 3/5] sched: User Mode Concurency Groups Peter Oskolkov
2022-01-13 23:39 ` [RFC PATCH v2 4/5] sched: UMCG: add a blocked worker list Peter Oskolkov
2022-01-17  9:19   ` Peter Zijlstra
2022-01-18 17:16     ` Peter Oskolkov
2022-01-27 15:37   ` Peter Zijlstra
2022-01-27 17:20     ` Peter Oskolkov
2022-01-13 23:39 ` [RFC PATCH v2 5/5] sched: UMCG: allow to sys_umcg_kick UMCG servers Peter Oskolkov
2022-01-27 16:35   ` Peter Zijlstra [this message]

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=20220127163512.GR20638@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=avagin@google.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jannh@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=pjt@google.com \
    --cc=posk@google.com \
    --cc=posk@posk.io \
    --cc=rostedt@goodmis.org \
    --cc=tdelisle@uwaterloo.ca \
    --cc=tglx@linutronix.de \
    --cc=vincent.guittot@linaro.org \
    --cc=x86@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;
as well as URLs for NNTP newsgroup(s).