Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1032729pxj; Fri, 4 Jun 2021 04:34:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxWKzl4ib8JNkKRUoK6ZCM1eyM/qs/ANsrBWQ68HGVKsl2FeYOe90wBvucDxPvohCg2w3P X-Received: by 2002:a05:6402:61a:: with SMTP id n26mr4225089edv.220.1622806466482; Fri, 04 Jun 2021 04:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622806466; cv=none; d=google.com; s=arc-20160816; b=M6NkXuzEelzhRZN6x05Pb8ZNMQUC0tA7C4ifoWrbu8wpk2/13vVBeVUJ63zVufY5NQ y0CWzqJJyWemuqNIV9AzYgSAC0h/Sa149AFGP7XLzYnt5tqaIOBC4/mdboffb+0oh/n9 YH18GrhXn2H13R5UMv7jJ3tzH6SiOcRynArkBdj7LcM7svOW7gKJ1aSDG/xXFdm+ZVIp dMaCZAWtrPY9r3wye5YKUfaxxvsGSOvT033eb7mb0jRExdowrHo6I4CL1QulMQ3Kg8Vv eD754JNjIV5tYF32HFUsVdvYtT37EZtpR6/UhnNySMRRa1GzKp+KzFsbYhN2KnZ6DTKj jhNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gI0ORUY1j3+yfCCTPD41XoWQLJMSa5nFnWiESMYeGPk=; b=i6TPioaVQ7UvpWGn4hIKoFGGOOrUvQYQSHVelXVAUQK8ijl0Vr23RpdBHPzWxHMaQc t/e7XUhL8HprD/RpJiJ0Lz5IGGudJ21QnzttNIOxxI2YfHmBoFjqpu9CNOLR5WXezACG hcxHoHovNhFGT9PoMakhJ2Dr8poY9ohVQeHthZYGCdJMvhb9srDi5PwRK3NexGxYtegA DE9S4jiQHjPzIsuqRqZdhfEXhf8RV1xxO0ISXibdnAPTHgBWJNwa/fF8t7pBbU/4J7zQ pDwHyTzX0yuP2ib/pVA6YtSYdynLvWmNlQnLJ3u72/aFTne6165jgMmKPmpgAxUHVEHM 3LEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uCgm9GFX; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m29si4686335ejn.735.2021.06.04.04.34.02; Fri, 04 Jun 2021 04:34:26 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=uCgm9GFX; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230231AbhFDLeA (ORCPT + 99 others); Fri, 4 Jun 2021 07:34:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:34490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230207AbhFDLd6 (ORCPT ); Fri, 4 Jun 2021 07:33:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DF8BD6143C; Fri, 4 Jun 2021 11:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622806332; bh=ZGPSl0rtuIsFTTwz7Y4VHvVmhKstD6YjuuRg0hrelgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uCgm9GFX4blmZDW1qwvT7vdwaijAMa/85SzzGRi25ucPw7kTcX4quRtavaYfZ9opP BuF7/hBqgLr+k1k+S5GIYj1X+GSMIkQ/VnylzE6czNvImn4IuI0ryDlYW05LT52gGB ixSbcpqPZiLUFswAmzZL6VYANdW8S5CM6+WgMCA3X/Uhy70JrPkSKSlb7k+ztsojoP 9ZI9nUzbSZLDyJhbqztvdGs5slXHFyQCCIiIyySro2KLIIS2lXicr7zrsh5aUq65xW IGKKHZcyo1uU+DAB8bQx+rWwj1R7AoLi2ebtfRuAi6oHfo/VuD/04SQWUW0z0ERsRk aF/P7sS0dJdVQ== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Peter Zijlstra , "Eric W . Biederman" , Oleg Nesterov , Ingo Molnar Subject: [PATCH 4/6] posix-cpu-timers: Force next_expiration recalc after timer reset Date: Fri, 4 Jun 2021 13:31:57 +0200 Message-Id: <20210604113159.26177-5-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210604113159.26177-1-frederic@kernel.org> References: <20210604113159.26177-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A timer reset only dequeues the timer but it doesn't shutdown the related costly process wide cputimer counter and the tick dependency. The following code snippet keeps this overhead around for one week after the timer reset: void trigger_process_counter(void) { timer_t id; struct itimerspec val = { }; val.it_value.tv_sec = 1; timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); timer_settime(id, 0, &val, NULL); val.it_value.tv_sec = 0; timer_settime(id, 0, &val, NULL); } Make sure the next target's tick recalculates the nearest expiration and clears the process wide counter and tick dependency if necessary. Signed-off-by: Frederic Weisbecker Cc: Oleg Nesterov Cc: Thomas Gleixner Cc: Peter Zijlstra (Intel) Cc: Ingo Molnar Cc: Eric W. Biederman --- kernel/time/posix-cpu-timers.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c index bb1f862c785e..0b5715c8db04 100644 --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -414,10 +414,14 @@ static int posix_cpu_timer_create(struct k_itimer *new_timer) static void disarm_timer(struct k_itimer *timer, struct task_struct *p) { struct cpu_timer *ctmr = &timer->it.cpu; + u64 old_expires = cpu_timer_getexpires(ctmr); struct posix_cputimer_base *base; + bool queued; int clkidx; - if (!cpu_timer_dequeue(ctmr)) + queued = cpu_timer_dequeue(ctmr); + cpu_timer_setexpires(ctmr, 0); + if (!queued) return; clkidx = CPUCLOCK_WHICH(timer->it_clock); @@ -427,7 +431,7 @@ static void disarm_timer(struct k_itimer *timer, struct task_struct *p) else base = p->signal->posix_cputimers.bases + clkidx; - if (cpu_timer_getexpires(ctmr) == base->nextevt) + if (old_expires == base->nextevt) base->nextevt = 0; } @@ -647,8 +651,6 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, if (unlikely(timer->it.cpu.firing)) { timer->it.cpu.firing = -1; ret = TIMER_RETRY; - } else { - cpu_timer_dequeue(ctmr); } /* @@ -713,9 +715,13 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, * For a timer with no notification action, we don't actually * arm the timer (we'll just fake it for timer_gettime). */ - cpu_timer_setexpires(ctmr, new_expires); - if (new_expires != 0 && val < new_expires) { - arm_timer(timer, p); + if (new_expires != 0) { + cpu_timer_dequeue(ctmr); + cpu_timer_setexpires(ctmr, new_expires); + if (val < new_expires) + arm_timer(timer, p); + } else { + disarm_timer(timer, p); } unlock_task_sighand(p, &flags); -- 2.25.1