Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1129793pxb; Thu, 4 Mar 2021 04:12:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoIxWaDDT5BfO/fANCsqZfes1wDJAtcQDFIXDIHJ6j7lqRpCwKVoQ+QW7i88Ol6j6/IPpf X-Received: by 2002:a17:906:4410:: with SMTP id x16mr3902401ejo.446.1614859975690; Thu, 04 Mar 2021 04:12:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614859975; cv=none; d=google.com; s=arc-20160816; b=J/4C6Mn5msYuI+VWtPuHmWvhKKgzm6riBhlsefl8VbeFE1pUoHKUmMvYl2izXl/kQS 0VH2ccyKde4115BxKpU1TtAU8O3n1fc8V6P9hVKhscivxs9cJZRJrIUdwjyjr/Z4RRb9 Bm4TCs22C4rigxrBPzwSU1svZPf0UlkF2wVQnVRYDVfS2wxdx8rxgvJWXXFGKsnWaz2Z Ojy+tb53cj+pX19/J63XbESJWpV/3nscNz28FAZAbo1q5F/k23aL3WYE27Dw9er23H0z PfeuyVIqXHKxyzk2KRSSbTgts0ZaBMX0sFNweCOyTDaKXevSbOyn6L2acJOGgRiEm9YT DJtA== 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=UgK6CdUmVmia3F32TSqVm1rGFuB6oMqXqSZlCi1K1AA=; b=lGbNcXF0YTuBt+sJ1rvfF48GCae5wKjJOI+t6qFMeuEcn1Czt+0QuofYBVvlpj7Nvy nh47+BUGWhvrQGcdpW3eGF6vhzTx8SrUrjgfI6TOhEE4wifReH11VYQhDW+MVY6olhJa VtIFp3fXfl9KLYGF1F3GoxnN9ozLjEs5EzA3q471MVwbWR9RHgyaU3QSbzmu7Jc9LJ3X 4R7DfJiC38dfAukkTT4ES9qzxqQmL8+nxTb5OmV6CDDhdPjVSOhOwf6shVQT+jdDt5IF Y9vkCBF28fOgAoQ1edCdJmmNZX1NEFGznSd11Mf0VIxJk3mTnMe6SZQrkQfekW/hMkjU JX+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=duaUVIGP; 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 u13si15875394ejc.243.2021.03.04.04.12.33; Thu, 04 Mar 2021 04:12:55 -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=@infradead.org header.s=desiato.20200630 header.b=duaUVIGP; 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 S1579843AbhCCScX (ORCPT + 99 others); Wed, 3 Mar 2021 13:32:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347322AbhCCQuH (ORCPT ); Wed, 3 Mar 2021 11:50:07 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CB5FC061756 for ; Wed, 3 Mar 2021 08:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=UgK6CdUmVmia3F32TSqVm1rGFuB6oMqXqSZlCi1K1AA=; b=duaUVIGPobMFDZfqpJdAQfeR/U Lf82qEMloQKwNyG6quGc3BDub7P0dT0k0CIYRkRGzec3vT4+UzvmKDsxIohkEuY0vyNp1hxznx7nJ GRUraaCyC/uCOp6v8P1FhkLXB8Bms4yTxrpjGwmk/mc4KYKHZjw2FGxRHlMsu4iyJ9IMbEBkYv+IP tTJRB7ccd/hd/3dr59/2rTIaonz9EYwdJEe6OC57zyLssT7STGvAvn47g06YPi2mF1cwK0Mwlx/J5 8wm8NEEto+4sPQnu0pAGD49zKnqFIpScSpsIBjW9ZoiJpgTgif1eIIUuqhnykAp2iEJG+OjDqEGPc gSroglCw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lHToH-005Tcr-F4; Wed, 03 Mar 2021 15:53:13 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 00736303205; Wed, 3 Mar 2021 16:53:13 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E44C923662BEE; Wed, 3 Mar 2021 16:53:12 +0100 (CET) Date: Wed, 3 Mar 2021 16:53:12 +0100 From: Peter Zijlstra To: Chengming Zhou Cc: hannes@cmpxchg.org, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, linux-kernel@vger.kernel.org, songmuchun@bytedance.com Subject: Re: [PATCH v2 4/4] psi: Optimize task switch inside shared cgroups Message-ID: References: <20210303034659.91735-1-zhouchengming@bytedance.com> <20210303034659.91735-5-zhouchengming@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210303034659.91735-5-zhouchengming@bytedance.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 03, 2021 at 11:46:59AM +0800, Chengming Zhou wrote: > The commit 36b238d57172 ("psi: Optimize switching tasks inside shared > cgroups") only update cgroups whose state actually changes during a > task switch only in task preempt case, not in task sleep case. > > We actually don't need to clear and set TSK_ONCPU state for common cgroups > of next and prev task in sleep case, that can save many psi_group_change > especially when most activity comes from one leaf cgroup. > > sleep before: > psi_dequeue() > while ((group = iterate_groups(prev))) # all ancestors > psi_group_change(prev, .clear=TSK_RUNNING|TSK_ONCPU) > psi_task_switch() > while ((group = iterate_groups(next))) # all ancestors > psi_group_change(next, .set=TSK_ONCPU) > > sleep after: > psi_dequeue() > nop > psi_task_switch() > while ((group = iterate_groups(next))) # until (prev & next) > psi_group_change(next, .set=TSK_ONCPU) > while ((group = iterate_groups(prev))) # all ancestors > psi_group_change(prev, .clear=common?TSK_RUNNING:TSK_RUNNING|TSK_ONCPU) > > When a voluntary sleep switches to another task, we remove one call of > psi_group_change() for every common cgroup ancestor of the two tasks. > Co-developed-by: Muchun ? > Signed-off-by: Muchun Song > Signed-off-by: Chengming Zhou