Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2482770pxb; Mon, 18 Jan 2021 20:44:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgS8hE9pvUUv0IjPiddrryFmQUtQk6JSfhQ7loRfLeGivT7YxB6meXBwYBZFlYUM4EXq+a X-Received: by 2002:a17:906:26d7:: with SMTP id u23mr1782342ejc.210.1611031458094; Mon, 18 Jan 2021 20:44:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611031458; cv=none; d=google.com; s=arc-20160816; b=0gkFNojb9vccmxNIE3MLhT4rNcqUSUQb6KVA/jdAYjzPuF539ydeH4zfSlzjTWkuh8 l54k3Qqg8YSEM9qZg8EzI6PkLL2cZ+z3ZwoLnRUuxIg17lRqmhcCc1VCGx8INo9pmSgo gILOjiFIFcL/irAlSS0Sam0RQAhtsF+z/qWy5gYTO0H+MoGCu/7H0vZGEzy9WMN9lTI2 m1OlAoHFM9kDNrwlX+TC55zfe+LiQKVsbOMmFqzMOGyKUlovCCAHAfVKPIq+MAoYdMtx K7ieVM8HlZI+ZIZ9GFnt9o6MwOxVRd8aIidlP4MkwDQXI8+6s8orpM1jFbUAkQkeUxIv wU+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KYV6v28PmbLgIKD3dOyIEV8BYNhkb29qTPJqNvBC4G0=; b=v4NCh9Npuvlln88A1qhe+XIxIcPdkcz8yYYhn8oZK9WTXrKmDC0k4wfL7qNMRN7IUj d9YQdTMl/hvOIQNZhmGrPFAx3omi+ZXoWxR1ISkU4FPIXHQpvuvsHwqgF7gtFkfMF2X+ PYDadXei798HSNL4piVVxzByX25Jf2pnvOGfxriKdCx8y4Uz018/x2G77cI8TJdBAHwi yYVOZq+ygGocOJCtPTc0C7QOXpvyu2+rYkNgkjgI8V6qxhtjqWdOUtoIRhOpXedc5bbk /CEvh9inhIIJYBOgCSRcbMry3z4QVJj2q54NWahjEzPk5yPMtW2n7MVlnOwODfX4l4u+ 7dTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f9jaiCBS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o3si8754651eda.133.2021.01.18.20.43.44; Mon, 18 Jan 2021 20:44:18 -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=@gmail.com header.s=20161025 header.b=f9jaiCBS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392391AbhARQHN (ORCPT + 99 others); Mon, 18 Jan 2021 11:07:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406420AbhARQGc (ORCPT ); Mon, 18 Jan 2021 11:06:32 -0500 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1813C061573 for ; Mon, 18 Jan 2021 08:05:51 -0800 (PST) Received: by mail-oi1-x235.google.com with SMTP id p5so18139841oif.7 for ; Mon, 18 Jan 2021 08:05:51 -0800 (PST) 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=KYV6v28PmbLgIKD3dOyIEV8BYNhkb29qTPJqNvBC4G0=; b=f9jaiCBSfMJKmnGKpqI597WW8A97ptieAH0VHgP5oRMfCKMawFDUUCERdK99KkeoTU ntyT88ojQn0/AMsi+Ye3qur+Bz7FFg728JyOkiuVcQnwi+PaNm/iqYitqPPeuVhW5xED dEwPczSHiBgw2YFb7voPk9oSHWB2kTes9niMJFqtADS+8VSJnMRf0yKjp46NYBSePlf0 Uae2ICsqxpe42/D33TAJaJJZFekbBQP2OwM/zoKTHl9cLeIUWV4y9EvaoFH229MfRVj1 yn4WSPbZNhcmzNMMctCqaPUmTx4kkJ7YT4pXhGuAwes+Y4BbQlmL0LxpmRNiZKqklGPK 95qg== 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=KYV6v28PmbLgIKD3dOyIEV8BYNhkb29qTPJqNvBC4G0=; b=db7sgw8+3CIgtJUz95sPbKi+sZBQ+zWUGXgwwtE7mLr0xHjyO1J+gKDJ7U+FGWex9K 51wpgVTHVNmZsKZkJ2Alv7BTZYaY5uGWP1aNHAmz6jOmum1n80J2Uz8Bf1uLB9juZ99z ptMalmjrLUeVX0heysXr2yHac/DCu8o40xy+e0Le009Id/bk1FzI3kz+tNxXzRk6pRgk 3P0Ovd+JeTvBTdjJFJYis2lrcot/HNknOGinv8DoNRH8YdLap5RvVVnutfddW98Ird+w FyVP34z1aOO58lvsoWjIE05+YntthTeBUFpYDtK3sCxK/WBwDGbV58hh1rIwu3eNtgwk A1Jw== X-Gm-Message-State: AOAM532xYu5n6/dC/npYXUyQdRS0VN9tXhzXq6oXoGwPTX2Y5OEm2HoW kM8nRa8Pe4u0yk4vKHD06CuaWufznpuYlrHM7gQ= X-Received: by 2002:a05:6808:651:: with SMTP id z17mr39609oih.150.1610985951282; Mon, 18 Jan 2021 08:05:51 -0800 (PST) MIME-Version: 1.0 References: <20210117123104.27589-1-benbjiang@tencent.com> In-Reply-To: From: Jiang Biao Date: Tue, 19 Jan 2021 00:05:40 +0800 Message-ID: Subject: Re: [PATCH] sched/fair: add protection for delta of wait time To: Vincent Guittot Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , linux-kernel , Jiang Biao Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Vincent On Mon, 18 Jan 2021 at 23:32, Vincent Guittot wrote: > > On Mon, 18 Jan 2021 at 15:11, Jiang Biao wrote: > > > > Hi, Vincent > > > > On Mon, 18 Jan 2021 at 15:56, Vincent Guittot > > wrote: > > > > > > On Sun, 17 Jan 2021 at 13:31, Jiang Biao wrote: > > > > > > > > From: Jiang Biao > > > > > > > > delta in update_stats_wait_end() might be negative, which would > > > > make following statistics go wrong. > > > > > > Could you describe the use case that generates a negative delta ? > > > > > > rq_clock is always increasing so this should not lead to a negative > > > value even if update_stats_wait_end/start are not called in the right > > > order, > > Yes, indeed. > > > > > This situation could happen after a migration if we forgot to call > > > update_stats_wait_start > > The migration case was what I worried about, but no regular use case > > comes into my mind. :) > > IIUC, you haven't faced the problem and it's only based on studying the code. Not yet. :). Just found there are protections for sleep_time/block_time, but no protection for wait_time. Think more later, the sleep_time/block_time do need to be protected for the migration case, because update_stats_enqueue_sleeper could be called right after migration with src cpu's sleep_start/block_start. But wait_time is not the case. The following case might be too extreme to happen. :) Thanks a lot for your patience. Regards, Jiang > > > As an extreme case, would it be a problem if we disable/re-enable > > sched_schedstats during migration? > > > > static inline void > > update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se) > > { > > u64 wait_start, prev_wait_start; > > > > if (!schedstat_enabled()) // disable during migration > > return; // return here, and skip updating wait_start > > ... > > } > > > > static inline void > > update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se) > > { > > struct task_struct *p; > > u64 delta; > > > > if (!schedstat_enabled()) // re-enable again > > return; > > > > /* > > * When the sched_schedstat changes from 0 to 1, some sched se > > * maybe already in the runqueue, the se->statistics.wait_start > > * will be 0.So it will let the delta wrong. We need to avoid this > > * scenario. > > */ > > if (unlikely(!schedstat_val(se->statistics.wait_start))) > > return; > > //stale wait_start which might be bigger than rq_clock would > > be used. -) > > delta = rq_clock(rq_of(cfs_rq)) - > > schedstat_val(se->statistics.wait_start); > > ... > > > > Thanks a lot. > > Regards, > > Jiang