Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp267229pxu; Tue, 1 Dec 2020 10:42:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeBPJ4qldCh7ffXVPs/w5OSh4cRj9sKfOijxkbvS+NiBEMJTRE4RJES0AbcIuAPHD3PpaM X-Received: by 2002:a17:906:b08b:: with SMTP id x11mr4496826ejy.302.1606848134118; Tue, 01 Dec 2020 10:42:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606848134; cv=none; d=google.com; s=arc-20160816; b=x8G4m7M8Mg8pCBJ1fMZ4CKF8j8Nl0ZRFgYpTtCX/JbGaFUXQCwIwW0jYXZysHSFD/W llEdiH0Baq3se7gpgHWrAOfTK8mmn5ecTA1qLnoLqbm1aJBV7+PN122rfU3ra4ZSx1hE QIaYg3iQUVKZRYaxF7rxMmT3sHJkJpj+xsKb332SzEPSxigBjDWCFLiCHTgnoovTtl4w OydWCIZpprKHaSPEEaU8bdgP5Eg/1SFK55Ojyiw37V0ZTjNmEdPuke/lm32MmNrBzKt5 DlmlMz0IhixKSSJYhZmiiizaxkP1CF7+3CyjssZbP+m/iT2gPGSl2XhYSF0mMGvypKc9 gJDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=spbeJrYokZ4Y9gd+VUqvGSeszDzVDW8TLup0VduoFa4=; b=Vc1fnDW94NrNUUKchBCoUJvBGpeIYu3ZkgAFXsVSvK5v4mZuoHkusd2dTA80tBjd/+ l73AWPh80mYWnoCM8xKOg7DnwYyH8Kv8Gfodx39hioqs0qwXa8LcMcvWVjUZ25PH8Z2/ CWZHvLsO0lL9mQjTndzHUv7Y0nYYuqK3J/5Mxj6zBnrH0eFPqE7F/+Lx7rZF0yj18Rhs bWcO1VfMcRzA5VqAxtxowLwnbW3e14DvwP7Uiphkwzha2q1kuIhFCVip1/4fQzchMeOP kfDUq8nzX13AqTj9GS2wlRzk+j9Ye4xZalgaFZx9PruGnWjQVp8N3zYFfHXri5qJBM9l XuAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=wG+rshCl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si389798edd.383.2020.12.01.10.41.50; Tue, 01 Dec 2020 10:42:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=wG+rshCl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392304AbgLASjQ (ORCPT + 99 others); Tue, 1 Dec 2020 13:39:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388802AbgLASjP (ORCPT ); Tue, 1 Dec 2020 13:39:15 -0500 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D064C0613CF for ; Tue, 1 Dec 2020 10:38:35 -0800 (PST) Received: by mail-qv1-xf35.google.com with SMTP id n9so1326822qvp.5 for ; Tue, 01 Dec 2020 10:38:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=spbeJrYokZ4Y9gd+VUqvGSeszDzVDW8TLup0VduoFa4=; b=wG+rshCludoC3+pPQIORQBUsVYLwBiM92Y9aSc80oBzfU6xLHThKui6WG29QRZeLpy 6tpTg+wdqPt8fTAosTT1Gyyj1eYP77PeKLDnok2qsjatn2wMx4KbBsX5Qincrj12H6Eb EerjombU1XJ5VHX9TP2pYSs/GepdTOAwCg1G8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=spbeJrYokZ4Y9gd+VUqvGSeszDzVDW8TLup0VduoFa4=; b=YkUK3yoexji9DxZhl2TZ44mLOy//TB7PAUBb1Ye2fNPz2TE9STjA+POLdJu3k0Vlkr +tSlvBnJF4+x+93MQ5zq1EDTKP8dKwYNJWCIqkQbPifOHWv8TvB4I7b6J+CrbW8ds7vU Uw1tfYhs75+n0Vrr//Ewa9mMjv2fNanZXmUl55l/tfk2YXh5RHW8mlD9IK0UJb2InwS+ B3tjnKriNbe0zM4z+YfOoA1zpMnCb/eCzUA4LeAJwze4teqru4s8rLUBUiX0+XU2/Hk/ IqT0ylbeDQYFEHP9XBRgVKwRvAmN2y9v92/AmCYtNtBX5sjphvxE0i9Zs/fRgHkE+Xs0 euBg== X-Gm-Message-State: AOAM532umHvXxNa4L6t/z9ucwXoTw8UJvF9ibwCca3cUtpval3TJI/Oc GHjrZ+NTN7wkD2ms0PQTDOt/pg== X-Received: by 2002:a05:6214:20a2:: with SMTP id 2mr4495835qvd.27.1606847902210; Tue, 01 Dec 2020 10:38:22 -0800 (PST) Received: from localhost ([2620:15c:6:411:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id 8sm394322qkd.131.2020.12.01.10.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 10:38:21 -0800 (PST) Date: Tue, 1 Dec 2020 13:38:21 -0500 From: Joel Fernandes To: Peter Zijlstra Cc: Nishanth Aravamudan , Julien Desfossez , Tim Chen , Vineeth Pillai , Aaron Lu , Aubrey Li , tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, torvalds@linux-foundation.org, fweisbec@gmail.com, keescook@chromium.org, kerrnel@google.com, Phil Auld , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini , vineeth@bitbyteword.org, Chen Yu , Christian Brauner , Agata Gruza , Antonio Gomez Iglesias , graf@amazon.com, konrad.wilk@oracle.com, dfaggioli@suse.com, pjt@google.com, rostedt@goodmis.org, derkling@google.com, benbjiang@tencent.com, Alexandre Chartre , James.Bottomley@hansenpartnership.com, OWeisse@umich.edu, Dhaval Giani , Junaid Shahid , jsbarnes@google.com, chris.hyser@oracle.com, Ben Segall , Josh Don , Hao Luo , Tom Lendacky , Aubrey Li , "Paul E. McKenney" , Tim Chen Subject: Re: [PATCH -tip 22/32] sched: Split the cookie and setup per-task cookie on fork Message-ID: <20201201183821.GA211031@google.com> References: <20201117232003.3580179-1-joel@joelfernandes.org> <20201117232003.3580179-23-joel@joelfernandes.org> <20201125125447.GV2414@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201125125447.GV2414@hirez.programming.kicks-ass.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 25, 2020 at 01:54:47PM +0100, Peter Zijlstra wrote: > On Tue, Nov 17, 2020 at 06:19:52PM -0500, Joel Fernandes (Google) wrote: > > +/* Per-task interface */ > > +static unsigned long sched_core_alloc_task_cookie(void) > > +{ > > + struct sched_core_cookie *ptr = > > + kmalloc(sizeof(struct sched_core_cookie), GFP_KERNEL); > > + > > + if (!ptr) > > + return 0; > > + refcount_set(&ptr->refcnt, 1); > > + > > + /* > > + * NOTE: sched_core_put() is not done by put_task_cookie(). Instead, it > > + * is done after the stopper runs. > > + */ > > + sched_core_get(); > > + return (unsigned long)ptr; > > +} > > + > > +static bool sched_core_get_task_cookie(unsigned long cookie) > > +{ > > + struct sched_core_cookie *ptr = (struct sched_core_cookie *)cookie; > > + > > + /* > > + * NOTE: sched_core_put() is not done by put_task_cookie(). Instead, it > > + * is done after the stopper runs. > > + */ > > + sched_core_get(); > > + return refcount_inc_not_zero(&ptr->refcnt); > > +} > > + > > +static void sched_core_put_task_cookie(unsigned long cookie) > > +{ > > + struct sched_core_cookie *ptr = (struct sched_core_cookie *)cookie; > > + > > + if (refcount_dec_and_test(&ptr->refcnt)) > > + kfree(ptr); > > +} > > > + /* > > + * NOTE: sched_core_get() is done by sched_core_alloc_task_cookie() or > > + * sched_core_put_task_cookie(). However, sched_core_put() is done > > + * by this function *after* the stopper removes the tasks from the > > + * core queue, and not before. This is just to play it safe. > > + */ > > So for no reason what so ever you've made the code more difficult? You're right, I could just do sched_core_get() in the caller. I changed it as in the diff below: ---8<----------------------- diff --git a/kernel/sched/coretag.c b/kernel/sched/coretag.c index 800c0f8bacfc..75e2edb53a48 100644 --- a/kernel/sched/coretag.c +++ b/kernel/sched/coretag.c @@ -274,6 +274,7 @@ void sched_core_change_group(struct task_struct *p, struct task_group *new_tg) /* Per-task interface: Used by fork(2) and prctl(2). */ static void sched_core_put_cookie_work(struct work_struct *ws); +/* Caller has to call sched_core_get() if non-zero value is returned. */ static unsigned long sched_core_alloc_task_cookie(void) { struct sched_core_task_cookie *ck = @@ -284,11 +285,6 @@ static unsigned long sched_core_alloc_task_cookie(void) refcount_set(&ck->refcnt, 1); INIT_WORK(&ck->work, sched_core_put_cookie_work); - /* - * NOTE: sched_core_put() is not done by put_task_cookie(). Instead, it - * is done after the stopper runs. - */ - sched_core_get(); return (unsigned long)ck; } @@ -354,12 +350,6 @@ int sched_core_share_tasks(struct task_struct *t1, struct task_struct *t2) mutex_lock(&sched_core_tasks_mutex); - /* - * NOTE: sched_core_get() is done by sched_core_alloc_task_cookie() or - * sched_core_put_task_cookie(). However, sched_core_put() is done - * by this function *after* the stopper removes the tasks from the - * core queue, and not before. This is just to play it safe. - */ if (!t2) { if (t1->core_task_cookie) { sched_core_put_task_cookie(t1->core_task_cookie); @@ -370,7 +360,9 @@ int sched_core_share_tasks(struct task_struct *t1, struct task_struct *t2) /* Assign a unique per-task cookie solely for t1. */ cookie = sched_core_alloc_task_cookie(); - if (!cookie) + if (cookie) + sched_core_get(); + else goto out_unlock; if (t1->core_task_cookie) { @@ -401,7 +393,9 @@ int sched_core_share_tasks(struct task_struct *t1, struct task_struct *t2) /* CASE 1. */ cookie = sched_core_alloc_task_cookie(); - if (!cookie) + if (cookie) + sched_core_get(); + else goto out_unlock; /* Add another reference for the other task. */