Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp203999pxb; Wed, 11 Nov 2020 01:15:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/GY6WAWkJCU1pp5y0M62dmtj782w0c5G1sRUWM5aXhUXmC2T9N/e6eqVQHOUG4GVC/upY X-Received: by 2002:a05:6402:1009:: with SMTP id c9mr3891511edu.157.1605086100418; Wed, 11 Nov 2020 01:15:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605086100; cv=none; d=google.com; s=arc-20160816; b=krqyGiYxgBoxnZELTsolhUD12uTnDIfhtn5bGmUMhJsKIKwhItmZXF3KqFV71wC1Lr Dz3UvVKo9NZS00/ZHhwt4ss+oWi0eD+LMtyD4YeliiZKEUXevpVWLZUnrdOP/dxq24Ak KIQhtccxPtWJgwxCDPJO+YWcGiUuKvMOwRS/kyCe/gBVmlP4KWV4E/r+WsW+9QrZHe4H bOKlIxNiph/MXfNffMfKN6Mig/hAQSl1uTcAj76Ra5iPwi4rHA8bLAQ8ZyoMjFBO81o2 0XWuopzCPd+GzoYWg2iZZHDooW3rUZUf6vgjZ74PZ3ogu1Hx5OjU+utIffjP1ykk4QCE ChdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:to; bh=9ocfWkhHuh6SoKFV4PtH6+6K1HfnDs9IDBJwHS1i2A0=; b=g/15z8N3gEq3MjzbPKSduKTB1+bTLIYFdzKHGmU3tx8VgX6XjtXopNe11UTpbQteR6 eMqlEOoTWApQLSA4MqOEqyUG7MOeS5vTmUewYJueNluNhshhxQK2d8r+7gdtz7FTvy/3 5XWsobNaopjJ+gJzUhUFtdc8x39tT0Ycxz/r49N7tdVl2MvNQfmjEhJgdh1c+zOBTLYB 71xIpqsvZZgppHtlZ9qO93tjCvrm0uInfBd6bgc2uBDKHaMvT5lpeezOD7ZwHNVDUUE1 MJTa9hJVp1SSUb5d369cXS9W8TcDnnCqX7yt0eXC8zBIyccoovyuOBQcppyqYxDFj62Z WLjQ== ARC-Authentication-Results: i=1; mx.google.com; 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 gx25si908993ejb.445.2020.11.11.01.14.36; Wed, 11 Nov 2020 01:15:00 -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; 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 S1726303AbgKKJMX (ORCPT + 99 others); Wed, 11 Nov 2020 04:12:23 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7206 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726593AbgKKJMR (ORCPT ); Wed, 11 Nov 2020 04:12:17 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CWJrj3WWnzkgWh; Wed, 11 Nov 2020 17:11:49 +0800 (CST) Received: from [10.174.176.199] (10.174.176.199) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Wed, 11 Nov 2020 17:11:52 +0800 To: , , , , Shiyuan Hu , Hewenliang From: Yunfeng Ye Subject: [PATCH] tick/nohz: Reduce the critical region for jiffies_seq Message-ID: Date: Wed, 11 Nov 2020 17:11:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.199] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When nohz or nohz_full is configured, the concurrency calls of tick_do_update_jiffies64 increases, and the conflict between jiffies_lock and jiffies_seq increases, especially in multi-core scenarios. However, it is unnecessary to update the jiffies_seq lock multiple times in a tick period, so the critical region of the jiffies_seq can be reduced to reduce latency overheads. By the way, last_jiffies_update is protected by jiffies_lock, so reducing the jiffies_seq critical area is safe. Signed-off-by: Yunfeng Ye --- kernel/time/tick-sched.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index f0199a4ba1ad..41fb1400439b 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -66,11 +66,11 @@ static void tick_do_update_jiffies64(ktime_t now) /* Reevaluate with jiffies_lock held */ raw_spin_lock(&jiffies_lock); - write_seqcount_begin(&jiffies_seq); delta = ktime_sub(now, last_jiffies_update); if (delta >= tick_period) { + write_seqcount_begin(&jiffies_seq); delta = ktime_sub(delta, tick_period); /* Pairs with the lockless read in this function. */ WRITE_ONCE(last_jiffies_update, @@ -91,12 +91,11 @@ static void tick_do_update_jiffies64(ktime_t now) /* Keep the tick_next_period variable up to date */ tick_next_period = ktime_add(last_jiffies_update, tick_period); - } else { write_seqcount_end(&jiffies_seq); + } else { raw_spin_unlock(&jiffies_lock); return; } - write_seqcount_end(&jiffies_seq); raw_spin_unlock(&jiffies_lock); update_wall_time(); } -- 2.18.4