From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3644C433EF for ; Thu, 27 Jan 2022 16:35:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 083576B0072; Thu, 27 Jan 2022 11:35:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 032C46B0073; Thu, 27 Jan 2022 11:35:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E63A96B0080; Thu, 27 Jan 2022 11:35:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id D35AB6B0072 for ; Thu, 27 Jan 2022 11:35:29 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8B38F9006F for ; Thu, 27 Jan 2022 16:35:29 +0000 (UTC) X-FDA: 79076617578.10.844C4AE Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id 78A2A12001C for ; Thu, 27 Jan 2022 16:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=t/MCe4N7Ko6is9DLB7uPGMJ/tYaOgslIsh77bZ85QzU=; b=pzgmDHJPfnOclTpFQU6PM7WHhS SUsJNzZTuhvkvo3z27n5iqlhd975F9rMLJaopHIZKJez/FChf7KM/zQOtSJdyZGTegGNQNsfswHje MEGDkb3uy+WqvrGjvC4GBwnD69G2eLmvBh5Q0uyazG7jt9lq3/oGRsoOQveG4F44of14B4yyHuT+z oSbGYyvlQhTnZuCTg2CjOPpqbAmoMZJwdrkOixGLuvLWM2mnwwbV/IJUvkJj7FwY68dh0Wi6eqafY qQug+QiAKvXjq4f7SH2EQiv4Dh3GTAL1dh4oPKQCSDdyWXuuQNjMp4k6b0UK/bMG0uR7+6v3dFXCn k1SBUSuQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nD7jt-005QJL-E4; Thu, 27 Jan 2022 16:35:14 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id B6891986245; Thu, 27 Jan 2022 17:35:12 +0100 (CET) Date: Thu, 27 Jan 2022 17:35:12 +0100 From: Peter Zijlstra To: Peter Oskolkov 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 Message-ID: <20220127163512.GR20638@worktop.programming.kicks-ass.net> References: <20220113233940.3608440-1-posk@google.com> <20220113233940.3608440-6-posk@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220113233940.3608440-6-posk@google.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 78A2A12001C X-Stat-Signature: dexd4afcdxz3ucmioq43aehjf16c3hxm X-Rspam-User: nil Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=pzgmDHJP; spf=none (imf29.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none X-HE-Tag: 1643301327-275461 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; }