Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5166004yba; Wed, 8 May 2019 08:52:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFI+MoNrq2ZQ+aM652vRIBj2PW2X4Iy5w9SWYS6jgys7vgEUm3nZSOM7yBgUtPqAiCpSxh X-Received: by 2002:a63:5907:: with SMTP id n7mr48157922pgb.416.1557330771674; Wed, 08 May 2019 08:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557330771; cv=none; d=google.com; s=arc-20160816; b=AqpbRirWoSw4pJY2XxwBXTlfw0DOejJvUk/kL3yt591fMgpRU5ZjMkaGukE9tgxG5I rD5+KtwRw9paOZj/LuEAGbj0G5+M21UGn8n7iX7AAt6LDoxyvw3YVAmcysiEXjUbf95C fnqBqw3UMAsTH/IaaCecaAqMJT/2w4oU2DUviGxIftLG9mmcSgT6e8ltNvTQTLFj9nKW 3ftagBt9PIQmSRvvGvNOjtJALilcMs4ad9u5EHoNvQJI/3mz374ExOH4ulFi3Y2zrpev RfnCu93l5uA0YJNeGuDHf+ABVazJ4VzdYL5hCpX5rc+lugFdZlQVF9uWBseD4xv1v3Lg iAkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=B305JCF4NGCczfGfXU1a1TKoXlp/y2MhWZaGK0Ie4es=; b=tWY3cu4hG7BYBFMcx+G1D8iMmxE0mwB9GON/E1jtvc9lwKLlqlXcwQQn0c2+AtITV8 Mha9tl8xzN/PX5PLHVibrcAFyfaRigtOkx+4ez2tpO34zf4vsJrtoyL6v+a64jSSyxuZ IqBqO7OwMJyuHheRT3dWUHWYPOfhTt+Lv3gabVSIWQET++UcAc4v9qCVPIKDCjQt8D0D tA8jkg9qJX/DTGEFrXdj7n4BRidzKo7CueGmJTH2lcbiGeBy4LEcn1Xc0wACFKrX4dDC 4nHcwVvGE3dj7ZRtai2sPMY3vUYpqzLX+ctyluCOvTHzyYr/YIYNSCwbkXK+o4oXJimz m+BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=A2CfoAC9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j71si22730638pfc.127.2019.05.08.08.52.36; Wed, 08 May 2019 08:52:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=A2CfoAC9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727530AbfEHPuM (ORCPT + 99 others); Wed, 8 May 2019 11:50:12 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:33471 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726506AbfEHPuM (ORCPT ); Wed, 8 May 2019 11:50:12 -0400 Received: by mail-lj1-f196.google.com with SMTP id f23so17946208ljc.0 for ; Wed, 08 May 2019 08:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=B305JCF4NGCczfGfXU1a1TKoXlp/y2MhWZaGK0Ie4es=; b=A2CfoAC96HAV0IlhpRIdq0sCzJOOUx6zxDraSZJePsGQe/2A8A/byVvNpR7hz+daF4 2a0ofpW8jtCw/hQJrpVYYGbOKWp+8b66TRCEwrwqjL3+Kz6QWv9huBpqZujXlMg0pD8P R5mo/uiy970d/CIf0irWTjfuvETtSt5Uynfv52guHz7jeOBvenHdcLnvHQvxvOqpgqe2 h6PbXLiiVL5zMAHl22IJBGpisgZXdZrNEe7n9IzK2bwvUgv9cJs9rqEAnluIsxdAi3oB UoVifu8pItlm7N1OZCfy/ZJNADLGh8eoItRVw0HgeytPli+tF0EKCKYdGtPwxdbvv7cv qEyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B305JCF4NGCczfGfXU1a1TKoXlp/y2MhWZaGK0Ie4es=; b=WIubzIxo8eWSX4RKaYSn3lBx7s7f41b4BgurU1b+4dZldmmqhiW+0yZSUpWZdyAfLw P/GtT/DTb/Tyk1JxcTS9qM2WDsc9SeMEX2S41hLNcg2gKHn+UglWuZ7ZJjnYwKctvpSf ybFsQgXtk8144niKFNLGiGMDuosGo6JwTv1pNq/9SGfLaiRshod9BxLN9v8H6O3NldG2 5GOwlvWimxK+1cRfYNGM/nhdoklLtm+JJoW1+6Y+xfvkiRjIR2Yv1BzfYnKjDVFVthxd JO+22NduCx6XJPYshKQvI4PRk8TK5tiqdbu8a5f+HYKTxcX7v3SzLCZCj/rwjGRnX6GQ qtGw== X-Gm-Message-State: APjAAAXmI/AMyYQebkescq8xNjyyE/8xWj1JKY5de4gOVgc4Lu0f/Wd2 GpfLY3rR5l36VhJNMERZHRUm3xikEbw0F7YYhKg2OA== X-Received: by 2002:a2e:810d:: with SMTP id d13mr20255512ljg.93.1557330609560; Wed, 08 May 2019 08:50:09 -0700 (PDT) MIME-Version: 1.0 References: <2364f2b65bf50826d881c84d7634b6565dfee527.1556025155.git.vpillai@digitalocean.com> <20190429061516.GA9796@aaronlu> <6dfc392f-e24b-e641-2f7d-f336a90415fa@linux.intel.com> <777b7674-4811-dac4-17df-29bd028d6b26@linux.intel.com> In-Reply-To: <777b7674-4811-dac4-17df-29bd028d6b26@linux.intel.com> From: Aubrey Li Date: Wed, 8 May 2019 23:49:58 +0800 Message-ID: Subject: Re: [RFC PATCH v2 11/17] sched: Basic tracking of matching tasks To: Tim Chen Cc: Aaron Lu , Vineeth Remanan Pillai , Nishanth Aravamudan , Julien Desfossez , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Paul Turner , Linus Torvalds , Linux List Kernel Mailing , Subhra Mazumdar , =?UTF-8?B?RnLDqWTDqXJpYyBXZWlzYmVja2Vy?= , Kees Cook , Greg Kerr , Phil Auld , Aaron Lu , Valentin Schneider , Mel Gorman , Pawan Gupta , Paolo Bonzini Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 3, 2019 at 8:06 AM Tim Chen wrote: > > On 5/1/19 4:27 PM, Tim Chen wrote: > > On 4/28/19 11:15 PM, Aaron Lu wrote: > >> On Tue, Apr 23, 2019 at 04:18:16PM +0000, Vineeth Remanan Pillai wrote: > >>> +/* > >>> + * Find left-most (aka, highest priority) task matching @cookie. > >>> + */ > >>> +struct task_struct *sched_core_find(struct rq *rq, unsigned long cookie) > >>> +{ > >>> + struct rb_node *node = rq->core_tree.rb_node; > >>> + struct task_struct *node_task, *match; > >>> + > >>> + /* > >>> + * The idle task always matches any cookie! > >>> + */ > >>> + match = idle_sched_class.pick_task(rq); > >>> + > >>> + while (node) { > >>> + node_task = container_of(node, struct task_struct, core_node); > >>> + > >>> + if (node_task->core_cookie < cookie) { > >>> + node = node->rb_left; > >> > >> Should go right here? > >> > > > > I think Aaron is correct. We order the rb tree where tasks with smaller core cookies > > go to the left part of the tree. > > > > In this case, the cookie we are looking for is larger than the current node's cookie. > > It seems like we should move to the right to look for a node with matching cookie. > > > > At least making the following change still allow us to run the system stably for sysbench. > > Need to gather more data to see how performance changes. > > Pawan ran an experiment setting up 2 VMs, with one VM doing a parallel kernel build and one VM doing sysbench, > limiting both VMs to run on 16 cpu threads (8 physical cores), with 8 vcpu for each VM. > Making the fix did improve kernel build time by 7%. I'm gonna agree with the patch below, but just wonder if the testing result is consistent, as I didn't see any improvement in my testing environment. IIUC, from the code behavior, especially for 2 VMs case(only 2 different cookies), the per-rq rb tree unlikely has nodes with different cookies, that is, all the nodes on this tree should have the same cookie, so: - if the parameter cookie is equal to the rb tree cookie, we meet a match and go the third branch - else, no matter we go left or right, we can't find a match, and we'll return idle thread finally. Please correct me if I was wrong. Thanks, -Aubrey > > Tim > > > > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 25638a47c408..ed4cfa49e3f2 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -208,9 +208,9 @@ static struct task_struct *sched_core_find(struct rq *rq, unsigned long cookie) > > while (node) { > > node_task = container_of(node, struct task_struct, core_node); > > > > - if (node_task->core_cookie < cookie) { > > + if (cookie < node_task->core_cookie) { > > node = node->rb_left; > > - } else if (node_task->core_cookie > cookie) { > > + } else if (cookie > node_task->core_cookie) { > > node = node->rb_right; > > } else { > > match = node_task; > > > > >